akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.Math;


class Main {
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        if(n==2){
            System.out.println(2);
        }
        else{
            if(n%2==0){
                n+=1;
            }
            int f=0;
            while(f==0){
                int k= (int) Math.ceil(Math.sqrt(n));
                int l=0;
                for(int i=2;i<k;i++){
                    if(n%i==0){
                        break;
                    }
                    else{
                        l+=1;
                    }
                

                }
                if(l==k-2){
                    f=1;
                    System.out.println(n);
                }
                else{
                    n+=2;
                }



            }


        }
        }
    

    }


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;



int main() {

	int A, P;
	cin >> A >> P;

	int sum;
	sum = 3 * A + P;

	int ans;
	ans = abs(sum / 2);

	cout << ans;


}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll l = a[n - 1];
  ll index = lower_bound(b.begin(), b.end(), l) - b.begin();
  ll ans = 0;
  ll damage = 0;
  ll tmp = n - 1;
  while(h > damage) {
    if (index <= tmp) {
      damage += b[tmp];
      tmp--;
      ans++;
    } else {
      ll temp = (h - damage + l - 1) / l;
      ans += temp;
      damage += (temp * l);
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

std::vector<int> pos[26];

int main() {
  std::string s, t; std::cin >> s >> t;
  for(int i = 0; i < s.size(); ++i) pos[s[i]-'a'].push_back(i);

  int n = 0, p = 0;
  int ix[26];
  std::fill_n(ix, 26, 0);
  for(int i = 0; i < t.size(); ++i) {
    int c = t[i] - 'a';
    std::vector<int>& target = pos[c];
    if(target.size() < 1) fin(-1);
    while(ix[c] < target.size() && target[ix[c]] < p) ++ix[c];
    if(ix[c] < target.size()) p = target[ix[c]]+1;
    else {
      ++n;
      std::fill_n(ix, 26, 0);
      p = target[0]+1;
    }
  }
  int64_t ans = (int64_t)n*s.size() + p;
  fin(ans);
  return 0;
}


Measured memory_bytes: 1344
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " <<a << endl;
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("D:\\input.txt", "r", stdin);
	freopen("D:\\output.txt", "w", stdout);
#endif
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll a, b, c, d;
		cin >> a >> b >> c >> d;

		ll ans1 = a * c;
		ll ans2 = a * d;
		ll ans3 = b * c;
		ll ans4 = b * d;

		cout << max(ans1, max(ans2, max(ans3, ans4)));
	}
	return 0;
}

Measured memory_bytes: 3644
#include <atcoder/twosat>
#include <cstdio>
#define rep(i, j, n) for (int i = j; i < n; ++i)

int n, d, x[1000], y[1000];

int main() {
  scanf("%d%d", &n, &d);
  rep(i, 0, n) scanf("%d%d", &x[i], &y[i]);
  
  atcoder::two_sat ts(n);
  rep(i, 0, n) rep(j, i + 1, n) {
    if (abs(x[i] - x[j]) < d) ts.add_clause(i, true, j, true);
    if (abs(x[i] - y[j]) < d) ts.add_clause(i, true, j, false);
    if (abs(y[i] - x[j]) < d) ts.add_clause(i, false, j, true);
    if (abs(y[i] - y[j]) < d) ts.add_clause(i, false, j, false);
  }
  if (ts.satisfiable()) {
    printf("Yes\n");
    auto b = ts.answer();
    rep(i, 0, n) printf("%d\n", b[i] ? y[i] : x[i]);
  } else
    printf("No");
  return 0;
}

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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

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

    int n = s.length();

    int a=0, b=0;

    for(int i=0; i<n; i++){
        if(i%2==0){
            if(s[i]=='0'){
                a++;
            }
            else{
                b++;
            }
        }
        else{
            if(s[i]=='1'){
                a++;
            }
            else{
                b++;
            }
        }
    }

    cout<<min(a,b)<<endl;
    
    return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin>>s;
	int ans=0;
	int res=0;
	for(int i=0;i<3;i++){
		 if(s[i]=='R'){
		 	ans++;
			res=max(res,ans);	
		 }
		else ans=0;
	}
	cout<<res<<endl;
	return 0;
 } 

Measured memory_bytes: 3624
n=int(input())

def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

a=fctr1(n)

ans=0

for i in range(len(a)):
    tmp=3
    p=2
    while a[i][1]>=tmp:
        p+=1
        tmp+=p
    ans+=(p-1)
print(ans)

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N;
  string S;
  cin >> N >> S;
  int ssize = S.size();
  string S2;
  for(int i = 0; i < ssize; i++){
    if(i == 0) S2 += S.at(i);
    else if(S.at(i) != S.at(i-1)) S2 += S.at(i);
  }
  cout << S2.size() << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
			Scanner scn = new Scanner(System.in);
			int n = scn.nextInt();
			long ans = 0;
			for(int i = 0;i < n;i++) {
				ans += scn.nextInt()-1;
			}
			System.out.println(ans);
			scn.close();
	}
}


Measured memory_bytes: 26096
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b,k = LI()
    c = 0
    for i in range(min(a,b),0,-1):
        if a % i == 0 and b % i == 0:
            c += 1
            if c == k:
                return i

    return -1



print(main())




Measured memory_bytes: 5460
from collections import Counter
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    arr = Counter(A)
    ans = sum(A)
    for i in range(Q):
        b,c = map(int, input().split())
        if arr.get(b,0) != 0:
            ans -= b*arr[b]
            ans += c*arr[b]
            arr[c] += arr[b]
            arr[b] = 0
        print(ans)

main()


Measured memory_bytes: 21452
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#include<complex>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
typedef complex<double> P;
P pin(){
	double x,y;
	cin>>x>>y;
	P p(x,y);
	return p;
}
void PIN(P* a,int i){
	rep(i,2)a[i]=pin();
}
double dot(P a,P b){
	return real(conj(a)*b);
}
double cross(P a,P b){
	return imag(conj(a)*b);
}
int main(){
	P a[2];
	PIN(a,2);
	int n;
	cin>>n;
	rep(i,n){
		P p2=pin();
		P p=a[1]-a[0];
		P ans=a[0]+dot(p2-a[0],p)*p/norm(p);
		printf("%.9f %.9f\n",real(ans),imag(ans));
	}
		


}

Measured memory_bytes: 1268
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}


int main(){
	int a,b;
cin>>a>>b;
cout<<a*b<<" "<<2*(a+b)<<endl;
	return 0;
}

Measured memory_bytes: 1164
# ABC 113, B - palace
n = int(input())
t, a = map(int, input().split(' '))
H = [int(el) for el in input().split(' ')]

B = []
for i in range(n):
    B.append(abs((t - H[i]*0.006) - a))
print(B.index(min(B))+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 200004;
const int MOD =998244353
 ;
const int INV2 = (MOD+1)/2;
int k,x,y;


     signed main(){
int n,s;
cin>>n>>s;
if(n-s<0){
     cout<<-1<<endl;
     return 0;
}
if(n==s){
     cout<<n+1<<endl;
     return 0;
}
vector<int> v;

for(int i=1;i*i<=n-s;i++)if((n-s)%i==0){
     v.push_back(i +1);
     if((n-s)/i!=i)v.push_back((n-s)/i +1);

}
sort(v.begin(),v.end());
for(auto&& i :v){
int m=0,l=n;
while(l){
     m+=(l%i);
     l/=i;
}
if(m==s){
     cout<<i<<endl;
     return 0;
}
}
cout<<-1<<endl;
return 0;





}


        


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(container) (continer).begin(), (container).end()
#define sz(container)  (int) (container).size();
#define rall(container) (container).rbegin(), (container).rend()
using ll = long long;

#ifdef LOCAL_DEFINE
    #include "../../library/DEBUG.hpp"
#else
    #define debug(...) 0
#endif

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int maxn = 2100;
vector<int> g[maxn];
vector<vector<int>> distances;
vector<bool> visited;

void bfs(int start) {
  queue<int> Q;
  Q.push(start);
  fill(visited.begin(), visited.end(), false);
  visited[start] = true;
  distances[start][start] = 0;
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (auto& v : g[cur]) {
      if (visited[v]) continue;
      visited[v] = true;
      distances[start][v] = 1 + distances[start][cur];
      Q.push(v);
    }
  }
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  distances.resize(n, vector<int>(n, 0));
  visited.resize(n, false);
  vector<pair<int, int>> edges;
  for (int i = 0; i < n - 1; i++) {
    int from, to;
    cin >> from >> to;
    --from, --to;
    g[from].push_back(to);
    g[to].push_back(from);
    edges.emplace_back(from, to);
  }
  for (int i = 0; i < n; i++) bfs(i);
  if (!(k & 1)) {
    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        if (j == i) continue;
        if (distances[i][j] > (k >> 1)) ++cnt;
      }
      uin(ans, cnt);
    }
    cout << ans << '\n';
  } else {
    int ans = INT_MAX;
    for (int i = 0; i < (int) edges.size(); i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        if (distances[edges[i].first][j] > ((k - 1) >> 1) && distances[edges[i].second][j] > ((k - 1) >> 1)) {
          ++cnt;
        }
      }
      uin(ans, cnt);
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 19448
n= int(input())
a= list(map(int, input().split()))
ans=[0]*n

for i in range(31):
    x=0
    for j in range(n):
        if (a[j]>>i)&1:
            x+=1
    if x%2==0:
        for j in range(n):
            if (a[j]>>i)&1:
                ans[j]+=pow(2,i)
    else:
        for j in range(n):
            if not (a[j]>>i)&1:
                ans[j]+=pow(2,i)

print(*ans)


Measured memory_bytes: 96332
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    vector<int> a(3);
    REP(i, 3) cin >> a[i];
    
    sort(ALL(a));

    cout << (a[1] - a[0]) + (a[2] - a[1]) << endl;

    return 0;
    

}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

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

    LL cnt_0 = 0;
    LL cnt_k_2 = 0;
    REP2(i,1,N+1){
        if(i%K==0) cnt_0++;
        if(i%K==K/2) cnt_k_2++;
    }

    if(K%2==1){
        cout<<cnt_0*cnt_0*cnt_0<<endl;
    }else{
        cout<<cnt_0*cnt_0*cnt_0+cnt_k_2*cnt_k_2*cnt_k_2<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
// Problem : Rabbo Loves Jumping
// Contest : CodeChef - ketek[i] QuickMatch 25
// URL : https://www.codechef.com/KQKM2020/problems/HRJMP
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf 1e9
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
//#define int long long
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
int n,k;
cin>>n>>k;
int h[n];
For(i,0,n)
cin>>h[i];
vector<int> dp(n,inf);
//dp[i] is the minimum cost to reach ith stone
dp[0]=0;
for(int i=0;i<n;i++){
for(int j=1;j<=k;j++){
	if(i+j<n)
	dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
}
}
//push up
cout<<dp[n-1];
}










Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		if (n % 1000 == 0) {
			System.out.println("0");
		} else {
			System.out.println(1000 - n % 1000);
		}
	}
}

Measured memory_bytes: 35620
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

/**
 * 拡張 Euclid の互除法
 * ref. https://qiita.com/drken/items/b97ff231e43bce50199a
 * @return ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
 */
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) {
        p = 1;
        q = 0;
        return a;
    }
    long long d = extGcd(b, a % b, q, p);
    q -= a / b * p;
    return d;
}

/**
 * Chinese remainder theorem (中国剰余定理)
 * ref. https://qiita.com/drken/items/ae02240cd1f8edfc86fd
 * @return リターン値を (r, m) とすると解は x ≡ r (mod. m), 解なしの場合は (0, -1) をリターン
 */
pair<long long, long long> chineseRemainderTheorem(long long b1, long long m1, long long b2, long long m2) {
    long long p, q;
    long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
    if ((b2 - b1) % d != 0) return make_pair(0, -1);
    long long m = m1 * (m2 / d); // lcm of (m1, m2)
    long long tmp = (b2 - b1) / d * p % (m2 / d);
    long long r = mod(b1 + m1 * tmp, m);
    return make_pair(r, m);
}

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void solve() {
    ll N;
    cin >> N;
    N *= 2;
    auto D = divisor(N);
    ll ans = INF;
    for (ll d: D) {
        ll n = d;
        ll n1 = N/d;
        auto res = chineseRemainderTheorem(0, d, -1, n1);
        if (res.first != 0) {
            ans = min(ans, res.first);
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3760
// Sliding Minimum Elements
#include <iostream>
#include <stdlib.h>
#include <math.h>
#define INF pow(2, 31) - 1
using namespace std;
int n, l, *D;

void initRMQ(int *data){
    int i, k, size = 1;
    while(size < l) size *= 2;
    D = (int *)malloc((2*size - 1)*sizeof(int));
    for(i = 0; i < 2*size - 1; ++i) D[i] = INF;
    n = size;
    k = n - 1;
    for(i = 0; i < l; ++i) D[k+i] = data[i];

    int start = n - 1;
    while(start > 0){
        for(i = int((start - 1)/2); i < start; ++i) D[i] = min(D[i*2 + 1], D[i*2 + 2]);
        start = int((start - 1)/2);
    }
}

void update(int k, int a){
    k += n - 1;
    D[k] = a;
    while(k > 0){
        k = int((k - 1)/2);
        D[k] = min(D[k*2 + 1], D[k*2 + 2]);
    }
}

int main(void){
    cin >> n >> l;
    int data[n];
    for(int i = 0; i < n; ++i) cin >> data[i];
    initRMQ(data);
    int index = 0;
    int length = int(sizeof(data)/sizeof(data[0]));
    while((length - index - l) >= 0){
        if((length - (index + 1) - l) >= 0){
            cout << D[0] << " ";
            update(index%l, data[index+l]);
        }else cout << D[0] << endl;
        ++index;
    }
    return 0;
}


Measured memory_bytes: 8060
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n,a[2][12],c,f,aa;
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++){
      scanf("%d",&a[0][i]); 
      a[1][i] = 0;
    }

    c = 0;
    f = 0;
    while(1){
      for(i=0;i<n;i++){
	aa = a[c%2][i];
	for(j=0;j<n;j++){
	  if(aa == a[c%2][j] && c%2 == 0) a[1][i]++;
	  else if(aa == a[c%2][j] && c%2 == 1) a[0][i]++;
	}
      }

      f = 1;
      for(i=0;i<n;i++){
	if(a[0][i] != a[1][i]){
	  f=0;
	  break;
	}
      }
      if(f == 1) break;
      for(i=0;i<n;i++) a[c%2][i] = 0;
      c++;
    }

    cout << c << endl;
    cout << a[0][0];
    for(i=1;i<n;i++) cout << " " << a[0][i];
    cout << endl;

  }
  return 0;
}

Measured memory_bytes: 0
v=[[3*M=998244353,s=1]]
`sort -nr`.lines{|e|x,d=e.split.map &:to_i
d&&(r=1
r*=v.pop[1]while v[-1][0]<x+d
v<<[x,r+1])}
v.map{|_,y|s=s*y%M}
p s

Measured memory_bytes: 25204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;
constexpr auto MAX = 10000;

class Disjointset{
  public:
    vector<int> rank, parent;

    Disjointset(){}
    Disjointset(int size){
      rank.resize(size, 0);
      parent.resize(size, 0);
      rep(i,size) makeSet(i);
    }

    void makeSet(int x){
      parent[x] = x;
      rank[x] = 0;
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }

    void link(int x, int y){
      if(rank[x] > rank[y]){
        parent[y] = x;
      }else{
        parent[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
      }
    }


    int findSet(int x){
      if(x != parent[x]){
        parent[x] = findSet(parent[x]);
      }
      return parent[x];
    }

};

class Edge{
  public:
  int source, target, cost;
  Edge(int source = 0, int target = 0, int cost = 0):
  source(source), target(target), cost(cost) {}
  bool operator < ( const Edge &e) const{
    return cost < e.cost;
  }
};

int kruscal(int N, vector<Edge> edges){
  int totalcost = 0;
  sort(edges.begin(), edges.end());
  Disjointset dset = Disjointset(N);

  int source, target;
  rep(i, edges.size()){
    Edge e  = edges[i];
    if( !dset.same(e.source, e.target)){
      //MST.push_back(e);
      totalcost += e.cost;
      dset.unite(e.source, e.target);
    }
  }
  return totalcost;
}

int main(){

  int N, M, cost;
  int source, target;

  cin >> N >> M;
  vector<Edge> edges;
  rep(i,M){
    cin >> source >> target >> cost;
    edges.push_back(Edge(source, target, cost));
  }

  cout << kruscal(N, edges) << endl;

  return 0;
}


Measured memory_bytes: 5384
#include<stdio.h>
int main(void){
	int d[3];
	int k;
	int i;
	int cnt=0;
	for(i=0;i<3;i++)
	 scanf("%d",&d[i]);
	scanf("%d",&k);

	while(d[0]>=d[1]){
		cnt+=1;
		d[1]*=2;
	}
	while(d[1]>=d[2]){
		cnt+=1;
		d[2]*=2;
	}
	if(cnt<=k) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll h, w, k, cnt[10];
string s[20];

bool hantei(){
	zep(i, 0, 10){
		if(cnt[i] > k){
			return false;
		}
	}
	return true;
}

void update(ll bit, ll j){
	ll at = 0;
	zep(i, 0, h){
		if(s[i][j] == '1'){
			cnt[at]++;
		}
		
		if(bit & (1LL << i)){
			at++;
		}
	}
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> h >> w >> k;
	zep(i, 0, h){
		cin >> s[i];
	}
	
	ll ans = INF;

	zep(bit, 0, (1LL << h-1)){
		memset(cnt, 0, sizeof(cnt));
		ll buf = __builtin_popcount(bit);
		
		zep(j, 0, w){
			if(!hantei()){
				buf = INF;
				break;
			}
			
			update(bit, j);
			
			if(!hantei()){
				buf++;
				
				memset(cnt, 0, sizeof(cnt));
				update(bit, j);
			}
		}
		ans = min(ans, buf);
	}
	print(ans)
	return 0;
}

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

const int dd[] = {1, 3, 4, 5};

int main()
{
  int N;
  cin >> N;
  while (N--) {
    vector<int> card(20);
    for (int i = 0; i < 20; ++i)
      cin >> card[i];

    int ans = 20;
    queue<vector<int> > que;
    set<vector<int> > visited;
    que.push(card);
    while (!que.empty()) {
      const vector<int> v = que.front();
      que.pop();

      ans = min(ans, (int)v.size());
      if (visited.find(v) != visited.end())
	continue;

      visited.insert(v);
      for (int i = 0; i < v.size(); ++i) {
	for (int d = 0; d < 4; ++d) {
	  if (0 <= i+dd[d] && i+dd[d] < v.size() && v[i] == v[i+dd[d]]) {
	    if (i % 4 == 0 && dd[d] == 3)
	      continue;
	    if (i % 4 == 3 && (dd[d] == 1 || dd[d] == 5))
	      continue;

	    vector<int> tmp;
	    for (int j = 0; j < v.size(); ++j) {
	      if (j == i || j == i+dd[d])
		continue;
	      tmp.push_back(v[j]);
	    }
	    que.push(tmp);
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import sys

def solve():
    i, o, t, j, l, s, z = map(int, input().split())
    length = o * 2
    #長方形>> i2個, l2個, j2個: length += 4; i, l, j1個ずつ: length += 6
    comb = min([i, j, l])
    length += 6 * comb
    i -= comb
    j -= comb
    l -= comb
    length += 4 * ((i // 2) + (j // 2) + (l // 2))
    lem = i % 2 + j % 2 + l % 2
    if lem == 2 and comb > 0: length += 2
    elif lem == 3 and comb > 0: length += 6
    print(length // 2)
   
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int GCD(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最大公約数を出力 */
  
 
  return b;
}



long long LCM(long long a,long long b)
{
      long long  r, x, tmp;
 
 
  x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最小公倍数を出力 */
  return x/b;
}


int main()
{
  long long N,M;
  string S,T;
  cin >> N >> M >> S >> T;
  long long L=LCM(N,M);

  bool ans=true;
  long long d_N,d_M;
  long long g=GCD(N,M);
  d_N=N/g;
  d_M=M/g;
  
  for(long long i=1;i<=g;i++)
  {
     
      if(S[d_N*(i-1)]!=T[d_M*(i-1)]){ans =false;break;}
      
  }
 
 
  if(ans==true) 
  {
      cout << L << endl;
  }else{
      cout << -1 << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
string s;
cin >> s ;
cout << s.at(0) << s.at(1) << s.at(2) << endl;
} 

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int b[10];
int bt, ct, tmp;
bool check(int i){
  if( i==10 )
    return true;

  if( bt<b[i] ){
    tmp=bt; bt=b[i];
    if( check(i+1) )
      return true;
    bt=tmp;
  }
  if( ct<b[i] ){
    tmp=ct; ct=b[i];
    if( check(i+1) )
      return true;
    ct=tmp;
  }
  return false;
}

int main(){
  int n;
  cin >> n;
  for( int lp=0;lp<n;lp++ ){
    for( int i=0;i<10;i++ )
      cin >> b[i];

    bt=-1, ct=-1;
    if( check(0) )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  
  int x=p[0];
  int cnt=1;
  
  for(int i=1;i<n;i++){
    if(p[i]<x){
      x=p[i];
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3984
import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range;

void main()
{
    auto n = readln.chomp.split(" ").map!(to!int)[0];
    string[] lines;
    0.iota(n).each!(_a => lines ~= readln.chomp);
    writeln(lines.sort!"a<b".join(""));
}

Measured memory_bytes: 380
fun main(args: Array<String>){
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val a = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }
    var e = b.sum()
    var i = 0
    for (i in 0..n-2){
        if (a[i]+1 == a[i+1]){
            e = e + c[a[i]-1]
        }
    }
    println(e)
}

Measured memory_bytes: 38004
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(long long int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  int ans=v[0];
  rep(i,n){
    ans=GCD(ans,v[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}


int main()
{
  int N = 5;
  vector<int> a(5);
  rep(i, N) cin >> a[i];
  int k;
  cin >> k;
  sort(a.begin(), a.end());
  bool ans = a[4] - a[0] <= k;
  puts(ans ? "Yay!" : ":(");
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> Ao, Bo;  // オリジナル
vector<ll> A[32];   // Ao を 2^i で mod をとったものの vector
vector<ll> B[32];   // Bo を 2^i で mod をとったものの vector
ll fact[32] = {};   // 2^i

// [lb, ub) の範囲で val 以上の要素が初めて出てくるインデックスを返す
// なければ -1 を返す
// -1 を返すとこ以外 std::lower_bound と同じ
ll bin_search2(ll k, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(B[k][mid] >= val) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    // この時点で lb + 1 = ub
    return (B[k][ub] >= val) ? ub : -1;
}

// [lb, ub) の範囲で val を超える要素が初めて出てくるインデックスを返す
// なければ -1 を返す
// -1 を返すとこ以外 std::upper_bound と同じ
ll bin_search3(ll k, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(B[k][mid] > val) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    // この時点で lb + 1 = ub
    return (B[k][ub] > val) ? ub : -1;
}

signed main()
{
    cin >> N;
    REP(i, N) {
        ll a;
        cin >> a;
        Ao.push_back(a);
    }
    REP(i, N) {
        ll b;
        cin >> b;
        Bo.push_back(b);
    }

    fact[0] = 1;
    for(ll i = 1; i < 32; ++i) { fact[i] = fact[i-1] * 2; }
    REP(i, 32) {
        for(auto& a : Ao) { A[i].push_back(a % fact[i]); }
        for(auto& b : Bo) { B[i].push_back(b % fact[i]); }
        SORT(A[i]); SORT(B[i]);
    }

    ll ans = 0;
    REP(k, 30) {    // k: ビット目
        DBG("k:%lld\n", k);
        ll b_num = 0;
        for(auto& a : A[k+1]) {
            // [T-a, 2T-a) と [3T-a, 4T-a) の範囲に b がいくつあるか
            ll T = fact[k];
            DBG("  T: %lld a: %lld\n", T, a);
            ll head = bin_search2(k+1, 0, N, T - a);
            ll tail = bin_search3(k+1, 0, N, 2 * T - a - 1);
            ll tmp = 0;
            if(head >= 0) {
                if(tail < 0) { tmp = N - head; }
                else { tmp = tail - head; }
            }
            b_num += tmp;
            DBG("  [T-a, 2T-a): [%lld, %lld) %lld\n", head, tail, tmp);
            head = bin_search2(k+1, 0, N, 3 * T - a);
            tail = bin_search3(k+1, 0, N, 4 * T - a - 1);
            tmp = 0;
            if(head >= 0) {
                if(tail < 0) { tmp = N - head; }
                else { tmp = tail - head; }
            }
            b_num += tmp;
            DBG("  [3T-a, 4T-a): [%lld, %lld) %lld\n", head, tail, tmp);
            DBG("  b_num: %lld\n", b_num);
        }
        if(b_num % 2 != 0) { ans |= (1 << k); }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 104944
h , w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    ans= min(h,w)
    for i in range(1,h):
        if w % 2 == 0:
            ans = min(ans,max(w*i,(h-i)*(w//2)) - min(w*i,(h-i)*(w//2)))
        elif w % 2 == 1:
            ans = min(ans,max(w*i,(h-i)*(w//2),(h-i)*(w//2+1)) - min(w*i,(h-i)*(w//2),(h-i)*(w//2+1)))
    for i in range(1,w):
        if h % 2 == 0:
            ans = min(ans,max(h*i,(w-i)*(h//2)) - min(h*i,(w-i)*(h//2)))
        elif h % 2 == 1:
            ans = min(ans,max(h*i,(w-i)*(h//2),(w-i)*(h//2+1)) - min(h*i,(w-i)*(h//2),(w-i)*(h//2+1)))
    print(ans)

Measured memory_bytes: 40432
#include<iostream>
#include<cstdio>
#define M 100
#define G -1
#define B -2
#define W 0
using namespace std;

int n,T = 0;
int A[M+1][M+1],t[M+1][2],color[M+1];

void white(){
    for(int i = 0; i <= n;i++) color[i] = W;
}

void DFS(int x){
    T++;
    color[x] = G;
    t[x][1] = T;
    for(int i = 1; i <= n; i++){
        if(A[x][i] == 0) continue;
        else if(color[i] == W){
            DFS(i);
        }
    }
    T ++;
    color[x] = B;
    t[x][2] = T; 
}

int main(){
    int u,k,v;
    scanf("%d",&n);
    for(int i = 0; i <= n; i++){
        for(int j =0 ; j <= n; j++) A[i][j] = 0;
    }
    for(int i = 1; i <= n; i++){
        scanf("%d %d",&u,&k);
        for(int j = 0; j < k; j++){
            scanf("%d",&v);
            A[u][v] = 1;
        }
    }
    
    white();
    for(int i = 1; i <= n; i ++){
        if(color[i] == W) DFS(i);
    }
    
    for(int i = 1; i <= n; i++) printf("%d %d %d\n",i,t[i][1],t[i][2]);
    
    return 0;
}




Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n =scn.nextInt();
	double[]p = new double[n+1];
	for(int i=1;i<=n;i++)
	{
		p[i]=scn.nextDouble();
	}
	double[][]dp = new double[n+1][n+1];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j!=0)
			dp[i][j]=((1-p[i])*(dp[i-1][j]))+(p[i]*dp[i-1][j-1]);
			else {
				dp[i][j]=((1-p[i])*(dp[i-1][j]));
			}
			
		}
	}
	double ans=0;
	for(int j=(n+1)/2;j<=n;j++)
	{
		ans+=dp[n][j];
	}
	System.out.println(ans);
}
}


Measured memory_bytes: 118784
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 1000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
bitset<maxx/2>vis;
vector<ll>prime;
void sieve(){
    ll x=maxx/2, y=sqrt(maxx)/2;
    for(ll i=1;i<=y;i++){
        if(vis[i]==0){
            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
                vis[j]=1;
        }
    }
    prime.push_back(2);
    for(ll i=3;i<maxx;i+=2)
        if(vis[i/2]==0)
        prime.push_back(i);
}
bool isprime(ll a)
{
    if(a==2){
        return true;
    }
    if(a%2==0){
        return false;
    }
    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++){
        if(a%prime[i]==0){
            return false;
        }
    }
    return true;
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a)<<endl;
    return;
}
int main()
{
	FastIO;
	///sieve();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3532
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;
int main(){
	int n;
	ll a,b;
	ll k;
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	ll inv[300010];
	ll jun[300010];
	ll gyaku[300010];
	inv[1] = 1;
	for(ll i=2;i<=n;i++){
		inv[i] = mod - (mod/i) * inv[mod%i] % mod;
	}
	for(ll i=1;i<=n;i++){
		if(i==1){
			jun[i] = 1;
			gyaku[i] = 1;
		}else{
			jun[i] = (jun[i-1] * i) % mod;
			gyaku[i] = (gyaku[i-1] * inv[i]) % mod;
		}
	}
	ll ans = 0;
	for(ll i=0;i<=n;i++){
		if(k-a*i>=0&&(k-a*i)%b==0){
			ll j = (k-a*i) / b;
			if(j>n) continue;
			ll l,r;
			if(i==0||i==n) l = 1;
			else l = ((jun[n] * gyaku[i]) % mod) * gyaku[n-i] % mod;
			if(j==0||j==n) r = 1;
			else r = ((jun[n] * gyaku[j]) % mod) * gyaku[n-j] % mod;
			ans += l * r % mod;
			ans %= mod;
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 7168
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <tuple>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    ll N,K;
    ll ans = 0;
    cin >> N >> K;

    set<ll> setT;
    map<ll, vector<ll>> t1;

    for1(i,N) {
        ll t,d;
        cin >> t >> d;
        setT.insert(t);
        t1[t].push_back(d);
    }
    vector<pair<ll,ll>> t2;
    vector<pair<ll,ll>> t3;
    for(ll t: setT) {
        sort(t1[t].begin(), t1[t].end(), greater<ll>());
    }
    for(ll t: setT) {
        bool first = true;
        for(ll tt: t1[t]) {
            if (first) {
                first = false;
                t2.push_back(make_pair(tt,t));
            } else {
                t3.push_back(make_pair(tt,t));
            }
        }
    }
    sort(t2.begin(), t2.end(), greater<pair<ll,ll>>());
    if (t2.size() > K) {
        ll cnt = t2.size() - K;
        for1(i,cnt) {
            auto b = t2.back();
            t2.pop_back();
            t3.push_back(b);
        }
    }
    sort(t3.begin(), t3.end(), less<pair<ll,ll>>());;
    ll cntT = t2.size();
    ll sc = cntT * cntT;
    if (t2.size() < K) {
        ll cnt = K - t2.size();
        for1(i,cnt) {
            auto b = t3.back();
            t3.pop_back();
            t2.push_back(b);
        }
        sort(t2.begin(), t2.end(), greater<pair<ll,ll>>());
    }
    for (auto t: t2) {
        sc += t.first;
    }
    ans = sc;

    map<ll,ll> counter;
    for (auto t: t2) {
        counter[t.second]++;
    }

    for1(i,min(N-K,K)) {
        auto b = t2.back();
        t2.pop_back();
        counter[b.second]--;
        if (counter[b.second] == 0) {
            sc -= cntT * cntT;
            --cntT;
            sc += cntT * cntT;
        }
        sc -= b.first;

        b = t3.back();
        t3.pop_back();
        counter[b.second]++;
        if (counter[b.second] == 1) {
            sc -= cntT * cntT;
            ++cntT;
            sc += cntT * cntT;
        }
        sc += b.first;
        ans = max(ans, sc);
    }

    cout << ans << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 24436
int1, n_int = map(int, input().split())
diff = 1
if n_int == 0:
    print(int1)
else:
    list_num = [int(i) for i in input().split()]
    while True:
        if int1 not in list_num:
            print(int1)
            break
        else:
            num_check_minus = int1 - diff
            # print(num_check_minus)
            num_check_plus = int1 + diff
            # print(num_check_plus)
            
            if num_check_minus not in list_num:
                print(num_check_minus)
                break
            elif num_check_plus not in list_num:
                print(num_check_plus)
                break
            else:
                diff += 1
            
            

Measured memory_bytes: 9200
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N,M;cin >> N >> M;
    if(M == 1){
        cout << 0 << endl;
        return 0;
    }
    cout << max(N-M,0) << endl;
}

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

using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    long long int n=s.length(),sum=0;
    for(int i=0;i<n;i++)
    {
         sum=sum+(s[i]-48);
        // cout<<sum<<endl;
         
         sum=sum%9;
    }
    if(sum==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
//#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> Q;

int board[505][505];

int main() {
    int n,m;
    cin>>n>>m;
    map<int,int>mp;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        mp[x]++;
        mp[y]++;
    }
    for(auto [x,y]:mp){
        if(y%2==1){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 7644
#include <stdio.h>
char s[200005];
int dp[200005][4];
int d;
int x;
int y;
int ans;
int main() {
	for (int i = 0; i < 200005; i++) {
		s[i] = '1';
	}
	scanf("%s", s);
	for (int i = 0; i < 200005; i++) {
		if (s[i] != '1')d = i;
	}
	dp[0][0] = 1;
	for (int i = 1; i < d; i++) {
		for (int j = 0; j < 4; j++) {
			if (i >= j) {
				if (i == j)dp[i][j] = 1;
				else {
					x = 0;
					for (int k = 0; k < 4; k++) {
						if (k + j < i) {
							if (k == j) {
								y = 0;
								for (int l = 0; l <= k; l++) {
									if (s[i - l] != s[i - l - j - 1])y = 1;
								}
								if (y && dp[i - j - 1][k] > x)x = dp[i - j - 1][k];
							}
							else {
								if (dp[i - j - 1][k] > x)x = dp[i - j - 1][k];
							}
						}
					}
					dp[i][j] = x + 1;
				}
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		if (dp[d - 1][i] > ans)ans = dp[d - 1][i];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[1000];
	scanf("%s",s);
	int len=strlen(s);
	bool p=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]=='C') p=1;
		if(s[i]=='F'&&p)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 256