akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
 int a,b;
 scanf("%d%d",&a,&b);
 while (a!=0 || b!=0){
  if(a<b)
   printf("%d %d\n",a,b);
  else
   printf("%d %d\n",b,a);
  scanf("%d%d",&a,&b);}
 return 0;
}


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


int main() {
  int X; cin >> X;
  int ans = 0;
  if(X >= 400 && X< 600) ans = 8;
  if(X >= 600 && X< 800) ans = 7;
  if(X >= 800 && X< 1000) ans = 6;
  if(X >= 1000 && X< 1200) ans = 5;
  if(X >= 1200 && X< 1400) ans = 4;
  if(X >= 1400 && X< 1600) ans = 3;
  if(X >= 1600 && X< 1800) ans = 2;
  if(X >= 1800 && X< 2000) ans = 1;

  cout << ans << endl;




  return 0;
}









Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	int a,b;
	cin>>a>>b;
	if(2*b>=a)
		cout<<0;
	else
		cout<<a-2*b;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 764
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    bit = [0] * (n+1)

    def add(i,x):
        while i <= n:
            bit[i] += x
            i += i & -i

    def query(i):
        x = 0
        while i > 0:
            x += bit[i]
            i -= i & -i
        return x

    for i,a in enumerate(LI()):
        add(i+1,int(a))

    ans = INF

    b = [bit,copy.copy(bit)]
    for s in (1,-1):
        bit = b[(s+1)//2]
        cnt = 0
        x = s
        for i in range(1,n+1):
            z = query(i)
            if z * x <= 0:
                add(i,x-z)
                cnt += abs(x-z)
            x = -x
        ans = min(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<int> v(n+1), w(n+1);
    for (int i=1; i<n+1; ++i) cin >> v[i] >> w[i];

    int m = min((1<<9), n+1);
    vector<vector<int>> dp(m, vector<int>(100001));
    for (int i=1; i<m; ++i) {
        int par = i / 2;
        for (int j=0; j<100001; ++j) {
            dp[i][j] = dp[par][j];
            if (j >= w[i]) chmax(dp[i][j], dp[par][j-w[i]] + v[i]);
        }
    }

    int q;
    cin >> q;
    for (int i=0; i<q; ++i) {
        int V, l;
        cin >> V >> l;
        vector<int> vec;
        while (V >= m) {
            vec.push_back(V);
            V /= 2;
        }
        int nn = (int)vec.size();
        int res = 0;
        for (int bits=0; bits<(1<<nn); ++bits) {
            int cv = 0, cw = 0;
            for (int j=0; j<nn; ++j) {
                if (bits & (1<<j)) {
                    cv += v[vec[j]];
                    cw += w[vec[j]];
                }
            }
            if (l - cw >= 0) chmax(res, cv + dp[V][l-cw]);
        }
        cout << res << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 206448
#include<vector>
#include<algorithm> // sort,reverse,min,lower_bound
#include<iostream>
using namespace std;
#define df 0
#define MAX_ORD 30
typedef long int li;
void fb(li a);
li solve(li a,vector<li>& b,int ord);
int dc=1000;

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<li> a(n),b(n);
  for(li& x: a) cin >>x;
  for(li& x: b) cin >>x;

  li s=0,mask=(1<<MAX_ORD)-1;
  for(int i=MAX_ORD-1;i>=0;i--,mask>>=1){
    for(li& x: b) x&=mask;
    sort(b.begin(),b.end());
    if(df){
      printf("b:");
      for(li& x: b){
	fb(x); cout << " ";
      }
    }
    li temp=0;
    for(int j=0;j<n;j++){
      temp ^= solve(a.at(j)&mask,b,i);
    }
    s^=temp;
  }
  cout << s;
}

void fb(li a){
  li mask=1<<MAX_ORD;
  while(mask){
    printf("%d",a&mask?1:0);
    mask/=2;
  }
}

li solve(li a,vector<li>& b,int ord){
  if(df) {
    printf("solve a:");
    fb(a);
    printf(", ord:%d\n",ord);
    fb((1<<(ord+1))-1);
    cout <<" ";
    fb(1<<ord);
    cout <<" ";
    fb((1<<(ord+2))-1);
    cout <<" ";
    fb((1<<ord)*3);
    cout <<"\n";
  }
  li count=upper_bound(b.begin(),b.end(),(1<<(ord+1))-1-a)-lower_bound(b.begin(),b.end(),(1<<ord)-a);
  count ^= upper_bound(b.begin(),b.end(),(1<<(ord+2))-1-a)-lower_bound(b.begin(),b.end(),(1<<ord)*3-a);
  if(df)printf("count %d\n",count);
  count %=2;
  return count<<ord;
}  

/// confirm df==0 ///


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    auto A = make_vec<int>(N, M);
    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int ans = INF;
    for (int bits = 0; bits < (1 << N); bits++) {
        int tmp = 0;
        vector<int> sum(M);
        for (int i = 0; i < N; i++) {
            int mask = 1 << i;
            if (mask & bits) {
                tmp += C[i];
                for (int j = 0; j < M; j++) {
                    sum[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for (int i = 0; i < M; i++) {
            if (sum[i] < X) ok = false;
        }
        if (ok) chmin(ans, tmp);
    }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rep(a,n,b) for(int i=a;i<n;i+=b)
#define rrep(a,n,b) for(ll i=n;i>=a;i-=b)
#define iter(obj) for(auto x : obj) 
#define pb(i) push_back(i)
#define ff first
#define ss second
#define pchr(flag) cout<<(flag ? "YES" : "NO")
#define ot(x) cout<<x
#define nl cout<<endl;
#define sc cout<<" "
#define ll long long int
#define input freopen("input.txt","r",stdin)
#define op freopen("output.txt","w",stdout);
#define fastio std::ios::sync_with_stdio(false)
using namespace std;
const int N = 2e5+7;
const int MOD  = 1000000007;
const float PI = 3.1415926535;
//33333333333;
int prime[N];
void SieveOfEratosthenes(int n) 
{ 
     for (int p=2; p*p<=n; p++) {
        if (prime[p] == 0)  {
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 1; 
        } 
    } 
} 
int main() 
{ 
	fastio;
	ll n,k,ans=0;
	cin>>n>>k;
	ll arr[n];
	rep(0,n,1) cin>>arr[i];
	sort(arr,arr+n);
	rep(0,n-k,1) {
		ans = ans + arr[i];
	}
	cout<<ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define MM <<" "<<
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using pl=pair<ll,ll>;
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;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll count[100];
    rep(i,100)count[i]=0;
    ll N;cin>>N;
    rep(i,N){
        ll p;cin>>p;
        rep(j,60){
            if(p&(1LL<<j))count[j]++;
        }
    }
    ll ans=0,p=1;
    rep(i,60){
        ans=(ans+count[i]*(N-count[i])%MOD*p)%MOD;
        p=p*2%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
players_card = STDIN.read.tr('abc', '012').split("\n")
players_list = 'ABC'
ptr = 0
loop{
    if players_card[ptr].size == 0
        puts players_list[ptr]
        break
    else
        next_ptr = players_card[ptr][0].to_i
        players_card[ptr] = players_card[ptr][1, players_card[ptr].size - 1]
        ptr = next_ptr
    end
}

Measured memory_bytes: 1916
/*
 * a.cc: 
 */

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

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int an = a.size(), bn = b.size();

  for (int i = 0; i <= an - bn; i++) {
    bool ok = true;
    for (int j = 0; j < bn; j++)
      if (b[j] != '_' && a[i + j] != b[j]) {
	ok = false;
	break;
      }

    if (ok) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
  return 0;
}


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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 500 + 100;
const int M = (int) 1e5 + 100;
const int K = (int) 200;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, m;
pii a[M];
int t[N];
vec v[M];

bool ok(int x, int y) {
	for (int i = 1; i <= n; i++) {
		t[i] = -1; // pohui
	}
	set<pii> st;
	st.insert(mp(m, x));
	st.insert(mp(m, y));
	t[x] = t[y] = m;
	while (!st.empty()) {
		int vertex = (--st.end()) -> s;
		//cout << vertex << ' ' << t[vertex] << endl;
		st.erase(--st.end());
		for (auto it : v[vertex]) {
			if (it > t[vertex]) 
				break;
			int pr = (a[it].f ^ a[it].s ^ vertex);
			if (t[pr] != -1) 
				return false;
			t[pr] = it - 1;
			st.insert(mp(it - 1, pr));
		}
	}
	return true;
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i].f >> a[i].s;
		v[a[i].f].pb(i);
		v[a[i].s].pb(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (ok(i, j)) {
			//	cout << i << ' ' << j << endl;
				ans++;
			}
		}
	}
	cout << ans;
	return 0;		
}

Measured memory_bytes: 4608
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = null;

		try {
			sc = new Scanner(System.in);
			int[] hillList = new int[10];

			for (int i = 0; i < 10; i++) {
				hillList[i] = sc.nextInt();
			}
			Arrays.sort(hillList);
			int n = hillList.length - 1;
			for (int j = 0; j < 3; j++) {

				System.out.println(hillList[n]);
				n--;
			}
		}catch (Exception e) {
			System.out.println(e);
		} finally {
			if (sc != null) {
				try {
					sc.close();
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
		}
	}

}

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

int main() {
  int N,K;
  int x = 1;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    if(x>K){
      x+=K;
    }else{
      x*=2;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += c[a[i][j]][1]

print(ans)


Measured memory_bytes: 67808
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int a[maxn], n;
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = 1 << 30;
  for (int i = 1; i < n; i++) {
    int s1 = 0, s2 = 0;
    for (int j = 1; j <= i; j++) {
      s1 += a[j];
    }
    for (int j = i + 1; j <= n; j++) {
      s2 += a[j];
    }
    ans = min(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}

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

  int* p;
  p = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }

  // sort
  for (int j = 0; j < N - 1; j++) {
    for (int i = 0; i < N - 1; i++) {
      if (p[i] > p[i + 1]) {
        int tmp = p[i + 1];
        p[i + 1] = p[i];
        p[i] = tmp;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    // cout << p[i] << " ";
  }
  // cout << endl;

  int lst[104];
  for (int i = 0; i < 104; i++) {
    lst[i] = i;
  }

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

  for (int i = 0; i < 101; i++) {
    // cout << lst[i] << " ";
  }
  // cout << endl;

  // judge
  if (lst[X] != -1) {
    cout << X << endl;
    exit(0);
  }

  bool flag = true;
  int LI = X - 1;
  int Lmin;
  int Ldist;
  // LeftDirection
  while (flag) {
    if (lst[LI] != -1) {
      Lmin = lst[LI];
      Ldist = X - Lmin;
      flag = false;
    }
    LI--;
  }

  flag = true;
  int RI = X + 1;
  int Rmin;
  int Rdist;
  // RightDirection
  while (flag) {
    if (lst[RI] != -1) {
      Rmin = lst[RI];
      Rdist = Rmin - X;
      flag = false;
    }
    RI++;
  }

  // cout << Lmin << Rmin << endl;

  int min;
  if (Ldist > Rdist) {
    min = Rmin;
  } else if (Ldist < Rdist) {
    min = Lmin;
  } else {
    min = Lmin;
  }

  cout << min << endl;
}

Measured memory_bytes: 3580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template <typename T> void add(T& a, T b, int mod) {
	a += b;
	if (a >= mod)
		a -= mod;
}

template <typename T> void mul(T& a, T b, int mod) {
	a = a * b % mod;
}


const int mxN = 1e5 + 5;

class TaskV {
public:
	int N, mod;
	vector<int> adj[mxN];
	vector<ll> dp, ans;

	void solve(std::istream& in, std::ostream& out) {
		in >> N >> mod;
		dp.resize(N, 0);
		ans.resize(N, 0);
		for (int i = 0; i < N - 1; i++) {
			int u, v;
			in >> u >> v;
			u--, v--;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		dfs_one(0, -1);
		dfs_two(0, -1, 1);
		for (int i = 0; i < N; i++)
			out << ans[i] << "\n";
	}

	void dfs_one(int u, int p) {
		dp[u] = 1;
		for (int v : adj[u]) {
			if (v == p) continue;
			dfs_one(v, u);
			mul(dp[u], dp[v], mod);
		}
		add(dp[u], 1ll, mod);
	}

	void dfs_two(int u, int p, ll ways) {
		vector<ll> pref, suff;
		pref.push_back(1);
		for (int v : adj[u]) {
			if (v == p) continue;
			pref.push_back(dp[v]);
			suff.push_back(dp[v]);
		}
		suff.push_back(1);
		for (int i = 1; i < (int) pref.size(); i++) {
			mul(pref[i], pref[i - 1], mod);
		}
		for (int i = (int) suff.size() - 2; i >= 0; i--) {
			mul(suff[i], suff[i + 1], mod);
		}
		ans[u] = pref.back() * ways % mod;
		int i = 0;
		for (int v : adj[u]) {
			if (v == p) continue;
			ll new_ways = 1;
			mul(new_ways, pref[i], mod);
			mul(new_ways, suff[i + 1], mod);
			mul(new_ways, ways, mod);
			add(new_ways, 1ll, mod);
			dfs_two(v, u, new_ways);
			i++;
		}
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskV solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 28440
#include<bits/stdc++.h>
using namespace std;
int parent[200005];
int find(int x){
	if(parent[x]<0)
		return x;
	return parent[x]=find(parent[x]);
}
void merge(int x,int y){
	int a=find(x);
	int b=find(y);
	if(a==b)return;
	parent[a]+=parent[b];
	parent[b]=a;
}
int main()
{
	memset(parent,-1,sizeof(parent));
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int p,q;
		cin>>p>>q;
		merge(p,q);
	}
	cout<<abs(*min_element(parent,parent+n+1))<<endl;
	return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    REP(i, n - 1) {
        cin >> b[i];
    }
    int t = b[0] + b[n - 2];
    REP(i, n - 2) {
        t += min(b[i], b[i + 1]);
    }
    cout << t << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;
	scanf ("%d %d %d %d %d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j,&k,&l,&m,&n);
	o = a - b;
	p = c - d;
	q = e - f;
	r = g - h;
	s = i - j;
	t = k- l;
	u = m - n;
	printf ("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",o,p,q,r,s,t,u);

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
#define         rep(i,n)       for (int i = 0;i<(int)(n);i++)
#define         rep1(i,n)      for (int i = 1;i<=(int)(n);i++)
#define         sajo(str)      sort(str.begin(),str.end())
#define         pi             3.14159265359
#define         neli            printf("\n")
#define         gcd(a,b)       __gcd(a,b)
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         pf             printf
#define         sf             scanf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
typedef long long int ll;

int main()
{

    FIO;
    ll i,j,k,q,temp,n,x,f=0;

    cin>>n;
    k=sqrt(n);
    for(i=k;i>=1;i--)
    {
        if(n%i==0)
        {
            j=n/i;
            break;
        }
    }

    q=j+i-2;
    cout<<q<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef JLOCAL
#include "stress.h"
#endif
using namespace std;

#define rep(i, z, n) for (int i = (z); i < int(n); ++i)
#define repr(i, n, z) for (int i = int(n) - 1; i >= (z); --i)
#define shl(n) (1 << (n))
#define hbit(n, i) (((n) >> (i)) & 1)

#define STRESS 0
using lint = long long;

int ans[111][111];

void solve(istream& cin, ostream& cout) {
    int h, w, n;
    cin >> h >> w >> n;
    int x = 0, y = 0;
    rep(in, 0, n) {
        int t;
        cin >> t;
        rep(it, 0, t) {
            ans[x][y] = in;
            if (y % 2 == 0) {
                x++;
                if (x == h) {
                    x--;
                    y++;
                }
            } else {
                x--;
                if (x == -1) {
                    x++;
                    y++;
                }
            }
        }
    }

    rep(i, 0, h) {
        rep(j, 0, w) {
            cout << ans[i][j] + 1 << " ";
        }
        cout << "\n";
    }
}

int main() {
#if !defined(JLOCAL) || !STRESS
#ifdef JLOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve(cin, cout);
#else
    srand();
    for (int ti = 0; ti < 100; ti++) {
        stress::gen();
        stress::stupid();
        ifstream in("input.txt");
        ofstream out("output.txt");
        solve(in, out);
        out.flush();
        stress::check();
    }
    cout << "ok" << endl;
#endif
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void) {
	int a, b;
	int sum = 0;

	scanf("%d %d", &a, &b);
	if (a < b) {
		sum += b;
		b--;
	}
	else {
		sum += a;
		a--;
	}
	if (a < b) {
		sum += b;
		b--;
	}
	else {
		sum += a;
		a--;
	}

	printf("%d\n", sum);
	return 0;
}


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

const int INF = numeric_limits<int>::max();

template < typename T >
struct SegmentTree {
        
        T id;
        function < T(T, T) > op;
        vector < T > dat;
        int size;

        SegmentTree(int n, T id, function < T(T, T) > op) : id(id), op(op) {
                size = 1;
                while ( size < n ) size *= 2;
                dat.assign(size * 2 + 10, id);
        }

        void update(int k, T x) {
                k += size, dat[k] = x;
                while ( k > 1 ) k >>= 1, dat[k] = op(dat[k << 1], dat[(k << 1) | 1]);
        }

        void merge(int k, T x) { update(k, op(x, dat[k + size])); }
        //[a, b)
        T query(int a, int b) {
                T tl = id, tr = id;
                for ( int l = a + size, r = b + size; l < r; l >>= 1, r >>= 1 ) {
                        if ( l & 1 ) tl = op(tl, dat[l++]);
                        if ( r & 1 ) tr = op(tr, dat[--r]);
                }
                return ( op(tl, tr) );
        }
};

int main()
{
        int N, Q;
        cin >> N >> Q;
        //RMQ
        SegmentTree < int > seg(N, 0, [](int a, int b) { return ( a + b ); } );

        while ( Q-- ) {
                int com, a, b;
                cin >> com >> a >> b;
                if ( com == 0 ) seg.merge(a, b);
                else cout << seg.query(a, b + 1) << endl;
        }
                
        return ( 0 );
}



Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  vector<Int> xs(n),ys(n);
  for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i];

  const Int MAX = 1e5+10;
  vector<vector<Int>> GX(MAX),GY(MAX);
  for(Int i=0;i<n;i++){
    GX[xs[i]].emplace_back(i);
    GY[ys[i]].emplace_back(i);
  }

  Int ans=0;
  vector<Int> ux(MAX,0),uy(MAX,0),used(n,0);
  for(Int i=0;i<n;i++){
    if(used[i]) continue;

    set<Int> sx,sy;
    queue<Int> que;
    que.emplace(i);

    while(!que.empty()){
      Int v=que.front();que.pop();
      if(used[v]) continue;
      used[v]=1;
      sx.emplace(xs[v]);
      sy.emplace(ys[v]);
      if(!ux[xs[v]]){
        for(Int u:GX[xs[v]]) que.emplace(u);
        ux[xs[v]]=1;
      }
      if(!uy[ys[v]]){
        for(Int u:GY[ys[v]]) que.emplace(u);
        uy[ys[v]]=1;
      }
    }

    ans+=(Int)sx.size()*(Int)sy.size();
  }
  cout<<ans-n<<endl;
  return 0;
}


Measured memory_bytes: 17152
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += sc.nextInt();
		}
		if (sum % 2 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 33308
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, T, A, B, U):
    if S == U:
        A -= 1
    else:
        B -= 1
    return '%d %d' % (A, B)


def main():
    S, T = read_str_n()
    A, B = read_int_n()
    U = read_str()
    print(slv(S, T, A, B, U))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6860
function D166(_input) {
    var lines = _input.split("\n");
    var x = lines.shift()*1;

    for (var i = 119; i > -118; i--) {
        for (var j = 118; j > -119; j--) {
            const fi = i*i*i*i*i;
            const fj = j*j*j*j*j;
            if (fi - fj === x) {
                console.log(`${i} ${j}`);
                return;
            }
        }
    }
}
D166(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32612
s = input()[::-1]
n = len(s)
x = 1
tot = 0 # 累積和
cnt = [0 for i in range(2019)] # 累積和の値になる個数

ans = 0
for i in range(n):
    # print('======={}======'.format(i))
    cnt[tot] += 1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    # print(tot)
    ans += cnt[tot]
    # print('ans:', ans)
    x = x*10%2019

print(ans)


Measured memory_bytes: 9316
n = int(input())
x = []
y = []
h = []
for i in range(n):
    xx,yy,zz = map(int,input().split())	
    x.append(xx)
    y.append(yy)
    h.append(zz)
kk = h.index(max(h))
k= 0
for i in range(101):
    for j in range(101):
        ass = h[kk]+abs(x[kk]-i)+abs(y[kk]-j)
        for r in range(n):
            if h[r] == 0:
                if ass -abs(x[r]-i)-abs(y[r]-j) > 0:
                    ass = -1
            else:
                if ass != abs(x[r]-i)+abs(y[r]-j)+h[r]:
                    ass = -1
        
        if ass != -1:
            print(str(i)+' '+str(j)+ ' '+ str(ass))
            break
                

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int s, w;

    do{
        scanf("%d%d", &s, &w);
    } while (s < 1 || s > 100 || w < 1 || w > 100);
    if (s > w)
        printf("safe");
    else
        printf("unsafe");

    return 0;
}

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

int main() {
    int a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans = ((a < b)? a : b) + ((c < d)? c : d);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	bool S[14] = {}, H[14] = {}, C[14] = {}, D[14] = {};

	int n; cin >> n;

	char suit;
	int number;
	for (int i = 0; i < n; i++){
		cin >> suit >> number;
		switch (suit){
			case 'S': S[number] = true; break;
			case 'C': C[number] = true; break;
			case 'H': H[number] = true; break;
			case 'D': D[number] = true; break;
		}
	}

	for (int i = 1; i <= 13; i++)
		if (!S[i]) cout << 'S' << " " << i << endl;

	for (int i = 1; i <= 13; i++)
			if (!H[i]) cout << 'H' << " " << i << endl;

	for (int i = 1; i <= 13; i++)
		if (!C[i]) cout << 'C' << " " << i << endl;

	for (int i = 1; i <= 13; i++)
		if (!D[i]) cout << 'D' << " " << i << endl;


	return 0;
}



Measured memory_bytes: 3112
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mina = min(A)
    for i in range(K):
        B = [0]*N
        for j in range(N):
            if j-A[j] >= 0:
                B[j-A[j]] += 1
            else:
                B[0] += 1
            if j+A[j]+1 < N:
                B[j+A[j]+1] -= 1
        A = list(accumulate(B[:]))
        mina = mina*2+1
        if mina >= N and A[0] == A[-1] == N:
            break
    print(*A)

if __name__ == "__main__":
    main()


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

using namespace std;
string S, T;

int N, M;

int check(int i) {

	for (int k = 0; k < M; k++) {
		if (S[k+i] == '?') { continue; }
		else if (S[k + i] != T[k]) { return -1; }
	}

	return 1;
}

string desc(int i) {

	string ret= S;

	//cout << ret << endl;
	for (int k = 0; k < N; k++) {
		if (ret[k] == '?') { ret[k] = 'a'; }
	}
	//cout << ret << endl;
	for (int k = i; k < i + M; k++) {
		ret[k] = T[k-i];
	}

	//cout << ret << endl;

	return ret;
}

int main(void) {

	cin >> S >> T;

	N = S.size();
	M = T.size();

	int p = -1;
	for (int i = 0; i <= N - M; i++) {
		if (check(i) == 1) { p = i; }
	}

	if (p == -1) { cout << "UNRESTORABLE" << endl; }
	else { cout << desc(p) << endl; }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>
 
using namespace std;
 
int main(){
     
    int n;
     
    float x[4], y[4];
     
    cin >> n;
     
    for(int loop = 0; loop < n; loop++){
        for(int i = 0; i < 4; i++){
            cin >> x[i] >> y[i];
        }
        x[1] -= x[0];
        y[1] -= y[0];
        x[3] -= x[2];
        y[3] -= y[2];
        if(x[3] * y[1] == y[3] * x[1]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
     
    return 0;
}


Measured memory_bytes: 3180
type apple_t = {abs_tst:int; id:int}

let () = Scanf.scanf "%d %d" @@ fun n l ->
  let abs_ary = Array.init n @@ fun i -> {abs_tst = abs (l + i); id = i} in
  let all = n * (l - 1) + (n * (n + 1) / 2) in
  let () = Array.sort compare abs_ary in
  let sub = l + abs_ary.(0).id in
  let ans = all - sub in
  Printf.printf "%d\n" ans


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

int main(){
  long long int n,k,kotae=0,kijun=1;
  cin>>n>>k;
  for(;;){
    if(kijun>n){
      break;
    }
    kijun*=k;
    kotae++;
  }
  cout<<kotae;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABC = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            var A = ABC[0];
            var B = ABC[1];
            var C = ABC[2];
            var cnt = 0;
            while(A%2==0&& B % 2 == 0&& C % 2 == 0)
            {
                var tA = B / 2+C/2;
                var tB = A / 2 + C / 2;
                var tC = B / 2 + A / 2;
                A = tA;
                B = tB;
                C = tC;
                cnt++;
                if(100<cnt)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            Console.WriteLine(cnt);

        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, h[100001];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &h[i]);
    long long dp[100001];
    dp[1] = 0;
    for (int i = 2; i <= n; i++)
        dp[i] = (long long) 1e18;
    for (int i = 1; i < n; i++)
        for (int j = 1; j <= 2; j++)
        if (i + j <= n)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A;
  int B;
  rd(A);
  rd(B);
  wt_L(A*B);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// {
//   int A, B;
//   rd(A,B);
//   wt(A*B);
// }


Measured memory_bytes: 3632
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	char X, Y; cin >> X >> Y;
	if (X < Y)cout << '<' << endl;
	else if (X > Y)cout << '>' << endl;
	else cout << '=' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 != 0) {
        cout << "No" << endl;
    }
    else if (s.substr(0, n/2) != s.substr(n/2)) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

#define P pair<ll,ll>
#define fs first
#define sc second

int main(){
    ll n;
    cin >> n;
    cout << n*(n-1)/2 << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	string s,t;
	cin>>s>>t;

	map<char,set<int>> mp;
	rep(i,s.size()){
		mp[s[i]].insert(i);
	}
	ll cnt = 0;
	int pos = -1;
	ll res = 0;
	rep(i,t.size()){
		if(mp[t[i]].empty()){
			cout<<-1<<endl;
			return 0;
		}
		auto it = mp[t[i]].upper_bound(pos);
		// cout<<t[i]<<" ";
		// for(auto x:mp[t[i]]) cout<<x<<" ";
		// cout<<endl;
		if(it == mp[t[i]].end()){
			// cout<<" here "<<t[i]<<endl;
			cnt++;
			pos=-1;
			it = mp[t[i]].upper_bound(pos);
			pos = *it;
		}else{
			pos = *it;
		}
		
		res = *it+1;
	}

	// cout<<"cnt = "<<cnt<<endl;

	cout<<cnt*(ll)s.size()+res<<endl;


	return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int N, M, S[15], D[100];
int sum[1 << 15];
int dp[1 << 15];

int main()
{

  while(scanf("%d %d", &N, &M), N) {
    for(int i = 0; i < N; ++i) {
      scanf("%d", &S[i]);
    }
    for(int i = 0; i < M; ++i) {
      scanf("%d", &D[i]);
    }
    sort(D, D + M);

    for(int i = 0; i < (1 << N); i++) {
      sum[i] = 0;
      for(int j = 0; j < N; j++) {
        if((i >> j) & 1) sum[i] += S[j];
      }
    }

    fill_n(dp, 1 << N, INF);
    dp[0] = 0;
    for(int i = 0; i < M; i++) {
      for(int k = 0; k < (1 << N); k++) {
        for(int j = 0; j < N; j++) {
          if((k >> j) & 1) continue;
          dp[k | (1 << j)] = min(dp[k | (1 << j)], dp[k]);
        }
      }
      for(int k = 0; k < (1 << N); k++) {
        dp[k] += abs(D[i] - sum[k]);
      }
    }
    printf("%d\n", *min_element(dp, dp + (1 << N)));
  }
}

Measured memory_bytes: 3496
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int a,p; cin >> a >> p;
    p+=3*a;
    cout << p/2 << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=10**18
for i in range(n-k+1):
  l=x[i]
  r=x[i+k-1]
  ans=min(ans,min(abs(l)+abs(r-l),abs(r)+abs(l-r)))
print(ans)

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

int main() {
  int x, n;
  cin >> x >> n;
  set<int> s;
  while (n--) {
    int e;
    cin >> e;
    s.insert(e);
  }
  int r = 1e9;
  for (int i = 0; i <= 101; i++) {
    if (s.count(i)) continue;
    if (abs(i - x) < abs(r - x)) r = i;
  }
  cout << r << endl;
}


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


int main(void) {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> s[i][j];
    }
  }

  bool ok = true;

  rep(i, H) {
    rep(j, W) {
      if (s[i][j] == '#') {
        // 隣接する上下左右が#でないなら塗れない
        bool isBlack = false;
        if (i > 0) {
          isBlack = s[i - 1][j] == '#' ? true : isBlack;
        }
        if (i < H - 1) {
          isBlack = s[i + 1][j] == '#' ? true : isBlack;
        }
        if (j > 0) {
          isBlack = s[i][j - 1] == '#' ? true : isBlack;
        }
        if (j < W - 1) {
          isBlack = s[i][j + 1] == '#' ? true : isBlack;
        }
        if (!isBlack) {
          ok = false;
        }
      }
    }
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const ll INF = 	922337203685477580;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
ll dp[100010];

int main(){
  int h,w;
  int n;
  cin>>h>>w>>n;
  int a[n];
  for(int i = 0; i < n; i++) cin>>a[i];
  int p[h][w];
  int cnt=0;
  int flg = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(cnt==a[flg]){
        flg+=1;
        cnt=0;
      }

      if(i%2==0)p[i][j]=flg+1;
      else p[i][w-1-j]=flg+1;
      cnt++;
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout<<p[i][j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    char tmp = s[0];

    REPN(i, 1, n) {
        if(tmp == s[i]) {

        } else {
            ans++;
            tmp = s[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
k = int(input())
prev_lunlun = list(range(1, 10))
lunlun = prev_lunlun[:]

while len(lunlun) < k:
    next_lunlun = []
    for x in prev_lunlun:
        r = x % 10
        y = x * 10 + r
        next_lunlun.append(y)
        if r != 9:
            next_lunlun.append(y+1)
        if r != 0:
            next_lunlun.append(y-1)
    lunlun += next_lunlun
    prev_lunlun = next_lunlun
lunlun.sort()
print(lunlun[k-1])

Measured memory_bytes: 85676
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = (int) 1e9 + 7;
const int inv2 = (mod + 1) / 2;

int mul(int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = 3005;
int n, m;
int a[maxn];
int xs[maxn], ys[maxn];

bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &xs[i], &ys[i]);
    xs[i]--;
    ys[i]--;
  }
  return true;
}

int dp[maxn][maxn];

void solve() {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      dp[i][j] = 1;
    }
  }
  int tomul = 1;
  for (int t = m - 1; t >= 0; t--) {
    int x = xs[t], y = ys[t];
    tomul = mul(tomul, 2);
    for (int i = 0; i < n; i++) {
      if (i == x || i == y) {
        continue;
      }
      auto &cur = dp[x][i];
      add(cur, dp[y][i]);
      cur = mul(cur, inv2);
    }
    for (int i = 0; i < n; i++) {
      if (i == x || i == y) {
        continue;
      }
      dp[y][i] = dp[x][i];
    }
    for (int i = 0; i < n; i++) {
      if (i == x || i == y) {
        continue;
      }
      auto &cur = dp[i][x];
      add(cur, dp[i][y]);
      cur = mul(cur, inv2);
    }
    for (int i = 0; i < n; i++) {
      if (i == x || i == y) {
        continue;
      }
      dp[i][y] = dp[i][x];
    }
    {
      int &cur = dp[x][y];
      add(cur, dp[y][x]);
      cur = mul(cur, inv2);
      dp[y][x] = cur;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i] <= a[j]) {
        continue;
      }
      auto cur = dp[i][j];
      cur = mul(cur, tomul);
      add(res, cur);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 35584
from collections import Counter

N = int(input())
A_list = list(map(int, input().split()))
c = Counter(A_list)

l = sorted(c.items(), key=lambda x: x[0], reverse=True)

first = 0
second = 0
square = 0

for i in l:
    k, v = i[0], i[1]
    if v >= 4:
        if square == 0:
            square = k
        if first == 0:
            first = k
        elif second == 0:
            second = k
    elif v >= 2:
        if first == 0:
            first = k
        elif second == 0:
            second = k
print(max(first * second, square * square))


Measured memory_bytes: 22436
#include <stdio.h>
 
main(void)
{
    int a,n,i;
     
    long long int min=1000000 , max=-1000000 , sum=0;
    a=0;
     
    scanf("%d",&n);
     
    for(a=1;a<=n;a++){
        scanf("%d",&i);
        if(i<min)
        min=i;
        if(i>max)
        max=i;
        sum+=i;
    }
    printf("%lld %lld %lld\n",min,max,sum);
     
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    string S;
    cin >> S;
    ll N = S.length();
    ll min = INF;
    {
        ll m = 0;
        REP(i, N) {
            if (S[i] - '0' != i % 2)
                m++;
        }
        min = std::min(min, m);
    }
    {
        ll m = 0;
        REP(i, N) {
            if (S[i] - '0' != (i + 1) % 2)
                m++;
        }
        min = std::min(min, m);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 512