akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;

int max(int a, int b){
    return a>b ? a : b;
}

int main(void){
    
    int A, B;
    cin >> A >> B;
    
    int ans = max(A-2*B, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,k,hang,lie,sum=0,count=0;
	cin>>n>>m>>k;
	char a[n][m];
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	cin>>a[i][j];
	for(hang=0;hang<(1<<n);hang++)
	{
		for(lie=0;lie<(1<<m);lie++)
		{
				for(int i=0;i<n;i++)
            	for(int j=0;j<m;j++)
             	{
             		if(((hang>>i)&1)&&((lie>>j)&1)&&a[i][j]=='#')
             		count++;
				}
				if(count==k)
				sum++;
				count=0;
		}
	}
	cout<<sum;
	
}


Measured memory_bytes: 3624
#--ROT N

alphabet_1 = [chr(ord('A') + i) for i in range(26)]
alphabet_2 = [chr(ord('A') + i) for i in range(26)]

alphabet = alphabet_1 + alphabet_2

N = int(input())
S = list(input())

count = len(S)

ans = " "
for i in range(count):
  number = int(alphabet.index(S[i]))
  ans = ans + alphabet[number+N]

print(ans)


Measured memory_bytes: 3060
using System;

class Program
{
	static void Main(string[] args)
	{
		string[] nums = Console.ReadLine().Split(' ');
		int a = int.Parse(nums[0]);
		int b = int.Parse(nums[1]);
		int c = int.Parse(nums[2]);

		int temp = 0;
		// ??\??????????????§??????????????????????????£?????????. 
		if (a > b)
		{
			temp = b; b = a; a = temp;
		}
		if (b > c)
		{
			temp = c; c = b; b = temp;
		}
		if (a > c)
		{
			temp = a; a = c; c = temp;
		}
		if (a > b)
		{
			temp = b; b = a; a = temp;
		}
		Console.WriteLine(a + " " + b + " " + c);
	}
}

	

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

int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << ' ' << X <<  ' ' << Y << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;

ll gcd (ll a, ll b){ return b == 0? a : gcd(b, a % b); }

void add_edge(vector<vll> &G, ll u, ll v){
    G[u].push_back(v); G[v].push_back(u);
}

bool dfs(vector<vll> &G, vb &checked, vll &match, ll v){
    //* match is initialized -1 outside
    checked[v] = true;
    REP(i, G[v].size()){
        ll u = G[v][i], w = match[u];
        if(w < 0 || !checked[w] && dfs(G, checked, match, w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

ll BipartiteMatching(vector<vll> &G){
    ll N = G.size();
    vb checked(N, false);
    vll match(N, -1);
    ll res = 0;
    REP(v, N){
        if(match[v] < 0){
            fill(ALL(checked), false);
            if(dfs(G, checked, match, v)){
                res++;
            }
        }
    }
    return res;
}

int main(){
    while(1){
        ll M, N; cin >> M >> N;
        if(M == 0 && N == 0)
            break;

        vll b(M), r(N);
        REP(i, M) cin >>b[i];
        REP(j, N) cin >>r[j];
        vector<vll> G(M+N);
        REP(i, M){
            REP(j, N){
                if(gcd(b[i], r[j]) > 1){
                    add_edge(G, i, j+M);
                }
            }
        }
        ll m = 0; 
        m = BipartiteMatching(G);
        cout << m << endl;
    }
    
    return 0;
}


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

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

using namespace std;

int main() {
  int score[6];
  rep(i,6) cin >> score[i];
  sort(score,score+4,greater<int>());
  sort(score+4,score+6,greater<int>());
  cout << score[0] + score[1] + score[2] + score[4] << endl;
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
#include <stdlib.h>
#include <bits/stdc++.h>

using namespace std;

int main() {

  int n,k,ans=0;
  vector<int> d(100,0),tmp(100,0);
  vector<vector<int>> A(100, vector<int>(100));
  
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>d[i];
    for(int j=0;j<d[i];j++){
      cin>>A.at(i).at(j);
      if(A.at(i).at(j)!=tmp[A.at(i).at(j)]){
        tmp[A.at(i).at(j)]=A.at(i).at(j);
		ans++;
      }
    }
  }
  
  cout<<n-ans<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MAXM = 4e6 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
bitset <MAXM> dp;
int main() {
	read(n);
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		sum += a[i];
	}
	dp.set(0);
	for (int i = 1; i <= n; i++)
		dp |= (dp << a[i]);
	for (int i = (sum + 1) / 2; i <= sum; i++)
		if (dp[i]) {
			writeln(i);
			return 0;
		}
	assert(false);
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, s, g1, g2;
int matrix[110][110];

int main() {
  while (scanf("%d %d %d %d %d", &n, &m, &s, &g1, &g2), n) {
    MEMSET(matrix, 0x0f);
    s--; g1--; g2--;
    REP(i, m) {
      int f, t, c;
      scanf("%d %d %d", &f, &t, &c);
      f--; t--;
      matrix[f][t] = c;
      //matrix[t][f] = c;
    }
    REP(k, n) REP(i, n) REP(j, n) {
      matrix[i][i] = 0;
      matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k][j]);
    }
    int ans = 1 << 30;
    REP(i, n) {
      ans = min(ans, matrix[s][i] + matrix[i][g1] + matrix[i][g2]);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 924
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim Semenov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ReplacingInteger solver = new ReplacingInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static final class ReplacingInteger {
        public void solve(int __, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            if (n < k) {
                out.println(Math.min(n, k - n));
            } else {
                final long mod = n % k;
                out.println(Math.min(mod, k - mod));
            }
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <functional>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int a, b, x;
string s, t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a >> b >>x;
    if(a+b>=x&&a<=x) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int n; cin >> n;
    int maximum = 0, minimum = 1e9;

    REPI(i, n){
        int x; cin >> x;
        maximum = max(maximum, x);
        minimum = min(minimum, x);
    }
    cout << maximum - minimum;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int digit_cnt(int N){
  if (N == 0) return 1;
  else{
    int ans = 0;
    while (N > 0){
      ans++; N /= 10;
    }
    return ans;
  }
}

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

  int s[M], c[M];
  for (int i = 0; i < M; i++){
    cin >> s[i] >> c[i];
    s[i] = N - s[i];
  }
  

  for (int i = 0; i < 1000; i++){
    if (digit_cnt(i) != N) continue;

    bool flag = true;
    for (int j = 0; j < M; j++){
      int dig = i;
      for (int k = 0; k < s[j]; k++){
        dig /= 10;
      }
      if (dig % 10 != c[j]) flag = false;
    }
    
    if (flag == true){
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;

  

  return 0;
}


Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

bool isPrime(int n) {
    bool ok = true;
    for(int i = 2; i * i <= n; i++) {
        if(n%i==0) ok = false;
    }
    return ok;
}
int main() {
    int N; cin >> N;
    int ans = 0;
    REP(i,N) {
        int p; cin >> p;
        if(isPrime(p)) ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3088
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	xLow := float64(n) / 1.08
	xHigh := float64(n+1) / 1.08
	if math.Trunc(xLow) == xLow {
		fmt.Printf("%d\n", int(xLow))
	} else if math.Trunc(xHigh) != xHigh && math.Trunc(xLow) < math.Trunc(xHigh) {
		fmt.Printf("%d\n", int(math.Trunc(xHigh)))
	} else {
		fmt.Println(":(")
	}

}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

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

	//n := nextInt()
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	easts, wests := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			if i == 0 {
				easts[i] = 1
			} else {
				easts[i] = easts[i-1]+1
				wests[i] = wests[i-1]
			}
		} else {
			if i == 0 {
				wests[i] = 1
			} else {
				wests[i] = wests[i-1]+1
				easts[i] = easts[i-1]
			}
		}
	}

	min := 300000
	for i := 0; i < n; i++ {
		// 右にいるeastの数
		rightEast := easts[n-1] - easts[i]
		leftWest := 0
		if i != 0 {
			leftWest = wests[i-1]
		}
		if min > rightEast + leftWest {
			min = rightEast + leftWest
		}
	}

	fmt.Println(min)
}

Measured memory_bytes: 7296
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
 
string s;
ll roc = 0;
map<char, ll> m1;
map<pair<char, ll>, ll> m2;
 
ll exp();
bool decass();
 
ll exp() {
    if(s[roc] >= '0' && s[roc] <= '9') {
        ll roc_buf = roc;
        while(s[roc] >= '0' && s[roc] <= '9') ++roc;
        ll num = stoi(s.substr(roc_buf, roc - roc_buf));
        return num;
    } else {
        char name = s[roc];
        ll size = m1[name];
        ++roc;
        ++roc;
        ll num = exp();
        ++roc;
        if(num == INF * INF) return INF * INF;
        if(num >= size || size < 0) return INF * INF;
        if(m2.count(pair<char, ll>(name, num)) == 0) return INF * INF;
        else return m2[pair<char, ll>(name, num)];
    }
}
 
bool decass() {
    if(m1.count(s[roc]) == 0) {
        char name = s[roc];
        ++roc;
        ++roc;
        ll roc_buf = roc;
        while(s[roc] >= '0' && s[roc] <= '9') ++roc;
        ll num = stoi(s.substr(roc_buf, roc - roc_buf));
        m1[name] = num;
        return true;
    } else {
        char name = s[roc];
        ll size = m1[name];
        ++roc;
        ++roc;
        ll index = exp();
        if(index == INF * INF) return false;
        if(index >= size || index < 0) return false;
        ++roc;
        ++roc;
        ll num = exp();
        if(num == INF * INF) return false;
        m2[pair<char, ll>(name, index)] = num;
        return true;
    }
}
 
int main(void) {
    while(true) {
        ll cnt = 0;
        ll res = 0;
        m1.erase(ALL(m1));
        m2.erase(ALL(m2));
        while(true) {
            cin>>s;
            roc = 0;
            if(s == ".") break;
            if(res == 0 && !decass()) res = cnt + 1;
            ++cnt;
        }
        if(cnt == 0) break;
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a;
    cin >> a;
    cout << a*32 << "\n";
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>

long long gcd(long long x,long long y){
    if(y == 0) return x;
    return gcd(y,x%y);
}

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

  int A[N];
  for(int i = 0;i < N;i++) scanf("%d",&A[i]);

  int ans = A[0];
  for(int i = 1;i < N;i++){
    ans = gcd(A[i],ans);
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
int ans[100000],ahl[100000];
bool hl[100000];
char last;
int zk(int x){
	if(s[x]!=last) return x;
	if(hl[x]) return ahl[x];
	hl[x]=1;
	if(s[x]=='R') {
		last=s[x];
		return ahl[x]=zk(x+1);
	}
	else {
		last=s[x];
		return ahl[x]=zk(x-1);
	}
}
int main(){
	memset(hl,0,sizeof(hl));
	ios::sync_with_stdio(false);
	cin>>s;
	for(int i=0;i<s.size();i++){
		last=s[i];
		int x=zk(i);
		hl[i]=1;
		ahl[i]=x;
		if((x-i)%2==0){
			ans[x]++;
		}
		else if((x-i)%2==1&&last=='R') ans[x-1]++;
		else ans[x+1]++;
	}
	for(int i=0;i<s.size();i++) cout<<ans[i]<<' ';
	return 0;
}


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

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

  vector< tuple< int, int, int > > stx(N);
  for (int i=0;i<N; ++i) {
    int sin, tin, xin;
    cin >> sin >> tin >> xin;
    stx[i] = make_tuple( xin, sin-xin, tin-xin );
  }

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

  set< pair< int,int > > D;
  vector< int > DO(Q,-1);
  
  for (int i=0; i<Q; ++i ) {
    int din;
    cin >> din;
    D.emplace( din,i );
  }
  for ( auto a: stx ) {
//      cout << "#" << get<0>(a) << " " << get<1>(a) << " " << get<2>(a) << endl;
    auto first = D.lower_bound( make_pair( get<1>(a), 0) );
    auto last = D.upper_bound( make_pair( get<2>(a)-1, Q) );
    for ( auto it = first; it != last; ++it ) {
      DO[ it->second ] = get<0>(a);
    }
    D.erase(first,last);
  }
  for (int i=0;i<Q;++i ) {
    cout << DO[i] << endl;
  }
}



Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 約数の列挙O(√n)
vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            // 重複しないならばiの相方であるN/iもpush
            if(i!=n/i) res.push_back(n/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main(){
    int n,m;
    cin>>n>>m;
    
    auto ed=enum_divisors(m);
    int ans=1;
    for(auto e : ed){
        if(e*n<=m) ans=e;
    }

    cout<<ans<<endl;
} 


Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
#define rep(i, n) for (int i=0; i<(int) (n);i++)
using ll = long long;
using P = pair<int, int>;

void solve_1() {//14m
	int a, b;
	cin >> a >> b;
	int total;
	int n = 0;
	while (!((a-1)*n + 1 >= b)) {
		n++;
	}
	cout << n << endl;

}

void solve_2() {//30m
	int n;
	cin >> n;
	vector<int> x;
	int total = 0;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);
		total += tmp;
	}
	int p1 = (double(total)/double(n)*2 - 1.0) / 2;
	int p2 = (double(total)/double(n)*2 - 1.0) / 2 + 1;
	int point_sum1 = 0, point_sum2= 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;

}

void solve_2re() {
	int n;
	cin >> n;
	vector<int> x(n);
	int total = 0;
	rep(i, n) {
		cin >> x[i];
		total += x[i];
	}
	int p1 = total / n;
	int p2 = total / n + 1;
	int point_sum1 = 0, point_sum2 = 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;
}

void solve_3() {//17m
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int sum = a + b;
	rep(i, n) {
		if (s[i] == 'a') {
			cout << (sum > 0 ? "Yes" : "No") << endl;
			if (sum>0) {
				sum--;
			}
		}
		else if (s[i] == 'b') {
			cout << (sum > 0 && b > 0 ? "Yes" : "No") << endl;
			if (sum > 0 && b > 0) {
				if (b>0) {
					sum--;
					b--;
				}
				else {
					sum--;
				}
			}
		}
		else if (s[i] == 'c') {
			cout << "No" << endl;
		}
	}
}

void solve_4() {//7m
	int n;
	cin >> n;
	rep(i, 50000) {
		if (int(i*1.08) == n) {
			cout << i;
			return;
		}
	}
	cout << ":(";
}

void solve_4re() {
	int n;
	cin >> n;
	int x = ceil(n/ 1.08);
	if (int(x*1.08)==n) {
		cout << x;
	}
	else
	{
		cout << ":(";
	}
}

void solve_5() {//7m
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	int score;
	int count = 0;
	rep(i, m) cin >> b[i];
	rep(i, n) {
		score = c;
		rep(i, m) {
			int a;
			cin >> a;
			score += b[i] * a;
		}
		if (score>0) {
			count++;
		}
	}
	cout << count;

}

void solve_6() {

}

void solve_100() {
	int n;
	cin >> n;
	vector<int> a(n);
	int pair_count = 0;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (a[a[i]-1] -1 == i) {
			pair_count++;
		}
	}
	cout << pair_count/2;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//solve_1();
	//solve_2();
	//solve_2re();
	//solve_3();
	//solve_4re();
	//solve_5();
	//solve_6();
	solve_100();
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int n;
int c[3] = {};
vector<pii> v;

map<vi, bool> dp[100000];

bool get(int i, vi d)
{
	if (i == n)
		return 1;

	if (dp[i].count(d))
		return dp[i][d];

	int cur[3] = {c[0] + d[0], c[1] + d[1], c[2] + d[2]};

	int i1 = v[i].ff;
	int i2 = v[i].ss;

	bool ans = 0;

	if (cur[i1] && d[i2] < 3 && d[i1] > -3)
	{
		vi tmp = d;
		tmp[i1]--, tmp[i2]++;
		ans |= get(i + 1, tmp);
	}

	if (cur[i2] && d[i1] < 3 && d[i2] > -3)
	{
		vi tmp = d;
		tmp[i2]--, tmp[i1]++;
		ans |= get(i + 1, tmp);
	}

	return dp[i][d] = ans;
}

void backtrack(int i, vi d)
{
	if (i == n)
		return;

	int cur[3] = {c[0] + d[0], c[1] + d[1], c[2] + d[2]};

	int i1 = v[i].ff;
	int i2 = v[i].ss;

	//cout << i1 << ' ' << i2 << '\n';

	bool ans = 0;

	if (cur[i1] && d[i2] < 3 && d[i1] > -3)
	{
		vi tmp = d;
		tmp[i1]--, tmp[i2]++;
		ans |= get(i + 1, tmp);

		if (ans)
		{
			char ch = i2 + 'A';
			cout << ch << '\n';
			backtrack(i + 1, tmp);
			return;
		}
	}

	if (cur[i2] && d[i1] < 3 && d[i2] > -3)
	{
		vi tmp = d;
		tmp[i2]--, tmp[i1]++;
		ans |= get(i + 1, tmp);

		char ch = 'A' + i1;
		cout << ch << '\n';
		backtrack(i + 1, tmp);
	}
}

int32_t main()
{
	FIO;
	cin >> n >> c[0] >> c[1] >> c[2];

	if (c[0] && c[1] && c[2])
	{
		vector<char> v;
		cout << "Yes\n";
		while (n--)
		{
			string s; cin >> s;

			int i1 = s[0] - 'A';
			int i2 = s[1] - 'A';

			if (c[i1] <= c[i2])
			{
				c[i1]++, c[i2]--;

				char ch = i1 + 'A';
				cout << ch << '\n';
			}

			else
			{
				c[i1]--, c[i2]++;
				char ch = i2 + 'A';
				cout << ch << '\n';
			}
		}
	}

	else
	{
		for (int i = 0; i < n; ++i)
		{
			string s; cin >> s;
			int i1 = s[0] - 'A';
			int i2 = s[1] - 'A';
			v.pb({i1, i2});
		}

		//memset(dp,-1,sizeof(dp));

		if (!get(0, {0, 0, 0}))
			cout << "No\n";

		else
		{
			cout << "Yes\n";
			backtrack(0, {0, 0, 0});
		}
	}
	return 0;
}

Measured memory_bytes: 92896
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)
ans = 0
mae = 0xffffffff
n.times do |i|
  ai = a[i] - 1
  ans += b[ai]
  if mae + 1 == ai
    ans += c[mae]
  end

  mae = ai
end
puts ans

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

int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)<abs(x-b)){
        cout << "A" << endl;
    }else {
        cout << "B" << endl;
    }
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a < b) cout << "a < b" << endl;
  else if (a > b) cout << "a > b" << endl;
  else cout << "a == b" << endl;
  
  return 0;
}
  

Measured memory_bytes: 1156
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

vector<Int> factorials(0), invs(0);
bool is_ncr_table = false;
void calc_ncr_table(Int n, Int mod) {
    is_ncr_table = true;

    // 1! ~ n! の計算
    Int f = 1;
    factorials.push_back(f);
    for (Int i = 1; i < n + 1; i++) {
        f *= i;
        f %= mod;
        factorials.push_back(f);
    }
    // n!^-1 の計算
    Int inv = modpow(factorials[n], mod - 2, mod);
    // (n-1)!^-1 ~ 1!^-1 の計算
    invs.assign(n, 1);
    invs[n] = inv;
    for (Int i = n; i >= 1; i--) {
        inv *= i;
        inv %= mod;
        invs[i - 1] = inv;
    }
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

Int ncr(Int n, Int r, Int mod, bool use_table = false) {
    if (use_table) {
        // modが素数の場合のみ
        if (!is_ncr_table) {
            calc_ncr_table(n, mod);
        }
        return factorials[n] * invs[r] * invs[n - r] % mod;
    } else {
        Int x = 1;
        for (Int i = n - r + 1; i < n + 1; i++) {
            x *= i;
            x %= MOD;
        }
        return x * modpow(factorial(r, mod), mod - 2, mod) % mod;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> P(n), Q(n), nu(n);
    iota(begin(nu), end(nu), 1);
    for (int i = 0; i < n; i++) {
        cin >> P[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> Q[i];
    }

    set<vector<int>> per;
    do {
        per.insert(nu);
    } while (next_permutation(begin(nu), end(nu)));

    int Pd, Qd;
    auto itrp = per.find(P);
    Pd = distance(begin(per), itrp);
    auto itrq = per.find(Q);
    Qd = distance(begin(per), itrq);

    cout << abs(Pd - Qd) << endl;

    return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    unordered_map<long long int, bool> m;
    for (int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        m[a] = !m[a];
    }

    int cnt = 0;
    for (auto &kv : m)
    {
        if (kv.second)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4388
n, q = gets.split.map(&:to_i)
ab = []
(n-1).times {|_x| ab << gets.split.map(&:to_i)}
ab.sort!
px =
  readlines.map do |i|
    i.chomp.split.map(&:to_i)
  end.to_a

ans = [0]*n
px.each do |pp,point|
  ans[pp-1]+=point
end

ab.each do |a,b|
  ans[b-1]+=ans[a-1]
end

puts ans.join(' ')

Measured memory_bytes: 56052
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

n = int(input())
t = num_divisors_table(n)

ans = 0
for k in range(1, n+1):
    ans += k * t[k]
print(ans)


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll a[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

void solve() {
    ll ans = 0;

    for (int l = 0, r; l < n; ++l) {
        if (a[l] == 0)
            continue;

        int cur = 0;

        for (r = l; r < n && a[r] > 0; ++r) {
            ans += a[r] / 2;
            cur += a[r] % 2;
        }

        ans += cur / 2;
        l = r - 1;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL L; cin >> L;
    int cnt = 0;
    LL now = 2;
    while(now <= L){
        cnt++;
        now = now * 2;
    }
    now /= 2;
    dump(cnt)
    dump(now)
    LL N = cnt+1;
    LL M = 0;


    vector<tuple<int,int,int>> ans;
    REP(i,cnt){
        auto t1 = make_tuple(i+1,i+2,0);
        auto t2 = make_tuple(i+1,i+2,(1LL<<i));
        ans.push_back(t1);
        ans.push_back(t2);
        M += 2;
    }


    LL amari = L - now;
    for(int i = 0; i < cnt; i++){
        if((amari >> i) & 1){
            auto t = make_tuple(i+1,N,now);
            ans.push_back(t);
            now += (1LL << i);
            M++;
        }
    }
    cout << N << " " << M << endl;
    for(auto t : ans){
        int a,b,c;
        tie(a,b,c) = t;
        cout << a << " " << b << " " << c << endl;
    }



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    REP(i,N) cin >> P[i];
    REP(i,N) cin >> Q[i];
    int cntp = 0, cntq = 0;
    vector<int> tmp(N);
    REP(i,N) tmp[i] = i + 1;
    do {
        cntp ++;
        bool flag = true;
        REP(i,N) {
            if (tmp[i]!=P[i]) {
                flag = false;
            }
        }
        if (flag) break;
    } while(next_permutation(all(tmp)));
    REP(i,N) tmp[i] = i + 1;
    do {
        cntq ++;
        bool flag = true;
        REP(i,N) {
            if (tmp[i]!=Q[i]) {
                flag = false;
            }
        }
        if (flag) break;
    } while(next_permutation(all(tmp)));
    cout << abs(cntp-cntq) << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   string s;
    map<string,int> mp;
    
    int n;
    cin >> n;
    
    while(n--)
    {
        cin >> s;
        mp[s]++;
    }
    
    cout <<"AC x " << mp["AC"] << '\n';
    cout <<"WA x " << mp["WA"] << '\n';
    cout <<"TLE x " << mp["TLE"] << '\n';
    cout <<"RE x " << mp["RE"] << '\n';
    
        
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

using namespace std;

int main(){
	string s;

	cin>>s;

	int gCnt=0;
	int pCnt=0;
	int point=0;
	for(int i=0;i<s.length();i++){
		if(s.at(i)=='g'){
			if(pCnt+1>gCnt){
				gCnt++;
			}
			else{
				pCnt++;
				point++;
			}
		}
		else{
			if(pCnt+1>gCnt){
				gCnt++;
				point--;
			}
			else{
				pCnt++;
			}
		}
	}
	cout<<point<<endl;

	return 0;

}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<locale>

using namespace std;

struct ToLower{
  char operator()(char c){ return tolower(c, locale()); }
};

int main()
{
  string w, t;
  int match=0;
  cin >> w;
  while(cin>>t){
    if(t=="END_OF_TEXT") break;
    transform(t.begin(), t.end(), t.begin(), ToLower());
    if(t==w){
      ++match;
    }
  }
  cout << match << endl;
  return 0;
}



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

using namespace std;

typedef long long int64;

const int mod = 1e9 + 7;


struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int64 lcm(int64 a, int64 b)
{
  return (a / __gcd(a, b) * b);
}


struct SegmentTree
{
  vector< int64 > latte, malta;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    latte.assign(2 * sz - 1, 1);
    malta.assign(2 * sz - 1, 0);
  }

  void set(int k, int x, int y)
  {
    latte[k + sz - 1] = x;
    malta[k + sz - 1] = y;
  }

  void build()
  {
    for(int k = sz - 2; k >= 0; k--) {
      latte[k] = lcm(latte[2 * k + 1], latte[2 * k + 2]);
      (malta[k] += latte[k] / latte[2 * k + 1] % mod * malta[2 * k + 1] % mod) %= mod;
      (malta[k] += latte[k] / latte[2 * k + 2] % mod * malta[2 * k + 2] % mod) %= mod;
    }
  }

  pair< int64, int64 > query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return {1LL, 0LL};
    if(a <= l && r <= b) return {latte[k], malta[k]};
    auto L = query(a, b, 2 * k + 1, l, (l + r) >> 1);
    auto R = query(a, b, 2 * k + 2, (l + r) >> 1, r);
    int64 LCM = lcm(L.first, R.first);
    int64 aaa = LCM / L.first % mod * L.second % mod;
    int64 bbb = LCM / R.first % mod * R.second % mod;
    return {LCM, (aaa + bbb) % mod};
  }

  int64 query(int a, int b)
  {
    return (query(a, b, 0, 0, sz).second);
  }
};

int main()
{
  int N, Q, P[100000];
  cin >> N >> Q;
  for(int i = 0; i < N; i++) cin >> P[i];
  UnionFind tree(N);
  for(int i = 0; i < N; i++) tree.unite(i, P[i] - 1);
  vector< int > sum(N, 0);
  for(int i = 0; i < N; i++) (sum[tree.find(i)] += P[i]) %= mod;
  SegmentTree seg(N);
  for(int i = 0; i < N; i++)  seg.set(i, tree.size(i), sum[tree.find(i)]);
  seg.build();
  while(Q--) {
    int a, b;
    cin >> a >> b;
    cout << seg.query(--a, b) << endl;
  }
}

Measured memory_bytes: 8120
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt[2][n+1];
    cnt[0][0] = cnt[1][0] = 0;
    rep(i, n){
        cnt[0][i+1] = cnt[0][i] + (s[i] == 'W');
        cnt[1][i+1] = cnt[1][i] + (s[i] == 'E');
    }
    int ans = n;
    rep(i, n) chmin(ans, cnt[0][i] + cnt[1][n] - cnt[1][i+1]);
    printf("%d\n", ans);
}

Measured memory_bytes: 2948
import java.util.*;
import java.lang.*;

public class Main {
  static boolean isPrime(int X){
    if(X <= 1) return false;
    
    for(int i = 2; i * i <= X; i++){
      if(X % i == 0) return false;
    }
    
    return true;
  }
  
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    while(!isPrime(X)){
      X++;
    }
    
    System.out.println(X);
  }
}


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

static const int MAX_N = 1400;

int dp[MAX_N+1][MAX_N+1];

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

  for (int i = 0; i < H; i++) {
    dp[i][0] = 0;
  }
  for (int i = 0; i < W; i++) {
    dp[0][i] = 0;
  }
  int tmp;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> tmp;
      dp[i][j] = (tmp + 1) % 2;
    }
  }

  int maxWidth = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (dp[i][j]) {
        dp[i][j] = min(dp[i-1][j], min(dp[i][j-1], dp[i-1][j-1])) + 1;
        maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }

  cout << maxWidth*maxWidth << endl;

  return 0;
}

Measured memory_bytes: 8828
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;

void main() {
	auto N = readln.chomp.to!int;
	bool[int] d;
	foreach(_; 0..N) {
		d[readln.chomp.to!int] = true;
	}
	writeln(d.length);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll hh(ll n){
  if(n<=1) return 0;
  return n*(n-1)/2;
}
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll b(n+1);
  b[0]=0;
  for(int i=1;i<n+1;i++){
    b[i]=b[i-1]+a[i-1];
  }
  map<ll,ll> p;
  rep(i,n+1){
    p[b[i]]++;
  }
  ll ans=0;
  for(auto i:p){
    ans+=hh(i.S);
  }
  COUT(ans);
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string s;
cin>>s;
string t = "";
ll n=s.size();
for(ll i=0; i<n; i++){
if(s.at(i)!='x'){
t+=s.at(i);}}
string u=t;
reverse(t.begin(), t.end());
if(t!=u){
cout << -1 << endl;}
else if(t.size()==0){
cout << 0 << endl;}
else{
ll ca=0;
ll m=0,h=n-1;
ll cm=0;
ll ch=0;
while(h!=m){
while(s.at(m)=='x'){
cm++;
m++;}
while(s.at(h)=='x'){
ch++;
h--;}
ca+=abs(cm-ch);
cm=0;
ch=0;
m++;
h--;
if(h-m<=0){
break;}}
cout << ca << endl;}}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C,D;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>D;
	cout<<max(A*B,C*D)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
int prime[MAXN*10 + 5];
vector<int> primes;

void sieve() {
	for (int i = 2; i <= MAXN*10; ++i) {
		if (!prime[i]) {
			primes.push_back(i);
			for (int j = 1; i*j <= MAXN * 10; ++j) prime[i*j] = 1;
		}
	}
	return;
}

int main()
{
	scanf("%d", &N);
	sieve();
	printf("%d", *lower_bound(primes.begin(), primes.end(), N));
	return 0;
}

Measured memory_bytes: 4732
function Main(input) {
        input = input.split("\n");
        tmp = input[0];
  if( tmp[2] === tmp[3] && tmp[4] === tmp[5] ){
    console.log("Yes");
  } else {
    console.log("No");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
s=int(input())

def collatz(n):
    if n%2==0:
        n=n/2
    else: 
        n=3*n+1
    return int(n)

l=[s]
while s!=1:
    s=collatz(s)
    l.append(s)

if l[0]==1:
    print(4)
elif l[0]==2:
    print(4)
else:
    print(len(l)+1)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
bool f1,f2;
int n1,n2;
string s;
int main(){
	int f,l;
	cin>>s;
	if(s.size()<2){	cout<<"No";	return 0;}
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			f1=true;
			n1=i;
			break;
		}
	}
	if(!f1){
		cout<<"No";
		return 0;
	}
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='F'){
			f2=true;
			n2=i;
			break;
		}
	}
	if(!f2||n1>n2){
		cout<<"No";
		return 0;
	}
	else if(n1<n2)	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,A,B;
  cin>>N>>A>>B;
 int ans=0;
  for(int i=1;i<=N;i++){
  int sum=0;
    for(int j=i;0<j;j/=10){
    sum+=j%10; 
    }if(A<=sum && sum<=B)
      ans+=i;
  }cout<<ans<<endl;
   return 0;
}

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

typedef long long ll;

ll X, K;
typedef array<ll, 4> State;
map<ll, State> States;
vector<ll> R;
ll Q;

void simulate() {
  State state = {0, 0, X, X};
  ll gravity = -1;
  ll t = 0;
  for (ll i = 0; i < R.size(); ++i) {
    ll t1 = min(t + (gravity < 0 ? state[1] : X - state[3]), R[i]);
    state[gravity < 0 ? 1 : 3] += gravity * (t1 - t);
    state[gravity < 0 ? 3 : 1] += gravity * (t1 - t);
    States[t1] = state;
    t = t1;
    ll t2 = min(t + (gravity < 0 ? state[3] : X - state[1]), R[i]);
    state[gravity < 0 ? 0 : 2] -= gravity * (t2 - t);
    state[gravity < 0 ? 3 : 1] += gravity * (t2 - t);
    States[t2] = state;
    t = t2;
    States[R[i]] = state;
    t = R[i];
    gravity *= -1;
  }
}
State interpolate(ll t0, State from, ll t1, State to, ll t) {
  State res;
  for (ll i : {0, 1, 2, 3})
    res[i] = from[i] + (to[i] - from[i]) / (t1 - t0) * (t - t0);
  return res;
}
int main() {
  cin >> X >> K;
  for (ll i = 0; i < K; ++i) {
    ll r;
    cin >> r;
    R.push_back(r);
  }
  R.push_back(1e9 + 1);
  simulate();
  cin >> Q;
  for (ll i = 0; i < Q; ++i) {
    ll t, a;
    cin >> t >> a;
    auto it1 = States.upper_bound(t);
    auto it0 = prev(it1);
    auto state =
        interpolate(it0->first, it0->second, it1->first, it1->second, t);
    ll x0 = state[0], y0 = state[1], x1 = state[2], y1 = state[3];
    cout << (a <= x0 ? y0 : x1 <= a ? y1 : (a - x0) + y0) << endl;
  }
  return 0;
}


Measured memory_bytes: 16884
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int T, D, ta, tb, da, db;
  cin >> T >> D >> ta >> tb >> da >> db;
  double res = 1e9;
  for (int i = 0; i < 1000; i++) {
	for (int j = 0; j < 1000; j++) {
	  int d = i * da + j * db;
	  if (1 <= d && d <= D) {
		double temp = (double)(ta * i * da + tb * j * db) / d;
		res = min(res, abs(T - temp));
	  }
	}
  }
  cout << res << endl;
}

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

int read()
{
	int num=0;
	int flg=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
		{
			flg=-1;
		}
		c=getchar();
	}
	while(isdigit(c))
	{
		num=(num<<1)+(num<<3)+(c^48);
		c=getchar();
	}
	return num*flg;
}

const int maxn=1125;
int a[maxn];

int main()
{
	int n=read();
	int sum=0;
	for(ri i=1;i<=n;i++)
	{
		a[i]=read();
		sum+=a[i];
	}
	int m=read();
	for(ri i=1;i<=m;i++)
	{
		int u=read();
		int v=read();
		printf("%d\n",sum+v-a[u]);
	}
}
/*
3
2 1 4
2
1 1
2 3
out:
6
9
*/

Measured memory_bytes: 256