akhauriyash/Code-Regression huggingface dataset:
def solve(string):
    n, s = string.split()
    n = int(n)
    es = {i for i, _s in enumerate(s) if _s == "E"}
    num_e = len(es)
    num_w = n - num_e
    count_e = 0
    count_w = 0

    ans = n
    for i, _s in enumerate(s):
        tmp = [count_e, count_w]
        if i in es:
            count_e += 1
        else:
            count_w += 1
        tmp += [num_e - count_e, num_w - count_w]
        ans = min(ans, tmp[1] + tmp[2])
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		long s[] = new long[n];
		s[0] = a[0];

		for (int i = 1; i < n; i++) {
			s[i] = s[i - 1] + a[i];
		}

		long ans = Long.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			ans = Math.min(ans, Math.abs((s[n - 1] - s[i]) - s[i]));
		}

		System.out.println(ans);
	}
}

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

int main() {
  int N;cin>>N;
  int M=N;
  int S = 0;
  while(M>0){
    S += M%10;
    M=M/10;
  }
  if(N%S==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
#define CAT(a,b)a b
#define VASIZE(a,b,N,...)N
template<class T>auto size(T&&a)->decltype(a.size(), int()) { return a.size(); }
template<class T, class = enable_if_t<is_integral<T>::value, T>>int size(T a) { return a; }
#define REP(t,a,N)for(int t=size(a),_l##t=size(N);t<_l##t;t++)
#define RREP(t,a,N)for(int t=size(N)-1,_l##t=size(a);t>=_l##t;t--)
#define rep(t,...)CAT(REP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define rrep(t,...)CAT(RREP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define all(a)(a).begin(),(a).end()
typedef long long ll;
typedef unsigned long long ull;
void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

void Calc() {
  int n = in;
  auto l = in.Array(n * 2);
  err(l);
  sort(all(l));
  int sum = 0;
  rep(i, n * 2) {
    sum += min(l[i], l[i + 1]);
    i++;
  }
  cout << (sum) << endl;
}


Measured memory_bytes: 256
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
ans=0
s.sort()
for i in range(n):
    for j in range(q):
        if s[i]==s[i-1]:
            continue
        else:
            if s[i]==t[j]:
                ans+=1

print(ans)


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const int N = 1e5 + 4;
vector<int> g[N];

int memo[N];
int rec (int curr)
{
  int& ret = memo[curr];
  if (ret != -1) return ret;

  int mx = 0;
  each (next, g[curr]) {
    setmax(mx, rec(next) + 1);
  }

  return ret = mx;
}

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

  int n, m;
  while (cin >> n >> m) {
    fill(g, g + N, vector<int>());
    fill(memo, memo + N, -1);
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      g[a].push_back(b);
    }

    int mx = 0;
    for (int i = 0; i < n; ++i) {
      setmax(mx, rec(i));
    }
    cout << mx << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8192
N=int(input())
if N==3:
  print(2,5,63)
  exit()
P=[]
X=[]
if N&1:
  X=[6,2,10,3,9,4,8,12]
else:
  X=[2,10,3,9,4,8,6,12]
for i in range(N):
  P.append(X[i%8]+12*(i//8))
print(*P)

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

int main(){
  int c[10][10]={};
  int N;
  cin >> N;
  for(int i=1; i<=N; i++){
    string s=to_string(i);
    c[s[0]-'0'][s[s.size()-1]-'0']++;
  }
  long ans=0;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      ans += c[i][j]*c[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

int main() {
	int N, M;
    cin >> N >> M;
    vector<pair<int,bool> > boxes(N, mp(1, false));
    boxes[0].second = true;

    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x, --y;

        boxes[x].first--;
        boxes[y].first++;
        if(boxes[x].second)
            boxes[y].second = true;

        if(boxes[x].first == 0)
            boxes[x].second = false;
    }

    int ans =0 ;
    rep(i, N) {
        if(boxes[i].first > 0 && boxes[i].second)
            ans++;
    }
    cout << ans << endl;
	
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <cmath>
#define PI acos(-1)
typedef long long ll;
const long long mod = 998244353;
const long long maxn = 1e7 + 5; 
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int main()
{
	int k;
	string s;
	cin >> k; 
	cin >> s;
	if (s.size() > k)
	{
		for (int i = 0; i < k; i++)
			printf("%c",s[i]);
		printf("...\n");
	}
	else
	{
	 	for (int i = 0; i < s.size(); i++)
			printf("%c",s[i]);
	} 

	return 0;
}

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

using namespace std;

int main()
{
    string s, t;
    cin>>s>>t;
    int a ,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s==u)
        cout<<a-1<<" "<<b;
    else
        cout<<a<<" "<<b-1;

    return 0;
}


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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  int ans=0;
  for(int a=A>=C?A+1:A;a<=B;a++){
    for(int b=C>=A?C+1:C;b<=D;b++){
      //if((a<=b&&a!=C)||(a>=b&&b!=A)){
        if(a==b)ans++;
      //}
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=1;i<n+1;i++)
	cin>>a[i];
	vector<int> dp(n+1,0);
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(ll i=3;i<=n;i++)
	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
    unsigned char conv[256];
    int n;
    int i;
    unsigned char b[10], a[10];
    int m;
    char in[10];
    
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        for (i = 0; i < 256; i++){
            conv[i] = i;
        }
        for (i = 0; i < n; i++){
            scanf("%s%s", b, a);
            
            conv[b[0]] = a[0];
        }
        
        scanf("%d", &n);
        for (i = 0; i < n; i++){
            scanf("%s", in);
            
            printf("%c", conv[in[0]]);
        }
        printf("\n");
    }
    return (0);
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

const double eps = 1e-8;
const double pi = acos(-1);
double cot(double ang){return 1.0 / tan(ang);}
double a, b, x;

bool check(double mid)
{
    double ang = mid * pi / 180;
    double V;
    if(ang < atan(a/b))
    {
        V = b * (b * tan(ang)) * 0.5 * a;
        //cout << "up " << mid << " " << V << endl;
    }
    else
    {
        V = (a * b - a * (a * tan(pi / 2 - ang)) * 0.5) * a;
        //cout << "ang = " << ang << endl;
        //cout << "down " << a*b << " " << a * (a * cot(ang)) * 0.5 << " " << mid << " " << V << endl;
    }

    if(V>x) return 1;
    return 0;
}

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> a >> b >> x;
    double lo = 0.0;
    double hi = 90.0;
    while(lo+eps<hi)
    {
        double mid = (lo+hi)/2;
        if(check(mid)) hi = mid;
        else lo = mid;
    }
    cout << fixed << setprecision(8) << 90.0-lo << endl;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    vector<int> cnt(3);
    cin >> n;
    string ans = "No";
    for(int i = 0;i < n;i ++){
        int a;
        cin >> a;
        if(a%4==0) cnt[2] ++;
        else if(a%2==0) cnt[1] ++;
        else cnt[0] ++;
    }
    if(cnt[2]>=cnt[0]||(cnt[1]==0&&cnt[2]>=cnt[0]-1)) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt(), x = scanner.nextInt();
        long l = scanner.nextInt(), ans = l > x ? l - x : 0;
        l -= ans;
        for (int i = 1, t; i < n; i++)
            ans += (t = scanner.nextInt()) - (l = Math.min(x - l, t));
        System.out.println(ans);
    }
}

Measured memory_bytes: 48588
#include<iostream>
int main()
{
	using namespace std;
	const int MAX=1000;
	int n,A[MAX],i,j,pos,item;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>A[i];
	for(i=0;i<n;i++)
		if(i<n-1)
			cout<<A[i]<<' ';
		else
			cout<<A[i];
	cout<<endl;
	for(i=1;i<n;i++)
	{
		item=A[i];
		pos=i-1;
		while(pos>=0&&A[pos]>item)
		{
			A[pos+1]=A[pos];
			pos--;
		}
		A[pos+1]=item;
		for(j=0;j<n;j++)
			if(j<n-1)
				cout<<A[j]<<' ';
			else
				cout<<A[j];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int main(void) {
	int N, K;
	scanf("%d %d", &N, &K);
	long long ans = K;
	for (int i = 1; i < N; i++) {
		ans *= K - 1;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3820
#include<stdio.h>
#include <stdlib.h>
#define	AREA(x1,y1,x2,y2,x3,y3) fabs(((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2)
main(){
  double x1,y1,x2,y2,x3,y3,xp,yp;
  double area,a_area,b_area,c_area;
  while(~scanf("%lf%lf %lf%lf %lf%lf %lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)){
    area=AREA(x1,y1,x2,y2,x3,y3);
    a_area=AREA(xp,yp,x1,y1,x2,y2);
    b_area=AREA(xp,yp,x2,y2,x3,y3);
    c_area=AREA(xp,yp,x3,y3,x1,y1);
    if(area==a_area+b_area+c_area)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct node{
	int k, p, sz;
	node * l;
	node * r;
	node(int k): k(k), p(rand()), l(NULL), r(NULL), sz(0){}
};
int sz(node *t){
	if(t == NULL) return 0;
	return t->sz;
}
void updsz(node *t){
	if(t == NULL) return;
	t->sz = sz(t->l)+sz(t->r)+1;
}
void split(node *t, node*& l, node*& r, int k){
	if(t == NULL){
		l = r = NULL;
	} else if(k <= t->k){
		split(t->l,l,t->l,k);
		r = t;
	} else {
		split(t->r,t->r,r,k);
		l = t;
	}
	updsz(t);
}
void merge(node *&t, node *l, node *r){
	if(l == NULL){
		t = r;
	} else if(r == NULL){
		t = l;
	} else if(l->p <= r->p){
		merge(l->r,l->r,r);
		t = l;
	} else {
		merge(r->l,l,r->l);
		t = r;
	}
	updsz(t);
}
void ins(node *&t, node *c){
	if(t == NULL){
		t = c;
	} else if(c->p >= t->p){
		split(t,c->l,c->r,c->k);
		t = c;
	} else if(c->k <= t->k){
		ins(t->l,c);
	} else {
		ins(t->r,c);
	}
	updsz(t);
}
void del(int k, node *&t){
	if(t->k == k){
		merge(t,t->l,t->r);
	} else if(t->k > k){
		del(k,t->l);
	} else {
		del(k,t->r);
	}
	updsz(t);
}
node* find(node *t, int k){
	if(t == NULL) return t;
	if(t->k == k) return t;
	if(t-> k < k){
		return find(t->r,k);
	} else {
		return find(t->l,k);
	}
}
int cnt(node *t, int k){ // <= k
	if(t == NULL) return 0;
	if(t->k <= k){
		return 1 + sz(t->l) + cnt(t->r,k);
	} else {
		return cnt(t->l,k);
	}
}
void pt(node *r){
	if(r == NULL) return;
	cout << r->k << " " << r->p << " " << r->sz << endl;
	pt(r->l);
	pt(r->r);
}

node* kth(node *t, int k){ // 0-based indexing
	if(k == sz(t->l)){
		return t;
	} else if(k < sz(t->l)){
		return kth(t->l,k);
	} else {
		return kth(t->r, k-1-sz(t->l));
	}
}



LL inv(vector<int> a){
	node * treap = NULL;
	LL ans = 0;
	for(int i = 0; i < a.size(); i++){
		node * t1, * t2, *t3;
		split(treap, t1, t2, a[i]);
		ans += sz(t2);
		node * cur = new node(a[i]);
		merge(t3, t1, cur);
		merge(treap, t3, t2);
	}
	return ans % 2;
}
int main(){
	int n;
	cin >> n;
	int a[3][n];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	int ok = 1;
	vector<int> b;
	int neg[2];
	neg[0] = neg[1] = 0;
	for(int j = 0; j < n; j++){
		if(abs(a[0][j] - a[1][j]) > 1) ok = 0;
		if(abs(a[2][j] - a[1][j]) > 1) ok = 0;
		int t = a[0][j] < a[1][j];
		b.push_back((a[1][j] + 1)/3);
		if(!t) neg[j%2]++;
	}
	for(int j = 0; j < n; j++){
		if(b[j] % 2 == j%2) ok = 0;
	}
	if(!ok){
		cout << "No" << endl;
		return 0;
	}
	vector<int> e[2];
	for(int i = 0; i < n; i++){
		e[i%2].push_back(b[i]);
	}
	if(inv(e[0]) % 2 != neg[1] % 2) ok = 0;
	if(inv(e[1]) % 2 != neg[0] % 2) ok = 0;
	if(!ok){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 7032
N, x = map(int, input().split())
L = list(map(int, input().split()))
l = sorted(L)
c = 0
if sum(L) < x:
  print(len(l)-1)
else:
  for i in range(N):
    if x < l[i]:
      break
    x = x - l[i]
    c += 1
    
  print(c)

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<int> a(100001);
    for(int i = 0;i < n;i ++){
        int b;
        cin >> b;
        a.at(b) ++;
    }

    int ans = 0;
    for(int i = 0;i < 100001;i ++){
        if(a.at(i) > 0) ans ++;
    }

    int c = 0;
    for(int i = 0;i < 100001;i ++){
        if(a.at(i) > 0){
            c += a.at(i)-1;
        }
    }

    if(c % 2 == 1) ans --;

    cout << ans << endl;
}

Measured memory_bytes: 1024
require 'pp'

def gets; ARGF.gets; end

def main
  n, x = gets.split.map(&:to_i)
  nums = Array.new(n)
  min_n = 1 << 30
  sum_n = 0
  n.times do |i|
    nums[i] = gets.chomp.to_i
    sum_n += nums[i]
    min_n = nums[i] if nums[i] < min_n
  end

  rest_x = x - sum_n
  ans = nums.length

  ans += rest_x / min_n

  puts ans
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int tmp[8][8]={
    {1,2,1,2,1,4,1,4},
    {1,2,1,4,1,4,1,2},
    {1,4,1,2,1,2,1,4},
    {1,4,1,4,1,2,1,2},
    {2,1,2,1,4,1,4,1},
    {2,1,4,1,4,1,2,1},
    {4,1,2,1,2,1,4,1},
    {4,1,4,1,2,1,2,1},
  };
  int in[8];
  while(cin>>in[0]){
    rep(i,7)cin>>in[i+1];
    int ans=0;
    int ans1;  
    rep(i,8){
      int co=0;
      rep(j,8)
	if(tmp[i][j]<=in[j])co+=tmp[i][j];
	else co+=in[j];
      if(ans<co){ans1=i;ans=co;}
    }
    rep(i,7)cout<<tmp[ans1][i]<<" ";
    cout<<tmp[ans1][7]<<endl;
  }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w, k;
  cin >> h >> w >> k;

  vector<string> c(h);
  for (int i = 0; i < h; ++i) {
    cin >> c[i];
  }

  int ans = 0;
  for (int bit_y = 0; bit_y < (1 << h); ++bit_y) {
    for (int bit_x = 0; bit_x < (1 << w); ++bit_x) {
      int b_cnt = 0;
      for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
          bool y_sel = bit_y & (1 << i);
          bool x_sel = bit_x & (1 << j);
          if (y_sel || x_sel || c[i][j] == '.') {
            continue;
          }

          b_cnt++;
        }
      }

      if (b_cnt == k) {
        ans++;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#include<vector>
#define N 201
vector<int>G[N];
int n,m,low[N],dfn[N];
bool is_cut[N];
int father[N];
int tim=0;
int a,b;
void input()
{
    scanf("%d%d",&n,&m);
    int a,b;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
}
void Tarjan(int i,int Father)
{
    father[i]=Father;
    dfn[i]=low[i]=tim++;
    for(int j=0;j<G[i].size();++j)
    {
        int k=G[i][j];
        if(dfn[k]==-1)
        {
            Tarjan(k,i);
            low[i]=min(low[i],low[k]);
        }
        else if(Father!=k)
            low[i]=min(low[i],dfn[k]);
    }
}
void count()
{
    int rootson=0;
    Tarjan(1,0);
    for(int i=2;i<=n;++i)
    {
        int v=father[i];
        if(v==1)
        rootson++;
        else{
            if(low[i]>=dfn[v])
            is_cut[v]=true;
        }
    }
    if(rootson>1)
    is_cut[1]=true;
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        int v=father[i];
        if(v>0&&low[i]>dfn[v])
        ans++;
    }
    printf("%d\n",ans);
}
int main()
{

    while(scanf("%d%d",&n,&m)==2){
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(dfn,-1,sizeof(dfn));
    memset(father,0,sizeof(father));
    memset(low,-1,sizeof(low));
    memset(is_cut,false,sizeof(is_cut));
    count();
    }
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    A_list = [int(i) for i in input().strip().split()]
    Q = int(input().strip())
    _sum = sum(A_list)
    num_count = Counter(A_list)
    for _ in range(Q):
        B, C = [int(i) for i in input().strip().split()]
        if B in num_count:
            if C in num_count:
                num_count[C] = num_count[C] + num_count[B]
            else:
                num_count[C] = num_count[B]

            _sum = _sum - (num_count[B] * B) + num_count[B] * C
            del num_count[B]
            print(_sum)
        else:
            print(_sum)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21348
#include <iostream>
#include <queue>
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main() {
    int K;
    cin >> K;
    queue<long long> q;
    for (int i = 1; i < 10; i++) {
        q.push(i);
    }
    long long v = 0;
    rep(i, K) {
        v = q.front(); q.pop();
        long long mod10 = v % 10;
        if (mod10 != 0) q.push(v * 10 + mod10 - 1);
        q.push(v * 10 + mod10);
        if (mod10 != 9) q.push(v * 10 + mod10 + 1);
    }
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, N;
    cin >> H >> N;
    ll A[N];
    ll sum = 0;
    REP(i, 0, N) {
        cin >> A[i];
        sum += A[i];
    }
    if (sum >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1024
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {

        int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(a.Max() - a.Min());
    }
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

string S;

int main(){
    cin >> S;

    int ans = S.size();
    for(int i = 1; i < S.size(); i++){
        if(S[i - 1] == S[i]){
            ans--;
            i += 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#include <math.h>
int main(){
	int n=0;
	while(cin>>n && n!=0){
		double x[300]={},y[300]={};
		int ans=1;
		for(int i=0;i<n;i++){
			cin>>x[i]>>y[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j){
					double dx=x[i]-x[j],dy=y[i]-y[j];
					double dd=dx*dx+dy*dy;
					if(dd<4.0){
						double h=pow(1.0-dd/4.0,1.0/2.0),d=pow(dd,1.0/2.0);
						double px=(x[i]+x[j])/2.0+h*dy/d,py=(y[i]+y[j])/2.0-h*dx/d;
						int a=0;
						for(int k=0;k<n;k++){
							if((x[k]-px)*(x[k]-px)+(y[k]-py)*(y[k]-py)<1.0001) a++;
						}
						if(a>ans)ans=a;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

using ll = long long;
int main() {
  ll n; cin >> n;
  string ans;
  while (n > 0) {
    ans += 'a'+(n-1)%26;
    n = (n-1)/26;
  }
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[ans.size()-1-i];
  }
  cout << endl;
}



Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  int a[100];
  cin >> n >> m;

  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  sort(a, a+n);

  int got = 0;
  for(int  i = n - 1; i >= 0; i--) {
    if (4 * m * a[i] < sum) {
      break;
    }
    got++;
    if (got == m){
      break;
    }
  }
  if (got == m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include <cstdlib>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 0;
    int siz;
    string s;
    cin >> s;
    siz = s.size();
    vector<int> dp(siz+1);
    //累積和で初期化。右端までの余りが0のものを考慮する必要がある。
    dp[siz] = 0;
    int tmp = 1;
    REPR(i, siz){//i桁目から右の2019で割った余りの2019で割った余り
        dp[i] = (dp[i+1] + (int)(s[i] - '0')*tmp)%2019;
        tmp *= 10; 
        tmp %= 2019;
    }
    
    vector<int> cnt(2019, 0);
    REP(i, siz+1){//i桁目から右の2019で割った余りを2019個のバケツに放り込んでいく。一致したらansを足す。
        ans += cnt[dp[i]];
        cnt[dp[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4312
// (r,g,b)の組み合わせの数は(rの個数)×(gの個数)×(bの個数)
// そのうち、j-i==k-jを満たすものを探し、p個あるとする。
// 答えは、(rの個数)×(gの個数)×(bの個数) - p
// pの求め方は、j-i==k-jを満たす(i,j,k)をO(N^2)で全列挙し、
// それぞれについて、S[i]とS[j]とS[k]が互いに異なるか調べればよい。
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    long long r=0,g=0,b=0;
    for(auto &p: S) {
        if(p=='R') ++r;
        else if(p=='G') ++g;
        else ++b;
    }

    map<char,int> RGB;
    RGB['R'] = 1, RGB['G'] = 1<<1, RGB['B'] = 1<<2;
    long long p = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            int k = 2*j-i;
            if(k >= N) continue;
            if(RGB[S[i]] ^ RGB[S[j]] ^ RGB[S[k]] ^ 0x07) continue;
            ++p;
        }
    }
    long long ans = r*g*b - p;
    cout << ans << endl;
    return 0;
}

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

int n,a[N];
void gg(){
	puts("-1"); exit(0);
}
int main(){
	int x,y;
	scanf("%*d%d%d",&x,&y);
	puts((y-x&1)?"Borys":"Alice");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >>s>>t;
  lol ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]) ans++;
  }

  cout <<ans<<'\n';
  return(0);
}

Measured memory_bytes: 3840
import Control.Monad
import Text.Printf

main = do
  line <- fmap (fmap (read :: String -> Double) . words) getLine
  let aa = Point { x = line !! 0, y = line !! 1}
  let bb = Point { x = line !! 2, y = line !! 3}
  let l = Line aa bb
  q <- readLn
  input <- replicateM q getLine
  let xs = fmap (fmap (read :: String -> Double) . words) input
  let result = fmap (\e -> (x $ res l (e !! 0) (e !! 1), y $ res l (e !! 0) (e !! 1))) xs
  mapM_  (\r -> (printf "%.8f %.8f\n" (fst r) (snd r))) result
    where res l x1 y1 = l `reflect` Point{x=x1,y=y1}

eps :: (Floating a) => a
eps = 1e-7

add :: (Ord a, Floating a) => a -> a -> a
add a b
  | abs (a + b) < eps * (abs a + abs b ) = 0.0
  | otherwise = a + b

data Point a = Point { x :: a, y :: a } deriving (Eq)
data Line a = Line {a :: Point a, b :: Point a}

(^+) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^+ b =  Point (add (x a) (x b)) (add (y a) (y b))

(^-) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^- b = Point (add (x a) (-(x b))) (add (y a) (-(y b)))

(^*) :: (Floating a) => Point a -> a -> Point a
a ^* d = Point (x a * d) (y a * d)

dot :: (Floating a) => Point a -> Point a -> a
a `dot` b = x a * x b + y a * y b

project :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `project` p = a l ^+ (base ^* t)
  where base = b l ^- a l
        t = ((p ^- a l) `dot` base) / (base `dot` base)

reflect :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `reflect` p = p ^+ (((l `project` p) ^- p) ^* 2.0)

Measured memory_bytes: 5060
N = int(input())
H = list(map(int, input().split(" ")))
memo = [0] * N

for i in range(N):
  if i == 0:
    memo[i] = H[i] - 1
    continue
  if H[i] >= H[i - 1]:
    memo[i] = max(H[i] - 1, memo[i - 1])
    continue
  else:
    if H[i - 1] - H[i] > 1:
      print("No")
      break
    if H[i] < memo[i - 1]:
      print("No")
      break
    memo[i] = max(H[i] - 1, memo[i - 1])
else:
  print("Yes")

Measured memory_bytes: 63708
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = float("inf")
    S = 0
    count = 0
    for i in A:
        if tmp > abs(i):
            tmp = abs(i)
        if abs(i) != i:
            count += 1
        S += abs(i)
    if count%2 == 0:
        print(S)
    else:
        print(S-2*tmp)
    
main()

Measured memory_bytes: 85868
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e2 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;



int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int x, a, b;
    scanf("%d%d%d",&x,&a,&b);
    x -= a;
    while(x >= b) x -= b;
    printf("%d\n",x);
    return 0;
}


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

struct Point {
    double x, y;   
};

void koch(int n, Point a, Point b) {
    if (n == 0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) /3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) /3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y -s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t, b);
}

int main() {
    Point a, b;
    int n;

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);
    return 0;
}


Measured memory_bytes: 3228
#include <cstdio>

int main()
{
  int n;

  for(;;)
    {
      int j,min=1001,max=-1,sum=0;

      scanf("%d",&n);
      if(n==0) break;

      for(int i=0;i<n;i++){
	scanf("%d",&j);
	if(j<min) min=j;
	if(j>max) max=j;
	sum += j;
      }

      printf("%d\n",(sum-min-max)/(n-2));
    }
  
}

Measured memory_bytes: 0
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<ll> A(N + 1), sum(N + 1);
    rep(i, N + 1) {
        cin >> A[i];
        sum[i] = A[i];
    }

    for (int i = N; i > 0; i--) {
        sum[i - 1] += sum[i];
    }

    ll ans = 0, node = 1;
    rep(i, N) {
        ans += node;
        if (node - A[i] <= 0) {
            cout << -1 << endl;
            return 0;
        }
        if ((node - A[i]) * 2 <= sum[i + 1]) {
            node = (node - A[i]) * 2;
        } else {
            node = sum[i + 1];
        }
    }
    if (node != A.back()){
        cout << -1 << endl;
        return 0;
    }

    ans += node;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4756
n = int(input())
a = map(int, input().split())
cnt = 0


def half(_a):
    ret = list()
    for i in _a:
        if i % 2 != 0:
            return None
        else:
            ret.append(i//2)
    return ret


while True:
    a = half(a)
    if not a:
        break
    cnt += 1

print(cnt)



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;

int NG[101010];
ll dp[101010];
ll mo=1000000007;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x;
		NG[x]=1;
	}
	dp[0]=1;
	for(i=1;i<=N;i++) if(NG[i]==0) {
		dp[i]+=dp[i-1];
		if(i>1) dp[i]+=dp[i-2];
		dp[i]%=mo;
	}
	cout<<dp[N]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1408
from collections import Counter


def pf(n):
    primes = Counter()
    c = 2
    while n // c > 0:
        if c**2 > n:
            primes[n] += 1
            break
        while n % c == 0:
            primes[c] += 1
            n //= c
        c += 1
    return primes


def count(t):
    n = 0
    ret = 0
    while True:
        if n * (n + 1) // 2 <= t < (n + 1) * (n + 2) // 2:
            ret = n
            break
        n += 1
    return ret


def main():
    N = int(input())
    primes = pf(N)
    print(sum(list(map(count, primes.values()))))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9496
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{



  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long mod=1000000007l;
  static int INF=10000000;

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); }
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //
  static long cnt;
  static TreeSet<Integer> ans;
  static int n,m;
  static int[][] dp;
  static HashMap<Pair,Boolean> arrl;
  static Stack<Integer> stk;
  static Queue<Integer> queue;
  static HashSet<Integer> mtrnode;
  static ArrayList<Pair> arrlans;
  static int[] ff;


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=1000000007l;

    char[] c=sc.next().toCharArray();
    long sum=0;
    for(char ci:c){
        sum=(sum+(long)(ci-'0'))%9;
    }
    if(sum%9==0){
        nl("Yes");
    }
    else{
        nl("No");
    }

    out.flush();
  }

}

class Pair{
  int x; int y;
  Pair(int x,int y){
    this.x=x;
    this.y=y;
  }
}


Measured memory_bytes: 43076
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

string so(int k, string s) {
	if (s.length()<=k) {return s;}
	string t="";
	for (int i=0;i<k;i++) {
		//cout<<t<<endl;
		t+=s[i];}
	t+="...";

	return t;
	}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    string s;
    cin>>k>>s;
    cout<<so(k,s)<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9+7;
int n,m,K,f[4005][2005][2],sum[4005];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
void upd(int &a,int b){a=(a+b>=mod)?a+b-mod:a+b;}
int main(){
	scanf("%d%d%d",&n,&m,&K);
	int tot=(n+m-1)/(K-1);
	f[0][0][0]=1;
	n--;K--;swap(n,m);
	int ans=0;
	for(int i=1;i<=tot;i++){
		for(int p=1;p<=n+1;p++) sum[p]=add(sum[p-1],add(f[i-1][p-1][0],f[i-1][p-1][1]));
		for(int p=0;p<=n;p++){
			f[i][p][0]=add(sum[p+1],mod-sum[p]);
			int k=max(0,p-K);
			f[i][p][1]=add(sum[p],mod-sum[k]);
		}
		for(int p=n%K;p<=n;p+=K){
			if(i*K-p<=m&&(i*K-p)%K==m%K) upd(ans,f[i][p][1]);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 62848
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashSet;

fn dfs(
  seen: &mut HashSet<usize>,
  frends: &mut HashSet<usize>,
  map: &Vec<Vec<usize>>,
  from: usize
) {
  if seen.contains(&from) { return }
  seen.insert(from);
  frends.insert(from);
  
  for to in map[from].iter() {
    dfs(seen, frends, map, *to);
  }
}

fn main() {
  input! {
    n: usize,
    m: usize,
    pairs: [(Usize1,Usize1);m]
  }
  
  let mut map: Vec<Vec<usize>> = vec![vec![];n];
  let mut seen: HashSet<usize> = HashSet::new();
  for (from, to) in pairs {
    map[from].push(to);
    map[to].push(from);
  }
  let mut max = 0;
  
  for from in 0..n {
    let mut frends = HashSet::new();
    seen.insert(from);
    frends.insert(from);
    for to in map[from].iter() {
      dfs(&mut seen, &mut frends, &map, *to);
    }
    
    max = std::cmp::max(max, frends.len());
  }
  
  println!("{}", max);
}

Measured memory_bytes: 35572
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n;
    cin >> n;

    //prime factors
    vector<int> pf;
    int m = n;
    for(int i = 2; i <= sqrt(n); i++){
        if(m % i == 0){
            pf.push_back(i);
            while(m % i == 0) m /= i;
        }
    }
    if(m != 1){
        pf.push_back(m);
    }

    int num = pf.size();
    int ans = 0;
    for(int s = 1; s < (1 << num); s++){
        int cnt = __builtin_popcount(s);

        int x = 1;
        rep(i, num){
            if((s >> i) % 2 == 1){
                x *= pf[i];
            }
        }

        if(cnt % 2 == 1){
            ans += n / x;
        }else{
            ans -= n / x;
        }
    }

    cout << n - ans << endl;

    return 0;
}



Measured memory_bytes: 3160
N=int(input())
lst=[]
s1=0
s2=0
s3=0
s4=0
s5=0
for i in range(N):
    s=input()
    if s[0]=="M":
        s1+=1
    elif s[0]=='A':
        s2+=1
    elif s[0]=="R":
        s3+=1
    elif s[0]=="C":
        s4+=1
    elif s[0]=="H":
        s5+=1
ans=0
ans+=s1*s2*s3
ans+=s1*s2*s4
ans+=s1*s2*s5
ans+=s1*s4*s5
ans+=s1*s3*s5
ans+=s1*s3*s4
ans+=s2*s3*s4
ans+=s2*s3*s5
ans+=s3*s4*s5
ans+=s2*s4*s5
print(ans)


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

int main(void) 
{
    int X, N;
    std::cin >> X >> N;

    std::vector<int> a(N);
    if (N == 0) {
        std::cout << X << std::endl;
        return 0;
    }
    else {
        for(int i = 0;i < N; i++) {
            std::cin >> a[i];
        }
    }

    if(std::find(a.begin(), a.end(), X) != a.end()) {
       
    }
    else {
        std::cout << X << std::endl;
        return 0;
    }  

    int count = 0;
    while(1) {
        count++;
        int s = X - count;
        int t = X + count;
        if(std::find(a.begin(), a.end(), s) != a.end()) {

        } 
        else {
            std::cout << s << std::endl;
            return 0;
        }
        
        if(std::find(a.begin(), a.end(), t) != a.end()) {
            
        }
        else {
            std::cout << t << std::endl;
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,l=MI()
lis=[input().rstrip() for i in range(n)]
u=sorted(lis)
#print(u)
print("".join(u))

Measured memory_bytes: 3316
<?php

fscanf(STDIN, "%d%d", $x, $n);
$p_list = explode(' ', trim(fgets(STDIN)));

$lte = $x;
$gte = $x;
while (in_array($lte, $p_list) && in_array($gte, $p_list)) {
    --$lte;
    ++$gte;
}

if (!in_array($lte, $p_list)) {
    echo $lte;
} else {
    echo $gte;
}


Measured memory_bytes: 16100
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007


int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	cin>>n>>s;
	if(s=="100")s[2]='1';
	for(ll i=1;i<=n;i++)
		s+="00";
	cout<<s;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	char a[100],c[100],b[100];
	scanf("%s %s %s",a,b,c);
	int i=0,j=0;
	while(a[i+1]!='\0')
		i++;
	while(b[j+1]!='\0')
		j++;
	if(a[i]==b[0] && b[j]==c[0])
		printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 128