akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int main(){
  int N; cin >> N;
  int L; cin >> L;
  
  int apple[N]; REP(i,N){apple[i] = L+i;}
  
  int z = 0; REP(i,N){z += apple[i];}
  
  int r;
  REP(i,N){
    int c = z-apple[i];
    if(i==0){r=c;}
    else{r = abs(z-c)<abs(z-r) ? c:r;}
    
  }
  
  cout << r << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
	char ch;
	string s(1201, '\0');
	int i = 0;
	while (scanf("%c", &ch), ch != '\n')
	{
		if (isalpha(ch))
		{
			if (islower(ch))
			{
				ch = toupper(ch);
			}
			else
			{
				ch = tolower(ch);
			}
		}
		s[i++] = ch;
	}
	i = 0;
	while (s[i] != '\0')
	{
		cout << s[i++];
	}
	cout << endl;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> ps(N + 1, 0);
  vector<int> todo;
  todo.reserve(N);
  for (int i = 1; i <= N; ++i) {
    cin >> ps[i];
    if (ps[i] == i) todo.push_back(i);
  }
  int count = todo.size();
  int prev = 0;
  for (int i = 0; i < todo.size(); ++i) {
    if (prev > 0 and prev + 1 == todo[i]) {
      --count;
      prev = 0;
    } else {
      prev = todo[i];
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
    int a,b;
    
    scanf("%d %d",&a,&b);

    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else if(a==b){
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2040
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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


int main(void){
    int s;
    cin >> s;

    vector<int> a;
    a.push_back(s);

    int i = 0;
    while(1){
        if(a[i] % 2 != 0){
            a.push_back(a[i] * 3 + 1);
        } else {
            a.push_back(a[i] / 2);
        }

        i++;
        
        bool finished = false;
        for(int j = 0; j <= i; j++){
            if(i == j)continue;
            if(a[j] == a[i]){
                cout << i + 1<< endl;
                finished = true;
                break;
            }
        }

        if(finished)break;

    }
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
		if(i%k==0)
		{
			puts("OK");
			return 0;
		}
	puts("NG");
	return 0;
}

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

const int N = 1000005;

int n;
string s;
int dp[N][2];

int gao() {
    int id = s[0] - '0';
    memset(dp, 127, sizeof(dp));
    dp[0][0] = min(id, 11 - id);
    dp[0][1] = min(id + 1, 10 - id);
    for (int i = 1; i < n; i++) {
        int id = s[i] - '0';
        dp[i][0] = dp[i - 1][0] + id;
        dp[i][0] = min(dp[i][0], dp[i - 1][1] + 10 - id);

        dp[i][1] = dp[i - 1][0] + id + 1;
        dp[i][1] = min(dp[i][1], dp[i - 1][1] + 9 - id);
    }
    return dp[n - 1][0];
}

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    while (cin >> s) {
        n = s.size();
        cout << gao() << '\n';    
    }
    return 0;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int l,r,i,j,c,mi=pow(10,9)*pow(10,9);
  cin >>l>>r;
  i=(l-1)/2019;
  j=r/2019;
  if(i!=j)cout <<0<<endl;

  else
  {
      for(long long int i=l;i<=r;i++)
      {
          for(long long int j=l;j<=r;j++)
          {
              if(i!=j){
              c=(i*j)%2019;
              mi=min(mi,c);
          }
          }
      }
      cout <<mi<<endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000
#define SZ 10

string str[SZ];
int len[SZ];
int conn[SZ][SZ];

// if s1 is smaller than s2
bool str_smaller(const string s1, const string s2){
  if(s1.size() < s2.size()) return true;
  else if(s1.size() == s2.size() )return s1<s2;
  else return false;
}

int main(){
  int n;
  while(cin>>n, n){
    rep(i,n){
      cin >> str[i];
      len[i] = str[i].size();
    }

    // substring delete
    vector<bool> rm(n, false);
    rep(i,n){
      repl(j,i+1,n){
	if(rm[i] || rm[j]) continue;
	int s=i,l=j; //(shorter, longer index)
	if(len[s]>len[l]) swap(s,l);
	int reps = len[l]-len[s];
	rep(k,reps+1){
	  if(str[l].substr(k,len[s]) == str[s]){
	    rm[s]=true;
	    break;
	  }
	}
      }// rep j
    }// rep i

    vector<string> s;
    rep(i,n) if(!rm[i]) s.pb(str[i]);
    n = s.size();
    rep(i,n) len[i]=s[i].size();

    // how many words duplicate when connecting i->j
    rep(i,n){
      rep(j,n){
	if(i==j) continue;
	conn[i][j] = 0;
	int reps = min(len[i],len[j]);
	for(int k=reps; k>0; k--){
	  if(s[i].substr(len[i]-k,k) == s[j].substr(0,k)){
	    conn[i][j] = k;
	    break;
	  }
	} // rep k
      } // rep j
    } // rep i


    string infstr = "zzzzzzzzzz"; // 10
    infstr += infstr; infstr+=infstr; infstr += infstr+infstr; //120


    // DP
    // dp[bitmask(use:1,no:0)][last str idx] = "smallest string"
    vector<vector<string> > dp(1<<n, vector<string>(n, infstr));
    rep(i,n) dp[1<<i][i] = s[i];

    repl(mask,1,1<<n){ // current bit mask
      rep(i,n){ // i:new adding str idx
	if((mask>>i) &1) continue; //already used
	int nm = mask+(1<<i);  //new mask

	rep(j,n){ // j:current mask's last idx
	  if(((mask>>i) &1)) continue;//not used
	  string nw=dp[mask][j] + s[i].substr(conn[j][i]);
	  if(str_smaller(nw, dp[nm][i])) dp[nm][i]=nw;
	}
      } // rep i
    } // rep mask


    // decide answer
    string ans = infstr;
    int mask = (1<<n)-1;
    rep(i,n){
      if(str_smaller(dp[mask][i], ans)) ans =dp[mask][i];
    }
    cout << ans << endl;

  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int a;
        cin >> a;
        if (a%2==0)
            if (a%3!=0 && a%5!=0)
                return cout << "DENIED", 0;
    }
    cout << "APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>

using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
typedef long long ll;

int main(){
	double n;
	scanf("%lf", &n);
	n /= 3.0;
	printf("%.8f\n", n*n*n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

// 方針
// 寿司が3個, 2個, 1個残っている皿数をそれぞれp,q,r(いずれも非負，p+q+r<=N)とする。
// 状態(p,q,r)からサイコロを振って移動できる状態は(p,q,r)自身,(p-1,q+1,r),(p,q-1,r+1),(p,q,r-1)のいずれか。この状態数はcombi(N+3,3)=O(N^3)である。

int main () {
	int N; cin >> N;
	int a, k3 = 0, k2 = 0, k1 = 0;
	rep(i, N) { cin >> a;	if (a == 3) k3++; if (a == 2) k2++; if (a == 1) k1++; }	
	// cout << "(k3,k2,k1)=(" << k3 << "," << k2 << "," << k1 << ")" << endl;
	vector<vector<vector<double>>> d(N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1))); // d[p][q][r]
	double x; bool f = false;
	rep(p, k3 + 1) {
		rep(q, N + 1 - p) {
			rep(r, N + 1 - p - q) {
				if (p == 0 && q == 0 && r == 0) continue;
				x = N;
				if (p > 0) x += p * d[p - 1][q + 1][r];
				if (q > 0) x += q * d[p][q - 1][r + 1];
				if (r > 0) x += r * d[p][q][r - 1];
				x /= p + q + r;
				d[p][q][r] = x;
				// printf("dp[%d][%d][%d] = %lf\n", p, q, r, x); //DB
				if (p == k3 && q == k2 && r == k1) f = true;
				if (f) break;
			}
			if (f) break;
		}
		if (f) break;
	}
	cout << fixed << setprecision(10); // 必要
	cout << d[k3][k2][k1] << endl;
}

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

int main() {
    int H,W;
    while(true) {
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        for(int j=0; j<H; j++) {
            for(int i=0; i<W; i++) {
                if(j%2 == 0 && i%2 == 0){
                    cout << "#";
                }else if(j%2 == 1 && i%2 == 1){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int a[101],f[100001];
int main()
{
	int i,j,n,k;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<=k;i++)
	{
		f[i]=0;
		for(j=1;j<=n;j++)
		{
			if(i<a[j])
				continue;
			if(f[i-a[j]]==0)
			{
				f[i]=1;
				break;
			}
		}
	}
	if(f[k]==1)
		printf("First");
	else
		printf("Second");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int R;
    cin >> R;
    cout << 2 * R * M_PI << endl;
    return 0;
}

Measured memory_bytes: 3788
n = int(input())
spi = []
for i in range(n):
    s,p = input().split()
    spi.append([s,int(p), i+1])
spi.sort()
before = spi[0][0]
ans = [spi[0][2]]
for s,p,i in spi[1:]:
    if s == before:
        ans.append(i)
    else:
        for x in ans[::-1]:
            print(x)
        before = s
        ans = [i]
for x in ans[::-1]:
    print(x)

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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N;
  cin >> N;
  ll A[N];
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll r = 0;
  ll tmp = 0;
  rep(l, N){
    while((tmp & A[r]) == 0 && r < N) tmp ^= A[r++];
    tmp ^= A[l];
    ans += r - l;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

double cost[30][256];
int n,m,p,a,b;
int t[8];
int map[30][30];

int main(){
  while(1){
    cin >> n >> m >> p >> a >> b;
    if(!n&&!m&&!p&&!a&&!b) break;
    for(int i=0;i<n;i++){
      scanf("%d",&t[i]);
    }
    a--;
    b--;
    memset(map,0,sizeof(map));
    for(int i=0;i<p;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      map[x-1][y-1] = z;
      map[y-1][x-1] = z;
    }

    for(int i=0;i<m;i++){
      for(int j=0;j<1<<n;j++){
        if(i==a){
          cost[a][j] = 0;
        }else{
          cost[i][j] = INF;
        }
      }
    }

    queue<P> que;
    que.push(P(a,(1<<n)-1));
    while(que.size()){
      P pa = que.front(); que.pop();
      int pos = pa.first;
      int ticket = pa.second;
      //cout << pos << endl;
      for(int i=0;i<m;i++){
        if(map[pos][i]!=0){
          for(int j=0;j<n;j++){
            if(ticket>>j&1){
              int next = ticket-(1<<j);
              if(cost[i][next]>cost[pos][ticket]+((double)map[pos][i]/t[j])){
                cost[i][next]=cost[pos][ticket]+((double)map[pos][i]/t[j]);
                que.push(P(i,next));
              }
            }
          }
        }
      }
    }

    double ans = INF;
    for(int i=0;i<1<<n;i++){
      if(ans>cost[b][i]){
        ans = cost[b][i];
      }
    }
    if(ans!=INF){
      printf("%lf\n",ans);
    }else{
      printf("Impossible\n");
    }

  }
  return 0;
}

Measured memory_bytes: 1452
use std::io;
use std::collections::VecDeque;

fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let (u, v) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1)
        };
        g[u].push(v);
    }
    let (s, t) = {
        let i = read::<usize>();
        (i[0] - 1, i[1] - 1)
    };

    let mut que = VecDeque::new();
    let mut dist = vec![vec![::std::usize::MAX; 3]; n];
    que.push_back((s, 0));
    while let Some((u, v)) = que.pop_front() {
        if dist[u][v % 3] != ::std::usize::MAX { continue; }
        dist[u][v % 3] = v;

        for i in 0..g[u].len() {
            let vv = g[u][i];
            que.push_back((vv, v + 1));
        }
    }

    if dist[t][0] != ::std::usize::MAX { println!("{}", dist[t][0] / 3); }
    else { println!("-1"); }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 18684
N = int(input())
P = 10**9+7
  
memo = [0]*(N+1)

for i in range(1,N+1):
  j = i
  while j % 2 == 0:
    memo[2] += 1
    j //= 2
  k = 3
  while k*k <= j:
    if j % k == 0:
      memo[k] += 1
      j //= k
    else:
      k += 2
  if j != 1:
    memo[j] += 1
  
rlt = 0
dic = {2:0, 4:0, 14:0, 24:0, 74:0}
for i in range(1, N+1):
  if memo[i] >= 74:
    dic[74] += 1
  if memo[i] >= 24:
    dic[24] += 1
  if memo[i] >= 14:
    dic[14] += 1
  if memo[i] >= 4:
    dic[4] += 1
  if memo[i] >=2:
    dic[2] += 1
    

rlt += dic[74]
rlt += dic[24]*(dic[2]-1)
rlt += dic[14]*(dic[4]-1)
rlt += dic[4]*(dic[4]-1)*(dic[2]-2)//2

print(rlt)

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

using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<int>  A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A[i]--;
  }  

  set<int> used;
  vector<int> path;
  int now = 0;
  while (used.count(now) == 0) {
    path.push_back(now);
    used.insert(now);
    now = A[now];
  }

  int initial = find(path.begin(), path.end(), now) - path.begin();
  int T = path.size() - initial;

  if (K < initial) {
    cout << path[K] + 1 << endl;
    return 0;
  } else {
    cout << path[(K - initial) % T + initial] + 1 << endl;
  }
}


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

using namespace std;
typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

int main() {
  double n,x,t;
  int ans ;
  cin >> n >> x >> t;
  ans = t*ceil(n/x);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  string s;
  ll c,q[120000]={},w[120000]={};
  cin >> s;
  c=s.length();
  if(s[c-1]=='1'){
    q[c-1]=3;
  }
  else{
    q[c-1]=1;
    w[c-1]=2;
  }
  per(i,c-1){
    if(s[i]=='1'){
      q[i]=(q[i+1]*3+w[i+1])%MOD;
      w[i]=2*w[i+1]%MOD;
    }
    else{
      q[i]=q[i+1]%MOD;
      w[i]=(2*q[i]+3*w[i+1])%MOD;
    }
  }
  printf("%lld",q[0]);
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int count_mine(const vector<string> &S, int i, int j)
{
	int ans = 0;
	const int H = S.size();
	const int W = S[0].size();
	for (int y = max(0, i - 1); y <= min(H - 1, i + 1); ++y) {
		for (int x = max(0, j - 1); x <= min(W - 1, j + 1); ++x) {
			if (S[y][x] == '#') {
				++ans;
			}
		}
	}
	return ans;
}

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (auto &x : S) {
		cin >> x;
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (S[i][j] == '.') {
				S[i][j] = '0' + count_mine(S, i, j);
			}
		}
	}

	for (auto &x : S) {
		cout << x << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
//input power
int n;

int main(){
cin>>n;
vector<int> A(n);
long long ans =1 ;
rep(i,n){
	cin>>A[i];
}
SORT(A);
REV(A);
int count = 0;
rep(i,n){
	if(A[i+1]==A[i]){
		i++;
		ans*=A[i];
		count++;	
	}
	if(count>=2){
		break;
	}
}
	if(count<2){
		cout<<0<<endl;
	}
	else{
	cout<<ans<<endl;
	}
}


Measured memory_bytes: 640
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
  int K,X;
  cin >> K >> X;

  int x,y;
  x = X - K + 1;
  y = X + K - 1;

  if(x < -100000){
    x = -100000;
  }
  if(y > 100000){
    y = 100000;
  }

  for(int i = x; i <= y; i++){
    cout << i << " ";
  }
}


Measured memory_bytes: 256
s = int(input())
arr = []
ans = 0
def calc(n, cnt):
    arr.append(n)

    if cnt >= 1000000:
        return n

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

    if n in arr:
        return cnt

    cnt += 1
    calc(n, cnt)
calc(s, 0)
print(len(arr) + 1)


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


int main()
{
    int n, x;
    cin >> n >> x;
    int l[105];
    for(int j = 0; j < n; j++) cin >> l[j];
    int sum = 0, i = 0;
    while(sum <= x){
        sum += l[i];
        i++;
        if(i == n + 1) break;
    }
    cout << i << endl;
    return 0;
}

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


int main(){
  string s;
  cin >> s;
  int n=s.size();
  if(n<26){
    map<char,int> mp;
    char a='a';
    for(int i=0;i<26;++i){
      mp['a'+i]++;
    }
    for(int i=0;i<n;++i){
      mp[s[i]]++;
    }
    bool ok=true;
    for(auto p : mp){
      if(p.second==1 && ok==true){
        s=s+p.first;
        ok=false;

      }
      //cout << p.first << p.second << endl;
    }
    cout << s << endl;
    return 0;
  }else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
      cout << "-1" << endl;
      return 0;
    }

    string ans;
    string x=s;
    next_permutation(x.begin(),x.end());
    for(int i=0;i<26;++i){
      if(s[i]==x[i]){
        ans+=x[i];
      }else{
        ans+=x[i];
        break;
      }
    }
    //next_permutation(ans.begin(),ans.end());
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明

// vector の使い方
// 宣言：
// vector<int> v;
// vector<int> v(N);
// 初期化:
// vector<int> v(10, 5); 要素数10，全ての要素の値5．
// vector<int> v = {1, 2, 3};
// 代入：
// v[0] = 3;
// sort:
// sort(v.begin(), v.end());
//

// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }

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

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

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

	ll S_all[N+1], S_pat[N+1];
	S_all[0] = 1; S_pat[0] = 1;
	for (int i=1; i<=N; i++) {
		S_all[i] = 2*S_all[i-1] + 3;
		S_pat[i] = 2*S_pat[i-1] + 1;
	}

	ll ans = 0;
	int i=N-1;
	while (X != 0) {
		if (X == 1) {
			break;
		} else if (X <  2 + S_all[i]) {
			X--;
			i--;
            if (i == -1) {
                ans++;
                break;
            }
		} else if (X == 2 + S_all[i]) {
			ans += 1 + S_pat[i];
			break;
		} else if (X <  3 + 2*S_all[i]) {
			ans += 1 + S_pat[i];
			X -= 2+S_all[i];
			i--;
            if (i== -1) {
                ans++;
                break;
            }
		} else if (X == 3 + 2*S_all[i]) {
			ans += 1 + 2*S_pat[i];
			break;
		}
	}

	cout << ans << endl;
}

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

int main(void)
{
	int t = 0, i, ans;
	int f1[30][30], f2[30];
	char s[5], sl;

	memset(f1, 0, sizeof(f1));
	memset(f2, 0, sizeof(f2));
	while(1){
		if (t == 0) {
			printf("?aaa\n");
			f1[0][0] = 1;
			i = 0;
		} else {
			for (i=0; i<26; i++) {
				if (f1[sl - 'a'][i] == 0) {
					printf("?%c%ca\n", sl, i + 'a');
					f1[sl - 'a'][i] = 1;
					break;
				}
			}
		}

		t++;
		fflush(stdout);
		scanf("%s", s);
		ans = 0;
		sl = s[strlen(s) - 1];
		if (s[0] != 'a') {
			ans = 1;
		} else {
			if (strlen(s) == 1) {//s=*
				if (f2[26] == 1){
					ans = 1;
				} else {
					f2[26] = 1;
				}
			} else {//s=**
				if ( f2[sl - 'a'] == 1) {
					ans = 1;
				} else {
					f2[sl - 'a'] = 1;
				}
			}
		}

		if (ans == 1) {
			printf("!OUT\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1260
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y;
    cin>>x>>y;
    PUTS(x+y/2);
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  ll sum = a + b;
  ll ans = 0;
  ans += n / sum * a;
  ans += min(a, n % sum);
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k[20],s[20][20],p[20],sum=0;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>k[i];
		for(int j=1;j<=k[i];j++)
		{
			cin>>s[i][j];
		}
	}
	for(int i=1;i<=m;i++)
	{
		cin>>p[i];
	}
	for(int i=0;i<(1<<n);i++)
	{
		int t=0;
		for(int j=1;j<=m;j++)
		{
			int count=0;
			for(int k=1;k<=m;k++)
			{
				if(i&(1<<(s[j][k]-1)))count++;
			}
			if(count%2==p[j])t++;
			else break;
		}
		if(t==m)sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  auto str=readln.chomp.to!(char[]);

  int[char] cnt;
  foreach(c; str){
    if(!(c in cnt)) cnt[c]=1;
  }

  bool g(char[] s){
    char tg=s[0];
    bool ok=true;
    foreach(c; s) ok&=(c==tg);
    return ok;
  }

  int f(char c, char[] s){
    int ret=0;
    while(!g(s)){
      foreach(i; 0..(s.length-1)){
        if(s[i+1]==c) s[i]=c;
      }
      /* if(s.back!=c) */ s.popBack;
      ret++;
    }
    return ret;
  }

  int mi=100;
  foreach(c, v; cnt){
    mi=min(mi, f(c, str.dup));
  }

  writeln(mi);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 256
(* O(n) *)
let n = read_int ()
let dp = Array.make (n + 1) n
let pss = Array.make_matrix 2 7 1
let f j b = for i = 1 to 6 do pss.(j).(i) <- pss.(j).(i - 1) * b done
let _ =
  List.iteri f [6; 9];
  dp.(0) <- 0;
  for i = 1 to n do
    for j = 0 to 1 do
      for k = 0 to 6 do
        if pss.(j).(k) <= i then dp.(i) <- min dp.(i) @@ dp.(i - pss.(j).(k)) + 1 done done done;
  dp.(n) |> Printf.printf "%d\n"

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll N;
	cin >> N;
	vector<ll> h(N);
	FOR(i,0,N){
		cin >> h[i];
	}
	ll ans = 0;
	queue< vector<ll> > vecset;
	vecset.push(h);
	while(not vecset.empty()){
		vector<ll> now,p,v;
		now = vecset.front();
		vecset.pop();
		ll nowmin = *min_element(now.begin(),now.end());
		ans += nowmin;
		FOR(i,0,now.size()){
			if(now[i]-nowmin!=0){
				p.push_back(now[i]-nowmin);
			}else{
				if(p.size()!=0){
					vecset.push(p);
					p = v;
				}
			}
		}
		if(p.size()!=0)vecset.push(p);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	dp[2] = abs(h[2]-h[1])
	for i in 3:n
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
	end
	println(dp[n])
end

main()


Measured memory_bytes: 117624
#include<iostream>
#include<iomanip>
#include<algorithm>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
using namespace std;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point p) {
		return Point(x + p.x, y + p.y); 
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double a) {
		return Point(a * x, a * y);
	}
	Point operator / (double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

Point project(Point p, Point p1, Point p2) {
	Vector hypo = p - p1, base = p2 - p1;
	return (p1 + base * dot(hypo, base) / base.norm());
}


int main() {
	int i, q, x, x1, x2, y, y1, y2;
	Point ans;
	cin >> x1 >> y1 >> x2 >> y2 >> q;
	Point p1(x1, y1), p2(x2, y2);
	for (i = 0; i < q; i++) {
		cin >> x >> y;
		Point p(x, y);
		ans = project(p, p1, p2);
		cout << setprecision(15) << ans.x << " " << ans.y << endl;
	}
	return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n,p,ans=1;
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	for(int i=2;i<200000;i++){
		int cnt=0;
		while(p%i == 0){
			cnt++;
			p = p/i;
		}
		for(int j=0;j<cnt/n;j++){
			ans *= i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define int long long

#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
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111],B[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>B[i];

    if(accumulate(A,A+N,0ll)<accumulate(B,B+N,0ll)){
        cout<<-1<<endl;
        return 0;
    }

    int uku=0;

    int ans=0;
    vint latte;
    rep(i,N){
        if(A[i]==B[i])continue;
        if(A[i]<B[i]){
            ans++;
            uku+=B[i]-A[i];
        }
        else{
            latte.pb(A[i]-B[i]);
        }
    }
    sort(all(latte));
    while(uku>0){
        uku-=latte.back();
        ans++;
        latte.pop_back();
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    bool x[n] = {};
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int p;
            cin >> p;
            x[p-1] = 1;
        }
    }
    int count = 0;
    for(int i = 0; i < n;i++){
        if(x[i] == 0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3592
# https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_5_A
# 全点間の距離を求めているとO(n**2)でパソコンが爆発する。
# P354はO(n)のシンプルなアルゴリズム。
# 厳密な証明は知らないけど、直感的に良さそう

from collections import deque, defaultdict
Tree = defaultdict(lambda: [])

# input data
N = int(input())
for _ in range(N - 1):
    s, t, w = list(map(int, input().split()))
    Tree[s].append((t, w))
    Tree[t].append((s, w))


def bfs(Tree, n_V, s):
    '''
    指定した点sからの単一始点で各点までの距離を返す。
    n_Vは頂点の数
    Treeはdefault dictで、valueには(隣接ノード,そこまでのコスト)がリスト形式で格納されているとする。
    '''
    INF = 10**9
    Dists = [INF] * n_V  # 距離の初期化 #こいつを更新して返すことにする
    is_visited = [False] * n_V
    is_visited[s] = True
    que = deque([(s, 0)])  # (ノード番号,そこまでたどり着くためのコスト)
    while que:
        cur, cost = que.popleft()
        Dists[cur] = cost
        for nx_node, nx_cost in Tree[cur]:
            if is_visited[nx_node]:
                continue
            que.append((nx_node, nx_cost + cost))
            is_visited[nx_node] = True

    return Dists


# 任意の点から一番遠い点を求めて、そこからさらに一番遠い点がほしい
Dists = bfs(Tree, N, 0)
next_node = Dists.index(max(Dists))
Dists = bfs(Tree, N, next_node)

print(max(Dists))



Measured memory_bytes: 52780
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] l = new int[n];
    for(int i=0; i<n; i++){
      l[i] = Integer.parseInt(sc.next());
    }
    int ans = 0;

    Arrays.sort(l);

    for(int i=0; i<n; i++){
      for(int j=0; j<i; j++){
        if(l[j] == l[i]){
          continue;
        }
        for(int k=0; k<j; k++){
          if(l[j] == l[k]){
            continue;
          }
          if(l[j]+l[k]>l[i]){
            ans++;
            // System.out.format("%d,%d,%d\n",l[i],l[j],l[k]);
          }
        }
      }
    }
    
    System.out.println(ans);
   
    sc.close();
    return;
  }
  
}


Measured memory_bytes: 36016
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let a: u32 = read();
    let b: u32 = read();
    let mut ans = 0;
    for i in 1..n+1 {
        let s = i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
        if s >= a && s <= b {
            ans += i
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include "iostream"
using namespace std;

int main()
{

	int r, c;

	int sumsum = 0;

	cin >> r >> c;

	int hyou[101][101];

	int a;//インプット要素変数

	int csum = 0;

	//インプット
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> a;
			hyou[i][j] = a;
		}
	}

	//合計
	for (int i = 0; i < r; i++){
		int rsum = 0;//行の合計変数
		for (int j = 0; j < c; j++){
			cout << hyou[i][j] << " ";
			rsum += hyou[i][j];
		}
		cout << rsum << endl;
	}
	//ここまで正解

	for (int i = 0; i < c; i++){
		csum = 0;//列の合計変数
		for (int j = 0; j < r; j++){

			csum += hyou[j][i];
			
		}
		cout << csum << " ";
		sumsum += csum;

	}
	cout << sumsum 
	<< endl;

	/*
	//↓未完成
	//合計最終行
	for (int j = 0; j < r; j++){
	int csum = 0;
	for (int i = 0; i < c; i++){
	csum += hyou[i][j];
	}
	cout << csum << " ";
	}
	cout <<endl;

	*/

	return 0;
}



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

int N, K;
ll ans = numeric_limits<ll>::max();

int main()
{
    cin >> N >> K;
    vector<pair<ll, ll>> p, q;
    for (int i = 0; i < N; i++)
    {
        ll x, y;
        cin >> x >> y;
        p.emplace_back(x, y);
    }

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

    for (int x1 = 0; x1 < N; x1++)
    {
        for (int x2 = x1 + 1; x2 < N; x2++)
        {
            for (int y1 = 0; y1 < N; y1++)
            {
                for (int y2 = y1 + 1; y2 < N; y2++)
                {
                    auto p1 = p[x1], p2 = p[x2], p3 = p[y1], p4 = p[y2];
                    if (p3.second > p4.second)
                        swap(p3, p4);
                    if (p1.second > p4.second || p2.second > p4.second || p1.second < p3.second || p2.second < p3.second || p3.first < p1.first || p4.first < p1.first || p3.first > p2.first || p4.first > p2.first)
                        continue;
                    int cnt = 0;
                    for (int i = 0; i < N; i++)
                        cnt += (p1.first <= p[i].first && p[i].first <= p2.first && p3.second <= p[i].second && p[i].second <= p4.second);
                    if (cnt < K)
                        continue;
                    ans = min(ans, (p2.first - p1.first) * (p4.second - p3.second));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (arr.shift() != 0) {
    var a = arr.shift().split(" ").map(Number);
    var min = Infinity;
    a.sort(function(a, b) {
        min = Math.min(min, Math.abs(a - b));
        return a - b;
    });
    console.log(min);
}

Measured memory_bytes: 18388
#include <iostream>
using namespace std;
 
int main(){ 
    int d,n;
    cin>>d>>n;
    if(d==0){
        if(n==100){
            cout<<101;
        }else{
            cout <<n;
        }
    }else if(d==1){
        if(n==100){
            cout<<10100;
        }else{
            cout<<100*n;
        }
    }else{
        if(n==100){
            cout<<1010000;
        }else{
            cout<<10000*n;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()
#define vl vector<lli>
#define pll pair<lli,lli>
#define vpll vector<pll >
const lli MAX=100005;

int main(){
	lli n,W;
	cin>>n>>W;
	lli w[n],v[n];
	loop(i,0,n) cin>>w[i]>>v[i];
	lli dp[n+1][W+1];
	loop(i,0,n+1){
		loop(j,0,W+1){
			if(i==0 || j==0) dp[i][j]=0;
			else if(w[i-1]>j) dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
			}
		}
	}
	cout<<dp[n][W];
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll num = n / (a+b);
    if (n - num * (a + b) <= a)
    {
        cout << num * a + (n - num * (a+b)) << endl;
    }
    else
    {
        cout << num * a + a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

  private void exec() {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String s = scan.next();
    int max = 0;
    for (int i = 1; i < s.length() - 1; i++) {
      Set<String> x = createSet(s.substring(0, i));
      Set<String> y = createSet(s.substring(i));
      int count = 0;
      for (String value : x) {
        if (y.contains(value)) {
          count++;
        }
      }
      if (count > max) {
        max = count;
      }
    }
    System.out.println(max);
  }

  private Set<String> createSet(String value) {
    Set<String> charSet = new HashSet<String>();
    for (int i = 0; i < value.length(); i++) {
      charSet.add(value.substring(i, i + 1));
    }
    return charSet;
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
  int cnt = 0;
  int n;
  int a;
  cin >> n;
  deque<int> S;
  
  for (int i = 0; i < n; i++){
    cin >> a;
    S.push_back(a);
  }

  sort(S.begin(), S.end());
  int q;
  cin >> q;
  int T[q];

  for (int i = 0; i < q; i++){
    cin >> T[i];
    if (binary_search(S.begin(), S.end(), T[i])){
      cnt++;
    }
  }
  cout << cnt << endl;

  return (0);
}

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vector<int> count(26);
    string str = s[0];
    for (int i = 0; i < str.size(); i++)
    {
        count[str[i] - 'a']++;
    }
    for (int i = 1; i < n; i++)
    {
        string t = s[i];
        vector<int> cnt(26);
        for (int j = 0; j < t.size(); j++)
            cnt[t[j] - 'a']++;
        for (int j = 0; j < 26; j++)
            count[j] = min(count[j], cnt[j]);
    }
    string ans = "";
    for (int i = 0; i < 26; i++)
    {
        if (count[i])
        {
            for (int j = 0; j < count[i]; j++)
            {
                ans += i + 'a';
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char character_a, character_t;
  scanf("%c %c", &character_a, &character_t);
  if(character_a == 'H') {
    printf("%c\n", character_t);
  } else {
    if(character_t == 'H') {
      printf("D\n");
    } else {
      printf("H\n");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=0;
    set<ll> s;
    map<ll,ll> mp;
    set<ll>::iterator itr;
    for(int i=0;i<n;i++){
        if(!s.empty()){
            itr=s.lower_bound(a[i]);
            if(itr==s.begin()){
                ans++;
                s.insert(a[i]);
                mp[a[i]]++;
            }
            else{
                itr--;
                mp[*itr]--;
                if(mp[*itr]==0){
                    s.erase(*itr);
                }
                s.insert(a[i]);
                mp[a[i]]++;
            }
        }
        else{
            ans++;
            s.insert(a[i]);
            mp[a[i]]++;
        }
    }
    cout << ans<<endl;
    return 0;
}



Measured memory_bytes: 11776
#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 N,M;
vector<int> E[2020];

int EE[2020][2],TE[2020][2];
set<int> VE[2020];
vector<int> EL[2020];
int dir[2020];
int cnt[2020][2020];

void shrink(int cur) {
	FORR(c,EL[cur]) dir[c%M] = c/M;
}

int dfs(int cur,int pre,int tar) {
	if(cur==tar) {
		cnt[pre][cur]++;
		return 1;
	}
	else {
		int ok=0;
		FORR(e,E[cur]) if(e!=pre) ok+=dfs(e,cur,tar);
		if(ok&&pre) cnt[pre][cur]++;
		return ok>=1;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	
	dfs(1,1,0);
	FOR(i,M) {
		cin>>EE[i][0]>>EE[i][1];
		dfs(EE[i][0],0,EE[i][1]);
		TE[i][0]=EE[i][0];
		TE[i][1]=EE[i][1];
		VE[EE[i][0]].insert(i);
		VE[EE[i][1]].insert(i+M);
		EL[i].push_back(i);
	}
	
	
	int ret=0;
	for(y=1;y<=N;y++) for(x=1;x<y;x++) ret+=min(2,cnt[x][y]+cnt[y][x]);
	cout<<ret<<endl;
	
	while(true) {
		for(i=1;i<=N;i++) if(E[i].size()==1) break;
		if(i>N) break;
		int cur=i;
		vector<int> delcand;
		FORR(v,VE[cur]) if(v<M && VE[cur].count(v+M)) {
			delcand.push_back(v);
			shrink(v);
		}
		FORR(d,delcand) VE[cur].erase(d),VE[cur].erase(d+M);
		
		
		int p=E[cur][0];
		if(VE[cur].size()==1) {
			int l=*VE[cur].begin();
			TE[l%M][l/M]=p;
			VE[p].insert(l);
		}
		else if(VE[cur].size()>=2) {
			int a=*VE[cur].begin()%M;
			
			VE[TE[a][0]].erase(a);
			VE[TE[a][1]].erase(a+M);
			int b=*VE[cur].begin()%M;
			VE[TE[b][0]].erase(b);
			VE[TE[b][1]].erase(b+M);
			
			if(TE[a][0]==cur) {
				FORR(e,EL[a]) {
					if(e>=M) e-=M;
					else e+=M;
				}
				swap(TE[a][0],TE[a][1]);
			}
			if(TE[b][1]==cur) {
				FORR(e,EL[b]) {
					if(e>=M) e-=M;
					else e+=M;
				}
				swap(TE[b][0],TE[b][1]);
			}
			TE[a][1]=TE[b][1];
			FORR(e,EL[b]) EL[a].push_back(e);
			EL[b].clear();
			VE[TE[a][0]].insert(a);
			VE[TE[a][1]].insert(a+M);
			
			FORR(v,VE[cur]) {
				TE[v%M][v/M]=p;
				VE[p].insert(v);
			}
		}
		VE[cur].clear();
		E[p].erase(remove(ALL(E[p]),cur),E[p].end());
		E[cur].clear();
	}
	
	for(i=1;i<=N;i++) FORR(v,VE[i]) shrink(v);
	FOR(i,M) {
		if(dir[i]) cout<<EE[i][1]<<" "<<EE[i][0]<<endl;
		else cout<<EE[i][0]<<" "<<EE[i][1]<<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);
	cout.tie(0); solve(); return 0;
}


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

int gcd(int a, int b);

int main() {
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else return gcd(b, a % b);
}

Measured memory_bytes: 1160
#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 n ;
  cin >> n ;
  ll ans = 0 ;
  rep(i,n+1){
    if(i%3 == 0 )continue ;
    if(i%5 == 0 )continue ;
    ans += i ;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;
int main(){
  long double pi =3.14159265358979323846;
  long long int A,B,H,M;
  long double x;
  cin>>A>>B>>H>>M;
  
  x=A*A+B*B-2.0*A*B*cos(abs(H*2*pi/12.0+pi*M/360.0-M*pi/30.0));
  cout<<setprecision(12)<<sqrt(x)<<endl;
}





Measured memory_bytes: 4152