akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}

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

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

  ll n;
  cin >> n;
  vll x(n);
  REP(i,n) cin >> x[i];
  ll ans = INF;
  for(ll i = -1; i < 101; i++){
    ll tmp = 0;
    for(ll j = 0; j < n; j++){
      tmp += (i - x[j]) * (i - x[j]);
    }
    ans = min(ans,tmp);
  }
  cout << ans <<endl;






  return 0;
}



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

using namespace std;

int n,m;
int i,j,k;
string str;

int m2(int x){
    unsigned int us = 1;
    while(us <= x) us <<=1;
    return us-x;
}
int main(){
    cin >> n;
    vector<int> v(n);
    for (i=0;i<n;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    vector<int> a,b;
    for(i = 0,j=0,k=-1;i < n;i++){
        if(v[i] != j){
            a.push_back(v[i]);
            b.push_back(1);
            j = v[i];
            k++;
        }
        else{
            b[k]++;
        }
    }
    int ans = 0;
    for(i = a.size()-1;i >= 0;i--){
        j = m2(a[i]);
        if(j == a[i]){
            ans += b[i]/2;
        }
        else{
            k = lower_bound(a.begin(),a.begin()+i,j) - a.begin();
            if(a[k] == j){
                m = min(b[k],b[i]);
                ans += m;
                b[k] -= m;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2804
import queue

n=int(input())

sixexp=[6**i for i in range(1,7)]
nineexp=[9**i for i in range(1,6)]

lis=[1]+sixexp+nineexp

q=queue.Queue()

numlist=[0 for i in range (n+1)]

c=0
while c!=n:
    for i in lis:
        if c+i<=n:
            if numlist[c+i]==0:
                q.put(c+i)
                numlist[c+i]=numlist[c]+1
    c=q.get()
print(numlist[n])

Measured memory_bytes: 5508
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    for(int i=1;i<=100;i++){
    if(A-(i-1)*D<=0){
        cout << "No" << endl;
        break;
    }
    else if(C-i*B<=0){
        cout << "Yes" << endl;
        break;
    }
    }
    
}

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

int main()
{
    ll int n,cnt,res=0,sq;
    cin>>n;
    sq=sqrt(n);
    for(int i=sq;i>0;i--)
    {
        if(n%i==0)
        {
            cout<<n/i+i-2<<endl;
            return 0;
        }
    }
    
    

    return 0;
}




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

int main()
{
	char ch;

	while(1) {
		scanf("%c", &ch);
		if (islower(ch)) cout << (char)toupper(ch);
		else if (isupper(ch)) cout << (char)tolower(ch);
		else cout << ch;

		if (ch == '\n') break;
	}

	return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  cout << N * (N+1) / 2 << endl;
  return 0;
}



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

long long W, H, x, y;

int main(){
	cin >> W >> H >> x >> y;
	if(2*x == W && 2*y == H){
		printf("%.10f %d\n", ((double)W * (double)H)/2, 1);
	}else{
		printf("%.10f %d\n", ((double)W * (double)H)/2, 0);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin>>N;
    
    if(N%1111==0||N%1110==N%10||(N%1000)%111==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t
using Graph = vector<vector<int> >;
typedef pair<int, int> P;

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

int dp[5010][5010];

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

  int N; string S; cin >> N >> S;
  RREP(i, N) RREP(j, N){
    if(S[i] == S[j]) dp[i][j] = dp[i+1][j+1]+1;
  }
  int mx = 0;
  REP(i, N) for(int j = i+1; j < N; j++){
    mx = max(mx, min(j-i, dp[i][j]));
  }
  cout << mx << endl;
}


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

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

    map<char, char> t2s;
    map<char, char> s2t;
    bool flag = true;
    rep(i, s.size())
    {
        auto itrt2s = t2s.find(t[i]);
        if (itrt2s != t2s.end())
        {
            if (t2s[t[i]] != s[i])
            {
                flag = false;
                break;
            }
        }
        else
        {
            t2s[t[i]] = s[i];
        }

        auto itrs2t = s2t.find(s[i]);
        if (itrs2t != s2t.end())
        {
            if (s2t[s[i]] != t[i])
            {
                flag = false;
                break;
            }
        }
        else
        {
            s2t[s[i]] = t[i];
        }
    }

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


Measured memory_bytes: 776
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b;
    string s;
    cin >> a >> b >> s;
    
    for (int i = 0; i < a+b; ++i) {
        if ((i == a and s[i] != '-') or (i != a and !isdigit(s[i]))) {
            cout << "No\n";
            return 0;
        }
    }
    
    cout << "Yes\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    ll ans = INF;
    
    int n;
    cin >> n;
    float a[n];
    rep(i, n){
        cin >> a[i];
    }
    rep2(i, -100, 101)
    {
        ll cnt = 0;
        rep(j,n){
            cnt += pow(a[j] - i, 2.0);
        }
        if(ans>cnt){
            ans = cnt;
        }
    }
    cout << ans << endl;
}

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

int main() {
  // N*Nのマス目
  int masuN = 0;
  // 白色のマス
  int whiteMasu = 0;
  
  // N*Nのマス目と白色のマスを入力
  cin >> masuN >> whiteMasu;
  
  // 黒色のマスを出力
  cout << masuN * masuN - whiteMasu << endl;
}

Measured memory_bytes: 256
import math

n, m = map(int, input().split(" "))
pyL = sorted([[i] + list(map(int,
                             input().split(" "))) for i in range(m)],
             key=lambda x: x[2])

li = [1] * (n + 1)

for i in range(len(pyL)):
    index, p, y = pyL[i]
    pyL[i].append(str(p).zfill(6) + str(li[p]).zfill(6))
    li[p] += 1

for py in sorted(pyL, key=lambda x: x[0]):
    print(py[3])

Measured memory_bytes: 44660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9, mod = 1e9+7;
#define endl     '\n'

void solve(){
    int n;
    cin >> n;
    if(n >= 400 and n <= 599)
        cout << 8 << endl;
    if(n >= 600 and n <= 799)
        cout << 7 << endl;
    if(n >= 800 and n <= 999)
        cout << 6 << endl;
    if(n >= 1000 and n <= 1199)
        cout << 5 << endl;
    if(n >= 1200 and n <= 1399)
        cout << 4 << endl;
    if(n >= 1400 and n <= 1599)
        cout << 3 << endl;
    if(n >= 1600 and n <= 1799)
        cout << 2 << endl;
    if(n >= 1800 and n <= 1999)
        cout << 1 << endl;
}


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

    solve();
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  int b[N + 1];
  for (int i = 1; i <= N; i++) cin >> a[i];

  int total = 0;
  for (int i = N; i >= 1; i--) {
    b[i] = a[i];
    for (int j = 2 * i; j <= N; j += i) {
      b[i] -= b[j];
    }
    b[i] %= 2;
    b[i] += 2;
    b[i] %= 2;
    total += b[i];
  }

  cout << total << endl;
  for (int i = 1; i <= N; i++) {
    if (b[i] == 1) {
      cout << i << " ";
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

int main() {
    int a[9] = {};
    int n;
    cin >> n;
    int in;
    REP(i,0,n) {
        cin >> in;
        if (in < 400) ++a[0];
        else if (in < 800) ++a[1];
        else if (in < 1200) ++a[2];
        else if (in < 1600) ++a[3];
        else if (in < 2000) ++a[4];
        else if (in < 2400) ++a[5];
        else if (in < 2800) ++a[6];
        else if (in < 3200) ++a[7];
        else ++a[8];
    }
    int cnt = 0;
    REP(i,0,8) {
        if (a[i] > 0) ++cnt;
    }
    cout << (cnt == 0 ? 1 : cnt) << " " << cnt + a[8];

    return 0;
}

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

using namespace std;

int main() {
  int n;
  double ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double x;
    string u;
    cin >> x;
    cin >> u;
    if (u == "JPY") {
      ans += x;
    } else {
      ans += 380000.0 * x;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1016
n,c,k=map(int,input().split())
t=[int(input()) for x in range(n)]
t.sort()

i=0
cnt=0
while i<n:
  departure=t[i]+k
  p=0
  for j in range(i,n):
    if t[j] > departure:
      break
    p+=1
  i+=min(c,p)
  cnt+=1
print(cnt)



Measured memory_bytes: 13344
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int amari = 0;
        int result = 0;

        result = (B - 1) / (A - 1);
        amari = (B - 1) % (A - 1);

        if (amari != 0) {
            result += 1;
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(result);
        sc.close();
        out.flush();
    }
}

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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 100000;
const int mod = 1e9 + 7;


namespace NT {
    int fact[N], inv[N];

    int bm(int b, int p, int m) {
        if(p == 0) return 1%m;
        int t = bm(b,p/2,m);
        t = (1ll*t*t)%m;
        if(p&1) return 1ll*t*b%m;
        return t;
    }

    int C(int n, int r) {
        if(n < 0 or r < 0 or r > n) return 0;
        int ret = 1ll*fact[n]*inv[r]%mod;
        ret = 1ll*ret*inv[n-r]%mod;
        return ret;
    }

    void init() {
        fact[0] = 1;
        for(int i = 1; i < N; i++) {
            fact[i] = 1ll*fact[i-1]*i%mod;
        }
        inv[N-1] = bm(fact[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--) {
            inv[i] = 1ll*inv[i+1]*(i+1)%mod;
        }
    }

    bool composite[N];
    vector<int> prime;

    void sieve() {
        composite[1] = 1;
        for(int i = 2; i < N; i++) {
            if(!composite[i]) prime.push_back(i);
            for(int j = 0; j < prime.size() && prime[j]*i < N; j++) {
                composite[prime[j] * i] = 1;
                if(i%prime[j] == 0) break;
            }
        }
    }
}

const int M = 4005, B = 2001;
int dp[M][M];

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);


    NT::init();

    int n;
    cin >> n;
    int sub = 0, ans = 0;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        sub += NT::C(2*(x+y), 2*x);
        sub %= mod;
        dp[-x+B][-y+B]++;
        a[i] = x+B, b[i] = y+B;
    }
    for(int i = 1; i < M; i++) {
        for(int j = 1; j < M; j++) {
            dp[i][j] += dp[i-1][j] + dp[i][j-1];
            dp[i][j] %= mod;
        }
    }
    for(int i = 0; i < n; i++) {
        ans += dp[a[i]][b[i]];
        ans %= mod;
    }
    ans -= sub;
    ans %= mod;
    ans = 1ll*ans*((mod+1)/2)%mod;
    if(ans < 0) ans += mod;
    cout << ans << endl;
}





Measured memory_bytes: 68324
#include <iostream>

using namespace std;

long long euclid(long long c, long long d) {
    long long x = min(c, d), y = max(c, d);

    if (y % x == 0) 
        return x;

    else
        return euclid(x, y%x);
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long nc, nd, ncd;
    long long gcd = euclid(c, d);
    
    gcd = c*d/gcd;
    nc = b/c - (a-1)/c;
    nd = b/d - (a-1)/d;
    ncd = b/gcd - (a-1)/gcd;

   

    long long ans = (b - a + 1) - nc - nd + ncd;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<iomanip>
#include<bits/stdc++.h>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int a,b,x;
    long double tmp;
    long double da,db,dx;
    cin >> a >> b >> x;
    da = (long double)a; db = (long double)b; dx = (long double)x;
    if( dx / (da*da*db) > 0.5 )
        tmp = atan(2./(da*da*da) * (da*da*db - dx));
    else tmp = atan( da*db*db / (2. *dx) );
    cout << DOUBLE << (180. / M_PI) * tmp << endl;
}

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

int main() {
  int H, W, count;
  cin >> H >> W;
  vector<string> S(H);
  
  for (int i = 0; i < H; i++) {
    cin >> S.at(i);
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count = 0;
      if (S.at(i).at(j) == '#') {
        cout << '#';
        continue;
      }
      if (j > 0 && S.at(i).at(j-1) == '#')
        count++;
      if (j < (W-1) && S.at(i).at(j+1) == '#')
        count++;
      if (i > 0 && S.at(i-1).at(j) == '#')
        count++;
      if (i < (H-1) && S.at(i+1).at(j) == '#')
        count++;
      if (i > 0 && j > 0 && S.at(i-1).at(j-1) == '#')
        count++;
      if (i > 0 && j < (W-1) && S.at(i-1).at(j+1) == '#')
        count++;
      if (i < (H-1) && j > 0 && S.at(i+1).at(j-1) == '#')
        count++;
      if (i < (H-1) && j < (W-1) && S.at(i+1).at(j+1) == '#')
        count++;
      cout << count;
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

n = ni()
a = list(na())

def gcd(n, m):
  while m:
    n, m = m, n%m
  return n

ans = a[0]
for e in a[1:]:
  ans = gcd(ans, e)
print(ans)


Measured memory_bytes: 14172
while True:
  try:
    hit=0
    blow =0
    a,b = raw_input(),raw_input()
    for x in range(0,7,2):
      for y in range(0,7,2):
        if a[x] == b[y]:
          if x == y: hit+=1
          else: blow +=1
    print hit,blow
  except EOFError:
      break

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

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int main(){
    int n;
    cin >> n;
    char mat[n][n];
    for(int i = 0; i < n*n; i++)    cin >> mat[i/n][i%n];
    int ret = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(mat[i][j] == 'x')    continue;
            mat[i][j] = 'x';
            ret++;
            queue<int> q;
            q.push(i*n+j);
            while(!q.empty()){
                int x = q.front();  q.pop();
                int I = x/n, J = x%n;
                for(int k = 0; k < 4; k++){
                    int ni = I+di[k], nj = J+dj[k];
                    if(inRange(ni,0,n)&&inRange(nj,0,n)&&mat[ni][nj]=='o'){
                        mat[ni][nj] = 'x';
                        q.push(ni*n+nj);
                    }
                }
            }
        }
    }
    cout << (ret-1)/3 << endl;
    return 0;
}


Measured memory_bytes: 3112
N, K = map(int, input().split())
P = list(map(int, input().split()))
result = 0
B = [a / 2 + 0.5 for a in P]

result = sum(B[0:K])
t = sum(B[0:K])
for i in range(N-K):
    t -= B[i]
    t += B[i+K]
    if t > result:
        result = t

print(result)

Measured memory_bytes: 24900
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <cassert>
using namespace std;
using VI = vector<long>;

long asum, bsum;

int main() {
    int n;
    cin >> n;
    VI as, bs;
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        as.push_back(a);
        asum += a;
    }
    
    for (int i = 0; i < n; i++) {
        long b;
        cin >> b;
        bs.push_back(b);
        bsum += b;
    }
    
    long turn = bsum - asum;
    if (turn < 0) {
        cout << "No" << endl;
        return 0;
    }
    
    long hoge = 0;
    for (int i = 0; i < n; i++) {
        if (as[i] < bs[i]) {
            hoge += (bs[i] - as[i] + 1) / 2;
        }
    }
    if (hoge <= turn) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            long[] nbrs = new long[N];
            long res;

            for (int i = 0; i < N; i++)
                nbrs[i] = long.Parse(Console.ReadLine());

            res = nbrs.Max();
            Array.Sort(nbrs);

            for(int i = nbrs.Length - 1; i > -1; i--)
            {
                long now = res;

                while(res % nbrs[i] != 0)
                    res += now;
            }

            Console.WriteLine(res);
        }
    }
}

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

int main() {
	// your code goes here
	int n, x, y;
	cin >> n >> x >> y;
	if(x > y) swap(x, y);
	int dist[n + 1][n + 1];
	int count[n];
	memset(count, 0, sizeof(count));
	for(int i = 1; i <= n; i++){
	    for(int j = 1; j <= n; j++){
	        dist[i][j] = 0;
	    }    
	}
	for(int i = 1; i <= n; i++){
	    for(int j = 1; j <= n; j++){
	        if(dist[i][j] == 0){
	            dist[i][j] = j - i;
	            if(i <= x && j >= y){
	                dist[i][j] -= (y - x - 1);
	            }
	            else if(i > x && j >= y){
	                dist[i][j] = min(dist[i][j], i - x + 1 + j - y);
	            }
	            else if(i <= x && j < y){
	                dist[i][j] = min(dist[i][j], x - i + 1 + y - j);
	            }
	            else if(i > x && j < y){
	                dist[i][j] = min(dist[i][j], i - x + 1 + y - j);
	            }
	            dist[j][i] = dist[i][j];
	            count[dist[i][j]]++;
	        }
	    }
	}
	for(int i = 1; i < n; i++){
	    cout << count[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 15872
from collections import Counter
from sys import stdin


def main():
    lines = stdin.readlines()
    N, K, Q = map(int, lines[0].split())
    A = Counter([int(i) - 1 for i in lines[1:]])
    print("\n".join(["Yes" if Q < K + A[i] else "No" for i in range(0, N)]))
    return


main()


Measured memory_bytes: 18152
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

int main(){
    int N; cin >> N;
    vector<int> p(N,0);
    rep(i,N) cin >> p[i];

    int ans = 0;
    rep(i,N){
        if (i+1 == p[i]){
            p[i+1] = p[i];
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout << max(0,c-a+b)<<"\n";
}

Measured memory_bytes: 256
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String p = sc.next();
        s = s + s;
        System.out.println(s.indexOf(p) >=0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 17276
import math
def main5():
    N, M = map(int, input().split())
    S = input()
    T = input()

    G = math.gcd(N, M)
    L = (N * M) // G

    for i in range(G):
        if S[i * N // G] != T[i * M // G]:
            print(-1)
            exit()

    print(L)

if __name__ == "__main__":
    main5()

Measured memory_bytes: 9400
N,A,B=map(int,input().split())

ans=0
n=A
while n<=N:
    if(n/10<1):
        if(n<=B):
            #print(n)
            ans+=n
    else:
        tmp=0
        temp=n
        while(temp!=0):
            a=temp%10
            tmp+=a
            temp=temp//10
        if(tmp<=B and tmp>=A):
            #print(n)
            ans+=n
    n+=1
print(ans)


Measured memory_bytes: 3060
import Control.Monad
import Data.Function
import Data.Char
import Data.List
import Text.Read
import Text.ParserCombinators.ReadPrec

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

data YN = Yes | No deriving (Show)

main :: IO ()
main = do
  x <- readLn
  print $ solve x

solve :: Int -> YN
solve x
  | x >= 30   = Yes
  | otherwise = No


Measured memory_bytes: 3924
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=2000009;
ll ara[22][22];
ll  n;
ll  dp[1LL<<22][22];
ll  call(ll  mask,ll  ind)
{
    if(mask==(1LL<<n)-1) return 1;
    ll  &ans=dp[mask][ind];
    if(ans!=-1) return ans;
    ans=0;
    for(ll  i=0;i<n;i++)
    {
        if(mask&(1<<i) or ara[ind][i]==false) continue;
        ans+=call(mask|(1LL<<i),ind+1);
        ans%=mod;
    }
    return ans;
}
int  main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(ll  i=0;i<n;i++)
    {
        for(ll  j=0;j<n;j++) cin>>ara[i][j];
    }
    cout<<call(0,0)<<endl;
}


Measured memory_bytes: 721152
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N, K;
  cin >> N >> K;

  if(K==0){
    cout << (ll)N*N << endl;
    return 0;
  }

  ll ans = 0;
  FOR(b, K+1, N+1) {
    ans += b - K;
    if(K > N%b){
      ans += ((N-K)/b) * (b-K);
    }else{
      ans += (N%b - K +1) * ((N-K)/b) + (b - (N%b)-1) * ((N-K)/b - 1);
    }
    //DUMP(ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int l, r;
    int d;
    cin >> l >> r >> d;

    int res = 0;
    for (int i = l; i <= r ; ++i) {
        if (i % d == 0) {
            ++res;
        }
    }

    cout << res << '\n';

    return 0;
}

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

using namespace std;

struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)

#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))

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

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

    int n; cin >> n;
    vi a(n);
    for (int i=0;i<n;++i) cin >> a[i];
    if (n == 2) {
        cout << max(a[0], a[1]);
        return 0;
    }

    vi gcd_up(n), gcd_down(n);
    gcd_up[0] = a[0];gcd_down[n-1] = a[n-1];
    for (int i=1;i<n;++i) gcd_up[i] = gcd(gcd_up[i-1], a[i]);
    for (int i=n-2;i>=0;--i) gcd_down[i] = gcd(gcd_down[i+1], a[i]);

    int max_gcd = 0;

    for (int i=0;i<n;++i) {
        if (i == 0 || i == (n-1)) {
            if (i == 0) max_gcd = max(max_gcd, gcd_down[1]);
            else max_gcd = max(max_gcd, gcd_up[n-2]);
        } else {
            max_gcd = max(max_gcd, gcd(gcd_up[i-1], gcd_down[i+1]));
        }
    }

    cout << max_gcd << "\n";

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int  a, b, c, d, i, j;
	int min(int x, int y);
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	i = min(a, b);
	j = min(c, d);
	printf("%d", i + j);
	return 0;
}
int min(int x, int y)
{
	int z;
	if (x > y)
		z = y;
	else z = x;
	return (z);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    A, B, C = map(int, input().split())

    for i in range(A, A*B+1, A):
        if i % B == C:
            print("YES")
            return

    print("NO")

if __name__ == "__main__": main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  int n, k, q, aa;
  cin >> n >> k >> q;
  vector<int> a(q);
  map<int, int> mp;
  rep(i, q) cin >> aa, mp[aa]++;

  for (int i = 1; i <= n; ++i) {
    if (k - q + mp[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string id[257];
    for(int i = 0; i < n; i++){
        cin >> id[i];
    }
    int lock = 0;
    int m;
    cin >> m;
    string x;
    for(int i = 0; i < m; i++){
        int cnt = 0;
        cin >> x;
        for(int j = 0; j < n; j++){
            if(x == id[j]){
                if(lock == 0){
                    lock = 1;
                    cout << "Opened by " << x << endl;
                }
                else{
                    lock = 0;
                    cout << "Closed by " << x << endl;
                }
                continue;
            }
            else cnt++;
        }
        if(cnt == n){
            cout << "Unknown " << x << endl;
        }
    }
        
    return 0;
}



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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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

    vector<int> v(N, 0);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        v[a - 1]++;
        v[b - 1]++;
    }

    bool ans = true;
    REP(i, N) {
        if(v[i] % 2){
            ans = false;
            break;
        }
    }

    cout << (ans ? "YES" : "NO") << endl;
    
    return 0;
}

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

int main() {
  int n;
  while(cin >> n){
    if(n==0) return 0;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int sum = accumulate(v.begin(), v.end(), 0);
    int cnt = 0;
    rep(i, n){
      if(v[i]<=sum/n) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI f(n);
	vector<VI> p(n,VI(11));
	
	rep(i, n) rep(j, 10){
		int q; cin >>q;
		if(q==1) f[i] |= 1<<j;
	};
	rep(i, n) rep(j, 11) cin >>p[i][j];
	
	ll ans = -1LL<<55;
	rep2(i, 1, 1<<10){
		ll sm = 0;
		rep(j, n){
			int mg = f[j] & i;
			int ct = __builtin_popcount(mg);
			sm += p[j][ct];
			//dbg(i,j,sm,ct,mg,f[j]);
		}
		ans = max(ans, sm);
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 2007;
const int INF = 2147483647;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n, m, Q;
int a[maxN];
pair<int, int> val[maxN], b[maxN];
bool vis[maxN];
int num[maxN];

int calc() {
	int tt = 0, bl = 0;
	for (int i = 1, j = 1; i <= n; i = j) {
		while (i <= n && vis[i]) ++i;
		if (i > n) break;
		for (j = i; j <= n && !vis[j]; ++j);
		int len = j - i;
		if (len < m) continue;
		num[++bl] = len - m + 1;
		rep (k, i, j-1) b[++tt] = (pair<int, int>){a[k], bl};
	}
	int cnt = 0, mx = 0;
	sort(b+1, b+tt+1);
	rep (i, 1, tt) if (num[b[i].second] > 0) {
		--num[b[i].second];
		mx = b[i].first;
		if (++cnt == Q) return mx;
	}
	return INF;
}

int main() {

	n = ri(), m = ri(), Q = ri();
	rep (i, 1, n) a[i] = ri();
	rep (i, 1, n) val[i] = (pair<int, int>){a[i], i};
	sort(val+1, val+n+1);
	
	int res = INF;
	for (int i = 1, j = 1; i <= n; i = j) {
		res = min(res, calc() - val[i].first);
		for (; j <= n && val[i].first == val[j].first; ++j)
			vis[val[j].second] = true;
	}
	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main()
{
 
  int i,j,minj,n,flag=1,cmp,hantei=0;
  char b[36][3],s[36][3],sw[36][3];
   
 
  /*??\???*/
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
 
    scanf("%s",b[i]);
 
    strcpy(s[i],b[i]);
     
      }
   
  i=0;
  while(flag){
    flag = 0;
for (j = n - 1; j >= i+1; j--) {
      if (b[j - 1][1] > b[j][1]) { 
    strcpy(sw[j],b[j]);        
    strcpy( b[j],b[j - 1]);
    strcpy( b[j - 1],sw[j]);
    flag = 1;
      }
 }
    i++;
  }
   
 
  for(i=0;i<n;i++){
 
    minj = i;
 
    for(j=i;j<n;j++){
      if(s[j][1] < s[minj][1]){
    minj = j;
      }
    }
    if(i != minj){
    
    strcpy(sw[i] ,s[i]);
    strcpy(s[i],s[minj]);
    strcpy(s[minj],sw[i]);
    }
  }
 
  /*BS??????*/
  for(i=0;i<n-1;i++){
 
    printf("%s ",b[i]);
  }
    printf("%s",b[i]);
   
 
  printf("\n");
  printf("Stable\n");
  /*SS??????*/
  for(j=0;j<n-1;j++){
 
    printf("%s ",s[j]);
 
  }
  printf("%s",s[j]);
  printf("\n");
  flag = 1;
  for(i=0;i<n;i++){
 
 
    if(strcmp(&b[i][0],&s[i][0])!=0 && hantei==0){
      printf("Not stable\n");
      flag=0;
      hantei++;
    }
  }
  if(flag==1){
    printf("Stable\n");
  }
 return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    string s,t;
    cin>>s>>t;
    cout<<t<<s;
}
int32_t main()
{
    // clock_t tStart = clock();
    // #ifndef ONLINE_JUDGE
    // _READ
    // #endif
    
    int t;
    t=1;
    while(t--)
        solve();
    
    // #ifndef ONLINE_JUDGE
    // cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    // #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    long long int n,i;
    cin >> n;
    i=sqrt(n);
    while(1){
        if(n%i==0){
            cout << n/i+i-2;
            break;
        }
        i--;
    }
    return 0;
}

Measured memory_bytes: 256
X,A,B=input().split()
numbers=[]
N=int(X)
 
def digitsum(n):
    s=str(n)
    array=list(map(int,s))
    return sum(array)
 
 
 
for num in range(1,N+1):
    if int(A)<=int(digitsum(num)) and int(digitsum(num))<=int(B):
        numbers.append(num)
    else:
        continue
 
print(sum(numbers))

Measured memory_bytes: 3524
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)
vector<ll> fact, invfact;
ll modpow(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll a)
{
    return modpow(a, MOD - 2);
}

ll nCk(ll n, ll k)
{
    ll inv = 1;
    ll fact = 1;
    repi(i,k,0){
        fact *= (n-i);
        fact %= MOD;
    }
    repi(i, k + 1, 1)
    {
        inv *= modinv(i);
        inv %= MOD;
    }
    return fact * inv % MOD;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll bin = modpow(2,n);
    ll ans = (bin - 1 - nCk(n, a) - nCk(n, b)) % MOD;
    if(ans < 0)ans += MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import string
n = int(input())

al = defaultdict(int)
old = defaultdict(int)

s = input()
for j in s:
  old[j] += 1
  al[j] += 1

for i in range(n-1):
  s = input()
  d = defaultdict(int)
  for j in s:
    d[j] += 1
  for k in string.ascii_lowercase:
    al[k] = min(old[k], d[k], al[k])
  old = d
ans = ""
for k in string.ascii_lowercase:
  ans += k * al[k]
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = 1000000000000000010;
  if ((a+b) % 2 == 0) {
    ll x = (a+b) / 2;
    ans = b - x;
    ans = min(ans, x - a);
  } else {
    ans = (b + (a-1)) / 2;
    ans = min(ans, n-ans);
  }

  cout << ans << endl;

  return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int32 n,m;
vector<string> c;

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

bool dfs(int32 y, int32 x,int32 dir = 2){
  // cout << y << " " << x << " " << dir <<  "\n";
  if(y == n-1 && x == 0)return true;
  if(c[y][x] == '#')return false;
  c[y][x] = '#';
  dir = (dir-1+4)%4;
  REP(k,4){
    int32 ny = y+dy[(dir+k)%4];
    int32 nx = x+dx[(dir+k)%4];
    if(ny < 0 || n <= ny)continue;
    if(nx < 0 || m <= nx)continue;
    if(dfs(ny,nx,(dir+k)%4))return true;
  }
  return false;
}

void solve(){
  c = vector<string>(n);
  REP(i,n)cin >> c[i];
  REP(lp,4){
    if(!dfs(0,0)){
      // REP(i,n){
      //   cout << c[i] << "\n";
      // }
      // cout << "\n";

      ANS("NO");
      return;
    }
    // REP(i,n){
    //   cout << c[i] << "\n";
    // }
    // cout << "\n";

    vector<string> tmp = c;
    c = vector<string>(m,string(n,'*'));
    REP(i,m){
      REP(j,n){
        c[i][j] = tmp[n-j-1][i];
      }
    }
    swap(n,m);
  }
  ANS("YES");
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(true){
    cin >> n >> m;
    if(n==0)return 0;
    solve();
  }
  return 0;
}


Measured memory_bytes: 3260
M=[ 31, 29, 31, 30, 31,30,31,31,30,31,30,31]
DAY=["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"]


m=2
d=29

	

while True:
	m,d=map( int , raw_input().split() )
	if m==d==0:
		quit()
	else:
		x=0
		for i in range(m-1):
			x+=M[i]
		x+=d
		print DAY[x%7]




Measured memory_bytes: 4648
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.io.*;

public class Main{
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";


	public static void main(String[] args) throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		solver();
		out.flush();
	}

	static long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	static char nc()
	{
		try {
			int b = skip();
			if(b == -1)return 0;
			return (char)b;
		} catch (IOException e) {
		}
		return 0;
	}

	static double nd()
	{
		try {
			return Double.parseDouble(ns());
		}catch(Exception e) {
		}
		return 0;
	}

	static String ns()
	{
		try{
			int b = skip();
			StringBuilder sb = new StringBuilder();
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b <= ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public static char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = skip(), p = 0;
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b <= ' ')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	public static byte[] nse(int n)
	{
		byte[] buf = new byte[n];
		try{
			int b = skip();
			if(b == -1)return null;
			is.read(buf);
			return buf;
		} catch (IOException e) {
		}
		return null;
	}

	static int skip() throws IOException
	{
		int b;
		while((b = is.read()) != -1 && !(b >= 33 && b <= 126));
		return b;
	}

	static boolean eof()
	{
		try {
			is.mark(1000);
			int b = skip();
			is.reset();
			return b == -1;
		} catch (IOException e) {
			return true;
		}
	}

	static int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}


	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = ni();
		int k = ni();
		int[] d = new int[k];
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < k; i++) {
			d[i] = ni();
			set.add(d[i]);
		}
		while (true) {
			int tmp = n;
			while (tmp >= 1) {
				if (set.contains(tmp % 10)) {
					break;
				}
				tmp /= 10;
			}
			if (tmp == 0) {
				out.println(n);
				return;
			}
			n++;
		}
	}
}


Measured memory_bytes: 9556
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n,x;
cin>>n;
set<int> st;
string ans="YES";
while(n--)
{
cin>>x;
if(st.count(x))
{
ans="NO";
break;
}
st.insert(x);
}
cout<<ans;
}

Measured memory_bytes: 12888