akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
long long gcd(long long a, long long b) {
    if (b==0)return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}
int main(){
ll n;
cin >> n;
ll a[n];
ll least = 1;
for (ll i = 0; i < n; i++) cin >> a[i];
for (ll i = 0; i < n;i++){
    least = lcm(least, a[i]);
}
cout << least << endl;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int a[200005];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]), a[i] -= i;
    sort(a+1, a+n+1);
    long long res = 0;
    for(int i=1; i<=n; i++) res += abs(a[i]-a[(n+1)/2]);
    printf("%lld", res);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t, x, y; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1), x(n), y(n) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
    x[u] += x[v];
    y[u] += y[v];
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> x(n), y(n);
  UnionFind uf(2e5);
  fill(begin(uf.x), begin(uf.x) + 1e5, 1);
  fill(begin(uf.y) + 1e5, end(uf.y), 1);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i], --x[i], --y[i];
    uf.unite(x[i], 1e5 + y[i]);
  }
  V<> a(2e5);
  for (int i = 0; i < n; ++i) ++a[uf.find(x[i])];
  set<int> se;
  for (int v = 0; v < 2e5; ++v) se.insert(uf.find(v));
  lint res = 0;
  for (int e : se) {
    res += (lint)uf.x[e] * uf.y[e] - a[e];
  }
  cout << res << '\n';
}

Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
long long n;
void solve(long long x){
	if(!x)return;
	if(x%26)solve(x/26);else solve(x/26-1);
	putchar((char)((x-1ll)%26ll+97));
}
int main(){
	scanf("%lld",&n);solve(n);
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    ll N, K;
    cin >> N >> K;
    priority_queue<ll> que;
    REP(i, N) {
        int H;
        cin >> H;
        que.push(H);
    }
    ll cnt = 0;
    if(K >= N) {
        cout << 0 << endl;
        return 0;
    }
    while(K--) {
        que.pop();
    }
    while(!que.empty()) {
        cnt += que.top();
        que.pop();
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3444
def binarySearch(key,n,S):
    mid = 0
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            return 1
        elif key < S[mid]:
            right = mid
        else:
            left = mid + 1
    return 0

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
set(S)

ctr = 0
for i in range(q):
    ctr += binarySearch(T[i],n,S)
        
        
print(ctr)


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

using namespace std;

const int max_n = 202222, inf = 1000111222;
const int max_v = 1000111;
const int max_c = 27;

char buf[max_v];

string read() {
    scanf("%s", buf);
    return buf;
}

int n;
int first, nxt[max_v][max_c], cnt[max_v][max_c], tot[max_c];
string s[max_n];
long long ans;

void add(const string &s) {
    memset(tot, 0, sizeof(tot));
    for (char c : s) {
        ++tot[c - 'a'];
    }
    int v = 0;
    for (char c : s) {
        for (int to = 0; to < max_c; ++to) {
            if (tot[to]) {
                ++cnt[v][to];
            }
        }
        --tot[c - 'a'];
        if (!nxt[v][c - 'a']) {
            nxt[v][c - 'a'] = ++first;
        }
        v = nxt[v][c - 'a'];
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        s[i] = read();
        reverse(s[i].begin(), s[i].end());
        add(s[i]);
    }
    for (int i = 0; i < n; ++i) {
        int v = 0;
        for (int j = 0; j + 1 < s[i].length(); ++j) {
            v = nxt[v][s[i][j] - 'a'];
        }
        ans += cnt[v][s[i].back() - 'a'] - 1;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 221552
import java.util.Scanner;

public class Main{

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

        // input
        int num = scan.nextInt();
        int count = 0;
        int answer = 0;
        for(int i = 1; i <= num; i++){
            if(scan.nextInt() == i){
                count++;
            } else {
                answer += (count + 1) / 2;
                count = 0;
            }
        }
        if(count > 0){
            answer += (count + 1) / 2;
        }

        // answer
        System.out.println(answer);
    }
}

Measured memory_bytes: 47520
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N;

int main(){
	getint(N);
	return printf("%d\n", 180 * (N - 2)), 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(i)-1 for i in input().split()]
l = []
d = {}
p = 0
while p not in d:
    d[p] = len(l)
    l.append(p)
    p = A[p]
if K < len(l):
    print(l[K % len(l)] + 1)
    exit()
elif K == len(l):
    print(p + 1)
    exit()
K -= d[p]
K %= len(l) - d[p]
print(l[K + d[p]] + 1)

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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1000 + 9, M = 50 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(0);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

char grid[N][N];
ll a, b, n, m, ways[N][N];

int main() {
//	INPUT();
	OUTPUT();
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> grid[i][j];
		}
	}
	ways[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (grid[i][j] == '#' || (i == j && i == 0))
				continue;
			a = 0, b = 0;
			if (i > 0)
				a = ways[i - 1][j];
			if (j > 0)
				b = ways[i][j - 1];
			ways[i][j] = (a % MOD) + (b % MOD) % MOD;
		}
	}
	cout << ways[n - 1][m - 1] % MOD;

	return 0;

}


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

#define    int               long long int
 #define    bp(x)         __builtin_popcount(x)
#define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
#define  mod  1000000007
#define  endl  "\n"
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}
vector<int>v[200005];
int sub[200005],inv[200005],a[200005],ans=1,n;

void dfs(int r,int p){
    sub[r]=1;
    for(auto i : v[r])
        if(i!=p){
            dfs(i,r);
            sub[r]+=sub[i];
        }
}
void dfs1(int r,int p){
    if(r!=1){
        int x=(a[p]*sub[r])%mod;
        x=(x*inv[n-sub[r]])%mod;
        a[r]=x;
    }
    for(auto i : v[r])
        if(i!=p)
            dfs1(i,r);
}

int32_t main()
{
    fast
    int x,y;  cin>>n;
    f(i,1,n-1)  ans=(ans*i)%mod;
    f(i,0,n+1)  inv[i]=power(i,mod-2,mod);
    f(i,1,n-1){
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1,1);
    f(i,2,n)    ans=(ans*inv[sub[i]])%mod;
    a[1]=ans;
    dfs1(1,1);
    f(i,1,n)    cout<<a[i]<<endl;

}

Measured memory_bytes: 20456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

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

struct Edge {
  int to;
  ll score;

  Edge() = default;
  Edge(int to, ll score): to(to), score(score) { }
};

int main() {
  int n, m;
  cin >> n >> m;
  static vector<Edge> G[1002];

  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(Edge(b, c));
  }

  ll score[1002] = { };
  int visit[1002] = { };

  queue<P> que;
  que.push(P(1, 0));
  visit[1] = 1;

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    int v = p.first;
    ll s = p.second;
    visit[v]++;

    for (auto edge : G[v]) {
      int u = edge.to;
      if (visit[u] > 10) {
        continue;
      }
      if (!visit[u] || s + edge.score > score[u]) {
        if (u == n && visit[n]) {
          cout << "inf" << endl;
          return 0;
        }
        score[u] = s + edge.score;
        que.push(P(u, s + edge.score));
      }
    }
  }

  cout << score[n] << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long int
int main(){
  int a,b;
  cin >> a >> b ;
  int ans = max( a+b,a-b );
  ans = max(ans , a*b);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[1001],m,s;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i],s+=a[i];
	sort(a+1,a+n+1);
		if((double)a[n-m+1]<(double)s/4.0/m)cout<<"No",exit(0);
	cout<<"Yes";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;


int main() {
	int n;
	cin >> n;
	int c;
	int ans = 1;

	cin >> c;
	
	for (int i = 1; i < n; i++) {
		int p;
		cin >> p;
		if (c >= p) {
			ans++;
			c = min(c, p);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
     int a, b, c;
     scanf("%d %d %d", &a, &b, &c);

     printf("%d\n", a * b / 2);
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PA pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e16+7;
const ll MOD=1e9+7;

// http://sesenosannko.hatenablog.com/entry/2017/09/01/214852
// https://beta.atcoder.jp/contests/abc061/submissions/3322496
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3166760#1
// 0-index
struct Bellman_Ford{
	struct edge{ll from, to, cost;};
	ll inf = 1e16;
	vector<edge> es;
	vector<ll> d;
	ll V,E;
	Bellman_Ford(ll v,ll e){init(v,e);}
	void init(ll v,ll e){
		V = v; E = e;
		d.resize(V);
	}
	void shortest_path(ll s){
		FOR(i,0,V) d[i] = inf;
		d[s] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
				}
			}
		}
	}
	bool find_negative_loop(){// all graph
		FOR(i,0,V)d[i] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i == V-1) return true;
				}
			}
		}
		return false;
	}
	bool find_negative_loop(ll s){// from s
		ll cnt = 0;
		FOR(i,0,V)d[i]=inf;
		d[s]=0;
		while(true){
			bool update = false;
			cnt++;
			FOR(i,0,E){
				edge e = es[i];
				if(d[e.from] != inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(cnt == V){
						return true;
					}
					update = true;
				}
			}
			if(! update)break;
		}
		return false;
	}
	bool shortest_path(int s, int t){ // t: destination
		FOR(i,0,V)d[i] = inf;
		d[s] = 0;
		FOR(i,0,2*V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i>=V-1 && e.to==t) return true;
				}
			}
		}	
		return false;
	}
};

int main(){
	int n,m,a,b;
	cin >> n >> m;
	Bellman_Ford bf(n,m);
	FOR(i,0,m){
		cin >> a >> b;
		bf.es.push_back({a,b,-1});
	}
	if(bf.find_negative_loop()){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
}


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

int main() 
{
    int n,x,y,i,j;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+ abs(arr[i]-arr[i-1]),dp[i-2]+ abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int n, p[21], i;

    scanf("%d",&n);
    for(i=1; i<=n; i++){
        scanf("%d",&p[i]);
    }

    int x=0;    
    for(i=2; i<n; i++){
        if(((p[i]>p[i-1])&&(p[i]<p[i+1])) || ((p[i]<p[i-1])&&(p[i]>p[i+1]))){
            x++;
        }
    }
    
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
int N;

long long int C;

vector<pair<long long int, long long int> > P, Q;
vector<long long int> x, v;

long long int CLM[100005],CRM[100005];

int main(void) {

	cin >> N >> C;

	x.push_back(0); v.push_back(0);

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; x.push_back(tmp);
		cin >> tmp; v.push_back(tmp);
	}

	//===== P ====================
	for (int i = 0; i <= N; i++) {
		P.push_back(pair<long long int, long long int>(x[i], v[i]));
	}
	sort(P.begin(), P.end());

	//====== Q ======================
	Q.push_back(pair<long long int, long long int >(0, 0));
	for (int i = 1; i <= N; i++) {
		Q.push_back(pair<long long int, long long int>(C - P[i].first, P[i].second));
	}
	sort(Q.begin(), Q.end());

	//=============================

	long long int sum = 0; CLM[0] = 0; 
	long long int tmp_max=0;
	for (int i = 1; i <= N; i++) {
		sum += Q[i].second;      tmp_max = max(tmp_max, sum - 2 * Q[i].first); CLM[i] = tmp_max;
	}
	//====================
	sum = 0; CRM[0] = 0; tmp_max = 0;
	for (int i = 1; i <= N; i++) {
		sum += P[i].second;  tmp_max = max(tmp_max, sum - 2 * P[i].first); CRM[i] = tmp_max; /*cout << "tmp_max= " << tmp_max << endl;*/
	}


	//======= R rotation
	long long int ans = 0; sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += P[i].second;   ans = max(ans, sum - P[i].first + CLM[N - i]);
	}
	//===== L rotation
	sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += Q[i].second; ans = max(ans, sum - Q[i].first + CRM[N - i]);
	}

	
	cout << ans << endl;


	//system("pause");
	return 0;
}

Measured memory_bytes: 6632
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    cin>>N;
    long long int lis[200002];
    for(int i=0;i<N;i++)cin>>lis[i];
    sort(lis,lis+N);
    long long int ans=0;
    for(int i=1;i<N;i++){
        ans+=lis[N-1-(i/2)];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5196
from heapq import heappush, heappop, heapify

n = int(input())
g = [[] for _ in range(n)]

for i in range(n):
    for j,k in enumerate(map(int,input().split())):
        if k != -1:
            g[i].append((j,k))
#    print(g[i])

ocupied = [0]*n
que = [(j,k) for k,j in g[0]] # 重み、子の順番
#print(f'g[0]: {g[0]}')　#子、重みの順番
#print(f'que: {que}')
ocupied[0] = 1
heapify(que)

ans = 0
while que:
    cv,v = heappop(que)
    #print(f'cv, v: {cv}, {v}')
    if ocupied[v]: # vは頂点　どこでvが頂点になるか
        continue
    ocupied[v] = 1
    ans += cv
    for j,k in g[v]:
        if ocupied[j]:
            continue
        heappush(que,(k,j))
    #print(f'ocupied: {ocupied}')
print(ans)




Measured memory_bytes: 6660
N, D = map(int, input().split())

XY = [list(map(int, input().split())) for _ in range(N)]

res = 0

for xy in XY:
    x = xy[0]
    y = xy[1]
    
    if x ** 2 + y ** 2 <= D ** 2:
        res += 1

print(res)

Measured memory_bytes: 45376
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)//2+1):
    for j in range(len(s[i])):
        s[i][j] += max(s[i-1][max(j-1,0):min(j+1,len(s[i-1]))])
for i in range(len(s)//2+1,len(s)):
    for j in range(len(s[i])):
        s[i][j] += max(s[i-1][j:j+2])
print(s[-1][0])


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

int main() {
  string S;
  cin >> S;

  if ( S == "Sunny" ){
    cout << "Cloudy" << endl;
  }
  else if ( S == "Cloudy" ){
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}


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

int main() {
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    int cnt = 0;
    for ( int i = 0; i < N-1; ++i){
        if ( S.at(i) != S.at(i+1) ){
            ++ cnt;
        }
    }
    cnt = max( cnt - 2 * K, 0 );
    
    int ans;
    ans = N - cnt  -  1;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int w,h,xs,ys,xg,yg,n;
int map[101][101];
string ans;
char start;
void fun(int y,int x){
    if(map[y][x]==start){
        map[y][x]=7;
    }
    else
        return;
    if(x<1||w<x||y<1||h<y)
        return;
    if(map[y][x]==map[yg][xg]){
        ans="OK";
        return;
    }
    fun(y,x+1);
    fun(y,x-1);
    fun(y+1,x);
    fun(y-1,x);
}
void mc(){
    int c,d,x,y;
    for(int i=0;i<n;i++){
        cin >> c >> d >> x >> y;
        if(d==0){
            for(int j=0;j<2;j++){
                for(int k=0;k<4;k++){
                    map[y+j][x+k]=c;
                }
            }
        }
        else{
            for(int j=0;j<4;j++){
                for(int k=0;k<2;k++){
                    map[y+j][x+k]=c;
                }
            }
        }
    }
}
int main(){
    while(cin >> w >> h,w){
    	ans="NG";
        cin >> xs >> ys >> xg >> yg >> n;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                map[i][j]=0;
            }
        }
        mc();
        start=map[ys][xs];
        if(map[ys][xs]==0||map[yg][xg]==0);
        else
        	fun(ys,xs);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

template <typename T>
T Pow(T a, ll b) {
	T res = 1;
	while (b) {
		if (b & 1) {
			res *= a;
		}
		a *= a;
		b >>= 1;
	}
	return res;
}

struct mint {
	ll val;
	mint() : val(0) {}
	mint(ll v) : val(v % mod) {}
	mint& operator=(ll v) {
		val = v % mod;
		return *this;
	}
	operator int() {
		return (int)val;
	}
	operator ll() {
		return val;
	}
	mint operator+(mint v) {
		return val + v.val >= mod ? val + v.val - mod : val + v.val;
	}
	mint operator-(mint v) {
		return val - v.val < 0 ? val - v.val + mod : val - v.val;
	}
	mint operator*(mint v) {
		return val * v.val % mod;
	}
	mint operator/(mint v) {
		return val * v.inv().val % mod;
	}
	mint inv() {
		return Pow(*this, mod - 2);
	}
	mint& operator+=(mint v) {
		*this = *this - v;
		return *this;
	}
	mint& operator-=(mint v) {
		*this = *this - v;
		return *this;
	}
	mint& operator*=(mint v) {
		*this = *this * v;
		return *this;
	}
	mint& operator/=(mint v) {
		*this = *this / v;
		return *this;
	}
};

istream& operator >> (istream& is, mint m) {
	is >> m.val;
	return is;
}

ostream& operator << (ostream& os, mint m) {
	os << m.val;
	return os;
}
const int MAX = 1e5;
mint fac[MAX + 2];
void init() {
	fac[0] = 1;
	for (int i = 1; i <= MAX + 1; i++) {
		fac[i] = fac[i - 1] * mint(i);
	}
}

mint combi(int n, int k) {
	if (k < 0 || k > n) return 0;
	return fac[n] / fac[k] / fac[n - k];
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> used(n, -1);
	int f, b;
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i]; a[i]--;
		if (used[a[i]] != -1) {
			f = used[a[i]];
			b = i;
		}
		used[a[i]] = i;
	}
	init();
	for (int i = 1; i <= n + 1; i++) {
		cout << (combi(n + 1, i) - combi(n - b + f, i - 1)) << endl;
	}
	return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int N=26;

int main(){
  int D;
  cin>>D;
  int c[N];
  REP(i,N)cin>>c[i];
  int s[D][N];
  REP(d,D)REP(n,N)cin>>s[d][n];
  REP(i,D)cout<<1<<endl;
  return 0;
}


Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 1010;
int Sx,Sy,Tx,Ty;
int N,M;
char mp[SIZEN][SIZEN];
int id[SIZEN][SIZEN];  
int root[SIZEN * SIZEN];
int f[SIZEN * SIZEN];
int xx[] = {0,0,0,-1,1};
int yy[] = {0,-1,1,0,0};

struct Link{
    int to,next;
}link[SIZEN * SIZEN * 50];
int head [SIZEN * SIZEN];
int tot = 0;
void add(int from,int to){
    link[++tot].to = to;
    link[tot].next = head[from];
    head[from] = tot;
}
int find(int x){
    if(root[x] == x)return root[x];
    return root[x] = find(root[x]);
}
queue<int> q;
void BFS(){
    memset(f,0x3f,sizeof f);
    f[find(id[Sx][Sy])] = 0;
    q.push(find(id[Sx][Sy]));
    while(!q.empty()){
        int x = q.front();q.pop();
        if(x == find(id[Tx][Ty])){
            printf("%d\n",f[x]);
            return;
        }
        for(int i = head[x];i;i=link[i].next){
            int p = link[i].to;
            if(f[p] <= f[x] + 1)continue;
            f[p] = f[x] + 1;
            q.push(p);
        }
    }
    puts("-1");
}

int main(){
    scanf("%d%d",&N,&M);
    scanf("%d%d%d%d",&Sx,&Sy,&Tx,&Ty);
    for(int i = 1;i <= N;i++){
        scanf("%s",mp[i] + 1);
    }
    int cnt = 0;
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= M;j++)id[i][j] = ++cnt;
    }
    for(int i = 1;i <= cnt;i++)root[i] = i;
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= M;j++){
            if(mp[i][j] == '#')continue;
            for(int k = 1;k <= 4;k++){
                int x = i + xx[k],y = j + yy[k];
                if(x < 1 || y < 1 || x > N || y > M || mp[x][y] == '#'){
                    continue;
                }
                int fa = find(id[x][y]);
                int fb = find(id[i][j]);
                if(fa == fb)continue;
                root[fa] = fb;
            }
        }
    }
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= M;j++){
            if(mp[i][j] == '#')continue;
            for(int l = -2;l <= 2;l++){
                for(int r = -2;r <= 2;r++){
                    int x = i + l,y = j + r;
                    if(x < 1 || y < 1 || x > N || y > M || mp[x][y] == '#'){
                        continue;
                    }
                    int fa = find(id[x][y]);
                    int fb = find(id[i][j]);
                    if(fa == fb)continue;
                    add(fa,fb);
                    add(fb,fa);
                }
            }
        }
    }
    BFS();
    return 0;
}

Measured memory_bytes: 49196
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int k,n;
  cin >> k >> n;
  int a[n+1];
  LOOP(i,n){
    cin >> a[i];
  }a[n] = k+a[0];

  int mindis = 0;
  LOOP(i,n){
    mindis = max(a[i+1]-a[i], mindis);
  }

  cout << (k-mindis) << endl;

}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

public class Main {

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

		String str = br.readLine();

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

		TreeSet<String> set = new TreeSet<>();

		for (int i = 0; i < str.length(); i++) {
			for (int j = 1; j <= 5; j++) {
				if (i + j <= str.length()) {
					set.add(str.substring(i, i + j));
				}
			}
		}
		List<String> list = new ArrayList<>(set);
		System.out.println(list.get(K - 1));
	}
}

Measured memory_bytes: 36628
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

struct SCC{//O(V+E)
    static const int MAX_V = 101000;
    int V;
    vector<int> G[MAX_V], rG[MAX_V];
    vector<int> vs;
    bool used[MAX_V];
    int cmp[MAX_V];
    vector<vector<int> > res;
 
 
    SCC(int v) : V(v){};
    void add_edge(int from, int to){
        G[from].push_back(to);
        rG[to].push_back(from);
    }
 
    void dfs(int v){
        used[v] = true;
        for(int i = 0; i < G[v].size(); i++){
            if(!used[G[v][i]]) dfs(G[v][i]);
        }
        vs.push_back(v);
    }
    void rdfs(int v, int k){
        used[v] = true;
        cmp[v] = k;
        for(int i = 0; i < rG[v].size(); i++){
            if(!used[rG[v][i]]) rdfs(rG[v][i], k);
        }
    }
 
    int scc(){
        memset(used, 0, sizeof(used));
        vs.clear();
        for(int v = 0; v < V; v++){
            if(!used[v]) dfs(v);
        }
        memset(used, 0, sizeof(used));
        int k = 0;
        for(int i = vs.size() - 1; i >= 0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
 
        res.clear();
        res.resize(k);
        for(int i = 0; i < V; i++){
            res[cmp[i]].push_back(i);
        }
        return k;
    }
};

int main(){
	int ans = 0;
	int n;
	cin>>n;
	SCC scc(n);
	rep(i, n) {
		int a;
		cin>>a;
		(a += i ) %= n;
		if(a == i) ans++;
		else scc.add_edge(i, a);
	}
	scc.scc();
	for(auto a : scc.res) {
		if(a.size()!=1) ans += a.size();
	}
	cout << ans << endl;
}

Measured memory_bytes: 18368
r=[*?A..?Z]
x=Hash[(r+" .,-'?".chars).zip (0..31).map{|i|"%05b"%[i]}]
y=/1(1.|0(1|0(0|1(1.#{z="..|0(1|0..)))"}))|0(1(1.|0(1|0(1|0.)))|0(1#{z}/,Hash["dggigggieedfigeiefiifdieffiigiii".bytes.map{|i|i-97}.zip("836$D4X-849<.C:+97,18:2;9:/05%&#".bytes.map{|c|c<51?c+109:c-51}).map{|a|"%0*b"%a}.zip" ',-.?".chars+r]
puts$<.map{|l|l.gsub(/./,x).gsub(*y).delete ?0}

Measured memory_bytes: 6116
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N, L = mulinputs()
    datas = []
    for _ in range(N):
        datas.append(input())
    datas.sort()
    # 出力
    print(''.join(datas))



# EOF

Measured memory_bytes: 5284
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define ll long long int

#define rep(p,q) for(int i = p; i < q;i++)


//8
int main(void) {
	int n;
	while (cin >> n) {
		if (n > 36) cout << 0 << endl;
		else {
			int ans = 0;
			for (int i = 0; i < 10; i++) {
				int sum = i;
				for (int j = 0; j < 10; j++) {
					sum = i;
					sum += j;
					if (sum > n)continue;
					for (int k = 0; k < 10; k++) {
						sum = i + j;
						sum += k;
						if (sum > n)continue;
						for (int l = 0; l < 10; l++) {
							sum = i + j + k;
							sum += l;
							if (sum == n) ans++;
						}
					}
				}
			}
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    long double sum = 0;
    ll ans = 1;
    for(int i = 0; i < n; i++) {
        long double x;
        cin >> x;
        if(x == 0) {
            cout << 0 << endl;
            return 0;
        }
        sum += log10l(x);
        ans *= x;
    }
    if(sum > 18 || ans > ll(1000000000000000000)) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 3816
N = int(input())

ac = wa = tle = re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)



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

#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int n, m, k;

int main(int argc, char const *argv[])
{
  scanf("%d %d %d" , &n, &m, &k);
  for(int a = 0 ; a <= n ; a++){
  	for(int b = 0 ; b <= m ; b++){
  		if(k == (a*m + b*n - 2*a*b)){
  			printf("Yes");
  			return 0;
  		}
  	}
  }
  printf("No");
  return 0;
}  

Measured memory_bytes: 256
def koyaku(a, b)
  loop do
    rem = b % a
    return a if rem == 0
    a, b = rem, a
  end
end

def kobai(a, b)
  (a * b) / koyaku(a, b)
end

while str = gets
  a, b = str.split(' ').map(&:to_i).sort
  puts "#{koyaku(a, b)} #{kobai(a, b)}"
end

Measured memory_bytes: 8632
def main():
    a, b, c, x = [int(input()) for i in range(4)]

    correct = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    correct += 1

    print(correct)


if __name__ == '__main__':
    main()


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")  
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007

ll gcd(ll x, ll y){ 
	if(x<y) 
		swap(x,y); 
	if(x%y==0)
		return y;
	return gcd(y, x%y);
}

ll pwm(ll a, ll n){
	ll ans = 1;
	while(n>0){
		if(n%2==1){
			ans = (ans * a)%mod;
		}
		a = (a*a)%mod;
		n /= 2;
	}
	return ans%mod;
}

const int pwn = 100010;
ll pw[pwn];
void pwtwo(){
	pw[0] = 1;
	for(int i=1; i<pwn; i++){
		pw[i] = (pw[i-1]*2)%mod;
	}
}


ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
ll modInverse(ll a, ll m) 
{ 	
	if(a==1)
		return 1;
	//cout<<"mi "<<a<<" "<<m<<" ";
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1){
        //cout << "Inverse doesn't exist"<<endl; 
        return -1;
    }
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        //cout<<res<<endl;
        return res;
        // cout << "modular multiplicative inverse is " << res; 
    } 
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll fact[1000010];
ll init(){
	fact[0] = 1;
	for(int i=1; i<1000010; i++)
		fact[i] = (fact[i-1]*i)%mod;
}

ll ncr(ll n, ll r){
	ll ans = fact[n];
	// cout<<ans<<" ";
	if(r>n)
		return 0;
	//if(r!=0)
	ans = (ans*modInverse(fact[r], mod))%mod;
	// if(n-r!=0)
	ans = (ans*modInverse(fact[n-r], mod))%mod;

	return ans;
}

int main(){
	// finput;
	// foutput;
	fast;

	ll n, k, i, j, x, m, r;
	ll ans = 0ll;
	// string s;
	cin>>n;
	init();
	// vector<int> vec;
	
	i=(n+1)/2;

	ll pre = 0;
	while(i<=n-1){
		r = n-1-i;
		// cout<<i<<" "<<n-2ll-r<< " "<<r<<" ";
		x = ((ncr(n-2ll-r, r)%mod)*((fact[r]*fact[i])%mod))%mod;
		// cout<<x<<endl;
		x = (x + mod - pre)%mod;
		
		pre += x;
		pre %= mod;

		// cout<<x;
		ans += (i*x)%mod;
		ans %= mod;

		i++;
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

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

using namespace std;

int main(){
  int n,x=0;
  cin>>n;
  string s;
  cin>>s;
  int result=0;
  rep(i,n){
    if(s[i]=='I'){
      x++;
      if(x>result)result=x;
    }else{
      x--;
    }
  }

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
priority_queue<ll>Q;
vector<ll> v[100010];
int main(){
  ll n,m; cin>>n>>m;
  for(int i=0;i<n;i++){
    ll a,b; cin>>a>>b;
    v[a].push_back(b);
  }
  ll ans=0;
  for(int i=1;i<=m;i++){
    for(auto t:v[i])Q.push(t);
    if(!Q.empty()){
      ans+=Q.top();
      Q.pop();
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <memory.h>
#include <cstdio>
using namespace std;
int main(){
  int i,n,m,l,x,y,a[21][21];
  char d;
  while(1){
    cin>>n;
    if(!n)
      break;
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      a[x][y]=1;
    }
    x=y=10;
    scanf("%d",&m);
    while(m--){
      cin>>d>>l;
      if(d=='N'){
	for(i=0;i<l;i++){
	  y++;
	  if(a[x][y]){
	    a[x][y]=0;
	    n--;
	  }
	}
      }
      else if(d=='E'){
	for(i=0;i<l;i++){
	  x++;
	  if(a[x][y]){
	    a[x][y]=0;
	    n--;
	  }
	}
      }
      else if(d=='S'){
	for(i=0;i<l;i++){
	  y--;
	  if(a[x][y]){
	    a[x][y]=0;
	    n--;
	  }
	}
      }
      else{
	for(i=0;i<l;i++){
	  x--;
	  if(a[x][y]){
	    a[x][y]=0;
	    n--;
	  }
	}
      }
    }
    if(!n)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define nl cout<<'\n'
#define nll <<'\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
int main()
{
    char a[7];
    cin>>a;
    if(a[2]==a[3] && a[4]==a[5]) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define SZ(c) int(c.size())
#define ff first
#define ss second
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	double ans = 0.0;
	ans += a[n - 1] / 2;
	for (int i = 0; i < n - 1; i++)
		ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = get_str()
    if 15 - len(s) + s.count("o") >= 8:
        print('YES')
    else:
        print('NO')
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65516
// ABC057C - Digits in Multiplication

#include <bits/stdc++.h>
using namespace std;

int F(long long int A, long long int B) {
	int ans = 0;
	long long int maxT = max(A, B);

	while (maxT > 0) {
		ans++;
		maxT /= 10;
	}

	return ans;
}

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

	int minT = 11;
	for (long long int A = 1; A <= (long long int)sqrt(N) + 1; A++) {
		long long int B;
		B = N / A;
		if (A * B == N) {
			minT = min(minT, F(A, B));
		}
	}

	cout << minT << endl;

	return 0;
}


Measured memory_bytes: 256
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=3005;
int dp[N][N][2];int a[N];
void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int l=1;l<=n;l++)
    {
        for(int i=0;i<=n-l;i++)
        {
            int j=i+l-1;
            if(l==1)
            {
                dp[i][j][0]=a[i];
                dp[i][j][1]= -a[i];
            }
            else
            {
                dp[i][j][0]=max(dp[i][j-1][1]+a[j],a[i]+dp[i+1][j][1]);
                dp[i][j][1]=min(dp[i][j-1][0]-a[j],dp[i+1][j][0]-a[i]);
            }
        }
    }
    cout<<dp[0][n-1][0]<<endl;
    
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int N, H[100005], dp[100005];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> H[i];
	dp[0] = 1e9;
	dp[1] = 0;
	for (int i = 2; i <= N; i++)
		dp[i] = min(dp[i - 1] + llabs(H[i] - H[i - 1]), dp[i - 2] + llabs(H[i] - H[i - 2]));
	cout << dp[N] << '\n';
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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, a, b;

int main() {
    cin >> n >> a >> b;

    ll x = n / (a + b);
    ll amari = n - (a+b) * x;
    cout << x * a + min(amari, a) << endl;
}


Measured memory_bytes: 256