akhauriyash/Code-Regression huggingface dataset:
def bng(card, nums):
    inv = {card[i][j]: (i,  j) for i in range(3) for j in range(3)}
    bingo  = {(i, j): False for i in range(3) for j in range(3)}
    for num in nums:
        if  inv.get(num) is not None:
            bingo[inv[num]] = True
    for i in range(3):
        if all(bingo[i, j] for j in range(3)) or all(bingo[j, i] for j in range(3)):
            return 'Yes'
    if all(bingo[i, i] for i in range(3)) or all(bingo[i, 2 - i] for i in range(3)):
        return 'Yes'
    return 'No'

card = [input().split() for _ in range(3)]
n = int(input())
nums = [input() for  _  in range(n)]
print(bng(card, nums))

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

int main() {
  int q;
  cin >> q;
  while(q--){
    int n,m;
    cin >> n >> m;
    int nm = n*n+m*m;
    vector <int> num;
    for(int i=0;i*i<=nm;i++)
      for(int j=i;j*j<=nm;j++)
	if(i+j!=0&&nm%(i*i+j*j) == 0)num.push_back(i*i+j*j);

    int ans = 0;
    for(int i=0;i<num.size();i++)
      for(int j=i;j<num.size();j++)
	if(num[i]*num[j] == nm)  ans+=2;

    if(ans  == 2)  cout << 'P'<<endl;
    else cout <<"C"<<endl;
  }
  return 0;
}  

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int l=0, r=n-1, cnt=0;
    while(l<r){
        if(s[l]=='W'&&s[r]=='R'){
            l++;
            r--;
            cnt++;
        }else if(s[l]=='R'&&s[r]=='R'){
            l++;
        }else{
            r--;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3752
// https://atcoder.jp/contests/abc151/tasks/abc151_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define FORR(i,b,e) for(int i=(b); i>=(int)(e); i--)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const int A_I_MAX = 1e9;
const int MOD = 1e9+7;

//------------------------------------------------------------------------------
int extgcd(int a, int b, int &x, int &y) {
  int ret = a;
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    ret = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  return ret;
}

int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

//------------------------------------------------------------------------------
const int F_MAX = N_MAX;

ll fact[F_MAX + 1];
ll fact_inv[F_MAX + 1];

void init_fact(int m) {
  fact[0] = 1;
  FOR(i, 1, F_MAX) fact[i] = fact[i - 1] * i % m;
  fact_inv[F_MAX] = mod_inverse(fact[F_MAX], m);
  FORR(i, F_MAX - 1, 0) fact_inv[i] = fact_inv[i + 1] * (i + 1) % m;
}

ll mod_comb_fast(ll n, ll k, ll mod) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll a = fact[n];
  ll b = fact_inv[k] * fact_inv[n - k] % mod;
  return a * b % mod;
}

//------------------------------------------------------------------------------
int N, K;
int A[N_MAX];
ll acc[N_MAX + 1];

void solve() {
  init_fact(MOD);
  sort(A, A + N);
  REP(i, N) acc[i + 1] = (acc[i] + A[i]) % MOD;
  ll ans = 0;
  FOR(m, K, N) {
    ll add = 0;
    add = (add + acc[N]) % MOD;
    add = (add + MOD - acc[m - 1]) % MOD;
    add = (add + MOD - acc[N - m + 1]) % MOD;
    ll mul = 1;
    if (K > 2) mul = mod_comb_fast(m - 2, K - 2, MOD);
    // printf("m:%d add:%lld, mul:%lld\n", m, add, mul);
    ans = (ans + add * mul % MOD) % MOD;
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional> 
#include <vector>

using namespace std;

int main(){

    int n,x;
    cin >> n;

    x = (n/100000000)%10 +
        (n/10000000)%10 +
        (n/1000000)%10 +
        (n/100000)%10 +
        (n/10000)%10 +
        (n/1000)%10 +
        (n/100)%10 +
        (n/10)%10 +
        n%10;

    if(n%x == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = int.MaxValue;
        for (int i = 0; i < N; i++){
            var ai = A[i];
            var count = 0;
            while ((ai & 1) == 0){
                ai >>= 1;
                count++;}
            answer = count < answer ? count : answer;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;
string t;

int main() {
	cin >> s;
	rep(i, s.size()) {
		if (s[i] != 'x')t += s[i];
	}
	if (t.empty()) {
		cout << 0 << endl;
		return 0;
	}
	string tt = t;
	reverse(ALL(t));
	if (tt == t) {
		int ans = 0;
		int lb = 0, ub = s.size() - 1;
		while (lb < ub) {
			if (s[lb] == 'x') {
				if (s[ub] == 'x') {
					lb++;
					ub--;
				}
				else {
					lb++;
					ans++;
				}
			}
			else {
				if (s[ub] == 'x') {
					ub--;
					ans++;
				}
				else {
					lb++;
					ub--;
				}
			}
		}
		//reverse(ALL(s));
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define MEMBER 20
using namespace std;
int n=MEMBER,k=0;
int score[MEMBER];
int main(){
	while(k!=n){
		cin >>score[k];
		k++;
	}
	sort(score,score+(10));
	sort(score+(10),score+(20));
	//k=0;
	//while(k!=n){
	//	cout <<score[k]<< " ";
	//	k++;
	//}
	cout << score[7]+score[8]+score[9]<<" ";
	cout << score[17]+score[18]+score[19]<<endl;
	return 0;
}

Measured memory_bytes: 2952
($%,@D)=<>;
$_=[split]for@D;
@s=(_,0,(-1e15)x$%);
for(2..2*$%){
	$s[$$_[1]]+=$-=$s[$$_[0]]+$$_[2]-$s[$$_[1]]for@D;
	$_-$%or$s=$s[-2]
}
print$s<$s[-2]?inf:$s


Measured memory_bytes: 1408
while True:
  n = int(input())
  if n == 0:
    break
  else:
    votes = [0] * 26
    for i, v in enumerate(map(lambda x:ord(x)-65, input().split())):
      votes[v] += 1
      l = sorted(votes, reverse=True)
      if l[0] > l[1] + (n - i - 1):
        print(chr(votes.index(l[0])+65) + ' ' + str(i + 1))
        break
    else:
      print('TIE')


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int n,num[60010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=100;++i)
		for(int j=1;j<=100;++j)
			for(int k=1;k<=100;++k)
				num[i*i+j*j+k*k+i*j+i*k+j*k]++;
	for(int i=1;i<=n;++i) printf("%d\n",num[i]);
	return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int l,r;
  cin>>l>>r;
  if(r-l>2018){
    cout <<0<<endl;
    return 0;
  }
  l=l%2019;
  r=r%2019;
  if(r<=l){
    cout<<0<<endl;
    return 0;
  }
  long long int mod=900000000000;
  for(long long int i=l;i<r;i++){
    for(long long int j=i+1;j<=r;j++){
        mod=min((i%2019*j%2019)%2019,mod);
    }
  }
  cout<<mod<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int N;
int a[200005];
int all;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		all ^= a[i];
	}
	for (int i = 0; i < N; i++) printf("%d ", all ^ a[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, h;
    cin>>h>>n;
    int sum = 0;
    for(int i=0; i<n; ++i) {
        int a;
        cin>>a;
        sum += a;
    }
    if(sum >= h)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1
print(ans)

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

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

    vector<int> a(n), b(n), c(n);

    forn(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<int> dp(3);
    dp[0] = a[0];
    dp[1] = b[0];
    dp[2] = c[0];
    for(int day = 1; day < n; day++){
        vector<int> new_dp(3);
        new_dp[0] = max(dp[1], dp[2]) + a[day];
        new_dp[1] = max(dp[0], dp[2]) + b[day];
        new_dp[2] = max(dp[0], dp[1]) + c[day];

        dp = new_dp; 
    }

    cout << max({dp[0], dp[1], dp[2]}) << endl;
}

int main()
{
    zoom;
    ll t = 1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 4520
N = int(input())
hs = list(map(int, input().split()))

dp = [0 for i in range(N)]
dp[1] = abs(hs[1] - hs[0])

for i in range(2,N):
  dp[i] = min(dp[i-1]+abs(hs[i]-hs[i-1]), 
              dp[i-2]+abs(hs[i]-hs[i-2]))
  
ans = dp[-1]

print(ans)

Measured memory_bytes: 52720
/*input
60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	vector<vector<int>> a(3, vector<int>(3));
	cin >> a[0][0] >> a[0][1] >> a[0][2];
	cin >> a[1][0] >> a[1][1] >> a[1][2];
	cin >> a[2][0] >> a[2][1] >> a[2][2];
	int n, i, j, k;
	cin >> n;
	for(i=0; i<n; i++) {
		int x; cin >> x;
		for(j=0; j<3; j++) {
			for(k=0; k<3; k++) {
				if(a[j][k] == x)
					a[j][k] = 0;
			}
		}
	}
	int ret1 = 0, ret2 = 0;
	for(i=0; i<3; i++) {
		ret1 = ret2 = 0;
		for(j=0; j<3; j++) {
			ret1 = ret1 || a[i][j];
			ret2 = ret2 || a[j][i];
		}
		if(!ret1 || !ret2) {
			cout <<"Yes" << endl;
			return;
		}
	}
	int ret = a[0][0] || a[1][1] || a[2][2];
	if(!ret) { cout << "Yes" << endl; return;}
	ret = a[2][0] || a[1][1] || a[0][2];
	if(!ret) { cout << "Yes" << endl; return;}
	cout << "No" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  string b;
  cin >> a >> b;
  int c = 0;
  for(int i = 0;i < a-2;i++){
    if(b.at(i) == 'A' && b.at(i+1) == 'B' && b.at(i+2) == 'C'){
      c++;}
  }
  cout << c << endl;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n, p = map(int, input().split())

factors = prime_factorize(p)

factor = {}

for i in factors:
    if i not in factor:
        factor[i]=1
    else:
        factor[i]+=1
ans = 1
for i in factor:
    if factor[i]>=n:
        ans *= i**(factor[i]//n)
print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int A, B, C, D, L, R;
	cin >> A >> B >> C >> D;
	L = A + B; R = C + D;
	if (L < R) cout << "Right";
	else if (L == R) cout << "Balanced";
	else cout << "Left";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static int x=sc.nextInt();
	private static final int I_MAX=100000;
	public static void main(String[] args){
		int i;
		for(i=1;i<I_MAX;i++){
			if(i*(i+1)/2>=x) break;
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;

const int MAX_P = 1e5+7;

int main() {
    int x; cin >> x;
    vl isPrime(MAX_P,1);
    isPrime[0] = isPrime[1] = 0;
    for (int i = 2; i < MAX_P; i++) {
        if (isPrime[i] and i >= x) {
            cout << i << endl;
            break;
        }
        for (int j = 2*i; j < MAX_P; j += i) {
            isPrime[j] = 0;
        }
    }
    return 0;
}


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

#define MAX_N 120000

int prime[MAX_N], x[MAX_N], n;

void isprime(int c) {
	prime[2] = 1;
	for (int i = 3; i < c; i += 2) {
		for (int j = 3; j <= sqrt(i); j += 2) {
			if (i%j == 0) { goto E; }
		}
		prime[i] = 1;
	E:;
	}
}

void checker(int d) {
	x[4] = 1;
	for (int i = 5; i < d; i++) {
		if (i % 2 == 1) {
			if (prime[i - 2] == 1) {
				x[i] = 2;
			}
		}
		else {
			if (prime[i / 2] == 1) {
				x[i] += 1;
			}
			for (int j = 3; j < i / 2; j += 2) {
				if (prime[j] + prime[i - j] == 2) {
					x[i] += 2;
				}
			}
		}
	}
}

int main() {
	isprime(MAX_N);
	checker(MAX_N);
	while (cin >> n) {
		cout << x[n + 1] << endl;
	}
}

Measured memory_bytes: 3976
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
bool I[32][100009]; int N, C, s[100009], t[100009], c[100009], dp[100009];
int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		cin >> s[i] >> t[i] >> c[i];
		for (int j = s[i]; j < t[i]; j++)I[c[i]][j] = true;
	}
	for (int i = 1; i <= C; i++) {
		int F = 0;
		for (int j = 1; j <= 100008; j++) {
			if (I[i][j - 1] == false && I[i][j] == true)F = j;
			if (I[i][j - 1] == true && I[i][j] == false) {
				dp[j]--; dp[F - 1]++;
			}
		}
	}
	for (int i = 1; i <= 100008; i++)dp[i] += dp[i - 1];
	int maxn = 0;
	for (int i = 0; i <= 100008; i++)maxn = max(dp[i], maxn);
	cout << maxn << endl;
	return 0;
}

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

int pre[110][110];
int dp[110][110][110];
int X[100];
int Y[100];

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

	int N, P;
	cin >> N >> P;
	for(int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
	}

	memset(pre, -1, sizeof pre);
	pre[0][0] = max(0, Y[0] - X[0]);
	for(int i = 0; i < N - 1; i++) {
		for(int j = 0; j < N; j++) {
			if(pre[i][j] == -1) continue;
			pre[i + 1][0] = max(0, Y[i + 1] - X[i + 1]);
			int x = max(0, X[i + 1] - pre[i][j]);
			int t = max(0, Y[i + 1] - x);
			pre[i + 1][j + 1] = t;
		}
	}

	const int INF = 1 << 30;
	fill((int*)begin(dp), (int*)end(dp), INF);
	dp[0][0][0] = 0;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			for(int k = 0; k < N; k++) {
				if(dp[i][j][k] == INF) continue;
				int sum = dp[i][j][k];
				dp[i + 1][0][k] = min(dp[i + 1][0][k], sum);
				if(sum + pre[i][j] <= P) {
					dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], sum + pre[i][j]);
				}
			}
		}
	}
	int ans = 0;
	for(int j = 0; j <= N; j++) {
		for(int k = 0; k <= N; k++) {
			if(dp[N][j][k] == INF) continue;
			ans = max(ans, k);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8444
def main():
    n,m,x = map(int,input().split())
    A = []
    ans = 10**9
    for i in range(n):
        tmp = [int(i) for i in input().split()]
        A.append(tmp)
    for i in range(2**n):
        arg = [0 for j in range(m+1)]
        cost = 0
        for j in range(n):
            if (i>>j)&1 ==1:
                cost += A[j][0]
                for k in range(1,m+1):
                    arg[k] += A[j][k]
        flag = True
        for k in range(1,m+1):
            if arg[k]<x:
                flag = False
                break
        if flag:
            ans = min(ans,cost)
    if ans==10**9:
        print('-1')
    else:
        print(ans)
main()

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

// #define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pii pair<int,int>
#define e "\n"

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

    
void solve()
{
	int n;
	cin>>n;
	string str;
	unordered_set<string> s;
	while(n--)
	{
			cin>>str;
			if(s.find(str)==s.end())
			s.insert(str);
	}
	cout<<s.size()<<e;
	s.clear();
}
int main()
{
	//c_p_c();
	// int t;cin>>t;
	// while(t--)
		solve();
	
}

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

//ll calc( ll a ) {
//    if ( a <= 0 ) return 0;
//    ++a;
//
//    ll ans = 0;
//    rep(i, 50) {
//        ll loop = (1LL << (i + 1));
//        ll cnt = ( a / loop ) * ( loop / 2 );
//        cnt += max(0LL, ( a % loop ) * ( loop / 2 ) );
//
//        if ( cnt % 2 == 1 ) {
//            ans += 1LL << i;
//        }
//    }
//    return ans;
//}
long long calc(long long A) {
 
	if (A <= 0) return 0;
 
	//4の時に、0,1,2,3,4までになるので、これは5つの整数まで
	//なので帳尻合わせで１足してあげる。
	A++;
	//10^3 <= 2^10
	//1000 <= 1024
	//10^12 <= 2^40
	//10^12 <= 2進数 40桁くらい
 
	long long ans = 0;
	//i桁目の偶奇を調べる
	for (int i = 0; i < 50; i++)
	{
		//0桁目 → 周期2
		//1				4
		//2				8
		long long loop = (1LL << (i + 1));
		long long cnt = (A / loop) * (loop / 2);
		//00000.....0011111.....11
		cnt += max(0LL, (A % loop) - (loop / 2));
 
		//その桁の1の数が奇数だったら足し算
		if (cnt % 2 == 1) {
			ans += 1LL << i;
		}
	}
 
	return ans;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = calc(b) ^ calc(a-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int N;

struct Matrix{ int R, W; };
Matrix M[MAX_N];

int mem[MAX_L][MAX_L];
Matrix memM[MAX_L][MAX_L];


void eval(Matrix M[], int s, int e){

	if (s == e){
		mem[s][e] = 0;
		memM[s][e] = M[s];
		return;
	}

	int minval = 1000000000;
	for (int mid = s; mid < e; mid++){
		Matrix m1 = memM[s][mid];
		Matrix m2 = memM[mid+1][e];
		int val = mem[s][mid] + mem[mid+1][e] + (m1.W * m1.R * m2.W);
		
		if (val < minval){
			minval = val;
			mem[s][e] = val;
			Matrix m; m.R = m1.R; m.W = m2.W;
			memM[s][e] = m;
		}
	}

}

int solve(Matrix M[], int N){

	for (int d = 0; d <= N; d++)
		for (int s = 0; s + d <= N; s++)
		{
			eval(M, s, s + d);
		}

	return mem[0][N - 1];
}

int main() {

	cin >> N;
	rep(i, N){
		Matrix m;
		cin >> m.R;
		cin >> m.W;
		M[i] = m;
	}

	cout << solve(M, N) << endl;

#ifdef DEBUGRUN
	rep (i, N){
		rep(j, N){
			cerr << mem[i][j] << ' ';
		}
		cerr << endl;
	}
#endif

}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

#define pt pair<long long, long long>
#define x first
#define y second

int n;
pt p[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y;

    return true;
}

long long cross(const pt& a, const pt& b) {
    return a.x * b.y - a.y * b.x;
}

void solve() {
    sort(p, p + n, [] (const pt& a, const pt& b) {
        return atan2(a.y, a.x) < atan2(b.y, b.x);
    });

    auto ans = 0ll;

    for (int l = 0; l < n; ++l) {
        pt cur = { 0ll, 0ll };

        for (int len = 1; len <= n; ++len) {
            cur.x += p[(l + len - 1) % n].x;
            cur.y += p[(l + len - 1) % n].y;
            ans = max(ans, cur.x * cur.x + cur.y * cur.y);
        }
    }

    cout << setprecision(15) << fixed << sqrtl(static_cast<long double>(ans)) << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();
 
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

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

	vector<int> vec(N-1);
	vector<int> count(N);
	count[0] = 0;
	for (int i = 0; i < N-1; i++) {
		cin >> vec.at(i);
		count[i+1] = 0;
	}

	for (int i = 0; i < N - 1; i++) {
		count[vec[i]-1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << count[i] << endl;
	}

}


Measured memory_bytes: 4844
import sys

def kth(ed, erase, k):
  if (k < erase):
    return k
  return k + 1

def ck(a, b, x):
  c = x
  if a <= x:
    c += 1
  d = x
  if b <= x:
    d += 1
  if x % 2 == 1:
    m = (x + 1) / 2
    return kth(c, a, m) * kth(d, b, m) < a * b
  else:
    m0 = x / 2
    m1 = x / 2 + 1
    return kth(c, a, m0) * kth(d, b, m1) < a * b and kth(c, a, m1) * kth(d, b, m0) < a * b

T = int(raw_input())
while T > 0:
  a, b = map(int, raw_input().split())
  l = 0
  r = a * b
  while r - l > 1:
    m = (l + r) / 2
    if ck(a, b, m):
      l = m
    else:
      r = m
  if ck(a, b, r):
    print r
  else:
    print l
  T -= 1

Measured memory_bytes: 2696
#include <iostream>
using namespace std;
int main(){
  int x,y,s,i,j,max,s1,s2,sum,c;
  while(1){
    max=0;
    cin >> x >> y >> s;
    if(x==0&&y==0&&s==0) break;
    /*    for(i=1;i<s;i++){
	  s1=i*(100+x)/100;
	  cout << "s1 " << s1 << endl;
	  cout << "s2 " << s2 << endl;
	  cout << "s1+s2 " << s1+s2 << endl;
      
	  }*/
    for(i=1;i<s;i++){
      s1=i*(100+x)/100;
      for(j=1;j<s;j++){
	s2=j*(100+x)/100;
	if(s1+s2==s){
	  sum=i*(100+y)/100+j*(100+y)/100;
	  if(sum>max) max=sum;  
	}
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int r,c;
int a[20][10010];
int cmax=0;
void solve(int rr){
	if( rr == 0 ){
        int sum=0;
		for(int i=0;i<c;i++){
            int count=0;
			for(int j=0;j<r;j++)
				if( a[j][i] )
					count++;
            sum += count > r / 2 ? count : r - count;
        }
		cmax = max(sum , cmax);
		return;
	}
	solve(rr - 1);                                  //?????£???????????????
	for(int i = 0;i < c;i++)
		a[rr][i] = a[rr][i] ? false : true;
	solve(rr - 1);
    for(int i = 0;i < c;i++)
		a[rr][i] = a[rr][i] ? false : true;
}
int main(){
	while(cin >> r >> c , r){
		cmax=0;
		for(int i=0;i<r;i++)
			for(int j=0;j<c;j++)
				cin >> a[i][j];
		solve(r);
		cout << cmax << endl;
	}
	return 0;
}

Measured memory_bytes: 3452
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 1100;

ll n,a,b,c,d,u;

int main()
{
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	u=b-a; n--;
	ll l=0,r=0,L=c*n,R=d*n;
	for(int i=n;i>=0;i--)
	{
		if(L+l<=u&&u<=R+r) { puts("YES");return 0; }
		L-=c,R-=d;
		l-=d,r-=c;
	}
	puts("NO");
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int c[3];
	while(cin>>c[0]>>c[1]>>c[2]){
		int count=0;
		for(int i=1;i<=10;i++){
			if(i==c[0] || i==c[1] || i==c[2]) continue;
			else if(c[0]+c[1]+i<=20) count++;
		}
		if(count>=4) cout<<"YES"<<endl;
		else if(count<4) cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N, M;
  ll sign[2] = {1, -1};
  cin >> N >> M;
  ll x[N], y[N], z[N], sum[N];
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = 0;
  for(int i = 0; i < 2; i++){
    for(int j = 0; j < 2; j++){
      for(int k = 0; k < 2; k++){
        for(int m = 0; m < N; m++){
          sum[m] = sign[i]*x[m] + sign[j]*y[m] + sign[k]*z[m];
        }
        sort(sum, sum + N, greater<ll>());
        ll p = 0;
        for(int m = 0; m < M; m++) p += sum[m];
        ans = max(ans, p);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			if(i==s.length()-1) {
				if(s.charAt(i)=='A') list.add(1);
				else list.add(-1);
			}else{
				if(s.charAt(i)=='A') list.add(1);
				else if(s.charAt(i)=='B'&&s.charAt(i+1)=='C') {
					list.add(0);
					i++;
				}
				else list.add(-1);
			}
		}
		int[] bit = new int[list.size()+1];
		int begin_idx = -1;
		long ans = 0;
		for(int i=0;i<list.size();i++) {
			if(list.get(i)==1) add(bit,i+1,1);
			else if(list.get(i)==0) {
				if(begin_idx==-1) ans += sum(bit,i+1);
				else {
					ans += sum(bit,i+1) - sum(bit,begin_idx+1);
				}
			}
			else if(list.get(i)==-1) begin_idx = i;
		}
		System.out.println(ans);
		
		in.close();
	}
	
	//add value at idx on bit O(logN)
	public static void add(int[] bit,int idx,int value) {
		for(int i=idx;i<bit.length;i+=(i&-i)) bit[i] += value;
	}
	
	//return sum [1,idx] O(logN)
	public static int sum(int[] bit,int idx) {
		int ret = 0;
		for(int i=idx;i>0;i-=(i&-i)) ret += bit[i];
		return ret;
	}

}


Measured memory_bytes: 31968
while True:
  s = input()
  if s == "END OF INPUT":
    break
  lst = []
  ind = 0
  count = 0
  while ind < len(s):
    if s[ind] == " ":
      lst.append(count)
      count = 0
    else:
      count += 1
    ind += 1
  lst.append(count)
  print(*lst,sep="")


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int a, b, c; cin >> a >> b >> c;
  cout << a * b / 2 << endl;

  return 0;
}




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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    bool result = false;
    for(int i=0; i<=k; i++) {
        for(int j=0; j<=k; j++) {
            int tmp_b =b;
            int tmp_c =c;
            for (int B=0; B<i; B++) tmp_b *= 2;
            for (int C=0; C<j; C++) tmp_c *= 2;        
            if (((i+j) <= k) && (a < tmp_b) && (tmp_b < tmp_c)) result = true;
        }
    }

    if (result == true) cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;
}


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

using namespace std;

long sums(long p){
  int sum=0;
  while(p!=0){
    sum += p%10;
    p/=10;
  }
  return sum;
}

int main(int argc,char* argv[]){
  long N;
  cin >> N;
  if(N%sums(N)==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<climits>
#define min(a,b) ((a)<(b)? (a):(b))
#define max(a,b) ((a)>(b)? (a):(b))
typedef long long ll;
ll p[5005],c[5005],sum[5005];
inline int read() {
    register int x=0,f=1;register char s=getchar();
    while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
    while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
    return x*f;
}
int main() {
    int n=read(),k=read();ll ans=LLONG_MIN;
    for(register int i=1;i<=n;++i) p[i]=read();
    for(register int i=1;i<=n;++i) c[i]=read();
    for(register int i=1;i<=n;++i) {
        int x=i,f=0,len=0; ll res=0;
        while(x!=i||!f) {f=1;x=p[x];sum[len+1]=sum[len]+c[x];++len;}
        if(sum[len]>=0) {
            res+=(sum[len])*(k/len-1);
            for(register int i=1;i<=len;++i) ans=max(ans,res+sum[i]);
            res+=sum[len];
            for(register int i=1;i<=k%len;++i) ans=max(ans,res+sum[i]);
        }
        else {
            for(register int i=1;i<=min(len,k);++i) ans=max(ans,sum[i]);
        } 
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1700
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 7*17*(1<<23) + 1;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
vector<int> a[331];
int main() { //DINIC ORZ, FFT ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i <n ;i++) {
		a[i].resize(m);
		for(auto &j : a[i]) cin >> j, j--;
		reverse(all(a[i]));
	}
	int ans = n;
	bool cont = true;
	vi cnt;
	bitset<2000> rem;
	while(cont) {
		int cur = 0, x = 0;
		cnt.assign(m, 0);
		for(int i = 0; i < n; i++) {
			if(++cnt[a[i].back()] > cur) {
				cur = cnt[a[i].back()];
				x = a[i].back();
			}
		}
		rem.set(x);
		ans = min(ans, cur);
		for(int i = 0; i < n; i++) {
			while(!a[i].empty()&&rem[a[i].back()]) a[i].pop_back();
			cont &= !a[i].empty();
		}
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 100010

vector<pair<int, int> > adj[SIZE];
ll num[SIZE], n, sum = 0, e;

void dfs (int v, int p, int c) {
   num[v] = 1;
   for (int i = 0 ; i < adj[v].size() ; ++i) {
      int t = adj[v][i].X, w = adj[v][i].Y;
      if (t == p) continue;
      dfs (t, v, w);
      num[v] += num[t];
   }
   if (num[v] <= n - num[v]) sum += 2ll * num[v] * c; 
   else sum += 2ll * (n - num[v]) * c;
}

int centroid (int v, int p) {
   int u = -1;
   for (int i = 0 ; i < adj[v].size() ; ++i) {
      int t = adj[v][i].X;
      if (t == p) continue;
      if (num[t] >  n / 2) {
         u = t;
         break;
      }
   }
   if (u != -1) return centroid (u, v);
   return v;
}

int main() {
   cin >> n;
   for (int i = 1 ; i < n ; ++i) {
      int u, v, c;
      cin >> u >> v >> c;
      adj[u].PB(MP(v, c)); adj[v].PB(MP(u, c));
   }
   dfs (1, 1, 0);
   int cent = centroid (1, 1), mn = INF;
   for (int i = 0 ; i < adj[cent].size() ; ++i) {
      int t = adj[cent][i].X, w = adj[cent][i].Y;
      mn = min (mn, w);
      if (n % 2 == 0 && n / 2 == num[t]) {
         cout << sum - 1ll * w << endl;
         return 0;
      }
   }
   cout << sum - 1ll * mn << endl;
   return 0;
}

Measured memory_bytes: 13184
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = IntArray(n) { sc.nextInt() }

    val ret = a
        .fold(mutableMapOf<Int, Int>()) { acc, v ->
            val prev = acc.get(v) ?: 0
            acc[v] = prev + 1
            acc
        }
        .map { entry ->
            val k = entry.key
            val v = entry.value
            if (k > v) v else v - k
        }
        .sum()

    println(ret)
}

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

int main() {
  string S;
  ll K;
  cin >> S >> K;
  for (int i = 0; i < min((ll)S.size(), K); i++) {
    if (S[i] != '1') {
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << '1' << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
abs_min = abs(A[0])
sum_abs = 0
cnt = 0
for x in A:
    abs_min = min(abs_min,abs(x))
    sum_abs += abs(x)
    if x < 0:
        cnt += 1
print(sum_abs if cnt%2 == 0 else sum_abs-2*abs_min)

Measured memory_bytes: 14284
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(s:#));
    let mut old = ' ';
    let mut res = 0;
    for c in s.chars() {
        if c != old {
            old = c;
            res += 1;
        }
    }
    res.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "10\naabbbbaaca\n" => "5\n",
    test2: "5\naaaaa\n" => "1\n",
    test3: "20\nxxzaffeeeeddfkkkkllq\n" => "10\n",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
#define pi 3.1415926535897
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n; cin >> n;
	string s;
	int a = 0, b = 0, c = 0, d = 0;
	rep(i, n){
		cin >> s;
		if(s == "AC") a++;
		if(s == "WA") b++;
		if(s == "TLE") c++;
		if(s == "RE") d++;
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	string S;
	cin >> S;
	int cnt[4] = { 0 };
	REP(i, S.size()) {
		if (S[i] == 'N')cnt[0] = 1;
		if (S[i] == 'S')cnt[1] = 1;
		if (S[i] == 'W')cnt[2] = 1;
		if (S[i] == 'E')cnt[3] = 1;
	}
	//REP(i, 4)cout << cnt[i] << endl;
	if (cnt[0] == cnt[1] && cnt[2] == cnt[3]) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}



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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

long long arr[200005];
int cur[20];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n; cin >> n;

    // a + b - 2 * (a & b) = a ^ b
    // therefore a & b == 0 for this to work

    for(int i = 0; i < n; ++i)
        cin >> arr[i];

    int l = 0, r = 0;
    long long tot = 0;

    for(int pos = 0; pos < 20; ++pos)
        if(((arr[r] >> pos) & 1) == 1)
            ++cur[pos];

    while(l < n){

        bool f = true;
        for(int pos = 0; pos < 20 && f; ++pos)
            if(cur[pos] > 1)
                f = false;

        if(r < n && f){
            //cout << "works " << l << " " << r << endl;
            ++r;
            for(int pos = 0; r < n && pos < 20; ++pos)
                if(((arr[r] >> pos) & 1) == 1)
                    ++cur[pos];
        } else {
            //cout << "ree " << l << " " << r << endl;
            for(int pos = 0; pos < 20; ++pos)
                if(((arr[l] >> pos) & 1) == 1)
                    --cur[pos];
            tot += r - l;
            ++l;
        }
    }

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 1792
import java.util.*;

class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String args[]){
    int m = sc.nextInt();
    int d = sc.nextInt();
    int sum = 0;
    for(int i=4;i<=m;i++){
      for(int j=22;j<=d;j++){
        if((j%10)>=2&&(j%10)*(j/10)==i){
          sum++;
        }
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 24276
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
//typedef complex<double>P;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑



ll n, k[200005], ans[200005];
vector<int>v;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> k[i];
	}

	for (int i = n; i > 0; --i) {
		ll mon = 0;
		for (int j = 2 * i; j <= n; j += i) { mon += ans[j]; }
		if (mon % 2 != k[i]) {
			ans[i] = 1;
		}
	}

	for (int i = 1; i <= n; ++i) {
		if (ans[i]) { v.push_back(i); }
	}
	cout << v.size() << endl;
	for (auto i : v) { cout << i << " "; }
	cout << endl;
}

Measured memory_bytes: 5496
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <bitset>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <deque>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef pair<int, int> P;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};


int n;
int a[5005] = { 0 };
int b[5005] = { 0 };
int res = INF;


int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	for (int i = 0; i <= 3; i++) {
		int sum = 0;
		for (int i = 0; i < n; i++) b[i] = a[i];
		sum += i;
		b[0] -= i;
		for (int i = 0; i < n - 1; i++) {
			if (b[i] > 0) {
				sum += b[i] * 2;
				b[i + 1] -= b[i];
			}
		}
		if (b[n - 1] > 0) sum += b[n - 1];
		//out(sum);
		res = min(res, sum);
	}
	out(res);
	return 0;
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

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

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

bool isok(const vector<i64> &ws, int k, i64 upper) {
    int j   = 0;
    int len = ws.size();
    bool ok = false;
    rep(i, 0, k) {
        i64 sum = 0;
        while (sum + ws[j] <= upper && j < len) {
            sum += ws[j];
            j++;
            // 上限を超えることなくn個の荷物を割り当てられた
            if (j == len) ok = true;
        }
    }
    return ok;
}

signed main() {
    int N, K;
    cin >> N >> K;
    vector<i64> ws(N);
    rep(i, 0, N) {
        i64 w;
        cin >> w;
        ws[i] = w;
    }

    i64 ng = -1, ok = 1e10;
    while (abs(ok - ng) > 1) {
        auto mid = (ok + ng) / 2;
        if (isok(ws, K, mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";
}



Measured memory_bytes: 3528