akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
const int MAXN = 1e6+10;
const int modul = 1e9+7;
int ken[300000][5];
int n,m,s,t;

vector<int> v[MAXN];

priority_queue<pair<pair<int,int>,int>> q;

void bfs(int x, int kenDiv, int kenMod){

	q.push({{-kenDiv,-kenMod},x});



	while(!q.empty()){
		pair<pair<int,int>,int> temp = q.top();
		q.pop();

		kenDiv = -temp.first.first;
		kenMod = -temp.first.second;
		x = temp.second;

		int slDiv = kenDiv;
		int slMod = (kenMod + 1)%3;
		if (slMod == 0)slDiv++;

		for (auto y : v[x]){
			if (ken[y][slMod] == -1 ||
				ken[y][slMod] > slDiv){
				ken[y][slMod] = slDiv;
				q.push({{-slDiv, -slMod},y});
			}
		}

	}

}

int main()
{

	scanf("%d %d",&n,&m);

	for (int i = 1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);

		v[x].push_back(y);
	}

	scanf("%d %d",&s,&t);

	for (int i = 1;i<=n;i++)
		for (int j = 0;j<3;j++)
			ken[i][j] = -1;

	ken[s][0] = 0;
	bfs(s,0,0);

	printf("%d\n",ken[t][0]);

	return 0;
}

Measured memory_bytes: 30016
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

int paper[10][10]={0};

void drop(int x,int y){
    
    if(0<=x && x<10 && 0<=y && y<10){
        paper[x][y]++;
    }
    
}

int main(){
    int a[3],ans_cho=0,ans_hishi=0;
    
    while(EOF!=scanf("%d,%d,%d",&a[0],&a[1],&a[2])){
        
        if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])
            ans_cho++;
        
        if(a[0]==a[1])
            ans_hishi++;
        
        
    }
    
    printf("%d\n%d\n",ans_cho,ans_hishi);
    
    return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i = 0 ; i < strlen(str) ; i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M - 1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i = 0 ; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i = 0 ; i < M ; i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s %s", com, str);

    if(com[0] == 'i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");
      }
      else printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 16096
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

string s;
 
void solve(){
	int x;

    cin >> x;

    int k = x / 500;
    k *= 1000;
    int h = (x % 500) / 5;
    cout << k + h * 5;
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      cout<<"T"<<flush;
    }else if(s[i]=='T'){
      cout<<"A"<<flush;
    }else if(s[i]=='G'){
      cout<<"C"<<endl;
    }else{
      cout<<"G"<<endl;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
def search(target, array):
	start,end=0,len(array)-1
	while (start+1<end):
		mid = (start + end) // 2
		if array[mid] == target:
			return 1
		elif array[mid] < target:
			start = mid
		elif array[mid] > target:
			end = mid

		if array[start] == target:
			return 1
		if array[end] == target:
			return 1
	return 0		

input()
userinput=input()
array=[int(s) for s in userinput.split(' ')]
#print(len(array))
input()
userinput=input()
searcharray=[int(s) for s in userinput.split(' ')]
count =0
for s in searcharray:
	count+=search(s,array)
print(count)	

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

using namespace std;

#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	char a;
	cin>>a;
	(a<'a')?cout<<"A\n":cout<<"a\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int n, p[10009][10], t[10009][11], minx = -1000000000;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++)cin >> p[i][j]; }
	for (int i = 0; i < n; i++) { for (int j = 0; j < 11; j++)cin >> t[i][j]; }
	for (int i = 1; i < (1 << 10); i++) {
		int bit[10]; for (int j = 0; j < 10; j++)bit[j] = (i / (1 << j)) % 2;
		int sum = 0;
		for (int j = 0; j < n; j++) {
			int ret = 0;
			for (int k = 0; k < 10; k++) { if (bit[k] == 1 && p[j][k] == 1)ret++; }
			sum += t[j][ret];
		}
		minx = max(minx, sum);
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
def 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
def numcount(n):
    i = 1
    while True:
        n -= i
 
        if n <= i:
            break
        i += 1
    return i
A = int(input())
L = factorize(A)
C = collections.Counter(L)
ret = 0
for c in C:
    ret += numcount(C[c])
print(ret)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r,d,x_ini;
  cin >> r >> d >> x_ini;
  vector<int> x(11);
  x.at(0) = x_ini;
  for(int i=1;i<11;i++){
    x.at(i) = r*x.at(i-1)-d;
    cout << x.at(i) << endl;
  }
  return 0;
}


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

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(i%2 && s[i] == '0') ans++;
		if(i%2==0 && s[i] == '1') ans++;
	}
	int tmp = 0;
	for(int i = 0; i < s.size(); i++){
		if(i%2==0 && s[i] == '0') tmp++;
		if(i%2 && s[i] == '1') tmp++;
	}
	cout << min(tmp, ans) << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int cnt=0,ans=0;;
    for(int i=0; i<n-1; i++){
        if(h[n-i-1]<=h[n-i-2])cnt++;
        else cnt=0;
        ans=max(cnt,ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 768
s, t = input(), input()
dict_s, dict_t = {}, {}

for i in range(len(s)):
  if s[i] not in dict_s:
    dict_s[s[i]] = t[i]
  else:
    if dict_s[s[i]] != t[i]:
      print("No")
      exit()
  if t[i] not in dict_t:
    dict_t[t[i]] = s[i]
  else:
    if dict_t[t[i]] != s[i]:
      print("No")
      exit()

print("Yes")

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<iomanip>
using namespace std;
#define eps 1e-12
#define INF 1000000
#define maxn 200005
double a[105][105];
double sum[105];
struct Edge
{
    int u,v;
    double w;
}b[10005],e[10005];
int pre[maxn],id[maxn],vis[maxn];
double in[maxn];

int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    return x<0?-1:1;
}

double Directed_MST(int root, int NV, int NE)
{
    double ret = 0;
    while(1)
    {
        for(int i=0;i<NV;i++)
            in[i]=INF;
        memset(pre,-1,sizeof(pre));
        memset(vis,-1,sizeof(vis));
        memset(id,-1,sizeof(id));
        for(int i=0;i<NE;i++)
        {
            if(e[i].u==e[i].v) continue;
            int v=e[i].v;
            if(dcmp(e[i].w-in[v])<0){
      //          ans=i;
                pre[v]=e[i].u;
                in[v]=e[i].w;
            }
        }
        for(int i=0;i<NV;i++)
        {
            if(dcmp(in[i]-INF)==0&&i!=root)
            {
                //cout<<i<<endl;
                return -1;
            }
        }
        int cnt=0;
        in[root]=0;
        for(int i=0;i<NV;i++)
        {
            ret+=in[i];
            int v=i;
            while(vis[v]!=i&&id[v]==-1&&v!=root)
            {
                vis[v]=i;
                v=pre[v];
            }
            if(v!=root&&id[v]==-1){
                for(int u=pre[v];u!=v;u=pre[u])
                {
                    id[u]=cnt;
                }
                id[v]=cnt++;
            }
        }
        if(cnt==0) break;
        for(int i=0;i<NV;i++)
            if(id[i]==-1) id[i]=cnt++;
        for(int i=0;i<NE;i++)
        {
            int v=e[i].v;
            e[i].u=id[e[i].u];
            e[i].v=id[e[i].v];
            e[i].w-=in[v];
        }
        NV = cnt;
        root = id[root];
     }
    return ret;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)    for(int j=0;j<n;j++)    scanf("%lf",a[i]+j);
    int tot=0;
    for(int i=1;i<=m;i++)             //j->i??±?
    {
        for(int j=1;j<=m;j++)
        {
            double x1=0,x2=0,x3=0;     // y=r*r*x3-2*r*x2+x1
            for(int k=0;k<n;k++)
            {
                x1+=a[i][k]*a[i][k];
                x3+=a[j][k]*a[j][k];
                x2+=a[i][k]*a[j][k];
            }
            sum[i]=x1;
            if(i==j)    continue;
            double x=x2/x3;
            double y=x*x*x3-2.0*x*x2+x1;
            e[tot].u=j;
            e[tot].v=i;
            e[tot].w=y;
            tot++;
        }
    }
    for(int i=1;i<=m;i++)
    {
        e[tot].u=0;
        e[tot].v=i;
        e[tot].w=sum[i];
        tot++;
    }
    double temp=Directed_MST(0,m+1,tot);
    printf("%.7f\n",temp);
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int n=0;
  while(n*a-n+1<b){
    n++;
  }
  cout << n << endl;
}


Measured memory_bytes: 256
a, b = gets.strip.split.map(&:to_i)
if a > b
  first_max = a
  a -= 1
  if a > b
    second_max = a
  else
    second_max = b
  end
else
  first_max = b
  b -= 1
  if a > b
    second_max = a
  else
    second_max = b
  end
end

puts first_max + second_max

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

int main(){
    string s, t, r;
    cin >> s >> t;
    int sizs = s.size(), sizt = t.size();
    int dp[sizs+1][sizt+1];

    for(int i = 0; i <= sizs; i++)  dp[i][0] = 0;
    for(int i = 0; i <= sizt; i++)  dp[0][i] = 0;

    for(int i = 1; i <= sizs; i++){
        for(int j = 1; j <= sizt; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = (1 + dp[i-1][j-1]);
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int ind = sizs;
    for(int i = sizt; i >= 1 && ind > 0;){
//        cout << ind << " " << i << '\n';
        if(dp[ind][i] == dp[ind-1][i]){
            ind--;
        } else if(dp[ind][i] == dp[ind][i-1]) {
            i--;
        } else {
            r += s[ind-1];
            ind--;  i--;
        }
    }
    reverse(r.begin(), r.end());
    cout << r;
}

Measured memory_bytes: 38760
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int dfs(int n, vector<int> &v, int A, int B){
  if(n >= v.size()) return abs(A - B);
  int ret = dfs(n + 1, v, A + v[n], B);
  ret = min(ret, dfs(n + 1, v, A, B + v[n]));
  return ret;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<int> v(N); REP(i, N) cin >>v[i];
    cout <<dfs(0, v, 0, 0) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
import Data.List

main = do
    [n,h] <- map read . words <$> getLine :: IO[Int]
    co <- getContents
    let (a,bs) = foldl (\ (a,bs) [a',b] -> (max a a', b:bs)) (0,[]) $ map (map read) $ map words $ lines co
    let xs = foldr (\ x' all@(x:xs) -> if x' >= x then x':all else all) [a] $ sortBy (flip compare) bs
    print $ solve xs h

solve :: [Int] -> Int -> Int
solve [x] h = (h+x-1) `div` x
solve (x:xs) h = if x >= h then 1 else 1 + solve xs (h-x)


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

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll a = 7;
  int ans = 1;
  vector<bool> v(1000000, false);
  while (true) {
    a = a % k;
    if (a == 0) break;
    if (v.at(a)) {
      ans = -1;
      break;
    }
    v.at(a) = true;
    a = a * 10 + 7;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
int main() {
    int H, W, D, Q;
    cin >> H >> W >> D;
    vector<pair<int, int>> vp(H * W);
    vector<int> d(H * W, 0);
    for (int i = 0; i < H; i++) for (int j = 0, A; j < W; j++) {
        cin >> A;
        vp[A - 1] = make_pair(i, j);
    }
    for (int i = D; i < H * W; i++) d[i] = d[i - D] + abs(vp[i].first - vp[i - D].first) + abs(vp[i].second - vp[i - D].second);
    cin >> Q;
    for (int i = 0, L, R; i < Q; i++) {
        cin >> L >> R;
        cout <<d[R - 1] - d[L - 1] << endl;
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;

int main(){


	int N; ull A, B; std::cin >> N >> A >> B;
	std::vector<ull> X(N);
	rep(i, N){
		std::cin >> X[i];
	}
	ull tired = 0;

	for(int i = 1; i < N; i++){
		ull dist = X[i] - X[i - 1];
		tired += std::min(dist * A, B);
	}

	std::cout << tired;


	return 0;
}

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

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

int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    
    ans += min(a, k);
    k -= a;

    if(0 < k ){
        k -= b;
    }

    if(0 < k){
        ans -= k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for(register int i = a;i <= b; ++i)

const int N = 5e6+10, B1=37,P1=19260817,B2=137,P2=998244353;
int n,ans;
int gcd(int a,int b) {if(a>b)a^=b^=a^=b;return a?gcd(b%a,a):b;}
int main() {
	cin>>n;
	f(i,1,n) f(j,1,n) f(k,1,n) ans+=gcd(i,gcd(j,k));
	cout<<ans;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 1000005;

/* ...o(^-^)o... */

int main(){
    int n; cin>>n;
    vector<P> v_pos, v_neg;
    rep(i, n){
        string str; cin>>str;
        int k = 0, mn = MAX;
        rep(j, str.size()){
            if(str[j]=='(') k++; else k--;
            mn = min(mn, k);
        }
        if(k>=0) v_pos.push_back(P(mn, k));
        else v_neg.push_back(P(mn-k, -k));
    }

    int possum=0, negsum=0;
    rep(i, v_pos.size()) possum += v_pos[i].se;
    rep(i, v_neg.size()) negsum += v_neg[i].se;
    if(possum != negsum){
        out("No"); return 0;
    }
    
    sort(all(v_pos), [](P &l, P &r){
        return l.fi > r.fi;
    });
    sort(all(v_neg), [](P &l, P &r){
        return l.fi > r.fi;
    });
    
    int p = 0, sum = 0; priority_queue<int> pq;
    rep(i, v_pos.size()){
        for(int j = p; j < v_pos.size(); j++){
            if(v_pos[j].fi+sum >= 0){
                pq.push(v_pos[j].se);
                p++;
            }else break;
        }
        if(pq.empty()){
            out("No"); return 0;
        }
        int w = pq.top(); pq.pop(); sum += w;
    }

    p = 0, sum = 0;
    rep(i, v_neg.size()){
        for(int j = p; j < v_neg.size(); j++){
            if(v_neg[j].fi+sum >= 0){
                pq.push(v_neg[j].se);
                p++;
            }else break;
        }
        if(pq.empty()){
            out("No"); return 0;
        }
        int w = pq.top(); pq.pop(); sum += w;
    }

    out("Yes");
}

Measured memory_bytes: 22600
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch TripleDots | diff TripleDots.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TripleDots.cpp && ./a.out

/*

 5/17/2020

 5:02-

 */

string S;
int K;

string solve() {
  if(SZ(S)<=K) return S;
  S=S.substr(0,K);
  return S+"...";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>K>>S;
  cout<<solve()<<endl;

  return 0;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		long M = long.Parse(str[1]);
		var list = new HashSet<long>();
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			list.Add(long.Parse(str2[i]));
		}
		long ans = 0;
		var list2 = new List<long>();
		foreach(var i in list){
			list2.Add(i);
		}
		long L = list2[0];
		for(var i=1;i<list2.Count;i++){
			L = Lcm(L,list2[i]);
			if(L>M*2){
				L = 0;
				break;
			}
		}
		if(L>0){
			ans = (L/2+M)/L;
		}
		var hs1 = new HashSet<int>();
		foreach(var i in list){
			long i1 = i;
			int ct = 0;
			while(i1%2==0){
				ct++;
				i1 /= 2;
			}
			hs1.Add(ct);
		}
		if(hs1.Count>=2){
			ans = 0;
		}
		Console.WriteLine(ans);
	}
	
	public static long Gcd(long a, long b) {
		if (a < b)
			return Gcd(b, a);
		while (b != 0) {
			var r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
	public static long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }
}

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

using namespace std;

using ll = long long;

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

    std::vector<ll> A(N);

    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= i;
    }

    std::sort(A.begin(), A.end());
    const ll median = N % 2 == 0 ? (A[N / 2] + A[N / 2 - 1]) / 2 : A[N / 2];

    const auto ans0 = std::accumulate(A.cbegin(), A.cend(), 0ll, [&median](const auto &acc, const auto &x) {
        return acc + std::abs(x - median);
    });

    const auto ans1 = std::accumulate(A.cbegin(), A.cend(), 0ll, [&median](const auto &acc, const auto &x) {
        return acc + std::abs(x - median - 1);
    });

    cout << std::min(ans0, ans1) << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
    int N;
    char flag = 0;
    char c = '0';
    scanf("%d", &N);
    while(scanf("%c", &c)!=EOF){
        if(c == 'Y'){
            flag = 1;
            break;
        }
    }
    if(flag == 1){
        printf("Four\n");
    }else{
        printf("Three\n");
    }
    return 0;
}


Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
s = input()
while s:
    if s[:11] == "dreameraser":
        s = s[11:]
    elif s[:10] == "dreamerase":
        s = s[10:]
    elif s[:7] == "dreamer":
        s = s[7:]
    elif s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "dream":
        s = s[5:]
    elif s[:5] == "erase":
        s = s[5:]
    else:
        print("NO")
        quit()
print("YES")
"""

#D
def root(x,par,rank):
    if x == par[x]:
        return x
    par[x] = root(par[x],par,rank)
    return par[x]
def unite(x,y,par,rank):
    x = root(x,par,rank)
    y = root(y,par,rank)
    if x == y:return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n,k,l = LI()
par1 = [i for i in range(n)]
rank1 = [0 for i in range(n)]
par2 = [i for i in range(n)]
rank2 = [0 for i in range(n)]
for i in range(k):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par1,rank1)
for i in range(l):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par2,rank2)
d = {}
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    if k in d:
        d[k] += 1
    else:
        d[k] = 1
ans = []
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    ans.append(d[k])
print(*ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 109700
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
priority_queue<ll> QA;
priority_queue<ll> QB;
priority_queue<ll> QC;
priority_queue<ll,vector<ll>,greater<ll>> QD;
int main(){
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  for(int i=1;i<=a;i++){
    int t;cin>>t;
    QA.push(t);
  }
  ll sum=0;
  for(int i=1;i<=x;i++){
    sum+=QA.top();
    QD.push(QA.top());
    QA.pop();
  //  cout<<" "<<sum<<endl;
  }
  for(int i=1;i<=b;i++){
    int t;cin>>t;
    QB.push(t);
  }
  for(int i=1;i<=y;i++){
    QD.push(QB.top());
    sum+=QB.top();
    QB.pop();

  ////  cout<<" "<<sum<<endl;
  }
  for(int i=1;i<=c;i++){
    int t;cin>>t;
    QC.push(t);
  }
  //cout<<QC.size()<<" "<<QD.size()<<endl;
  while(QC.size()>0&&QD.size()>0){
    //cout<<QC.top()<<" "<<QD.top()<<endl;
    if(QC.top()>QD.top()){
      sum=sum-QD.top()+QC.top();
      QC.pop();
      QD.pop();

    //  cout<<" "<<sum<<endl;
    }
    else QC.pop();
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 4976
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

signed main() {
    Fast();

    int n, m, c;

    cin >> n >> m >> c;
    int ret = 0;

    int b[m];
    for(int i=0; i<m; i++)
        cin >> b[i];

    for(int i=0; i<n; i++){
        int sum = c;
        for(int j=0; j<m; j++){
            int val;
            cin >> val;
            sum += val * b[j];
        }
        ret += (int)(sum > 0);
    }

    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 888
import itertools


def solve():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    cntA, cntB = 0, 0
    for i in range(N):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                cntA += 1
        for j in range(N):
            if A[i] > A[j]:
                cntB += 1

    M = 10**9 + 7
    # オーバーフロー対策で掛け算毎に剰余をとる
    a = cntA * K % M
    b = ((K - 1) * K // 2) % M * cntB % M
    print((a + b) % M)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 73820
#include <iostream>
using namespace std;
int main(){
	int sum,tmp,f=1,i=0;
	char c;
	cin>>sum;
	for(i=0;f;){
		if(i){
			cin>>tmp;
			if(c=='+')sum+=tmp;
			else if(c=='-')sum-=tmp;
			else if(c=='*')sum*=tmp;
			else if(c=='/')sum/=tmp;
			i--;
		}
		else{
			cin>>c;
			if(c=='='){
				cout<<sum<<endl;
				f=0;
			}
			i++;
		}
	}
	return 0;
}


Measured memory_bytes: 1160
n=int(input())
h=[]
add=[]
diff=[]
diff1=[]
for i in range(n):
  l=list(map(int,input().split()))
  h.append(l)
  p=h[i][0]+h[i][1]
  add.append(p)
  k=h[i][0]-h[i][1]
  diff.append(k)
  r=h[i][1]-h[i][0]
  diff1.append(r)
a=max(add)-min(add)
b=max(diff)-min(diff)
c=max(diff1)-min(diff1)
print(max(a,b,c))

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

using namespace std;

const int INF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    long long a;
    cin >> a;
    if (a % 2){
        cout << 0;
        return 0;
    }
    long long ans = 0;
    for (long long x = 5; 2 * x <= a; x *= 5)
        ans += (a / (2 * x));
    cout << ans;
}


Measured memory_bytes: 384
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();

	    int count = 0;
	    for (int a = n; a > 0; a--) {
	    	int b_max = (int)Math.floor((double)n / (double)a);
	    	if (b_max > n) {
	    		b_max = n;
	    	}
	    	if (b_max > a) {
	    		b_max = a;
	    	}
	    	for (int b = b_max; b <= a && b > 0; b--) {
    			int c = n - a * b;
	    		if (c <= n && c > 0) {
	    			count++;
	    			if (a != b) {
	    				count++;
	    			}
	    		}
	    	}
	    }
	    System.out.println(count++);
	}

}

Measured memory_bytes: 36372
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

bool is_meets_demand(std::string& S,std::string& T,int& pos){
    for(int i=0;i<T.size();i++){
        if(!(S[i+pos]=='?' || S[i+pos]==T[i])){
            return false;
        }
    }
    return true;
}

int main(void){
    std::string S;
    std::string T;
    cin>>S>>T;
    int m1=0;
    for(int i=(int)S.size()-(int)T.size();i>=0;i--){
        if(is_meets_demand(S,T,i)){
            int j=0;
            for(;j<=i-1;j++){
                if(S[j]=='?') S[j]='a';
            }
            for(int k=0;k<(int)T.size();k++){
                S[j]=T[k];
                j++;
            }
            for(;j<=(int)S.size()-1;j++){
                if(S[j]=='?') S[j]='a';
            }
            cout<<S<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;

	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a,b) << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

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

  ll n, p;
  cin >> n >> p;

  map<ll, int> mp = prime_factor(p);

  int c = 0;
  for (auto m : mp)
    c += m.second;
  if (c < n) {
    cout << 1 << endl;
    return 0;
  }

  std::map<ll, int>::reverse_iterator i = mp.rbegin();
  vector<ll> v(n, 1);
  int j = 0;
  for (; i != mp.rend(); ++i) {
    rep(k, 0, i->second) {
      v[j] *= i->first;
      j++;
      if (j == n)
        j = 0;
    }
  }

  ll ans = v[0];
  rep(i, 1, n) { ans = __gcd(ans, v[i]); }

  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <atomic>
#include <thread>
#include <mutex>
#include <string>
#include <string.h>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define P std::pair<int,int> 
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, m, x[100010];
vector<int> vec;
signed main() {
	cin >> n >> m;
	rep(i, m)cin >> x[i];
	sort(x, x + m);
	for (int i = 1; i < m; i++) {
		vec.push_back(x[i] - x[i - 1]);
	}
	sort(vec.begin(), vec.end(), greater<int>());
	int ans = x[m-1] - x[0];
	rep(i, min(n - 1, m - 1)) {
		ans -= vec[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2168
void main(){
	switch(_scan()%10){
		case 0,1,6,8:
			writeln("pon");
			break;
		case 3:
			writeln("bon");
			break;
		default:
			writeln("hon");
	}	
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2664
def number():
    return int(input())


def space():
    return list(map(int, input().split()))


def seq_space(n):
    return [list(map(int, input().split())) for _ in range(n)]


N, W = space()
WV = seq_space(N)

V = N*1000+1
DP = [float('inf')] * V
DP[0] = 0

for i in range(N):
    w, v = WV[i]
    for j in range(V-1, v-1, -1):
        DP[j] = min(DP[j-v]+w, DP[j])

for i in range(V-1, -1, -1):
    if DP[i] <= W:
        print(i)
        exit()


Measured memory_bytes: 92620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n, k;
vector<ll> a;
bool check(ll x) {
    ll count = 0;
    rep1(i, n) count += (a[i] - 1) / x;
    if (count <= k) return true;
    else return false;
}

int main() {
    cin >> n >> k;
    a.resize(n);
    rep1(i, n) cin >> a[i];
    ll ans = 0;
    ll left = 1, right = 1e9;
    while (right > left){
        ll mid = (right + left) / 2;
        if (check(mid)) right = mid;
        else left = mid+1;
    }  
    cout << left << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b;
	cin>>a>>b;
	if((a*b)&1){
		cout<<"Odd";
	}
	else{
		cout<<"Even";
	}
	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
string s;
ll ans;
int main() {
    cin>>n;
    cin>>s;

    vi csumw(n+1);
    vi csume(n+1);
    csumw[0] = 0;
    csume[n] = 0;

    FOR(i,0,n){
        csumw[i+1] += csumw[i];
        if(s[i] == 'W') csumw[i+1]++;
    }

    FORR(i,1,n+1){
        csume[i-1] = csume[i];
        if(s[i-1] == 'E') csume[i-1]++;
    }

    //DEBUG_VEC(csumw);
    //DEBUG_VEC(csume);

    ans = LLONG_MAX;
    REP(i,n){
        ll tmp;
        if(s[i]=='W')
            tmp = (csumw[i+1]-1) + csume[i];
        else
            tmp = csumw[i+1] + (csume[i]-1);

        
        if(ans > tmp)
            ans = tmp;
    }

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

Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());

		System.out.println((n - h + 1) * (n - w + 1));

		sc.close();
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define zcin(type, a) type a; cin >> a;
#define zcout(a, sep1, b, sep2) cout << a << sep1 << b << sep2;
#define zfor(i, b, n) for (int i = b; i < n; ++i)
#define pb push_back

using namespace std;

int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	int n;
	cin >> n;

	set<string> ens;
	for (int i = 0; i < n; ++i)
	{
		string s; cin >> s;
		ens.insert(s);
	}

	cout << ens.size();

	return 0;
}


Measured memory_bytes: 19180
let N = Int(readLine()!)!
let S = readLine()!.characters.map{$0}
var a = (1..<N).reduce(0){$0+(S[$1]=="E" ?1:0)}
var ans = a
for i in 1..<N {
    if S[i] == "E" {
        a -= 1
    }
    if S[i-1] == "W" {
        a += 1
    }
    ans = min(a, ans)
}
print(ans)

Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> q;
    vector<int> check(N, -1), check2(N, -1);
    q.push(0);
    check[0] = 0;
    int cnt = 0, cnt2=0;
    while(!q.empty()) {
        int node = q.front(); q.pop();
        rep(i, G[node].size()) {
            int next = G[node][i];
            if (check[next] >= 0) continue;
            check[next] = check[node] + 1;
            q.push(next);
        }
    }
    q.push(N-1);
    check2[N-1] = 0;
    while(!q.empty()) {
        int node = q.front(); q.pop();
        rep(i, G[node].size()) {
            int next = G[node][i];
            if (check2[next] >= 0) continue;
            check2[next] = check2[node] + 1;
            q.push(next);
        }
    }
    rep(i, N) {
        if (check[i] <= check2[i]) cnt++;
        else cnt2++;
    }
    if (cnt > cnt2) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 9592
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    d, x = map(int, input().split())
    ans = x
    for _ in range(n):
        a = int(input())
        ans += (d - 1) // a + 1
    print(ans)

main()


Measured memory_bytes: 2940
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

P f(ll a){
    ll x = 0, y = 0;
    while(a%2 == 0){
        a /= 2;
        x++;
    }
    while(a%5 == 0){
        a /= 5;
        y++;
    }
    return mp(x, y);
}

int main(){
    ll n; cin >> n;
    vvll d(n, vll(2));
    rep(i, 0, n){
        string s; cin >> s;
        string t = "";
        bool b = false;
        ll c = 0;
        for(auto x: s){
            if(x == '.'){
                b = true;
                continue;
            }else{
                t.pb(x);
            }
            if(b){
                c++;
            }
        }
        ll g = stoll(t);
        P v = f(g);
        d[i][0] = v.fst-c;
        d[i][1] = v.snd-c;
    }
    map<ll, vll> m;
    rep(i, 0, n){
        ll x = d[i][0], y = d[i][1];
        m[x].emplace_back(y);
    }
    ll ans = 0;
    ll r = -100;
    while(r < 60){
        if(m.find(r) == m.end()){
            r++;
            continue;
        }
        sort(m[r].begin(),m[r].end());
        r++;
    }
    rep(i, 0, n){
        ll x = d[i][0], y = d[i][1];
        //prt(x); prt(" "); prtl(y);
        ll v = -x;
        while(v < 60){
            if(m.find(v) == m.end()){
                v++;
                continue;
            }
            ans += m[v].end() - lower_bound(m[v].begin(), m[v].end(), -y);
            v++;
        }
        if(x>=0&&y>=0){
            ans--;
        }
    }
    prtl(ans/2);
}


Measured memory_bytes: 16304
/**
*  author: rits1272
*  created: Aug 29, 2020
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define print(x) cout << "[" << #x << ":" << x << "] "; 
#define println(x) cout << "[" << #x << ":" << x << "]\n";

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    int n = s.size(), k = t.size();
    for(int i=0; i<n-k+1; i++){
	string tmp = s.substr(i, (int)t.size());
	//cout << tmp << "\n";
	int cnt = 0;
	for(int i=0; i<(int)t.size(); i++){
	    if(tmp[i] != t[i])
		cnt++;
	}
	ans = min(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A (N, 0);
    int accum = 0;
    REP (i, N) {
        cin >> A[i];
        accum += A[i];
    }
    ALL (sort, A, greater<int>());
    cout << ((accum + 4 * M - 1) / (4 * M) <= A[M - 1] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
    #include<vector>

    using namespace std;

    int main(){
        int N; cin >> N;
        int sum = 0;

        vector<int> a(N);
        vector<int> b(N);
        vector<int> c(N-1);

        for(int i = 0;i  < N;i++){
            cin >> a.at(i);
        }

         for(int i = 0;i  < N;i++){
            cin >> b.at(i);
        }

         for(int i = 0;i  < N-1;i++){
            cin >> c.at(i);
        }

        for(int i = 0;i < N;i++){
            if(i != 0 && (a.at(i-1)+1 == a.at(i) )){
                sum += c.at(a.at(i-1)-1);
               //cout << "ボーナス:" << c.at(i-1) << endl; 
            }
            sum += b.at(a.at(i)-1);

           // cout << "i = " << i << "の時"<< b.at(a.at(i)-1)<< "追加" << endl;
        }

        cout << sum << endl;

        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma optimize("-O2")
#define pb push_back
#define fi first
#define se second
#define SIZE 10000
#define PAD 250
#define MOD 1000000007LL
#define MAXV 200111
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

ll n, chk[100011], a[100011], diff;
ll fact[100111], finv[100111];

ll getPow(ll a, ll k) {
	ll b = 1;
	while(k>0) {
		if(k%2LL)	b=b*a%MOD;
		k/=2LL, a=a*a%MOD;
	}
	return b;
}

ll C(ll a, ll b) {
	return fact[a] * finv[a-b] % MOD * finv[b] % MOD;
}

int main () {
	fact[0] = 1, finv[0] = 1;
	for(ll i=1;i<100111;i++)		fact[i] = fact[i-1] * i % MOD;
	for(ll i=1;i<100111;i++)		finv[i] = getPow(fact[i], MOD-2LL);
	// for(ll i=0;i<10;i++)	printf("%lld\n",fact[i]);
	// for(ll i=1;i<10;i++) {
	// 	for(ll j=1;j<=i;j++)	printf("%lld ",C(i,j));
	// 	printf("\n");
	// }
	scanf("%lld",&n);
	for(ll i=1;i<=n+1;i++) {
		scanf("%lld",a+i);
		if(chk[a[i]])	diff = i - chk[a[i]] + 1;
		else		chk[a[i]] = i;
	}
	// printf("diff %lld\n",diff);
	for(ll i=1;i<=n+1LL;i++) {
		ll ans = C(n+1LL,i);
		if(n+1LL-diff >= i-1LL)	ans = (ans - C(n+1LL-diff, i-1LL) + MOD)%MOD;
		// printf("i %lld val %lld %lld just %lld\t",i,n+1LL-diff, i-1LL,C(n+1LL,i));
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 4352