akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for (int i = 5; N > 0; i++) {
            if (i % 5 == 1) {
                if (isPrime(i)) {
                    System.out.print(i + " ");
                    N--;
                }
            }
        }
    }

    public static boolean isPrime(int num) {
        if (num < 2) {
            return false;
        } else if (num == 2) {
            return true;
        } else if (num % 2 == 0) {
            return false; // 偶数はあらかじめ除く
        }
        double sqrtNum = Math.sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}

Measured memory_bytes: 21332
#include<stdio.h>

int main(void)
{
    int a,b;
    char op;
    do {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '+')
        {
            printf("%d\n",a+b);
        }
        else if (op == '-')
        {
            printf("%d\n", a-b);
        }
        else if (op == '*')
        {
            printf("%d\n", a*b);
        }
        else if (op == '/')
        {
            printf("%d\n",a/b);
        }
        else if (op == '?')
        {
            break;
        }
    }while (1);
    return 0;
}



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

int main()
{
	bool is_prime[10000001];
	
	is_prime[0]=is_prime[1]=false;
	
	for(int i=2;i<10000001;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<100000011;i++){
		if(is_prime[i]){
			for(int j=i*i;j<10000001;j+=i){
				is_prime[j]=false;
			}
		}
	}
	
	while(true){
		int n;
		cin>>n;
		
		if(n==0)
			break;
			
		for(int i=n;i>12;i--){
			if(is_prime[i]&&is_prime[i-2]&&is_prime[i-6]&&is_prime[i-8]){
				cout<<i<<endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 12780
/**
 * Author: Deb Natkh Maxim (debnatkh@gmail.com)
 * Date: 24.03.2019
 */

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;

const int MAXN = 100, MAXA = 1e5 + 10;
int dp[MAXN + 1][MAXA];
int arr[MAXN];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    string s;
    cin >> s;
    for (auto c : s) {
        if (c == 'A') cout << 'T';
        if (c == 'T') cout << 'A';
        if (c == 'C') cout << 'G';
        if (c == 'G') cout << 'C';
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    Integer a = scan.nextInt();
    Integer b = scan.nextInt();
    if(a + b >= 10){
      System.out.println("error");
    }else{
      System.out.println(a+b);
    }
  }
}
    

Measured memory_bytes: 21460
a1,b1=input().split()
a2,b2=input().split()
a3,b3=input().split()
t=a1+b1+a2+b2+a3+b3
if t.count("1")*t.count("2")*t.count("3")*t.count("4")==0 or max(t.count("1"),t.count("2"),t.count("3"),t.count("4"))==3:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        int n     = int.Parse(spl[0]);
        int k     = int.Parse(spl[1]);

        int[] ss = new int[n];
        for(int i=0; i<n; i++) {
            ss[i] = input.Read();
        }

        int ret = count(ss);
        ret += Math.Min(k * 2, sa(ss));

        return ret;
    }
    
    static void print(int[] ary) {
        foreach(var i in ary) {
            Debug.Write((char)i);
        }
        Debug.Write("(" + count(ary) + ")");
        Debug.Write("(" + sa(ary) + ")");
        Debug.WriteLine("");
    }

    static int[] swap(int[] ary, int a, int b) {
        int[] ret = new int[ary.Length];
        int n = ary.Length;
        a = a - 1;
        b = b - 1;

        for(int i=0; i<n; i++) {
            if(a <= i && i <= b) {
                ret[i] = ary[b - (i-a)] == 'L' ? 'R' : 'L';
            } else {
                ret[i] = ary[i];
            }
        }
        return ret;
    }

    static int count(int[] ary) {
        int c = 0;
        int n = ary.Length;
        for(int i=0; i<n; i++) {
            if (ary[i] == 'L') {
                if (i > 0 && ary[i - 1] == 'L') c++;
            } else {
                if (i < n - 1 && ary[i + 1] == 'R') c++;
            }
        }
        return c;
    }

    static int sa(int[] ary) {
        int c = 0;
        int n = ary.Length;
        for(int i=0; i<n-1; i++) {
            if (ary[i] != ary[i + 1]) c++;
        }
        return c;
    }
}


Measured memory_bytes: 11232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;


int main (int argc, char const *argv[])
{
    int N;
    cin>>N;

    if (N%2==0) {
        cout<<N<<endl;
    }
    else
    {
        cout<<N*2<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

vector<long long> enum_divisors(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    sort(a.begin(), a.end());
    auto candy = enum_divisors(a[0]);
    auto tmp = enum_divisors(a[1]);
    candy.insert(candy.end(), tmp.begin(), tmp.end());
    long long ma = 0;
    for (auto x: candy) {
        int cnt = 0;
        for (auto ai: a) if (ai % x != 0) cnt++;
        if (cnt <= 1) ma = max(ma, x);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 640
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-08 01:54:56
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

constexpr int64 MOD = 1e9 + 7;

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

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

  string s; cin >> s;
  int n = s.size();
  vector<int64> cntA(n, 0LL), cntB(n, 0LL), cntC(n, 0LL), cntq(n, 0LL);

  for (int i = 0; i < n; ++i) {
    cntA[i] = s[i] == 'A';
    cntB[i] = s[i] == 'B';
    cntC[i] = s[i] == 'C';
    cntq[i] = s[i] == '?';
  }

  for (int i = 1; i < n; ++i) {
    cntA[i] += cntA[i - 1];
    cntB[i] += cntB[i - 1];
    cntC[i] += cntC[i - 1];
    cntq[i] += cntq[i - 1];
  }
  
  int64 ans = 0LL;

  //debug(cntB);

  for (int i = 1; i < n - 1; ++i) {
    if (s[i] == 'A' || s[i] == 'C') continue;
    int64 left = (cntA[i - 1] * mod_pow(3LL, cntq[i - 1], MOD) % MOD + cntq[i - 1] * mod_pow(3LL, cntq[i - 1] - 1LL, MOD)) % MOD;
    int64 right = ((cntC[n - 1] - cntC[i]) * mod_pow(3LL, cntq[n - 1] - cntq[i], MOD) % MOD + (cntq[n - 1] - cntq[i]) * mod_pow(3LL, cntq[n - 1] - cntq[i] - 1, MOD) % MOD) % MOD;
    ans += left * right % MOD;
  }

  cout << ans % MOD << endl;

  return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    string s;
    cin >> n >> s;
    string t;
    rep(i, s.size())
    {
        char c = s[i];
        c += n;
        if (c > 'Z')
            c -= 26;
        t.pb(c);
    }
    cout << t << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

ll N;
cin>>N;
int p=0;
string ans="";
while(true){
if(p%2==0){
    if(N%2!=0){
        ans=string(1,'1')+ans;
        N--;
    }
    else{
        ans=string(1,'0')+ans;

    }
    N/=2;

}
else{
    if(N%2!=0){
        ans=string(1,'1')+ans;
        N++;
    }
    else{
        ans=string(1,'0')+ans;

    }
    N/=2;
}
if(N==0){
    break;
}
p++;
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3656
n = int(input())
init_time = list(map(int, input().split()))
m = int(input())

drink = list()

for a in range(m):
    drink.append(list(map(int, input().split())))

x = 0

for a in range(m):
    for b in range(n):
        if drink[a][0] == b+1:
            x += drink[a][1]
        else:
            x += init_time[b]
    print(x)
    x = 0


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

vector<bool> isp;
void sieve(int N) {
	isp.assign(N+1, true);
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}

int main() {
	sieve(55555);
    int n; cin >> n;
    vector<int> ans;
    for (int i = 4;; i+=5) {
        if (isp[i]) ans.push_back(i);
        if (sz(ans)==n) break;
    }
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N, A, B;

int main(){
	cin >> N >> A >> B;
	A *= N;
	if (A < B){
		cout << A << endl;
	}
	else if (A > B) {
		cout << B << endl;
	}
	else {
		cout << A << endl;
	}


	return 0;
}

Measured memory_bytes: 256
def main():
    x, y = input().split()
    answer = 0
    prize = {"1": 300000, "2": 200000, "3": 100000}
    if x in prize:
        answer += prize[x]
    if y in prize:
        answer += prize[y]
    if x == y == "1":
        answer += 400000
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << endl;
}

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

int main(){

	long long ll,rr;
	cin >> ll>> rr;

	

	long long l=INT_MAX,r=0;

	for(int i=0;i<2020;i++){
		if(i+ll>rr)
			break;

		if(l>(i+ll)%2019){
			l=(i+ll)%2019;
		}

	}

	for(int i=0;i<2020;i++){
		if(rr-i<ll)
			break;

		if(r<(rr-i)%2019){
			r=(rr-i)%2019;
		}

	}


	long long ans = INT_MAX;
	for(int i=l;i<r;i++){
		for(int j=i+1;j<=r;j++){
			if(ans > (i*j)%2019){
				ans = (i*j)%2019;
			}
		}
	}

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String line = in.readLine();
      int k = Integer.parseInt(in.readLine());

      int n = line.length();
      Set<String> set = new TreeSet<>();

      for(int i=0; i <= n; i++) {
        for(int j=i+1; j<=n && j<=i+k; j++) {
            set.add(line.substring(i, j));
        }
      }

      Iterator<String> ite = set.iterator();
      String[] ans = new String[k];
      for(int i=0; i<k; i++)
        ans[i] = ite.next();

      System.out.println(ans[k-1]);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 24916
#include <iostream>
#include <algorithm>
using namespace std;
int min(int a,int b){
    return a<b?a:b;
}
int main(void){
    int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;i++)cin>>p[i];
    int top = 1000000;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(p[i] <= top){
            top = p[i];
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	cout << 180*(N-2)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <int,pi>
#define ull unsigned long long int
using namespace std;
int arr[nax];
int siz[nax];
vector< ll > ans;
vector< pi > v;

int root(int x)
{
	while(arr[x] != x)
	{
		 x = arr[x];
		 arr[x] = arr[arr[x]];
	}
	return x;
}

ll unite(int a, int b)
{
	a = root(a);
	b = root(b);
	ll ret = siz[a] * 1ll * siz[b];
	if(siz[a] > siz[b])
	{
		arr[b] = a;
		siz[a] += siz[b];
	}
	else
	{
		arr[a] = b;
		siz[b] += siz[a];
	}
	return ret;
}


int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a, b, k;
    cin >> a >> b >> k;
    int ctr = 0;
    for(int i = min(a,b); i >= 1; i--)
    {
    	if(a % i == 0 && b % i == 0)
    		ctr++;
    	if(ctr == k)
    	{
    		cout << i << "\n";
    		return 0;
    	}
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char S[262144], T[262144];
	scanf("%s%s", S, T);

	int s[26], n;
	for(int i=0; i<26; i++){
		s[i] = -1;
	}
	for(n=0; S[n]!='\0'; n++){
		if(s[S[n]-'a']==-1){
			s[S[n]-'a'] = T[n]-'a';
		} else if(s[S[n]-'a'] != T[n]-'a'){
			printf("No\n");
			return 0;
		}
	}

	for(int i=0; i<26; i++){
		s[i] = -1;
	}
	for(n=0; T[n]!='\0'; n++){
		if(s[T[n]-'a']==-1){
			s[T[n]-'a'] = S[n]-'a';
		} else if(s[T[n]-'a'] != S[n]-'a'){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 512
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<utility>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};


/*
(char)'1' - (int)48 = (int)1;


*/
int main()
{
	int h, w;
	cin >> w>> h;
	while (w != 0 || h != 0)
	{
		queue<XY> m;
		int a[200][200] = {};
		for (int i = 0; i < h; i++)
		{
			for (int l = 0; l < w; l++)
			{
				cin >> a[i + 1][l + 1];
			}
		}


		int ans = 0;

		for (int i = 0; i <= h; i++)
		{
			for (int l = 0; l <= w; l++)
			{
				if (a[i][l] == 1)
				{
					ans++;
					XY now;
					now.x = l;
					now.y = i;
					m.push(now);
					while (!m.empty())
					{
						XY gg;
						int x, y;
						x = m.front().x;
						y = m.front().y;
						m.pop();

						for (int i = 0; i < 8; i++)
						{
							if (a[y + dY[i]][x + dX[i]] == 1)
							{
								a[y + dY[i]][x + dX[i]] = 0;
								gg.x = x + dX[i];
								gg.y = y + dY[i];
								m.push(gg);
							}
						}

					}
				}
			}
		}
		cout << ans << endl;
		cin >> w >> h;
	}
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b-a == c-b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

#define FOR( i, m, n )	for( int (i) = (m); (i) < (n); i++ )
#define REP( i, n )		FOR( i, 0, n )
#define ALL( x )	(x).begin(), (x).end()

int main() {
	int a;
	int i = 1;
	while( 1 ) {
		cin >> a;
		if( a == 0 ) break;
		cout << "Case " << i << ": " << a << endl;
		i++;
	}
}


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

using namespace std;

#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vii;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
//int mod=1000000007








int main(){
	int n, m, p;
	while (cin >> n >> m >> p){
		if (n == 0 && m == 0 && p == 0) break;
		int sum = 0, w, t;
		for (int i = 0; i < n; i++){
			cin >> t;
			sum += t;
			if (i == m - 1) w = t;
		}
		sum *= 100;
		double d = (double)sum*(100 - p) / 100;
		if (w == 0)cout << "0" << endl;
		else cout << (int)(d / w) << endl;
		//cout << sum << endl;
	}

}

Measured memory_bytes: 1160
import collections
n,c,k = map(int,input().split())
d = collections.deque()
ans = 0
lis = []
for _ in range(n):
    lis.append(int(input()))
lis.sort()

wait = lis[0]
for tm in lis[1:]:

    if tm > wait+k:
        ans += 1
        d.clear()
        wait = 1000000000
    d.append(tm)
    if len(d) == c-1:
        ans += 1
        d.clear()
        wait = 1000000000

    if len(d)!=0 and wait == 1000000000:
        wait = d.popleft()


if c==1: ans = n-1
print(ans+1)

Measured memory_bytes: 8120
import math


def main():
    x = int(input())

    primes = []
    i = 2
    while True:
        if len(primes) == 0:
            primes.append(i)
        max_val = int(math.sqrt(i))
        is_prime = True
        for p in primes:
            if p > max_val:
                break
            if i % p == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(i)
            if x <= i:
                print(i)
                return
        i += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 3296
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, H = LI()
ab = [[]] * N
a = [0] * N
b = [0] * N

for i in range(N):
    a[i], b[i] = LI()
    ab[i] = [a[i], b[i]]

a_max = max(a)
ans = 0
b.sort(reverse= 1)
for i in range(N):
    if H <= 0:
        break
    if b[i] > a_max:
        H -= b[i]
        ans += 1
if H > 0:
    ans += math.ceil(H / a_max)
print(ans)


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

int DP[100001] = {};

int main(){
  int n;
  cin >> n;
  for(int i = 1;i <= n;i++){
    int j;
    int Min = DP[i - 1];
    for(j = 6;j <= i;j *= 6){
      if(DP[i - j] < Min){
        Min = DP[i - j];
      }
    }
    for(j = 9;j <= i;j *= 9){
      if(DP[i - j] < Min){
        Min = DP[i - j];
      }
    }
    DP[i] = Min + 1;
  }
  cout << DP[n] << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int odd = n / 2 + (n % 2);
  ld ans = (ld)odd / (ld)n;
  if(n == 1) ans = 1.0;
  cout << ans << endl;
  return 0;
}


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

ll T[101];

int main() {
    int N, M, P, X;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> T[i];
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> P >> X;
        P--;
        ll ans = 0;
        for (int j = 0; j < N; j++) {
            if (j == P) ans += X;
            else ans += T[j];
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  int X;
  cin >> X;
  if(X>=400 && X<=599) cout << 8 << endl;
  else if(X>=600 && X<=799) cout << 7 << endl;
  else if(X>=800 && X<=999) cout << 6 << endl;
  else if(X>=1000 && X<=1199) cout << 5 << endl;
  else if(X>=1200 && X<=1399) cout << 4 << endl;
  else if(X>=1400 && X<=1599) cout << 3 << endl;
  else if(X>=1600 && X<=1799) cout << 2 << endl;
  else if(X>=1800 && X<=1999) cout << 1 << endl;
}

Measured memory_bytes: 3620
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;
vector<int> rIndex;
vector<int> gIndex;
vector<int> bIndex;


int gcd(int a, int b)
{
	int buffer = a;
	if (b > a)
	{
		a = b;
		b = buffer;
	}

	int remainder = a%b;
	while (remainder != 0)
	{
		a = b;
		b = remainder;
		remainder = a%b;
	}
	return b;
}

int func(int a, int b, int c)
{
	return gcd(gcd(a, b), c);
}

int doSummation(vector<int> a, vector<int> b, vector<int> c)
{
	int ret = 0;
	map<int, int> summation;
	for (auto it = a.begin(); it != a.end(); it++)
	{
		for (auto itB = b.begin(); itB != b.end(); itB++)
		{
			summation[*it + *itB]++;
		}
	}
	for (auto it = c.begin(); it != c.end(); it++)
	{
		auto sum = summation.find(2 * (*it));
		if (sum != summation.end())
			ret += sum->second;
	}

	return ret;
}

int calcDup()
{
	int ret = 0;
	for (auto rIt = rIndex.cbegin(); rIt != rIndex.cend(); rIt++)
	{
		for (auto gIt = gIndex.cbegin(); gIt != gIndex.cend(); gIt++)
		{
			for (auto bIt = bIndex.cbegin(); bIt != bIndex.cend(); bIt++)
			{
				int sum = *rIt + *gIt + *bIt;

				if (3 * *rIt == sum || 3 * *bIt == sum || 3 * *gIt == sum)
					ret++;
			}
		}
	}

	//ret += doSummation(rIndex, gIndex, bIndex);
	//ret += doSummation(gIndex, bIndex, rIndex);
	//ret += doSummation(bIndex, rIndex, gIndex);

	return ret;
}

int main()
{
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++)
	{
		switch (s[i])
		{
		case 'R':
			rIndex.push_back(i);
			break;
		case 'G':
			gIndex.push_back(i);
			break;
		case 'B':
			bIndex.push_back(i);
			break;
		default:
			break;
		}
	}
	long long output = rIndex.size() * gIndex.size() * bIndex.size();
	output -= calcDup();
	cout << output << endl;
    return 0;
}



Measured memory_bytes: 3652
#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(){
  ll N,K; cin >> N >> K;
  ll ans = 1;

  while(N){
    ans++;
    N /= K;
  }
  cout << ans-1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int max = a, min = a;
		for(int i = 0; i < n - 1; i++) {
			a = sc.nextInt();
			if(a > max) max = a;
			else if(a < min) min = a;
		}
		System.out.println(max - min);
	}
}


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

#define MOD_1_000_000_007 (1000000007LL)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, M;

  void init() {
    scanf("%lld %lld", &N, &M);
  }

  void solve() {
    ll ans = 0;
    ans += N*(N-1)/2;
    ans += M*(M-1)/2;
    printf("%lld\n", ans);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

using namespace std;

int main(void) {
  long N, K;
  cin >> N >> K;

  vector<long> vec;

  for (long i = 0; i < N; i++) {
    long tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }

  sort(vec.begin(), vec.end());

  long ans = vec[vec.size() - 1];

  for (long i = 0; i + K <= vec.size(); i++) {
    long tmp = vec[i+K-1] - vec[i];
    if (tmp < ans) ans = tmp;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>

using namespace std;

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

        int res = 0;
        for (int j = 1; j < n; j++) {
            int s = 0;
            for (int k = j; k < n; k++) {
                s += k;
                if (s == n) {
                    res++;
                    break;
                }
            }
        }

        cout << res << endl;
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
vector<pii> num(90001);

int main()
{
    int h, w, d;
    cin >> h >> w >> d;
    rep(i, h)
    {
        rep(j, w)
        {
            int n;
            cin >> n;
            num[n].first = i;
            num[n].second = j;
        }
    }

    int cost[w * h + 1] = {};

    for (int j = d + 1; j <= w * h; j++)
    {
        cost[j] = cost[j - d] + abs(num[j].first - num[j - d].first) + abs(num[j].second - num[j - d].second);
    }

    int q;
    cin >> q;

    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        OP(cost[r] - cost[l]);
    }

    return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>

int main() {
  long i;
  long K;
  char S[100];
  scanf("%s %ld", S, &K);
  for(i = 0;i < K;i++) {
    if(S[i] != '1') {
      printf("%c\n", S[i]);
      return 0;
    }
  }
  puts("1");
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		int N=cin.nextInt();
		int[][]p=new int[N][3];
		for(int i=0;i<N;i++){
			for(int j=0;j<3;j++){
				p[i][j]=cin.nextInt();
			}
		}
		int[] ans=new int[N+1];
		for(int i=0;i<3;i++){
			int[] a=new int[101];
			for(int j=0;j<N;j++){
				int num=p[j][i];
				if(a[num]==0){
					a[num]=j+1;
				}
				else{
					a[num]=-100;
				}
			}
			for(int j=0;j<N;j++){
				if(a[p[j][i]]>0){
					ans[j+1]+=p[j][i];
				}
			}
		}
		for(int i=1;i<=N;i++){
			System.out.println(ans[i]);
		}
	}

}

Measured memory_bytes: 20788
#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
const int mod=1e9+7;
int n,m;
ll jie[100100];
int main()
{
	cin>>n>>m;
	jie[0]=1;
	for(int i=1;i<=max(n,m);i++)
		jie[i]=jie[i-1]*i%mod;
	
	ll ans=0; 
	if(abs(n-m)<=1) ans=(jie[m]*jie[n])%mod*((n==m)+1)%mod;
	printf("%lld",ans);
	return 0;	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, d; cin >> n >> d;
	int x[11][11];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin >> x[i][j];
		}
	}
	int ans = 0;
	int l = 0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=0;k<d;k++){
				l += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			double ll = sqrt(l);
			if(ceil(ll)==floor(ll))ans++;
			l = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define REP(i,a,b) for (ll int i = a; i <b; i++)
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;
    ll int wg;
    cin>>n>>wg;
    ll int wt[n],val[n];
    REP(i,0,n)
        cin>>wt[i]>>val[i];
    ll int K[n+1][wg+1];
    REP(i,0,n+1){ 
       REP(w,0,wg+1){ 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   }
    cout<<K[n][wg]<<"\n";
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<ll> dp(100010, 0);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    set<ll> a;
    for (ll i = 0; i < m; i++)
    {
        int t;
        cin >> t;
        a.insert(t);
    }
    dp[0] = 1;
    dp[1] = 1;
    for (ll i = 2; i <= n; i++)
    {
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        if (a.count(i - 1))
        {
            dp[i] = dp[i] - dp[i - 1] + MOD;
        }
        if (a.count(i - 2))
        {
            dp[i] = (dp[i] - dp[i - 2]) + MOD;
        }
    }
    cout << dp[n] % MOD << endl;
}

Measured memory_bytes: 5760
S = input()


if S[0]=="R":
    if S[1]=="R" and S[2]=="R":
        print(3)
    elif S[1]=="R" and S[2]=="S":
        print(2)
    else:
        print(1)
else:
    if S[1]=="R" and S[2]=="R":
        print(2)
    elif S[1]=="S" and S[2]=="S":
        print(0)
    else:
        print(1)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    return x.first>y.first;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}
int dp[100001];
void solve()
{   
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(auto &it : v)
        cin>>it;
    sort(v.begin(),v.end());
    dp[0]=2;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-v[j]>=0 && dp[i-v[j]]==2){
                dp[i]=1;
                break;
            }
            else if(i-v[j]<0){
                dp[i]=2;
                break;
            }
        }
        if(dp[i]==0) dp[i]=2;

    }
    if(dp[k]==1)
        cout<<"First";
    else 
        cout<<"Second";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public class Node {
		int score;
		int x;
		int y;
		public Node(int score, int x, int y) {
			super();
			this.score = score;
			this.x = x;
			this.y = y;
		}
		
		
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		char[][] s = new char[h][];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().toCharArray();
		}
    	Deque<Node> queue = new ArrayDeque<>();
        queue.add(new Node(1,0,0));
        
        int b = 0;
        Node node; 
        while( (node = queue.poll()) != null ) {
        	int score = node.score;
        	int x = node.x;
        	int y = node.y;
        	if( x<0 || w<=x || y<0 || h<=y )
        		continue;
        	if( s[y][x]!='.')
        		continue;
        	s[y][x] = '/';
        	
            boolean isGoal = x == w-1 && y == h-1;
			if( isGoal ) {
				for (int i = 0; i < h ; i++) {
					for (int j = 0; j < w ; j++) {
						if( s[i][j] != '#' )
							b++;
					}
				}
				System.out.println( b - node.score );
				return ;
            }
			
			// 
	        queue.add(new Node(score+1, x+1, y ));
	        queue.add(new Node(score+1, x-1, y ));
	        queue.add(new Node(score+1, x, y+1 ));
	        queue.add(new Node(score+1, x, y-1 ));

        }

		System.out.println(-1);
	}
	
    
}


Measured memory_bytes: 35768
n, x, y = gets.split.map(&:to_i)

x -= 1
y -= 1

res = Array.new(n) { 0 }

(0...n).each do |i|
   ((i+1)...n).each do |j|
     d = 0
     if i <= x and y <= j
       d = (x - i) + 1 + (j - y)
     elsif i <= x and x < j
       d = (x - i) + [j - x, 1 + (y - j)].min
     elsif i < y and y <= j
       d = (j - y) + [y - i, 1 + (i - x)].min
     elsif x < i and j < y
       d = [j - i, (i - x) + 1 + (y - j)].min
     else
       d = j - i
     end
     
     res[d] += 1
   end
end

res[1...n].each do |x|
  puts x
end

Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
    char a[25]={0};
    int i;
    scanf("%s",a);
    for(i=24;i>=0;i--){
        if(a[i]!=0){
        printf("%c",a[i]);
        }
    }
    printf("\n");
    return 0;
}

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

int main()
{
    int n, d;
    cin >> n >> d;
    int num = 2 * d + 1;
    int ans = (n + num -1)/num;
    cout << ans <<endl; 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, K, X, Y;
	
	cin >> N >> K >> X >> Y;

	int remainder = max(0, N - K);

	int sum = 0;
	if (remainder > 0)
	{
		sum = K * X + (N-K)*Y;
	}
	else
	{
		sum = N * X;
	}

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> P;
 
#define M 1005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt","rt",stdin);
	
	int n,m;
	cin>>n>>m;
	
	lli sum = 0;
	for(int i=0;i<m;i++)
	{
		lli x;
		cin>>x;
		sum += x;
	}
	
	if(sum<=n)
		cout<<n-sum;
	else
		cout<<"-1";
}


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

public class Main
{
    private static final int MAX_N = (int) 1e6 + 16;
    private static int[] number = new int[MAX_N];

    private static int solve(int n)
    {
        Arrays.fill(number, 0);
        number[0] = 1;
        number[1] = 1;
        int count = 0;
        for (int i = 2; i <= n; i++)
        {
            if (number[i] == 0)
            {
                count++;
                for (int j = 2*i; j <= n; j += i)
                {
                    if (j < 0) break;
                    number[j] = 1;
                }
            }
        }
        return count;
    }

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

        while (in.hasNext())
        {
            sb.append(String.format("%d\n", solve(in.nextInt())));
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 30724
from collections import deque

print("Yes")

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

q = deque([0])
b = [0] * n
while q:
    x = q.popleft()
    for i in g[x]:
        if b[i] != 0:
            continue
        b[i] = x + 1
        q.append(i)

print(*b[1:], sep="\n")

Measured memory_bytes: 38464
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(x){
    const a = this.a;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(a[j] <= x)break;
      a[i] = a[j];
    }
    a[i] = x;
  }
  pop(){
    const a = this.a, r = a[0], x = a.pop(), k = a.length >> 1;
    for(var i = 0, j; i < k; i = j){
      j = (i << 1) + 1;
      if(a[j+1] < a[j])j++;
      if(x <= a[j])break;
      a[i] = a[j];
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var a = nexts(n*3);
  var pq = new priorityQueue();
  var lt = Array(3*n+1);
  lt[0] = 0;
  for(var i = 0; i < 2*n; i++){
    lt[i+1] = lt[i]+a[i];
    pq.push(a[i]);
    if(i >= n){
      lt[i+1] -= pq.pop();
    }
  }
  pq = new priorityQueue();
  var rt = Array(3*n+1);
  rt[3*n] = 0;
  for(var i = 3*n-1; i >= n; i--){
    rt[i] = rt[i+1]-a[i];
    pq.push(-a[i]);
    if(i < 2*n){
      rt[i] -= pq.pop();
    }
  }
  var ans = -1e18;
  for(var i = n; i <= 2*n; i++){
    var t = lt[i] + rt[i];
    if(ans < t)ans = t;
  }
  return ans;
}

Measured memory_bytes: 75316
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		String str = in.next();
		Map<String, Integer> map = new HashMap<>();
		for (int i=0; i<str.length(); i++) {
			String sub = str.substring(i,  i+1);
			if (!map.containsKey(sub))
				map.put(sub, 0);
			map.put(sub, map.get(sub)+1);
		}
		
		boolean good = true;
		for (String s: map.keySet()) {
			if (map.get(s) != 2)
				good = false;
		}
		
		System.out.println(good == true ? "Yes" : "No");
		
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 22996