akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>	
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;


int main(){
	
	ll a,b,k;

	scanf("%lld%lld%lld",&a,&b,&k);
	ll j=a;
	for (int i = 0; i < k && i+a<=b; ++i)
	{
		cout<<a+i<<endl;
		j=a+i;
	}
	for (int i = max(b-k+1,j+1); i <= b; ++i)
	{
		cout<<i<<endl;
	}

	return 0;
}	

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    string S;
    cin >> S;

    int ans = 0;
    REP(i, S.length()) {
        if (S[i] == '-') ans--;
        else ans++;
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N, K;
  
  	cin >> N >> K;
  
  	if(N % K == 0)
    {
		cout << 0 << endl;
    }
  	else
    {
      	cout << 1 << endl;
    }
  
  	return 0;
}

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

typedef long long ll;

const int maxn=1e6+10; 

int prime[5000000];//保存素数
int vis[maxn];//初始化
int cnt;
 
void getprime(int n)
{
    cnt=0;
    memset(vis,0,sizeof(vis));
    for(int i=2;i<n;i++ )
    {
        if(vis[i]==0)
            prime[cnt++]=i;
        for(int j=0;j<cnt&&i*prime[j]<n;j++)
        {
            vis[i*prime[j]]=1;
			// vis[i*prime[j]]=prime[j]; 
            if(i%prime[j]==0)
                break;
        }
    }
}
 
ll a[maxn],p[70];

int main()
{
	getprime(maxn-1);
	p[1]=1;
	for( int i=2;i<=70;i++ ) p[i]=p[i-1]+i;
	ll n,ans=0;
	cin>>n;
	for( int i=0;i<cnt && prime[i]<=n ;i++ )
	{
		if( n%prime[i]==0 )
		{
			int num=0;
			while( n%prime[i]==0 ) n/=prime[i],num++;
			int idx=lower_bound(p+1,p+1+65,num)-p;
			if( p[idx]>num ) idx--;
			ans+=idx;
			if( n==1 ) break;
		}
	}
	if( n>1 ) ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 7852
f = lambda :[int(i) for i in input().split()]
from sys import stderr
debug = lambda x:stderr.write(repr(x)+'\n')

a,b,c = sorted(f())
ans = 0
while a < b:
    a += 2
    ans += 1
if b < a:
    b += 1
    c += 1
    ans += 1
while b < c:
    a += 1
    b += 1
    ans += 1
print(ans)

Measured memory_bytes: 3316
/*************************
author : coldbeer
2019-05-20 10:38:08 PM IST
*************************/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long double n,k; cin >> n >> k;

	long double ans = 0;
	for(int i = 1;i < n + 1;i++){
		int p = i;
		long double tmp = 1;
		while(p < k) p = 2 * p,tmp /= 2;
		ans += tmp;
	}
	ans = ans / n;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A, B;
    string s;

    cin >> A >> B;
    cin >> s;

    for (int i = 0; i < A; i++)
        if (!( '0' <= s[i] && s[i] <= '9'))
        {
            cout << "No" << endl;
            return 0;
        }
    if (s[A] != '-')
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = A + 1; i <= A + B; i++)
        if (!( '0' <= s[i] && s[i] <= '9' ))
        {
            cout << "No" << endl;
            return 0;
        }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=400010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
char s[N],t[N];
signed main()
{
    scanf("%s%s",s,t);
    int res=0;
    int n=strlen(s);
    for(ri int i=0;i<n;i++) res+=(s[i]!=t[i]);
    printf("%lld\n",res);
    return 0;
}

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

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

  if (A == B) {
    cout << C << endl;
  }
  else if (B == C) {
    cout << A << endl;
  }
  else {
    cout << B << endl;
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        System.out.println(s.substring(0, 1) + String.valueOf(s.length() - 2) + s.substring(s.length() - 1, s.length()));
    }
}

Measured memory_bytes: 23120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iA = int.Parse(sS.Substring(0, 2));
            int iB = int.Parse(sS.Substring(2, 2));

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "NA";
            if ((iA >= 1 && iA <= 12) && (iB >= 1 && iB <= 12)) { sOut = "AMBIGUOUS"; }
            else if (iA >= 1 && iA <= 12) { sOut = "MMYY"; }
            else if (iB >= 1 && iB <= 12) { sOut = "YYMM"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13524
#include <iostream>
#include <map>
#include <algorithm>
int main()
{
	typedef std::map<std::string, int>	simap;
	typedef std::pair<std::string, int> 	sipair;
	simap 		words; 
	std::string 	input;

	while (std::cin >> input) 
		++words[input]; 
	
	auto result  = std::minmax_element(words.begin(), words.end(), [](const sipair & a, const sipair & b) { return a.first.length() < b.first.length(); });
	auto result2 = std::minmax_element(words.begin(), words.end(), [](const sipair & a, const sipair & b) { return a.second < b.second; });

	std::cout << result2.second->first << ' ' << result.second->first << std::endl;
}

Measured memory_bytes: 1196
package main

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

func main() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	l := make([]int, n)
	s := make([]int, n)
	ans := 0
	for i := 0; i < n; i++ {
		if a[i]+i < n {
			l[a[i]+i]++
		}
		if i-a[i] > 0 {
			s[i-a[i]]++
		}
	}
	for i := 0; i < n; i++ {
		ans += l[i] * s[i]
	}
	fmt.Println(ans)
}

func myAbs(a int, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readChar() rune {
	stdinScanner.Scan()
	temp := stdinScanner.Text()
	return rune(temp[0])
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 9064
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		
		int result = c - (a-b);
		result = result < 0 ? 0 : result;
		System.out.println(result);
	}
}

Measured memory_bytes: 23632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[500050];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
}
template<typename T>
struct BIT{ //1-indexed
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
	int n;
	scanf("%d", &n);
	fac(n);
	bool used[500050]={};
	int p[500050];
	int cnt0=0;
	ll s1=0, s2=0;
	for(int i=1; i<=n; i++){
		scanf("%d", &p[i]);
		if(p[i]) used[p[i]]=1;
		else cnt0++;
		if(p[i]==0) (s1+=f[n-i])%=MOD;
	}
	for(int i=1; i<=n; i++){
		if(!used[i]) s2+=i-1;
	}
	s2%=MOD;
	ll ans=f[cnt0];
	if(cnt0){
		(ans+=s1*s2%MOD*f[cnt0-1])%=MOD;
	}
	for(int i=1; i<=n; i++){
		if(p[i]) (ans+=f[cnt0]*f[n-i]%MOD*(p[i]-1))%=MOD;
	}
	int c1[500050];
	c1[0]=0;
	for(int i=1; i<=n; i++){
		c1[i]=c1[i-1];
		if(!used[i]) c1[i]++;
	}
	int cnt1=0;
	for(int i=1; i<=n; i++){
		if(p[i] && cnt0){
			ll s=f[n-i]*f[cnt0-1]%MOD*c1[p[i]-1]%MOD*cnt1%MOD;
			(ans+=MOD-s)%=MOD;
		}
		if(p[i]==0) cnt1++;
	}
	BIT<int> bit(n);
	ll s3=0;
	for(int i=1; i<=n; i++){
		if(p[i]){
			ll s=f[n-i]*f[cnt0]%MOD*bit.sum(p[i]-1)%MOD;
			(ans+=MOD-s)%=MOD;
			bit.add(p[i], 1);
			(s3+=c1[n]-c1[p[i]])%=MOD;
		}else{
			if(cnt0){
				ll s=f[n-i]*f[cnt0-1]%MOD*s3%MOD;
				(ans+=MOD-s)%=MOD;
			}
		}
	}
	if(cnt0>=2){
		ll d=(ll)cnt0*(cnt0-1)/2%MOD;
		int cnt2=0;
		for(int i=1; i<=n; i++){
			if(p[i]==0){
				ll s=f[n-i]*f[cnt0-2]%MOD*cnt2%MOD*d%MOD;
				(ans+=MOD-s)%=MOD;
				cnt2++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10496
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n::Int=parseInt(readline())
    a::Vector{Int}=parseMap(split(readline()))
    cnt::Vector{Int}=[0 for i in 1:10^6]
    for i in a
        cnt[i]+=1
    end
    if cnt[1]==1
        println(1)
    elseif cnt[1]>2
        println(0)
    else
        ans::Int=0
        for i in a
            flag::Bool=true
            for j in 2:trunc(Int,sqrt(i))+1
                if i%j==0 && i>j && (cnt[i÷j]>0 || cnt[j]>0)
                    flag=false
                    break
                end
            end
            if cnt[i]>1
                flag=false
            end
            if flag
                ans+=1
            end
        end
        println(ans)
    end
end
main()

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

int main(){
    vector <int> A(3);
    rep(i,3) cin >> A[i];
    sort(A.begin(),A.end());
    int K; cin >> K;
    
    int sum=0;
    sum+=A[0]+A[1];
    int large=A[2];
    rep(i,K){
        large*=2;
    }
    sum+=large;
    cout << sum ;
}

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

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

template< typename T >
T mod_pow(T x, T n) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= MOD;
        (x *= x) %= MOD;
        n >>= 1;
    }
    return ret;
}

int main(void) {
    int64_t N;
    cin >> N;
    vector<int64_t> C(N);
    for(int i=0; i<N; i++) {
        cin >> C[i];
    }

    sort(C.begin(), C.end());
    int64_t ans = mod_pow(2L, 2*N-2);
    int64_t tmp = 0;
    for(int i=0; i<N; i++) {
        tmp = (tmp + (N+1-i) * C[i]) % MOD;
    }

    cout << (tmp * ans) % MOD << endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = {}
total = 0
for i in a:
  total += i
  d[i] = d.get(i, 0) + 1

#クエリによって、それぞれの数値の個数を変更し、
#対象となる個数×差分で合計を修正し出力する

for i in range(q):
  b, c = map(int, input().split())
  b_cnt = d.get(b, 0)
  c_cnt = d.get(c, 0)
  total = total + b_cnt * (c - b)
  print(total)
  d[c] = d.get(c, 0) + d.get(b, 0)
  d[b] = 0

Measured memory_bytes: 94344
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    ng = 0
    for i in range(N):
        si = S[i]
        if si == "B":
            continue
        for j in range(i+1, N):
            sj = S[j]
            if (si == "R" and sj == "G") or (si == "G" and sj == "R"):
                k1 = 2*i-j
                if k1 >= 0:
                    if S[k1] == "B":
                        ng += 1
                if i%2 == j%2:
                    k2 = (i+j) // 2
                    if S[k2] == "B":
                        ng += 1
                k3 = 2*j-i
                if k3 < N:
                    if S[k3] == "B":
                        ng += 1
    print(S.count("R") * S.count("G") * S.count("B") - ng)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69752
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    string ss;
    ss = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    int ans = 0;
    rep(i,s.size()) if(s[i]!=ss[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a,b,c,d;
  vector<pair<int, int> > v_s;
  vector<pair<int, int> > v_p;
  REP(i,n){
      cin >> a >> b;
      v_s.push_back(make_pair(a,b));
      
  }
  REP(i,m){
      cin >> c >> d;
      v_p.push_back(make_pair(c,d));
  }
  for (auto s: v_s){
      int min_d = INTINF;
      int argmin;
      REP(i,v_p.size()){
          int d = abs(s.first - v_p[i].first) + abs(s.second - v_p[i].second);
          if (d < min_d){
              argmin = i+1;
              min_d = d;
          }
      }
      cout << argmin << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int r;
	cin >> r;
	cout << r * r;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=3009;
int x,t;
pair<int,int>p[N];
int dp[3009][6009];
int f(int i,int time)
{
    if (time>=t||i==x+1)
        return 0;
    if (dp[i][time]!=-1)
        return dp[i][time];
    return dp[i][time]=max(f(i+1,time),f(i+1,time+p[i].first)+p[i].second);
}
int main()
{
    FASTINOUT;
    cin>>x>>t;
    for (int i=1; i<=x; i++)
        cin>>p[i].first>>p[i].second;
    sort(p+1,p+x+1);
    memset(dp,-1,sizeof dp);
    cout<<f(1,0);
    return 0;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

typedef long long ll;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll n, k;

int main() {
    // 前処理
    COMinit();
    cin >> n >> k;
    for(ll i = 1; i <= k; i++)
    {
        printf("%lld\n", COM(n-k+1,i) * COM(k-1,i-1) % MOD); 
    }
}


Measured memory_bytes: 12160
n,x,m=map(int, input().split())
alist=[]
blist=[0]*m
num=x%m
while blist[num]==0:
  alist.append(num)
  blist[num]=1
  num=(num**2)%m
num1=alist.index(num)
num2=len(alist)
if x==1:
  print(n)
elif n<=num1:
  print(sum(alist[0:n]))
else:
  cycle=(n-num1)//(num2-num1)
  print(sum(alist[0:num1])+cycle*sum(alist[num1:num2+1])+sum(alist[num1:n-cycle*(num2-num1)]))

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

int main(){
  int N,ans=0;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  for(int i=0;i<N;i++){
   	cin >> a.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<N;i++){
    c.at(i) = a.at(i) - b.at(i);
    if(c.at(i)>0)
      ans += c.at(i);
  }
  cout << ans << endl;
}

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

int main() {
  
  float a, b;
  int ans, r;
  
  
  cin >> a >> b;
  ans = (a + b) * 5;
  
  r = (ans % 10) / 5;
  ans = ans / 10 + r;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m; std::cin >> n >> m;
    std::vector<std::vector<int>> edg(n), rev(n);
    for (int i = 0; i < m; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        rev[b].push_back(a);
    }
    bool vis[1003] = {};
    auto find = [&](int start) {
        std::fill(vis, vis + n, false);
        std::deque<std::pair<int, int>> que;
        que.emplace_back(start, 0);
        vis[start] = true;
        int min_cycle = 1e9, goal = -1;
        while (!que.empty()) {
            int pos, d;
            std::tie(pos, d) = que.front();
            que.pop_front();

            for (int v : edg[pos]) {
                if (v == start && d < min_cycle) {
                    min_cycle = d;
                    goal = pos;
                }
                if (vis[v]) continue;
                vis[v] = true;
                que.emplace_back(v, d + 1);
            }
        }
        return std::make_pair(min_cycle, goal);
    };
    int min_cycle = 1e9, start = -1, goal = -1;
    for (int i = 0; i < n; i++) {
        int min, v;
        std::tie(min, v) = find(i);
        if (min < min_cycle) {
            min_cycle = min;
            start = i;
            goal = v;
        }
    }
    if (start == -1) {
        std::cout << -1 << std::endl;
        return 0;
    }
    std::vector<int> dist(n, 1e9);
    dist[start] = 0;
    std::deque<int> que;
    que.push_back(start);
    while (!que.empty()) {
        int pos = que.front();
        que.pop_front();

        for (int v : edg[pos]) {
            if (dist[v] <= dist[pos] + 1) continue;
            dist[v] = dist[pos] + 1;
            que.push_back(v);
        }
    }
    std::vector<int> ans = { goal };
    int pos = goal;
    while (pos != start) {
        for (int v : rev[pos]) {
            if (dist[v] == dist[pos] - 1) {
                pos = v;
                ans.push_back(v);
            }
        }
    }
    std::cout << ans.size() << std::endl;
    for (int i : ans) std::cout << i + 1 << std::endl;
    return 0;
}

Measured memory_bytes: 384
import math
N=int(input())
mi=float("inf")
nu=0
for i in range(int(math.sqrt(N))):
    a=i+1
    b=N/a
    if (b.is_integer())==True:
        nu=max(len(str(int(a))),len(str(int(b))))
        mi=min(mi,nu)
print(mi)


Measured memory_bytes: 39024
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	if (a - 2 * b <= 0) {
		cout << 0 << endl;
	}
	else {
		cout << a - 2 * b << endl;
	}
}

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


int main() {
    ios::sync_with_stdio(false);

    int a, b, k;
    cin >> a >> b >> k;

    int t = 1;
    for (int i = 100; i >= 0; --i) {
        if ((a % i == 0) && (b % i == 0)) {
            if (t == k) {
                cout << i << endl;
                return 0;   
            }
            t++;
        }
    }

    return 0;
}


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

namespace my {
/*汎用*/
template <typename T>
void input_vec(vector<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_vec" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_set" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }

/*整数*/
ll gcd(ll a, ll b) {  // O( log(max(a,b)) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(max(a,b)) )
ll modinv(ll n, ll mod) {                               // O( log(max(n,mod)) )
  if (mod < 0 || my::gcd(n, mod) != 1) {
    cout << "error in modinv" << endl;
    exit(1);
  }
  n %= mod;
  if (n < 0) n += mod;
  ll a = mod, b = n, x = 1, y = 0;
  while (b != 0) {
    ll q = a / b, r = a % b;
    a = b;
    b = r;
    y -= q * x;
    swap(x, y);
  }
  y %= mod;
  if (y < 0) y += mod;
  return y;
}

bool isPrime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
   ////////////////////////////////////////////////

const ll M = 1e9 + 7;

/*
int hoge(int a, int b) {
  ll ret = 1;
  for (int i = b; i <= a; i++) {
    ret *= i;
    ret %= M;
  }
  return ret;
}
*/

ll kaijo(int a) {
  ll ret = 1;
  for (int i = 1; i <= a; i++) {
    ret *= i;
    ret %= M;
  }
  return ret;
}

int main() {
  int s;
  cin >> s;
  ll ans = 0;
  for (int kousu = 1; kousu <= s / 3; kousu++) {
    int bunpai = s - 3 * kousu;
    // ans += kaijo(bunpai) / hoge(bunpai + kousu - 1, kousu - 1);
    // ans += kaijo(bunpai) * (kaijo(kousu - 1) / kaijo(bunpai + kousu - 1));
    ans += kaijo(bunpai + kousu - 1) *
           my::modinv(kaijo(bunpai) * kaijo(kousu - 1), M);
    ans %= M;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
long long x;
long long f(long long n) {
  if (n == -1) return 0;
  return n/x + 1;
}

int main() {
  long long a, b;
  cin >> a >> b >> x;
  cout << f(b) - f(a-1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%10==7||(n%100)/10==7||n/100==7)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3608
x = int(input())
if x >= 400 and x<600:
    print("8")
elif x >= 600 and x<800:
    print("7")
elif x >= 800 and x<1000:
    print("6")
elif x >= 1000 and x<1200:
    print("5")
elif x >= 1200 and x<1400:
    print("4")
elif x >= 1400 and x<1600:
    print("3")
elif x >= 1600 and x<1800:
    print("2")
else:
    print("1")

Measured memory_bytes: 9180
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
cut = max([a for a, b in AB])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
    AB[i + 1][1] = AB[i + 1][1]
ans = float('inf')
throw = 0
for i in range(N, 0, -1):
    a, b = AB[i]
    throw += max(cut, b)
    count = N + 1 - i + max(0, 1 + (H - throw - 1) // cut)
    ans = min(ans, count)
    if cut >= b:
        break
print(ans)


Measured memory_bytes: 23504
def resolve():
    s = input()
    if s == s[::-1]:
        s_1 = s[:len(s)//2]
        s_2 = s[(len(s)+1)//2:]
        if (s_1 == s_1[::-1]) and (s_2 == s_2[::-1]):
            print('Yes')
        else:
            print('No')
    else:
        print('No')
resolve()

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

int main(){
    char c;
    cin >> c;
    if(isupper(c)) cout << 'A' << endl;
    else cout << 'a' << endl;
}

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

int calc(vector<int> a){
  a.push_back(-1);  

  while(1){
    int s=0,t=0;
    for(int i=1;i<(int)a.size();i++)
      if(a[i]!=a[i-1]){
	if(i-s>=4){t=i;break;}
	s=i;
      }
    if(t-s<4)break;
    a.erase(a.begin()+s,a.begin()+t);
  }
  return a.size()-1;
}

int main(){
  int n;
  vector <int> a;
  while(cin>>n,n){
    a.resize(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int ans=a.size();

    for(int i=0;i<(int)a.size();i++)
      for(int j=1;j<=3;j++)
	if(a[i]!=j){
	  int tmp=a[i];
	  a[i]=j;
	  ans=min(ans,calc(a));
	  a[i]=tmp;
	}
    cout << ans<<endl;
  }

  return 0;
}

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

    int main()
    {
        long long int i,n,a,q=0;
       cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>a;
            if(a%2==0)
            {
               while(a%2==0)
               {
                   q++;
                   a=a/2;
               }
            }
        }
        printf("%lld\n",q);
    }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int v[50];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) {
		cin >> v[i];
	}
	sort(v, v + n);
	
	double ans = 0;
	rep(i, n) {
		int p = min(n - i, n - 1);
		ans += v[i] / (double)(1LL << p);
	}
	printf("%.14f\n", ans);
	return 0;
}

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

using namespace std;

long long ans = 0;
string s;
int num[10];
int p[10];

void dfs(int d, int g) {
    if (d == g) {
        long long t = 0;
        for (int i = 0; i <= g; ++i) {
            t = t * 10 + num[i];
            if (p[i] == 1) {
                ans += t;
                t = 0;
            }
        }
        return;
    }
    dfs(d + 1, g);
    p[d] = 1;
    dfs(d + 1, g);
    p[d] = 0;
}

int main() {
    cin >> s;
    int l = s.size();
    for (int i = 0; i < l; ++i) {
        num[i] = s[i] - '0';
    }
    p[l - 1] = 1;
    dfs(0, l - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.algorithm, std.range;

void main()
{
    while(true)
    {
        auto a = readln.split.map!(to!int), b = readln.split.map!(to!int);
        if(a.length != 4) break;
        auto hit = iota(4).map!(i => a[i] == b[i] ? 1 : 0).reduce!"a + b",
             blow = a.map!(n => count(b, n)).reduce!"a + b" - hit;
        writeln(hit, " ", blow);
    }
}

Measured memory_bytes: 1060
//2718 佐々木 稜平 問2
import java.util.Scanner;
public class Main{
   
    public void solve(){
        Scanner sc = new Scanner(System.in);
        for(int a =0;a<4;a++){
            int t = sc.nextInt();
            int n = sc.nextInt();
        switch (t){
           case 1:
             System.out.println(n*6000);
             break;
           case 2:
             System.out.println(n*4000);
             break;
           case 3:
             System.out.println(n*3000);
             break;
           case 4:
             System.out.println(n*2000);
             break;
              }   
        }
    }
    public static void main(String[] args){
       Main obj = new Main();
       obj.solve();
    }
}

Measured memory_bytes: 17360
#include <stdio.h>

#define true 1
#define false 0

int n;
int A[21];

int canMakeM(int, int);

int main() {

  int i, input, m;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &input);
    
    if (canMakeM(0, input)) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int canMakeM(int i, int m) {
  if (m == 0) {
    return true;
  }
  if (i >= n) {
    return false;
  }
  return canMakeM(i + 1, m) || canMakeM(i + 1, m - A[i]);
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a1[100],a2[100];
    int n,i,c=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a1[i];
    }
    for(i=0; i<n; i++)
    {
        a2[i]=a1[i];
    }
    sort(a1, a1+n);
    for(i=0; i<n; i++)
    {
        if(a1[i]!=a2[i])
        {
            c=c+1;
        }
    }
    if(c==0 || c==2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int n = 1e5+5;
int N, K;

int main(){
	cin >> N >> K;
	long double p = 0;
	for(int i = 1; i <= N; ++i){
		int x = ceil(log2((long double)(1.0)*K/i));
		x = max(x, 0);
		//cerr << "log2(K/"<<i<<"): " << x << endl;
		long double p1 = 1;
		p += p1/N * pow((long double)(0.5), x);
	}
	cout <<setprecision(30) <<  p << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M;
    cin >> N >> M;
    
    if (abs(N-M) > 1){
        cout << 0 << endl;
        return 0;
    }

    long long count = 1;
    if (N == M){
        for (int i = 1; i <= N; i++) {
            count *= i;
            count %= 1000000007;
        }
        count *= count * 2;
        count %= 1000000007;
    }
    else {
        if (N > M){
           for (int i = 1; i <= M; i++) {
               count *= i;
               count %= 1000000007;
            } 
            count *= count;
            count %= 1000000007;
            count *= N;
            count %= 1000000007;
        }
        else {
            for (int i = 1; i <= N; i++) {
                count *= i;
                count %= 1000000007;
            } 
            count *= count;
            count %= 1000000007;
            count *= M;
            count %= 1000000007;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3644
$m = gets.to_i
$n = gets.to_i
$s = (1..$n).map{gets.split.map(&:to_i)}

def solve(a)
  if a.size == $m
    return a
  end
  $s.select{|e|a.include?(e[1])&& !a.include?(e[0])}.map{|e|
    r = solve(a + [e[0]])
    if r
      return r
    end
  }
end

p solve([2])

Measured memory_bytes: 6120
<?php
fscanf(STDIN, '%d %d', $d, $n);

switch ($d) {
    case 0:
        if ($n === 100) {
            echo 101 . PHP_EOL;
        } else {
            echo $n . PHP_EOL;
        }
        break;
    case 1:
        if ($n === 100) {
            echo 10100 . PHP_EOL;
        } else {
            echo $n * 100 . PHP_EOL;
        }
        break;
    case 2:
        if ($n === 100) {
            echo 1010000 . PHP_EOL;
        } else {
            echo $n * 10000 . PHP_EOL;
        }
        break;
}

Measured memory_bytes: 4728
#include <stdio.h>

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

typedef struct{
    int y;
    int x;
} pos_t;

char a[512];
short out[4*512*512];

int main(void){
    int h=gl(), w=gl();
    char haveCoin = 0;
    int pos = 0;
    short old_y, old_x;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            int t = getchar_unlocked() - 48;
            getchar_unlocked();
            a[j] = t;
        }
        if(i%2==1){
            for(int j=1; j<=w; j++){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }else{
            for(int j=w; j>0; j--){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }
    }
    printf("%d\n", pos);
    for(int i=0; i<pos; i++){
        printf("%d %d %d %d\n", out[4*i+0], out[4*i+1], out[4*i+2], out[4*i+3]);
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		double x1,y1,x2,y2;
		Scanner scan = new Scanner(System.in);
		x1=scan.nextDouble();
		y1=scan.nextDouble();
		x2=scan.nextDouble();
		y2=scan.nextDouble();
		System.out.println(String.format("%.8f", Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
	}
}


Measured memory_bytes: 28212
#include<iostream>
#include<string>
using namespace std;
string s;
char c='C';
int main()
{
	cin>>s;
	for(int i=0; i<s.length(); i++)
	{
		if(s[i]==c)
		{
			if(c=='C')
			{
				c='F';
			}
			else
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

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

int main(){
  int a, b, c;

  cin >> a >> b >> c;

  bool can = 0;

  for(int i = 1; i <= b; i++){
    int r = i*a % b;
    if(r == c) {
      can = 1;
      break;
    }
  }

  if(can) cout << "YES" << endl;
  else    cout << "NO"  << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector<ll> p[1003];
ll prox[1008];
ll vis[1003];
vector<pair<ll,ll> >v;
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		ll N;
		cin>>N;
		for(ll i=1;i<=N;i++){
        for(ll j=0;j<N-1;j++){
          ll a;
          cin>>a;
          p[i].push_back(a);

        }
		}
		while(1){
			bool gg=0;
			for(ll i=1;i<=N;i++){
				if(prox[i]==N-1 || prox[p[i][prox[i]]]==N-1)continue;
				ll k=p[i][prox[i]];
				if(p[k][prox[k]]==i){
          v.push_back({k,i});
					prox[k]++;
					prox[i]++;
					gg=1;
				}
			}
			if(gg==0){
          break;
			}
		}
		if(v.size()!=N*(N-1)/2){
      cout<<-1;
      return 0;
		}
		ll sol=0;
		for(ll i=0;i<v.size();i++){
      ll a=v[i].first,b=v[i].second;
      vis[a]=max(vis[a],vis[b])+1;
      vis[b]=vis[a];
      sol=max(sol,vis[a]);
		}
		cout<<sol;
		return 0;
}


Measured memory_bytes: 18668
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

X, Y, Z = map(int, input().split())

X, Y = Y, X
X, Z = Z, X

print(X, Y, Z)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d,x,y,z;
    cin>>n>>y;
    for(i=0;i<=n;i++)
    {
        for(j=0;i+j<=n;j++)
        {
            k=(n-(i+j));
            l=10000*i+5000*j+1000*k;
            if(l==y)
            {
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
from math import ceil
    

time_list = []
for i in range(5):
    time_list.append(int(input()))
    

min_time = float('inf')


for order in list(permutations([0,1,2,3,4])):
    total = 0
    for i in range(5):
        total += time_list[order[i]]
        if i!=4:
            total = ceil(total / 10) * 10
    min_time = min(min_time, total)
   
  
print(min_time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
struct UnionFind{
  vector<int> data;
  int __size;
  UnionFind(int sz) {
  data.assign(sz, -1);
  __size = sz;
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);//親は負でサイズを保存
    __size--;
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  bool same(int x, int y){
    return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
 
  int union_count() {
    return (__size);
  }
};
 
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
 
int main(){
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
 
  UnionFind uf(h * w);
 
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '.') continue;
 
      for (int k = 0; k < 4; k++) {
        int x = dx[k] + i, y = dy[k] + j;
        if (x < 0 || y < 0 || x >= h || y >= w) continue;
        if (g[x][y] == '.') continue;
        uf.unite(i * w + j, x * w + y);
      }
 
    }
  }
 
  bool ok = true;
 
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '.') continue;
      ok &= (uf.size(i * w + j) != 1);
    }
  }
 
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
 
  return 0;
} 

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

ll power(ll x,ll y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%mod)*(temp%mod))%mod; 
    else
        return ((((x%mod)*(temp%mod))%mod)*(temp%mod))%mod; 
}

int main(){
    ll n;
    cin>>n;
    ll ans;
    if(n==1){
        cout<<0;
    }else{
        ans=power(10,n) - (2*power(9,n));
        ans+=power(8,n);
        ans=ans%mod;
        if(ans<0){
            ans=ans+mod;
        }
        cout<<ans;
    }

}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;

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

constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,C_h,C_w,D_h,D_w;

  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  vector<string> S(H);
  rep(i,H)cin>>S[i];

  vector dist(H,vector(W,INF));
  vector seen(H,vector(W,false));
  dist[C_h][C_w] = 0;
  seen[C_h][C_w] = true;
  deque<pair<int,int>> deq;
  deq.emplace_front(C_h,C_w);
  while(!deq.empty()){
    auto [y,x] = deq.front();
    deq.pop_front();
    seen[y][x] = false;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]){
          dist[ny][nx] = dist[y][x];
          if(!seen[ny][nx]){
            deq.emplace_front(ny,nx);
            seen[ny][nx] = true;
          }
        }
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny>=0&&nx>=0&&ny<H&&nx<W&&S[ny][nx]=='.'){
        if(dist[ny][nx]>dist[y][x]+1){
          dist[ny][nx] = dist[y][x]+1;
          if(!seen[ny][nx]){
            deq.emplace_back(ny,nx);
            seen[ny][nx] = true;
          }
        }
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}


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

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

int main(void) {
  int R0, W0, C, R;
  while (cin >> R0 >> W0 >> C >> R, R0 && W0 && C && R) {
    int x = 0;
    while (x * R + R0 - W0 * C < 0) x++;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 3000
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	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{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[100005][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    dp[n][3] = 1;
    dp[n][0] = dp[n][1] = dp[n][2] = 0;
    for(int i = n-1; i >= 0; i--){
        for(int j = 3; j >= 0; j--){
            dp[i][j] = dp[i+1][j] * (s[i] == '?' ? 3 : 1);
            if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])){
                dp[i][j] += dp[i+1][j+1];
            }
        }
    }
    cout << dp[0][0].x << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

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

    vector<string> S(H);

    vector<int> dx{1, 0,-1, 0, 1,-1,-1, 1};
    vector<int> dy{0, 1, 0,-1, 1, 1,-1,-1};

    REP(i,H){
        cin >> S[i];
    }

    //.を0に
    REP(i,H){
        REP(j,W){
            if(S[i][j] == '.'){
                S[i][j] = '0';
            }
        }
    }

    REP(i,H){
        REP(j,W){
            if(S[i][j] == '#'){
                continue;
            }

            int num = 0;
            REP(k,8) {
                const int ni = i + dy[k];
                const int nj = j + dx[k];

                if((ni < 0) || (H <= ni) || (nj < 0) || (W <= nj)){
                    continue;
                }

                if(S[ni][nj] == '#'){
                    num++;
                }
            }

            S[i][j] = '0' + num;
        }
    }

    REP(i,H) {
        cout << S[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3612
#include "stdio.h"

int main()
{
	//まずは文字列を立てて、初期化してから標準入力
	char pass1[55], pass2[55];
	for (int i = 0; i < 55; i++) {
		pass1[i] = ' ';
		pass2[i] = ' ';
	}
	scanf("%s", &pass1);
	scanf("%s", &pass2);

	//ルールに従って一文字ずつ順番に表示。
	//見ている要素が空白の場合は表示しない。
	//文字列の最後の\0も回避する。
	for (int i = 0; i < 55; i++) {
		if ( (pass1[i]!=' ')&&(pass1[i] != '\0') ) {
			printf("%c", pass1[i]);
		}
		if ( (pass2[i] != ' ') && (pass2[i] != '\0')) {
			printf("%c", pass2[i]);
		}
	}

    return 0;
}

Measured memory_bytes: 128
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) 
{
	int ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() 
{
	fast_io();
	int n; cin >> n;
	For(i,1,10)
	{
		For(j,1,10)
		{
			if (i*j == n)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 256