akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
 
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int k = Integer.parseInt(scanner.next());
        scanner.close();
        List<Integer> list1 = new ArrayList<Integer>();
        List<Integer> list2 = new ArrayList<Integer>();
        List<Integer> res = new ArrayList<Integer>();
        for(int i = 1; i <= a ; i++){
            if(a%i == 0) list1.add(i);
        }
        for(int i = 1; i <= b ; i++){
            if(b%i == 0) list2.add(i);
        }
        for(Integer u : list1){
            if(list2.contains(u)){
                res.add(u);
            }
        }
 
        System.out.println(res.get(res.size() - k));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int use[202020];
int X[202020],S[202020],T[202020];
int ans[202020];

int main(){
  int N,Q; cin>>N>>Q;
  vector<pair<int,int>> V;
  rep(i,N){
    cin>>S[i]>>T[i]>>X[i];
    V.push_back({S[i]-X[i],i});
    V.push_back({T[i]-X[i],i});
  }
  rep(i,Q){
    int D; cin>>D;
    V.push_back({D,i+N});
  }
  sort(V.begin(),V.end());
  priority_queue<pair<int,int>> pq;
  for(auto p:V){
    int ind=p.second;
    if(ind<N){
      if(use[ind]==0){
        pq.push({-X[ind],ind});
      }
      use[ind]++;
    }else{
      if(pq.size()==0){
        ans[ind-N]=-1;
      }else{
        while(pq.size()){
          auto P=pq.top();
          if(use[P.second]>1){
            pq.pop();
            continue;
          }
          ans[ind-N]=-P.first;
          break;
        }
      }
    }
  }
  rep(i,Q){
    if(ans[i]==0) cout<<-1<<endl;
    else cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,t,a,b;
    cin>>n;
    t=sqrt(n);
    for(int i=t;i>0;i--)
    {
        if(n%i==0)
        {
            a=i;
            b=n/i;
            break;
        }
    }
    cout<<(a-1)+(b-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

ll ans = 0;
ll k;

// 隣接リスト
vvll g(100010, vll());
vi visited(100010, 0);

// グラフに対する深さ優先探索
ll dfs(ll node, ll parent){
    visited[node] = 1;
    ll height = 0;
    rep(i, SZ(g[node])){
        if(!visited[g[node][i]]){
            chmax(height, dfs(g[node][i], node));
        }
    }
    if(height == k-1){
        if(parent != 1){
            ans++;
        }
        return 0;
    }else{
        return height+1;
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n >> k;
    vll a(n+1, 0);
    rep(i, n){
        cin >> a[i+1];
    }
    if(a[1] != 1){
        ans++;
        a[1] = 1;
    }
    if(k == 1){
        repr(i, 2, n+1){
            ans += (a[i] != 1);
        }
    }else if(k >= n-1){
    }else{
        repr(i, 2, n+1){
            g[a[i]].push_back(i);
        }
        dfs(1, 1);
    }
    dump(a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11648
def make_division(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return len(divisors)            

n = int(input())
ans_cnt = 0
for num in range(n+1):
    cnt = 0
    if num%2==0:
        pass
    else:
        cnt = make_division(num)
        if cnt == 8:
            ans_cnt += 1
print(ans_cnt)
            

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };




signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> d;
  d[24] = 1;
  REP(i, n) {
    int x;
    cin >> x;
    if(d.count(x) > 0) {
      d[x]++;
    }
    else {
      d[x] = 1;
    }
  }
  if(d.count(0) > 0  || (d.count(12) ? d[12] :0) > 1) {
    cout << 0 << endl;
    return 0;
  }
  REP(i, 24) {
    // cout << (d.count(i) ? d[i] :0) << " ";
    if((d.count(i) ? d[i] :0) > 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  // cout << endl;
  ll ans = 0;
  REP(i, 1<<24) {
    bool valid = true;
    if(d.count(0) == 0 && i % 2 == 1) {
      continue;
    }
    REP_FROM(j, 1, 12) {
      int cnt = (d.count(j) ? d[j] :0);
      bool lft = i & (1 << j);
      bool rgt = i & (1 << (24-j));
      if(cnt == 0 ) {
        if(lft || rgt) {
          valid = false;
          break;
        }
      }
      if(cnt == 1) {
        if(lft ^ rgt) {
        }
        else {
          valid = false;
          break;
        }
      }
      if(cnt > 1) {
        if(lft && rgt) {
        }
        else {
          valid = false;
          break;
        }
      }
    }
    {
      bool cnt = d.count(12);
      if((i & (1 << 12)) > 0 != cnt) {
        valid = false;
      }
    }
    if(valid) {
      ll tmp = 100;
      ll lft = 0;
      REP(j, 24) {
        if(i & 1 << j) {
          tmp = min(tmp, j - lft);
          lft = j;
        }
      }
      tmp = min(tmp, 24 - lft);
      // cout << bitset<64>(i) << endl;
      // cout << tmp << endl;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	string s;
	cin >> s;
	
	if(s=="SUN") cout << 7 << endl;
	if(s=="MON") cout << 6 << endl;
	if(s=="TUE") cout << 5 << endl;
	if(s=="WED") cout << 4 << endl;
	if(s=="THU") cout << 3 << endl;
	if(s=="FRI") cout << 2 << endl;
	if(s=="SAT") cout << 1 << endl;
	
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    
    rep1(x,n){
        
        rep1(y,n){

            rep1(z,n){
                ll ans = x*x + y*y + z*z + x*y + y*z + z*x;
                if(ans > n){
                    break;
                }
                a[ans]++;
            }
        }
    }
    rep1(i,n){
        cout << a[i] << endl;
    }
   	
  	
    
    
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    if(a < 10 and b < 10) cout << a * b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n,m;cin>>n>>m;
	int co[40]={};
	for(int i=0;i<n;i++){
		int k;cin>>k;
		for(int j=0;j<k;j++){
			int a;cin>>a;
			co[a]++;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){
		if(co[i]==n){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;

ll count(ll k)
{
    ll p=0;
    while(k)
    {
        p+= (k/5);
        k/=5;
    }
    return p;
}


int main()
{
    SYNC
    //clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n; in(n);
    if(n)
        o("0");
    else
        o("1");
    









   // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


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

int main() {
	// your code goes here
	
	int n;
	
	cin >> n;
	
	vector<int> v;
	
	for(int i =0;i<n;i++)
	{
		int x ;
		
		cin >> x;
		
		v.push_back(x);
	}
	
	sort(v.begin(),v.end());
	
	cout << v[n/2] - v[n/2 -1] << endl;
	
	
	return 0;
}

Measured memory_bytes: 892
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  map<string, int> mp;
  for (int i = 0; i < N; i++)
  {
    std::cin >> S[i];
    mp[S[i]]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;

  return 0;
}


Measured memory_bytes: 6356
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
k=0
l=0
m=0
for x in p:
    if x<=a: k+=1
    elif x>=a+1 and x<=b: l+=1
    elif x>=b+1: m+=1
print(min(k, l, m))


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

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    
    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if (s < t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

int
main(int argc, char **argv)
{
    u_int64_t n,k,x,y;
    cin >> n >> k;

    y=1;
    while(1){
        x = n / k;
        if(x == 0)
            break;
        else
            n = x;

        y++;
    }

    cout << y << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int mx = 0, sum = 0;
	for(int i = 0; i < 3; i++){
		int val;
		cin >> val;
		sum += val;
		mx = max(mx, val);
	}
	cout << sum - mx << "\n";
	return 0;
}

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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

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

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

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

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

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

LL left_sum[2000][2000] = {0};
LL right_sum[2000][2000] = {0};
LL up[2000][2000] = {0};
LL down[2000][2000] = {0};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL h,w;
    cin>>h>>w;
    VS s(h);
    REP(i,h)cin>>s[i];

    REP(i,h){
        LL space = 0;
        REP(j,w){
            left_sum[i][j] = space;
            if(s[i][j] == '.'){
                space++;
            }else{
                space = 0;
            }
        }
    }

    REP(i,h){
        LL space = 0;
        REP(j,w){
            right_sum[i][w-1-j] = space;
            if(s[i][w-1-j] == '.'){
                space++;
            }else{
                space = 0;
            }
        }
    }

    REP(j,w){
        LL space = 0;
        REP(i,h){
            down[i][j] = space;
            if(s[i][j] == '.'){
                space++;
            }else{
                space = 0;
            }
        }
    }

    REP(j,w){
        LL space = 0;
        REP(i,h){
            up[h-1-i][j] = space;
            if(s[h-1-i][j] == '.'){
                space++;
            }else{
                space = 0;
            }
        }
    }

    LL ans = 0;
    REP(i,h)REP(j,w)if(s[i][j]=='.'){
        ans = max(ans, left_sum[i][j]+right_sum[i][j]+down[i][j]+up[i][j]+1);
    }
    PUTS(ans);
}

Measured memory_bytes: 129536
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 1000000000000000000LL
    #define MOD 1000000007
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

    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; }

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


    int main()
    {
        string s;
        cin>>s;
        bool app[26];
        REP(i,25)
        {
            app[i]=false;
        }
        for (int i = 0; s[i] != '\0'; ++i) {
            app[s[i] - 'a'] = true;
        }
        for (int i = 0; i < 26; ++i) {
            if (!app[i]) {
                printf("%c\n", (char)(i + 'a'));
                return 0;
            }
        }
        puts("None");
        return 0;
    }

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

int main() {
    string s, t;
    cin >> s >> t;
    bool flag = true;
    rep(i, s.length()) flag &= (s.at(i) == t.at(i));
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3536
//template---{{{
#include <bits/stdc++.h>

using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  string S;
  int num = 0;

  cin >> S;

  int i;
  REP(i, 4) {
    if (S[i] == '+') num++;
    else if (S[i] == '-') num--;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var xs = Enumerable.Range(0, n)
            .Select(_ => int.Parse(Console.ReadLine()))
            .ToArray();
        
        var complete = xs.Sum();
        var dp = new int[complete + 1];;
        for (int i = 0; i < n; ++i)
        {
            for (int j = complete; j > xs[i] - 1; --j)
            {
                dp[j] = Math.Max(dp[j], dp[j - xs[i]] + xs[i]);
            }
        }
        
        Console.WriteLine(dp.LastOrDefault(x => x % 10 != 0));
    }
}


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

ifstream fin("pentagon.in");
ofstream fout("pentagon.out");

#define NMAX 2005
#define INF -1000000


int main()
{

   string s;
   cin>>s;
   if(s[2] == s[3] && s[4] == s[5])
      cout<<"Yes";
   else cout<<"No";

   return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{

    int N, M;
    int maxNum=1;
    cin>>N>>M;

    int criteria = M/N;

    for(int i=1; i*i<M; ++i)
    {
        if(M%i==0)
        {
            int a =M/i;
            if(a<=criteria)
                maxNum = max(maxNum, a);
            if(M/a<=criteria)
                maxNum = max(maxNum, M/a);
        }

    }

    cout<<maxNum<<endl;


    return 0;
}

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

int main()
{
    int K,N;
    cin >> K >> N;
    int A[N] ={},AA[N] = {};
    
    int i = 0;
    while(cin >> A[i] && i<N-1){
        i++;
    }
    A[N] =  K;
    //AA[0] = A[1]-0;
    for(i=0; i<N; i++){
        AA[i]=A[i+1]-A[i];
    }
    AA[N-1] = AA[N-1] + A[0];
    int max= 0,dis = 0;
    
    for(i=0;i<N;i++){
        if(max<AA[i]){
            max = AA[i];
        }
        dis = dis + AA[i];
    }

    dis = dis - max;

    cout << dis << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60; //仮想的な無限大の値
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    //エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    // 2017-like 数かどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    //累積和
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    //クエリ処理
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  int N, H, W;
  int A[1010], B[1010];

  cin >> N >> H >> W;
  for (int i = 0; i< N; i++) {
    cin >> A[i] >> B[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (H <= A[i] && W <= B[i]) ans++;
  }
    
  cout << ans << endl;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  set<char> st;
  vector<int> at;
  for(int i = s.size() - 1; i >= 0; i--){
    st.insert(s[i]);
    if(st.size() == 26){
      at.pb(i);
      st.clear();
    }
  }
  reverse(at.begin(), at.end());
  at.pb(s.size());
  string res = "";
  int start = 0;
  rep(i, at.size()){
    st.clear();
    FOR(j, start, at[i]){
      st.insert(s[j]);
    }
    char t = 'a';
    rep(j, 26){
      if(st.find(char('a' + j)) == st.end()){
        t = char('a' + j);
        break;
      }
    }
    res += t;
    if(i != at.size() - 1){
      FOR(j, at[i], at[i + 1]){
        if(s[j] == t){
          start = j + 1;
          break;
        }
      }
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;
#define ll long long

int main()
{
	ll a, b, k;
	cin >> a >> b >> k;
	if (k >= a)
	{
		k -= a;
		a = 0;
	}
	else
	{
		a -= k;
		k = 0;
	}
	if (k >= b)
	{
		b = 0;
	}
	else
		b -= k;
	cout << a << " " << b;
	system("pause>0");
	return 0;
}


Measured memory_bytes: 504
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<string>s(n);vector<int>t(n);
    for(int i=0;i<n;i++)cin>>s[i]>>t[i];
    string x;cin>>x;
    int ans=0;bool abc=0;
    for(int i=0;i<n;i++){
        if(s[i]==x)
        {
            abc=1;
            continue;
        }
        if(abc==1){
            ans+=t[i];
        }
    }
    cout<<ans<<endl;
    
    
    //------------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define deb(x) cout << #x << " => " << x << endl

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

    ll n, w;
    cin >> n >> w;
    vector<ll> weights(n), vals(n);
    for (int i = 0; i < n; i++) {
        cin >> weights[i] >> vals[i];
    }
    int max_val = 0;
    for (auto x : vals) {
        max_val += x;
    }

    // dp[i] => minimum weight required to get i value
    vector<ll> dp(max_val + 1, 1e18 + 1);
    dp[0] = 0;
    for (int item = 0; item < n; item++) {
        for (int j = max_val; j >= vals[item]; j--) {
            dp[j] = min(dp[j], dp[j - vals[item]] + weights[item]);
        }
    }

    for (int i = max_val; i >= 0; i--) {
        if (dp[i] <= w) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main() {
    int n,k;
    cin>>n>>k;
    int d,a[n];
    REP(i,n){
        a[i]=0;
    }
    REP(i,k){
        cin>>d;
        REP(i,d){
            int cnt=0;
            cin>>cnt;
            a[cnt-1]=1;
        }
    }
    int ans=0;
    REP(i,n){
        if (a[i]==0)
        {
            /* code */
            ans++;
        }
        
    }
    cout<<ans<<endl;
}

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

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

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

	int A,B; cin >> A >> B;

	if(A%2 == 0 || B%2 == 0) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;

}


Measured memory_bytes: 512
// 155 B

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, tmp;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp;
        if(tmp % 2 == 1){
            continue;
        }else{
            if(tmp % 3 == 0 || tmp % 5 == 0){
                continue;
            }else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}


int32_t main()
{
  io
  int n;
  cin>>n;
  map<string,int>mm;string ss;
  for(int i=0;i<n;i++){cin>>ss;mm[ss]++;}
    cout<<mm.size()<<endl;

}

Measured memory_bytes: 19252
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

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

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};

Int getHead(Int n) {
    while(n / 10 > 0){
        n /= 10;
    }
    n %= 10;
    return n;
}

int main(void) {
    string s;
    cin >> s;
    ansYes(s.at(2) == s.at(3) && s.at(4) == s.at(5));
}




Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let xs = Array.(sort (-) a_s; fold_left (fun (xs, p) a -> if p = a then a :: xs, 0 else xs, a) ([], 0) a_s) |> fst
let _ = Printf.printf "%d\n" @@ match xs with a :: b :: _ -> a * b | _ -> 0

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	ll n,p;
	cin >> n >> p;
	ll ans = 1;
	for(ll i = 2; i * i <= p; i++){
		if(p == 1)break;
		ll count = 0;
		while(p % i == 0){
			count++;
			p /= i;
		}
		if(count >= n){
			for(ll j = 0; j < (count / n); j++)
				ans *= i;
		}
	}
	if(n == 1)ans *= p;
	ANS(ans);
	return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL A, B, C;
	LL a, b, c;
	cin >> A >> B >> C;

	a = A, b = B, c =C;

	LL ans = 0;
	while(true){
		if((a % 2) !=0 || (b % 2) !=0 || (c % 2) != 0){
			break;
		}
		if(a == b && b == c){
			printf("-1\n");
			return 0;
		}

		ans++;
		LL u = a, v = b, w = c;
		a = v/2 + w/2;
		b = w/2 + u/2;
		c = u/2 + v/2;

		if(a == A && b == B && c == C){
			printf("-1\n");
			return 0;
		}
		if(a == A && b == C && c == B){
			printf("-1\n");
			return 0;
		}
		if(a == B && b == A && c == C){
			printf("-1\n");
			return 0;
		}
		if(a == B && b == C && c == A){
			printf("-1\n");
			return 0;
		}
		if(a == C && b == B && c == A){
			printf("-1\n");
			return 0;
		}
		if(a == C && b == A && c == B){
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;

int main(){
    int x,y;
    cin  >> x >> y;
    for(int i=0; i<=x; i++){
        if(y==2*i+4*(x-i)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}

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

#define lli long long int
#define endl "\n"
#define forn(i, in, fin) for(int i = in; i<fin; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;


int main()
{
    fastIO();
    lli n; cin>>n;
    lli dp[n][n];
    vector<lli> nums(n);
  
    for(auto &x: nums)
        cin>>x;
  
    for(int L = n-1; L>=0; L--) 
    {
        for(int R = L; R<n; R++)
        {
            if(L==R) 
            {
                dp[L][R] = nums[L];
                continue;
            }
            dp[L][R] = max(nums[L] - dp[L+1][R],  nums[R] - dp[L][R-1]);
        }
    }

    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 70400
import bisect

ans = 0
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()

for b in B:
  a = bisect.bisect_left(A, b)
  c = N - bisect.bisect_right(C, b)
  ans += a * c
  
print(ans)

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

#include <iostream>
#include <fstream>

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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



class DColoringEdgesOnTree {
public:
    map<int, vector<p> > edges;
    int colors[100000] = {};
    int colorNum = 1;
	void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        REP(i, N-1) {
            int a, b;
            in >> a >> b;
            a--;b--;
            edges[a].pb(make_pair(b , i));
            edges[b].pb(make_pair(a , i));
        }
        search(0, 0);
        out << colorNum << endl;
        REP(i, N-1) {
            out << colors[i] << endl;
        }
	}

	void search(int t, int prec) {
	    int color = 1;
        for(auto x: edges[t]) {
            if (colors[x.second]) {
                continue;
            }
            if (color == prec) {
                color++;
            }
            colors[x.second] = color;
            search(x.first, color);
            chmax(colorNum, color);
            color++;
        }

	}
};


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


Measured memory_bytes: 12416
N, M = map(int, input().split())
M_list = [list(map(int, input().split())) for _ in range(M)]


ans = ['#' for _ in range(N)]
flg = False
# 値重複チェック
for m in M_list:
    if ans[m[0]-1]=='#' or ans[m[0]-1]==m[1]:
        ans[m[0]-1] = m[1]
    else:
        flg = True
        break


# 0パディングチェック
if not flg:
    if ans[0]==0 and len(ans)>1:
        flg = True
    if ans[0]=='#' and len(ans)>1:
        ans[0] = 1
    ans = [i if i !='#' else 0 for i in ans]

if not flg:
    ans = ''.join([str(i) for i in ans])
    print(ans)
else:
    print(-1)

Measured memory_bytes: 38384
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int main(){
	int i;
	int tmp;
	int n;
	int ca1, ca2;
	cin >> n;
	int dp[n];
	int h[n];
	rep(i, n){
		scanf("%d", &h[i]);
	}
	dp[0] = 0;
	repx(i, n, 1){
		if(n==2){
			cout << h[1]-h[0] << endl;
			exit(0);
		}
		else{
			if(i==1)dp[i] = abs(h[i]-h[i-1]);
			else{
				ca1 = abs(h[i]-h[i-1])+dp[i-1];
				ca2 = abs(h[i]-h[i-2])+dp[i-2];
				dp[i] = min(ca1, ca2);
			}
		}
	}
	cout << dp[n-1] << endl;
}


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

using namespace std;

#define mod 1e9+7

int main() {

	long long int a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;

	if(a<b)

    {

        if((v-w)*t>=b-a)

            cout<<"YES";

        else

            cout<<"NO";

    }

    else

    {

          if((v-w)*t>=a-b)

            cout<<"YES";

        else

            cout<<"NO";

    }

	return 0;

}

Measured memory_bytes: 3620
import sys
import math

OFFSET = 20

def main():

    while True:
        r,n = map(int, sys.stdin.readline().split())
        if r == 0 and n == 0:
            break

        seq = [0] * 40
        for i in range(n):
            x1,x2,h = map(int,sys.stdin.readline().split())
            for k in range(x1, x2):
                seq[k + OFFSET] = max(seq[k + OFFSET], h)

        # ??????????????§??????????????? => ??????????????????????????¶??????????????°??????????????¶????????????
        # seq[x] = [x,x+1]?????????h?????¨???
        ans = 9999999999
        for x in range(-r+1, r):
            y = min(seq[x + OFFSET - 1], seq[x + OFFSET])
            t = y + r - math.sqrt(r*r - x*x) # ???????????\????????????
            #print("r:{}\tx:{}\tx[]:{}\ty:{}\tt:{}".format(r,x,seq[x + OFFSET],y,t))
            ans = min(ans, t)

        print("{0:.4f}".format(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7740
#include <stdio.h>
#include <stdbool.h>

bool is_leap_year(int y);

int get_leap_years(int leap_years_list[1000], int year_begin, int year_end)
{
    int count = 0;
    for(int year = year_begin; year <= year_end; ++year) {
        if (is_leap_year(year) != false) {
            leap_years_list[count] = year;
            ++count;
        }
    }
    return count;
}
        

int main()
{
    int leap_years_list[1000]; //A.D. 0 - A.D. 3000 の間に閏年は高々1000個しかない

    bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので

    while (true) {
        int year_begin, year_end;

        //読み込み
        scanf("%d %d", &year_begin, &year_end);

        //終了判定
        if (year_begin == 0 && year_end == 0) {
            break;
        }

        //閏年を計算する
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);

        //セットとセットの間には空行を入れる
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n'); //putcharは一文字だけ出力する関数です
        }

        //閏年を出力
        if (leap_years_count == 0) {
            puts("NA"); //putsは与えられた文字列を出力した後改行する関数です
        } else {
            for (int i = 0; i < leap_years_count; i++) {
                printf("%d\n", leap_years_list[i]);
            }
        }
        
    }
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0;
    }
}

Measured memory_bytes: 1048
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b:
        heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Measured memory_bytes: 20872
S, T = [input() for i in range(2)]
ans = 0

for i in range(len(S)-len(T)+1):
    diff = 0

    for j in range(len(T)):
        if T[j] == S[i+j]:
            diff +=1
    ans = max(ans, diff)

print(len(T)-ans)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000000000000
#define test int t; cin>>t;
#define MOD 1000000007LL
#define all(x) (x).begin(),(x).end()

using namespace std;

ll nxt(){
    ll x;
    cin>>x;
    return x;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    ll n = nxt(), x = nxt(), T = nxt();
    cout<<(ll)ceil((double)n/x)*T<<endl;
    return 0;
}

Measured memory_bytes: 3728
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n, m;
	cin>>n>>m;

	bool pos[n] = {0};
	int num[n] = {0};
	forn(i,n) num[i] = 1;
	pos[0] = 1;

	forn(i,m){
		int a,b; 
		cin>>a>>b;
		a--; b--;
		if(pos[a]){
			if(num[a] == 1) pos[a] = 0;
			pos[b] = 1;
		}
		num[a]--;
		num[b]++;
	}

	int ans = 0;
	forn(i,n) if(pos[i]) ans++;
	cout<<ans<<ln;

	return 0;
}

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

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, K;
  cin >> n >> K;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = -1; i < n; i++) {
    for (int j = n; j > i; j--) {
      vector<int> b;
      int sum = 0;
      for (int k = 0; k <= i; k++) {
        b.push_back(a[k]);
        sum += a[k];
      }
      for (int k = j; k < n; k++)  {
        b.push_back(a[k]);
        sum += a[k];
      }
      sort(b.begin(), b.end());
      if (b.size() <= K) {
        ans = max(ans, sum);
        for (int k = 0; k < b.size() && k + b.size() < K; k++) {
          sum -= b[k];
          ans = max(ans, sum);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, nFlips = map(int, input().split())
s = input().rstrip()

segs = []
i = 0
while i < n:
    if s[i] == '0':
        j = i
        while j + 1 < n and s[j + 1] == '0':
            j += 1
        segs.append((i, j))
        i = j
    i += 1
segs = segs or [(0, n - 1)]

ret = 0
left = 0
for right in range(len(segs)):
    while right - left + 1 > nFlips:
        left += 1
    size = segs[right][1] - segs[left][0] + 1
    size += segs[left][0] - segs[left - 1][1] - 1 if left - 1 >= 0 else segs[left][0]
    size += segs[right + 1][0] - segs[right][1] - 1 if right + 1 < len(segs) else n - segs[right][1] - 1
    ret = max(ret, size)
print(ret)


Measured memory_bytes: 8316
#include<iostream>
using namespace std;
int p = 1000000007;
int log2_p_MAX = 32;
long long felmer(long long a)
{
  long long rem[log2_p_MAX];
  rem[0] = a%p;
  for(int i=1;i<log2_p_MAX;i++)
    rem[i] = (rem[i-1]*rem[i-1])%p;
  long long res = 1;
  long long expo = p-2;
  for(int i=0;i<log2_p_MAX;i++){
	if(expo%2==1){
      res *= rem[i];
      res = res%p;
    }
  	expo /= 2;
  }
  return res;
}
int main()
{
  long long n,m,k,mn,i,res;
  cin >> n >> m >> k;
  res=m*n*(m*(n-1)*(n+1)+n*(m-1)*(m+1));
  res%=p;
  res*=felmer(6);
  res%=p;
  mn=m*n-2;
  k-=2;
  for(i=1;i<=k;i++){
    res*=mn-i+1;
    res%=p;
    res*=felmer(i);
    res%=p;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256