akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>>ret(h, vector<char>(w, '0'));
  for(int i=0; i<h; i++)for(int j=0; j<w; j++){
    char c;
    cin >> c;
    if(c=='#'){
      ret[i][j]='#';
      for(int x=max(i-1, 0); x<min(i+2, h); x++){
        for(int y=max(j-1, 0); y<min(j+2, w); y++){
          if(ret[x][y]!='#')ret[x][y]++;
        }
      }
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++)cout << ret[i][j];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
void solve () {
  int a, b, c;
  cin >> a >> b >> c;
  if (a+b+c > 21) cout << "bust\n";
  else cout << "win\n";
}
int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 256
n, c, k = map(int, input().split())
t = sorted([int(input()) for i in range(n)])
ans = 0
a = 0
bus = 0
for i in range(n):
    bus += 1
    if bus == c or t[i] > a:
        bus = 0
        a = t[i] + k
        ans += 1
print(ans)

Measured memory_bytes: 8280
N,W = map(int,input().split())

product = [(0,0)]
for _ in range(N):
    v,w = map(int,input().split())
    product.append((w, v))

#縦が商品i，横が仮想カバンの耐久値
#i番目までの商品だけを使って，耐久wのカバンの価値を最大化していく
dp = [[-float('inf')]*(W+1) for _ in range(N+1)]

for i in range(N+1):
    for w in range(W+1):
        if i == 0:
            dp[i][w] = 0
            continue
        if w == 0:
            dp[i][w] = 0
            continue
        if product[i][0] > w:
            dp[i][w] = dp[i-1][w]
        else:
            not_choice = dp[i-1][w]
            choice = dp[i-1][w-product[i][0]] + product[i][1]
            same_choice = dp[i][w-product[i][0]] + product[i][1]#重複を許して選ぶことに相当
            dp[i][w] = max(not_choice, choice, same_choice)
print(max(dp[N]))


Measured memory_bytes: 15708
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 7;
int n;
map <int, bool> vis;

int main() {
	cin >> n;
	vis[n] = 1;
	for(int i = 2; i <= maxx; i++) {
		if(n & 1) n = n * 3 + 1;
		else n /= 2;
		if(vis[n]) {
			cout << i << endl;
			break;
		}
		vis[n] = 1;
	}
}

Measured memory_bytes: 256
chomp( my $n = <> );
print qw/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 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 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 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 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5/[$n];

Measured memory_bytes: 640
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
# p.append(float('inf'))
# q.append(float('inf'))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
p=p[:x]
q=q[:y]
anslst=p+q+r
anslst.sort(reverse=True)
print(sum(anslst[:x+y]))

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

void call(int n);

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

    call(n);
    
    return 0;
}

void call(int n){


    for(int i = 1; i <= n ; i++){
        if( (i % 3) == 0 ){
            cout << " " << i;
        }else{
            int x = i;
            while(x){
                if ( (x % 10) == 3 ){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;

    return;
}

Measured memory_bytes: 1164
import java.io.*;
import java.util.*;
class Main
{
public static void main (String args[])
{
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    String ans;

    if( d*(-1) <= a-c && a-c <= d){ // aとcの差がd以内
        ans = "Yes";
    }
    else if( d*(-1) <= a-b && d*(-1) <= c-b && d >= a-b && d>= c-b){
        ans = "Yes";
    }
    else{
        ans = "No";
    }
    System.out.println(ans);

}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#define r(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
  int n;
  int a, k=0;
  int cnt=0;
  int c[8];
  cin >> n;
  r(i,n){
    cin >> a;
    if(0<a && a<=399){c[0]=1;}
    else if(a<=799){c[1]=1;}
    else if(a<=1199){c[2]=1;}
    else if(a<=1599){c[3]=1;}
    else if(a<=1999){c[4]=1;}
    else if(a<=2399){c[5]=1;}
    else if(a<=2799){c[6]=1;}
    else if(a<=3199){c[7]=1;}
    else{k++;}
  }
  r(i,8){
    if(c[i]==1){cnt++;}
  }
  if(cnt==0 && k!=0){cout << 1 << ' ';}
  else{cout << cnt << ' ';}
  cout << cnt+k << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	
	scanf("%d",&N);
	
	if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9){
		printf("hon");
	}else if(N%10==0||N%10==1||N%10==6||N%10==8){
		printf("pon");
	}else if(N%10==3){
		printf("bon");
	}
	
	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s;cin>>s;
  ans(s[6]-'0'<=4&&s[5]=='0',"Heisei","TBD");
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <map>
#define MOD 1000000007
typedef long long ll; 
inline int quick_pow(int a, int n)
{
	int res = 1; 
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD; 
		a = (ll)a * a % MOD; 
		n >>= 1; 
	}
	return res; 
}
std::map<int, int> idx_e[200005]; 
int lst[200005], to[400005], pre[400005], w[400005], tot; 
int st[200005], vis[200005], sz[200005], e, tp; 
int fact[200005], inv[200005], dp[200005], res; 
bool cyc, del[400005]; 
inline void add_edge(int u, int v, int _w)
{
	to[tot] = v; 
	pre[tot] = lst[u]; 
	w[tot] = _w; 
	idx_e[u][v] = tot; 
	lst[u] = tot++; 
}
void dfs(int u, int fa = -1)
{
	vis[u] = 1; 
	st[tp++] = u; 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		int v = to[i]; 
		if (v == fa)
			continue; 
		if (vis[v] == 1)
		{
			e = i; 
			for (int j = tp - 2; j >= 0; j--)
			{
				int cur = idx_e[st[j]][st[j + 1]]; 
				if (w[cur] > w[e])
					e = cur;
				if (st[j] == v)
					break; 
			}
			if (cyc)
			{
				puts("0");
				exit(0); 
			}
			cyc = true; 
		}
		else if (!vis[v])
			dfs(v, u); 
	}
	vis[u] = 2; 
	tp--; 
}
void work(int u, int fae)
{
	sz[u] = 0; 
	dp[u] = 1; 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		int v = to[i]; 
		if (i == fae || del[i])
			continue; 
		work(v, i ^ 1); 
		if (w[i] > w[fae])
			res = (ll)res * inv[sz[v]] % MOD * dp[v] % MOD; 
		else
		{
			sz[u] += sz[v]; 
			dp[u] = (ll)dp[u] * dp[v] % MOD * fact[sz[u]] % MOD
			 * inv[sz[v]] % MOD * inv[sz[u] - sz[v]] % MOD; 
		}
	}
	sz[u]++; 
}
int main()
{
	// freopen("ARC083-F.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n; 
	scanf("%d", &n);
	for (int i = 0; i < n << 1; i++)
	{
		int x, y; 
		scanf("%d%d", &x, &y); 
		x--; 
		y--; 
		add_edge(x, y + n, x + y); 
		add_edge(y + n, x, x + y); 
	}
	n <<= 1; 
	fact[0] = inv[0] = 1; 
	for (int i = 1; i <= n; i++)
		fact[i] = (ll)fact[i - 1] * i % MOD; 
	inv[n] = quick_pow(fact[n], MOD - 2); 
	for (int i = n; i; i--)
		inv[i - 1] = (ll)inv[i] * i % MOD; 
	int ans = fact[n]; 
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue; 
		cyc = false; 
		dfs(i, 0); 
		del[e] = del[e ^ 1] = true; 
		int sum = 0; 
		res = 1; 
		work(to[e], e ^ 1); 
		sum += (ll)inv[sz[to[e]]] * dp[to[e]] % MOD * res % MOD; 
		res = 1; 
		work(to[e ^ 1], e); 
		sum += (ll)inv[sz[to[e ^ 1]]] * dp[to[e ^ 1]] % MOD * res % MOD; 
		ans = (ll)ans * sum % MOD;
	}
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 44544
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  ll a,b,m;
  std::cin>>a>>b>>m;

  std::vector<ll> an(a),bn(b);
  rep(i,0,a)std::cin>>an[i];
  rep(i,0,b)std::cin>>bn[i];

  ll ans=std::numeric_limits<ll>::max();

  rep(i,0,m){
    ll x,y,c;
    std::cin>>x>>y>>c;
    x--;y--;
    chmin(ans,an[x]+bn[y]-c);
  }

  std::sort(all(an));
  std::sort(all(bn));

  chmin(ans,an[0]+bn[0]);

  std::cout<<ans<<"\n";

  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#define V 100090
#define mod 1000000007
#define LL long long
using namespace std;
int a,b,c,n;
int main()
{
   //freopen("fence8.in","r",stdin);freopen("fence8.out","w",stdout);
 // freopen("in.txt","r",stdin);//freopen("11.txt","w",stdout);
  cin>>a>>b>>c;
  if(a==b)cout<<c;
  else if(b==c)cout<<a;
  else if(a==c)cout<<b;
   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;
using P = pair<int, int>;

int main()
{
    ll x;
    ll ans = 0;
    ll ans5 = 0;
    cin >> x;
    ans = (x / 500);
    x = x - (ans * 500);
    ans5 = x / 5;
    cout << ans*1000 + ans5*5 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int s;
  cin>>s;
  vector<int>dp(2005);//cout<<s<<endl;
  dp[0]=1;
  for(int i=0;i<=s;i++){
    for(int now=3;now<=2000;now++){
      if(i+now<=2000){(dp[i+now]+=dp[i])%=mod;}
    }
  }
  cout<<dp[s]<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
    #include <algorithm>
    #include <string>
    #include <functional>
     
    using namespace std;
     
    int main() {
    	int n, k, a[50];
    	cin >> n >> k;
    	for (int i = 0; i < n; ++i) {
    		cin >> a[i];
    	}
    	sort(a, a + n, greater<int>());
     
    	int ans = 0;
    	for (int i = 0; i < k; ++i) {
    		ans += a[i];
    	}
    	cout << ans << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX

using namespace std;
using LL=long long;

int X[100005],Y[100005];

int main(){
    int n,W,H,x,y,w,ax=1,ay=1,xs=0,ys=0;
    cin>>n>>W>>H;
    for(int i=0;i<n;i++){
        cin>>x>>y>>w;
        X[max(0,x-w)]++;
        X[min(x+w,W)]--;
        Y[max(0,y-w)]++;
        Y[min(y+w,H)]--;
    }
    for(int i=0;i<W;i++){
        xs+=X[i];
        if(xs<=0) ax=0;
    }
    for(int i=0;i<H;i++){
        ys+=Y[i];
        if(ys<=0) ay=0;
    }
    if(ax||ay) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3872
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
       int a,b,c;
       a=in.nextInt();
       b=in.nextInt();
        for (int i = 1; i <=3; i++) {
            if(i!=a && i!=b){
                System.out.println(i);
            }
        }
    }
    
}

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

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    string s;
    cin >> s;

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);

    ll S;
    cin >> S;
    ll V = 1e9;
    ll x = V;
    ll y2 = (S - 1) / (V) + 1;
    ll x2 = 1;
    ll y = (x * y2 - S);
    cout << "0 0 " << x << " " << y << " " << x2 << " " << y2 << "\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b;

	cin>>a>>b;

	if(a>=13){
		cout<<b<<endl;
	} else if(a>=6){
		cout<<b/2<<endl;
	} else{
		cout<<0<<endl;
	}
}


Measured memory_bytes: 256
#define MAP(x,y)map[31+(x)+(y)*(W+1)+1]
#define MAP2(x,y)map2[31+(x)+(y)*(W+1)+1]
char map[32*31+2],map2[32*31+2],*D="ENWS",*p,c,c2;
main(){
	int W,H;
	int vx[]={1,0,-1,0},vy[]={0,-1,0,1};
	int t,x,y,d,i,e;
	for(;scanf("%d%d%[^0-9]",&W,&H,map+31),W;){
		e=1;
		for(t=0;e&&++t<180;){
			//puts(&MAP(0,0));
			//ツ陛サツ古シツ転ツ環キ
			e=0;
			for(y=0;y<H;y++){
				for(x=0;x<W;x++){
					p=strchr(D,MAP(x,y));
					if(p){
						e=1;
						d=p-D-1;//ツ古」ツづォツつゥツづァツ篠楪計ツ嘉アツづィツづ可陳イツづ猟づゥ
						for(i=4;i--;){
							d+=3;
							d%=4;
							c=MAP(x+vx[d],y+vy[d]);
							if(c=='.'||c=='X')
								MAP(x,y)=D[d];
						}
					}
				}
			}
			//ツ暗堋督ョ
			memcpy(map2,map,sizeof(map));
			for(y=0;y<H;y++){
				for(x=0;x<W;x++){
					c=MAP(x,y);
					if(c=='.'||c=='X'){
						for(d=0;d<4;d++){
							c2=MAP(x+vx[d],y+vy[d]);
							if(c2==D[d^2]){
								MAP2(x+vx[d],y+vy[d])='.';
								if(c=='.')
									MAP2(x,y)=c2;
								break;
							}
						}
					}
				}
			}
			memcpy(map,map2,sizeof(map));
		}
		printf(e?"NA\n":"%d\n",t-1);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
    return b ? gcd(b, a%b) : abs(a);
}

bool solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a < b) return false;
    if (d < b) return false;
    if (c >= b-1) return true;

    ll ra = a % b;
    ll step = gcd(d, b);
    ll cs = (c - ra + b) % step;

    return b <= step - cs + c;
}

int main() {
    ll t;
    cin >> t;
    while (t--) cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    int x;  cin >> x;
    if(x == 0)  print(1);
    else print(0);
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N,P;
  cin >> N >> P;
  //n[0]は偶数の個数, n[1]は奇数の個数
  int n[2]={};
  rep(i,N){
    int a;
    cin >> a;
    if(a%2==0) n[0]++;
    else n[1]++;
  }
  ll ans = pow(2,N-1);
  if(n[0]==N){
    if(P==0) cout << ans*2 << endl;
    else cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int N,K,T,U,V,L,D[10010];

int main() {
  cin>>N>>K>>T>>U>>V>>L;
  REP(i,0,N) cin>>D[i];

  int pos=D[0], vdist=0, di=1, keep=0;
  int diEnd = D[0]+V*T;
  queue<int> dq;

  while(1){
    REP(nowPos,pos,diEnd+1){
      if(nowPos!=pos)vdist++;
      if(nowPos == L)break;
      if(di < N && nowPos == D[di]){
        if(keep < K) keep++, dq.push(di);
        else{
          diEnd = max(nowPos,D[dq.front()]) + V*T;
          dq.pop();
          dq.push(di);
        }
        di++; //uodate next_Di_candidate
      }
      if(nowPos==diEnd && keep>0){
        diEnd = max(nowPos,D[dq.front()]) + V*T;
        dq.pop();
        keep--;
      }
    }
    pos = diEnd+1;
    if(pos >= L) break;

    bool flag = true;
    /*always leep is 0 here*/
    REP(nowPos,pos,L+1){
      if(di < N && D[di] == nowPos){
        pos = D[di];
        diEnd = D[di] + V*T;
        di++;
        //use immediately
        flag = false;
        break;
      }
    }
    if(flag) break;
  }

  double ans = (double)(L-vdist)/(double)U + (double)vdist/(double)V;
  printf("%.8lf\n", ans);

  return 0;
}

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

int main(){	
		
char a,b,c,d,e,f;

cin >> a >> b >> c >> d >> e >> f;

if(c==d&&e==f){
	cout << "Yes" << endl;
}else{
	cout << "No" << endl;
}		
			
return 0;	
}


Measured memory_bytes: 3672
#include<stdio.h>

int main(void)
{

    int n, i, h = 100000;

    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        h = h / 100 * 105;
        if(h % 1000 != 0)
            h = h / 1000 * 1000 + 1000;
    }

    printf("%d\n", h);

    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  int lim=100010;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<string,string> pi;

std::vector<bool> visited(lim);
std::vector<int> g[100010];
int dist[100010]={0};

void dfs(int node)
{
  // int ans=0;
  visited[node]=true;
  for(auto child: g[node])
  {
    if(!visited[child])
      dfs(child);

    dist[node]=std::max(dist[child]+1,dist[node]);
      
  }
  // cout<<"node ans "<<node<<" "<<ans<<endl;
  
}



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

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

  int ans=INT_MIN;
  for(int i=1;i<=n;i++)
  {
    if(!visited[i])
    {
      dfs(i);
    }
  }

  // cout<<ans<<endl;

  for (int i = 1; i <=n; ++i)
  {
    ans=std::max(ans,dist[i]);
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 12168
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	if (a == 1) a += 13;
	if (b == 1) b += 13;
	if (a > b) puts("Alice");
	if (a < b) puts("Bob");
	if (a == b) puts("Draw");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == 5 && b == 5 && c == 7) || (a == 5 && c == 5 && b == 7) || (a == 7 && b == 5 && c == 5)) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);

    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    if (s == u) a--;
    else b--;
    cout << a << " " << b << "\n";
}

Measured memory_bytes: 256
li = list(map(int,input().split()))
if li[0] == 7:
    if li[1]==5 and li[2]==5:
        print("YES")
    else:
        print("NO")
elif li[0] == 5:
    if li[1]==7:
        if li[2]==5:
            print("YES")
        else:
            print("NO")
    elif li[1] == 5:
        if li[2]==7:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3064
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    if len(S) == len(set(S)):
        print(yes)
    else:
        print(no)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
//
//  main.cpp
//  ABC167C2

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const ll INF=1001001001L;
int main(int argc, const char * argv[]) {
    int n,m,x;
    cin >> n >> m>>x;
    vector<int>c(n);
    int A[n][m];
    rep (i,n) {
        cin >> c.at(i);
        rep (j,m) {
            cin >> A[i][j];
        }
    }
    ll ans=INF;
    for (int k=0; k<(1<<n); k++) {
        ll cost=0;
        vector<int> sum(m);
        bool ok=true;
        for (int s=0; s<n; s++) {
            if (k>>s&1) {
                cost+=c.at(s);
                for(int i=0;i<m;i++){
                    sum.at(i)+=A[s][i];
                }
            }
        }
        /*
        rep(j,m){
            cout<< sum.at(j)<<" ";
        }
        cout<<endl;
         */
        for (int j=0; j<m; j++) {
            if (sum[j]<x) {
                ok=false;
            }
        }
        if (ok) {
            ans=min(ans,cost);
        }
    }
    if (ans==INF) {
        cout <<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define       pb                 push_back
#define       sf                 scanf
#define       pf                 printf
#define       sz                 200005
#define       MOD                1000000007
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

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

int dx[] = {0, 0, +1, -1};
int dy[] = {+1,-1, 0,  0};
/*============GRAPH MOVES==================*/
//const int fx[] = {1, -1, 0, 0};
//const int fy[] = {0, 0, 1, -1};
//const int fx[] = {0, 0, 1, -1, -1, 1, -1, 1};  // Kings move
//const int fy[] = {-1, 1, 0, 0, 1, 1, -1, -1};  // Kings move
//const int fx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; // Knights move
//const int fy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; // Knights move
/*=========================================*/

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return m-(abs(a)%m); else if(a<m) return a; else return (a%m); }
inline string tstring(ll a) {stringstream ss; ss << a; string str = ss.str(); return str; }

int dp[sz];

int main()
{
	//READ
	optimize

	dp[0] = 1;

	int s;

	cin >> s;

	for(int i = 3; i <= s; i++)
	{
		for(int j = 0; j <= i-3; j++)
		{
			dp[i] = modAdd(dp[i], dp[j]);
		}
	}

	cout << dp[s] << endl;

    return 0;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int k, s;

	cin >> k >> s;

	int ans = 0;
	for(int x=0; x<=k; x++){
		for(int y=0; y<=k; y++){
			int z = s - (x+y);
			if(z >= 0 && z <= k) ans++;
		}
	}

	cout << ans << endl;


	
	return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()

cnt=s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        k=2*j-i
        if j<k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                cnt-=1
print(cnt)


Measured memory_bytes: 68188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll func(ll b,ll n){
    if(n<b)return n;
    return func(b,(ll)(n/b))+n%b;
}
vector<ll> yak;
void yakusuu(ll x){
    for(ll i=1;i*i<=x;i++){
        if(x%i==0){
            yak.push_back(i);
            if(i*i!=x){
                yak.push_back(x/i);
            }
        }
    }
    sort(yak.begin(),yak.end());
}

int main(){fastio
    ll n,s;cin>>n>>s;
    for(ll i=2;i*i<=n;i++){
        if(func(i,n)==s){
            cout<<i<<endl;
            return 0;
        }
    }
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }else if(n-s<0){
        cout<<-1<<endl;
        return 0;
    }
    yakusuu(n-s);
    rep(i,0,(ll)yak.size()-1){
        ll b=yak[i]+1;
        if(func(b,n)==s){
            cout<<b<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
    
}





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

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		int p[100];
		for(int i=0;i<n;i++){
			cin >> p[i];
		}
		sort(p,p+n);
		int sum=0;
		for(int i=1;i<n-1;i++){
			sum += p[i];
		}
		cout << sum/(n-2) << endl;
	}
	return 0;
}

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

using namespace std;

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

const int INF = 1000000000;
const int N = 16;
int n;
int cost[N][N];
int hoge[N];

int dp[(1<<N)];

void init(){
  rep(i,(1<<N))dp[i]=-1;
}


bool input(){
  cin>>n;
  if(n==0)return false;

  rep(i,n){
    cin>>hoge[i];
    rep(j,n){
      cin>>cost[i][j];
    }
  }
  return true;
}

bool has(int s, int i){
  return (s&(1<<i))>0;
}

int getcost(int s,int num){
  int mini = hoge[num];
  rep(i,n){
    if(has(s,i))mini = min(mini, cost[num][i]);
  }
  return mini;
}

int saiki(int num){
  if(dp[num]!=-1)return dp[num];

  int mini = INF;
  for(int i=0;i<n;i++){
    if(!has(num,i)){
      mini = min(mini, saiki(num | (1<<i))+getcost(num,i));
    }
  }

  if(mini==INF)return dp[num]=0;
  return dp[num]=mini;
}
int solve(){
  return saiki(0);
}

int main(){
  while(init(),input())printf("%d\n",solve());
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;

    ll ans = pow(k-1,n-1) * k;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

ll gcd(ll a,ll b)
{
	if (a%b==0)return(b);
	else return(gcd(b,a%b));
}
 
int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
 
    sort(ALL(a));

    ll base = a.front();
    rep(i, n)base = gcd(base, a[i]);
    if(a.back() >= k && k%base == 0)cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
 
}

Measured memory_bytes: 1024
#include <iostream>

bool IsEaseString(std::string sentense);

int main(int argc, char const *argv[]) {

    std::string S;
    std::cin >> S;


    for(int times = S.length() - 1 ; times > 0 ; times--)
    {
        std::string check_sentence = S.substr(0,times);

        if(IsEaseString(check_sentence))
        {
            std::cout << check_sentence.length() << '\n';
            break;
        }

    }

    return 0;
}


bool IsEaseString(std::string sentence)
{
    int string_length = sentence.length();

    /** 2の倍数でない時点で同じ文字列を２つ並べた形にならない **/
    if(string_length % 2 == 1)
        return false;

    /** 前半と後半で文字列が同じならば偶文字列 **/
    std::string forward_sentence = sentence.substr(0,string_length/2);
    std::string back_sentence = sentence.substr(string_length/2,string_length/2);


    return forward_sentence == back_sentence;
}


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

int main()
{
  int N;
  int a[110];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i];

  sort(a,a+N);

  rep(i,N){
    rep(j,N){
      if(i==j) continue;
      res+= a[i]*a[j];
    }
  }

  cout << res/2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    if(b < a) {
        tmp = b;
        b = a;
        a = tmp;
    }
    if (c < b) {
        tmp = c;
        c = b;
        b = tmp;
    }
    if (b < a) {
        tmp = b;
        b = a;
        a = tmp;
    }

    printf("%d %d %d\n", a,b,c);
    return(0);
}



Measured memory_bytes: 2112
// Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include "bits/stdc++.h"

#pragma region Template

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define llint long long int;

using namespace std;

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#pragma endregion

template <typename T>
void write(T val, bool nl = true) {
	cout << val;
	if (nl) {
		cout << "\n";
	}
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

/* Entry Point */
int main()
{
	// ↓入出力高速化
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ↑
	
	int n, l;
	cin >> n >> l;
	vector<string> vs(n);
	REP(i, n) cin >> vs[i];
	VSORT(vs);
	REP(i, n) write(vs[i],false);	
	write("");

	return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
l=list(map(int,input().split()))
wa=0
for i in range(n):
  wa+=l[i]
ans=0
for i in range(n):
  if l[i]>=wa/4/m:
    ans+=1
if ans>=m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

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

int main(){
  ll n,k;
  cin >> n >> k;
  ll a = n%k;
  ll ans = min(a,abs(k-a));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			double a = scan.nextInt();
			double b = scan.nextInt();
			double e = scan.nextInt();
			double c = scan.nextInt();
			double d = scan.nextInt();
			double f = scan.nextInt();
			
			double x = (d * e - b * f) / (a * d - b * c);
			double y = (a * f - c * e) / (a * d - b * c);
			
			NumberFormat nf = NumberFormat.getInstance();
			nf.setMaximumFractionDigits(3);
			nf.setMinimumFractionDigits(3);
			
			if (x == 0) {
				x = 0;
			}
			if (y == 0) {
				y = 0;
			}
			
			System.out.println(nf.format(x) +" "+ nf.format(y));
		}
	}
}

Measured memory_bytes: 18280
mod=10**9+7
n,k=map(int,input().split())
A=list(map(int,input().split()))
K=k

B,C=[],[]
for i in A:
    if i>=0:B.append(i)
    else:C.append(i)

B.sort()
C.sort(key=lambda x:abs(x))

ans,flag=1,1
while k!=0:
    if k>=2:
        point=0
        if len(B)>=2 and len(C)>=2:
            if B[-1]*B[-2]>C[-1]*C[-2]:
                ans *=B.pop()
                point=1
            else:ans *=C.pop()*C.pop()
        elif len(B)>=2:ans *=B.pop()*B.pop()
        elif len(C)>=2:ans *=C.pop()*C.pop()
        else:flag=0
        k -=2-point
    else:
        if len(B)>=1:ans *=B.pop()
        else:flag=0
        k -=1
    ans %=mod

if flag:print(ans)
else:
    ans=1
    A=sorted(A,key=lambda x:abs(x))
    for i in range(K):
        ans *=A[i]
        ans %=mod
    print(ans)

Measured memory_bytes: 112576
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define erep(i, n) for (ll i = 1; i <= (n); i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
// input
ll h[100010];
// dp table
ll dp[100010];

int main(void) {
  int n, k;
  cin >> n >> k;
  rep(i, n) cin >> h[i];
  rep(i, 100010) dp[i] = INF;
  dp[0] = 0;
  rep(i, n) erep(j, k) { mins(dp[i + j], dp[i] + abs(h[i] - h[i + j])); }
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 5144
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    mn = 1e9
    for i in range(1 << N):
        for j in range(1 << N):
            n = []
            a = []
            b = []
            c = []
            for k in range(N):
                if (i >> k) % 2 == 0 and (j >> k) % 2 == 0:
                    n.append(k)
                if (i >> k) % 2 == 0 and (j >> k) % 2 == 1:
                    a.append(k)
                if (i >> k) % 2 == 1 and (j >> k) % 2 == 0:
                    b.append(k)
                if (i >> k) % 2 == 1 and (j >> k) % 2 == 1:
                    c.append(k)
            if len(a) == 0 or len(b) == 0 or len(c) == 0:
                continue
            else:
                m = 10 * (len(a) + len(b) + len(c) - 3) + abs(A - sum([l[aa] for aa in a])) + abs(B - sum([l[bb] for bb in b])) + abs(C - sum([l[cc] for cc in c]))
                if mn > m:
                    mn = m
    print(mn)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
vector<ll> h(MAX);

bool check(ll a,ll A,ll B,ll N){
    ll cnt=0;
    for(int i=0;i<N;i++){
        if(h[i]<=B*a) continue;
        cnt+=(h[i]-B*a+(A-B)-1)/(A-B);
    }
    if(cnt<=a) return true;
    return false;
}

int main(){
    
    int N;
    ll A,B;cin>>N>>A>>B;
    for(int i=0;i<N;i++){
        cin>>h[i];
    }
    ll left=0,right=1000000000;
    while(left!=right){
        ll mid=(left+right)/2;
        if(check(mid,A,B,N)) right=mid;
        else left=mid+1;
    }
    if(check(left,A,B,N)) cout<<left<<endl;
    else cout<<left+1<<endl;
}


Measured memory_bytes: 1024
#ABC131
N,L = map(int,input().split())
f = 0
k = 0
j = []
for i in range(1,N+1):
    f += L+i-1
for i in range(1,N+1):
    k = L+i-1
    n = f-k
    p = abs(f-n)
    j.append(p)
if f >0:
    print(int(f-min(j)))
else:
    print(int(f+min(j)))


Measured memory_bytes: 9104
#include <stdio.h>

int main(void)
{
  char a[102], b[102], c[102], now;
  int ai=0, bi=0, ci=0;
  scanf("%s %s %s", a, b, c);

  now = a[ai];
  if(now != 'a') ai++;
  
  while(1){
    if(now == 'a'){
      if(a[ai] == '\0'){
	printf("A\n");
	break;
      }
      now = a[ai];
      ai++;
    }else if(now == 'b'){
      if(b[bi] == '\0'){
	printf("B\n");
	break;
      }
      now = b[bi];
      bi++;
    }else if(now == 'c'){
      if(c[ci] == '\0'){
	printf("C\n");
	break;
      }
      now = c[ci];
      ci++;
    }
  }
  return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
bulbs = []
for i in range(M):
    _, *conn_switches = map(int, input().split())
    bulbs.append(conn_switches)
P = list(map(int, input().split()))

ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j, conn_switches in enumerate(bulbs):
        if P[j] ^ sum(i >> s - 1 & 1 for s in conn_switches) & 1:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
use List::Util min;
$\="\n";
$,=",";
($n,$x,$y)=glob<>;
for $i(1..$n){
  for$j(1..$i-1){
    $a[min ($i-$j,abs($j-$x)+1+abs($y-$i))]++;
  }
}
for(1..$n-1){
  print($a[$_]||0)
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FIO "A" 
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

int n,a,b;
ll ans=0; 

int main()
{
#ifdef dxymaster
	freopen(FIO".in","r",stdin);
	freopen(FIO".out","w",stdout);
#endif

	n=read();a=read(),b=read();
	if(a>b) return puts("0"),0;
	if(a==b) return puts("1"),0;
	if(n==1) return puts("0"),0;
	ans=1LL*(b-a)*(n-2);
	cout << ans + 1 << endl;

#ifdef dxymaster
	cerr<< " Time: " << (double) clock() / CLOCKS_PER_SEC << "s			It Runs So Fast!" << endl;
#endif

	return 0;
}


Measured memory_bytes: 256
// author : Kartikey Tewari
// date: 2020-02-22   17:50:19
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;

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

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

    double a=log10(n+1)/log10(k);
    cout << ceil(a) << endl;

    // if (floor(a)!=a)
    // {
    //     cout << floor(a)+1 << endl;
    // }
    // else
    // {
    //     cout << a << endl;
    // }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
int dp[300001],dp1[300001];
string kal;
int c,n,k;
set<int>pos;
set<int>posi;
int solve(int index)
{
    int ans=1;
    auto u = pos.lower_bound(index+c+1);
    if(dp[index]!=-1)return dp[index];
    if(u!=pos.end())
    {
       ans=max(ans,1+solve((*u))); 
    }
    return dp[index]=ans;
}
int solve1(int index)
{
    int ans=1;
    auto u = posi.lower_bound(-index+c+1);
    if(dp1[index]!=-1)return dp1[index];
    if(u!=pos.end() && (*u)<=0)
    {
       ans=max(ans,1+solve1(-(*u))); 
    }
    return dp1[index]=ans;
}
int main()
{
  //flash;
  cin>>n>>k>>c;
  cin>>kal;
  ve kaki;
  memset(dp,-1,sizeof dp);
  memset(dp1,-1,sizeof dp1);
  for (int i = 0; i < kal.size(); ++i)
  {
      if(kal[i]=='o'){pos.insert(i);posi.insert(-i);kaki.pb(i);}
  }
  for(auto it:pos){solve(it);solve1(it);}
  int last=0;
  ve ans;
  for (int i = 0; i < kaki.size(); ++i)
  {
    int v=0;
    int s=0;
    if((i+1)>=kaki.size())s=0;
    else s = dp[kaki[i+1]];
    if((i-1)<0)v=0;
    else v = dp1[kaki[i-1]];
    if((v+s)<k)ans.pb(kaki[i]);
  }
  for(auto it:ans)cout<<it+1<<'\n';
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 29300
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	n%=10;
	if(n==2 || n==4 || n==5 || n==7 || n==9)
		cout<<"hon"<<'\n';
	else if(n==3){
		cout<<"bon"<<'\n';
	}
	else
		cout<<"pon"<<'\n';
}


Measured memory_bytes: 3612