akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)	
using namespace std;
string a,b; 
int main ()
{
	fast;
	cin>>a>>b;
	int len=min(a.size(),b.size());
	for (int i=0;i<=len-1;i++)
	   cout<<a[i]<<b[i];
	if (a.size()>b.size())
	   cout<<a[len]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005,md=1000000007;
int n,K,i,a[N],jc[N],rjc[N],inv[N],ans;
int C(int n,int m)
{
	return 1ll*jc[n]*rjc[m]%md*rjc[n-m]%md;
}
int main()
{
	scanf("%d%d",&n,&K);
	inv[1]=1;
	for(i=2;i<=n;++i)
		inv[i]=1ll*inv[md%i]*(md-md/i)%md;
	jc[0]=rjc[0]=1;
	for(i=1;i<=n;++i)
		jc[i]=1ll*jc[i-1]*i%md,rjc[i]=1ll*rjc[i-1]*inv[i]%md;
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	sort(a+1,a+1+n);
	for(i=K;i<=n;++i)
		ans=(ans+1ll*(a[i]+md)%md*C(i-1,K-1))%md;
	for(i=1;i+K-1<=n;++i)
		ans=(ans+1ll*(-a[i]+md)%md*C(n-i,K-1)%md)%md;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1664
# coding: utf-8
# Your code here!


n, m = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]

for i in range(n):
   A[i] = list(map(int, input().split()))

S = [0 for j in range(m)]
c = 0
for i in range(n):
   for j in range(m):
      print(A[i][j], end = "")
      print(" ", end = "")
   print(sum(A[i]))
   c += sum(A[i])

for j in range(m):
   sum = 0
   for i in range(n):
      sum += A[i][j]
   print(sum, end = "")
   print(" ", end = "")
print(c)


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

int main(){

  int n;
  cin >> n;
  while(n){
    int out = 0,hit = 0,point= 0;
    while(out != 3){
      string s;
      cin >> s;
      if(s == "OUT") out++;
      else if(s == "HIT"){
	hit++;
	if(hit == 4){
	  point++;
	  hit = 3;
	}
      }
      else if(s == "HOMERUN"){
	point += hit + 1;
	hit = 0;
      }
     
    }
    cout << point<<endl;
    n--;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
// inline long long abs(long long x) {
//   long long res = x > 0?x:-x;
//   return(res);
// }

using namespace std;

int main(){
  long long result = 0;
  long long min_a = 9223372036854775807;
  long long zeros = 0;
  long long minuses = 0;
  long long n;
  cin >> n;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    if (a < 0) {
      minuses++;
      result += -a;
    } else if (a==0){
      zeros++;
    } else {
      result += a;
    }
    if (abs(a) < min_a) {
      min_a = abs(a);
    }
  }
  if (zeros > 0) {
    cout << result << endl;
  } else if (minuses % 2 == 0) {
    cout << result << endl;
  } else {
    cout << result - 2*min_a << endl;
  }
  return(0);
}


Measured memory_bytes: 888
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    ll ans = TEN(18);
    for (ll i = 1; i <= 2 * TEN(6); i++) {
        if (n % i) continue;
        ll j = n / i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<double> V(N);
  for(int i=0;i<N;i++) cin >> V[i];
  sort(V.begin(),V.end());
  
  for(int i=1;i<N;i++){
    V[i] = (V[i]+V[i-1])/2;
  }
  cout << V[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  double n,m,d,x;
  scanf("%lf %lf %lf",&n,&m,&d);
  if(d==0)x=(n-d)/(n*n)*(m-1.0);
  else x=2*(n-d)/(n*n)*(m-1.0);
  printf("%lf",x);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

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

    string S;
    cin >> S;

    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            ++tmp;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    ans = max(ans, tmp);
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll solve(vector<ll> a, vector<ll> b, ll n) {
    vector<ll> dp(n + 1, -1);
    dp[0] = 0;
    dp[n] = n;
    auto set = [&](ll i, ll v) {
        if (i > n) return;
        if (dp[i] == -1) dp[i] = v;
        else
            cmax(dp[i], v);
    };

    rep(i, n+1) {
        if (i > 0) set(i, dp[i - 1] + 1);
        rep(j, 3) {
            ll ld = i + a[j];
            ll gd = dp[i] + b[j];
            set(ld, gd);
        }
    }
    ll ans = *max_element(dp.begin(), dp.end());
    return ans;
}
// 1908079
//453448648
//9043383240

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

    n = solve(a, b, n);
    n = solve(b, a, n);
    cout << n << endl;

}
// 27362
//5000
//613 821 717
//112 150 131

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


int main()
{
    int n,m;cin>>n>>m;
    vector<int> a(n), b(n), c(m), d(m);
    for(int i = 0; i<n;i++)cin>>a[i]>>b[i];
    for(int i = 0; i<m;i++)cin>>c[i]>>d[i];
    for(int i = 0; i<n;i++){
        int rec;
        int mi = 1000000000;
        for(int j = 0; j<m;j++){
            if(mi > abs(c[j] - a[i]) + abs(d[j] - b[i])){
                mi = abs(c[j] - a[i]) + abs(d[j] - b[i]);
                rec = j;
            }
        }
        cout << rec + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	ll L[87] = {0LL};
	L[0] = 2LL;
	L[1] = 1LL;
	for (int i = 2; i <= 86; ++i){
		L[i] = L[i-1] + L[i-2];
	} // end for

	int n; cin >> n;

	ll res = L[n];
	cout << res << endl;
	
	return 0;
}

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

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long ans = n - 1;
    for(long long i = 1; i * i <= n; i++){
        if(n % i) continue;
        ans = min(ans, i + n / i - 2);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val links = Array(n) { mutableListOf<Int>() }
    val edges = Array(m) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() - 1 }
        links[a].add(b)
        links[b].add(a)
        a to b
    }
    fun isBridge(e: Pair<Int, Int>): Boolean {
        val removedLinks = links.mapIndexed { src, dists ->
            if (src == e.first || src == e.second) {
                dists.filter { it != e.first && it != e.second }
            } else {
                dists
            }
        }
        if (removedLinks.any(List<Int>::isEmpty)) return true
        val visited = hashSetOf<Int>()
        fun visit(src: Int) {
            visited.add(src)
            removedLinks[src].filterNot { it in visited }.forEach(::visit)
        }
        visit(0)
        return visited.size != n
    }
    val ans = edges.filter(::isBridge).count()
    println(ans)
}


Measured memory_bytes: 38164
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X; cin >> X;

    int ans = 1;
    for (int b = 2; b < 32; b++) {
        int n = b*b;
        while(true) {
            if (n > X) break;
            ans = max(ans, n);
            n *= b;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n, m;
  cin>>n>>m;
  string s, t;
  cin>>s>>t;
  if (s[0] != t[0]) {
    cout<<-1<<endl;
    return 0;
  }

  long long a = gcd(n, m);
  long long l = n / a * m;

  long long x = l / n;
  long long y = l / m;

  long long a2 = gcd(x, y);
  long long l2 = x / a2 * y;

  for (int i=1; l2*i<l; i++) {
    if (s[l2*i/x] != t[l2*i/y]) {
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<l<<endl;
}

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

int main()
{
    int h, w;

    while ((cin >> h >> w), h != 0 || w != 0) {
        for (int y = 0; y < h; ++y) {
            for (int x = 0; x < w; ++x) {
                cout << "#";
            }

            cout << endl;
        }

        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <set>
using namespace std;
using ll = long long;

const long long BASE_NUM = 1000000007;

long long gcd(long long a, long long b){

    if (a== 0){
        return b;
    }else if (b == 0){
        return a;
    }

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

vector<int> prime_numbers(int n){
    if (n <= 1){
        return vector<int>(0);
    }
    vector<int> ans = {2};
    for(int i = 3;i <= n;i++){
        bool is_prime = true;
        for(int j = 0; ans[j] * ans[j] <= i;j++){
            if (i % ans[j] == 0){
                is_prime = false;
                break;
            }
        }
        if (is_prime){
            ans.push_back(i);
        }
    }
    return ans;
}

void decomposite(int N, map<int,int> & factors, vector<int> &primes,int p_index = 0){
    if (N == 1){
        return;
    }

    while (primes[p_index] * primes[p_index] <= N ) {
        if (N % primes[p_index] == 0) {
            factors[primes[p_index]] += 1;
            decomposite(N/primes[p_index],factors,primes,p_index);
            return;
        } else {
            p_index++;
        }
    }
    factors[N] += 1;
}

int main()
{
  // 整数の入力
  ll N;
  cin >> N;
  vector<ll> A(N);
  bool pairwise_co = true;
  ll all_gcd = 0;
  set<ll> used_primes;
  vector<int> primes = prime_numbers(2001);

  for (size_t i = 0; i < N; i++)
  {
    cin >> A[i];
    map<int,int> factors;
    decomposite(A[i],factors,primes);
    all_gcd = gcd(all_gcd,A[i]);

    for(auto &p:factors){
      if (used_primes.find(p.first) != used_primes.end()){
        pairwise_co = false;
      }
      used_primes.insert(p.first);
    }

  }

  if (pairwise_co){
    cout << "pairwise coprime" << endl;
  }else if(all_gcd == 1){
    cout << "setwise coprime" << endl;
  }else{
    cout << "not coprime" << endl;
  }
  return 0;
}


Measured memory_bytes: 14736
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<strstream>
#include<math.h>
using namespace std;
int main()
{
    char a[100500];
    scanf("%s",a);
    int l=strlen(a),j,i;
    for( i=0;i<26;i++)
    {
        for( j=0;j<l;j++)
           if(i+'a'==a[j]) break;
        if(j>=l)
        {
            printf("%c\n",i+'a');
            break;
        }
    }
    if(i>=26)
            printf("None\n");
}


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

int main() {
    int k, x;
    cin >> k >> x;
    if(k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	x := getNextInt64(scanner)
	var ans, prev, a int64
	for i := 0; i < n; i++ {
		a = getNextInt64(scanner)
		diff := maxint64(0, prev+a-x)
		ans += diff
		a -= diff

		prev = a
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}
func maxint64(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> a){
    int answer = 0;
    rep(i,0,N) {
        if ((i+1)%2==1 && a[i]%2==1) {
            answer++;
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
  }


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

const int MAX = 100;
int main() {
	int N, t[MAX + 1], v[MAX + 1];
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> t[i];
	for (int i = 0;i < N;i ++) cin >> v[i];
	t[N] = 1;
	v[N] = 0;
	
	for (int i = N - 1;i >= 0;i --) {
		v[i] = min(v[i], v[i + 1] + t[i]); // これで、制限速度のつもりが超過は避けられるね
	}
	
	int dist = 0; // 移動距離の8倍
	int speed = 0; // 現区間における速度
	int accel; // 現区間の加速時間の2倍
	int decel; // 現区間の減速時間の2倍
	int cons; // 現区間の直線移動時間の2倍
	for (int i = 0;i <= N - 1;i ++) {
		accel = max(0, min(t[i] * 2, min((v[i] - speed) * 2, t[i] + v[i + 1] - speed))); // 加速度
		decel = max(0, speed * 2 + accel - v[i + 1] * 2); // 減速度
		cons = t[i] * 2 - accel - decel; // 等速度
		dist += (speed * 4 + accel) * accel; // v-tグラフの面積は移動距離を顕しているよ
		dist += (speed * 2 + accel) * cons * 2;
		dist += (speed * 4 + accel * 2 - decel) * decel;
//		cout << t[i] << "," << v[i] << ":(" << speed << "," << accel / 2 << "," << cons / 2 << "," << decel / 2 << ")" << endl;
		speed += (accel - decel) / 2; // 次の速度
	}
	cout << dist / 8;
	if (dist % 8) {
		cout << '.' << 125 * (dist % 8);
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まずこういう問題では最後に制限速度0m/sの区間を用意しておくと分かりやすい 場合分けしたくないし
次に、速度条件について考えよう
最初速度10m/sで制限速度10m/sだったとしようか
その直後、区間1で制限速度1m/sとかやると急にその速度にできないね
その辺を改善するため、まずは逆から見て制限速度に関して、今の自分の区間の最大速度まで出しても大丈夫なようにしておこう

これが改善されたなら、順にその時の制限速度ギリギリまで出せるから出してしまえばいいよ！
ただし細かい端数関連でミスを起こさないようにね
場合分け面倒だなぁ
*/

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Harry on 4/2/20.
 */
//https://atcoder.jp/contests/dp/tasks/dp_h
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int mod = 1000000007;
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        char[][] grid = new char[H][W];
        for(int r=0; r<H; r++){
            String line = scanner.next();
            for(int c=0; c<W; c++){
                grid[r][c] = line.charAt(c);
            }
        }
        int[][] dp = new int[H][W];
        dp[0][0] = 1;
        for(int r=0; r<H; r++){
            for(int c=0; c<W; c++){
                char cur = grid[r][c];
                if(cur=='#'){
                    dp[r][c]=-1;
                    continue;
                }
                if(r>0 && c>0){
                    dp[r][c] = ((dp[r-1][c]==-1 ? 0 : dp[r-1][c])+(dp[r][c-1]==-1 ? 0 : dp[r][c-1]))%mod;
                }
                else if(r>0){
                    dp[r][c] = (dp[r-1][c]==-1 ? 0 : dp[r-1][c])%mod;
                }
                else if(c>0){
                    dp[r][c] = (dp[r][c-1]==-1 ? 0 : dp[r][c-1])%mod;
                }
            }
        }
        System.out.print(dp[H-1][W-1]);
    }
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n,m;
  cin>>a>>b;
  n = a / 500;
  m = a % 500;
  if(a-n*500 > b){
    cout<<"No"<<'\n';
  }
  else{
    cout<<"Yes"<<'\n';
  }
}



Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] strings = line.split(" ");

		int[] is = new int[3];
		for (int i = 0; i < strings.length; i++) {
			is[i] = Integer.parseInt(strings[i]);
		}

		for (int i = 0; i < strings.length; i++) {
			int x = is[i];

			while (i > 0 && is[i - 1] > x) {
				is[i] = is[i - 1];
				--i;
			}
			is[i] = x;
		}
		System.out.println(is[0] + " " + is[1] + " " + is[2]);
	}

}

Measured memory_bytes: 26136
#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() {
  string S, T;
  cin >> S >> T;
  T = T.substr(0, S.size());
  cout << (S == T ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3612
from collections import deque

N = int(input())
A = []
B = []

for i in range(N):

    a = int(input())

    A.append(a)

A.sort()

now = A.pop(0)
L = now
R = now
ans = 0
Lind = 0
Rind = -1

for i in range(N-1):

    if abs(L-A[Lind]) == max(abs(L-A[Lind]),abs(L-A[Rind]),abs(R-A[Lind]),abs(R-A[Rind])):
        ans += abs(L-A[Lind])
        L = A[Lind]
        Lind += 1

    elif abs(L-A[Rind]) == max(abs(L-A[Lind]),abs(L-A[Rind]),abs(R-A[Lind]),abs(R-A[Rind])): 
        ans += abs(L-A[Rind])
        L = A[Rind]
        Rind -= 1

    elif abs(R-A[Lind]) == max(abs(L-A[Lind]),abs(L-A[Rind]),abs(R-A[Lind]),abs(R-A[Rind])):
        ans += abs(R-A[Lind])
        R = A[Lind]
        Lind += 1

    elif abs(R-A[Rind]) == max(abs(L-A[Lind]),abs(L-A[Rind]),abs(R-A[Lind]),abs(R-A[Rind])):
        ans += abs(R-A[Rind])
        R = A[Rind]
        Rind -= 1

    else:
        print ("eeror")

    #print (A,L,R,ans)

print (ans)

Measured memory_bytes: 63064
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int h,n;
  cin>>h>>n;
  int a[n];
  int i;
  int s=0;
  for(i=0;i<n;i++)
  {
  	
  	cin>>a[i];
  	s=s+a[i];
  	
  }
  
  if(h>s){
  	cout<<"No"<<endl;
  }
  
  else{
  	
  	cout<<"Yes"<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 4016
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n, a[50][26];
    cin >> n;
    for(int i=0;i<n;i++){
        int len;
        string s;
        cin >> s;
        len = s.length();
        fill(a[i], a[i]+26, 0);
        for(int j=0;j<len;j++){
            a[i][s[j]-'a']++;
        }
    }
    string ans = "";
    for(int j=0;j<26;j++){
        int mn = 1e9;
        for(int i=0;i<n;i++){
            mn = min(mn, a[i][j]);
        }
        ans += string(mn, 'a' + j);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long n, m;
    cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1;
    }else if (n == 1 || m == 1){
        cout << n + m - 3;
    }else{
        cout << (n - 2) * (m - 2);
    }
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
struct edge{int to; ll cost;};
const ll INF = 1e18;
int N, Q, K;
vector<edge> G[100010];
ll d[100010];

int main(){
  cin >> N;
  for (int i = 1; i <= N - 1; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  cin >> Q >> K;
  fill(d, d + N + 1, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, K));
  d[K] = 0;
  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  while (Q--) {
    int x, y;
    cin >> x >> y;
    cout << d[x] + d[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 11120
import sys
import itertools
import collections


def search(H, W, S, start):
    wall_i = ord(b'#')
    used = [[-1 for h in range(W)] for w in range(H)]

    qu = collections.deque()
    qu.append(start)
    used[start[0]][start[1]] = 0

    while qu:
        h, w = qu.popleft()
        cost = used[h][w]
        for h0, w0 in ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1)):
            if not (0 <= h0 < H and 0 <= w0 < W):
                continue
            if used[h0][w0] != -1:
                continue
            if S[h0][w0] == wall_i:
                continue

            used[h0][w0] = cost + 1
            qu.append((h0, w0))

    return max(cost for costs in used for cost in costs)


def resolve(in_):
    H, W = map(int, next(in_).split())
    S = tuple(s.strip() for s in itertools.islice(in_, H))

    road_i = ord(b'.')

    roads = []
    for h in range(H):
        for w in range(W):
            if S[h][w] == road_i:
                roads.append((h, w))
    
    ans = max(search(H, W, S, start) for start in roads)
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9540
def main():
    n=int(input())
    task=[]
    for i in range(n):
        a,b=map(int,input().split())
        task.append([b,a])
    task.sort()
    t=0
    ans="Yes"
    for i in range(n):
        t+=task[i][1]
        if t>task[i][0]:
            ans="No"
            break
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 35612
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
vector<string> vec;
int h, w;
vector<vector<bool> > visited;
long long white;
long long black;
void dfs(int i, int j, char cur){
	visited[i][j]=true;
	if(cur == '.')white++;
	if(cur == '#')black++;
	for(int k = 0; k < 4; ++k){
		int r = i + dx[k];
		int c = j + dy[k];
		if(r >= 0 && c >= 0 && r < h && c < w){
			if(vec[r][c] == '.' && cur == '#' && !visited[r][c]){
			    dfs(r, c, '.');
			}
			if(vec[r][c] == '#' && cur == '.' && !visited[r][c]){
				dfs(r, c, '#');
			}
		}
	}
}
int main(){
	cin>>h>>w;
	vec.resize(h);
	for(int i = 0; i < h; ++i){
		cin>>vec[i];
	}
	vector<bool> e(w, false);
	visited.resize(h, e);
	long long res = 0;
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(vec[i][j]=='#' && !visited[i][j]){
				white=black=0;
				dfs(i, j, '#');
				res += white * black;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int abs(int n) {
  if (n < 0) {n = -n;}
  return n;
}

int main() {
  int N; 
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<P> v;
  
  for (int i = 0; i < N; i++) {
    v.push_back(P(abs(a[i]), a[i]));
  }
  sort(v.begin(), v.end());
  
  int flag = 0;
  ll ans = 0;
  for (int i = N-1; i > 0; i--) {
    if (v[i].second < 0) {flag++;}
    ans += v[i].first;
  }
  
  if (flag % 2 == 0) {ans += v[0].second;}
  else {ans -= v[0].second;}
  
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <iostream>
using namespace std;
int main(void){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
mt19937 rnd(random_device{}());

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
V<ll>fac,rfac; void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}

ll randInt(ll l,ll r){return uniform_int_distribution<ll>(l,r)(rnd);}
double randDouble(double l,double r){return uniform_real_distribution<double>(l,r)(rnd);}
void dout(double d){printf("%.12f\n",d);}

const double PI = acos(-1);
const double EPS = 1e-10;
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;

const int N = 200;
int n, D[N];
V<int> e[N];
void dfs(int a, int d){
  D[a] = d;
  for(int b:e[a]){
    if(!D[b]) dfs(b, d+1);
    else if((D[b]-d)%2==0){
      cout << -1 << endl;
      exit(0);
    }
  }
}
int bfs(int a){
  fill(D, D+n, 0);
  queue<int> q, q2;
  q.push(a);
  int d = 0;
  D[a] = 1;
  while(!q.empty()){
    d++;
    while(!q.empty()){
      int t = q.front(); q.pop();
      for(int b:e[t]) if(!D[b]){
        q2.push(b);
        D[b] = 1;
      }
    }
    swap(q, q2);
  }
  return d;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    string s;
    cin >> s;
    FOR(j, i+1, n) if(s[j]-'0'){
      e[i].pb(j);
      e[j].pb(i);
    }
  }
  dfs(0, 1);
  int ans = 0;
  FOR(i, 0, n) maxs(ans, bfs(i));
  cout << ans << endl;
}

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

typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

int main(){
	std::vector<int> a(3);
	rep(i,3)std::cin >> a[i];
	sort(all(a));
	std::cout << a[2]*10+a[1]+a[0] << std::endl;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n,t;
  cin >> n >> t;
  
  ll total = 0;
  int a = 0;
  int prevA = -t-1;
  for(int i=0;i<n;i++){
    cin >> a;
    total += t;
    
    if(a-prevA<=t){
      total -= t-(a-prevA);
    }
    prevA = a;
  }
  
  cout << total << endl;
  
  return 0;
}




Measured memory_bytes: 3600
n = gets.to_i
s = gets.chomp
ans = 0
l, r = 0, 0
while r < n
  subst = s[l..r]
  rest = s[r + 1..-1]
  if rest.include?(subst)
    ans = subst.size if subst.size > ans
    r += 1
  else
    l += 1
    r += 1
  end
end
p ans


Measured memory_bytes: 6140
#include "bits/stdc++.h"
using namespace std;

int z(int x)
{
  if(x>=0)
    return x;
  else
    return x*-1;
}

int main()
{
  int n,l,sum,sa,hi;
  sa=10000;
  sum=0;
  cin>>n>>l;
  vector<int> t(n);
  for(int i=0;i<n;i++)
  {
    t.at(i)=l+i;
    sum+=t.at(i);
  }
  for(int i=0;i<n;i++)
  {
    if(sa>z(t.at(i)))
    {
      sa=z(t.at(i));
      hi=t.at(i);
    }
  }
  cout<<sum-hi<<endl;
}

Measured memory_bytes: 3568
n = int(input())

li = list()

for i in range(n):

    a, b = [int(x) for x in input().split()]

    li.append([a,b])

count = 0

for i in li:

    if count < 3:

        if i[0] == i[1]:

            count += 1

        else:

            count = 0

    else:

        break

if count >= 3: print('Yes')

else: print('No')

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

int basecnt(int n, int k){
    int res=0;
    while(n){
        n/=k;
        res++;
    }
    return res;
}
    
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%d", basecnt(n, k));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 200002;
int ans, a[N];
pair < int, int > h[N], rh[N], p[N];
int mod1 = 1e9 + 7;
int mod2 = 1e9 + 9;
int b = 432;
map < string, pair < int, int > > f;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    int n = s.length();
    int l = n;
    for (int i = 1; i <= n; i++){
        a[s[i - 1] - 'a']++;
    }
    for (int i = 1; i <= n; i++){
        ans += l - a[s[i - 1] - 'a'];
        a[s[i - 1] - 'a']--;
        l--;
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 2580
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__

	string S,T;
	cin>>S>>T;

	bool ok=true;

	if(T.size()<=S.size())ok=false;
	else{
		REP(i,S.size()){
			if(S[i]!=T[i])ok=false;
		}
	}
	
	YesNo(ok)

	



	

		return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str;
	cin>>str;
	for(int i=0;i<str.length();i++){
		if(str[i]=='?')str[i]='D';
	}
	cout<<str<<endl;
	return 0;
} 

Measured memory_bytes: 3772
def solve():
    from math import atan2, degrees, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = degrees(atan2(b, a))
        sx += a
        sy += b
        txy.append((theta_0, a, b))
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N;
    cin >> N;
    
    ll min = 10000000000000;
    for(ll i = 1; i < N; i++){
        st Ast = to_string(i);
        st Bst = to_string(N - i);
        ll sum = 0;
        for(auto& j : Ast) sum += j - '0';
        for(auto& j : Bst) sum += j - '0';
        if(sum < min) min = sum;
    }
    cout << min << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
    L = 8
    for i in range(N):
        readline()
        G = [list(map(int, readline().strip())) for i in range(L)]
        x = int(readline())-1
        y = int(readline())-1
        que = deque([(x, y)])
        G[y][x] = 0
        while que:
            x, y = que.popleft()
            for dx, dy in dd:
                for k in range(1, 4):
                    nx = x + dx*k; ny = y + dy*k
                    if not 0 <= nx < L or not 0 <= ny < L:
                        continue
                    if G[ny][nx]:
                        que.append((nx, ny))
                        G[ny][nx] = 0
        write("Data %d:\n" % (i+1))
        for line in G:
            write("".join(map(str, line)))
            write("\n")
solve()


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	llong N, M, V, P;
	vector<llong> A;

	cin >> N >> M >> V >> P;
	A.resize(N + 1);
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
	}
	sort(A.begin() + 1, A.end(), greater<>());

	int ok = 0, ng = N + 1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (mid <= P) {
			ok = mid;
		}
		else if (A[mid] + M < A[P]) {
			ng = mid;
		}
		else {
			llong vote = 0;
			for (int i = 1; i <= N; ++i) {
				if (i >= mid || i < P) {
					vote += M;
				}
				else {
					vote += A[mid] + M - A[i];
				}
			}

			if (vote < M * V) {
				ng = mid;
			}
			else {
				ok = mid;
			}
		}
	}

	cout << ok << endl;

	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            //var n = cin.ReadInt;
            //var m = cin.ReadInt;
            //if(n==m) WriteLine("Yes");
            //else WriteLine("No");

            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var t = 0.0;
            if (a > b)
            {
                for (double i = 0; i < a; i++) t += Pow(10, i) * b;
            }
            else
                for (int i = 0; i < b; i++) t += Pow(10, i) * a;
            WriteLine(t);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;
int a[205];
int main()
{
    int n,l;
    cin>>n>>l;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        a[i]=l+i-1;
        sum+=a[i];
    }
    pair<int,int> dist=mp(abs(a[1]),(a[1]>=0 ? 1 : -1));
    for(int i=2;i<=n;i++)
    {
        dist.F=min(dist.F,abs(a[i]));
        if(dist.F==abs(a[i]))
            dist.S=(a[i]>=0 ? 1 : -1);
    }
    cout<<sum-dist.F*dist.S<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long S){
  string x = to_string(S);
  ll ans = 0;
  for (int bit = 0; bit < (1 << x.length()-1); bit++) {
    string a = "0";
    for (int i = 0; i < x.length(); i++) {
      a += x[i];
      if(bit & (1 << i)){
        ans += stol(a);
        a = "0";
      }  
    }
    ans += stol(a);
  }
  cout << ans << endl;
}

int main(){
    long long S;
	scanf("%lld",&S);
    solve(S);
}


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

int main(){
    string s;
    cin >> s;
    int zero=0,iti=0;
    rep(i,s.size()){
        if(s[i] == '1') iti++;
        else zero++;
    }
    cout << min(iti,zero)*2 << endl;
}

Measured memory_bytes: 512
N = int(input())
A = sorted(list(map(int, input().split())))

#篩
M = 10**6+ 10
c = [0] * M
for i in range(N):
    if c[A[i]-1] >= 1:
        c[A[i]-1] = c[A[i]-1] + 1
    else:
        for j in range(1, M//A[i] + 1):
            c[A[i]*j-1] += 1

#チェック
ans = 0
for i in range(N):
    if c[A[i]-1] <= 1:
        ans += 1

print(ans)


Measured memory_bytes: 32976