akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;


void search(int h, int w, int tairu[22][22], int check[22][22]){
    if(check[h][w]==1)return;
    if(tairu[h][w]==0)return;
    
    check[h][w]=1;
    search(h+1,w,tairu,check);
    search(h-1,w,tairu,check);
    search(h,w+1,tairu,check);
    search(h,w-1,tairu,check);
}






int main()
{

    int H,W;
    while(cin>>W>>H){
        if(W==0&&H==0)break;
        int tairu[22][22]={0};
        int start_w, start_h;
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                char input;
                cin>>input;
                if(input=='.')tairu[i][j]=1;
                if(input=='@'){
                    tairu[i][j]=1;
                    start_w=j;
                    start_h=i;
                }
            }
        }
        //
        
        int check[22][22]={0};
        search(start_h, start_w, tairu, check);
        int ans=0;
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                ans+=check[i][j];
            }
        }
        cout<<ans<<endl;
        
        
        
    }
}

Measured memory_bytes: 1176
import copy
from collections import deque


def shori(d, r, max_distance):
    si, sj = d.popleft()
    next_kouho = [
        {'x': si + 1, 'y': sj},
        {'x': si - 1, 'y': sj},
        {'x': si, 'y': sj + 1},
        {'x': si, 'y': sj - 1}
    ]
    for nk in next_kouho:
        if (0 <= nk['x'] < h) and (0 <= nk['y'] < w) and (r[nk['x']][nk['y']] == '.'):
            r[nk['x']][nk['y']] = r[si][sj] + 1
            if max_distance < r[si][sj] + 1:
                max_distance = r[si][sj] + 1
            d.append((nk['x'], nk['y']))
    return d, r, max_distance


if __name__ == '__main__':
    h, w = list(map(int, input().split(" ")))
    s = []
    r = []
    for i in range(h):
        s.append(list(input()))

    d = deque()
    max_distance = 0
    # start 総当り
    for si in range(h):
        for sj in range(w):
            r = copy.deepcopy(s)
            if r[si][sj] == '.':
                r[si][sj] = 0
                d.append((si, sj))

                while True:
                    if len(d) == 0:
                        break
                    else:
                        d, r, max_distance = shori(d, r, max_distance)

    print(max_distance)

Measured memory_bytes: 3444
n,k,q = map(int, input().split())
A = [int(input()) for _ in range(q)]
L = [k] * n
P = [q] * n
for i in A:
  L[i-1] += 1
for k in [a - b for a, b in zip(L, P)]:
  if k > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 15196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<string,int>;

int main(){
   int n,x;
   cin >> n >> x;
   auto m = vector<int>(n,0);
   for (int i = 0; i < n; i++)
   {
      cin >> m[i];
   }

   x -= accumulate(m.begin(),m.end(),0);

   cout << x / *min_element(m.begin(),m.end()) + m.size() ;  
}
  
  

Measured memory_bytes: 256
/**
 *   created: 25 January 2019  14:14:58
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007

void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
ll n,w;
vector< vector<ll> > val;
vector< vector<ll> > dp;
ll knapsack(ll cs, ll wt)
{
	//cout<<cs<<" "<<wt<<endl;
	if(wt<0){
		//cout<<"return -inf"<<endl;
		return -INFLL;
	}
	if(cs>=n){
		////cout<<"return 0"<<endl;
		return 0;
	}
	
	if(dp[cs][wt]!=-1){
		//cout<<"return dp state "<<dp[cs][wt]<<endl;
		return dp[cs][wt];
	}
	dp[cs][wt] = max(val[cs][1]+knapsack(cs+1, wt-val[cs][0]), knapsack(cs+1,wt));
	//cout<<dp[cs][wt]<<" "<<cs<<" "<<wt<<endl;
	return dp[cs][wt];// = max(val[cs][1]+knapsack(cs+1, wt-val[cs][0]), knapsack(cs+1,wt));
}
int main()
{
	optimizeIO();
	cin>>n>>w;
	val.resize(n, vector<ll>(2));
	dp.resize(n,vector<ll>(w+1,-1));
	F(i,0,n-1){
		ll x,y;
		cin>>x>>y;
		val[i][0]=x;
		val[i][1]=y;
	}
	cout<<knapsack(0,w);
	return 0;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	vi ans;
	int c=0;
	while((1LL<<(c+1))-1<=n)c++;
	vi ad(c,0);
	n-=((1LL<<(c))-1);
	int s=0;
	REP(i,c)
		if((n>>i)&1){
			ad[i]=1;
			s++;
		}
	REP(i,s+c)
		ans.PB(i);
	int idx=0;
	REP(i,c){
		if(ad[i])ans.PB(idx++);
		ans.PB(s+c-1-i);
	}
	FOR(i,s+c,(s+c)*2){
		int j=(s+c)-1-(i-(s+c))+(s+c);
		if(i<j)swap(ans[i],ans[j]);
	}
	cout<<ans.size()<<endl;
	REP(i,ans.size())
		print(ans[i]+1,i==int(ans.size())-1?1:2);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>
#include <vector>
//#include <boost/integer/common_factor_rt.hpp> // gcd, lcm
//#include <bits/stdc++.h>

using namespace std;

int main()
{
	string S, T;
	cin >> S;
	cin >> T;
	bool j = true;
	if (S.size() != (T.size() - 1))
	{
		cout << "Noa" << endl;
		return 0;
	}
	T.pop_back();

	if (!S.compare(0,S.size(),T,0,S.size()))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int H=sc.nextInt();
        int W=sc.nextInt();
        int D=sc.nextInt();
        int B[][]=new int[H*W+1][2];
        int dist[]=new int[H*W+1];

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                int a=sc.nextInt();
                B[a][0]=i;
                B[a][1]=j;
            }
        }

        for(int i=1;i<=D;i++){
            dist[i]=0;
            for(int j=1;i+D*j<=H*W;j++){
                dist[i+D*j]=dist[i+D*(j-1)]+Math.abs(B[i+D*j][0]-B[i+D*(j-1)][0])+Math.abs(B[i+D*j][1]-B[i+D*(j-1)][1]);
            }
        }

        int Q=sc.nextInt();
        for(int i=0;i<Q;i++){
            int l=sc.nextInt();
            int r=sc.nextInt();
            System.out.println(dist[r]-dist[l]);
        }
        sc.close();
    }
}

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

using namespace std;

string line;
int str_len;

bool is_finish() {
  for(int i=0; i<str_len-3; i++) {
    if(line[i] == 't') {
      if(line[i+1] == 'h') {
        if(line[i+2] == 'e') { return true; }
        else if(line[i+2] == 'i' && line[i+3] == 's') { return true; }
        else if(line[i+2] == 'a' && line[i+3] == 't') { return true; }
      }
    }
  }
  return false;
};


int main() {
  while(getline(cin, line)) {
    str_len = line.length();

    for(int j=0; j<26; j++) {
      if(is_finish()) { 
        cout << line << endl;
        break; 
      }

      for(int j=0; j<str_len; j++) {
        if('a' <= line[j] && line[j] < 'z') {
          line[j] += 1;
        }
        else if(line[j] == 'z') {
          line[j] = 'a';
        }
      }
    }
  }
  return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<long> l(n);
    long ans=0;
    rep(i,n){
        cin>>l[i];
        rep(j,i){
            if(l[i]==l[j]) continue;
            rep(k,j){
                if(l[i]==l[k] || l[j]==l[k]) continue;
                if(l[i]<l[k]+l[j] && l[k]<l[i]+l[j] && l[j]<l[k]+l[i]) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {

    int64_t A, B, K;
    cin >> A >> B >> K;

    if (A >= K) {
        cout << A - K << " " << B << endl;
    } else if (B >= (K - A)) {
        cout << 0 << " " << B - (K - A) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
A,B,C,D = (int(T) for T in list(input()))
ABCD = [A+B+C+D,A+B+C-D,A+B-C+D,A+B-C-D,A-B+C+D,A-B+C-D,A-B-C+D,A-B-C-D]
Op   = ['+++','++-','+-+','+--','-++','-+-','--+','---']
Disp = list(Op[ABCD.index(7)])
print('{}{}{}{}{}{}{}=7'.format(A,Disp[0],B,Disp[1],C,Disp[2],D))

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int count = 0;
  for (int i = 100; i > 0; i--) {
    if (a % i == 0 && b % i == 0) {
      count++;
      if (count == k) {
        P(i);
        return 0;
      }
    }

  }
  return 0;

}

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

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

   bool flag = false;

   for(int i=a;i<=b;i++){
      if(i%k==0) flag = true;
      
   }
   if(flag)
      cout << "OK" << endl;
   else
      cout << "NG" << endl;
   return 0;  
}

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


#define dhai_machli ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)



using namespace std;

int main()
{



    dhai_machli;

    
    int a[5];

    for(int i=0; i<5; i++)
    {
        cin>>a[i];

        if(a[i] == 0)
        {
            cout<<i+1<<endl;
        }
    }



    return 0;
}

Measured memory_bytes: 3596
use io::*;
use std::collections::HashMap;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let m: usize = sc.next();
    let mut v: Vec<usize> = sc.next_vec(n);
    for i in 1..n {
        v[i] += v[i-1];
    }
    let mut map: HashMap<usize,usize> = HashMap::new();
    for x in v {
        let y = x % m;
        let c = map.entry(y).or_insert(0);
        *c += 1;
    }
    let mut ans = 0;
    for (k,x) in map.iter() {
        if *k == 0 {
            ans += x * (x + 1) / 2;
        } else {
            ans += x * (x - 1) / 2;
        }
    }
    println!("{}", ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 14588
#def main():
#    N = int(input())
#    S = input()
#    R = []
#    G = []
#    B = []
#    for i, s in enumerate(S):
#        if s == "R":
#            R.append(i)
#        elif s == "G":
#            G.append(i)
#        else:
#            B.append(i)
#    s = 0
#    for i in R:
#        for j in G:
#            for k in B:
#                if abs(i-j) != abs(j-k) and abs(i-j) != abs(k-i) and abs(j-k) != abs(k-i):
#                    s += 1
#    print(s)
#if __name__ == '__main__':
#    main()
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r*g*b
for i in range(N):
    for j in range(i+1, N):
        k = 2*j -i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -=1
print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

struct compare
{
    bool operator()(const double& l, const double& r)
    {
        return l > r;
    }
};

int main() {
    fastIO
    int i, n;
    cin >> n;
    priority_queue<double, vector<double>, compare> arr;

    vi a(n, 0);
    fo(i, n) {
        cin >> a[i];
        arr.push(a[i]);
    }

    for(i = 0; i < n - 1; i++)
    {
        double x = arr.top();
        arr.pop();
        double y = arr.top();
        arr.pop();
//        cout << x << " " << y << endl;
        double temp = (x + y) / 2.0;
        arr.push(temp);
    }
    cout <<fixed << setprecision(10)<< arr.top() <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#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 = uint32_t;
using namespace std;

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

template <typename T>
struct edge {
    int to; T cost;

    edge(int to, T cost) : to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>> > &G){
    size_t n=G.size();
    using P = pair<T, int>;
    vector<T> d(n, INF<T>);
    priority_queue<P,vector<P>,greater<> > Q;
    d[s]=0;
    Q.emplace(d[s],s);
    while(!Q.empty()){
        T cost;
        int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}


int main() {
    int n, m, p, a, b;
    while(cin >> n >> m >> p >> a >> b, n){
        a--; b--;
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        vector<vector<edge<double>>> G(m<<n);
        for (int i = 0; i < p; ++i) {
            int x, y; double z; cin >> x >> y >> z;
            x--; y--;
            for (int j = 0; j < (1<<n); ++j) {
                for (int k = 0; k < n; ++k) {
                    if(j & (1<<k)){
                        int to = j^(1<<k);
                        G[(x<<n)+j].emplace_back((y<<n)+to, z/v[k]);
                        G[(y<<n)+j].emplace_back((x<<n)+to, z/v[k]);
                    }
                }
            }
        }
        using P = pair<double, int>;
        vector<double> d(m<<n, INF<double>);
        priority_queue<P,vector<P>,greater<> > Q;
        d[((a+1)<<n)-1]=0;
        Q.emplace(0, ((a+1)<<n)-1);
        while(!Q.empty()){
            double cost;
            int i;
            tie(cost, i) = Q.top(); Q.pop();
            if(d[i] < cost) continue;
            for (auto &&e : G[i]) {
                auto cost2 = cost + e.cost;
                if(d[e.to] <= cost2) continue;
                d[e.to] = cost2;
                Q.emplace(d[e.to], e.to);
            }
        }
        double ans = INF<double>;
        for (int i = 0; i < (1<<n); ++i) {
            ans = min(ans, d[(b<<n)+i]);
        }
        if(ans >= INF<int>){
            puts("Impossible");
        }else {
            printf("%.10lf\n", ans);
        }
    }

    return 0;
}


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


#define ALL(a) 		(a.begin() , a.end())
#define ll 			long long int
#define ff          first
#define ss          second
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,a,b)   	for(ll i =a;i<=b;i++)
#define inf 		INT_MAX
#define pll 		pair<ll,ll>
#define mat 		vector<vector<ll>>


#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 //debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }


 

const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
 
bool checkp2(ll n){
	return n && !(n & (n-1));
}

ll numsetbit(ll n){
	ll count = 0;
	for(;n;count++){
		n = n & (n-1);
	}
	return count;
}
 
ll powe(ll x , ll n ,const ll mod){
    x = x % mod;
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x) % mod;
		}
		n = n>>1;
		x = ((x % mod) * (x % mod)) % mod;
	}
	return po;
}

ll powm(ll x , ll n){
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x);
		}
		n = n>>1;
		x = (x*x);
	}
	return po;
} 



bool isPrime(ll x){
	if(x < 2)
		return 0;
	for(ll y = 2; y * y <= x; y++){
		if(x % y == 0){
			return 0;
		}
	}
	return true;
}
const ll  mod = 1e9 + 7;
void solve(){

	ll n;
	cin>>n;

	vector<ll> a(n) , b(n);

	for(ll i = 0;i<n;i++){
		cin>>a[i];
	}
	for(ll i = 0;i<n;i++){
		cin>>b[i];
	}
	
	reverse(b.begin() , b.end());

	ll lpt = 0 , rpt = n-1;

	for(ll i = 0;i<n;i++){

		if(a[i] == b[i]){
			
			if(b[lpt] != b[i] && a[lpt] != b[i]){
				swap(b[i] , b[lpt]);
				lpt++;
			}
			else if(b[rpt] != b[i] && a[rpt] != b[i]){
				swap(b[i] , b[rpt]);
				rpt--;
			}
			else{
				cout<<"No"<<endl;
				return;
			}
		}
	}

	for(ll i = 0;i<n;i++){
		if(a[i] == b[i]){
			cout<<"No"<<endl;
			return;
		}
	}

	cout<<"Yes"<<endl;

	for(ll i = 0;i<n;i++){
		cout<<b[i]<<" ";
	}
	cout<<endl;
}

int main(){
	
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 6376
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024
#define ARRAY_SIZE 100

int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[ARRAY_SIZE];
	int change_count = 0;

	for(int i = 0; i < n; i++){
		cin >> array[i];
	}

	int tmp = 0;
	for(int i = n-1;i > 0;i--){
		for(int j = 0; j < i;j++){
			if(array[j] > array[j+1]){
				tmp = array[j+1];
				array[j+1] = array[j];
				array[j] = tmp;
				change_count++;
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(i != n-1){
			printf("%d ",array[i]);
		}else{
			printf("%d\n",array[i]);
		}
	}
	printf("%d\n",change_count);
}



Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin >> n >> m) {
    int w[n], v[3][n];
    REP(i,n) {
      string s;
      getline(cin, s);
      getline(cin, s);
      cin >> w[i] >> v[0][i]>>v[1][i]>>v[2][i];
    }
    int dp[3][m+1];
    memset(dp,0,sizeof(dp));
    int res = 0;
    REP(k,3) {
      REP(i,n) {
        for (int j=w[i]; j<=m; ++j) {
          dp[k][j] = max(dp[k][j], dp[k][j-w[i]] + v[k][i]);
        }
      }
      res = max(res, dp[k][m]);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define N ((ll)101*1000)
#define INF ((ll)2e9)

string s;

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]=='C')
			for(int j=i+1;j<s.size();j++)
				if(s[j]=='F')
					return cout<<"Yes",0;
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>

using namespace std;

vector<int> v[51];

int main(){
  int n, m, a[51], b[51];
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  int cnt=0;
  for(int i=0;i<m;i++){
    queue<int> q1, q2;
    int check[51];
    int tmpa = a[i], tmpb=b[i];
    bool ans=false;
    memset(check, 0, sizeof(check));
    while(!q1.empty())q1.pop();
    for(int j=0;j<v[tmpa].size();j++){
      if(v[tmpa][j]!=tmpb)q1.push(v[tmpa][j]);
    }
    check[tmpa]=1;
    while(!q1.empty()){
      while(!q2.empty())q2.pop();
      while(!q1.empty()){
        int fr = q1.front();q1.pop();
        for(int j=0;j<v[fr].size();j++){
          if(v[fr][j]==tmpb){
            ans=true;
            break;
          }
          if(check[v[fr][j]]==0){
            check[v[fr][j]] = 1;
            q2.push(v[fr][j]);
          }
        }
        if(ans)break;
      }
      if(ans)break;
      q1 = q2;
    }
    if(!ans){
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main() {
    ll N,W;
    cin >> N >> W;
    vector<vector<ll>> dp(N+10,vector<ll>(W+10));
    vector<ll> weight(N+10),value(N+10);
    for(int i=0;i<N;i++){
        cin >> weight[i] >> value[i];
    }
    for(int i=1;i<=N;i++){
        for(int j=0;j<=W;j++){
            if(j<weight[i-1]) dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

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

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

template <typename T>
T gcd(const T a, const T b)
{
    return b ? gcd(b, a % b) : a;
}

int main()
{
    int N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N);

    ll maxi = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        maxi = max(maxi, A[i]);
    }
    ll g = A[0];
    for (int i = 1; i < N; i++) {
        g = gcd(g, A[i]);
    }
    if (K % g == 0 and K <= maxi) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>

using namespace std;

int selectSort(int *A, int N);
void display(int *A, int N);

int main(){
    int N;
    int A[100];
    int cnt;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    cnt = selectSort(A, N);
    display(A, N);
    cout << cnt <<endl;
}

int selectSort(int *A, int N){
    int cnt=0;
    for(int i=0; i<N; i++){
        int minj =i;
        for(int j=i; j<N; j++){
            if (A[j] < A[minj]) minj=j;
        }
        if(minj!=i) cnt+=1;
        int tmp;
        tmp=A[i];
        A[i]=A[minj];
        A[minj]=tmp;
    }
    return cnt;
}
void display(int *A, int N){
  for(int i=0; i<N-1 ;i++){
    cout <<A[i] << " ";
  }
  cout << A[N-1] << endl;
}


Measured memory_bytes: 3100
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

string S;

bool isGood(string S) {
	if (S.size() == 0)
		return true;
	for (int i = 0; i < S.size() - 1; i++)
		if (S[i] != S[i + 1])
			return false;
	return true;
}

int main() {
	
	cin >> S;
	int l = S.size();

	for (int i = 0; i <= l / 2; i++) {
		if (isGood(S.substr(i, l - 2 * i))) {
			cout << (l - i) << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;

i64 dp[1010][1010];
vector<i64> c,w;

i64 ret[1010];

int main(){
  cin >> N;
  c.resize(N + 1);
  w.resize(N + 1);
  rep(i,1,N) cin >> c[i] >> w[i];
  rep(i,1,N) w[i] += w[i - 1];


  rep(i,1,N) dp[i][i] = 1;
  for(int d = 1;d <= N;d++){
    for(int l = 1;l + d <= N;l++){
      int r = l + d;
      if(dp[l][r - 1] == 1 && (w[r - 1] - w[l - 1]) <= c[r]){
        dp[l][r] = 1;
      }
      if(dp[l + 1][r] == 1 && (w[r] - w[l + 1 - 1]) <= c[l]){
        dp[l][r] = 1;
      }
    }
  }

  for(int i = 1;i <= N;i++) ret[i] = 1e9;
  for(int i = 1;i <= N;i++){
    for(int j = i;j <= N;j++){
      if(dp[i][j] == 1){
        ret[j] = min(ret[j] , ret[i - 1] + 1);
      }
    }
  }

  cout << ret[N] << endl;
}



Measured memory_bytes: 7728
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

T = S

while 1:
	if T.count("()") == 0:
		break
	try:
		T = T.replace("()", "")
	except:
		pass
l = 0
r = 0
for x in T:
	if x == ")":
		l += 1
	else:
		r += 1
print("("*l + S + ")"*r)


Measured memory_bytes: 13588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    char s;
    bool b = true;
    for(int i; i<N; ++i){
        cin >> s;
        if(s == 'Y'){
            printf("Four");
            b = false;
            break;
        }
    }
    if(b){
        printf("Three");
    }
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef pair<int,int> pii;
int main() {
  int n, m;
  while(cin >> n >> m, n||m) {
    int a[n];
    REP(i, n)
      cin >> a[i];
    pii min;
    int ans;
    REP(i, n) {
      pii now = pii(a[i] * (m / a[i]), a[i]);
      //printf("%d (%d,%d)\n", i, now.first, now.second);
      if (i==0 || min > now) {
        min = now;
        ans = i+1;
      } else if (min == now) ans = n;
      else continue;
        
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
print(x3, y3, x4, y4)


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


  
int main(){
  int n;
  cin >> n;
  int ans=0;
  vector<vector<pair<int,int>>> vec(n,vector<pair<int,int>>(14));
  vector<int>a(n);
  rep(i,n){
    int A;
    cin >> A;
    a[i]=A;
    rep(j,A){
      int x,y;
      cin >> x >> y;
      vec[i][j]={x-1,y};
    }
  }
  for(int bit=0; bit<(1<<n); bit++){
    bool ok = true;
    int sum = __builtin_popcount(bit);
    rep(i,n){
      if(!(bit&(1<<i))) continue;
      rep(j,a[i]){
        if(((bit >> vec[i][j].first)&1)^vec[i][j].second) ok=false;
      }
    }
    if(ok){
      if(ans<sum)ans=sum;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
   l[i]=gcd(l[i-1],A[i])
   r[i]=gcd(r[i-1],A[N-1-i])
gcdlist = [1,l[N-2],r[N-2]]
for i in range(N-2):
   gcdlist.append(gcd(l[i],r[N-3-i]))

print(max(gcdlist))

Measured memory_bytes: 16580
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))

b= defaultdict(int)
ans = []
ans2 = []
for i in range(n):
    b[a[i]] += 1
    if b[a[i]] == 2:
       ans.append(a[i])
    if b[a[i]] == 4:
        ans2.append(a[i])
ans = sorted(ans,reverse=True)
ans2 = sorted(ans2,reverse=True)
if len(ans) <= 1 and len(ans2) == 0:
    print(0)
    exit()
if len(ans2) == 0:
    print(ans[0]*ans[1])
elif len(ans) <= 1:
    print(ans2[0]**2)
else:
    print(max(ans[0]*ans[1],ans2[0]**2))

Measured memory_bytes: 22052
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int one = 0;
		int two = 0;
		int three = 0;
		
		
		
		for(int i = 0; i < 10; i++) {
			int x = input.nextInt();
			//System.out.println("x = " + x);
			if (x > one) {
				three = two;
				two = one;
				one = x;
			}
			else if (x > two) {
				three = two;
				two = x;
			}
			else if(x > three) {
				three = x;
			}
		}
		
		System.out.println(one);
		System.out.println(two);
		System.out.println(three);
	}

}

Measured memory_bytes: 17168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
struct edge {
    ll from;
    ll to;
    ll cost;
};
int main(void){
    ll n,m;
    ll d[1000];
    vector<edge> edges;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        struct edge add;
        cin>>add.from>>add.to>>add.cost;
        add.from--,add.to--;
        edges.push_back(add);
    }
    fill(d,d+n,-INF);
    d[0]=0;
    for(int i=0;i<2*n;i++){
        for(auto e:edges){
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=min(d[e.from]+e.cost,INF);
                if(i>=n-1){
                    d[e.to]=INF;
                }
            }
        }
    }
    for(auto e:edges){
        if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
            d[e.to]=min(d[e.from]+e.cost,INF);
        }
    }
    if(d[n-1]==INF) cout<<"inf"<<endl;
    else cout<<d[n-1]<<endl;
}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.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 inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int N;
const int Size = 2e5;
ll A[Size + 5], DP[Size + 5][2][2];

int main(){
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", A + i);

  DP[1][1][1] = A[1];
  for (int i = 2; i <= N; i++){
    if (i % 2 == 0){
      DP[i][0][0] = max(DP[i-1][0][0], DP[i-1][0][1]);
      DP[i][1][0] = DP[i-1][1][1];
      DP[i][1][1] = DP[i-1][0][0] + A[i];
    }else{
      DP[i][0][0] = max(DP[i-1][1][0], DP[i-1][1][1]);
      DP[i][0][1] = DP[i-1][0][0] + A[i];
      DP[i][1][1] = DP[i-1][1][0] + A[i];
    }
  }

  if (N % 2 == 0){
    cout << max(DP[N][1][0], DP[N][1][1]) << endl;
  }else{
    cout << max(DP[N][0][0], DP[N][0][1]) << endl;
  }

  return 0;
}


Measured memory_bytes: 11572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int H,W,N,sx,sy,ans;
int tx,ty,pre_lastx,pre_lasty,tmpx,tmpy;
char g[1005][1005];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int bfs(int n){
    queue<pair<int,int> > q;
    bool flag[1005][1005]={0};
    tx=sx,ty=sy,pre_lastx=sx,pre_lasty=sy,tmpx=sx,tmpy=sy;
    q.push(pair<int,int>(tx,ty));
    int t=0;
    flag[tx][ty]=true;
    while(!q.empty()){
        pair<int,int> p=q.front();q.pop();

        if(g[p.first][p.second]==char('0'+n)){
            sx=p.first;sy=p.second;
            break;
        }
        for(int i=0;i<4;i++){
            tx=p.first+dx[i];ty=p.second+dy[i];
            if(tx>=0&&tx<H&&ty>=0&&ty<W&&g[tx][ty]!='X'&&!flag[tx][ty]){
                q.push(pair<int,int>(tx,ty));
                flag[tx][ty]=true;
                tmpx=tx;tmpy=ty;
            }
        }
        if(p.first==pre_lastx&&p.second==pre_lasty){
            pre_lastx=tmpx;pre_lasty=tmpy;
            t++;
        }
    }

    return t;
}

int main(){
    cin>>H>>W>>N;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>g[i][j];
            if(g[i][j]=='S'){
                sx=i;sy=j;
            }
        }
    }

    ans=0;
    for(int i=1;i<=N;i++){
        ans+=bfs(i);
    }
    cout<<ans<<endl;

    return 0;
}


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

#define DIV 1000000007

string S;
long long dp[4][100005];

int main(){
	cin >> S;

	dp[0][0] = 1;

	for(long long i = 0; i < S.size(); i++){
		dp[0][i+1] = dp[0][i];
		dp[1][i+1] = dp[1][i];
		dp[2][i+1] = dp[2][i];
		dp[3][i+1] = dp[3][i];
		if(S[i] == 'A'){
			dp[1][i+1] += dp[0][i];
		} else if(S[i] == 'B'){
			dp[2][i+1] += dp[1][i];
		} else if(S[i] == 'C'){
			dp[3][i+1] += dp[2][i];
		} else {
			dp[0][i+1] += 2 * dp[0][i];
			dp[1][i+1] += 2 * dp[1][i];
			dp[2][i+1] += 2 * dp[2][i];
			dp[3][i+1] += 2 * dp[3][i];
			dp[1][i+1] += dp[0][i];
			dp[2][i+1] += dp[1][i];
			dp[3][i+1] += dp[2][i];
		}
		dp[0][i+1] %= DIV; 
		dp[1][i+1] %= DIV; 
		dp[2][i+1] %= DIV; 
		dp[3][i+1] %= DIV; 
	}

	cout << dp[3][S.size()] << endl;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n ;
int mini,maxi;
int check[10];

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> n ;
    for (int i=1 ; i <= n ;i++) {
        int x;
        cin >> x;
        if ( x <= 399) {
            if ( !check[1] ) mini++ , check[1] = 1;
        }
        if ( x >= 400 && x <= 799) {
            if ( !check[2] ) mini++ , check[2] = 1;
        }
        if ( x >= 800 && x <= 1199) {
            if ( !check[3] ) mini++ , check[3] = 1;
        }
        if ( x >= 1200 && x <= 1599) {
            if ( !check[4] ) mini++ , check[4] = 1;
        }
        if ( x >= 1600 && x <= 1999) {
            if ( !check[5] ) mini++ , check[5] = 1;
        }
        if ( x >= 2000 && x <= 2399) {
            if ( !check[6] ) mini++, check[6] = 1;
        }
        if ( x >= 2400 && x <= 2799) {
            if ( !check[7] ) mini++, check[7] = 1;
        }
        if ( x >= 2800 && x <= 3199) {
            if ( !check[8] ) mini++, check[8] = 1;
        }
        if ( x >= 3200 ) maxi++;
    }
    cout << max(mini,1) << " " << maxi + mini;
}


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

using namespace std;

int main() {
    int n, k;
    cin>>n;
    cin>>k;
    int h[n];
    for (int i = 0; i < n; i++) cin>>h[i];
    vector<int> d(n, 0);
    for (int i = 1; i < n; i++) {
      int mi = INT_MAX;
      for (int j = i-1, l = 0; l < k && j >= 0; j--, l++) {
        mi = min(mi, d[j] + abs(h[i]-h[j]));
      }
      d[i] = mi;
    }
    cout<<d[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  if(a*b>=c*d){
    cout<<a*b<<endl;
  }else{
    cout<<c*d<<endl;
  }

}

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

#define fori(i, a, b) for (int i = a; i <= b; ++ i)
#define fori2(i, a, b) for (int i = a; i < b; ++ i)
#define ford(i, a, b) for (int i = a; i >= b; -- i)

using namespace std;

typedef long long ll;

const int N = 1e3;
const int M = 1e3;
const int c1[4] = {-1,0,1,0};
const int c2[4] = {0,1,0,-1};

int n, m;

queue <pair <int, int>> q;
bool a[N][M];

bool check(int u, int v) {
        return(u >= 0 && u < n && v >= 0 && v < m);
}

int cal() {
		int ans;

		ans = 0;

		while (! q.empty()) {
                ans ++;

                int b;

				b = q.size();

				fori2(i, 0, b) {
                        int u, v;

                        u = q.front().first;
                        v = q.front().second;

                        q.pop();

                        fori(i, 0, 4) {
                                int u2, v2;

                                u2 = u + c1[i];
                                v2 = v + c2[i];

                                if (check(u2, v2) && ! a[u2][v2]) {
                                        a[u2][v2] = true;

                                        q.push(make_pair(u2, v2));
                                }
                        }
				}
		}

		return(ans - 1);
}

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

		fori2(i, 0, n)
				fori2(j, 0, m) {
						char c;

						cin >> c;

						if (c == '#') {
								a[i][j] = true;

								q.push(make_pair(i, j));
						}
				}

		int ans;

		ans = cal();

		cout << ans;
}

int main() {
        ios::sync_with_stdio(false);
        process();
}



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

int n;
vector<vector<int> > C;
vector<vector<int> > D;

void bfs(int initCX, int initCY){
    queue<int> Q;
    Q.push(initCX);
    Q.push(initCY);
    D[initCX][initCY] = 0; // ?????????
    while(!Q.empty()){
        // ??????????´???????????????????
        int cx, cy;
        cx = Q.front();
        Q.pop();
        cy = Q.front();
        Q.pop();
        for(int i = -1; i <= 1; ++i){
            for(int j = -1; j <= 1; ++j){ // ??????????????????????????????
                if(C[cx + i][cy + j] == 1 && D[cx + i][cy + j] == -1){ // ???????????£??????????¨??????????
                    D[cx + i][cy + j] = D[cx][cy] + 1;
                    // ????????????????¨??????????????????????
                    Q.push(cx + i);
                    Q.push(cy + j);
                }
            }
        }
    }
}

int main(){
    int w, h;
    // index?????????????°???????????????£????????§???????????§h??¨w?????\?????????????????????????????????????????????????????????
    while(cin >> h >> w, w != 0 || h != 0){
        C = vector<vector<int> >(w+2, vector<int>(h+2, 0));
        for(int i=1; i<=w; ++i){
            for(int j=1; j<=h; ++j){
                cin >> C[i][j];
            }
        }
        D = vector<vector<int> >(w+2, vector<int>(h+2, 0));
        for(int i=1; i<=w; ++i){
            for(int j=1; j<=h; ++j){
                D[i][j] = -1;
            }
        }
        int n = 0;
        for(int i=1; i<=w; ++i){
            for(int j=1; j<=h; ++j){
                if(C[i][j] == 1 && D[i][j] == -1){ // ???????????£??????????¨??????????
                    bfs(i, j);
                    ++n;
                }
            }
        }
        cout << n << endl;
    }
}

Measured memory_bytes: 3152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(){
  string s;
  cin >> s;
  char tmp1,tmp2;
  bool can = false;
  if(s[0] == s[1]){
    if(s[2]==s[3] && s[0] != s[2]){
      can = true;
    }
  }else if(s[0] == s[2]){
    if(s[1]==s[3] && s[0] != s[1]){
      can = true;
    }
  }else if(s[0] == s[3]){
    if(s[1]==s[2] && s[0] != s[1]){
      can = true;
    }
  }
  if(can){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


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

int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << a[2]*10+a[1]+a[0];
}

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

vector<int> al[55];

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	int N, M;
	scanf("%d %d", &N, &M);
	int a, b;
	for (int i = 1; i <= M; i++) {
		scanf("%d %d", &a, &b);
		al[a].push_back(b);
		al[b].push_back(a);
	}
	for (int i = 1; i <= N; i++) printf("%d\n", (int)al[i].size());	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,c; cin >> a >> b >> c;
    int ans = 0;
    for(int i = a; i <= b;i++){
        if(c%i==0 and c>=i)ans++;
    }
    cout << ans << endl;
}





Measured memory_bytes: 3104
import java.util.*;

/**
 * D Main
 *
 * @date 2020.09.19
 * @author 焼き鮭 <yaki-shake@up-tri.me>
 */

public class Main {
  Scanner sc;
  int MIN = 3;
  int MOD = 1000000007;

  long[] dist = new long[2001];

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

  public void execute() {
    this.sc = new Scanner(System.in);
    int s = this.sc.nextInt();
    if (s <= 2) {
      System.out.println(0);
      return;
    }
    System.out.println(distribute(s));
  }

  public long distribute(int a) {
    long sum = 1;
    if (dist[a] != 0) {
      return dist[a];
    }
    for (int c = MIN; c <= (a - MIN); c++) {
      sum = (sum + distribute(c)) % MOD;
    }
    dist[a] = sum;

    return sum;
  }
}


Measured memory_bytes: 27120
import itertools
N,K = input().split()
N,K = int(N),int(K)
Alist = []

for i in range(0,K*2):
    Alist.append(input().split())

intAlist = [[int(item) for item in row] for row in Alist]

#菓子iを持ったすぬけくんはdi人いる、菓子はK種類、
#1の菓子を持ったすぬけが2人いる
count = 0
oklist = []
nowD = 0
for j in range(0,K*2):

    if j % 2 == 0:
        # nowD = intAlist[j]
        pass
    else:
        oklist.append(intAlist[j])
oklist = list(set(list(itertools.chain.from_iterable(oklist))))
print(N - len(oklist))


Measured memory_bytes: 9772
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  int a[n],b[n],c[n];
  int i=0;
  while(i<n)
  {
    cin>>a[i]>>b[i]>>c[i];
    i++;
  }
  int dp1[n],dp2[n],dp3[n];
  dp1[0]=a[0];
  dp2[0]=b[0];
  dp3[0]=c[0];
  for(i=1;i<n;i++)
  {
    dp1[i]=a[i]+max(dp2[i-1],dp3[i-1]);
    dp2[i]=b[i]+max(dp1[i-1],dp3[i-1]);
    dp3[i]=c[i]+max(dp2[i-1],dp1[i-1]);
  }
  cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]))<<"\n";
  return 0;
}


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

int N;

struct V {
  double x, y, t;

  V(double x = 0, double y = 0): x(x), y(y), t(atan2(y,x)) {
  };

  bool operator < (const V &that) {
    return t < that.t;
  }

  V& operator += (const V &v) {
    x += v.x;
    y += v.y;
    return *this;
  }
};

vector<V> x;

int main () {
  cin >> N;

  rep(i,N) {
    double a, b;
    cin >> a >> b;
    x.emplace_back(a, b);
  }

  sort(all(x));

  double ans = 0;
  rep(i,N) {
    V c(0, 0);
    rep(j,N) {
      c += x[(i+j)%N];
      ans = max(ans, c.x*c.x + c.y*c.y);
    }
  }

  cout << fixed << setprecision(12) << sqrt(ans) << endl;

  return 0;
}


Measured memory_bytes: 256