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

char map[255][255];
int dire4[][2] = { {1, 0}, {-1, 1}, {0, 1}, {1, 1} };

int main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;

        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                cin >> map[y][x];
            }
        }

        int ans = 0;
        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                for(int z = 0;z < 4;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y, c = 0;
                    for(;map[cy][cx] == '1' && 0 <= cx && cx < n && 0 <= cy && cy < n;cx += dx, cy += dy, c++);
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1224
def fibonacci_dp(n,lf):
    if n == 0 or n == 1:
        return lf[n]
    if n < len(lf):
        return lf[n]
    lf.insert(n,fibonacci_dp(n-2,lf) + fibonacci_dp(n-1,lf))
    return lf[n]

if __name__ == "__main__":
    n = int(input())
    lf = [1,1,]
    print(fibonacci_dp(n,lf))



Measured memory_bytes: 5596
# -*- coding: utf-8 -*-
x, y = map(int, raw_input().split())

g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

xg = 0
yg = 0

if x in g1:
    xg = 1
elif x in g2:
    xg = 2
elif x in g3:
    xg = 3

if y in g1:
    yg = 1
elif y in g2:
    yg = 2
elif y in g3:
    yg = 3

if xg == yg:
    print 'Yes'
else:
    print 'No'

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

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

  map<int, int> mp;
  mp[s]++;

  int ans = 1;
  while (1) {
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = 3 * s + 1;
    }

    if (mp.count(s)) {
      cout << ans + 1 << endl;
      return 0;
    } else {
      mp[s]++;
      ans++;
    }
  }

}


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

int main() {
  long A, B, N;
  cin >> A >> B >> N;
  // cout << (A * N) / B - A * (N / B) << "\n";
  // for (int i = 0; i <= N; i++) {
  //   cout << (A * i) / B - A * (i / B) << "\n";
  // }
  if (N < B - 1) cout << (A * N) / B - A * (N / B) << "\n";
  else cout << (A * (B - 1)) / B - A * ((B - 1) / B) << "\n";
}

Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    cout<<(1ll<<static_cast<ll>(ceil(log2(in()+1))))-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  set<string> st;
  while (n--) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19288
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>
#include<queue>

using namespace std;


int main(){

	int ans=0;
	int h,n;
	cin>>h>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		h-=a[i];
	}
	if(h>0)cout<<"No";
	else cout<<"Yes";





	cout<<endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define F first
#define S second
#define T  third
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define MT make_tuple
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}

int32_t main(){
   ios_base::sync_with_stdio(0);cin.tie(0);   cout.tie(0);
   int n, W;
   cin >> n >> W;
   vector<int> dp(W + 1, 0);
   for(int i = 0 ; i < n; i ++){
      int weight, value;
      cin >> weight >> value;
      for(int wa = W - weight; wa >= 0; wa --){
         dp[wa + weight] = max(dp[wa + weight], dp[wa] + value);
      }
   }
   int ans = 0;
   for(int i = 0 ; i <= W; i ++)
      ans = max(ans, dp[i]);
   cout << ans;
}


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

int main() {
  int N; cin >> N;
  pair<int, int> J[N];
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    J[i] = make_pair(a, b);
  }
  sort(J, J+N, [](auto &a, auto &b) {
    return a.second < b.second;
  });
  long t = 0; bool res = true;
  for (int i = 0; i < N; i++) {
    t += J[i].first;
    if (t > J[i].second) {
      res = false; break;
    }
  }
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define   ll     long long int

const int N = 200005;
ll ara[N];
ll lft[N];
ll rht[N];

int main( )
{
    ll n, i, j, k, mn = 1e18;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
        lft[i] = lft[i - 1] + ara[i];
    }
    for (i = n; i >= 1; i--) {
        rht[i] = rht[i + 1] + ara[i];
    }
    for (i = 2; i <= n; i++) {
        mn = min(mn, abs(lft[i - 1] - rht[i]));
    }
    cout << mn << '\n';
    return 0;
}



Measured memory_bytes: 4992
#include <stdio.h>

#define NODE (100)
#define INF (100000000)

int cost[NODE][NODE];

int min(int a, int b)
{
    return (b > a ? a : b);
}

int main(void)
{
	int i, j, k;
	int n;
	int from, to, m, s;
    int g1, g2;
    int V;
    int ans;
    
	while (1){
		scanf("%d%d%d%d%d", &V, &n, &s, &g1, &g2);
		
        if (V + n + s + g1 + g2 == 0){
			break;
		}
		
        s--;
        g1--;
        g2--;
        
		for (i = 0; i < V; i++){
			for (j = 0; j < V; j++){
				cost[i][j] = INF;
			}
			cost[i][i] = 0;
		}
		
		while (n-- != 0){
			scanf("%d%d%d", &from, &to, &m);
			cost[from - 1][to - 1] = m;
		}
        
        ans = INF;
		for (k = 0; k < V; k++){
            for (i = 0; i < V; i++){
                for (j = 0; j < V; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
        
		for (i = 0; i < V; i++){
			ans = min(ans, cost[s][i] + cost[i][g1] + cost[i][g2]);
		}
		
		printf("%d\n", ans);
	}
	return (0);
}

Measured memory_bytes: 1064
H,W,N = gets.split.map(&:to_i)
sr,sc = gets.split.map(&:to_i)
l,r,u,d = sc,sc,sr,sr
S = gets.chomp
T = gets.chomp

N.times do |i|
  c = S[i]
  if c == "L"
    l -= 1
  elsif c == "R"
    r += 1
  elsif c == "U"
    u -= 1
  elsif c == "D"
    d += 1
  end

  if l < 1 || r > W || u < 1 || d > H
    puts "NO"
    #p [l,r,u,d]
    exit
  end

  c = T[i]
  if c == "L"
    r -= 1 if r > 1
  elsif c == "R"
    l += 1 if l < W
  elsif c == "U"
    d -= 1 if d > 1
  elsif c == "D"
    u += 1 if u < H
  end

  #p [l,r,u,d]
end
puts "YES"


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int n;
vector<int> dp(200005, INF);  /* dp[i] := 長さがi+1である増加部分列における最終要素の最小値 */
vector<int> a, ans;
vector<int> edge[200005];

void dfs(int point, int parent) {
    int idx = lower_bound(ALL(dp), a[point]) - dp.begin();   /* 更新する場所を覚える */
    int pre = dp[idx];  /* 更新する場所の値を覚える */

    ans[point] = idx + 1;

    dp[idx] = a[point];   /*更新*/
    if(parent != -1) ans[point] = max(ans[point], ans[parent]);

    REP(i, edge[point].size()) {
        if(parent != edge[point][i]) dfs(edge[point][i], point);
    }

    dp[idx] = pre;      /* 戻す */
}

int main() {
    cin >> n;
    a.resize(n), ans.resize(n);
    REP(i, n) cin >> a[i];

    REP(i, n-1) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }

    dfs(0, -1);
    REP(i, n) cout << ans[i] << endl;

    return 0;
}

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

using namespace std;

int main()
{

    int n;
    cin>>n;
    int a[4]={0};
    for(int i=0 ; i<n ; i++){
        string s;
        cin>>s;
        if(s=="AC")
            a[0]+=1;
        else if(s=="WA")
            a[1]+=1;
        else if(s=="TLE")
            a[2]+=1;
        else
            a[3]+=1;
    }


     cout<<"AC x "<<a[0]<<endl;
     cout<<"WA x "<<a[1]<<endl;
     cout<<"TLE x "<<a[2]<<endl;
     cout<<"RE x "<<a[3]<<endl;







}


Measured memory_bytes: 3556
N, M, K = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)

aa = [0]
bb = [0]
N.times do |i|
    aa << a[i] + aa.last
end
M.times do |i|
    bb << b[i] + bb.last
end

ans, j = 0, M
(N + 1).times do |i|
    break if aa[i] > K
    while bb[j] > K - aa[i]
        j -= 1
    end
    ans = i + j if i + j > ans
end

puts ans

Measured memory_bytes: 45044
#include <stdio.h>
#define MAXSIZE 50

typedef long long int lli;

lli layer[MAXSIZE] = {};
lli paties[MAXSIZE] = {};

lli get_layer(int n){
    if(n == 0){
        return 1;
    }
    if(layer[n] == 0){
        return layer[n] = get_layer(n - 1) * 2 + 3;
    }else{
        return layer[n];
    }
}

lli get_paties(int n){
    if(n == 0){
        return 1;
    }
    if(paties[n] == 0){
        return paties[n] = get_paties(n - 1) * 2 + 1;
    }else{
        return paties[n];
    }
}

lli find_paties(int n, lli x){
    if(x == 1){
        //return 0;
        return (n == 0)? 1 : 0;
    }else if(x <= 1 + get_layer(n - 1)){
        return find_paties(n - 1, x - 1);
    }else if(x == 2 + get_layer(n - 1)){
        return get_paties(n - 1) + 1;
    }else if(x <= 2 + 2 * get_layer(n - 1)){
        return get_paties(n - 1) + 1 + find_paties(n - 1, x - (2 + get_layer(n - 1)));
    }else{
        return 2 * get_paties(n - 1) + 1;
    }
}

int main(void){
    int n;
    lli x;
    scanf("%d %lld", &n, &x);
    //get_layer(n);
    //get_paties(n);
    printf("%lld\n", find_paties(n, x));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rng(i,a,b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define repd(i, n) for(ll i = (ll)(n)-1;i>=0;--i)
#define rngd(i,b,a) for(ll i = (ll)(b);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define ctoi(x) ((x)-'0')

int main() {
  int ans=0;
  int n,m,k;
  bool p[10];
  vector<int> s=vector<int>(10,0);
  cin>>n>>m;
  rep(i,m){
    cin>>k;
    rep(j,k){
      int tmp;
      cin>>tmp;
      s[i]|=(1<<(tmp-1));
    }
  }
  rep(i,m){
    bool tmp;
    cin>>tmp;
    p[i]=tmp;
  }
  
  int cnt=0;
  rep(i,(1<<n)){
    cnt=0;
    rep(j,m){
      if(__builtin_popcount(s[j]&i)%2==p[j]){
        cnt++;
      }else{
        break;
      }
    }
    if(cnt==m){
      ans++;
    }
  }

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

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

using namespace std;

constexpr static int MAXN = 1e6;

int K;
int a[MAXN];

pair <int64_t, int64_t> solve() {
    if (a[K - 1] != 2)
        return {-1, -1};

    int64_t l = 2;
    int64_t r = 3;
    for (int i = K - 2; i >= 0; i--) {
        // a[i] * dl >= l
        int64_t dl = (l + a[i] - 1) / a[i];
        // a[i] * dr <= r
        int64_t dr = r / a[i];
        if (dl > dr || dr == 0)
            return {-1, -1};
        l = dl * a[i];
        if (l == 0)
            l = 1;
        r = dr * a[i] + a[i] - 1;
    }
    return {l, r};
}

int main() {
    cin >> K;
    for (int i = 0; i < K; i++)
        cin >> a[i];

    auto p = solve();
    if (p.first == -1)
        cout << -1 << endl;
    else
        cout << p.first << " " << p.second << endl;
}


Measured memory_bytes: 640
n,m,v[100*100],w[50*50],w2[50*50],o;
R(){
	int x,y;
	o=-1;
	for(y=0;y<m;y++){
		for(x=0;x<m;x++){
			w2[x+m*y]=w[m-1-y+m*x];
			if(o==-1&&w2[x+m*y]!=-1)
				o=x+m*y;
		}
	}
	memcpy(w,w2,4*m*m);
}
F(x,y){
	int xx,yy;
	for(yy=0;yy<m;yy++)
		for(xx=0;xx<m;xx++)
			if(w[xx+m*yy]!=-1&&v[x+xx+n*(y+yy)]!=w[xx+m*yy])
				return 0;
	return 1;
}
main(){
	int d,x,y,t,f;
	for(;scanf("%d%d",&n,&m),n;){
		for(x=0;x<n*n;x++)
			scanf("%d",v+x);
		for(x=0;x<m*m;x++)
			scanf("%d",w+x);
		f=n*n;
		for(d=4;d--;){
			R();
			for(y=0;y+m<=n;y++)
				for(x=0;x+m<=n;x++)
					if(F(x,y)&&(t=x+o%m+(n+o/m)*y)<f)
						f=t;
		}
		printf(f<n*n?"%d %d\n":"NA\n",1+f%n,1+f/n);
	}
	exit(0);
}

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

int main(){
  string s,t,u;
  int a,b,c;
  cin >>s>>t>>a>>b>>u;
  if(s==u){
    cout << a-1 << " " << b << endl;
  }else{
    cout << a << " " << b-1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int d = sc.nextInt();
		int n = sc.nextInt();

		if (n == 100) {
			n = 101;
		}

		System.out.println(n * (d == 0 ? 1 : d == 1 ? 100 : 10000));

		sc.close();
	}
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define ll long long int
#define pii <pair<ll,ll>>
using namespace std;

int digit(ll p)
{
    ll c=0;
    while(p>0)
    {
        c++;
        p=p/10;
    }
    return c;
}

void solve()
{
    ll n;
     cin >> n;
     ll ans=0;
     for(int i=1;i<=n;i++)
     {
         if(digit(i)%2!=0)
            ans++;
     }
     cout << ans << endl;
}

int main()
{
     solve();
     return 0;
}

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

using namespace std;

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

	vector<double> a(n);
	double ave = 0.0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ave += a[i];
	}
	ave /= n;

	double mn = 1010101010;
	int ans = -1;
	for (int i = 0; i < n; i++) {
		a[i] = fabs(ave - a[i]);

		if (a[i] < mn) {
			mn = a[i];
			ans = i;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int memo[1001][1001];
int kati[1001];
int omosa[1001];
int W;
int N;

int max(int a, int b)
{
	if (a >= b){
		return (a);
	}
	return (b);
}

int calc(int index, int w)
{
	int ans;
	
	ans = 0;
	
	if (index == N){
		return (0);
	}
	
	if (memo[index][w] == -1){
		/*盗る*/
		if (w - omosa[index] >= 0){
			ans = calc(index + 1, w - omosa[index]) + kati[index];
		}
		
		/*盗らない*/
		ans = max(ans, calc(index + 1, w));
	}
	else {
		ans = memo[index][w];
	}
	
	memo[index][w] = ans;
	
	return (ans);
}

int main(void)
{
	int i, j;
	int deta;
	
	int ma;
	int ma_weight;
	
	
	deta = 1;
	while (1){
		scanf("%d", &W);
		if (W == 0){
			break;
		}
		scanf("%d", &N);
		
		for (i = 0; i < N; i++){
			scanf("%d,%d", &kati[i], &omosa[i]);
		}
		
		for (i = 0; i < N; i++){
			for (j = 0; j < 1001; j++){
				memo[i][j] = -1;
			}
		}
		
		ma = -1;
		ma_weight = -1;
		for (i = W; i >= 0; i--){
			int temp = calc(0, i);
			if (temp >= ma){
				ma = temp;
				ma_weight = i;
			}
		}
		
		printf("Case %d:\n", deta);
		printf("%d\n", ma);
		printf("%d\n", ma_weight);
		
		deta++;
	}
	
	return (0);
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    rep(i, n) {
        int x;
        cin >> x;
        if (!(a <= x && x < b)) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int H, W;
    cin >> H >> W;

    vs grid(H);
    for (int i = 0; i < H; i++) {
        cin >> grid[i];
    }

    vvi left(H, vi(W)), up(H, vi(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) if(grid[i][j] != '#') {
            left[i][j] = 1 + (j ? left[i][j-1] : 0);
            up[i][j] = 1 + (i ? up[i-1][j] : 0);
        }
    }

    int ans = 0;

    vvi right(H, vi(W)), down(H, vi(W));
    for (int i = H - 1; i >= 0; i--) {
        for (int j = W - 1; j >= 0; j--) if (grid[i][j] != '#') {
            right[i][j] = 1 + (j+1<W ? right[i][j+1] : 0);
            down[i][j] = 1 + (i+1<H ? down[i+1][j] : 0);

            ans = max(ans, down[i][j] + up[i][j] + left[i][j] + right[i][j] - 3);
        }
    }

    cout << ans << endl;

    return 0;
}



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

int main(){
    int H, W;
    cin >> H >> W;

    vector<vector<char>> image(H,vector<char>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> image.at(i).at(j);
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << image.at(i).at(j);
        }
        cout << endl;
        for(int k = 0; k < W; k++){
            cout << image.at(i).at(k);
        }
        cout << endl;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#define INFTY 1000000001

using namespace std;
int A[500001], L[500001], R[500001];
int n;
int countNum = 0;

void merge(int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(int i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	int i = 0;
	int j = 0;
	for(int k = left; k < right; k++){
		countNum++;
		if(L[i] <= R[j]){
			A[k] = L[i];
			i++;
		}else{
			A[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int left , int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}


int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	mergeSort(0, n);
	for(int i = 0; i < n - 1; i++){
		cout << A[i] <<" ";
	}
	cout<<A[n - 1] << endl;
	cout << countNum << endl;
	return 0;
}

Measured memory_bytes: 6048
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int h, n, a[100001];
    scanf("%d%d", &h, &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    for (int i = n - 1; i >= 0; i--)
    {
        h -= a[i];
        if (h <= 0)
        {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define loop1(x,s,e) for(int x=s;x!=e;x+=1-2*(s>e))
#define input_matrix(a,m,n) for(int i=0;i<m;i++)for(int j=0;j<n;j++)cin>>a[i][j];
#define input_array(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define all(x) x.begin(),x.end()
#define newl "\n"
#define tests(t) int t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
 {
	string s;
	cin>>s;
	int len=s.length();
	int flag=1;
	for(int i=0;i<len;i++)
	{
	    int j=i+1;
	    if( j%2==0 && (s[i]=='R')) flag=0;
	    if( j%2 && (s[i]=='L')) flag=0;
	}
	if(flag)
	    cout<<"Yes";
	else
	    cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            pos = [(0, 0) for i in range(n)]
            for i in range(1, n):
                n, d = map(int, raw_input().split())
                if d == 0:
                    pos[i] = (pos[n][0] - 1, pos[n][1])
                elif d == 1:
                    pos[i] = (pos[n][0], pos[n][1] - 1)
                elif d == 2:
                    pos[i] = (pos[n][0] + 1, pos[n][1])
                elif d == 3:
                    pos[i] = (pos[n][0], pos[n][1] + 1)
            width = max(x for x, y in pos) - min(x for x, y in pos) + 1
            height = max(y for x, y in pos) - min(y for x, y in pos) + 1
            print width, height
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4708
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

int main(void) {
    string s;
    cin >> s;
    ll i;
    ll min=(ll)s.size();
    for(i=0; i<s.size()-1; i++) {
        if(s[i]!=s[i+1]) {
            min=min(min, max(i+1, (ll)s.size()-i-1));
        }
    }
    
   prin(min);

}

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

int main() {
    string a;
    int s = 0;
    cin >> a;
    for(int i=0; i<a.size(); i++) {
        s += (int)(a[i] - '0');
    }
    if(s%9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3716
package main

import (
	"fmt"
	"io"
	"os"
)

func proc(r io.Reader, w io.Writer) {
	var n, d int
	fmt.Fscanf(r, "%d", &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &d)
		arr[i] = d
	}

	uniq := map[int]int{}
	for i := 0; i < n; i++ {
		uniq[arr[i]] = 1
	}
	res := 0
	for _, v := range uniq {
		res += v
	}
	fmt.Fprintf(w, "%d", res)
}

func main() {
	proc(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 2e3 + 5;
int n, m, k, pos;

int main(){
    string s;
    cin >> s;
    if(s == "SUN") puts("7");
    else if(s == "MON") puts("6");
    else if(s == "TUE") puts("5");
    else if(s == "WED") puts("4");
    else if(s == "THU") puts("3");
    else if(s == "FRI") puts("2");
    else if(s == "SAT") puts("1");
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=(1<<16);
int n,m;
int cst[22][22];
int f[22][maxn],dp[22][maxn];
int fa[22];
inline int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}
int check(int msk)
{
	int sum=0;
	for(int i=0;i<n;i++)fa[i]=i;
	for(int i=0;i<n;i++)if(msk>>i&1)
	{
		for(int j=i+1;j<n;j++)if((msk>>j&1)&&~cst[i][j])
		{
			int x=getfa(i),y=getfa(j);
			fa[x]=y;
			sum+=cst[i][j];
		}
	}
	int p=-1;
	for(int i=0;i<n;i++)if(msk>>i&1)
	{
		if(p==-1)p=getfa(i);
		else
		{
			if(p!=getfa(i))return -1;
		}
	}
	return sum;
}
int good[maxn];
inline void update(int &a,int b)
{
	if(a<b)a=b;
}
int main()
{
	memset(cst,-1,sizeof(cst));
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		cst[a][b]=cst[b][a]=c;
	}
	memset(f,-1,sizeof(f));
	memset(good,-1,sizeof(good));
	for(int msk=0;msk<(1<<n);msk++)
	{
		good[msk]=check(msk);
		for(int i=0;i<n;i++)if(msk>>i&1)
		{
			f[i][msk]=good[msk];
		//	if(~f[i][msk])good[msk]=1;
	//		cout<<i<<" "<<msk<<" "<<f[i][msk]<<endl;
		}
	}
	
	//1
	memset(dp,-1,sizeof(dp));
	for(int msk=0;msk<(1<<n);msk++)
	{
		dp[0][msk]=f[0][msk];
	}
	for(int msk=0;msk<(1<<n);msk++)
	{
		for(int i=0;i<n;i++)if((msk>>i&1)&&(~dp[i][msk]))
		{
			int rmsk=((1<<n)-1)^msk;
			for(int s=rmsk;s;s=(s-1)&rmsk)if(~good[s])
			{
				for(int j=0;j<n;j++)if((s>>j&1)&&(~cst[i][j]))
				{
					update(dp[j][msk|s],dp[i][msk]+cst[i][j]+good[s]);
				}
			}
		}
	}
	
	int ans=inf;
	int sum=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(~cst[i][j])sum+=cst[i][j];
	for(int msk=0;msk<(1<<n);msk++)
	{
		if(~dp[n-1][msk])
		{
			ans=min(ans,sum-dp[n-1][msk]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11776
N = int(input())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a+b,a,b])

AB.sort(reverse = True)
ans = 0
for i in range(N):
    if i%2 == 0:
        ans += AB[i][1]
    else:
        ans -= AB[i][2]
print(ans)

Measured memory_bytes: 59608
#include<stdio.h>

static const int MAX = 500;
static const int INFTY=(1<<21);

int main( ){
  int i,j,n,u,vg,k,c;
  int Adj[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int mini,sum;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      Adj[i][j] = INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&vg,&c);
      Adj[u][vg] = c;
    }
  }
  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    v[i] = 0;
  }
  d[0] = 0;

  while(1){
    mini = INFTY;
    u = -1;
    for(i=0;i<n;i++){
      if(mini>d[i]&&!v[i]){
	u=i;
	mini=d[i];
      }
    }
    if(u==-1)break;
    v[u]=1;
    for(vg=0;vg<n;vg++){
      if(!v[vg] && Adj[u][vg]!=INFTY){
	if(d[vg]>d[u]+Adj[u][vg]){
	  d[vg]=d[u]+Adj[u][vg];
	}
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){
   
    printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
  }
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 != 0) cout << "Odd";
  else cout << "Even";
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = input()
b = input()
c = input()

count = 0
for i in range(0, n):
    if (a[i] != b[i] and a[i] != c[i] and c[i] != b[i]):
        count += 2
    elif (a[i] == b[i] and a[i] == c[i]):
        count = count
    else:
        count += 1
print(count)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/



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

    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    for (int i = 0; i<n; i++) a[i]-=i;

    sort(a.begin(), a.end());
    int cur = a[n/2];
    ll ans = 0;
    for (int i = 0; i<n; i++) ans+=abs(a[i]-cur);
    cout<<ans;


}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a + b + c;

	if (sum >= 22) { cout << "bust" << endl; }
	else { cout << "win" << endl; }

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int main()
{
    int h=in(), w=in();

    int cnt = 0;

    rep(i,h)rep(j,w){
        char a;
        scanf("\n%c",&a);
        cnt += a == '#';
    }

    printf("%s\n", cnt == h + w - 1 ? "Possible" : "Impossible");
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define vi           vector<ll>
#define pii          pair<ll,ll>
#define vpp          vector<pii>
#define mii          map<ll,ll>
#define pb           push_back
#define endl        '\n'
#define rep(i,a,bb)  for(ll i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         ll T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzll(x)
const ll inf = 5 * (1e+18);
const ll mod = 7 + 1e+9;




int32_t main()
{
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif


  /*ll n, m, q;
  cin >> n >> m >> q;
  vector<pair<ll, pair<ll, pair<ll, ll>>>> v;
  while (q--)
  {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    v.pb({d, {a, {b, c}}});

  }
  vi arr(n + 1, 0);
  __rsort(v);
  ll ans = 0;
  for (auto i : v)
  {
    ll d = i.ff;
    ll a = i.ss.ff;
    ll b = i.ss.ss.ff;
    ll c = i.ss.ss.ss;
    if (arr[a] == 0 && arr[b] == 0)
    {
      if (c < m) {
        ans += d;
        arr[a] = 1;
        arr[b] = 1 + c;
      }


    }
    else if (arr[a] == 0)
    {
      if (arr[b] - c > 0)
      {
        ans += d;
        arr[a] = arr[b] - c;
      }

    }
    else if (arr[b] == 0)
    {
      if (arr[a] + c < m + 1)
      {
        arr[b] = arr[a] + c;
        ans += d;
      }

    }
    else
    {

      if (abs(arr[b] - arr[a]) == c)ans += d;
    }

  }

  cout << ans;*/


  ll a, b, n;

  cin >> a >> b >> n;


  cout << a*min(n, b - 1) / b << endl;



  return 0;
}





Measured memory_bytes: 3536
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  rep(i,n+1) {
    mint now = c(n,i);
    now *= c.p(m,n);
    now *= c.p(m-i,n-i);
    if (i&1) now = -now;
    ans += now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

vector<int> c, s, f;
int n;
vector<int> ans;

void gotoN(int pos){
    int now = s[pos];
    for(int i = pos; i < n-1; i++){
        now = now + c[i];
        if(i == n-2) break;
        if(now <= s[i+1]) now = s[i+1];
        else {
            if(now % f[i+1] == 0) continue;
            else now += (f[i+1] - now%f[i+1]);
        }
    }
    ans.push_back(now);
}

int main(){
    cin >> n;
    c.resize(n-1), s.resize(n-1), f.resize(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    rep(i,n-1) gotoN(i);
    ans.push_back(0);
    for(auto elem : ans) cout << elem << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#define ll long long
using namespace std;

int main()
{
    int n;
    ll sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0)
            continue;
        else
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,ans=0;cin>>N;
  ll l=to_string(N).length();
  vector<lvector> V(l+1);
  bool is_continue=true;
  V[0].emplace_back(0);
  for(ll i=1;i<l+1;++i) {
    for(ll j:V[i-1]) {
      if(j*10+3<=N) V[i].emplace_back(j*10+3);
      else {is_continue=false;break;}
      if(j*10+5<=N) V[i].emplace_back(j*10+5);
      else {is_continue=false;break;}
      if(j*10+7<=N) V[i].emplace_back(j*10+7);
      else {is_continue=false;break;}
    }
    if(!is_continue) break;
  }
  string s;
  rep(i,l+1) {
    for(ll j:V[i]) {
      s=to_string(j);
      if(find(s.begin(),s.end(),'3')!=s.end()&&
         find(s.begin(),s.end(),'5')!=s.end()&&
         find(s.begin(),s.end(),'7')!=s.end()  ) ans++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, res = 1;
int main(void){
    // Your code here!
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i <= n; i++) res = res * i % 1000000007;
    for (int i = 1; i <= m; i++) res = res * i % 1000000007;
    cout << (abs(n - m) ? res : res * 2 % 1000000007) << endl;
}


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

typedef long long ll;
ll n, mn = 1e18;
int main()
{
	ll i;
	cin >> n;
	for (i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			mn = min(mn, i - 1 + n / i - 1);
		}
	}
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int K[N];
  int A[N][M];
  int count[M];
  for(int i=0;i<M;i++) count[i]=0;
  for(int i=0;i<N;i++){
    cin >> K[i];
    for(int j=0;j<K[i];j++){
      cin >> A[i][j];
      count[A[i][j]-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<M;i++){
    if (count[i]==N) ans++;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'003;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

long long power(long long x, long long n, long long mod = MOD) {
    if (n <= 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

void solve() {
    int q,x,d,n;
    cin >> q;
    VLL k(1000003*2);
    k[0] = 1;
    REP(i,1,1000003*2) k[i] = (k[i-1] * i) % MOD;

    REP(i,0,q) {
        cin >> x >> d >> n;
        if (d == 0) cout << power(x,n) << endl;
        else if (n >= MOD) cout << 0 << endl;
        else {
            cout << ((k[(x * power(d, MOD-2)) % MOD + n - 1] * power(k[(x * power(d, MOD-2)) % MOD - 1], MOD-2)) % MOD * power(d, n)) % MOD << endl;
        }
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 16512
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  private final static List<String> permutation = new ArrayList<>();

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

    int n = sc.nextInt();

    int[] x = new int[n];
    int[] y = new int[n];

    StringBuilder input = new StringBuilder();
    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      input.append(i + 1);
    }

    permutation(input.toString(), "");
    BigDecimal sum = new BigDecimal(0);
    for (String s : permutation) {
      for (int j = s.length(); j > 1; j--) {
        int firstIndex = Character.getNumericValue(s.charAt(j - 1)) - 1;
        int secondIndex = Character.getNumericValue(s.charAt(j - 2)) - 1;
        int xSum = x[firstIndex] - x[secondIndex];
        int ySum = y[firstIndex] - y[secondIndex];
        sum = sum.add(BigDecimal.valueOf(Math.sqrt(Math.pow(xSum, 2) + Math.pow(ySum, 2))));
      }
    }
    System.out.println(sum.divide(new BigDecimal(permutation.size()), 8, RoundingMode.DOWN).doubleValue());
  }

  public static void permutation(String q, String ans) {
    if (q.length() <= 1) {
      permutation.add(ans + q);
    } else {
      for (int i = 0; i < q.length(); i++) {
        permutation(q.substring(0, i) + q.substring(i + 1),
            ans + q.charAt(i));
      }
    }
  }
}


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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

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

    int n, x, val;

    cin >> n >> x;
    vector<int> d(n+1);

    d[0] = 0;
    for(int i = 0; i < n; i++) {
        cin >> val;
        d[i+1] = d[i]+val;
    }

    int count = 0;
    for(int i =0;i  <= n; i++) {
        if(d[i] <= x)
            count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::min;
fn main() {
    input! {
        a: u64,
        b: u64,
        c: u64,
        x: u64,
        y: u64,
    }

    let mut ans :u64 = 0;
    ans += min(a + b, 2 * c) * min(x, y);
    if x > y {
        ans = ans + (x - y) * min(a, 2 * c);
    } else if y > x {
        ans = ans + (y - x) * min(b, 2 * c);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
long long arr[3005];
long long memo[3005][3005];
long long dp(int i,int j, bool k){
    if (i==j) return k?arr[i]:-arr[i];
    if (memo[i][j]!=-1) return memo[i][j];
    if (k){
        return memo[i][j]=max(arr[i]+dp(i+1,j,!k),arr[j]+dp(i,j-1,!k));
    }
    else{
        return memo[i][j]=min(-arr[i]+dp(i+1,j,!k),-arr[j]+dp(i,j-1,!k));
    }
}
int main(){
    memset(memo,-1,sizeof(memo));
    scanf("%d",&n);
    for (int x=0;x<n;x++){
        scanf("%lld",&arr[x]);
    }
    printf("%lld\n",dp(0,n-1,true));
}


Measured memory_bytes: 70912
module Main (main) where

import Control.Applicative

main :: IO ()
main = do
  [x,y] <- (map read . words) <$> getLine 
  putStr $ show $ area x y
  putStr " "
  putStrLn $ show $ circum x y

area :: Integer -> Integer -> Integer
area x y = x * y

circum :: Integer -> Integer -> Integer
circum x y = 2 * x + 2 * y

Measured memory_bytes: 3556