akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};
int main() {
	//sort(a.begin(),a.end());
	ll n;
	cin >> n;
	ll ans=0;
	ans += 1000 * (n / 500);
	n = n % 500;
	ans += 5 * (n / 5);
	cout << ans;
	return 0;
}









Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
  a, b = map(int, input().split())
  graph[a].append(b); graph[b].append(a)

d = deque([[1, 0]])
par = [0] * (N+1)
while d:
  node, p = d.popleft()
  children = graph[node]
  for child in children:
    if child == p or par[child] != 0:
      continue
    par[child] = node
    d.append([child, node])

print('Yes')
print(*par[2:], sep='\n')

Measured memory_bytes: 39924
#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 INF = 1001001001;

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

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int n;
//ll dp[100005][3];
int main() {
    int n;
    cin >> n;
    int a[n][3];
    rep(i,n) rep(j,3) cin >> a[i][j];
    vector<vector<int>> dp(n+1, vector<int>(3));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i < 3; i++) chmax(res, dp[n][i]);
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 9876
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll a,b;
	rl2(a,b);
	ll ansa=0,ansb=0;
	fr(i,0,b)
		ansa=ansa*10+a;
	fr(i,0,a)
		ansb=ansb*10+b;
	ll ans=max(ansa,ansb);
	cout<<ans<<endl;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	getchar_unlocked();
	char S[300][300];

	int kara[300] = {};
	int hajimete = 500;
	rep(i, H) {
		int aru = 0;
		rep(j, W) if ((S[i][j] = getchar_unlocked()) == '#') aru = 1;
		getchar_unlocked();
		if (!aru) kara[i] = 1;
		if (aru && hajimete == 500) hajimete = i;
	}

	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		if (!kara[i]) {
			k++;
			int aru = 0;
			rep(j, W) {
				if (S[i][j] == '#') {
					if (aru == 0) aru = 1;
					else k++;
				}
				kotae[i][j] = k;
			}
		}
		else if (hajimete < i) {
			rep(j, W) kotae[i][j] = kotae[i - 1][j];
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) putint(kotae[i][j]);

	fwrite(dn, 1, di - dn, stdout);


	Would you please return 0;
}

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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> v;
  for (int i = 0; i < n; ++i) {
    int tmp;
    std::cin >> tmp;
    v.push_back(tmp);
  }
  int count_of_dequeue = std::min(n, k);
  int max_value = 0;
  for (int a = 0; a <= count_of_dequeue; ++a) {
    for(int b = 0; b + a <= count_of_dequeue; ++b) {
      std::vector<int> negative_nums;
      int value = 0;
      for(int a2 = 0; a2 < a; ++a2) {
        value += v.at(a2);
        if (v.at(a2) < 0) {
          negative_nums.push_back(v.at(a2));
        }
      }
      for(int b2 = 0; b2 < b; ++b2) {
        value += v.at(n-1-b2);
        if (v.at(n-1-b2) < 0) {
          negative_nums.push_back(v.at(n-1-b2));
        }
      }
      std::sort(negative_nums.begin(), negative_nums.end());
      for (int i = 0; i < std::min((k-a-b), static_cast<int>(negative_nums.size())); ++i) {
        value -= negative_nums.at(i);
      }
      max_value = std::max(value, max_value);
    }
  }
  std::cout << max_value << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){

    string c;
    while(1){
        cin>>c;
        if(c[0]==c[1]&&c[1]==c[2]&&c[2]==c[3]){
            if(c[0]=='0')break;
            cout<<"NA"<<endl;
            continue;
        }
        int a[4];
        for(int i=0;i<4;i++){
            a[i] = c[i] - '0';
        }
        int t=0;
        while(t++,1){
            if(a[0]==6&&a[1]==1&&a[2]==7&&a[3]==4){
                cout<<t-1<<endl;
                break;
            }
            int L,S;
            sort(a,a+4);
            L = a[0]+10*a[1]+100*a[2]+1000*a[3];
            reverse(a,a+4);
            S = a[0]+10*a[1]+100*a[2]+1000*a[3];
            int next = L - S;
            a[3] = next%10;
            a[2] = (next/10)%10;
            a[1] = (next/100)%10;
            a[0] = (next/1000)%10;
        }

    }
    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

ll a[1000100], n;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    ll sum = 0, t=0;
    for(ll i=0 ; i<n ; i++){
        cin >> a[i];
        sum += a[i];
        t += i+1;
    }
    if(sum % t != 0){
        cout << "NO\n";
        return 0;
    }
    ll rem = sum / t;
    for(ll i=0 ; i<n ; i++){
        ll x = a[(i+1)%n] - a[i] - rem;
        if(x > 0 || (-x) % n != 0){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

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


int main(){
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    long long res=0;
    if(K <= A) res=K;
    else if(K > A && K <= B) res=A;
    else res=A-(K-A-B);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
L = [[] for i in range(k)]
for i in range(n):
    L[i%k].append(t[i])
ans = 0
for i in range(k):
    if L[i][0] == 's':
        ans += r
    elif L[i][0] == 'p':
        ans += s
    else:
        ans += p
    lose = False
    for j in range(1,len(L[i])):
        if L[i][j] != L[i][j-1]:
            lose = False
            if L[i][j] == 's':
                ans += r
            elif L[i][j] == 'p':
                ans += s
            else:
                ans += p
        elif L[i][j] == L[i][j-1]:
            if lose == True:
                if L[i][j] == 's':
                    ans += r
                elif L[i][j] == 'p':
                    ans += s
                else:
                    ans += p
                lose = False
            else:
                lose = True
print(ans)


Measured memory_bytes: 13436
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a;cin>>a;
  double c,b=0,d;
  rep(i,a){
    cin>>c;
    b+=1/c;
    
  }
  cout<<fixed<<setprecision(12)<<1/b;
}

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

int32_t main() {
 int n;
 cin >> n;
 vector <int> cnt(100001);
 int sum = 0;
 for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    sum += x;
 }

 int q;
 cin >> q;
 while(q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << "\n";
 }
 return 0;
}


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

int main(int argc, const char * argv[]) {
    int H;
    int W;
    int cnt;
    string A[55];
  
    cin >> H >> W;
    for(int i = 0; i < H; i++){
          cin >> A[i];
    }

    for(int i = 0; i < H; i++){
       for(int j = 0; j < W; j++){
          cnt = 0;
          if(A[i][j] == '.'){
              if(A[i-1][j-1] == '#') ++cnt;
              if(A[i-1][j] == '#') ++cnt;
              if(A[i-1][j+1] == '#') ++cnt;
              if(A[i][j-1] == '#') ++cnt;
              if(A[i][j+1] == '#') ++cnt;
              if(A[i+1][j-1] == '#') ++cnt;
              if(A[i+1][j] == '#') ++cnt;
              if(A[i+1][j+1] == '#') ++cnt;
              A[i][j] = '0' + cnt;
          }
       }
    }

    for(int i = 0; i < H; i++){
             cout << A[i] << endl;
    }

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
    int h,w;cin>>h>>w;
    int c[210][210];for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>c[i][j];
	for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;cin>>a;
            if(a!=-1){
                ans+=c[a][1];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int s;
vector<int> used(1000001, 0);

int collatz(int i, int v) {
  if(used[v]) return i;
  used[v] = 1;
  int x = (v % 2 == 0 ? v/2 : 3*v+1);
  return collatz(i+1, x);
}

int main () {
  cin >> s;

  cout << collatz(1, s) << endl;

  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll N, K, Q;
	cin >> N >> K >> Q;
	vector<ll> data(N,0);
	K -= Q;
	while (Q--)
	{
		ll c;
		cin >> c;
		c--;
		data.at(c)++;
	}

	FOR(i, 0, N)
	data.at(i) = K + data.at(i);

	FOR(i,0,N){
		if(data.at(i)>0)
			Yes();
		else
			No();
	}

	return 0;
}



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

int main() {
	while(1){
	int n,a,i=0;
	cin>>n;
	if(n==0)
		break;
	a=1000-n;
	if(a>=500){
		i+=1;
		a-=500;
	}
	if(a>=100){
		int b=a/100;
		i+=b;
		a-=100*b;
	}
	if(a>=50){
		i+=1;
		a-=50;
	}
	if(a>=10){
		int b=a/10;
		i+=b;
		a-=10*b;
	}
	if(a>=5){
		i+=1;
		a-=5;
	}
	if(a>=1)
		i+=a;
	cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define mp std::make_pair
#define pb push_back
using ll = long long;
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }

constexpr int MOD = 998244353;
inline ll quick_pow(ll a, ll n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

std::map<std::pair<int, int>, int> app, lim;
ll dp[200005][2];
int main()
try
{
	// freopen("caddi2018-F.in", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	ll ans = quick_pow(2, (ll)(n - 1) * (n - 2) / 2);
	while (m--)
	{
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		if (--l > --r)
			std::swap(l, r);
		if (app.count({l, r}) || l == r)
			lim[ {l, r}] = app[ {l, r}] ^ x;
		else
		{
			if (r - l + 1 >= 3)
				ans = ans * (MOD + 1) / 2 % MOD;
			app[ {l, r}] = x;
		}
	}
	for (auto &it : lim)
	{
		int l = it.first.first, r = it.first.second;
		if (r - l + 1 >= 4)
		{
			if (it.second)
				throw false;
		}
		if (r - l + 1 == 3)
		{
			if (lim.count({l + 1, r - 1}))
			{
				if (lim[ {l + 1, r - 1}] != it.second)
					throw false;
			}
			else
				lim[ {l + 1, r - 1}] = it.second;
		}
	}
	if (lim.count({0, 0}))
		dp[0][lim[ {0, 0}]] = 1;
	else
		dp[0][0] = dp[0][1] = 1;
	for (int i = 0; i + 1 < n; i++)
	{
		for (int x = 0; x < 2; x++)
		{
			if (!dp[i][x])
				continue;
			for (int y = 0; y < 2; y++)
			{
				if (lim.count({i + 1, i + 1}) && y != lim[ {i + 1, i + 1}])
					continue;
				int z = x ^ y;
				if (lim.count({i, i + 1}) && z != lim[ {i, i + 1}])
					continue;
				(dp[i + 1][y] += dp[i][x] * (!app.count({i, i + 1}) + 1)) %= MOD;
			}
		}
	}
	printf("%lld\n", ans * (dp[n - 1][0] + dp[n - 1][1]) % MOD);
	return 0;
}
catch (bool)
{
	puts("0");
	return 0;
}


Measured memory_bytes: 8320
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = [] # heapでソートを保つ
added = defaultdict(int) # 入ってる個数

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    added[c] -= 1
  elif b&1: # b == 1
    heappush(se,c)
    added[c] += 1
  else: # b == 2
    while se and added[se[0]] == 0:
      heappop(se)
    answer[c] = se[0] if se else -1

print('\n'.join(map(str,answer)))


Measured memory_bytes: 146992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {
	long long n, a, b, loop, blue, leave;
	scanf("%lld %lld %lld", &n, &a, &b);
	loop = n / (a + b);
	blue = a * loop;
	leave = n - (a + b) * loop;
	if (leave == 0) {
		;
	}
	else if (leave >= a) {
		blue += a;
	}
	else {
		blue += leave;
	}
	
	printf("%lld", blue);
		
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

#define lowbit(x) x & (-x)
#define lson left,mid,root << 1
#define rson mid+1,right,root << 1 | 1

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=2e6+100;	

int n;
int a[maxn];
int b[maxn];
char s[maxn];


int main()
{
	scanf("%d",&n);
	scanf("%s",s + 1);
	for(int i = 1; i <= n; i ++)
		a[i] = a[i - 1] + (s[i] == '#');
	for(int i = n; i >= 1; i --)
		b[i] = b[i + 1] + (s[i] == '.');
	
	int ans = inf;
	for(int i = 0; i <= n; i ++)
		{
			ans = min(ans, a[i] + b[i + 1]);
		}
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int ans;
  rep(i,5){
    int x; cin >> x;
    if(x==0){ ans=i+1;}
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 3624
//配るdp
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll N;
    cin >> N;
    ll dp[MAX];
    ll i, j;
    
    for(i=1; i<=N; i++) dp[i]=INF;
    dp[0]=0;
    
    for(i=1; i<=N; i*=6) {
        for(j=0; i+j<=N; j++) {
            chmin(dp[i+j], dp[j]+1);
        }
    }
    
    for(i=1; i<=N; i*=9) {
        for(j=0; i+j<=N; j++) {
            chmin(dp[i+j], dp[j]+1);
        }
    }
    
    pt(dp[N]);
}


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

int main() {
    string s;
    cin >> s;
    int size = s.size();
    if (s[size - 1] == 's') {
        cout << s + "es" << endl;
    } else {
        cout << s + 's' << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  for(int i=0;i<2;i++)
    if(s[i] == s[i+1] && s[i+1] == s[i+2])
    {
      cout << "Yes";
      return 0;
    }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MAX_N = (int)5007;

ll fact[MAX_N], invfact[MAX_N];

ll binpow(ll x, ll y)
{
	if(!y)
		return 1;

	ll ret = binpow(x, y >> 1LL);
	ret = (ret * ret) % mod;

	if(y & 1)
		ret = (ret * x) % mod;

	return ret;
}

ll c(ll i, ll j)
{
	ll answ = fact[i];

	answ = (answ * invfact[j]) % mod;
	answ = (answ * invfact[i - j]) % mod;

	return answ;
}

ll count(ll value, ll part)
{
	if(part == 0)
		return 0;

	if(part > value)
		return 0;

	return c(value - 1, part - 1);
}

void solve()
{
	fact[0] = 1;

	for(ll a = 1; a < MAX_N; ++a)
		fact[a] = (a * fact[a - 1]) % mod;

	for(ll a = 0; a < MAX_N; ++a)
		invfact[a] = binpow(fact[a], mod - 2);

	ll n, k;
	cin >> n >> k;

	if(k == n)
	{
		cout << "1\n";

		for(ll a = 2; a <= n; ++a)
		{
			cout << "0\n";
		}

		return;
	}

	for(ll a = 1; a <= k; ++a)
	{
		ll answ = 1, mlt = 0;

		mlt = (mlt + count(n - k, a - 1)) % mod;
		DBG(mlt);
		mlt = (mlt + 2 * count(n - k, a)) % mod;
		DBG(mlt);
		mlt = (mlt + count(n - k, a + 1)) % mod;
		DBG(mlt);

		answ = (answ * count(k, a)) % mod;
		answ = (answ * mlt) % mod;

		cout << answ << "\n";
	}
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

typedef long double lld;

#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))

ll r, D;
ll x[100];

int main()
{
	cin >> r >> D;
	cin >> x[0];
	for (int i = 0; i < 10; i++)
	{
		x[i + 1] = r * x[i] - D;
		cout << x[i + 1] << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
int N, a[100], b=0;
int main() {
    scanf("%d", &N);
    if(N==0){printf("0"); return 0;}
    while(N!=0){
        a[b]=N&1;
        if(b%2) N+=2*(N&1);
        b++;
        N>>=1;
    }
    for(int i=b; i>0; i--) printf("%d", a[i-1]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,V,dp[3005][3005],maxw[3005],ans;
pii p[3005];
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> V;
	rep(i,1,n) cin >> p[i].fi >> p[i].se;
	sort(p+1,p + n+1);
	for(int i = n;i >= 1;i--) maxw[i] = max(maxw[i + 1],p[i].se);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < V;j++){
			dp[i][j] = dp[i-1][j];
			if(j >= p[i].fi) dp[i][j] = max(dp[i][j],dp[i-1][j-p[i].fi] + p[i].se);
		}
		ans = max(ans,dp[i][V-1] + maxw[i + 1]);
	}
	cout << ans << endl;		
	return 0; 
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int numOfDigits(long long n) {
  int num = 0;
  while (n > 0) { // n が 0 になるまで
    n /= 10;
    ++num;
  }
  return num;
}

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

int N; cin >> N;
int cnt = 0;

rep(i, 1, N+1){
    if(numOfDigits(i) % 2 == 1) ++cnt;
}

cout << cnt << "\n";

return 0;
}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = a[0]

nn = (n-2)//2
nnn = (n-2)%2

for i in range(nn):
    ans = ans + a[i+1]*2

if nnn == 1:
    ans = ans + a[i+2]

print(ans)

Measured memory_bytes: 31604
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_R = 30;
const int MAX_C = 30;
const int MAX_K = 3;

const int INF = 1 << 30;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

/* typedef */

struct Stat {
  int d, x, y;
  Stat() {}
  Stat(int _d, int _x, int _y): d(_d), x(_x), y(_y) {}
  bool operator<(const Stat &s) const { return d > s.d; }
};

/* global variables */

string flds[MAX_R];
int dists[MAX_R][MAX_C];

/* subroutines */

/* main */

int main() {
  int r, c;
  cin >> r >> c;

  int sx, sy, gx, gy;

  for (int y = 0; y < r; y++) {
    cin >> flds[y];
    for (int x = 0; x < c; x++)
      switch (flds[y][x]) {
      case 'S': flds[y][x] = '.'; sx = x; sy = y; break;
      case 'G': flds[y][x] = '.'; gx = x; gy = y; break;
      }
  }
  //printf("(%d,%d)-(%d,%d)\n", sx, sy, gx, gy);

  for (int y = 0; y < r; y++)
    for (int x = 0; x < c; x++) dists[y][x] = INF;
  dists[sy][sx] = 0;

  priority_queue<Stat> q;
  q.push(Stat(0, sx, sy));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (dists[u.y][u.x] != u.d) continue;

    if (u.x == gx && u.y == gy) break;

    for (int di = 0; di < 4; di++) {
      int on = 0, xn = 0;
      for (int k = 1; k <= MAX_K; k++) {
	int vx = u.x + dxs[di] * k, vy = u.y + dys[di] * k;
	if (vx >= 0 && vx < c && vy >= 0 && vy < r) {
	  if (flds[vy][vx] == '#') break;
	  if (flds[vy][vx] == 'o') on++;
	  else if (flds[vy][vx] == 'x') xn++;
	  int vd = u.d + ((xn > 0) ? 2 + k : min(2 + k, k * 2 - on));
	  if (dists[vy][vx] > vd) {
	    dists[vy][vx] = vd;
	    q.push(Stat(vd, vx, vy));
	  }
	}
      }
    }
  }

  printf("%d\n", dists[gy][gx]);
  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
  	int N;
  	int A[100000];
  	int ans = 1145141919;
  	cin >> N;
  	for(int i = 0; i < N; i++){
    	cin >> A[i];
      	if(i >= 1)ans = min(ans, gcd(A[i], A[i - 1]));
    }
  	cout << ans << endl;
 	return 0; 
}

Measured memory_bytes: 640
import sys


def main():
    n = int(input())
    ws = [input() for _ in range(n)]

    for i in range(n-1):
        if ws.count(ws[i]) > 1:
            print('No')
            sys.exit(0)

        if ws[i][-1] != ws[i+1][0]:
            print('No')
            sys.exit(0)

    print('Yes')


if __name__ == "__main__":
    main()


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

int main(){
    string s; cin >> s;
    string t="";
    int q; cin >> q;
    rep(i,q){
        int ty; cin >> ty;
        if(ty==1){
            swap(s,t);
        }
        else{
            int f; cin >> f;
            string c; cin >> c;
            if(f==2){
                s+=c;
            }
            else t+=c;
        }
    }
    reverse(t.begin(),t.end());
    cout << t+s << endl;
}

Measured memory_bytes: 1312
N=int(input())
graph=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
dfs_stack_Fennec=[0]
dfs_stack_Snuke=[N-1]
depth_Fennec=[-1]*N
depth_Snuke=[-1]*N
depth_Fennec[0]=0
depth_Snuke[N-1]=0
while dfs_stack_Fennec or dfs_stack_Snuke:
  s1=dfs_stack_Fennec.pop()
  s2=dfs_stack_Snuke.pop()
  for t1 in graph[s1]:
    if depth_Fennec[t1]==-1:
      depth_Fennec[t1]=depth_Fennec[s1]+1
      dfs_stack_Fennec.append(t1)
  for t2 in graph[s2]:
    if depth_Snuke[t2]==-1:
      depth_Snuke[t2]=depth_Snuke[s2]+1
      dfs_stack_Snuke.append(t2)
ans=0
for i in range(N):
  if depth_Fennec[i]<=depth_Snuke[i]:
    ans+=1
if 2*ans>N:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 59808
n,a,b = map(int,input().split())
total_sum = 0
for i in range(n+1):
  s = str(i)
  digit_sum = 0
  for j in range(len(s)):
    digit_sum += int(s[j])
  if a <= digit_sum <= b:

    total_sum += i

print(total_sum)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int tmp = i*1.08;
        if(tmp == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


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

    vector<ll> a(n),l(n),r(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    l[0]=a[0];
    for (int i = 1; i < n; i++)
    {
        l[i]=__gcd(l[i-1],a[i]);
    }
    r[n-1]=a[n-1];
    for (int i = n - 2; i >= 0; i--)
    {
        r[i]=__gcd(r[i+1],a[i]);
    }
    ll ans=max(r[1],l[n-2]);
    for (int i = 1; i < n-1; i++)
    {
        ll tmp = __gcd(l[i-1],r[i+1]);
        ans=max(ans,tmp);
    }
    
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
#define ll long long 
#define pb(a) push_back(a)
#define fi first
#define se second
#define rep(a,b,c) for(int a = b ;a<=c;a++)
#define repn(a,b,c) for(int a = b ; a>=c ; a--)
#define FOR(a,b,c) for(int a = b ; a<c ;a++)
#define mem(a,b) memset(a,b , sizeof(a))
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define Size(a) ((int)a.size())
#define ii int
const int INF=0x3f3f3f3f;
const int maxn=5e5+10;
const int maxk=30;



 int main(){

 	ll n , a , b;

 	cin>>n>>a>>b;

 	ll cnt = 0;

 	while(n -- ){
 		ll x;
 		cin>>x;

 		if(x >= a && x < b){

 		}else{
 			cnt++;
 		}
 	}

 	cout<<cnt<<endl;

    return 0;
 }

Measured memory_bytes: 256
s = input()
sets = set(s)
ls = list(s)
count = 100
if len(set(ls)) == 1:
    print(0)
else:
    for c in sets:
        tmp = ls.copy()
        cnt = 0
        while True:
            cnt += 1
            for i in range(len(tmp) - 1):
                if c in (tmp[i], tmp[i+1]):
                    tmp[i] = c
            tmp = tmp[:-1]
            if len(set(tmp)) == 1:
                break
        count = min(cnt, count)
    print(count)
        
        
            


Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var sw = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(sw[0] > sw[1] ? "safe" : "unsafe");
        }
    }
}


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

int bigmod(int a,int b,int M)
{
    if(b==0)
        return 1%M;
    int x=bigmod(a,b/2,M);
    x=(x*x)%M;
    if(b%2==1)
        x=(x*a)%M;
    return x;
}

int main()
{
    int ar[3];
    cin>>ar[0]>>ar[1]>>ar[2];
    sort(ar,ar+3);
    cout<<ar[2]*10+ar[1]+ar[0]<<endl;

    return 0;
}


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

int main(){
  int i,j,cnt=0;
  int n,x;
  cin>>n>>x;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n;i++){
    if(x>=a[i]){
      x-=a[i];
      cnt++;
    }
  }
  if(x>0 && cnt==n)cnt--;
  cout<<cnt;
}

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

int main() {
  string N;
  cin >> N;
  
  if (N[0] == '7') {
    cout << "Yes" << endl;
  }
  
  else if (N[1] == '7') {
    cout << "Yes" << endl;
  }
  
  else if (N[2] == '7') {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

black_idx = [(h,w) for h in range(H) for w in range(W) if A[h][w] == "#"]

distance = [[float("inf")]*W for _ in range(H)]
for b in black_idx:
    distance[b[0]][b[1]] = 0

d = deque(black_idx)
ans = 0

while d:
    y, x = d.popleft()
    for new_y, new_x in ([y+1, x], [y, x+1], [y-1, x], [y, x-1]):
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1 and distance[y][x] + 1 < distance[new_y][new_x]:
            distance[new_y][new_x] = distance[y][x] + 1
            ans = max(ans, distance[y][x] + 1)
            d.append([new_y, new_x])

print(ans)

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    rep(i, N) cin >> A[i];

    bool ok = true;
    for (auto a : A) {
        if (a % 2 == 0) {
            if (not(a % 3 == 0 or a % 5 == 0)) { ok = false; }
        }
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;

    return 0;
}

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

using namespace std;

int w,h,cnt,rest;
int x[1000],y[1001],dir[1001];
char in[51][51];
int fie[51][51];
int fie2[51][51];
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int sw[1000001][4];

int simulation(){
	int turn=0,rest=cnt;
	while(rest>0){
		turn++;
		if(turn>180)return -1;
		for(int i=0;i<cnt;i++){
			if(fie[x[i]][y[i]]==-2)continue;
			int ndir=(dir[i]+3)%4,j;
			for(j=0;j<4;j++){
				int nx=x[i]+dx[ndir],ny=y[i]+dy[ndir];
				if(nx>=0 && nx<w && ny>=0 && ny<h){
					if(fie[nx][ny]==0 || fie[nx][ny]==-1)break;
				}
				ndir=(ndir+1)%4;
			}
			if(j!=4){
				dir[i]=ndir;
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				fie2[j][i]=fie[j][i];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(fie[j][i]==-2 || fie[j][i]>0)continue;
				for(int k=0;k<4;k++){
					int nx=j+dx[k],ny=i+dy[k];
					if(nx>=0 && nx<w && ny>=0 && ny<h){
						if(fie[nx][ny]>0 && dir[fie[nx][ny]-1]==(k+2)%4){
							x[fie[nx][ny]-1]=j;
							y[fie[nx][ny]-1]=i;
							if(fie[j][i]==-1){
								rest--;
								fie2[nx][ny]=0;
							}
							if(fie[j][i]==0)swap(fie2[j][i],fie2[nx][ny]);
							break;
						}
					}
				}
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				fie[j][i]=fie2[j][i];
			}
		}
	}
	return turn;
}

int main(void){
	while(1){
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		for(int i=0;i<h;i++)scanf("%s",in[i]);
		cnt=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(in[i][j]=='E' || in[i][j]=='N' || in[i][j]=='W' || in[i][j]=='S'){
					x[cnt]=j;
					y[cnt]=i;
					if(in[i][j]=='E')dir[cnt]=0;
					if(in[i][j]=='N')dir[cnt]=1;
					if(in[i][j]=='W')dir[cnt]=2;
					if(in[i][j]=='S')dir[cnt]=3;
					cnt++;
					fie[j][i]=cnt;
				}
				if(in[i][j]=='X')fie[j][i]=-1;
				if(in[i][j]=='#')fie[j][i]=-2;
				if(in[i][j]=='.')fie[j][i]=0;
			}
		}
		int res=simulation();
		if(res==-1)printf("NA\n");
		else printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1240
n = int(input())
arr = []
for i in range(1, n + 1):
  a = []
  for j in range(1, i + 1):
    if j % 2 == 1:
      if i % j == 0:
        a.append(j)
  if len(a) == 8:
    arr.append(i)
print(len(arr))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);


int main()
{
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2)
    {
        cout << "1" << endl;
    }
    else
    {
        cout << "0" << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    typedef array<int,3> happiness_t; int n, max_happiness = INT_MIN; 
    
    cin >> n; vector<happiness_t> h(n), dp(n);

    for(int i = 0; i < n; ++i)
        for(auto&x:h[i])
            cin >> x;

    dp[0] = h[0];
    
    for(int i = 0, j = 1; j < n; i = j++)
        for(int k = 0; k < 3; k++)
        {
            dp[j][k] = INT_MIN; 
            
            for(int l = 0; l < 3; ++l)
                if(l != k)
                    dp[j][k] = max(dp[j][k],dp[i][l]);
                    
            dp[j][k] += h[j][k];
        }
        
    for(int i = n-1, j = 0; j < 3; ++j)
        max_happiness = max(max_happiness,dp[i][j]);
        
    cout << max_happiness; 
}

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

int main()
{
	int n, m; cin >> n >> m;
	

	vector<int> k(n);
	vector<vector<int>> a(0, vector<int>());

	for (int i = 0; i < n; i++) {

		cin >> k[i];

		vector<int> tmpVec(k[i]);

		for (int j = 0; j < k[i]; j++) {

			cin >> tmpVec[j];
		}

		a.emplace_back(tmpVec);

	}

	int ans = 0;
	for (int x = 1; x <= m; x++) {

		vector<bool> exist(n,false);

		for (int i = 0; i < n; i++) {

			for (int j = 0; j < k[i]; j++) {
			
				if (x == a[i][j]) exist[i] = true;			
			
			}

		}

		for (int i = 0; i < n; i++) {
		
			if (!exist[i]) break;
			
			if (i == n - 1) ans++;

		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
 * ITP1_4A.c
 *
 *  Created on: 2016/05/28
 *      Author: TakaakiShogaki
 */
#include<stdio.h>

int main(){
	int a,b;
	double f;

	scanf("%d %d",&a,&b);
	f=1.0*a/b;
	printf("%d %d %f\n",a/b,a%b,f);

return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
	const char* strs[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" };

	reep(i, 1, 12)
		days[i] += days[i-1];

	int m, d;
	while(scanf("%d%d", &m, &d), m&&d){
		puts(strs[(days[m-1]+d-1)%7]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    long long n;cin>>n;
    long long a[5];
    for(int i = 0;i<5;i++) cin>>a[i];
    sort(a,a+5);
    long long kai;
    if(n%a[0] == 0) kai = n/a[0];
    else kai = n/a[0]+1;
    cout<<4+kai;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,y,a;
	scanf("%d %d",&x,&y);
	if(x<y){
			a=y-x;
	}
	else if(x>y){
			a=x-y;
	}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int >    vecint;
typedef vector<double >   vecd;
typedef vector<ll >      vecll;
typedef vector<string > vecstr;
typedef vector<bool >  vecbool;
typedef vector<bool >  vecbool;
typedef vector<vector<bool> >  vec2bool;
typedef vector<vector<int> >    vec2int;
typedef vector<vector<double> >   vec2d;
////////////////////////////////////////////////
int main()
{
  ll n, x; cin >> n >> x;
  vecll a(n,0);
  ll sum = 0;
  REP(i,n){
    cin >> a[i];
    sum += a[i];
  }
  if(sum == x){
    cout << n << endl;
    return 0;
  }else if(sum < x){
    cout << n - 1 << endl;
    return 0;
  }
  sort(all(a));
  ll tmp = 0;
  int ans = 0;
  REP(i,n){
    if(tmp + a[i] <= x){
      tmp += a[i];
      ans ++;
    }else{
      break;
    }
  }
  cout << ans << endl;
} 

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

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

int main()
{    
   int n,m;
   cin>>n>>m;
   vector<pair<int,int>> all;
   REP(i,n)
   {
       int a;
       cin>>a;
       all.push_back(make_pair(a,1));
   }
   REP(i,m)
   {
       int b,c;
       cin>>b>>c;
       all.push_back(make_pair(c,b));
   }
   sort(all.begin(),all.end(),greater<pair<int,int>>());
   int64_t ans=0;
   int j=0;
   REP(i,n)
   {
       if(all.at(j).second<=0)
       {
           j++;
           i--;
       }
       else
       {
           ans+=all.at(j).first;
           all.at(j).second--;
       }  
   }
   cout<<ans<<endl;
}

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

int main(void) {
  int n, cnt=0;
  cin >> n;
  int p[n], d[3];
  
  for(int i=0; i<n; i++) cin >> p[i];
  
  for(int i=1; i<n-1; i++){
    d[0] = p[i-1];
    d[1] = p[i];
    d[2] = p[i+1];
    
    if(d[0] < d[1] && d[1] < d[2])
      cnt++;
    if(d[0] > d[1] && d[1] > d[2])
      cnt++;
  }
  
  cout << cnt << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define MAXN 200000

lli power(lli x, lli y, lli p) 
{ 
    lli res = 1;   
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1;  
        x = (x*x) % p;   
    } 
    return res; 
}
 
int main()
{
    
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////  
  
	lli n;
	cin>>n;
	lli a[n+1],cnt[n]={0};

	loopl(i,1,n+1)
	{
		cin>>a[i];
		cnt[a[i]]++;

	}

	if(a[1] !=0 || cnt[0]>1)
	{
		cout<<0;
		return 0;
	}

	lli ans=1;
	loopl(i,1,n)
	{
		ans = ans*power(cnt[i-1],cnt[i],mo);
		ans %= mo;
	}

	cout<<ans;
}

        
 


Measured memory_bytes: 1792