akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint(), K = getint();
	int x[100000];
	rep(i, N) x[i] = getint();

	int saishou = 300000001;
	rep(i, N) {
		if (i + K <= N) {
			int kari = abs(x[i]) + abs(x[i + K - 1] - x[i]);
			saishou = min(kari, saishou);
		}
		if (i - K + 1 >= 0) {
			int kari = abs(x[i]) + abs(x[i - K + 1] - x[i]);
			saishou = min(kari, saishou);
		}
	}
	printf("%d", saishou);

	Would you please return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
      
		int K = sc.nextInt();
		int X = sc.nextInt();
		
		int total = 500*K;
		
		System.out.println(total>=X?"Yes":"No");

	}
}

Measured memory_bytes: 21588
fun main(args: Array<String>) {
  val N = readInt()

  if (N == 0) {
    println(0)
    return
  }

  var result = ""

  var current = N
  while (current != 0) {
    val d = Math.abs(current % 2)
    result += d.toString()
    if (d == 1) current--
    current /= -2
  }

  println(result.reversed())
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int s, w;
    cin >> s >> w;
    cout << (s <= w ? "unsafe" : "safe") << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <math.h>
#define PI 3.141592653589793238462643383279  
using namespace std;

int main() {

  float a,b,h,m;
 cin >> a>>b>>h>>m;

	cout << fixed << setprecision(30)<< sqrt(a*a + b*b - 2*a*b*cos((330*h + 5.5*m)*PI / 180)) << endl;
    
    
   
}


Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
int main(){long long int n,i,a,b,c=0,k=0;
cin>>n;
vector<pair<long long int,long long int>>v;
for(i=0;i<n;i++){
    cin>>a>>b;
    v.push_back(make_pair(b,a));
}
sort(v.begin(),v.end());
for(i=0;i<n;i++){
    c+=v[i].second;
    //cout<<c<<" "<<v[i].first<<endl;;
    if(v[i].first<c){k++;}
}//cout<<k<<endl;
if(k){cout<<"No";}
else{cout<<"Yes";}
    return 0;}

Measured memory_bytes: 6128
#入力
#関数へ
#関数
    #
def a(t,i):
    if i == len(s)-1:
        return sum(map(int,t.split('+')))
    return a(t+s[i+1],i+1) + a(t+'+'+s[i+1],i+1) #関数の中に入れると最後の項でまとめて処理できる
s = input()
print(a(s[0],0))

Measured memory_bytes: 9116
n = int(input())
s = input()
z = ['0','1','2','3','4','5','6','7','8','9']

count = 0
point_i=0

for s_i in z:
    point = point_i
    point_j = n
    for i in range(point,n):
        if s[i]==s_i:
            point_j = i+1
            break
            
    for s_j in z:
        point = point_j
        point_k = n
        for j in range(point,n):
            if s[j]==s_j:
                point_k = j+1
                break
            
        for s_k in z:
            point = point_k
            #point_l = n
            for k in range(point,n):
                if s[k]==s_k:
                    #point = k+1
                    count +=1
                    break
print(count)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long ret = 0;
		if(A==B) System.out.println(A);
		else {
			for(int i=0;i<64;i++) {
				//System.out.println(ad(B+1,i+1));
				//System.out.println(ret);
				if((ad(B+1,i+1)-ad(A,i+1))%2==1){
					ret = ret|((long)1<<i);
				}
			}
			System.out.println(ret);}
	}
	public static long ad(long v,long rank) {
		if(rank==1) return v/2;
		else {
		long u = (long) Math.pow(2,rank);
		return v%u-(u/2)>0? (v/u)*(u/2)+v%u-(u/2) : v/u*(u/2);
		}
	}
}


Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
int dp2csv(const vector<vector<T>> & dp, const string fname);
int range_check(int val, int min, int max) {
	if (val < min) {
		return -1;
	}
	if (val > max) {
		return -1;
	}
	return val;
}
template<class T,class T1>
bool array_find(const T& array, const T1& dst) {
	auto result = find(array.first(), array.end(), dst);
	if (result == array.end()) {
		return false;
	}
	else {
		return true;
	}
}
int main() {
	llong n;
	cin >> n;
	llong ans=0;
	if (n % 2 != 0) {
		cout << 0 << endl;
	}
	else {
		for (int i = 1;; ++i) {
			llong aa = n / (powl(5, i) * 2);
			if (aa > 0) {
				ans += aa;
			}
			else {
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
template<class T>
int dp2csv(const vector<vector<T>> & dp, const string fname) {
	ofstream ofs(fname);
	if (ofs.fail()) { cerr << "cannot open file. :" + fname << endl; return -1; }
	for (auto dp_row : dp) {
		for (auto dp_cell : dp_row) {
			ofs << dp_cell << ",";
		}
		ofs << endl;
	}
	ofs.close();
	return 0;
}


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

typedef long long ll;

string S;
int N;
int C[26];

int main(void) {
	cin >> S;
	N = S.length();

	fill(C, C + 26, 0);
	for (int i = 0; i < N; ++i) {
		int id = (int)(S[i] - 'a');
		++C[id];
	}

	ll cnt = 0;
	for (int i = 0; i < 26; ++i) {
		if (C[i] >= 2)
			cnt += (ll)C[i] * (C[i] - 1) / 2;
	}

	ll ans = (ll)N * (N - 1) / 2 + 1;
	ans -= cnt;

	cout << ans << '\n';
	return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    queue<int> quex;
    queue<int> quey;
    vector<vector<int>> dist(H+2, vector<int>(W+2, -1));
    vector<vector<int>> dist_min(H+2, vector<int>(W+2, 2001));

    vector<int> x_tmp = {-1, 0, 1, 0};
    vector<int> y_tmp = {0, -1, 0, 1};

    vector<vector<bool>> map_bit(H+2, vector<bool>(W+2, false));
    vector<vector<char>> map(H+2, vector<char>(W+2, '#'));
    for(int i=1; i<H+1; i++){
        for(int j=1; j<W+1; j++){
            cin >> map.at(i).at(j);
            if(map.at(i).at(j) == '#') {
                quex.push(j);
                quey.push(i);
                dist.at(i).at(j) = 0;
            }
        }
    }

    int cnt = 0;
    while(!quex.empty() && !quey.empty()){ 
        int x = quex.front();
        int y = quey.front();
        quex.pop();
        quey.pop();
        for(int k=0; k<4; k++){
            if(map.at(y+y_tmp.at(k)).at(x+x_tmp.at(k)) != '#'){
                dist.at(y+y_tmp.at(k)).at(x+x_tmp.at(k)) = dist.at(y).at(x) + 1;
                quex.push(x+x_tmp.at(k));
                quey.push(y+y_tmp.at(k));
                map.at(y+y_tmp.at(k)).at(x+x_tmp.at(k)) = '#';
            } 
        }
    }

    for(int i=1; i<H+1; i++){
        for(int j=1; j<W+1; j++){
            cnt = max(cnt, dist.at(i).at(j));
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 17536
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (i + j <= s && s - i - j <= k) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
}



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

using namespace std;

int main()
{
  int W, H, T, P;
  int mas[50][50] = {{}};


  cin >> W >> H >> T;
  cin >> P;
  for(int i = 0; i < P; i++) {
    int X, Y, T;
    cin >> X >> Y >> T;
    ++mas[X][Y];
  }

  int ret = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      int S;
      cin >> S;
      if(S == 1) ret += mas[j][i];
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 1176
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

class SegTree
{
public:
    SegTree() {}
    ~SegTree() {}
    SegTree(int n_)
    : n((u32)1 << n_), dat(vs32(2 * n - 1, INF))
    {}

    void update(int k, int a)
    {
        k += n - 1;
        dat[k] = a;
        while (k > 0)
        {
            k = (k - 1) / 2;
            dat[k] = MIN(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    // return the minimum value in the range [a, b)
    // set k, l, r = 0, 0, n when you call this function
    int query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l) return INF;

        if (a <= l && r <= b)
        {
            return dat[k];
        }
        else
        {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return MIN(vl, vr);
        }
    }

    static const u32 INF = ((u32)1 << 31) - 1;
    int n;
    vs32 dat;
};

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

    int n, q;
    cin >> n >> q;

    int n_ = 0;
    int temp = n;
    while (temp)
    {
        ++n_;
        temp >>= 1;
    }

    SegTree st(n_);
    n = 1 << n_;

    int c, x, y;
    rep (i, q)
    {
        cin >> c >> x >> y;
        if (c == 0)
        {
            st.update(x, y);
        }
        else
        {
            cout << st.query(x, y + 1, 0, 0, n) << "\n";
        }
    }

    return 0;
}



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

int main()
{	
	int n;
	cin >> n;
	long long a[n + 1],b[n];
	
	for(int i = 0;i < n + 1;i++) scanf("%lld",&a[i]);
	for(int i = 0;i < n;i++) scanf("%lld",&b[i]);
	
	long long sum = 0;
	for(int i = 0;i < n;i++){
		if(b[i] <= a[i]) sum += b[i];
		else if(b[i] <= a[i] + a[i + 1]){
			sum += b[i];
			b[i] -= a[i];
			a[i + 1] -= b[i];
		}
		else{
			sum += a[i] + a[i + 1];
			a[i + 1] = 0;
		}
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(void){
  ll n;
  cin >> n;
  string s[n];
  ll ac=0,wa=0,tl=0,re=0;
  rep(i,n){
    cin >> s[i];
    if(s[i]=="AC")ac++;
    if(s[i]=="WA")wa++;
    if(s[i]=="TLE")tl++;
    if(s[i]=="RE")re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tl << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6728
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	long long H;
	cin >> H;

	if (H == 1) {
		cout << 1 << endl;
		return 0;
	}

	if (H % 2ll == 1){
		--H;
	}

	long long atackCount = 0;
	long long count = 0;
	while (H != 0) {
		atackCount += pow(2ll, count);
		++count;
		H /= 2ll;
	}
	cout << atackCount << endl;
}


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

int main() {
  int X;
  cin >> X;
  
  int happy500, happy5;
  happy500 = X / 500 * 1000;
  happy5 = (X - happy500 / 2) / 5 * 5;
  cout << happy500 + happy5 << endl;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Chars, Usize1};

fn main() {
    input! {
        h: usize,
        w: usize,
        k: i64,
        s: (Usize1, Usize1),
        g: (Usize1, Usize1),
        c: [Chars; h],
    };
    let mut d = vec![vec![None; w]; h];
    let mut q = std::collections::VecDeque::new();
    d[s.0][s.1] = Some(0);
    q.push_back((0, s.0, s.1));
    while let Some((cost, y, x)) = q.pop_front() {
        for &(dy, dx) in [(-1, 0), (0, 1), (1, 0), (0, -1)].iter() {
            for k_i in 1..=k {
                let (ny, nx, ncost) = (
                    dy as i64 * k_i + y as i64,
                    dx as i64 * k_i + x as i64,
                    cost + 1,
                );
                if (0..h as i64).contains(&ny) && (0..w as i64).contains(&nx) {
                    let (ny, nx) = (ny as usize, nx as usize);
                    if c[ny][nx] == '@' {
                        break;
                    }
                    match d[ny][nx] {
                        Some(w_o) if ncost > w_o => break,
                        Some(w_o) if ncost == w_o => continue,
                        None | Some(_) => {
                            d[ny][nx] = Some(ncost);
                            q.push_back((ncost, ny, nx));
                        }
                    }
                }
            }
        }
    }
    println!("{}", d[g.0][g.1].unwrap_or(-1));
}


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


int main(){
	//入力機構
	std::string S,T;
	std::cin>>S>>T;

	//処理機構
	bool ans=true;//falseだと変換不可能
/*
	//S内の同じ文字のある位置全てに対して、Tの同じ位置にある全ての文字が同じ文字であればok
	//その変換ルールのテーブルをsetで作る
	//S,Tの要素数は20000と多いが、英小文字しか要素の候補がないので、setで十分実装可能だろう
	//と思ったけど、アクセスに時間がかかりそうなので、配列を使って実装する
	//std::set<char,char> transTable;
	//このやり方は違う、「c2をc1に置き換える」のルールを無視してしまった
	char transTable[sizeof(char)*256]={};//0は英小文字でないので、初期化はこれでよい。要素が0であれば変換ルールが定義されていない（＝自由に決めて良い）ということである。
	const size_t size=S.size();
	for(size_t i=0;i<size;i++){
		if(transTable[S[i]]==0){
			//まだ変換ルールがない時
			transTable[S[i]]=T[i];//S[i]はT[i]に変換するという変換ルールを定める
		} else{
			//変換ルールがある時
			if(transTable[S[i]]==T[i]){
				//変換ルールに則っている場合は、特に何もしない
			} else{
				//変換ルールに則っている場合は、S->Tの変換は不可能だと判定できる
				ans=false;
				break;
			}

		}
	}
//*/
/*
	//上のやり方において、変換ルール作成の際にT[i]をS[i]に変換するという変換ルールも同時に定めればよい
	//これでもダメ。集合が同じであるかを判定するかをプログラムしないとダメ
	char transTable[sizeof(char)*256]={};//0は英小文字でないので、初期化はこれでよい。要素が0であれば変換ルールが定義されていない（＝自由に決めて良い）ということである。
	const size_t size=S.size();
	for(size_t i=0;i<size;i++){
		if(transTable[S[i]]==0){
			//まだS[i]の変換ルールがない時
			if(transTable[T[i]]==0){
				//T[i]の変換ルールもなければ変換ルールを定めればよい
				transTable[S[i]]=T[i];//S[i]はT[i]に変換するという変換ルールを定める
				transTable[T[i]]=S[i];//T[i]はS[i]に変換するという変換ルールを定める
			} else{
				//T[i]の変換ルールがある場合、S->Tの変換が不可能になる
				ans=false;
				break;
			}
		} else{
			//変換ルールがある時
			if(transTable[S[i]]==T[i]){
				//変換ルールに則っている場合は、特に何もしない
			} else{
				//変換ルールに則っている場合は、S->Tの変換は不可能だと判定できる
				ans=false;
				break;
			}

		}
	}
//*/
	//1番目のやり方でテーブルを作ったあとに、同じ文字に変換する別の文字がないかを判定すればよい
	//テーブル作成
	const size_t tableSize=sizeof(char)*256;
	char transTable[tableSize]={};//0は英小文字でないので、初期化はこれでよい。要素が0であれば変換ルールが定義されていない（＝自由に決めて良い）ということである。
	const size_t size=S.size();
	for(size_t i=0;i<size;i++){
		if(transTable[S[i]]==0){
			//まだ変換ルールがない時
			transTable[S[i]]=T[i];//S[i]はT[i]に変換するという変換ルールを定める
		} else{
			//変換ルールがある時
			if(transTable[S[i]]==T[i]){
				//変換ルールに則っている場合は、特に何もしない
			} else{
				//変換ルールに則っている場合は、S->Tの変換は不可能だと判定できる
				ans=false;
				break;
			}

		}
	}
	//集合が別々であるかを判定
	if(ans){
		for(size_t i=0;i<tableSize;i++){
			if(transTable[i]!=0){
				for(size_t j=i+1;j<tableSize;j++){
					if(transTable[i]==transTable[j]){
						//S[i]->T[i]の変換において、別のS[i]から同一のT[i]に変換するものを見つけたら、変換不可能の判定
						ans=false;
						break;
					}
				}
			}
		}
	}

	//出力機構
	std::cout<<(ans?"Yes":"No")<<std::endl;

	return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int n, s[200] = {}, num[200] = {}, result = 0, lamp = 1, in, ax, h, w, m,a,b,c,r,tmp;
	string str ,str2;
	cin >>str>>str2;
	if (str.length() > str2.length()) { cout << "GREATER"; return 0; }

	if (str.length() < str2.length()) { cout << "LESS"; return 0; }
	for (int i = 0; i < str.length(); i++) {
		if (str[i] > str2[i]) { cout << "GREATER"; return 0; }

		if (str[i] < str2[i]) { cout << "LESS"; return 0; }
	}
	cout << "EQUAL";
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    long long a, b, ans=0;
    cin >> a >> b;
    for(long long i=a;i<=a/4*4+3;i++){
        ans^=i;
    }
    for(long long i=b/4*4;i<=b;i++){
        ans^=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
vl divisor(ll n){
    vl res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            if(i!=n/i)res.pb(n/i);
        }
    }
    return res;
}
int main(){
    ll n,m;
    cin>>n>>m;
    auto vec(divisor(m));
    ll ans=1;
    REP(i,vec.size()){
        if(vec[i]*n<=m&&(m-vec[i]*n)%vec[i]==0){
            chmax(ans,vec[i]);
        }
    }
    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<(n);++i)
const long long INF = 1LL<<60;
const long long mod=1e9+7;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    r = int(input())
    print(r**2)




if __name__ == '__main__':
    main()

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

bool isMM(string s){
    string str = s;
    set<string>st{"01","02","03","04","05","06","07","08","09","10","11","12"};
    auto itr = st.find(str);
    if(itr!=st.end()){
        return true;
    }else{
        return false;
    }
}
int main(){
    string s;
    bool blYYMM;
    bool blMMYY;
    cin >> s;
    blYYMM = isMM(s.substr(2,2));
    blMMYY = isMM(s.substr(0,2));
    if(blYYMM == true && blMMYY == true){
        cout << "AMBIGUOUS" << endl;
    }else if(blYYMM == true && blMMYY == false){
        cout << "YYMM" << endl;
    }else if(blYYMM == false && blMMYY == true){
        cout << "MMYY" << endl;
    }else {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>

using namespace std;

#define INF 1000000007
int n,m;
long long dp[20001][256];
int c[16];
int x[20001];

long long dfs(int k){
  if(k > n){
    long long t = INF;
    for(int i = 0; i < 256; i++){
      t = t > dp[n][i] ? dp[n][i] : t;
    }
    return t;
  }
  for(int i = 0 ; i < 256; i++){
    if(dp[k-1][i] == INF) continue;
    for(int j = 0; j < m ; j++){
      long long t = i + c[j];
      if(t > 255) t = 255;
      if(t < 0) t = 0;
      dp[k][t] = dp[k][t] > dp[k-1][i] + (x[k] - t)*(x[k] - t) ? dp[k-1][i] + (x[k] - t)*(x[k] - t) : dp[k][t];
    }
  }
  return dfs(k+1);
}

int main(){
  while(cin >> n >> m && n != 0){
    for(int i = 0; i < 20001; i++){
      for(int j = 0; j < 256; j++){
        if(i == 0 && j == 128) dp[i][j] = 0;
        else dp[i][j] = INF;
      }
    }
    for(int i = 0; i < m; i++){
      cin >> c[i];
    }
    x[0] = 128;
    for(int i = 0; i < n ; i++){
      cin >> x[i+1];
    }
    cout << dfs(1) << endl;
  }

}



Measured memory_bytes: 43100
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const ll LIMIT = 100000000L;
bool my_greater (int a, int b){return a>b;}
int main (int argc, char *argv[]) {
	int N, get;
	cin >> N;
	for(int z = 0; z < N; ++z) {
		cin >> get;
		vector<int> inc(8), dec(8);
		dec[0] = inc[0] = get % 10;
		for(int i = 1; i < 8; ++i) {
			int sum = 1;
			for(int j = 0; j < i; ++j) sum *= 10;
			inc[i] = dec[i] = get % (sum * 10) / sum;
		}
		sort(inc.begin(), inc.end());
		sort(dec.begin(), dec.end(), my_greater);
		ll isum = 0, dsum = 0, times = 1;
		for(int i = 0; i < 8; ++i) {
			isum += inc[i] * times;
			dsum += dec[i] * times;
			times *= 10;
		}
		cout << isum - dsum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#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};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if (p[i - 1] < p[i] && p[i] < p[i + 1])
        {
            ans++;
        }
        else if (p[i + 1] < p[i] && p[i] < p[i - 1])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cctype>
#include<cstdio>
using namespace std;
#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
char BB[1 << 15],*SS = BB,*TT = BB;
inline int read()
{
	register int x = 0;
	register char ch = getchar();
	for(;!isdigit(ch);ch = getchar());
	for(;isdigit(ch);ch = getchar())
		x = x * 10 + (ch ^ 48);
	return x;
}
inline void print(int x)
{
	char ch = x % 10 + '0';
	if(x > 9)
		print(x / 10);
	putchar(ch);
}

int mod;
inline int add(int a,int b)
{
	a += b;
	return a >= mod ? a - mod : a;
}
inline int qpow(long long a,int b,int p = mod)
{
	register long long ans = 1;
	while(b)
	{
		if(b & 1) ans = ans * a % p;
		a = a * a % p,b >>= 1;
	}
	return ans;
}

const int N = 3010;
int n;
long long s[N][N],c[N][N],ans;

inline void init()
{
	c[0][0] = s[0][0] = 1;
	for(register int i = 1;i <= n + 1;i++)
	{
		c[i][0] = 1;
		for(register int j = 1;j <= i;j++)
			s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod,
			c[i][j] = add(c[i - 1][j - 1],c[i - 1][j]);
	}
}

int main()
{
	n = read(),mod = read();
	init();

	for(register int i = 0;i <= n;i++)
	{
		register long long _2 = qpow(2,n - i);

		long long mul = i & 1 ? mod - 1 : 1,res = 0;
		mul = mul * c[n][i] % mod * qpow(2,qpow(2,n - i,mod - 1)) % mod;

		register long long _2j = 1;
		for(register int j = 0;j <= i;j++)
			res = (res + s[i + 1][j + 1] * _2j) % mod,
			_2j = _2j * _2 % mod;

		ans = (ans + res * mul) % mod;
	}
	print(ans);
}

Measured memory_bytes: 139904
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) {
        cin >> a[i];
    }

    vi vec(26);
    rep(i, h) {
        rep(j, w) {
            vec[a[i][j]-'a']++;
        }
    }

    vi amari(4);
    rep(i, 26) {
        ++amari[vec[i]%4];
    }

    bool flag;

    if(!(1&h) && !(1&w)) {
        if(amari[1] || amari[2] || amari[3]) {
            flag = false;
        } else {
            flag = true;
        }
    } else if((h+w)&1) {
        if(amari[1] || amari[3]) {
            flag = false;
        } else if((h&1) && (w/2&1) == (amari[2]&1)) {
            flag = true;
            if(w/2 < amari[2]) flag = false;
        } else if((w&1) && (h/2&1) == (amari[2]&1)) {
            flag = true;
            if(h/2 < amari[2]) flag = false;
        } else {
            flag = false;
        }
    } else {
        if(amari[3]) {
            flag = false;
        } else if(amari[1] != 1) {
            flag = false;
        } else if(((h-1)/2+(w-1)/2&1) == (amari[2]&1)) {

            flag = true;
        } else {
            flag = false;
        }
    }




    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll D,T,S;cin>>D>>T>>S;
  if(D>T*S)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

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

int main(){
	std::string s;
	std::cin>>s;
	for(int i=0;i<s.size();++i){
		s[i]-=3;
		if(s[i]<'A')s[i]+=26;
	}
	std::cout<<s<<std::endl;
	return 0;
	}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n+1);
    int dp[n+1]={INT_MAX};dp[1]=0;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=2;i<=n;i++){
        dp[i]=INT_MAX;
        for(int j=1;j<=k;j++){
           if(i>j){
               dp[i]=min(dp[i],abs(v[i]-v[i-j])+dp[i-j]);
           }
        }//cout<<dp[i]<<" ";
    }
    cout<<dp[n];
}

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

int main(){
    int k,n;
    cin>>k>>n;
    vector<int>x(n);
    
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int max=0;
    int sub=0;
    for(int i=0;i<n;i++){
        if(i==n-1){
            sub=x[0]-x[i]+k;
        }else{
            sub=x[i+1]-x[i];
        }
        if(sub>max){
            max=sub;
        }
    }
    cout<<k-max;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
long ans,n,a[2<<17],b;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)a[i]-=i+1;
	sort(a,a+n);
	if(n==1)cout<<0<<endl;
	else
	{
		ans=1e15;
		for(int i=n/2-1;i<=n/2;i++)
		{
			long now=0;
			for(int j=0;j<n;j++)now+=abs(a[j]-a[i]);
			ans=min(ans,now);
		}
		cout<<ans<<endl;
	}
}


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

// 入力
int N;
double p[3000];

double dp[3000][3000];

void solve(){
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1.0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			dp[i+1][j+1] += dp[i][j] * p[i];
			dp[i+1][j] += dp[i][j] * (1.0-p[i]);
		}
	}
	double ans = 0.0;
	for(int j = (N+1)/2; j <= N; j++) ans += dp[N][j];
	cout << fixed << setprecision(10) << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++){
    	cin >> p[i];
    }
    solve();
    return 0;
}

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

int main()
{
    int N, M;

    cin >> N >> M;

    //long long int A[N];

    priority_queue<int> q;

    for (int i = 0; i < N; i++)
    {
        int a;
        //cin >> A[i];
        cin >> a;
        q.push(a);
    }

    // no longer use A

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

        // find the max
        int max = q.top();
        q.pop();
        q.push(max / 2);

        // find the max
        /*
        long long int motonemax = 0;
		int motonemaxi;

		for (int j = 0; j < N; j++)
		{
			int motone = A[j];
			if (motone > motonemax)
			{
				motonemax = motone;
				motonemaxi = j;
			}
        }
        */

        // update
        //A[motonemaxi] = A[motonemaxi] / 2;
    }

    long long int ans = 0;

    for (int i = 0; i < N; i++)
    {
        //ans += A[i];
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n,k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];
  ll ans=-INF;

  rep(a,n+1){
    rep(b,n+1){
      if(a+b>n || a+b>k) continue;

      vector<ll> val;
      rep(l,a) val.pb(v[l]);
      rep(l,b) val.pb(v[n-1-l]);
      sort(all(val));

      int l=0;
      for(l=0; l<k-(a+b); l++){
        if(l>=sz(val))break;
        if(val[l]>=0) break;
      }

      ll sum=0;
      for(; l<sz(val); l++){
        sum+=val[l];
      }
      ans=max(sum,ans);
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;
static const int MAX = 2E+5;

int main()
{
    int N;
    ll A[MAX];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    int left = 0, right = 0;
    ll ans = 0, sumXOR = 0;
    while (left < N)
    {
        while (right < N && (sumXOR & A[right]) == 0 )
        {
            sumXOR ^= A[right];
            right++;
        }
        ans += right - left;
        sumXOR ^= A[left];
        left++;
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int N, A, B, sum_all = 0;
  cin >> N >> A >> B;
  for (int i = 1; i <= N; ++i) {
    int sum = 0;
    int tmp = i;
    while (tmp > 0) {
      sum += tmp % 10;
      tmp /= 10;
    }
    if (sum >= A && sum <= B) sum_all += i;
  }
  cout << sum_all << endl;

  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
long long x[200],y[200];
pair<long long,long long> z[1000];
bool BNS(long long a,long long b){
	int left=0,right=n,mid;
	while(true){
		mid=(left+right)/2;
		if(z[mid].first==a&&z[mid].second==b)return true;
		if(left>=right-1)break;
		if(z[mid].first<a||(z[mid].first==a&&z[mid].second<b))left=mid;
		else right=mid;
	}
	return false;
}
int main(){
	while(true){
	cin>>m;
	if(!m)break;
	cin>>x[0]>>y[0];
	for(int i=1;i<m;i++){
		cin>>x[i]>>y[i];
		x[i]-=x[0],y[i]-=y[0];
	}
	cin>>n;
	for(int i=0;i<n;i++)cin>>z[i].first>>z[i].second;
	sort(z,z+n);
	for(int i=0;i<n;i++){
		bool ok=true;
		for(int j=1;j<m;j++)if(!BNS(z[i].first+x[j],z[i].second+y[j]))ok=false;
		if(ok)cout<<z[i].first-x[0]<<" "<<z[i].second-y[0]<<endl;
	}
	}
	return 0;
}

Measured memory_bytes: 3084
#include<cstdio>
#include<cmath>

struct Point {
	double x, y;
};

void koho(int n, Point p1, Point p2) {
	if (n == 0) {
		printf("%.8f %.8f\n", p1.x, p1.y);
		return;
	}

	double th = M_PI * 60.0 / 180.0;
	Point p3, p4, p5;
	p3.x = (2.0 * p1.x + p2.x) / 3;
	p3.y = (2.0 * p1.y + p2.y) / 3;
	p5.x = (p1.x + 2.0 * p2.x) / 3;
	p5.y = (p1.y + 2.0 * p2.y) / 3;
	p4.x = p3.x + (p5.x - p3.x) * cos(th) - (p5.y - p3.y) * sin(th);
	p4.y = p3.y + (p5.x - p3.x) * sin(th) + (p5.y - p3.y) * cos(th);

	koho(n - 1, p1, p3);
	koho(n - 1, p3, p4);
	koho(n - 1, p4, p5);
	koho(n - 1, p5, p2);
}

int main() {
	int n;
	scanf("%d", &n);
	Point s, t;
	s.x = 0;
	s.y = 0;
	t.x = 100;
	t.y = 0;
	koho(n, s, t);
	printf("%.8f %.8f\n", t.x, t.y);
}

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

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

  rep(i,1,n+1) 
  {
    cin>>wt[i]>>v[i];
    z+=v[i];
  }

  int dp[z+1];
  rep(i,0,z+1) dp[i]=INT_MAX;
  dp[0]=0;

  rep(i,1,n+1)
  {
    for(int j=z;j>=v[i];j--)
      dp[j]=min(dp[j],dp[j-v[i]]+wt[i]);
  }

  int ans=0;
  rep(j,0,z+1)
  {
    if(dp[j]<=w)
        ans=max(ans,j);
  }

  cout<<ans;
 



}

Measured memory_bytes: 1024
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

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

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> m >> n;

	fo(i,0,n)
	{
		cin >> a[i];
		a[ i + n] = a[i];
	}
	int ans = 0;
	vi v;
	fo(i,0,2*n-1)
	{
		int d  = ( abs( a[i+1] - a[i] ) );

		if( i == n-1 )
		{
			d = abs( a[i + 1] + m  - a[i] );
		}
		v.pb(d);
	}

	fo(i,0,n-1)
	{
		ans += v[i];
	}
	int nans = ans;
	fo(i,n-1,v.size())
	{
		int id = i - ( n - 1);
		nans -= v[id];
		nans += v[i];
		ans = min( ans , nans );
	}


	cout << ans << endl;


}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

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

using namespace std;

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

typedef long long ll;

int W,H;
int P[100][100];
int DR[] = {1, 0, -1, 0};
int DC[] = {0, 1, 0, -1};

void findFloorRec(int r,int  c, bool visited[100][100], int& xl, int& xr){
  if (visited[r][c]) return;
  visited[r][c] = true;
  for (int i = 0; i < 4; ++i) {
    int nr = r + DR[i];
    int nc = c + DC[i];
    if (nr < 0 || H <= nr || nc < 0 || W <= nc) continue;
    if (P[nr][nc] == P[r][c]) {
      findFloorRec(nr, nc, visited, xl, xr);
    }
  }
  if ((r < H-1 && P[r+1][c] != P[r][c] && P[r+1][c] != 0) || r == H-1) {
    xl = min(c, xl);
    xr = max(c+1, xr);
  }
}

void findFloor(int r, int c, int& xl, int& xr){
  bool visited[100][100] = {};
  findFloorRec(r, c, visited, xl, xr);
}

void findCenterRec(int r, int c, bool visited[100][100], int& count, int& sum){
  if (visited[r][c]) return;
  visited[r][c] = true;
  ++count;
  sum += c;
  for (int i = 0; i < 4; ++i) {
    int nr = r + DR[i];
    int nc = c + DC[i];
    if (nr < 0 || H <= nr || nc < 0 || W <= nc) continue;
    if (P[nr][nc] == P[r][c]) {
      findCenterRec(nr, nc, visited, count, sum);
    }
  }
  if ((r > 0 && P[r-1][c] != P[r][c] && P[r-1][c] != 0)) {
      findCenterRec(r-1, c, visited, count, sum);
  }
}

void findCenter(int r, int c, int& count, int& sum){
  bool visited[100][100] = {};
  findCenterRec(r, c, visited, count, sum);
}

bool solve(){
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (P[i][j] == 0) continue;
      int xl = 100;
      int xr = 0;
      findFloor(i, j, xl, xr);
      int count = 0;
      int sum = 0;
      findCenter(i, j, count, sum);
      //      cout << i << " " << j << " " << xl << " " << xr << " " << count << " " << sum << endl;
      // xl < sum / count + 1/2  < xr
      if (2 * count * xl >= 2 * sum + count) {
	return false;
      }
      if (2 * count * xr <= 2 * sum + count) {
	return false;
      }
    }
  }
  return true;
}

int main(){
  while(true){
    cin >> W >> H;
    if (W == 0) break;
    for (int i = 0; i < H; ++i) {
      string line;
      cin >> line;
      for (int j = 0; j < W; ++j) {
	P[i][j] = line[j] == '.' ? 0 : line[j] - '0';
      }
    }
    cout << (solve() ? "STABLE" : "UNSTABLE") << endl;;
  }
  return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define print(x) cout << (x) << '\n'
#define all(v) (v).begin(), (v).end();
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

const int INF = 1e8;

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

  int H, W; cin >> H >> W;
  string s[H];
  for (int i = 0; i < H; ++i) cin >> s[i];
  
  int dis[H][W];
  for (int i = 0;i < H; ++i){
    for (int j = 0; j < W; ++j) dis[i][j] = INF;
  }


  int sx = 0, sy = 0, gx = H, gy = W;
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  
  queue<pii> q;
  q.push(pii(sx, sy));
  dis[sx][sy] = 0;
  
  while (!q.empty()){
    pii p = q.front();
    q.pop();
    if (p.fi == gx && p.se == gy) break;
    
    for (int i = 0; i < 4; ++i){
      int nx = p.fi+ dx[i], ny = p.se + dy[i];
      if (nx >= 0 && nx < H && ny >= 0 && ny < W && s[nx][ny] == '.' && dis[nx][ny] == INF){
        q.push(pii(nx, ny));
        dis[nx][ny] = dis[p.fi][p.se] + 1;
      }
    }
  }
  
  if (dis[H - 1][W - 1] == INF){
    print(-1); return 0;
  }
  
  int whitesum = 0;
  for (int i = 0; i < H; ++i){
    for (int j = 0; j < W; ++j) {
      whitesum += (s[i][j] == '.');      
    }
  }
  
  print(whitesum - dis[H - 1][W - 1] - 1);
  
  //  print(dis[H - 1][W - 1]);
 
  return 0;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

if M==0:
    if N==3:
        print(100)
        exit(0)
    elif N==2:
        print(10)
        exit(0)        
    elif N==1:
        print(0)
        exit(0)

if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N

for i,j in A:
    ans[i-1]=j

for i in range(len(ans)):
    if ans[i]==None:
        if i==0:
            ans[i]=1
        else:
            ans[i]=0

print(''.join(map(str,ans)))

Measured memory_bytes: 9232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt1 = 0;
		int cnt2 = 0;
		int cnt4 = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 4 == 0) {
				cnt4++;
			} else if (a % 2 == 0) {
				cnt2++;
			} else {
				cnt1++;
			}
		}
		sc.close();

		if (cnt2 == 0) {
			cnt1--;
		}
		if (cnt1 <= cnt4) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 47588
import Control.Applicative

type Row = [Int]

type Rows = [Row]

type Matrix = (Int, Int, Rows)

type Problem = (Matrix, Matrix)

type Result = Rows

access :: Rows -> Int -> Int -> Int

access rows row col
    = rows !! row !! col
    
calcElement :: Matrix -> Matrix -> Int -> Int -> Int

calcElement (_, m, rows1) (_, _, rows2) row col
    = sum [access rows1 row x * access rows2 x col | x <- ms] where
        ms = [0..(m - 1)]

solve :: Problem -> Result

solve (mat1@(n, _, _), mat2@(_, l, _))
    = [[calcElement mat1 mat2 row col | col <- ls] | row <- ns] where
        ns = [0..(n - 1)]
        ls = [0..(l - 1)]

output :: Result -> String

output rows
    = init.concat $ [outputRow row ++ "\n" | row <- rows]
    
outputRow :: Row -> String

outputRow row
    = init.concat $ [show x ++ " " | x <- row]
    
input :: IO Problem

input
    = do
        [n, m, l] <- map read.words <$> getLine
        rows1 <- inputRows n []
        rows2 <- inputRows m []
        return ((n, m, rows1), (m, l, rows2))
        
inputRows :: Int -> Rows -> IO Rows

inputRows 0 rows
    = return rows
    
inputRows n rows
    = do
        row <- map read.words <$> getLine
        inputRows (n - 1) $ rows ++ [row]
    
main :: IO ()

main
    = putStrLn.output =<< solve <$> input

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


int main() {
	int a;
	int b;
	cin >> a >> b;

	int ga=0;
	switch (a) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:case 10:case 12:
		ga = 1;
		break;
	case 4:case 6:case 9:case 11:
		ga = 2;
		break;
	case 2:
		ga = 3;
		break;
	}
	int gb = 0;
	switch (b) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:case 10:case 12:
		gb = 1;
		break;
	case 4:case 6:case 9:case 11:
		gb = 2;
		break;
	case 2:
		gb = 3;
		break;
	}
	if (ga == gb) cout << "Yes";
	else cout << "No";

	return 0;
}

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

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		long n = sc.nextLong();
		long p = sc.nextLong();

		HashMap<Long, Long> insu = new HashMap<Long,Long>();
		long c = 2;
		if(p == 1){
			System.out.println(1);
			return;
		}
		if(n == 1){
			System.out.println((long)p);
			return;
		}

		while(true){				//素因数分解
			if(p < c*c){
				break;
			}

			if(p%c == 0){
				if(insu.get(c) != null){
					long nn = insu.get(c) + 1;
					insu.put(c, nn);
					p /= (long)c;
					c = 2;
				}else{
					long nn = 1;
					insu.put(c, nn);
					p /= (long)c;
					c = 2;
				}
			}else{

				c++;
			}
		}

		if(insu.get(p) != null){
			long nn = insu.get(p) + 1;
			insu.put(p, nn);
		}else{
			long nn = 1;
			insu.put(p, nn);
		}

//		for(long i:insu.keySet()){				//確認
//			System.out.println("素数 "+i + " 数 "+insu.get(i));
//		}		
//		System.out.println();


		//
		//
		//		for(long i:insu.keySet()){				//整理
		//			if(insu.get(i) >= 2*n){
		//				insu.put(i*i, insu.get(i)/2);
		//			}
		//		}

		long setnum = 0;
		for(long i:insu.keySet()){			
			
			setnum++;
		}
		
		

		if(n <= setnum){
			long min = (long)1000000000*1000000;
			long keynum = (long)1;
			for(long i:insu.keySet()){				//数が3つ以上のを見つける
				min = (long)Math.min(min, i);
				if(insu.get(i) >= n){
//					System.out.println((long)Math.pow(i, insu.get(i)/setnum));
					keynum *= (long)Math.pow(i, insu.get(i)/n);
				}
			}

			if(keynum!= 1){
				System.out.println((long)keynum);
			}else{
				System.out.println((long)1);

			}

		}else{
			long min = (long)1000000000*1000000;

			long keynum = (long)1;
			for(long i:insu.keySet()){				//数が3つ以上のを見つける
				min = (long)Math.min(min, i);
				if(insu.get(i) >= n){
					keynum *= (long)Math.pow(i, insu.get(i)/n);
				}
			}

			if(keynum!= 1){
				System.out.println((long)keynum);
			}else{
				System.out.println((long)1);

			}
		}

	}


}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256