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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[]= new int[201];
		for (int i=1;i<200;i++) {
			a[i] ++;
		}
		for (int i=3;i<200;i+=2) {
			for (int j=1;j*i<200;j+=2) {
				a[i*j]++;
			}
		}
		int N =sc.nextInt();
		int count =0;
		for (int i=1;i<=N;i++) {
			if (a[i]==8) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35668
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 + 10, INF = 1e9 * 1000;

vector<vector<ll>> gr;
vector<ll> a[2];

bool used[SIZE];
ll dist[SIZE], lst = 0;

void bfs(int v) {
	for (int i = 0; i < gr.size(); i++) {
		used[i] = 0;
		dist[i] = INF;
	}
	used[v] = 1;

	queue<ll> q;
	q.push(v);
	dist[v] = 0;
	
	while (!q.empty()) {
		ll v = q.front();
		q.pop();

		for (auto to : gr[v]) {
			if (!used[to]) {
				used[to] = 1;
				dist[to] = dist[v] + 1;
				q.push(to);
			}
		}
	}
}

void build_ans(int v, int st, int nd, int i) {
	used[v] = 1;
	if (v == st) {
		a[i].push_back(1);
		lst++;
		build_ans(gr[v][0], st, nd, i);
		
		return;
	}
	if (v == nd) {
		a[i].push_back(lst + 1);
		return;
	}

	ll sz = gr[v].size();
	for (int j = 0; j < sz - 2; j++) {
		a[i].push_back(lst + j + 2);
	}
	a[i].push_back(lst + 1);
	lst = sz + lst - 1;
	for (auto to : gr[v]) {
		if (!used[to] && gr[to].size() != 1 || to == nd) {
			build_ans(to, st, nd, i);
		}
	}
}

int main() {
	fastInp;

	ll n;
	cin >> n;
	gr.resize(n);
	for (int i = 0; i < n - 1; i++) {
		ll u, v;
		cin >> u >> v;
		u--; v--;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}

	for (int i = 0; i < n; i++) {
		ll cnt = 0;
		for (auto to : gr[i]) {
			if (gr[to].size() > 1) cnt++;
		}

		if (cnt > 2) {
			cout << "-1";
			return 0;
		}
	}

	bfs(0);

	pair<ll, ll> d = { -1, -1 };
	for (ll i = 0; i < n; i++) {
		if (make_pair(dist[i], i) > d) {
			d = { dist[i], i };
		}
	}

	ll v = d.second;
	bfs(v);
	d = { -1, -1 };
	for (ll i = 0; i < n; i++) {
		if (make_pair(dist[i], i) > d) {
			d = { dist[i], i };
		}
	}
	ll u = d.second;

	for (int i = 0; i < n; i++) used[i] = 0;
	build_ans(u, u, v, 0);
	lst = 0;
	for (int i = 0; i < n; i++) used[i] = 0;

	build_ans(v, v, u, 1);

	bool fl = true;
	for (int i = 0; i < n; i++) {
		if (a[1][i] < a[0][i]) {
			fl = false;
			break;
		}
		else if (a[0][i] < a[1][i]) {
			break;
		}
	}

	if (fl) {
		for (auto cur : a[0]) cout << cur << " ";
	}
	else {
		for (auto cur : a[1]) cout << cur << " ";
	}

	return 0;
}


Measured memory_bytes: 22776
n = int(input())
cnt = [0]*11000

for x in range(1,101):
    for y in range(1, 101):
        for z in range(1, 101):
            value = x*x + y*y + z*z + x*y + y*z + z*x
            if value <= n:
                cnt[value] += 1

for i in range(1, n+1):
    print(cnt[i])
    

Measured memory_bytes: 9152
function Main(input) {
	input = input.split("\n");
	square = input[0].split(" ");
	del = input[1].split(" ");
	H = parseInt(square[0]);
	W = parseInt(square[1]);
	h = parseInt(del[0]);
	w = parseInt(del[1]);

	console.log((H*W)-(h*W)-(H*w)+(h*w));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

struct P{
  int x,y;
};

int main(){
  P point[100];
  int n;
  int Nari = 1;
  double S;

  while(cin >> n && n){
    for(int i=0;i<n;i++)cin >> point[i].x >> point[i].y;
    point[n].x = point[0].x;
    point[n].y = point[0].y;
    double sum=0;
    for(int i=0;i<n;i++){
      sum+=(point[i].x - point[i+1].x)*(point[i].y+point[i+1].y);
    }
    printf("%d %.1lf\n",Nari,fabs(sum/2.0));
    Nari++;
  }



  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef double ld;
using namespace std;

ld solve(int n, ld d, ld x)
{
	if(n==1) return d*0.5;
	ld sum = d*0.5 + ld(n-1)*0.25*x;
	sum+=solve(n-1,d+((2*d+3*x)/ld(n*2)), x+(ld(4*x)/ld(2*n)));
	return sum;
}

int main()
{
	int n,d,x; cin>>n>>d>>x; cout<<fixed<<setprecision(20)<<solve(n,d+d+x,4.0*x)<<'\n';
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    ll k, n;
    cin >> k >> n;
    vll a(n);
    ll r = 0;
    ll r2 = 10000000;
    
    rep(i, n) cin >> a[i];
    
    rep (i, n) {
        r = a[(n-1+i)%n]-a[i];
        if (r < 0) r += k;
        if (r < r2) r2 = r;
    }
    
    
    cout << r2;

    
    
}

Measured memory_bytes: 4812
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int d = sc.nextInt();
                double e = sc.nextInt();
                if(d+e == 0)break;
                
                double val = e;
                if(d>e)
                	val = d;
                for(int x=0;x<=d;x++) {
                	int y=d-x;
                	if(Math.abs(Math.sqrt(x*x+y*y)-e)<val)
	                		val = Math.min(Math.abs(Math.sqrt(x*x+y*y)-e),val);
                }
                System.out.println(val);
            }
        }
    }
}



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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
    for(int i=0; i<N;i++)
	cin >> v[i];
	int k=0;

  while(true){
      bool exist_odd = false;
  for(int i = 0; i<N ;i++)
    if(v[i]%2 !=0) exist_odd =true;
    if(exist_odd)
      break;
    for(int i=0; i < N; i++){
      v[i] /=2;
    }
    k++;
  }
  cout << k << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define maxn 100005
#define max(a,b) ((a)>(b)?(a):(b))
struct node { int v; node *nxt; } edge[maxn],*head[maxn],*ncnt;
int n,k,a[maxn],dep[maxn],ans;
void addedge(int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
void dfs(int u)
{
	for(node *p=head[u];p;p=p->nxt)
	{
		int v=p->v;
		dfs(v);
		dep[u]=max(dep[u],(dep[v]+1)%k);
		if(u!=1&&dep[v]==k-1) ans++;
	}
}
int main()
{
	ncnt=&edge[0];
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]!=1) a[1]=1,ans++;
	for(int i=2;i<=n;i++) addedge(a[i],i);
	dfs(1);
	printf("%d\n",ans);
}

Measured memory_bytes: 7936
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)

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

int henkan(int a) {
	if (a == 10000) {
		return 199;
	}
	else {
		return (a + 10000) / 100;
	}
}

LL mod = 1000000007;
int main() {

	int n;
	cin >> n;

	if (n <= 100) {
		vector<vector<int>> v(n, vector<int>(2));
		REP(i, n) {
			cin >> v[i][0] >> v[i][1];

		}
		int min = 1000000000;
		REP(i, n) {
			FOR(j, i+1, n) {
				int r = (v[i][0] - v[j][0])*(v[i][0] - v[j][0]) + (v[i][1] - v[j][1])*(v[i][1] - v[j][1]);
				if (r < min) { min = r; }
			}
		}
		cout << min << endl;
	}
	else {

		vector<vector<vector<vector<int>>>> v(200, vector<vector<vector<int>>>(200, vector<vector<int>>(0)));
		REP(i, n) {
			int a, b;
			cin >> a >> b;
			v[henkan(a)][henkan(b)].push_back({ a,b });
		}
		int min = 100000;
		REP(i, 199) {

			REP(j, 199) {
				vector<vector<int>> vv(0);

				vv.insert(vv.end(), v[i][j].begin(), v[i][j].end());
				vv.insert(vv.end(), v[i][j+1].begin(), v[i][j + 1].end());
				vv.insert(vv.end(), v[i + 1][j].begin(), v[i + 1][j].end());
				vv.insert(vv.end(), v[i + 1][j + 1].begin(), v[i + 1][j + 1].end());

				REP(ii, vv.size()) {
					FOR(jj, ii + 1, vv.size()) {
						int r = (vv[ii][0] - vv[jj][0])*(vv[ii][0] - vv[jj][0]) + (vv[ii][1] - vv[jj][1])*(vv[ii][1] - vv[jj][1]);
						if (r < min) { min = r; }
					}
				}
			}
		}
		cout << min << endl;
	}
}

Measured memory_bytes: 35896
import sys

n = int(sys.stdin.readline())
p = [int(sys.stdin.readline()) for i in range(n)]
a = [None] * n
for i in range(n):
    a[p[i]-1] = i
prv = -1
mx = 1
nw = 0
for i in range(n):
    if prv < a[i]:
        nw += 1
        mx = max(mx, nw)
    else:
        nw = 1
    prv = a[i]
print(n-mx)


Measured memory_bytes: 20916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
uint N, K;
uint v[100000 + 10] ;
uint b[100000 + 10] ;
int main () {
  cin >> N >> K;
  for(int i = 0; i < N; ++i) cin >> v[i] >> b[i];
  uint mask = 1U << 31;
  uint rmask = mask - 1;
  uint lmask = ~rmask;
  const uint full = ~(0U);
  ll ret = 0;
  for(int i = 0; i <=32; ++i) {
    if (mask & K) {
      ll cret = 0;
      uint left = (K - mask) & lmask;
      // cout << "left: " << left << endl;
      for(int j = 0; j < N; ++j) {
        uint c = v[j];
        if ((left| (lmask & c)) != left) continue;
        // cout << v[j] << ' ';
        cret += b[j];
      }
      // cout << endl;
      // cout << "cret: " << cret << endl;
      ret = max(ret, cret);
    }
    mask >>= 1;
    rmask >>= 1;
    lmask = ~rmask;
  }

  ll cret = 0;
  for(int j = 0; j < N; ++j) {
    uint c = v[j];
    if ((K | c) != K) continue;
    // cout << v[j] << ' ';
    cret += b[j];
  }
  // cout << endl;
  ret = max(ret, cret);
  cout << ret << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val s = sc.next
    val K = sc.nextInt

    val ss = new mutable.HashSet[String]()

    for (i <- 0 until s.length; j <- i + 1 to Array(i + K, s.length).min) {
      ss += s.substring(i, j)
    }

//    ss.toList.sorted.foreach(println)
    ss.toList.sorted.take(K).last
  }
}


Measured memory_bytes: 33504
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#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() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-1000000001,min=1000000001,sum=0;
    string s,t;
    cin >> n >> m;
    VL a(m);
    VL b(200000);
    vector<bool> ans(m,false);
    rep(i,m){
        cin >> a[i] >> b[i];
	}
    rep(i,m){
        if(a[i] == 1){
            ans[b[i]] = true;
        }
    }
    rep(i,m){
        if(b[i]==n && ans[a[i]]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
   
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 3456
N=int(input())
F=[]
for i in range(N):
    tmp=list(input().split())
    F.append(int(''.join(tmp)))
P=[list(map(int, input().split())) for _ in range(N)]
ans=-float("inf")
for i in range(1,1<<10):
    s=[]
    for j in range(N):
        tmp=str(bin(i & int(str(F[j]), 2)))
        s.append(P[j][sum(list(map(int, list(tmp[2:]))))])
    if ans<sum(s):
        ans=sum(s)
print(ans)


Measured memory_bytes: 3064
s = input()
record = list(s)
n = 0
high_score = 0
yesterday = ' '
for today in record :
    ####### main
    if today == 'R':
        if yesterday == 'R' :
            n += 1
        else :
            n = 1
    ###### ato
    if high_score < n :
        high_score = n
    yesterday = today
print(high_score)


Measured memory_bytes: 8980
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;

  if (x1 == 0) {
    cout << 1 << endl;
  }
  if (x2 == 0) {
    cout << 2 << endl;
  }
  if (x3 == 0) {
    cout << 3 << endl;
  }
  if (x4 == 0) {
    cout << 4 << endl;
  }
  if (x5 == 0) {
    cout << 5 << endl;
  }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

int main(){
	int n;
	cin>>n;
	int a[n];

	int pa,pb;
	bool left=false,right=false;
	for (int i = 0; i < n; ++i){
		cin>>a[i];
	}

	int miss=0;
	for (int i = 0; i < n; ++i){
		if(a[i]!=i+1)miss++;
	}


	if(miss==0||miss==2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}



	


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

int main()
{
    string S;
    cin >> S;
    
    for (int i = 0; i < 4; i++)
    {
        int count = std::count(S.begin(), S.end(), S[i]);
        if (count != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
if N == 1:print(1);exit()
A = [int(hoge) for hoge in input().split()]
ans = 1
cur = A[0]
Decided = A[0] != A[1]
Flat = A[0] == A[1]
Up = A[0] < A[1]

for n in range(1,N):
    if Decided:
        if A[n] == cur:
            continue
        if (A[n]>=cur) == Up:#数列が続く
            cur = A[n]
        else:
            cur = A[n]
            Up = 1 - Up
            Decided = False
            ans += 1
    else:
        if A[n] != cur:
            Up = A[n] > cur
            cur = A[n]
            Decided = True
print(ans) 

Measured memory_bytes: 62704
A, B, C, X, Y = map(int, input().split())
ans = min(X, Y) * min(A + B, 2 * C)
if X > Y:
    ans += (X - Y) * min(A, 2 * C)
else:
    ans += (Y - X) * min(B, 2 * C)
print(ans)

Measured memory_bytes: 3060
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - I hate Matrix Construction
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int BN = 64;

enum { AND0 = 0, AND1 = 1, OR0 = 2, OR1 = 3 };
enum { ND = 2, NG = 3 };

const int qm[4][4] = {
  //           AND0, AND1,  OR0,  OR1
  /* AND0 */ {    0,    1,    0,   ND },
  /* AND1 */ {    1,    1,   NG,    1 },
  /*  OR0 */ {    0,   NG,    0,    0 },
  /*  OR1 */ {   ND,    1,    0,    1 },
};

/* typedef */

typedef unsigned long long ull;

/* global variables */

int ss[MAX_N], ts[MAX_N], sus[MAX_N], tvs[MAX_N];
ull us[MAX_N], vs[MAX_N];
ull fs[MAX_N][MAX_N];
int fbs[MAX_N][MAX_N], hbs[MAX_N][2], vbs[MAX_N][2];

/* subroutines */

inline void setbit(int y, int x, int b) {
  fbs[y][x] = b, hbs[y][b]++, vbs[x][b]++;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", ss + i);
  for (int i = 0; i < n; i++) scanf("%d", ts + i);
  for (int i = 0; i < n; i++) scanf("%llu", us + i);
  for (int i = 0; i < n; i++) scanf("%llu", vs + i);

  for (int k = 0; k < BN; k++) {
    memset(fbs, -1, sizeof(fbs));
    memset(hbs, 0, sizeof(hbs));
    memset(vbs, 0, sizeof(vbs));

    for (int i = 0; i < n; i++) {
      sus[i] = (ss[i] << 1) | (int)((us[i] >> k) & 1);
      tvs[i] = (ts[i] << 1) | (int)((vs[i] >> k) & 1);
    }

    for (int y = 0; y < n; y++)
      for (int x = 0; x < n; x++) {
	int q = qm[sus[y]][tvs[x]];
	if (q == NG) { puts("-1"); return 0; }
	setbit(y, x, (q == ND) ? 0 : q);
      }

    for (int y = 0; y < n; y++)
      if (sus[y] == OR1 && hbs[y][1] == 0) {
	bool ok = false;
	for (int x = 0; ! ok && x < n; x++)
	  if (tvs[x] == AND0 && vbs[x][0] > 1) {
	    setbit(y, x, 1);
	    hbs[y][0]--, vbs[x][0]--;
	    ok = true;
	  }
	if (! ok) { puts("-1"); return 0; }
      }

    for (int x = 0; x < n; x++)
      if (tvs[x] == OR1 && vbs[x][1] == 0) {
	bool ok = false;
	for (int y = 0; ! ok && y < n; y++)
	  if (sus[y] == AND0 && hbs[y][0] > 1) {
	    setbit(y, x, 1);
	    hbs[y][0]--, vbs[x][0]--;
	    ok = true;
	  }
	if (! ok) { puts("-1"); return 0; }
      }

    for (int i = 0; i < n; i++)
      if ((sus[i] == AND0 && hbs[i][0] == 0) ||
	  (sus[i] == AND1 && hbs[i][0] > 0) ||
	  (sus[i] == OR0 && hbs[i][1] > 0) ||
	  (sus[i] == OR1 && hbs[i][1] == 0) ||
	  (tvs[i] == AND0 && vbs[i][0] == 0) ||
	  (tvs[i] == AND1 && vbs[i][0] > 0) ||
	  (tvs[i] == OR0 && vbs[i][1] > 0) ||
	  (tvs[i] == OR1 && vbs[i][1] == 0)) {
	puts("-1");
	return 0;
      }
    
    ull bk = 1ULL << k;
    for (int y = 0; y < n; y++)
      for (int x = 0; x < n; x++)
	if (fbs[y][x]) fs[y][x] |= bk;
  }

  for (int y = 0; y < n; y++) {
    for (int x = 0; x < n; x++) {
      if (x) putchar(' ');
      printf("%llu", fs[y][x]);
    }
    putchar('\n');
  }
  return 0;
}


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

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

    int64_t Lucas_0 = 2, Lucas_1 = 1, Lucas;

    int index = 1;

    while(index != N){
        Lucas = Lucas_1 + Lucas_0;
        Lucas_0 = Lucas_1;
        Lucas_1 = Lucas;
        index++;
    }
  
	if(N == 1) cout << Lucas_1 << endl;
    else cout << Lucas << endl;
}


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

using namespace std;

char s[100010];
int sz, ans[100010];

int main() {
    scanf("%s", s);
    sz = strlen(s);

    int acum = 0;
    for(int i = 0; i < sz; i++) {
        if(s[i] == 'L') {
            ans[i-1] += acum / 2 + (acum % 2);
            ans[i] += acum / 2;
            acum = 0;

            int j = i;
            while(j < sz && s[j] == 'L') {
                acum++;
                j++;
            }

            ans[i] += acum / 2 + (acum % 2);
            ans[i-1] += acum / 2;
            i = j-1;
            acum = 0;
        } else acum++;
    }

    for(int i = 0; i < sz; i++) printf("%d ", ans[i]);
    return 0;
}


Measured memory_bytes: 896
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
const int maxn = 1000;
int a[maxn];


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    long long  ans =0;
    if(n==1 && a== b) ans =1;
    else if(a <= b && n > 1){
        int cnt = n-2;
        long long  minLen=a+b;
        long long  maxLen=a+b;
        for(int i=0; i<cnt; i++){
            minLen += a;
            maxLen += b;
        }
        ans = maxLen - minLen + 1;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 256
from functools import reduce
N,M= map(int,input().split())
a = list(map(int,input().split()))

b = [i//2 for i in a]

t = b[0]
while t & 1 == 0:
    t //= 2
p2 = b[0]//t

odds = [1]*N
for i, n in enumerate(b):
    if n % p2 != 0 or (n//p2 & 1) == 0:
        print(0)
        exit()
    odds[i] = n//p2
def gcd(a,b):
    while b:
        a,b = b, a%b
    return a
def lcm(a,b):
    return a*b // gcd(a,b)
l = reduce(lcm,odds)

M = M//p2
print((M//l-1)//2 + 1)


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

using namespace std;

int main() {

    int D, G;
    cin >> D >> G;

    int p[11], c[11];
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;

    for(int mask = 0; mask < (1 << D); mask++) {
        int s = 0, num = 0, rest_max = -1;

        for(int i = 0; i < D; i++) {

            if(mask & 1 << i) {
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];

            } else {
                rest_max = i;
            }
        }

        if(s < G) {
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]) {
                continue;
            }
            num += need;
        }

        ans = min(ans, num);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
l = deque(map(int, input().split()))

while len(l) > 1:
  key = min(l)
  for i in range(len(l)):
    j = l.popleft()
    sup = j % key
    if sup > 0:
      l.append(sup)
  l.append(key)

print(l[0] if len(l) == 1 else 0)

Measured memory_bytes: 14636
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

int main() 
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i]; 
  vector<int> rev(N);
  for (int i = 0; i < N; i++) rev[A[i] - 1] = i + 1;
  for (int i = 0; i < N; i++) cout << rev[i] << endl;

}


Measured memory_bytes: 1664
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        long[] l = new long[2];
        l[0] = sc.nextLong();
        l[1] = sc.nextLong();
        long ans =  l[0] * l[1];
        long[] s = new long[3];
        for (int i = 0; i < 2; i++) {
            for (int j = 1; j <= l[i]; j++) {
                s[0]=(long)j*l[abs(1-i)];
                s[1]=(l[i]-(long)j)/2*l[abs(1-i)];
                s[2]=l[0]*l[1]-s[0]-s[1];
                Arrays.sort(s);
                ans=min(ans,s[2]-s[0]);
                s[0]=(long)j*l[abs(1-i)];
                s[1]=l[abs(1-i)]/2*(l[i]-(long)j);
                s[2]=l[0]*l[1]-s[0]-s[1];
                Arrays.sort(s);
                ans=min(s[2]-s[0],ans);
            }
        }
        out.println(ans);
    }
}


Measured memory_bytes: 23124
N, W = map(int, input().split())
wv = []
for _ in range(N):
    w, v = map(int, input().split())
    wv.append((w, v))
memo = [{} for _ in range(N + 1)]


def f(i, j):
    if 0 >= i or 0 >= j:
        return 0
    if j in memo[i]:
        return memo[i][j]
    w, v = wv[i - 1]
    t = f(i - 1, j)
    if j - w >= 0:
        t = max(t, f(i - 1, j - w) + v)
    memo[i][j] = t
    return t


def main():
    print(f(N, W))


main()


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

const int N = 2e5 + 5;

int n, m;
vector<int> adj[N];
vector<int> dist(N, -1), par(N, -1);

void bfs(int s) {
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    
    while(!q.empty()) {
        int v = q.front();
        q.pop();

        for(auto u : adj[v]) {
            if(dist[u] == -1) {
                par[u] = v;
                dist[u] = 1 + dist[v];
                q.push(u);
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        cin >> n >> m;
        while(m--) {
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        
        bfs(1);

        cout << "Yes\n";
        for(int i = 2; i <= n; i++)
            cout << par[i] << '\n';
    }
    
    return 0;
}



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

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

        public void Solve(ConsoleInput cin)
        {
            int a = cin.ReadInt;
            int b = cin.ReadInt;
            int c = cin.ReadInt;
            int x = cin.ReadInt;
            int y = cin.ReadInt;

            int min = -1;
            for(int i = 0; i <= 100000; i++)
            {
                if (min > 2 * c * i + a* Max(0, x - i) + b*Max(0, y - i) || min == -1)
                    min = 2 * c * i + a*Max(0, x - i) + b*Max(0, y - i);
            }

            Console.WriteLine(min);
        }
    }

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

Measured memory_bytes: 11220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.StringTokenizer;


public class Main {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);


    public static int solve(String s) {
        if (s.contains("R")) {
            if (s.charAt(0) == 'R' && s.charAt(1) == 'R' && s.charAt(2) == 'R') {
                return 3;
            } else if (s.charAt(0) == 'R' && s.charAt(1) == 'R' ||
                    s.charAt(1) == 'R' && s.charAt(2) == 'R') {
                return 2;
            } else {
                return 1;
            }
        }
        return 0;

    }

    public static void main(String[] args) {

        out.println(solve(in.next()));

        out.flush();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }


        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

    }


}


Measured memory_bytes: 32564
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 100000;

int n, h;
int a, b;
int ans = 0;

int max_a = 0;
priority_queue<int> que_b;

int main() {
  cin >> n >> h;
  REP(i, n) {
    cin >> a >> b;
    max_a = max(max_a, a);
    que_b.push(b);
  }

  while (h > 0) {
    if (que_b.empty() || max_a >= que_b.top()) {
      int quo = (h+max_a-1) / max_a;
      h -= max_a*quo;
      ans += quo;
    } else {
      h -= que_b.top();
      que_b.pop();
      ++ans;
    }
  }

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


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

using namespace std;
typedef long long int ll;
ll MOD = 1000000007;

int main() {
    long long A, B, X;
    cin >> X;
    for (A = -118; A <= 119; A++) {
        for (B = -119; B <= 118; B++) {
            if (A * A * A * A * A - B * B * B * B * B == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#define MN 50
#define mod 1000000007	
using namespace std;
int n,f[MN+5][MN+5][MN+5],p[MN+5],inv[MN+5],ans;
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
int main()
{
	scanf("%d",&n);p[0]=inv[0]=p[1]=inv[1]=1;
	for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod; 
	for(int i=2;i<=n;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
	f[1][0][1]=p[n];
	for(int i=1;i<=n;++i) for(int j=0;j<=i;++j) for(int k=0;j+k<=i;++k) if(f[i][j][k])
	{
		for(int l=i+2;l<=n;l+=2) R(f[l][(l-i)/2][(l-i)/2],1LL*f[i][j][k]*inv[j]%mod*inv[k]%mod);
		for(int x=1;x<=j;++x)
			for(int l=i+x;l<=n;l+=2)
				R(f[l][x+(l-i-x)/2][(l-i-x)/2],1LL*f[i][j][k]*inv[j-x]%mod*inv[k+x]%mod);
		for(int x=1;x<=k;++x)
			for(int l=i+x;l<=n;l+=2)
				R(f[l][(l-i-x)/2][x+(l-i-x)/2],1LL*f[i][j][k]*inv[j+x]%mod*inv[k-x]%mod);
	}
	for(int i=0;i<=n;++i) for(int j=0;j<=n;++j)R(ans,1LL*f[n][i][j]*inv[i]%mod*inv[j]%mod);
	printf("%d",ans);
	return 0;
}



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

using namespace std;


int main()
{
  static int INF = 1000000000;
  int N;
  cin >> N;
  vector <int> h(N);
  vector <int> dp(N, INF);
  for( int i=0;i<N;i++ )
    cin >> h[i];

  dp[0] = 0;
  for( int i=1;i<N;i++ )
    {
      if( i-1>=0 )
	dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i]);
      if( i-2>=0 )
	dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i]);
    }

  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],sum,ans,n,k,b[maxn];

inline bool jud(int x)
{
	for(int i=1;i<=n;i++) b[i]=a[i]%x;
	sort(b+1,b+n+1);
	int l=1,r=n,nl=0,nr=0;
	while(nl<=k) {nl+=b[l]; l++;} l--;
	while(nr<=k) {nr+=(x-b[r]); r--;} r++;
	if(l>=r) return true; return false;
}

int main()
{
	n=read(); k=read(); ans=1;
	for(int i=1;i<=n;i++) a[i]=read(),sum+=a[i];
	for(int i=2;i*i<=sum;i++)
	{
		if(sum%i==0)
		{
			if(jud(i)) ans=max(ans,i);
			if(jud(sum/i)) ans=max(ans,sum/i);
		}
	}
	if(jud(sum)) ans=max(ans,sum);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
N = int(input())
voteString = {}
count = 0
highList = []

for i in range(N):
  
  string = input()
  
  if string in voteString: 
    voteString[string] += 1
  else:
    voteString[string] = 1

for key in voteString:
  count = max(voteString[key], count)
  
for key in voteString:
  if voteString[key] == count:
    highList.append(key)

highList.sort()

for element in highList:
  print(element)

#print(voteString)



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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
ll x[e5];
ll y[e5];
unordered_map<ll,vl> x_map,y_map;
graph g;
set<ll> x_set,y_set;
ll cnt;
ll vis[e5];
ll ans;

void dfs(ll p){
  vis[p] = 1;
  cnt++;
  x_set.insert(x[p]);
  y_set.insert(y[p]);
  for(auto q : g[p]){
    if(vis[q.first] == 0) dfs(q.first);
  }
}

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> x[i] >> y[i];
  for(ll i = 0;i < n;i++){
    if(x_map[x[i]].size() > 0){
      g[x_map[x[i]][0]][i] = 1;
      g[i][x_map[x[i]][0]] = 1;
    }
    if(y_map[y[i]].size() > 0){
      g[y_map[y[i]][0]][i] = 1;
      g[i][y_map[y[i]][0]] = 1;
    }
    x_map[x[i]].push_back(i);
    y_map[y[i]].push_back(i);
  }
  for(ll i = 0;i < n;i++){
    if(vis[i] == 0){
      x_set = set<ll>();
      y_set = set<ll>();
      cnt = 0;
      dfs(i);
      ans += x_set.size()*y_set.size()-cnt;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 41404
import java.util.Scanner;

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

	String n = scan.next();

	String ans = "";
	for(int i = 0; i < 3; i++){	    
	    if(n.charAt(i) == '9'){
		ans += "1";
	    }else{
		ans += "9";
	    }
	}

	System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a, b, c, d;

signed main() {
	cin >> n >> a >> b >> c >> d;
	n--;
	b = abs(b - a);
	int x = (d - c) * n + 1;
	int y = c + d - x;
	int z = d * n;
	if (z < b) {
		cout << "NO" << endl;
		return 0;
	}
	if (y <= 0) {
		cout << "YES" << endl;
		return 0;
	}
	int cnt = (z - b + 1) % (x + y);
	if (cnt <= x && 0 < cnt)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if nowmax-nowmin<num and nowmax%num>=nowmin%num and not(nowmax%num==0 or nowmin%num==0):
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(((nowmin-1)//num)+1)*num
print(nowmin,nowmax)

Measured memory_bytes: 14224
#include <iostream>
//#include <iomanip>
 
using namespace std;
//#define
 
int main() {
    int h, w;
 
    while(1){
        cin >> h >> w;
        if(h==0 && w==0) break;
 
        for(int i=0;i<h;i++){
            for(int k=0;k<w;k++){
                cout << '#';
            }
            cout << "\n";
        }
        cout << "\n";
    }
    return 0;
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> vec(Q);
  vector<int> count(N,0);
  for(int i = 0; i < Q; i++){
    cin >> vec[i];
  }
  for(int i = 0; i < Q; i++){
    count[vec[i]-1] ++;
  }
  for(int i = 0; i < N; i++){
    if(Q - count[i] < K){
      cout << "Yes" <<endl;
    }
    else{
      cout << "No" <<endl;
    }
  }  
}


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

int main() {
    int n;
    cin >> n;
    vector<int> v;
    rep(i,n) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    
    int min_cost = 200 * 200 * 101;
    for (int i = -100; i < 101; i++) {
        int cost = 0;
        for (int j : v) {
            cost += (i-j)*(i-j);
        }
        min_cost = min(cost, min_cost);
    }
    cout << min_cost << endl;
}

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

int n,k,m;
int ans=0;
vector<int>s(10);

void bfs(int nn,int sum,int min){
    
    if(nn==0&&sum==0){
        ans++;
        return;
    }
    
    for(int i=min;i<10&&n>0;i++){
        if(sum-i>=0){
            bfs(nn-1,sum-i,i+1);
        }
    }
    
}

int main(){
    while(cin>>n>>m){
        if(n==0 && m==0)break;
        bfs(n,m,0);
        cout<<ans<<endl;
        ans=0;
        
    
    }
    return 0;
}


Measured memory_bytes: 3076
#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 H,W;
char s[50][50];
int cnt[50][50];
int dx[4]={ 0, 1, 0,-1};
int dy[4]={ 1, 0,-1, 0};

void dfs(int x, int y){
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i], ny = y + dy[i];
    if(nx<0 || nx>W-1 || ny<0 || ny>H-1) continue;
    if(s[ny][nx]=='.' && cnt[ny][nx]>cnt[y][x]+1){
      cnt[ny][nx] = cnt[y][x]+1;
      dfs(nx, ny);
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> H >> W;
  int wht = 0;
  REP(h,H) REP(w,W){
    cin >> s[h][w];
  	if(s[h][w]=='.') wht++;
    cnt[h][w] = H*W;
  }
  cnt[0][0] = 1;
  dfs(0,0);
  
  cout << (cnt[H-1][W-1]<H*W ? wht-cnt[H-1][W-1] : -1) << endl;
  return 0;
}


Measured memory_bytes: 384
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
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};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << 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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin>>a;
    if(a>=30)yes;
    else no;
}


Measured memory_bytes: 3548
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> array(n,0);
    rep(i,k)
    {
        int d;
        cin>>d;
        rep(j,d)
        {
            int a;
            cin>>a;
            array[a-1]++;
        }
    }
    int cnt=0;
    rep(i,array.size())
    {
        if(array[i]==0)cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
#define MAXN 100101
#define MAXP 101
int c[MAXN][MAXP];
void init()
{
    REPS(i, MAXN - 1)
    {
        c[i][0] = 1;
    }
    c[1][1] = 1;
    FORS(i, 2, MAXN - 1)
    {
        REPS(j, MAXP - 1)
        {
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
            //6 2,5 2,5 1
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    init();

    int tmpM = M;
    vector<int> res;
    FORS(i, 2, sqrt(M))
    {
        int count = 0;
        while (tmpM % i == 0)
        {
            count++;
            tmpM /= i;
        }
        if (count > 0)
        {
            res.push_back(count);
        }
    }
    if (tmpM != 1)
        res.push_back(1);

    lli ans = 1;
    for (auto v : res)
    {

        ans *= c[v + N - 1][v];
        ans %= MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 39808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

string S;
int main()
{
    cin >> S;
    int count = 0;
    for(int i = 0;i < 3;i++)
    {
        if(S[i] == '1') count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,*t=map(int,open(0).read().split())\n"
"c=f=0\n"
"for b,a in sorted(zip(t[1::2],t[::2])):c+=a;f|=c>b\n"
"print('YNeos'[f::2])\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 48944
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,n,k,x,y,ans=0;
    cin>>n>>k>>x>>y;
    for(i=1; i<=n; i++){
        if(i<=k){
            ans+=x;
        }else{
            ans+=y;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N, M;
ll dp[2][3010][2];

inline void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; }

int main() {
	cin >> N >> M;
	dp[0][0][1] = 1;

	for (int i = 1; i <= N; ++i) {
		dp[0][i][0] = 1;
	}

	int c = 0, f = 1;

	rep(i, M) {
		memset(dp[f], 0, sizeof(dp[f]));

		for (int j = 0; j <= N; ++j) {
			rep(k, 2) {
				if (j) {
					bool t = (k | ((j - 1) == 0));
					add(dp[f][j-1][t], dp[c][j][k]);
					add(dp[f][j][t], dp[c][j][k]);
				}

				if (j < N) {
					add(dp[f][j+1][k], dp[c][j][k]);
					add(dp[f][j][k], dp[c][j][k]);				
				}
			}
		}
		swap(c, f);
	}

	ll ret = 0;
	for (int j = 0; j <= N; ++j) {
		add(ret, dp[c][j][1]);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 5;
class node {
public:
    int u, v, w;
    node(int a, int b, int c) :u(a), v(b), w(c) {};
};
int fa[maxn];
int getf(int i) { return i == fa[i] ? i : fa[i] = getf(fa[i]); }
vector<node>edge;
bool cmp(const node&a, const node&b){return a.w < b.w;}
class T {
public:
    int value, id;
    bool operator<(const T &a){return value < a.value;}
};
T sx[maxn], sy[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i, j, k, m, n, ta, tb;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        fa[i] = i;
    for (int i = 1; i <= n; ++i)
    {
        cin >> sx[i].value >> sy[i].value;
        sx[i].id = sy[i].id = i;
    }
    sort(sx + 1, sx + n + 1);
    sort(sy + 1, sy + 1 + n);
    for (int i = 1; i < n; ++i)
    {
        edge.push_back(node(sx[i].id, sx[i + 1].id, sx[i+1].value - sx[i].value));
        edge.push_back(node(sy[i].id, sy[i + 1].id, sy[i+1].value - sy[i].value));
    }
    sort(all(edge), cmp);
    ll ans = 0;
    for (int i = 0; i <edge.size(); ++i)
    {
        if (getf(edge[i].u) != getf(edge[i].v))
        {
           ans += edge[i].w;
           fa[getf(edge[i].u)] = getf(edge[i].v);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6900