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

using namespace std;

vector<string> memo;

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

//    vector<string> memo;
    int cnt = 0;


    for (int i = 0; i < 26; ++i) {
        char search = char('a' + i);
        for (int j = 0; j < s.length(); ++j) {
            if (s[j] == search) {
                for (int k = 1; k <= s.length() - j; ++k) {
                    string sub = s.substr(j, k);
                    memo.push_back(sub);
//                    cnt++;
//                    if (cnt > 100) break;
                    if (k == 5) break;
                }
            }
//            if (cnt > 500) break;
        }
//        if (cnt >= 4) break;
    }
//    for (int i = 0; i < memo.size(); ++i) {
//        cout << memo[i] << endl;
//    }


    sort(memo.begin(), memo.end());
//    cout << "sorted" << endl;
//    for (int i = 0; i < memo.size(); ++i) {
//        cout << memo[i] << endl;
//    }

    unique(memo.begin(), memo.end());
//    cout << "uniqued" << endl;
//    for (int i = 0; i < memo.size(); ++i) {
//        cout << memo[i] << endl;
//    }

    cout << memo[K - 1] << endl;

//    cout << memo[K] << endl;
//    string ans;
//    if (K == memo.size()) {
//        ans = memo[K - 1];
//    } else {
//        cnt = 0;
//        for (int i = 1; i < memo.size(); ++i) {
//            if (memo[i - 1] != memo[i]) {
//                cnt++;
//                if (cnt == K) {
//                    ans = memo[i - 1];
//                    break;
//                }
//            }
//        }
//    }
//
//    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int dp[600000],n,a,cnt;
long long ans;
map<int,int> mp;
vector<int> v;
void BITadd(int a,int b){
    while(a>0){
        dp[a]+=b;
        a-=a&(-a);
    }
    return ;
}
int BITsum(int a){
    int tot=0;
    while(a<600000){
        tot+=dp[a];
        a+=a&(-a);
    }
    return tot;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        v.push_back(a);
        mp[a]=1;
    }
    for(auto x:mp){
        mp[x.first]+=cnt++;
    }
    for(int i=0;i<n;i++){
        a=mp[v[i]];
        ans+=BITsum(a);
        BITadd(a,1);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 13748
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N),b(N),c(N);
    REP(i,N) cin>>a[i];
    REP(i,N) cin>>b[i];
    REP(i,N) cin>>c[i];

    sort(ALL(a));
    sort(ALL(c));

    int ans=0;
    REP(i,N){
        int x=lower_bound(ALL(a),b[i])-a.begin();
        int y=upper_bound(ALL(c),b[i])-c.begin();
        ans+=x*(N-y);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
double A,B;
  cin>>A>>B;
  
  double minA,maxA,minB,maxB;
  minA=A*12.5;
  maxA=(A+1)/0.08;
  minB=B*10;
  maxB=(B+1)/0.1;
  
  double min,max;
  if(minA>minB)min=minA;
  else min=minB;
  max=std::min(maxA,maxB);
  
  double ans;
  ans=std::ceil(min);
  if(ans>=max)ans=-1;
  
cout<<ans<<endl;
  
  
}


Measured memory_bytes: 256
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<int>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;

int main()
{
    int n;
    scn(n);
  
    cout<<((n*(n+1))/2)<<endl;
}



Measured memory_bytes: 3728
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){    
  int A,B,sum=0;
  cin >> A >> B;

  if(A > B){
    sum += A;
    A = A-1;
    if(A > B){
      sum += A;
    }
    else{
      sum += B;
    }
  }
  else{
    sum += B;
    B = B-1;
    if(A > B){
      sum += A;
    }
    else{
      sum += B;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 300001
bool prime[MAX];

void hurui(){
  for(int i=0;i<MAX;++i)
    prime[i] = (i%7==1 || i%7==6) ? true : false; //MSn -> true
  for(int i=6; i*i<MAX; ++i){
    if(prime[i]){
      for(int j=i*i; j<MAX; j+=i) prime[j] = false; //MSn*x -> false
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  hurui();
  int n;
  while(cin>>n, n!=1){
    cout<<n<<":";
    for(int i=2; i<=n; ++i){
      if(prime[i] && n%i==0) cout<<" "<<i;
    }
    cout<<endl;
  }
  return 0;
}

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

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

int main() {
  int n,e,t;
  cin>>n>>e>>t;
  t--;
  int dp[n];
  REP(i,n) {
    bool w;cin>>w;
    dp[i] = w?1:INF;
  }
  vector<vector<int> > v[n];
  REP(i,e) {
    int g, c;
    cin >>g>>c;
    g--;
    vector<int> tmpv;
    REP(j,c) {
      int s;
      cin >> s;
      s--;
      tmpv.push_back(s);
    }
    v[g].push_back(tmpv);
  }
  bool update = 1;
  while(update) {
    update = 0;
    REP(i,n) {
      if (v[i].size()==0)continue;
      FOR(it, v[i]) {
        vector<int> tmpv;
        FOR(jt, *it) {
          tmpv.push_back(dp[*jt]);
        }
        sort(ALL(tmpv), greater<int>());
        int tmp = 0;
        REP(j, tmpv.size()) {
          tmp = max(tmp, j+tmpv[j]);
        }
        //printf("i=%d tmp=%d\n",i,tmp);
        if (dp[i] > tmp) {
          update = 1;
          dp[i] = tmp;
        }
      }
    }
  }
  if (dp[t] == INF) cout << -1 << endl;
  else cout << dp[t] << endl;
}

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll k;cin>>k;

  if(k%2LL==0){ cout<<-1<<endl; return 0; }

  ll ss=7%k;
  rep1(i, 10000000){
    if(ss==0){cout<<i<<endl; return 0;}
    ss*=10LL;
    ss+=7LL;
    ss%=k;
  }

  cout<<-1<<endl;

  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cmath>
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		long long a,b,c;
		scanf("%lld%lld",&a,&b);
		c=int(sqrt(a*b));
		if(c*(c+1)<a*b)
			printf("%lld\n",2*c-1);
		else if(c*c==a*b){
			if(a==b)
				printf("%lld\n",2*c-2);
			else
				printf("%lld\n",2*c-3);
		}
		else
			printf("%lld\n",2*c-2);
	}
}


Measured memory_bytes: 128
# -*- 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(N):
    ans = 0

    d = Counter()
    for i in range(N+1):
        l = len(str(i))
        a = i // 10 ** (l-1)
        b = i % 10
        if a != 0 and b != 0:
            d[(a, b)] += 1

    ans = 0
    for a, b in product(range(1, 10), repeat=2):
        ans += d[(a, b)] * d[(b, a)]
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5456
n, y = map(int, input().split())

for i in range(0,n+1,1):
    for j in range(0,n-i+1,1):
        k = n - i - j
        if i * 10000 + j * 5000 + k * 1000 == y:
            print(i,j,k)
            exit()

print(-1,-1,-1)


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

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

int main () {
    int K;
    cin >> K;

    int ans = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
string a,b;
int main()
{
    cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
    cout<<"YES";
    else
    cout<<"NO";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef vector<ll>   vll;
typedef vector<int>   vi;
typedef set<ll>      sll;
typedef set<int>      si;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

ll i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}

// #define cerr if(0)cerr
void solve()
{
	ll n,l; cin>>n>>l;
	ll s=0;
	rep(i,1,n)
	 s+=l+i-1;

	ll ans=s,min=mod;
    rep(i,1,n)
       if(abs(l+i-1)<min)
       	 {
       	 	min=abs(l+i-1); 
       	 	ans=s-(l+i-1);
       	 }
       	 cout<<ans<<'\n';

}

Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
  xs <- (map read . words) <$> getLine
  putStrLn $ show (solve (xs !! 0) (xs !! 1) (xs !! 2))

solve :: Int -> Int -> Int -> Int
solve a b c
  | a > b = 0
  | (mod c a) == 0 = 1 + solve (a + 1) b c
  | otherwise = solve (a + 1) b c


  

Measured memory_bytes: 3876
l=[int(input()) for i in range(5)]
t=0
mx=10
for i in l:
    if i%10!=0 and i%10<mx:
        mx=i%10
    if i%10==0:
        t+=i
    else:
        t+=int(i/10.0)*10+10


print(t-10+mx)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

vector<vector<pair<long, pair<long,long>> > > zz;    // neighbor, cost, cost
ll dist0[100005];
ll dist1[100005];
ll dist[100005];

void dfs0( long bgn, ll val0 )
{
    priority_queue<pair<ll,long>, vector<pair<ll,long> >, greater<pair<ll,long> > > que;

    que.push( make_pair( val0, bgn ) );
    while( !que.empty() ) {
        auto tmp = que.top();
        que.pop();
        long curr = tmp.second;
        ll   val  = tmp.first;

        if(dist0[curr]==LINF) {
            dist0[curr] = val;
            long n = (long)zz[curr].size();
            long i;
            for(i=0; i<n; i++) {
                long next = zz[curr][i].first;
                ll   val2 = val + zz[curr][i].second.first;
                if(dist0[next]>val2) {
                    que.push( make_pair( val2, next ) );
                }
            }
        }
    }

    return;
}

void dfs1( long bgn, ll val0 )
{
    priority_queue<pair<ll,long>, vector<pair<ll,long> >, greater<pair<ll,long> > > que;

    que.push( make_pair( val0, bgn ) );
    while( !que.empty() ) {
        auto tmp = que.top();
        que.pop();
        long curr = tmp.second;
        ll   val  = tmp.first;

        if(dist1[curr]==LINF) {
            dist1[curr] = val;
            long n = (long)zz[curr].size();
            long i;
            for(i=0; i<n; i++) {
                long next = zz[curr][i].first;
                ll   val2 = val + zz[curr][i].second.second;
                if(dist1[next]>val2) {
                    que.push( make_pair( val2, next ) );
                }
            }
        }
    }

    return;
}

int main(int argc, char* argv[])
{
    long n, m, s, t;
    scanf("%ld%ld%ld%ld", &n, &m, &s, &t);

    zz.resize(n);

    vector<long> u(m), v(m), a(m), b(m);
    long i;
    for(i=0; i<m; i++) {
        scanf("%ld%ld%ld%ld", &u[i], &v[i], &a[i], &b[i]);
        zz[u[i]-1].push_back(make_pair(v[i]-1, make_pair(a[i], b[i])));
        zz[v[i]-1].push_back(make_pair(u[i]-1, make_pair(a[i], b[i])));
    }

    for(i=0; i<n; i++) {
        dist0[i]=LINF;
    }
    dfs0( s-1, 0 );

    for(i=0; i<n; i++) {
        dist1[i]=LINF;
    }
    dfs1( t-1, 0 );

    for(i=0; i<n; i++) {
        dist[i] = dist0[i]+dist1[i];
    }

    for(i=n-2; i>=0; i--) {
        dist[i] = MIN(dist[i], dist[i+1]);
    }
    for(i=0; i<n; i++) {
        printf("%lld\n", 1000000000000000 - dist[i]);
    }

    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int A, V;
  int B, W;
  int T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;

  if(A >= B){
    swap(A,B);
  }
  
  if(V <= W){
    cout << "NO" << endl;
    return 0;
  }

  ll diff = V-W;
  ll t = (B-A + diff-1)/diff;
  if(t <= T){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
	int n,m,x,y,i,ans;
	cin >> n >> m;
	
	UnionFind tree(n);
	ans=n;
	for(i=0; i<m; i++){
		cin >> x >> y;
		x--; y--;
		if(!(tree.same(x,y))){
			tree.unite(x,y); ans--;
		}
		cin >> y;
	}
	cout << ans;
	
}

Measured memory_bytes: 640
#include <stdio.h>

#define MAX (1<<(2*12))

void init();
void insert(char *str);
int find(char *str);
int get_hash(char *str);

const int key[] = {
    0  /* A */
    ,0 /* B */
    ,1 /* C */
    ,0 /* D */
    ,0 /* E */
    ,0 /* F */
    ,2 /* G */
    ,0 /* H */
    ,0 /* I */
    ,0 /* J */
    ,0 /* K */
    ,0 /* L */
    ,0 /* M */
    ,0 /* N */
    ,0 /* O */
    ,0 /* P */
    ,0 /* Q */
    ,0 /* R */
    ,0 /* S */
    ,3 /* T */
};

char dic[MAX];

int main(){
    char cmd[7];
    char str[13];
    int n;
    int i;

    init();

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s %s",cmd,str);
        if(cmd[0]=='i'){
            /* cmd is "insert" */
            insert(str);
        }else if(cmd[0]=='f'){
            /* cmd is "find" */
            printf(find(str)?"yes\n":"no\n");
        }
    }

    return 0;
}

void init(){
    int i;
    for(i=0;i<MAX;i++)dic[i]=0;
}

void insert(char *str){
    dic[get_hash(str)]=1;
}

int find(char *str){
    return dic[get_hash(str)];
}

int get_hash(char *str){
    int hash;
    int idx;

    hash=1;
    for(idx=0;str[idx];idx++){
        hash<<=2;
        hash+=key[str[idx]-'A'];
    }

    return hash;
}

Measured memory_bytes: 18240
n=int(input())
a=[int(x) for x in input().split()]

dic1={}
dic2={}
for i in range(n):
  if i+1+a[i] not in dic1:
    dic1[i+1+a[i]]=1
  else:
    dic1[i+1+a[i]]+=1

for i in range(n):
  if i+1-a[i] not in dic2:
    dic2[i+1-a[i]]=1
  else:
    dic2[i+1-a[i]]+=1

ans=0

for i in dic1:
  if i not in dic2:
    continue

  ans+=dic1[i]*dic2[i]
print(ans)

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

using namespace std;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    int res = 0;

    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (x >= k) res++;
    }

    printf("%d\n", res);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir[8] = { //?§????
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

signed main() {
	int n, m;

	while (scanf("%d %d", &n, &m)) {
		if (!n)
			break;
		vector<int> po(n);
		REP(i, n) {
			scnaf("%d", &po[i]);
		}
		po.push_back(0);
		vector<int> toku;
		REP(i, n + 1) {
			REP(j, n + 1) {
				toku.push_back(po[i] + po[j]);
			}
		}
		sort(ALL(toku));
		toku.erase(unique(ALL(toku)),toku.end());
		int ans = 0;
		for (auto itr : toku) {
			if (m >= itr) {
				auto itr2 = --upper_bound(ALL(toku), m - itr);
				if (itr2 != toku.end())
					ans = max(itr + *itr2, ans);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 10788
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int h, w;
int maze[1010][1010];
vector<pair<int, pair<int, int>>> v;
int memo[1010101];
int ans;

int main() {
	cin >> h >> w;
	REP(i, h)REP(j, w) {
		cin >> maze[i][j];
		v.push_back(make_pair(maze[i][j], make_pair(i, j)));
	}
	sort(ALL(v));
	REP(i, v.size()) {
		int next = v[i].first;
		int cnt = 0;
		pair<int, pair<int, int>> now = v[i];
		bool flg = false;
		REP(j, 4) {
			int nx = now.second.first + dx[j];
			int	ny = now.second.second + dy[j];
			if (0 > nx || nx >= h || 0 > ny || ny >= w)continue;
			if (maze[nx][ny] == -1) {
				maze[now.second.first][now.second.second] = -1;
				flg = true;
				ans++;
				break;
			}
			if (maze[nx][ny] > maze[now.second.first][now.second.second])continue;
			if (memo[maze[nx][ny]] != i + 1) {
				memo[maze[nx][ny]] = i + 1;
				cnt++;
				next = maze[nx][ny];
			}
		}
		if (!flg && cnt > 1) {
			ans++;
			maze[now.second.first][now.second.second] = -1;
		}
		else if (!flg)maze[now.second.first][now.second.second] = next;
	}
	cout << ans << endl;
}


Measured memory_bytes: 18640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

bool ok(const string& str) {
  char mx = 'a';
  for(char c:str) {
    if (c > mx+1) return false;
    mx = max(mx, c);
  }
  return true;
}

void solve(int n, int i, const string& str) {
  if (n == i) {
    if(ok(str)) cout<<str<<'\n';
    return;
  }
  for(auto&& j:irange(0,i+1)) {
    string nx = str;
    nx += 'a' + j;
    solve(n,i+1,nx);
  }
}

int main() {
  int n;
  cin>>n;
  solve(n, 0, "");
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N, W; cin >> N >> W;
  Vll w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];

  VVll dp(N+1, Vll(W+1));
  rep(i, N) rep(j, W+1) {
    dp[i+1][j] = dp[i][j];
    int jj = j-w[i];
    if (jj >= 0) chmax(dp[i+1][j], dp[i][jj] + v[i]);
  }

  ll ans = dp[N][W];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 80256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c;
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
A = set(a)
MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
    if i in A:
        dp[i] = -1
        continue
    if i == 1:
        if not i - 1 in a:
            dp[i] = 1
    else:    
        if dp[i - 1] != -1:
            dp[i] += dp[i - 1] % MOD
        if dp[i - 2] != -1:
            dp[i] += dp[i - 2] % MOD
print(dp[-1] % MOD)

Measured memory_bytes: 13216
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll n, m, d;
  cin >> n >> m >> d;
  ll on, tw;
  if (d == 0) {
    on = n, tw = 0;
  } else {
    on = min(d * 2, n), tw = n - on;
  }

  printf("%.10f\n", double(m - 1) * double(1) / double(n) * 2.0 * double(tw) / double(n) + double(m - 1) * double(1) / double(n) * double(on) / double(n));
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  map<int64_t, int64_t> m;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    if (m.find(a) == m.end()) {
      m[a] = 1;
    } else {
      ++m[a];
    }
  }
  int64_t result = 0;
  for (const auto a : m) {
    if (a.second >= a.first) {
      result += (a.second - a.first);
    } else {
      result += a.second;
    }
  }
  cout << result << endl;
  return 0;
}


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

// @author: pashka

const int MAX = 159 * 80;
int a[80][80];
bool d[80][80][MAX + 1];

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x; cin >> x;
            a[i][j] += x;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x; cin >> x;
            a[i][j] -= x;
            a[i][j] = abs(a[i][j]);
        }
    }

    d[0][0][a[0][0]] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k <= MAX; k++) {
                if (!d[i][j][k]) continue;
                if (i < n - 1) {
                    d[i + 1][j][k + a[i + 1][j]] = true;
                    d[i + 1][j][abs(k - a[i + 1][j])] = true;
                }
                if (j < m - 1) {
                    d[i][j + 1][k + a[i][j + 1]] = true;
                    d[i][j + 1][abs(k - a[i][j + 1])] = true;
                }
            }
        }
    }

    int res = 0;
    while (!d[n - 1][m - 1][res]) res++;
    cout << res;

    return 0;
}

Measured memory_bytes: 78848
N, K = map(int, input().split())
A = list(map(lambda a: int(a) - 1, input().split()))

T = [A]
for _ in range(64):
    prev = T[-1]
    T.append([prev[a] for a in prev])

now = 0
for d, P in enumerate(T):
    if ((1 << d) & K) > 0:
        now = P[now]
print(now + 1)


Measured memory_bytes: 218352
package main

import (
        "fmt"
)

func solution(x, y int) string {
        for i := 0; i <= x; i++ {
                j := x - i
                if i*4+j*2 == y {
                        return "Yes"
                }
        }
        return "No"
}

func main() {
        var x, y int
        fmt.Scan(&x, &y)
        fmt.Println(solution(x, y))
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define INF 2e9+7
using namespace std;
using pii=pair<int,int>;
using ll=long long int;



int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    string n; cin>>n;
    bool ok=false;
    for(int i=0;n[i];i++) {
        if(n[i]=='7') ok=true;
    }
    cout<<(ok?"Yes":"No")<<endl;

}


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

vector<vector<int>> nPn(vector<int>vec){
  vector<vector<int>>tmp(0);
  sort(vec.begin(),vec.end());
  do{
    tmp.push_back(vec);
  }while (next_permutation(vec.begin(),vec.end()));
  return tmp;
}

bool is_there_path(int M,vector<int>A,vector<int>B,int j1,int j2){
  bool res = false;
  for (int i=0;i<M;i++){
    if (A.at(i)-1 == j1 && B.at(i)-1 == j2){
      res = true;
    }
    if (A.at(i)-1 == j2 && B.at(i)-1 == j1){
      res = true;
    }
  }
  return res;
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int>A(M);
  vector<int>B(M);
  for (int i=0;i<M;i++){
    cin >> A.at(i) >> B.at(i);
  }
  vector<int>S(N);
  for (int i=0;i<N;i++){
    S.at(i) = i;
  }
  vector<vector<int>>R;
  R = nPn(S);
  int ans = 0;
  for (int i=0;i<R.size();i++){
    if (R.at(i).at(0)==0){
      bool res = true;
      for (int j=0;j<R.at(i).size()-1;j++){
        int j1 = R.at(i).at(j);
        int j2 = R.at(i).at(j+1);
        if (!is_there_path(M,A,B,j1,j2)){
          res = false;
        }
      }
      if (res){
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int main()
{
	string x;cin>>x;
	for(int i=1;i<=x.length();i++)putchar('x');
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#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 all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  vector<int> D;
  while(n > 0) {
    D.push_back(n%10);
    n /= 10;
  }
  reverse(all(D));
  int d = D.size();
  vector<vector<int>> dp(d+1, vector<int>(2));
  rep(i, d) {
    if(i == 0) {
      dp[i+1][0] = max(dp[i][0]+D[i], dp[i+1][0]);
      dp[i+1][1] = max(dp[i][0]+D[i]-1, dp[i+1][1]);
    } else {
      dp[i+1][0] = max(dp[i][0]+D[i], dp[i+1][0]);
      dp[i+1][1] = max({dp[i][0]+D[i]-1, dp[i][1]+9, dp[i+1][1]});
    }
  }
  cout << max(dp[d][0], dp[d][1]) << "\n";
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

const ll mod = 1'000'000'007;

auto main (void) -> int {
  int n;
  cin >> n;

  vector<int> a (n);
  for (auto i = 0; i < n; i++) cin >> a[i];

  ll tmp_0 = 0;
  ll tmp_1 = 0;

  for (auto i = 0; i < n; i++) {
    auto c = static_cast<ll> (a[i]);
    tmp_0  = (tmp_0 + c) % mod;
    tmp_1  = (tmp_1 + c * c) % mod;
  }
  tmp_0 = (tmp_0 * tmp_0) % mod;

  auto b = tmp_0 < tmp_1 ? tmp_0 - tmp_1 + mod : tmp_0 - tmp_1;

  cout << (b + (b % 2) * mod) / 2 << endl;

  return 0;
}


Measured memory_bytes: 3968
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	char s[2000][2000];
	for(int i=0; i<h; i++){
		scanf("%s", s[i]);
	}
	bool x1[2000][2000], x[2000][2000];
	int n[2000][2000];
	for(int i=0; i<h; i++){
		for(int j=0; j<w-1; j++){
			if(s[i][j]==s[i][j+1]){
				x1[i][j]=0;
			}else{
				x1[i][j]=1;
			}
		}
	}
	for(int i=0; i<h-1; i++){
		for(int j=0; j<w-1; j++){
			if(x1[i][j]==x1[i+1][j]){
				x[i][j]=0;
			}else{
				x[i][j]=1;
			}
		}
		int t=w-1;
		for(int j=w-2; j>=0; j--){
			if(x[i][j]==1){
				t=j;
				n[i][j]=0;
			}else{
				n[i][j]=t-j;
			}
		}
	}
	int ans=max(h, w);
	for(int j=0; j<w-1; j++){
		int l[2000], r[2000];
		vector<int> v;
		for(int i=0; i<h-1; i++){
			while(!v.empty()){
				int x=v.back();
				if(n[x][j]>=n[i][j]){
					v.pop_back();
				}else{
					break;
				}
			}
			if(v.empty()){
				l[i]=0;
			}else{
				l[i]=v.back()+1;
			}
			v.push_back(i);
		}
		vector<int> v2;
		for(int i=h-2; i>=0; i--){
			while(!v2.empty()){
				int x=v2.back();
				if(n[x][j]>=n[i][j]){
					v2.pop_back();
				}else{
					break;
				}
			}
			if(v2.empty()){
				r[i]=h-1;
			}else{
				r[i]=v2.back();
			}
			v2.push_back(i);
		}
		for(int i=0; i<h-1; i++){
			if(ans<((n[i][j]+1)*(r[i]-l[i]+1))) ans=((n[i][j]+1)*(r[i]-l[i]+1));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 27648
def main():
    D, G, *pc = map(int, open(0).read().split())
    p = pc[::2]
    c = pc[1::2]
    # コンプリート
    comp = [c[i] + 100 * (i + 1) * p[i] for i in range(D)]

    def dfs(G, i):
        # G 総合スコア
        # i 問題 1-based indexing
        if i <= 0:
            # 目標の 総合スコア に到達しなかった
            return 1e9 + 7
        score = 0
        num = 0
        if G // (100 * i) < p[i - 1]:
            # コンプリートしない
            num = G // (100 * i)
            score = 100 * i * num
        else:
            # コンプリートする
            num = p[i - 1]
            score = comp[i - 1]
        if score < G:
            num += dfs(G - score, i - 1)
        return min(num, dfs(G, i - 1))
    print(dfs(G, D))


main()


Measured memory_bytes: 3188
def main():
    N = int(input())
    A = list(map(lambda x: int(x)+100, input().split()))
    avg = int(sum(A)/N + 0.5)
    ans = 0
    for i in range(N):
        ans += (A[i] - avg)**2
    print(ans)


if __name__ == "__main__":
    main()


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

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

int main()
{
    int k;
    long long n=0;
    cin >> k;
    int a[205][205];
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            a[i][j] = gcd(i, j);
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int l = 1; l <= k; l++) {
                if (i == 1 || j == 1 || l == 1) n += 1;
                 else n += gcd(a[i][j], l);
            }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3772
import math

[A,B,H,M] = [int(x) for x in input().split()]

h_speed = 2 * math.pi / (12 * 60)
m_speed = 2 * math.pi / 60

h_agree = (h_speed * (H * 60 + M)) % (2 * math.pi)
m_agree = (m_speed * (H * 60 + M)) % (2 * math.pi)
true_agree = abs(h_agree - m_agree)
if true_agree >=  math.pi:
     true_agree = 2 * math.pi - true_agree


l_distance = max(A,B)
s_distance = min(A,B)

answer = ((math.sin(true_agree) * s_distance) ** 2 + (l_distance - math.cos(true_agree) * s_distance) ** 2) ** 0.5

print(answer)


Measured memory_bytes: 9596
#include <stdio.h>
#include <string.h>
int main(void)
{
    int k;
    int kuro = 0;
    char S[15];
    scanf("%s", S);
    k = strlen(S);
    for (int i = 0; i <= k; i++) {
        if (S[i] == 'x') {
            kuro++;
        }
    }
    if (kuro >= 8) {
        printf("NO");
    }
    else {
        printf("YES");
    }
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.JSC_2019_qual
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            string s = Read();
            long mask = 1000000000 + 7;
            long pats = 1;
            long remain = 0;
            for(int i = 0; i < 2*n; i++)
            {
                if (s[i] == 'B')
                {
                    if (remain % 2 == 1)
                    {
                        pats *= remain;
                        pats %= mask;
                        remain--;
                    }
                    else
                    {
                        remain++;
                    }
                }
                else
                {
                    if (remain % 2 == 1)
                    {
                        remain++;
                    }
                    else
                    {
                        if (remain == 0)
                        {
                            WriteLine(0);
                            return;
                        }
                        else
                        {
                            pats *= remain;
                            pats %= mask;
                            remain--;
                        }
                    }
                }
            }
            if (remain > 0)
            {
                WriteLine(0);
                return;
            }
            for(long i = 1; i <= n; i++)
            {
                pats *= i;
                pats %= mask;
            }
            WriteLine(pats);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13664
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
      
        int a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(0);
        }
	}
}

Measured memory_bytes: 64328
#include <stdio.h>

int main(void)
{
  double A[1000],s,m;
  int i,N;

  scanf("%d",&N);

  for(i=0;i<N;i++){
   scanf("%lf",&A[i]);
   m=m+1/A[i];
  }
  s=1/m;

  printf("%lf\n",s);

 return 0;
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
C_h, C_w = map(lambda x:int(x) - 1,input().split())
D_h, D_w = map(lambda x:int(x) - 1,input().split())
S = [input() for _ in range(H)]

waiting = deque()
went = [[10**9]*W for _ in range(H)]
waiting.append([0, C_h, C_w])

ans = -1
while len(waiting) > 0:
    n, cur_h, cur_w = waiting.popleft()
    if cur_h == D_h and cur_w == D_w:
        ans = n
        break
    if went[cur_h][cur_w] > n:
        went[cur_h][cur_w] = n
        for i in range(-2, 3):
            for j in range(-2, 3):
                next_h = cur_h + i
                next_w = cur_w + j
                if 0 <= next_h < H and 0 <= next_w < W:
                    if (i == 0 and j == -1) or (i == 0 and j == 1) or (i == -1 and j == 0) or (i == 1 and j == 0):
                        if went[next_h][next_w] > n and S[next_h][next_w] == '.':
                            waiting.appendleft([n, next_h, next_w])
                    else:
                        if went[next_h][next_w] > n + 1 and S[next_h][next_w] == '.':
                            waiting.append([n + 1, next_h, next_w])

print(ans)

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    rep(i, n) l[i]--;
    int ans = 0;
    rep(i, n) if (l[l[i]] == i) ans++;
    cout << ans / 2 << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  double x1, x2, x3, y1, y2, y3;
  cin >> x1>> y1>> x2>> y2>> x3>> y3;
  double a = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
  double b = sqrt((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3));
  double c = sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1));
  double S = abs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2.0;
  double r = 2.0*S / (a+b+c);
  cout << fixed << setprecision(12) << max({a, b, c}) / (2.0 + max({a,b,c}) / r) << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int isprime(int);

int main(){

  int i,x,n,count = 0;
  int *m;

  scanf("%d",&n);
  m = malloc(sizeof(int) * n);
  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&m[i]);
      if( isprime(m[i]) == 1)
        {
          count++;
        }
    }
  printf("%d\n",count);
  free(m);
  return 0;
}

int isprime(x){

int i = 3;

if( x == 2) return 1;
if( x  < 2 || x % 2 == 0) return 0;
while ( i <= sqrt(x) )
    {
      if(x % i == 0) return 0;
      i = i +2;
    }

return 1;
}

Measured memory_bytes: 628
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	cout << n * (n - 1) / 2;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

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

using namespace std;
 
int main()
{
    char s[255], t[255];
    cin.getline(s, sizeof(s));
    cin.getline(t, sizeof(t));
    int n = strlen(s), m = strlen(t);
    if( n >= m ){
        cout << "No";
    } 
    for( int i = 0; i < n; i++ ){
        if( s[i] != t[i] ){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int x, y, z;
    cin >> x >> y >> z;

    x -= 2 * z;
    int ans = x / (y + z);
    if (x - ans * (y + z) >= y) ans++;

    print(ans);
    
}


Measured memory_bytes: 3584
// Vol02_0296
// A_Fat_Wallet

#include <cstdio>

int coins[] = {1, 5, 10, 50, 100, 500, 1000};
int sum;

int main()
{
  for (int i = 0; coins[i] <= 500; ++i) {
    int c;
    scanf("%d", &c);
    sum += (c * coins[i]);
  }
  printf("%d\n", (sum >= 1000));
  return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        int res = x;
        for(int i=0; i<d; i++) {
            for(int j=0; j<n; j++) {
                if(a[j] == 1) {
                    res ++;
                } else {
                    if(i % a[j] == 0) res++;
                }
            }
        }

        System.out.println(res);
    }

}


Measured memory_bytes: 21972