akhauriyash/Code-Regression huggingface dataset:
n=int(input())
b=list(map(int,input().split()))
ans=[0]*n
t=0
while t<n:
  res=t
  for i in range(n-t):
    if b[n-t-1-i]==n-t-i:
      ans[t]=b[n-t-1-i]
      b.remove(b[n-t-1-i])
      t+=1
      break
  if t==res:
    print(-1)
    exit()
for i in range(n):
  print(ans[n-1-i])

Measured memory_bytes: 9024
n,m=map(int,input().split())
s=[]
t=[]
for i in range(m):
  u,v=input().split()
  s.append(int(u)-1)
  t.append(v)
ans=-1
for i in range(1000):
  x=str(i)
  if len(x)!=n:
    continue
  flag=True
  for j in range(m):
    if x[s[j]] != t[j]:
      flag = False
  if flag:
    ans=i
    break
print(ans)

Measured memory_bytes: 3188
//2018年  3月 22日 木曜日 16:41:20 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, H, W;
int A[MAX_N];
int ans[110][110];

void solve() {
	cin >> H >> W;
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}
	int at = 0;
	rep(i, 0, H) {
		if(i % 2 == 0) {
			rep(j, 0, W) {
				ans[i][j] = at;
				A[at]--;
				if(A[at] == 0) at++;
			}
		}
		else {
			rer(j, W, 0) {
				ans[i][j] = at;
				A[at]--;
				if(A[at] == 0) at++;
			}
		}
	}
	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << ans[i][j] + 1 << " ";
		}
		cout << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std;

int main(){
  struct SC {
    int s;
    int c;
  };

  int n, m;
  cin >> n >> m;
  vector<SC> scs(m);
  for (int i=0; i<m; i++){
    cin >> scs[i].s >> scs[i].c;
  }
  sort(scs.begin(), scs.end(), [](const SC& x, const SC& y) { return x.s > y.s;});
  // for (int i=0; i<scs.size(); i++){
  //   cout << scs[i].s << scs[i].c << endl;
  // }
  int ans = 0;
  int num = 0;
  for (int i=1; i<n+1; i++) {
    num = -1;
    while (!scs.empty() && scs.back().s == i) {
      if (num == -1) {
        num = scs.back().c;
      } else if (scs.back().c != num) {
        cout << -1 << endl;
        return 0;
      }
      scs.pop_back();
    }
    if (n == 1 && (num == -1 || num == 0)) {
      cout << 0 << endl;
      return 0;
    }
    if (num == 0 && i == 1) {
      cout << -1 << endl;
      return 0;
    } else if (num == -1 && i == 1) {
      num = 1;
    } else if (num == -1) {
      num = 0;
    }
    ans += num * pow(10,(n+1-i)) / 10;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int t_hp,t_ap,m_hp,m_ap;
    cin >> t_hp >> t_ap >> m_hp >> m_ap;
    while(true){
        m_hp -= t_ap;
        if(m_hp<=0){
            cout << "Yes\n";
            return 0;
        }
        t_hp -= m_ap;
        if(t_hp<=0){
            cout << "No\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3160
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
flag=dict()
for i in range(n):
    if i in flag:
        continue
    cur=i
    accum=[]
    flag[cur]=0
    s=0
    while flag[cur]<2:
        cur=p[cur]-1
        s+=c[cur]
        accum.append(s)
        if cur not in flag:
            flag[cur]=0
        else:
            flag[cur]+=1
    l=len(accum)//2
    accum=[0]+accum
    #print(accum)
    for x in range(1,l+1):
        if accum[x+l-1]-accum[x-1]<=0 or k//l<1:
            ans=max(ans,max(accum[x:x+min(k,l)])-accum[x-1])
        else:
            a=max(accum[x:x+l-1])-accum[x-1]
            d=accum[x+l-1]-accum[x-1]
            if k%l!=0:
                b=max(accum[x:x+k%l])-accum[x-1]
                ans=max(ans,max(k//l*d,k//l*d+b,(k//l-1)*d+a))
            else:
                b=max(accum[x:x+l-1])-accum[x-1]
                ans=max(ans,max(k//l*d,(k//l-1)*d+a))
print(ans)


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 110;

const int Mod = 998244353;

map<string, int> f;

int count(const string &x)
{
	if (x.empty()) return 1;
	if (f.count(x)) return f[x];
	int &ret = f[x];
	ret = count(x.substr(1));
	if (x[0] == '1') (ret <<= 1) %= Mod;
	int len = SZ(x);
	REP(i, 1, len)
	{
		string tmp = "";
		REP(j, 0, i) tmp += '1';
		for (int j = 0, cnt = 1; j + i <= len; j += i, ++cnt)
		{
			REP(k, 0, i)
				if (x[j + k] == '0') tmp[k] = '0';
			if (cnt >= 2)
			{
				(ret += (LL)count(tmp) * count(x.substr(j + i)) % Mod) %= Mod;
			}
		}
	}
	return ret;
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	int ans = count(s);
	(ans += Mod) %= Mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int a[maxn];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int all =0;
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
        all+=a[i];
    }
    if(all>n){
        printf("-1\n");
    }else {
        printf("%d\n",n-all);
    }



    return 0;
}




Measured memory_bytes: 3852
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

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

    vector<int> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }

    int ans = 0;
    for(int i = n - 1; i >= 0; i--){
        ans += (b[i] - (a[i] + ans) % b[i]) % b[i];
    }
    cout << ans << endl;
    return 0;
}


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

static const int N=100;

int main(){
   int n;cin>>n;
   int g[n+1][n+1];

   for(int i = 1; i < n+1; i ++) {
      for(int j = 1; j < n+1; j ++) {
         g[i][j] = 0;
      }
   }

   for(int i = 1; i < n+1; i ++) {
      int i_node; cin >> i_node;
      int deg; cin >> deg;
      rep(j, deg) {
        int j_node; cin >> j_node;
        g[i_node][j_node] = 1;
      }
   }

   for(int i = 1; i < n+1; i ++) {
      for(int j = 1; j < n+1; j ++) {
         cout << g[i][j];
         if(j != n) cout << " ";
         else cout << endl;
      }
   }
   return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

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

  vector<vector<ll>> v(n, vector<ll>(3, 0));
  for (ll i=0; i<n; i++)
    for (ll j=0; j<3; j++)
      cin>>v[i][j];

  vector<vector<ll>> dp(n, vector<ll>(3, 0));
  for (ll i=0; i<n; i++) {
    for (ll j=0; j<3; j++) {
      if (i==0) {
        dp[i][j] = v[i][j];
      }
      else {
        ll a = (j + 1) % 3, b = (j + 2) % 3;
        dp[i][j] = max(dp[i-1][a], dp[i-1][b]) + v[i][j];
      }
    }
  }

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

int
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  ll t = 1;
  //cin>>t;

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

  return 0;
}



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

int main() {
    int N;
    string S;

    cin >> N;
    char s[N];

    for (int i = 0; i < N; i++) {
        cin >> s[i];
    }

    bool b = false;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'Y') {
            b = true;
            break;
        }
    }

    if (b)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}


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

vector<int> g[100000];
int c[100000],n;


void dfs(int r,int a){
  stack<int> s;
  s.push(r);
  c[r]=a;
  while(!s.empty()){
    int u=s.top();
    s.pop();
    for(int i=0;i<g[u].size();i++){
      int v=g[u][i];
      if(c[v]==-1){
	c[v]=a;
	s.push(v);
      }
    }
  }
}

void color(){
  int id=1;
  for(int i=0;i<n;i++) c[i]=-1;
  for(int i=0;i<n;i++){
    if(c[i]==-1) dfs(i,id++);
  }
}
    
int main(){
  int s,t,m,q;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  color();
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>s>>t;
    if(c[s]==c[t]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}



Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

signed main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> v;
  for(int i = 1;i*i<=M;i++){
    if(M%i==0){
      v.pb(i);
      v.pb(M/i);
    }
  }
  sort(ALL(v));
  cout << M/(*lower_bound(ALL(v),N)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 
14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
int main() {
    cin >> k;
    cout << a[k - 1];
    return 0;
}


Measured memory_bytes: 256
s = input()


def is_palinedrome(st):
    for i in range(len(st)//2):
        if st[i] != st[-(i+1)]:
            return False
    return True


s_pali = is_palinedrome(s)
sub_pali_left = is_palinedrome(s[:len(s)//2])
sub_pali_right = is_palinedrome(s[len(s)//2+1:])

if s_pali and sub_pali_left and sub_pali_right:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9100
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
int main()
{
	string a , b;
	cin >> a >> b;
	if(a.length() < b.length())cout << "LESS" << endl;
	else if(a.length() > b.length())cout << "GREATER" << endl;
	else{
		bool flag = false;
		for(int i = 0 ; i < a.length() ; i++)
		{
			if(a[i] == b[i]);
			else if(a[i] > b[i])
			{
				cout << "GREATER" << endl;
				break;
			}
			else {
				cout << "LESS" << endl;
				break;
				}
			if(i == a.length() - 1 && a[i] == b[i])cout << "EQUAL" << endl;
		}
	}
	return 0;
	}

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

int main(){
	int a,b,c;
	int k;
	int max_num = 0;
	cin>>a>>b>>c;
	cin>>k;
	int sum = 0;
	sum = a+b+c;
	max_num = max(a,b);
	max_num = max(max_num,c);
	for(int i=1;i<=k;i++){
		sum -= max_num;
		max_num = 2*max_num;
		sum+=max_num;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000099
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define LL long long
// ios::sync_with_stdio(false);
using namespace std;
int n;
LL S;
int main()
{
    cin >> S;
    LL t = sqrt(S);
    if (t * t < S)
        t++;
    cout << "0 0 " << t << " " << t * t - S << " 1 " << t << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll jumps=x/d;
	if(jumps>k)
	{
		cout<<x-(k*d);
	}
	else
	{
		x-=jumps*d;
		k-=jumps;
		if(k%2==0)
		{
			cout<<x;
		}
		else
		{
			cout<<min(abs(x+d),abs(x-d));
			
		}
	}

	return 0;
}

Measured memory_bytes: 3524
#include <bits//stdc++.h>
using namespace std;
#define int long long
signed main(){
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();){
		int j=i;
		while(j<s.size()&&s[i]==s[j]){
			j++;
		}
		sum++;
		i=j;
	}
	cout<<sum-1<<endl;
}


Measured memory_bytes: 512
N,X,Y = map(int, input().split())
ans = [0]*N
X -= 1
Y -= 1

for i in range(N-1):
  for j in range(i+1,N):
    _ = min(j-i, abs(X-i)+1+abs(Y-j))
    ans[_] += 1

for _ in range(1,N):print(ans[_])

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

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

	static bool g[400][400];

	while (m--) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--;
		y--;
		if (!g[x][y]) {
			for (int i = 0; i < n; i++) {
				if (g[x][i]) {
					g[y][i] = true;
					g[i][y] = true;
				}
				if (g[y][i]) {
					g[x][i] = true;
					g[i][x] = true;
				}
			}
		} else {
			for (int i = 0; i < n; i++) {
				g[i][x] = true;
				g[x][i] = true;
				g[i][y] = true;
				g[y][i] = true;
			}
		}
		g[x][y] = true;
		g[y][x] = true;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (!g[i][j]) {
				ans++;
			}
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


const ll MAX = 510000;
const ll MOD =1000000007;



int main(void) {
	int N; cin >> N;
	set<string> st;
	map<string, ll> mp;
	for (int i = 0; i < N; i++) {
		vector<char> v;
		for (int i = 0; i < 10; i++) {
		    char c; cin>>c;
		    v.push_back(c);
		}
		sort(v.begin(), v.end());
		string s = "";
		for (int i = 0; i < 10; i++) s += v[i];
		st.insert(s);
		mp[s]++;
	}

	ll ans = 0;
	for(auto itr = st.begin(); itr != st.end(); ++itr) {
		string s = *itr;
		ans += mp[s] * (mp[s] - 1) / 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

V<int> a;


bool solve(int tail, int left_num) {
  if(left_num == 0) {
    return true;
  }
  if(left_num < 0 || tail > a.size()) {
    return false;
  }

  // Use
  if(solve(tail + 1, left_num - a[tail])) {
    return true;
  };
  // Not use
  if(solve(tail + 1, left_num)) {
    return true;
  }

  return false;
}

int main() {
  int n;
  int q;

  cin >> n;
  a.resize(n);
  rep(i, n) {
    cin >> a[i];
  }
  cin >> q;

  rep(i, q) {
    int m;
    cin >> m;

    bool can = solve(0, m);

    if(can) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 3092
import Control.Applicative

import Control.Monad
    (replicateM)
    
import Data.List
    (elemIndex, intercalate)

type Dice
    = [Int]

type Question
    = (Int, Int)
    
type Table
    = [[Int]]

type Problem
    = (Dice, [Question])

type Result
    = [Int]

table :: Dice -> Table

table [s1, s2, s3, s4, s5, s6]
    = [
        [0, s3, s5, s2, s4, 0],
        [s4, 0, s1, s6, 0, s3],
        [s2, s6, 0, 0, s1, s5],
        [s5, s1, 0, 0, s6, s2],
        [s3, 0, s6, s1, 0, s4],
        [0, s4, s2, s5, s3, 0]
        ]

right :: Dice -> Question -> Int

right dice (top, front)
    = table dice !! ti !! fi where
        Just ti = elemIndex top dice
        Just fi = elemIndex front dice

solve :: Problem -> Result

solve (dice, questions)
    = map (right dice) questions

output :: Result -> String

output result
    = intercalate "\n" $ map show result
    
input :: IO Problem

input
    = do
        dice <- map read <$> words <$> getLine
        n <- read <$> getLine
        questions <- replicateM n inputQuestion
        return (dice, questions)
        
inputQuestion :: IO Question

inputQuestion
    = do
        [top, front] <- map read <$> words <$> getLine
        return (top, front)

main :: IO ()

main
    = putStrLn <$> output =<< solve <$> input

Measured memory_bytes: 4004
import java.util.*;

public class Main {
    public static void main(String[] args) {
        long MOD = 1000000007;
        Scanner sc = new Scanner(System.in);
        String l = sc.next();
        long[] dp1 = new long[l.length() + 1];
        long[] dp2 = new long[l.length() + 1];
        dp1[0] = 2; // 以下未定
        dp2[0] = 1; // 以下確定
        for (int i = 1; i < l.length(); i++) {
            if (l.charAt(i) == '0') {
                dp1[i] = (dp1[i - 1] + dp1[i]) % MOD;
                dp2[i] = (3 * dp2[i - 1] + dp2[i]) % MOD;
            } else {
                dp1[i] = (2L * dp1[i - 1] + dp1[i]) % MOD;
                dp2[i] = (dp1[i - 1] + 3 * dp2[i - 1]) % MOD;
            }
        }
        System.out.println((dp1[l.length() - 1] + dp2[l.length() - 1]) % MOD);
    }
}

Measured memory_bytes: 26024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	int sum = 0;
	for (int i = 1; i <= N; i++)
	{
		if(i%3==0 && i%5==0){
			continue;
		}else if(i%3==0){
			continue;
		}else if(i%5==0){
			continue;
		}else{
			sum += i;
		}
	}
	cout << sum << endl;
}


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

using namespace std;

int main(){
    long m1=0,m2=0,temp,n,i,j;
    cin>>n;
    long a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
        
    sort(a, a+n, greater<int>());
    
    for(i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            m1=a[i];
            break;
        }
    }
    for(j=i+2;j<n-1;j++){
        if(a[j]==a[j+1]){
            m2=a[j];
            break;
        }
    }
    cout<<m1*m2;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    bool ok=false;
    if(b<=a) swap(a,b);
    rep(i,t+1){
        if(a+v*i >= b+w*i) ok=true;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long ll;
ll s[2000];
ll dp[2000][2000];
int main(void){
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        ll a=1e9+1;
        for(int j=0;j<n;j++){
            a=min(a,s[(i+j)%n]);
            dp[i][j]=a;
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<dp[i][j];
        }
        cout<<endl;
    }*/
    ll rans=1LL<<60;
    for(int i=0;i<n;i++){
        ll ans=i*k;
        for(int j=0;j<n;j++){
            ans+=dp[j][i];
            
        }
        rans=min(ans,rans);
    }
    cout<<rans<<endl;
}


Measured memory_bytes: 31488
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 21:21:55 2020

@author: azikausy
"""


S = input()
N = len(S)
forw = S[:int((N-1)/2)]
back = S[int((N+3)/2)-1:]

if S == S[::-1] and forw == forw[::-1] and back == back[::-1]:
    print("Yes")
else:
    print("No")

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

int main()
{
    int a[5];
    int sum = 0;
    for(int i = 0; i < 5; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    cout << 15 - sum << endl;
    return 0;
}

Measured memory_bytes: 3636
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [0] * M

for _ in range(M):
    BC[_] = tuple(map(int, input().split()))

# solve
A.sort()
BC.sort(key=lambda x: x[1], reverse=True)
ans = A.copy()
pos = 0

for B, C in BC:
    while B > 0 and pos < N:
        if C > A[pos]:
            A[pos] = C
            pos += 1
            B -= 1
        else:
            break

print(sum(A))



Measured memory_bytes: 22444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = a*2+b*2;
    System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26160
N,*E=*$<
E.each_slice(3).map{|_,a,s,*b|p a.split.map(&:to_i).zip(s.chars).reverse.all?{|a,f|b.map{a=[a,a^_1].min}
a<1||f[?0]&&b<<a}?0:1}

Measured memory_bytes: 14672
while True:
  r, c, q = map(int, input().split())
  if r == 0: break
  querys = [list(map(int, input().split())) for _ in range(q)]
  querys.reverse()
  r_used = [False] * r
  c_used = [False] * c
  r_cnt = c
  c_cnt = r
  ans = 0
  for a, b, o in querys:
    if a == 0:
      if not r_used[b]:
        r_used[b] = True
        c_cnt -= 1
        if o:
          ans += r_cnt

    else:
      if not c_used[b]:
        c_used[b] = True
        r_cnt -= 1
        if o:
          ans += c_cnt
  print(ans)


Measured memory_bytes: 21712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

int dist(pair<int,int> p,pair<int,int> q){
    return(abs(p.first-q.first)+abs(p.second-q.second));
}


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

    int N;
    cin>>N;
    pair<int,int> p[N];
    rep(i,N){
        int a,b;
        cin>>a>>b;
        p[i]=make_pair(a,b);
    }
    sort(p,p+N);
    int res=0;
    vector<pair<int,int>> qs(N*2);
    int k=0;
    rep(i,N){
        while(k>1&&(qs[k-1].first-qs[k-2].first)*(p[i].second-qs[k-1].second)-(qs[k-1].second-qs[k-2].second)*(p[i].first-qs[k-1].first)<=0)k--;
        qs[k++]=p[i];
    }
for(int i=N-2,t=k;i>=0;i--){
    while(k>t&&(qs[k-1].first-qs[k-2].first)*(p[i].second-qs[k-1].second)-(qs[k-1].second-qs[k-2].second)*(p[i].first-qs[k-1].first)<=0)k--;
    qs[k++]=p[i];
}
    qs.resize(k-1);
    int ans=0;
    rep(i,qs.size()){
        rep(j,i){
            ans=max(ans,dist(qs[i],qs[j]));
        }
    }
    cout<<ans<<endl;

    



}


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

using namespace std;

int main(void)
{
	long long n;
	cin >> n;
	map<int, long long> m;
	for (long long i = 1; i <= n; i++) {
		if (i <= 9) {
			m[i*10+i]++;
		} else if (i <= 99) {
			m[i]++;
		} else if (i <= 999) {
			m[(i/100)*10 + i%10]++;
		} else if (i <= 9999) {
			m[(i/1000)*10 + i%10]++;
		} else if (i <= 99999) {
			m[(i/10000)*10 + i%10]++;
		} else if (i <= 999999) {
			m[(i/100000)*10 + i%10]++;
		}
	}
	long long ans = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			ans += m[i*10+j]*m[j*10+i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int n,x,ans;
	long long k,c,tmp,t;
	vector<long long> v;
	cin >> n >> c >> k;
	for(int i=0;i<n;i++){
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(),v.end());
	t=v[0];
	x=1;
	ans=0;
	for(int i=1;i<n;i++){
		if(i!=(n-1)){
			if((t+k)>=v[i]&&x<c){
				x+=1;
			}else{
				t=v[i];
				ans +=1;
				x=1;
			}
		}else{
			if((t+k)>=v[i]&&x<c){
				ans+=1;
			}else{
				t=v[i];
				ans +=2;
				x=1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
    int a, b, count = 0, sum = 1;
    
    cin >> a >> b;
    
    while(b > sum){
        sum += a-1;
        count++;
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll N,a=0;
  cin>>N;
  vector<string> s(N);
  vector<ll> t(N);
  for(ll i=0;i<N;i++){
    cin>>s.at(i)>>t.at(i);
    a+=t.at(i);
  }
  string str;
  cin>>str;
  ll rock=0;
  for(ll i=0;i<N;i++){
    rock+=t.at(i);
    if(str==s.at(i)){
      cout<<a-rock<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	int i, j, tikaA, tikaB;
	int N, M, A[1001], B[1001], na[1001];
	scanf("%d%d", &N, &M);
	for (i=0; i < N ;i++) {
		scanf("%d", &A[i]);
		na[i] = 0;
	}
	for (i=0; i < M ;i++) {
		scanf("%d", &B[i]);
	}
	for (i=0; i < M ;i++) {
		for (j=0; j < N ;j++) {
			if (B[i] >= A[j]) break;
		}
		na[j]++;
	}
	tikaA = 0, tikaB = na[0];
	for (i=0; i < N ;i++) {
		if (tikaB < na[i]) {
			tikaA = i;
			tikaB = na[i];
		}
	}
	printf("%d\n", tikaA+1);
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll x,n,a[1000],l,r,fl,i,j;
	cin>>x>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;;i++) {
		l=x+i;
		r=x-i;
		fl=1;
		for(j=0;j<n;j++) {
			if(a[j]==r) {
				fl=0;
				break;
			}
		}
		if(fl==1) {
			cout<<r;
			break;
		}
		fl=1;
		for(j=0;j<n;j++) {
			if(a[j]==l) {
				fl=0;
				break;
			}
		}
		if(fl==1) {
			cout<<l;
			break;
		}
		
	}
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] C = new String[H];
        for(int i = 0; i < H; i++){
            C[i] = sc.next();
        }
        
        for(int i = 0; i < H; i++){
            System.out.println(C[i]);
            System.out.println(C[i]);
        }
    }
}


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

int main(){
 string s;
  cin >> s;
  vector<char> t;
  for(int i=0;i<s.size();i+=2){
   t.push_back(s[i]);
  }

  for(int i=0;i<t.size();i++){
  cout <<t[i];
  }
  return 0;
}


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

int bs(vector<ll> b, ll tar) {
  int start = 0, end = b.size() - 1;
  int ans = -1;
  while(start <= end) {
    int mid = start + (end - start) / 2;
    if(b[mid] <= tar) {
      ans = mid;
      start = mid + 1;      
    } else end = mid - 1;
  }
  return ans;
}

int solve(vector<ll> a, vector<ll> b, ll k) {
  int res = 0;
  ll left;
  for(int i = 0; i < a.size(); ++i) {
    left = k - a[i];
    if(left < 0) break;
    int index = bs(b, left);
    if(index == -1) break;
    res = max(res, i + index);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  ll k, now;
  cin >> n >> m;
  cin >> k;
  vector<ll> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  rep(i, n) {
    cin >> now;
    a[i + 1] = now + a[i];
  }
  rep(i, m) {
    cin >> now;
    b[i + 1] = now + b[i];
  }
  ll ans = 0;
  rep(i,n+1)
  {
      ll cur=k-a[i];
      if(cur>=0){
      ll cur2=upper_bound(b.begin(), b.end(),cur)-b.begin()-1;
      ans=max(ans,i+cur2);
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6348
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val countCharMap = mutableMapOf<Char, Int>()
    while (scanner.hasNextLine()) {
        val line = scanner.nextLine()
        for (c in line) {
            countCharMap.merge(c.toLowerCase(), 1, Int::plus)
        }
    }
    ('a'..'z')
        .map { "${it} : ${countCharMap.getOrDefault(it, 0)}" }
        .forEach { println(it) }
}



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

int main() {
  int A, B, c = 0, n = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++) {
    n = i;
    int n5 = (n / 10000);
    n -= (n / 10000) * 10000;
    int n4 = (n / 1000);
    n -= (n / 1000) * 1000;
    n -= (n / 100) * 100;
    int n2 = (n / 10);
    n -= (n / 10) * 10;
    int n1 = n;

    if (n5 == n1 && n4 == n2)
      c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int H, W, K;
char c[6][6];
bool red[6][6];

int main() {
    cin >> H >> W >> K;
    REP(i, H) REP(j, W) cin >> c[i][j];
    int ans = 0;

    REP(bit, 1<<(H+W)) {
        REP(i, H) REP(j, W) red[i][j] = false;
        REP(i, H) REP(j, W) {
            if (bit & 1<<(i+W) || bit & 1<<j) red[i][j] = true;
        }
        int cnt_black = 0;
        REP(i, H) REP(j, W) {
            if (c[i][j] == '#' && red[i][j] == false) cnt_black++;
        }
        if (cnt_black == K) ans++;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3640
#include <fstream>
#include <iostream>
#include <algorithm>

using namespace std;

/*ifstream fin ("contest.in");
ofstream fout ("contest.out");*/

char c[101];
int n, m;
int main()
{
    cin >> n >> m;
    for (int i = 1; i <=n; i++)
    {
        cin >> c;
        cout << c << '\n';
        cout << c << '\n';
    }

    return 0;
}


Measured memory_bytes: 384
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Main main=new Main();
		main.run();
	}

	public static int h;
	public static int w;
	public static boolean done;

	public static Integer[][] field;

	public static boolean[][] isReached;

	public static Deque<Point> data;



	void run() {

//
//		Scanner sc=null;
//		try {
//			File file=new File("C:\\pleiades\\eclipse\\text\\atcoder.txt");
//
//			sc = new Scanner(file);
//		} catch (FileNotFoundException e) {
//			// TODO 自動生成された catch ブロック
//			e.printStackTrace();
//		}
		Scanner sc=new Scanner(System.in);


		while(true) {
			w=sc.nextInt();
	    	h=sc.nextInt();

	    	if(w==0 && h ==0) {
	    		break;
	    	}

			field=new Integer[h][w];
			isReached=new boolean[h][w];


			for(boolean[] a:isReached) {
				Arrays.fill(a, false);
			}



			for(int i=0;i<h;i++) {
				for(int j=0;j<w;j++) {

					Integer buf=sc.nextInt();
					field[i][j]=buf;

					if(buf.equals(0)) {
						isReached[i][j]=true;
					}

				}
			}

			done=false;

			data=new ArrayDeque<Point>();

			int counter=0;

			while(true) {

				Point buf=getLocateIsNotReached();



				if(buf!=null) {
					data.push(buf);
					counter++;
					dfs();
				}else {
					break;
				}

			}

				System.out.println(counter);
			}

		sc.close();


		}

		void dfs() {
			Point bufPoint=null;

			while(!data.isEmpty()) {

				bufPoint=data.pop();


				int nowY=bufPoint.getY();
				int nowX=bufPoint.getX();

				isReached[nowY][nowX]=true;


				int nextY=0;
				int nextX=0;

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

				for(int d=0;d<8;d++) {
					nextY=nowY+dy[d];
					nextX=nowX+dx[d];

					if(canProceed(nextY,nextX)) {
						data.push(new Point(nextY,nextX));
					}
				}

		}

	}

	Point getLocateIsNotReached() {



		for(int i=0;i<h;i++) {
			for(int j=0;j<w;j++) {

				if(!isReached[i][j]) {
					return new Point(i,j);
				}

			}
		}

		return null;
	}



	boolean canProceed(int nextY,int nextX) {

		boolean isInY =nextY>=0 && nextY<h;
		boolean isInX=nextX>=0 && nextX<w;

		boolean isIn=isInY && isInX;

		if(!isIn) {
			return false;
		}

		boolean notWall=!field[nextY][nextX].equals(0);

		return isInY && isInX && notWall && !isReached[nextY][nextX];
	}


}

class Point{
	int y;
	int x;
	/**
	 * @return y
	 */
	public int getY() {
		return y;
	}
	/**
	 * @return x
	 */
	public int getX() {
		return x;
	}
	/**
	 * @param y セットする y
	 */
	public void setY(int y) {
		this.y = y;
	}
	/**
	 * @param x セットする x
	 */
	public void setX(int x) {
		this.x = x;
	}
	public Point(int y, int x) {
		super();
		this.y = y;
		this.x = x;
	}


}


Measured memory_bytes: 46940
///*
#include<iostream>
#include<string>
using namespace std;

int main() {
	string cube;
	string first = "1", second = "0";
	int one = 0, zero = 0, number = 0;
	
	cin >> cube;
	
	while (number != cube.length()) {
		if (cube[number] == '1') {
			one++;
		}
		number++;
	}
	number = 0;

	while (number != cube.length()) {
		if (cube[number] == '0') {
			zero++;
		}
		number++;
	}

	one < zero ? cout << one * 2 << endl : cout << zero * 2 << endl;

	return 0;

}
//*/

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

int main(void) {
    int N;
    cin >> N;
    int t[100010] = {0};
    int x[100010] = {0};
    int y[100010] = {0};
    for (int i = 1; i <= N; i++) {
        cin >> t[i];
        cin >> x[i];
        cin >> y[i];
    }

    for (int i = 0; i < N; i++) {
        int dt = t[i+1] - t[i];
        int dx = x[i+1] - x[i];
        int dy = y[i+1] - y[i];
        if (dx < 0) dx *= (-1);
        if (dy < 0) dy *= (-1);
        if (dt < dx+dy) {
            cout << "No" << endl;
            return 0;
        }
        if ((dt%2) != ((dx+dy)%2)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n;

int main()
{
    cin>>n;
    n*=100;
    int x=n/108;
    n/=100;
    int d=x*1.08;
    if (x*1.08!=n)
    {
        x++;
        d=x*1.08;
        if (d!=n)
            cout<<":(";
        else cout<<x;
    }
    else cout<<x;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll W, H, x, y;
  std::cin >> W >> H >> x >> y;
  std::cout << std::fixed << std::setprecision(9);

  if (x * 2 == W && y * 2 == H ) {
    print ((ld)(W*H)/2.0, (ll)1);
    return 0;
  }
  print ((ld)(W*H)/2.0, (ll)0);

  return 0;
}


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

const int MAX = 20;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int map[MAX][MAX];
int ans = 1;

void dfs(int x, int y)
{
	map[x][y] = 2;

	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if (nx >= 0 && nx < MAX&&ny >= 0 && ny < MAX) {
			if (map[nx][ny] == 1) {
				ans++;
				dfs(nx, ny);
			}
		}
	}
}

int main()
{
	while (true) {
		ans = 1;
		int W, H;
		cin >> W >> H;

		if (W == 0 && H == 0) {
			break;
		}

		for (int i = 0; i < MAX; i++) {
			for (int j = 0; j < MAX; j++) {
				map[i][j] = 0;
			}
		}

		int x, y;

		for (int i = 0; i < H; i++) {
			string str;
			cin >> str;

			for (int j = 0; j < W; j++) {
				if (str.substr(j, 1) == ".") {
					map[i][j] = 1;
				}
				else if (str.substr(j, 1) == "@") {
					map[i][j] = 2;
					x = i;
					y = j;
				}
			}
		}

		dfs(x, y);

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3184
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

string g[100];
int main(){
	int h, w;
	cin>>h>>w;
	rep(i, h) cin>>g[i];
	bool ok = true;
	if(g[0][0]!='#') ok = false;
	{
		int i = 0, j = 0;
		while(i<h && j<w){
			if(i==h-1 && j==w-1) break;
			if(i<h-1 && g[i+1][j]=='#') i++;
			else if(j<w-1 && g[i][j+1]=='#') j++;
			else break;
		}
		if(!(i==h-1 && j==w-1)) ok = false;
	}
	{
		int cnt = 0;
		rep(i, h) rep(j, w) if(g[i][j]=='#') cnt++;
		if(cnt!=h+w-1) ok = false;
	}
	cout<<(ok?"Possible":"Impossible")<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
int primes[25] = {
	2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
};
int pcount[25] = {
	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

vector<vector<int>> DP;

int dp2(int a, int b) {
	DP[0][0] = 1;
	for (int n = 1; n <= 25; n++) {
		DP[n][0] = 1;
		DP[n][1] = DP[n - 1][1];
		DP[n][2] = DP[n - 1][2];
		if (pcount[n - 1] >= a)DP[n][1] += DP[n - 1][0];
		if (pcount[n - 1] >= b)DP[n][2] += DP[n - 1][1];
	}
	return DP[25][2];
}

int dp3(int a, int b, int c) {
	DP[0][0] = 1;
	for (int n = 1; n <= 25; n++) {
		DP[n][0] = 1;
		DP[n][1] = DP[n - 1][1];
		DP[n][2] = DP[n - 1][2];
		DP[n][3] = DP[n - 1][3];
		if (pcount[n - 1] >= a)DP[n][1] += DP[n - 1][0];
		if (pcount[n - 1] >= b)DP[n][2] += DP[n - 1][1];
		if (pcount[n - 1] >= c)DP[n][3] += DP[n - 1][2];
	}
	return DP[25][3];
}

int main() {
	cin >> N;
	for (int n = 1; n <= N; n++) {
		int oldn = n;
		int p = 0;
		while (oldn > 1) {
			if (oldn % primes[p] == 0) {
				oldn /= primes[p];
				pcount[p]++;
			}
			else p++;
		}
	}
	DP.resize(26, vector<int>(4, 0));
	//(2,24)
	int ans = 0;
	for (int p = 0; p < 25; p++) {
		if (pcount[p] >= 74)ans++;
	}
	ans += dp2(2, 24);
	ans += dp2(24, 2);
	//(4,14)
	ans += dp2(4, 14);
	ans += dp2(14, 4);
	//(2,4,4)
	ans += dp3(2, 4, 4);
	ans += dp3(4, 2, 4);
	ans += dp3(4, 4, 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ull powMod(ull x, ull n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  ull tmp = powMod(x, n / 2);
  if (n % 2 == 0) return (tmp * tmp) % MOD;
  return ((ull)2) * (tmp * tmp) % MOD;
}

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int s = a + b + c;
  if (s >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


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

//わからなかった

int main(){
    int A,B,C;
    std::cin >> A >> B >> C;

    bool canDivid = false;
    for(int i=1;i<=B;i++)
    {
        if((A*i)%B == C)
        {
            canDivid = true;
            break;
        }
    }

    if(canDivid)
    {
        std::cout << "YES";
    }else
    {
        std::cout << "NO";
    }
    


    return 0;
}

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

using namespace std;


int main() {
    int N, K;
    cin >> N >> K;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int xi;
        cin >> xi;
        sum += std::min(xi, K - xi);
    }
    sum *= 2;
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int a= scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		String ans = a<b && b<c ? "Yes" : "No";
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 17296
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CAXBC {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        int res = 0;
        FOR(a, 1, N) {
            int num = (N-1) / a;
            res += num;
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CAXBC solver;
    solver.solve(in, out);
    return 0;
}


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

int main(){
    int N,P;
    cin >> N >> P;
    int m = 0;
    for(int i = 0; i < N; i++){
        int A; cin >> A;
        if(A%2 == 1 )m++;
    }
    if(m == 0)cout << (P == 0 ? (1LL << N) : 0 ) << endl;
    else cout << (1LL <<(N - 1)) << endl;
}



Measured memory_bytes: 3520
import bisect
s = int(input())
a = list(map(int, input().split()))
aa = sorted(a)
v = 0
m = aa[-1]
x = bisect.bisect_left(aa,m//2)
if abs(aa[x-1]) > abs(m-aa[x]):
	b = aa[x-1]
else:
	b = aa[x]
if aa[x] == m:
	x -= 1
	b = aa[x]
print (m,b)

Measured memory_bytes: 14428