akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }



void func(long long N, long long D, std::vector<long long> X, std::vector<long long> Y){

    lli ans = 0;
    REP(i,0,N){
        lli dist = X[i]*X[i] + Y[i]*Y[i];
        if(dist <= D*D)ans++;
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
    }
    func(N, D, std::move(X), std::move(Y));
    return 0;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
 
int main(){ 
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i=1; i<N; i++){
    cin >> a[i]; 
    b[a[i]-1]++;
  }
  for(int i=0; i<N; i++){
    cout << b[i] <<endl;
  }
}

Measured memory_bytes: 4788
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out,false);
        int n = scanner.nextInt();
        int[][] dists = new int[n][n];
        for(int[] dd: dists) Arrays.fill(dd, Integer.MAX_VALUE/3);
        for(int i = 0; i < n; i++) {
            dists[i][i] = 0;
        }
        for(int i = 0; i < n; i++) {
            char[] line = scanner.next().toCharArray();
            for(int j = 0; j < n; j++) {
                if (line[j] == '1') {
                    dists[i][j] = 1;
                }
            }
        }
        for(int k = 0; k < n; k++) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    dists[i][j] = Math.min(dists[i][j], dists[i][k] + dists[k][j]);
                }
            }
        }
        Boolean[] col = new Boolean[n];
        col[0] = true;
        ArrayDeque<Integer> queue = new ArrayDeque<>();
        queue.offer(0);
        while(!queue.isEmpty()) {
            int cur = queue.poll();
            for(int edge = 0; edge < n; edge++) {
                if (dists[cur][edge] != 1) continue;
                if (col[edge] == null) {
                    col[edge] = !col[cur];
                    queue.offer(edge);
                }
                else if (col[edge] == col[cur]) {
                    System.out.println(-1);
                    return;
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if (dists[i][j] != Integer.MAX_VALUE/3) ans = Math.max(ans, dists[i][j] + 1);
        out.println(ans);
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> M(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> M.at(i).at(j);
    }
  }
  for(int i=0;i<H;i++){
    bool white=true;
    for(int j=0;j<W;j++){
      if(M.at(i).at(j) == '#'){
        white=false;
        break;
      }
    }
    if(white){
      for(int j=0;j<W;j++){
        M.at(i).at(j)='$';
      }
    }
  }
  for(int i=0;i<W;i++){
    bool white=true;
    for(int j=0;j<H;j++){
      if(M.at(j).at(i) == '#'){
        white=false;
        break;
      }
    }
    if(white){
      for(int j=0;j<H;j++){
        M.at(j).at(i)='$';
      }
    }
  }
  for(int i=0;i<H;i++){
    bool printed=false;
    for(int j=0;j<W;j++){
      if(M.at(i).at(j) != '$'){
        cout << M.at(i).at(j);
        printed=true;
      }
    }
    if(printed){
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n];
	int sum=0,k=0;
	float min;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	min=(float)sum/(4.0*m);
	for(int i=0;i<n;i++)
	{
		if(a[i]>=min)
			k++;
		if(k==m)
			break;
	}
	if(k==m)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	string s;
	cin>>s;
	int n = s.size();
	vi suffixlr(n,-1);
	vi prefixrl(n,-1);
	for(int i=n-2;i>=0;i--)
	{
		if(s[i]=='R'&&s[i+1]=='L')
			suffixlr[i] = i;
		else
			suffixlr[i] = suffixlr[i+1];
	}
	for(int i=1;i<n;i++)
	{
		if(s[i]=='L'&&s[i-1]=='R')
			prefixrl[i]=i;
		else
			prefixrl[i] = prefixrl[i-1];
	}
	vi count(n,0);

	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
		{
			int rem = (2-(suffixlr[i]-i)%2)%2;
			rem ==0?count[suffixlr[i]]++:count[suffixlr[i]+1]++;
		}
		else
		{
			int rem = (2 - (i-prefixrl[i])%2)%2;
			rem ==0?count[prefixrl[i]]++:count[prefixrl[i]-1]++;
		}
	}
	cout<<count;
	return 0;	
}

Measured memory_bytes: 1872
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,m;
	cin>>a>>b>>m;
	VII aa(a),bb(b);
    ll ans=INT_MAX;
	int ma=INT_MAX;
	for(auto &x:aa){
	    cin>>x;
	    ma=min(ma,x);
	}
	ans=ma;
	ma=INT_MAX;
	for(auto &x:bb){
	    cin>>x;
	    ma=min(ma,x);
	}
	ans+=ma;
	map<PII,ll> dis;

	while(m--)
    {
	    int x,y,c;
	    cin>>x>>y>>c;
	    if(dis.find({x-1,y-1})==dis.end())
	        dis[{x-1,y-1}]=(ll)aa[x-1]+bb[y-1]-c;
	    else
	    dis[{x-1,y-1}]=min(dis[{x-1,y-1}],(ll)aa[x-1]+bb[y-1]-c);
	    ans=min(ans,dis[{x-1,y-1}]);
    }

	cout<<ans;
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int ls=s.size(),lt=t.size();
	int minn=10000;
	for(int i=0;i<=ls-lt;i++)
	{
		int sum=0,k=0;
		for(int j=i;j<i+lt;j++)
		{
			if(s[j]!=t[k]) sum++;
			k++;
		}
		minn=min(minn,sum);
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(){
	int a,b,c,d,e;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	int check=10;
	for (int i=1;i<10;i++){
		if (a%10==i||b%10==i||c%10==i||d%10==i||e%10==i){
			check=i;
			break;
		}
	}
	int res=((a+9)/10+(b+9)/10+(c+9)/10+(d+9)/10+(e+9)/10)*10-10+check;
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  
    int a[3];
    int c5=0,c7=0;
    for(int i=0;i<3;i++){
        cin >> a[i];
        if(a[i]==5){
            c5++;
            continue;
            
        }
        else if(a[i]==7) {
            c7++;
            continue;
            
        }
    }
    if(c5==2 && c7==1) cout << "YES";
    else cout << "NO";
    
 
 
  	return 0;
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		int max = 0;
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			max = Math.max(max, a);
			sum += a;
		}
		
		if(max < sum-max) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 24148
#include<bits/stdc++.h>
#define ll long long
#define int long long

#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int h[n],ans[n];

  rep(i,0,n){ cin>>h[i]; ans[i]=INT_MAX;}
  ans[0]=0;
  rep(i,0,n)
  {
    if(i+1<n)
      ans[i+1]=min(ans[i+1],ans[i]+abs(h[i+1]-h[i]));
    if(i+2<n)
      ans[i+2]=min(ans[i+2],ans[i]+abs(h[i+2]-h[i]));
  }
  cout<<ans[n-1];
 



}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   vector<int> v(n+1,0),a(n+1,0);
   for(int i=1;i<=n;i++)cin>>a[i];
   int count=0;
   v[n]=a[n]%2;
   for(int i=n;i>=1;i--){
       count=0;
       for(int j=2;j*i<=n;j++)count+=v[i*j];
       if(abs(count-a[i])%2)v[i]=1;
   }
   int ans=accumulate(v.begin()+1,v.end(),0);
   cout<<ans<<endl;
   for(int i=1;i<=n;i++)if(v[i])cout<<i<<' ';
   
}

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

constexpr long long INF = 1e18;

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);
	for (auto & e : a) cin >> e;
	sort(a.begin(), a.end());
	
	
	long long ans = 1;
	for (auto &e : a) {
		if (__builtin_mul_overflow(e, ans, &ans)) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	if (INF < ans) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

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

#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll N = 5e5 +9;

ll a, b, c, ans;
int main(){
    cin >> a;
    for(int i = 1; i <= a; ++i){
        for(int j=1;j <= i;j+=2){
            if(i % j == 0){
                c++;

            }
        }

        if(c == 8 ){
            ans++;
        }
        c=0;
    }

    cout<<ans;




}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp
# Matching - Bipartite Matching

class EdmondsKarp
  def initialize(n)
    @n = n
    @flow = Array.new(n) { Array.new(n, 0) }
    @cap = Array.new(n) { Array.new(n, 0) }
  end

  def connect(s, t, w)
    @cap[s][t] = w
  end

  def calc(start, goal)
    inf = 2 ** 30
    sum = 0
    while true
      que = [start]
      prev = Array.new(@n, -1)
      prev[start] = start
      while !que.empty? && prev[goal] == -1
        u = que.shift
        @n.times do |i|
          if prev[i] == -1 && @cap[u][i] - @flow[u][i] > 0
            prev[i] = u
            que.push(i)
          end
        end
      end
      return sum if (prev[goal] == -1)
      inc = inf
      c = goal
      while c != start
        inc = [inc, @cap[prev[c]][c] - @flow[prev[c]][c]].min
        c = prev[c]
      end
      c = goal
      while c != start
        @flow[prev[c]][c] += inc
        @flow[c][prev[c]] -= inc
        c = prev[c]
      end
      sum += inc
    end
  end
end

vn, en = gets.split.map(&:to_i)
n = vn + 2
g = EdmondsKarp.new(n)

en.times do |i|
  s, t, w = gets.split.map(&:to_i)
  g.connect(s, t, w)
end

puts g.calc(0, vn - 1)



Measured memory_bytes: 7068
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

alias Pair = Tuple!(int, "i", int, "j");

void main() {
    int H, W, D;
    scan(H, W, D);
    auto a = iota(H).map!(i => readln.split.to!(int[])).array;
    auto p = new Pair[](H*W + 1);
    foreach (i ; 0 .. H) {
        foreach (j ; 0 .. W) {
            p[a[i][j]] = Pair(i, j);
        }
    }

    auto dis(int x, int y) {
        return abs(p[x].i - p[y].i) + abs(p[x].j - p[y].j);
    }
    auto r = new long[](H*W + 1);
    foreach (i ; D + 1 .. H * W + 1) {
        r[i] = r[i - D] + dis(i, i - D);
    }

    int Q;
    scan(Q);

    foreach (_ ; 0 .. Q) {
        int li, ri;
        scan(li, ri);
        auto ans = r[ri] - r[li];
        writeln(ans);
    }
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 13308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


int main(){ 
  int n;
  int p=0;
  int m=0;
  cin >> n;
  int x[n];
  int y[n];
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>=0) p++;
    else m++;
  }
  
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    int min = a[0];
    int max = a[n-1-i];
    a.erase(a.begin());
    a.erase(a.begin()+(n-2-i));
    if(min>=0) p--;
    else m--;
    if(max>=0) p--;
    else m--;
    if(p<=0){
     x[i]=max;
     y[i]=min;
     a.push_back(max-min);
    }
    else{
      x[i]=min;
      y[i]=max;
      a.insert(a.begin(), min-max);
    }  
    
  }
  
  
  
  
  cout << a[0] << endl;
  
  for(int i=0;i<n-1;i++){
    cout << x[i] << " " << y[i] << endl;
  }
  
  
  
  
  
  
  
}

Measured memory_bytes: 3072
/*
[by.YXH_XianYu]
2018.06.03
AtCoder 
*/
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>

int n,ans=1000000000;

int Digit(int n){
	int cnt=0;
	while(n>=10){
		cnt+=n%10;
		n/=10;
	}
	return cnt+n%10;
}

int main(){
	//freopen("YXH_XianYu.in","r",stdin);
	//freopen("YXH_XianYu.out","w",stdout);

	scanf("%d",&n);
	int b,lim=n/2;
	for(int a=1;a<=lim;a++){
		b=n-a;
		//printf("%d %d %d\n",a,b,Digit(a)+Digit(b));
		ans=std::min(ans,Digit(a)+Digit(b));
	}
	printf("%d\n",ans);
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class Hello
{
    const  int MOD = 1000000007;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        var d = new Dictionary<char, int>();
        for (int i = 0; i < n; i++)
            if (d.ContainsKey(s[i])) d[s[i]]++;
            else d[s[i]] = 1;
        var ans = 1L;
        foreach(var x in d)
        {
            ans *= (x.Value + 1);
            ans %= MOD;
        }
        Console.WriteLine(ans - 1);
    }
}

Measured memory_bytes: 13152
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 201001;
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int s = 0;
    for (int d = 1; d <= n; d++) {
        for (int i = 1; i <= n; i++) {
            int gc = __gcd(d, i);
            for (int j = 1; j <= n; j++) {
                s += __gcd(gc, j);
            }
        }
    }
    cout << s;
}


Measured memory_bytes: 3640
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    ans = []
    for i in p:
        if i % 5 == 1:
            ans.append(i)
    print(*ans[:n],sep = " ")
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 5816
#include <iostream>
using namespace std;
int main()
{
	int k,a,b,c=0;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			c++;
		}
	}
	if(c!=0)
	{
		cout<<"OK";
	}
	else
	{
		cout<<"NG";
	}
	return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import math
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
n = int(input())
#s = input()

# スペース区切りの入力
#n, x = input().split()

# スペース区切りの整数の入力
#a, b = map(int, input().split())
#n, x = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
v = [int(x) for x in input().split()]
#b = [int(x) for x in input().split()]
#print("a", a, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#b = []
#for x in range(m):
#  b.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s


#print("a", a, file=sys.stderr)
#print("b", b, file=sys.stderr)

def getEnergy():
  for y in b:
    yield y

  #print(res, file=sys.stderr)
  return res

v.sort()
def doit():
  ret = v[0]
  for x in v:
    ret = (ret + x) / 2
  return ret

def yn():
  if doit():
    return "YES"
  else:
    return "NO"

#print(doit([0] * 4))
#doit(a)
#print(doit())
try:
  #doit()
  print(doit())
  #print(yn())
except Exception as e:
  print("e", e, file=sys.stderr)


Measured memory_bytes: 5148
using System;

class Abc126C
{
    static void Main(string[] args)
    {
        var buf = Console.ReadLine().Split();
        var N = int.Parse(buf[0]);
        var K = int.Parse(buf[1]);
        var p = new double();

        for(var i = 1; i <= N; ++i) {
            var temp = i;
            var j = 0;
            for(; ; ++j) {
                if(temp >= K)
                    break;
                temp *= 2;
            }
            p += (1.0 / N) * Math.Pow((1.0 / 2), j);
        }
        Console.WriteLine($"{p:f10}");
    }
}


Measured memory_bytes: 13140
N = int(input())
ans=0
c=0
for a in range(1,1001):
    c=N-a*a
    if c>=1:
        ans+=1
ans1=0
for a in range(1,1000001):
    for b in range(a+1,int(N/a)+1):
        c=N-a*b
        if c>=1:
            ans1+=1
print(ans+ans1*2)

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

int main(int argc, const char * argv[]) {
    string str;
    cin >> str;
    int sum = 0;
    for (int i = 0; i < 3; i++) {
        if (str[i] == '1')  sum += 1;
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    int cnt=0;
    reps(i,n){
        int p;
        cin>>p;
        if(p!=i) cnt++;
    }
    cout<<((cnt==2||cnt==0)?"YES":"NO")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


int main(){
  int N; cin >> N;
  string S; cin >> S;
  int Q; cin >> Q;
  vector<set<int>> st(26);
  rep(i,N) st[(int)(S[i]-'a')].insert(i);
  rep(q,Q){
    int op; cin >> op;
    if(op == 1){
      int id; char x;
      cin >> id >> x; id--;
      st[(int)(S[id]-'a')].erase(id);
      st[(int)(x-'a')].insert(id);
      S[id] = x;
    }
    else if(op == 2){
      int l, r; cin >> l >> r;
      l--; r--;
      int ans = 0;
      rep(i,26){
        if(st[i].lower_bound(l) != st[i].upper_bound(r)) ans++;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}


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

struct UnionFind {
  vector<int> par, weight;
  UnionFind(int n) : par(n,-1), weight(n) {}
  void unite(int x, int y, int w = 0) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y), w = -w;
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if(par[x] < 0) return x;
    int r = find(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
};

int N, M, K, L;

int main() {
  cin >> N >> M;
  UnionFind uf(N + M);

  for(int i = 0; i < N; ++i) {
    cin >> K;
    for(int j = 0; j < K; ++j) {
      cin >> L;
      --L;
      uf.unite(i, N + L);
    }
  }
  for(int i = 1; i < N; ++i) {
    if(!uf.same(0, i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

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

int sum_digits(int n){
	int ret = 0;
	int digit = log10(n) + 1;
	for(int i = 0; i < digit; i++){
		ret += ctoi(to_string(n).at(i));
	}
	return ret;
}

int main(){
	int N, S;
	string ret;
	cin >> N;
	S = sum_digits(N);
	if(N%S == 0){
		ret = "Yes";
	}else{
		ret = "No";
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

int a, b, c, d;

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

    cin >> a >> b >> c >> d;

    while(a > 0 && c > 0) {
        a -= d;
        c -= b;
    }

    if(c <= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3612
N = int(input())

ans = ''
if N == 0:
    print(0)
    exit()

while N != 0 and N != 1:
    if N > 0:
        if N%2:
            ans += '1'
            N = -(N//2)
        else:
            ans += '0'
            N = -N//2
    else:
        if -N%2:
            ans += '1'
            N = -(N-1)//2
        else:
            ans += '0'
            N = N//(-2)
if N:
    ans += '1'
print(ans[::-1])



Measured memory_bytes: 3060
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
def ls(n,a)
  if n==0 then
    return a
  else
    return (1.05*ls(n-1,a)/1000.0).ceil*1000
  end
end

n = gets.to_i
x0 = 100000
puts ls(n,x0)

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

int dp[502][2][10][500][3], m, len[2];
char S[2][550];

int solve(int o) {
	memset(dp,0,sizeof(dp));
    dp[0][0][0][0][0] = 1;
    rep(i, len[o])rep(j, 2)rep(k, 10)rep(l, m)rep(d, 3) {
        if (dp[i][j][k][l][d] == 0)continue;
        int s, g, p = S[o][i] - '0';
        if (d == 1) { s = k + 1; g = (j ? 9 : p); }
        else if (d == 2) { s = 0; g = (j ? k - 1 : min(k - 1, p)); }
        else { s = 0; g = (j ? 9 : p); }
        for (int x = s; x <= g; x++) {
            if (x&&k == x)continue;
            int y;
            if (d == 1)y = 2;
            else if (d == 2)y = 1;
            else {
                if (k == 0)y = 0;
                else if (x < k)y = 1;
                else y = 2;
            }
            (dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %= MOD;
        }
    }
    int sum=0;
    rep(j,10)rep(t,3){
    	(sum+=dp[len[o]][1][j][0][t])%=MOD;
    	if(o)(sum+=dp[len[o]][0][j][0][t])%=MOD;
    }
    return sum;
}
int main() {
    scanf("%s%s%d", S[0], S[1], &m);
    rep(i, 2)len[i] = strlen(S[i]);
    printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}

Measured memory_bytes: 62036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()

	if s[2] == s[3] && s[4] == s[5] {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}
func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

type Group struct {
	Depth int
	Value string
}

type Job struct {
	No     int
	S      int
	E      int
	Worker string
}

type Res struct {
	No int
}

func Abs(a int64, b int64) int64 {
	res := a - b
	if a-b < 0 {
		res = -res
	}
	return res
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	n := nextInt()
	res := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			for k := 1; k <= n; k++ {
				res += gcd(gcd(i, j), k)
			}
		}
	}
	fmt.Fprintln(out, fmt.Sprint(res))
}


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> a;

    cout << a*800-(a/15)*200;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 8223372036854775807
//#define LLINF 
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

struct edge { int to, cost; };
typedef pair<int, int> P;

int V;
vector<edge> G[101010];
int d[101010];

void dikstra(int s) {
	priority_queue<P, vector<P>, greater<P> >que;
	REP(i, V)d[i] = INF;
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		REP(i, G[v].size()) {
			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));
			}
		}
	}
}

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

	int M;
	cin >> V >> M;
	REP(i, M) {
		int a, b, c;
		
		cin >> a >> b >> c;
		a--;
		b--;
		edge e = { b,c };
		G[a].push_back(e);
	}
	
	for (int i = V - 1; i > 0; i--) {
		edge e = { i - 1,0 };
		G[i].push_back(e);
	}
	dikstra(0);
	//REP(i, V)cout << d[i] << endl;
	if (d[V - 1] == INF)d[V - 1] = -1;
	cout << d[V - 1] << endl;
	return 0;
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int ans = 1;
  for (int i = 1; i < n; i++) if (s[i - 1] != s[i]) ans++;
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    int c1=0, c2=0, c3=0, c4=0;
    for (int i=0; i<n; i++)
    {
        cin >> s;
        if (s == "AC")
            c1++;
        else if (s == "WA")
            c2++;
        else if (s == "TLE")
            c3++;
        else if (s == "RE")
            c4++;
    }
    cout << "AC x " << c1 << "\nWA x " << c2 << "\nTLE x " << c3 << "\nRE x " << c4;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int x,y,z;
    cin>>x>>y>>z;
    x-=z;
    cout<<x/(y+z)<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define int long long 
using namespace std;
using Graph = vector<vector<int>>;

signed main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for( int i = 0; i < N; i++ ){
    cin >> C.at(i);
    for( int j = 0; j < M; j++ ) cin >> A.at(i).at(j);
  }
  
  
  int ans = 10000000000;
  for (int bit = 0; bit < (1<<N); ++bit) {
    vector<int> algo(M, 0);
    int now = 0;
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) { // i番目のbitが立っていれば
        now += C.at(i);
        for( int j = 0; j < M; j++ ) algo.at(j) += A.at(i).at(j);
      }
    }
    bool fg = 1;
    for( int j = 0; j < M; j++ ){
      if( algo.at(j) < X ) fg = 0;
    }
    if ( fg ) ans = min(ans, now);
  }
  if( ans == 10000000000 ){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;

typedef long long ll;
const int NAX = 1e5 + 5;
int res[NAX];

int main() {
    string s; cin >> s;
    int n = s.length();
    deque<int> l, r;
    for(int i=0; i<n; ++i) {
        if(s[i] == 'L')
            l.push_back(i);
        else
            r.push_back(i);
    }
    int last_lo = -1, lo = l.front();
    for(int i=0; i<n; ++i) {
        if(s[i] == 'R') {
            while(last_lo < i) {
              lo = l.front();
              l.pop_front();
              last_lo = lo;
            }
            int diff = lo - i;
            if(diff & 1)
                ++res[lo - 1];
            else
                ++res[lo];
        }
    }
    int last_r = NAX, ri = r.back();
    for(int i=n-1; i>=0; --i) {
        if(s[i] == 'L') {
            while(last_r > i) {
               ri = r.back();
               r.pop_back();
               last_r = ri;
            }
            int diff = i - ri;
            if(diff & 1)
                ++res[ri+1];
            else
                ++res[ri];
        }
    } 
    for(int i=0; i<n; ++i)
        cout << res[i] << " ";
    cout << "\n";
    return 0;
} 


Measured memory_bytes: 1408
n, a ,b = map(int, input().split())
x = list(map(int, input().split()))

res = 0
for i in range(1, len(x)):
    a_c = (x[i]-x[i-1])*a
    b_c = b
    if a_c > b_c:
        res += b_c
    else:
        res += a_c

print(res)


Measured memory_bytes: 14252
h,w = map(int,input().split())
rows = []

for _ in range(h):
    rows.append(input())

for i in range(h):
    for j in range(w):
        if rows[i][j] =='#':
            judge = 0
            for nh,nw in [(1,0),(-1,0),(0,-1),(0,1)]:
                if (0<=i+nh<=h-1)and(0<=j+nw<=w-1):
                    if rows[i+nh][j+nw] =='#':
                        judge =1
                        break
            if judge == 0:
                print('No')
                exit()
print('Yes')
                

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k,ans=0;
    cin>>n>>k;
    while(n>0){
        ans+=1;
        n/=k;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    int n,W; cin>>n>>W;
    
    int first_w,first_v; cin>>first_w>>first_v;
    vector<vector<int>> vs(4);
    vs.at(0).push_back(first_v);
    rep(i,n-1){
        int w,v; cin>>w>>v;
        vs.at(w-first_w).push_back(v);
    }
    
    rep(i,4){
        sort(all(vs.at(i)),greater<int>());
    }
    
    vector<vector<int>> vsum(4);
    rep(i,4){
        int sum=0;
        vsum.at(i).push_back(0);
        rep(j,vs.at(i).size()){
            sum+=vs.at(i).at(j);
            vsum.at(i).push_back(sum);
        }
    }
    
    int ans=0;
    rep(i,vs.at(0).size()+1){
        rep(j,vs.at(1).size()+1){
            rep(k,vs.at(2).size()+1){
                rep(l,vs.at(3).size()+1){
                    if(first_w*i+(first_w+1)*j+(first_w+2)*k+(first_w+3)*l<=W){
                        chmax(ans, vsum.at(0).at(i)+vsum.at(1).at(j)+vsum.at(2).at(k)+vsum.at(3).at(l));
                    }
                }
            }
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w;
vector<string> field;

int main() {
    cin >> h >> w;
    int ans = h*w;
    field.resize(h);
    vector<vector<int>> matrix(h, vector<int>(w, -1));

    rep(i, h) {
        cin >> field[i];
    }

    rep(i, h) {
        rep(j, w) {
            if(field[i][j] == '#') {
                matrix[i][j] = 0;   //黒マスは0
                ans--;
            }
        }
    }
    matrix[0][0] = 1;   //スタートは1

    queue<pair<int, int>> next;

    next.push(make_pair(0, 0)); //queueにスタートを入れる

    while(!next.empty()) {
        int x = next.front().first;
        int y = next.front().second;
        rep(i, 4) { //4方向調べる
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || h <= nx || ny < 0 || w <= ny) {
                continue;   //field外はダメ
            }
            if(matrix[nx][ny] >= 0) {
                continue;   //探索したマスもダメ
            }
            matrix[nx][ny] = matrix[x][y] + 1;  //隣マスに1足す
            next.push(make_pair(nx, ny));   //隣マスをqueueに入れる
        }
        next.pop(); //探索したマスをqueueから出す
    }

    ans -= matrix[h-1][w-1];

    if(matrix[h-1][w-1] == -1) {
        cout << -1;
    }
    else {
        cout << ans;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b,m;
 cin>>a>>b>>m;
 vector<int> vea(a);
for(int i=0;i<a;i++){
  cin>>vea.at(i);
}
vector<int> veb(b);
for(int i=0;i<b;i++){
  cin>>veb.at(i);
}
float sum=INFINITY;
for(int i=0;i<m;i++){
    int x,y,c;
    cin>>x>>y>>c;
if(vea.at(x-1)+veb.at(y-1)-c<sum){
    sum=vea.at(x-1)+veb.at(y-1)-c;
}
}
sort(vea.begin(), vea.end());
sort(veb.begin(), veb.end());
if(vea.at(0)+veb.at(0)<sum){
    sum=vea.at(0)+veb.at(0);
}
cout<<sum<<endl;

}

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

const int mxN=1e5, INF=1e9+7;
int n;
vector<int> h(mxN+1);

vector<int>dp(mxN+1);

int main(){
  cin>>n;
  for(int i=1;i<=n;i++)
	cin>>h[i];

    dp[2] = abs(h[2]-h[1]);

    for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}

	cout<< dp[n];

}


Measured memory_bytes: 3908
use std::collections::BTreeMap;

fn get_prime_factors(n: usize) -> BTreeMap<usize, usize> {
    let mut prime_factors = BTreeMap::new();

    if n < 2 {
        prime_factors.insert(n, 1);
        return prime_factors;
    }

    let mut m = n;

    for f in (2..).take_while(|a| a*a <= n) {
        let mut i = 0;
        while m % f == 0 {
            i = i+1;
            m = m / f;
        }
        if i > 0 {
            prime_factors.insert(f, i);
        }
    }

    if m > 1 {
        prime_factors.insert(m, 1);
    }

    prime_factors
}

fn main() {
    let s = read_string();
    let mut sc = Scanner::new(&s);

    let n: usize = sc.next();
    let p: usize = sc.next();

    let mut ans = 1;

    for (f, i) in get_prime_factors(p) {
        for _ in 0..i/n {
            ans = ans * f;
        }
    }

    print!("{}\n", ans);
}

// 以下、たなこふ先生からぱくったやつ (´･_･`)

struct Scanner<'a> {
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Scanner<'a> {
    fn new(s: &str) -> Scanner {
        Scanner {
            iter: s.split_whitespace(),
        }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        let s = self.iter.next().unwrap();
        s.parse().unwrap()
    }
}

fn read_string() -> String {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    buf
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;




int main()
{

    ll n,k,m;

    cin>>n>>k;
    m=n*500;

    if(m>=k)cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 256
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
            int n;
            cin >> n;

            int x = ceil(n * 1.0 / 1000);
            cout << 1000 * x - n << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 1
#define inf 0x7fffffff
int n,m,ans,a[maxn];
int main()
{
	cin>>n;m=n;
	while(m)
	{
		ans+=m%10;m/=10;
	}
	if(n%ans) cout<<"No";
	else cout<<"Yes";
}

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

int main(){
	int i, t, a[3], r= 3;
	for(i = 0; i < 3; i++){
		cin >> a[i];
	}
	
	for(i = 0; i < 2; i++){
		if(a[i] > a[i + 1]){
			t = a[i];
			a[i] = a[i + 1];
			a[i + 1] = t;
		}
	}
	for(i = 0; i < 2; i++){
		if(a[i] == a[i + 1]) r--;
	}
	cout << r;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int one =0, four = 0;
    bool two = false;
    int N, x;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x;
        if(x % 4 == 1 || x % 4 == 3){
            one++;
        }
        else if(x % 4 == 0){
            four ++;
        }
        else{
            two = true;
        }
    }
    if(two == true){
        if(four >= one) cout << "Yes";
        else cout << "No";
    }
    else{
        if(four + 1 >= one) cout << "Yes";
        else cout << "No";
    }
}

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

#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define F first
#define S second
#define JULEE_DO_THE_THING fast()
#define to_str to_string
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMIN INT_MIN
#define IMAX INT_MAX
#define pow POW

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast() {
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
}

bool compare(int &a, int &b) {
	return a > b;
}

ll numOfDigits(ll n) {
	if (!n)
		return 1;
	return (ll) (log10(n)) + 1;
}

ull POW(ll a, ll b);

/*

*/

ll BN();

int main() {
	JULEE_DO_THE_THING;
	//freopen("test cases\\.txt", "r", stdin) ;
    str arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    cout<<arr[0][0]<<arr[1][0]<<arr[2][0];
	return 0;
}

ll BN() {
	int low = 1;
	int up = 0;
	int ans = -1;
	while (low <= up) {
		ll mid = (((ll)low + up) / 2);
		if (mid){
			ans = mid;
			low = mid + 1;
		} else
			up = mid - 1;
	}
	return ans;
}

ull POW(ll a, ll b) {
	ull res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int count=1;
  if(a==b){
    count++;
    if(b==c){
      count++;
    }
  }
  else if(a==c){
    count++;
  }
  else if(b==c){
    count++;
  }
  cout<<4-count<<endl;
}

Measured memory_bytes: 256
// Example program
#include <bits/stdc++.h>
using namespace std;
bool checked[3][3];
int main()
{
  int a[3][3];
  memset(checked,0,sizeof checked);
  bool ok=0;
  int n,x;
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>a[i][j];
  cin>>n;
  for(int q=0;q<n;q++)
  {
      cin>>x;
      for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(a[i][j]==x)checked[i][j]=1;
  }
  for(int i=0;i<3;i++)
  {
      if(checked[i][0]==1&&checked[i][1]==1&&checked[i][2]==1)ok=1;
  }
  
  for(int i=0;i<3;i++)
  {
      if(checked[0][i]==1&&checked[1][i]==1&&checked[2][i]==1)ok=1;
  }
  if(checked[0][0]==1&&checked[1][1]==1&&checked[2][2]==1)ok=1;
  if(checked[0][2]==1&&checked[1][1]==1&&checked[2][0]==1)ok=1;
  if(ok)cout<<"Yes\n";
  else cout<<"No\n";
}


Measured memory_bytes: 256