akhauriyash/Code-Regression huggingface dataset:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def pprint(c):
    for ci in c:
        print(*ci)

def main():
    h, w = MII()
    n = II()
    aa = MII()
    aa = deque([i+1 for i, a in enumerate(aa) for _ in range(a)])
    for i in range(h):
        tmp = []
        for j in range(w):
            tmp.append(aa.popleft())
        if i%2==1:
            tmp = tmp[::-1]
        print(*tmp)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

vi A;
ll n;

ll Get_mx() {
	vi Ne = {3};
	rep(i,0,n-1) Ne.pb(((Ne[i]/A[i+1])+1)*A[i+1]-1);
	rep(i,0,n) if(Ne[i] < A[i]) return -1;
	return Ne[n-1];
}

ll Get_mn() {
	ll mn = 2;
	vi Ne = {2};
	rep(i,0,n-1) {
		ll num = Ne[i];
		if(A[i+1] >= num) mn = A[i+1];
		else {
			ll ok = (((Ne[i]/A[i+1]+1)*A[i+1]));
			if(ok-A[i+1] >= num) mn = ok-A[i+1];
			else mn = ok;
		}
		Ne.pb(mn);
	}
	return mn;
}

int main() {
    cin.sync_with_stdio(false);
	cin >> n;
	A = vi(n);
	rep(i,0,n) cin >> A[i];
	reverse(A.begin(),  A.end());
	if(A[0] > 2) cout << -1 << endl;
	else {
		ll mx = Get_mx();
		ll mn = Get_mn();
		if(mx == -1 || mn == -1 || mx < mn) cout << -1 << endl;
		else cout << mn << " " << mx << endl;

	}
    return 0;
}


Measured memory_bytes: 2916
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 100000000000000000
#define MOD 1000000007
#define files  freopen("oUTPUT.TXT","r",stdin);
#define PI 3.141592653589793238462
#define INF 1000000000
using namespace std;
int n,p,a;
long long j=0,o=1;

int main()
{
    cin>>n>>p; 
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(a&1)
        {
            o=j+o;
            j=o;
        }
        else
        {
            j=j<<1;
            o=o<<1;
        }
    }
    if(p)cout<<j;
	else cout<<o;
    return 0;
}

Measured memory_bytes: 256
typedef long long LL;
LL n,k;
LL f(LL n,LL x){if(!n)return(x<=0?0:1);
LL p=(1LL<<n)-1;
if(x<=2*p)return f(n-1,x-1);else return p+1+f(n-1,x-1-2*p);}
main(){scanf("%lld%lld",&n,&k);printf("%lld",f(n,k));}

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

 vector<bool> seen;
void dfs(const vector<vector<int>> &G, int v ,const vector<int> &t,vector<int> &ans,int q) {
    seen.at(v) = true;
  q += t.at(v);
    ans.at(v) = q;
    for (auto next_v : G.at(v)) { 
        if (seen[next_v]) continue;
        dfs(G, next_v,t,ans,q);
    }
}
int main() {
  int a,b;
  cin >> a >> b;
  vector<vector<int>> g(a);
  vector<int> p(a);
  vector<int> ans(a);
  for(int i = 0;i<a-1;i++){
    int x,y;
    cin >> x;
    cin >> y;
    g.at(x-1).push_back(y-1);
    g.at(y-1).push_back(x-1);
  }
  for(int i = 0;i<b;i++){
    int x,y;
    cin >> x >> y;
    p.at(x-1) +=y;
  }
  seen.assign(a, false);

    dfs(g,0,p,ans,0);
  for(int i = 0;i<a;i++){
    cout << ans.at(i);
    if(i==a)break;
    cout << ' ';
  }
  cout << endl;
}

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

void chmin(int &a, int b) { a = min(a, b); }

int n;
char c[4000]; int a[4000];
int posB[2001];			//posB[i] = 黒iがどこにあるか(0-indexed)
int posW[2001];
int cntB[2001][4001];	//cntB[i][j] = 先頭j個にi以下のBがいくつあるか
int cntW[2001][4001];
int dp[2001][2001];		//dp[Bを置いた数][Wを置いた数] = 反転数の最小値

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < 2 * n; i++) {
		cin >> c[i] >> a[i];
		if (c[i] == 'B') { posB[a[i]] = i; cntB[a[i]][i + 1] = 1; }
		if (c[i] == 'W') { posW[a[i]] = i; cntW[a[i]][i + 1] = 1; }
	}
	
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= 2 * n; j++) {
			cntB[i][j] += cntB[i][j - 1];
			cntW[i][j] += cntW[i][j - 1];
		}
	}
	
	for (j = 1; j <= 2 * n; j++) {
		for (i = 1; i <= n; i++) {
			cntB[i][j] += cntB[i - 1][j];
			cntW[i][j] += cntW[i - 1][j];
		}
	}
	
	for (i = 0; i <= n; i++) for (j = 0; j <= n; j++) dp[i][j] = 11451419;
	
	dp[0][0] = 0;
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n; j++) {
			//黒i + 1を選ぶ
			if (i < n) {
				chmin(dp[i + 1][j], dp[i][j] + posB[i + 1] - (cntB[i][posB[i + 1]] + cntW[j][posB[i + 1]]));
			}
			//白j + 1を選ぶ
			if (j < n) {
				chmin(dp[i][j + 1], dp[i][j] + posW[j + 1] - (cntB[i][posW[j + 1]] + cntW[j][posW[j + 1]]));
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 78464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define in insert

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

    ll x;
    cin >> x;
    ll amt = 100;
    ll counter = 0;
    for(;;) {
        amt *= 1.01;
        counter++;
        if(amt >= x) {
            cout << counter;
            break;
        }
    }
}


Measured memory_bytes: 3652
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] arg){
        Scanner scan =new Scanner(System.in);
        int p=scan.nextInt();
        int q=scan.nextInt();
        int r=scan.nextInt();

        int r1=p+q;
        int r2=p+r;
        int r3=q+r;

        if(r1<=r2 && r1<=r3) System.out.print(r1);
        else if(r2<=r1 && r2<=r3) System.out.print(r2);
        else System.out.print(r3);

    }
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int k;
	cin >> k;

	int seven = 7, i = 1;
	unordered_set<int> st;

	while (true) {

		if (st.find(seven) != st.end()) {
			cout << -1;
			break;
		}

		st.insert(seven);

		if (seven % k == 0) {
			cout << i;
			break;
		}

		seven = (seven*10 + 7) % k;
		i++;
	}

	return 0;
}

Measured memory_bytes: 42568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,T;
    cin >>N>>T;
    ll ans=0;
    vector<ll>t(N);
    rep(i,N){

        cin>>t[i];

    }

    rep(i,N-1){
        ans+=min(T,t[i+1]-t[i]);
    }
    ans+=T;
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4768
#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 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){
  int X,A;cin >> X >> A;
  if(X < A){
    cout << 0 << endl;
  }else{
    cout << 10 << endl;
  }
}


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

int main() {
  int s, s1, s2, s3;
  
  cin >> s;
  
  s1 = s / 100 ;
  s2 = (s - s1 * 100) /10;
  s3 = s - s1 * 100 - s2 * 10 ;
  
  cout << s1 + s2 + s3 << endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    p,q=divmod(j,9)
    if p>a:
        anslist.append(str(k))
    else:
        anslist[p]+=int(k)
answer=0
for some in anslist:
    some=str(some)
    some=some.zfill(61)
    for j in range(61):
        if int(some[j])!=0:
            use[j]+=int(some[j])

for j in range(61):
    answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))


Measured memory_bytes: 38968
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod) 繰り返し二乗法*/
ll modpow(ll a, ll n, ll mod){
    ll s[digits(n,2)],ans=1;
    rep(i,0,digits(n,2)){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;
    }
    return n?ans:1;
}
ll inv[200005],finv[200005];
void makeinv(ll n){
    inv[1]=1;finv[0]=finv[1]=1;
    rep(i,2,n+1){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        finv[i] = finv[i - 1] * inv[i] % MOD1;
    }
}
ll modfac(ll n, ll mod){
    ll x=1;
    rep(i,2,n+1){x*=i%mod;x%=mod;}
    return x;
}

int main(void){
    // char ;
    ll n,k;
    scanf("%lld%lld",&n,&k);
    // ll [n];
    makeinv(3000);

    rep(i,1,k+1){
        ll a=1;
        a*=modfac(k-1,MOD1);
        a*=modfac(n-k+1,MOD1); a = mod(a);
        a*=finv[i-1]; a = mod(a);
        // printf("%lld ",a);
        a*=finv[k-i]; a = mod(a);
        // printf("%lld ",a);
        a*=finv[n-k-i+1]; a = mod(a);
        // printf("%lld ",a);
        a*=finv[i];
        printf("%lld\n",mod(a));
    }

    
    // printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
program a175

implicit none
character(len=3) :: a

read *, a

if(a == 'SSS') then
 print *, 0
else if(a == 'RRS') then
 print *, 2
else if(a == 'SRR') then
 print *, 2
else if(a == 'RRR') then
 print *, 3
else
 print *, 1
end if

end program a175

Measured memory_bytes: 2856
#include <iostream>
#define llint long long 

using namespace std;

llint N;
llint A[100005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	
	llint ans = 0;
	llint val = 1;
	for(int i = 0; i < N; i++){
		if(A[i] < val) continue;
		if(A[i] == val) val++;
		else ans += (A[i] - 1) / val;
		if(val == 1) val = 2;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

//#pragma 03
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2")

#define ll long long
#define ld long double
#define fi first
#define se second
#define sz(x) x.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
//#define int long long

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

inline void EXECUTE_TIME() {cout << endl << setprecision(10) << fixed << "CPU Time: " << clock() / double(CLOCKS_PER_SEC) << " sec(s)\n";}

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}
template <class T> inline T gcd(T a, T b) {if (b) return gcd(b, a % b); else return a;}
template <class T> inline T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

const int N = 1e5 + 1;

vector<vii> adj;
bool check[N];
int dist[N];
bool FAIL;

void dfs(int u) {
    if (!check[u]) check[u] = true;
    for (ii v : adj[u]) {
        if (!check[v.fi]) {
            dist[v.fi] = dist[u] - v.se;
            dfs(v.fi);
        } else {
            if (dist[u] - v.second != dist[v.first]) FAIL = true;
        }
    }
}

signed main() {
//    freopen("connect.in", "r", stdin);
//    freopen("connect.out", "w", stdout);
    fastio();

    int n, m; cin >> n >> m;
    adj.assign(n, vii());

    int l, r, d;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d; l--, r--;
        adj[l].pb({r, d});
        adj[r].pb({l, -d});
    }

    for (int i = 0; i < n; i++) {
        if (!check[i]) {
            dist[i] = 0;
            dfs(i);
        }
    }

    if (!FAIL) cout << "Yes";
    else cout << "No";

//    EXECUTE_TIME();
}



Measured memory_bytes: 14860
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
    if a%2==0:
      a//=2
      cur+=1
    else:
      a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

Measured memory_bytes: 63984
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;
typedef pair <double, int> PDI;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 1000003, M = N << 1;

int n;
int x[1005], y[1005], r[1005];
double dis[N];
int tot, head[N], ver[M], nxt[M];
double edge[M];
bool vis[N];

inline void add(int u, int v, double w)
{
	ver[++tot] = v, edge[tot] = w, nxt[tot] = head[u], head[u] = tot;
}

inline double gdis(int x, int y, int xx, int yy)
{
	LL p = x - xx, q = y - yy;
	return sqrt(p * p + q * q);
}

inline void Dij(int s)
{
	priority_queue <PDI> q;
	q.push(make_pair(0.0, s));
	for (int i = 1; i <= n; i+=1) dis[i] = 100000000000000.0;
	dis[s] = 0.0;
	memset(vis, false, sizeof vis);
	while (!q.empty())
	{
		int u = q.top().second; q.pop();
		if (vis[u]) continue; vis[u] = true;
		for (int i = head[u]; i; i = nxt[i])
		{
			int v = ver[i]; double w = edge[i];
			if (dis[v] > dis[u] + w)
			{
				dis[v] = dis[u] + w;
				q.push(make_pair(-dis[v], v));
			}
		}
	}
}

int main()
{
	//File("in");
	int xs = gi <int> (), ys = gi <int> (), xt = gi <int> (), yt = gi <int> ();
	n = gi <int> ();
	x[n + 1] = xs, y[n + 1] = ys, x[n + 2] = xt, y[n + 2] = yt;
	for (int i = 1; i <= n; i+=1) x[i] = gi <int> (), y[i] = gi <int> (), r[i] = gi <int> ();
	n += 2;
	for (int i = 1; i <= n; i+=1)
		for (int j = i + 1; j <= n; j+=1)
			add(i, j, max(0.0, gdis(x[i], y[i], x[j], y[j]) - r[i] - r[j])), add(j, i, max(0.0, gdis(x[i], y[i], x[j], y[j]) - r[i] - r[j]));
	Dij(n - 1);
	printf("%.10lf\n", dis[n]);
	return 0;
}


Measured memory_bytes: 23888
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}



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


int main(){
	int n,a,sum=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		sum+=i;
		if(sum>=n) break;
	}
	a=sum-n;
	for(int i=1;i<=n;i++){
		sum-=i;
		if(a==i) continue;
		cout << i << endl;
		if(sum==0) break;
	}
	
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const ll oo = 1e15, N = 2e5 + 10;
int h[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n, ans = 0;
	map < int, int > f;
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> h[i];
		f[h[i] + i] ++;
	}
	for(int i = 1; i <= n; ++i){
		ans += f[i - h[i]];
	}
	cout << ans << '\n';
}


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

#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 INF 1e9
const ll mod = 1e9+7;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    k = min(k, n-k);
    ll ans = 1;
    REP(i, k){
      ans *= ((n-i)*inv[i+1])%mod;
      ans %= mod;
    }
    return ans;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  COMinit();
  int n, a, b;
  cin >> n >> a >> b;
  ll ans = modpow(2, n) - 1;
  cerr << ans << endl;
  ans %= mod;
  ans -= COM(n, a);
  cerr << "a:"<<COM(n, a) << endl;
  ans %= mod;
  if(ans < 0){
    ans += mod;
  }
  ans -= COM(n, b);
  cerr << "b:" << COM(n, b) << endl;
  ans %= mod;
  if(ans < 0){
    ans += mod;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	int mincount = 1000000;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			int counter = 0;
			for (int k = 0; k < h; k++) {
				for (int l = 0; l < w; l++) {
					counter += min(abs(i - k), abs(j - l))*a[k][l];
				}
			}

			mincount = min(counter, mincount);

		}
	}
	cout << mincount << endl;
}



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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    using namespace std;
bool visited[3009][3009]={false};
pair<ll,ll> dp[3009][3009];
pair<ll,ll> dfs(int i,int j, ll arr[])
{

    if(i==j)
    {
        visited[i][j]=true;
        // cout<<i<<" "<<j<<" "<<dp[i][j].first<<" "<<dp[i][j].second<<"\n";
        return dp[i][j];
    }
    visited[i][j]=true;


        if(!visited[i+1][j] && !visited[i][j-1])
        {
                if(arr[i]+dfs(i+1,j,arr).second>=arr[j]+dfs(i,j-1,arr).second)
                    dp[i][j]=mp((arr[i]+dp[i+1][j].second),dp[i+1][j].first);
                else
                    dp[i][j]=mp((arr[j]+dp[i][j-1].second),dp[i][j-1].first);
        }

        else if(visited[i+1][j] && !visited[i][j-1])
        {
            if((arr[i]+dp[i+1][j].second)>=arr[j]+dfs(i,j-1,arr).second)
                dp[i][j]=mp((arr[i]+dp[i+1][j].second),dp[i+1][j].first);
            else
                dp[i][j]=mp((arr[j]+dp[i][j-1].second),dp[i][j-1].first);
        }
         else if(!visited[i+1][j] && visited[i][j-1])
        {
            if(arr[i]+dfs(i+1,j,arr).second>=(arr[j]+dp[i][j-1].second))
                dp[i][j]=mp((arr[i]+dp[i+1][j].second),dp[i+1][j].first);
            else
                dp[i][j]=mp((arr[j]+dp[i][j-1].second),dp[i][j-1].first);
        }
        else
        {
            if((arr[i]+dp[i+1][j].second)>=(arr[j]+dp[i][j-1].second))
                dp[i][j]=mp((arr[i]+dp[i+1][j].second),dp[i+1][j].first);
            else
                dp[i][j]=mp((arr[j]+dp[i][j-1].second),dp[i][j-1].first);
        }


  //  cout<<i<<" "<<j<<" "<<dp[i][j].first<<" "<<dp[i][j].second<<"\n";
    return dp[i][j];
}
    int main()
    {

        ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

        ll n;
        cin>>n;
        ll arr[n];
        for(int i=0; i<n; i++)
            cin>>arr[i];

       for(int i=0; i<n; i++)
        dp[i][i]=mp(arr[i],0);

        pair<ll,ll> p =dfs(0,n-1,arr);
        cout<<p.first-p.second;

       return 0;
    }


Measured memory_bytes: 94512
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n;
vector< pair<int, int> > a;
int dp[2005][2005];

int rec(int l, int r) {
    if(l > r) return 0;
    int &ans = dp[l][r];
    if(ans != -1) return ans;
    ans = 0;
    int left = r - l + 1;
    int id = n - left;
    ans = max(rec(l + 1, r) + a[id].first * abs(a[id].second - l), rec(l, r - 1) + a[id].first * abs(a[id].second - r));
    return ans;
}  

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) {
        int tt;
        cin>>tt;
        a.pb({tt, i});
    }
    rs(a);
    f(i, n + 1) f(j, n + 1) dp[i][j] = -1;
    cout<<rec(0, n - 1);
    return 0;
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int N = 404;
int dp[N][N];
int sum[N][N];
int a[N], b[N];
int n, c;

int add(int x, int y) {
    int ret = x + y;
    if (ret >= MOD)ret -= MOD;
    return ret;
}

int sub(int x, int y) {
    int ret = x - y;
    if (ret < 0)ret += MOD;
    return ret;
}

int mul(int x, int y) {
    return 1LL * x * y % MOD;
}


int solve(int idx, int rem) {
    if (idx == n) return rem == 0;
    int &ret = dp[idx][rem];
    if (~ret)return ret;
    int cur = 1;
    ret = 0;
    range(i, 0, rem) {
        ret = add(ret, mul(sub(sum[b[idx]][i], sum[a[idx] - 1][i]), solve(idx + 1, rem - i)));
    }
    return ret;
}

void run_case() {
    memset(dp, -1, sizeof dp);
    cin >> n >> c;
    loop(i, n)cin >> a[i];
    loop(i, n)cin >> b[i];
    range(i, 1, N - 1) {
        sum[i][0] = 1;
        range(p, 1, N - 1) {
            sum[i][p] = mul(sum[i][p - 1], i);
        }
    }

    range(i, 1, N - 1) {
        loop(p, N) {
            sum[i][p] = add(sum[i][p], sum[i - 1][p]);
        }
    }


    cout << solve(0, c) << endl;
}

int main() {

#ifndef ONLINE_JUDGE
//    freopen("in.in", "r", stdin);
//    freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int T = 1;
//    cin >> T;
    while (T--)run_case();

    return 0;
}


Measured memory_bytes: 4956
///
// File:  a.cpp
// Author: ymiyamoto
//
// Created on Sun Jan  7 21:14:25 2018
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;

  cin >> str;
  for (uint32_t i = 0; i < str.size(); i++) {
    if (i == 3) {
      cout << '8';
    } else {
      cout << str[i];
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    A = input()
    if N == K:
        print('1')
    elif (N-1) % (K-1) == 0:
        print((N-1)//(K-1))
    else:
        print((N-1)//(K-1) + 1)
main()


Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;cin>>n;
cout<<n+n*n+n*n*n;
}

Measured memory_bytes: 3656
a,b,c,x,y=gets.split.map(&:to_i)
t1=a*x+b*y
t2=c*([x,y].min*2)+(case when x>y then (x-y)*a when x<y then (y-x)*b else 0 end)
t3=c*([x,y].max*2)
p [t1,t2,t3].min

Measured memory_bytes: 14368
class Rectangle(object):
    def __init__(self, length:int, breadth:int) -> None:
        if length < 1:
            raise ValueError('Paramter length is lower than 1.')
        if length > 100:
            raise ValueError('Paramter length is larger than 100.')
        if breadth < 1:
            raise ValueError('Paramter breadth is lower than 1.')
        if breadth > 100:
            raise ValueError('Paramter breadth is larger than 100.')

        self.length = length
        self.breadth = breadth

    def get_area(self) -> int:
        return self.length * self.breadth

    area = property(get_area)

    def get_perimeter(self) -> int:
        return 2 * (self.length + self.breadth)

    perimeter = property(get_perimeter)

if __name__ == "__main__":
    in_str = input()
    param = in_str.split()
    length = int(param[0])
    breadth = int(param[1])

    rect = Rectangle(length, breadth)
    print('{0} {1}'.format(rect.area, rect.perimeter))



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

int main() {
  int N, K;
  std::cin >> N >> K;
  std::string str;
  std::cin >> str;
  
  str[K-1] = 'a' + (str[K-1] - 'A');
  std::cout << str << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
s1 = input()
s2 = input()
n = len(s2);    m = len(s1)
dp = [[0 for i in range(m+1)] for i in range(n+1)]
for i in range(n):
    for j in range(m):
        if s2[i] == s1[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
# for i in range(n+1):
#     if i == 0:
#         print("   ", *s1)
#         print(" ", *dp[i])
#     else:
#         print(s2[i-1], *dp[i])
# print(dp[n][m])
i = n;  j = m
ind = ''
while i > 0 and j > 0:
    if dp[i][j] != dp[i-1][j] and dp[i][j] != dp[i][j-1]:
        ind = s1[j-1]+ind;  i -= 1; j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        j -= 1
print(ind)


Measured memory_bytes: 120540
//
// Created by Tetsuya Shiota on 2019-03-30.
//

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<cstdlib>
#include<string>
#include<sstream>

using namespace std;

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

    string s;
    cin >> s;

    vector<pair<char,char>> query(Q);
    for(auto &&q:query){
        cin >> q.first >> q.second;
    }

    reverse(query.begin(), query.end());

    int safeLeft = 0, safeRight = N-1;
    for(auto q : query){
        if(safeLeft > safeRight){
            break;
        }
        if(q.second == 'R') {
            if (q.first == s[safeRight]) {
                safeRight--;
            }
            if(safeLeft-1 >= 0 && q.first == s[safeLeft-1]){
                safeLeft--;
            }
        }
        if(q.second == 'L') {
            if (q.first == s[safeLeft]) {
                safeLeft++;
            }
            if(safeRight+1 < N && q.first == s[safeRight+1]){
                safeRight++;
            }
        }
    }
    cout << max(safeRight - safeLeft + 1,0) <<endl;
    return 0;

}

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

int main() {
    int n;cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    int l[n+1],r[n+1];
    l[0]=r[n]=0;
    for (int i=1;i<=n;i++)
        l[i]=__gcd(l[i-1],a[i-1]);
    for (int i=n-1;i>=0;i--)
        r[i]=__gcd(r[i+1],a[i]);
    int mx=0;
    for (int i=0;i<n;i++)
        mx=max(mx,__gcd(l[i],r[i+1]));
    cout<<mx<<endl;
}

Measured memory_bytes: 1408
# coding: utf-8

def is_yy(s):
    return s.isdigit()

def is_mm(s):
    if s[0] == '0':
        return s[1] in '123456789'
    else:
        return s[1] in '012'

def is_yymm(s):
    return is_yy(s[:2]) and is_mm(s[2:])

def is_mmyy(s):
    return is_mm(s[:2]) and is_yy(s[2:])

s = input()
  
if is_yymm(s):
    if is_mmyy(s):
        print('AMBIGUOUS')
    else:
        print('YYMM')
elif is_mmyy(s):
    print('MMYY')
else:
    print('NA')
    


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
//#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
 
int32_t main()
{
	fastio();
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a;
	
}


Measured memory_bytes: 3644
#include <stdlib.h>
#include <stdio.h>         
#include <errno.h>         
                            
#define SENTINEL 2000000000  
#define MAX_ARR_SIZE 100000

typedef struct card { char c; int n; } c_t;          
        
static void merge(c_t *a, int left, int mid, int right) {
  int n1, n2, i, j, k;          
  c_t *l;
  c_t *r;                       
                         
  n1 = mid - left;            
  l = (c_t *) malloc(sizeof(c_t) * (n1 + 1));
  if (l == NULL) return;
  for (i = 0; i < n1; ++i) l[i] = a[left + i];
  l[i].n = SENTINEL;

  n2 = right - mid;                                         
  r = (c_t *) malloc(sizeof(c_t) * (n2 + 1));
  if (r == NULL) return;
  for (i = 0; i < n2; ++i) r[i] = a[mid + i];
  r[i].n = SENTINEL;       
                       
  for (i = j = 0, k = left; k < right; ++k) {
    if (l[i].n <= r[j].n) {
      a[k] = l[i++];    
    } else {                         
      a[k] = r[j++];   
    }
  }                        
                                             
  free(l);                                 
  free(r);             
}                 
   
static int partition(c_t *a, int left, int right) {
  int i, j, x;         
  c_t tmp;             

  x = a[right - 1].n;                     
  for (i = left - 1, j = left; j < right - 1; ++j) {
    if (a[j].n > x) continue;
    tmp = a[++i];
    a[i] = a[j];
    a[j] = tmp;
  }                                                   
  tmp = a[++i];    
  a[i] = a[right - 1];
  a[right - 1] = tmp;
 
  return i;                                
}

static void merge_sort(c_t *a, int left, int right) {
  int mid;

  if (left >= right - 1) return;

  mid = (left + right) / 2;
  merge_sort(a, left, mid);
  merge_sort(a, mid, right);
  merge(a, left, mid, right);
}

static void quick_sort(c_t *a, int left, int right) {
  int x;

  if (left >= right - 1) return;

  x = partition(a, left, right);
  quick_sort(a, left, x);
  quick_sort(a, x + 1, right);
}

static void print_arr(c_t *a, int n) {
  int i;

  for (i = 0; i < n; ++i) printf("%c %d\n", a[i].c, a[i].n);
}

int main(int argc, char **argv) {
  int n, ret, i, is_stable;
  c_t a1[MAX_ARR_SIZE];
  c_t a2[MAX_ARR_SIZE];

  ret = scanf("%d", &n);
  if (errno != 0) perror("scanf: n");
  if (ret < 1) exit(1);

  for (i = 0; i < n; ++i) {
    ret = scanf("%s %d", &a1[i].c, &a1[i].n);
    if (errno != 0) perror("scanf: a1[i]");
    if (ret < 1) break;
    a2[i] = a1[i];
  }

  quick_sort(a1, 0, n);
  merge_sort(a2, 0, n);

  for (is_stable = 1, i = 0; i < n; ++i) {
    if (a1[i].c != a2[i].c || a1[i].n != a2[i].n) {
      is_stable = 0;
      break;
    }
  }
  printf("%s\n", is_stable ? "Stable" : "Not stable");
  print_arr(a1, n);

  exit(0);
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int cnobasho;
  bool flag1 = false;
  bool flag2 = false;
  if(S.at(0) == 'A'){//先頭がAか
    for(int i=2;i<N-1;i++){//2~N-2にCがあるか
      if(S.at(i) == 'C'){
        flag1 = true;
        cnobasho = i;
      }
    }
  }
  if(flag1 == true){//上の二つを満たしているか
    for(int i=0;i<N;i++){
      if(i!=0&&i!=cnobasho){
        if(isupper(S.at(i))){//AとC以外に大文字があるか
          flag2 = false;
          break;
        }
        if(i == N-1){//最後までいったらtrue
          flag2 = true;
        }
      }
    }
  }
  if(flag2 == true){
    cout<<"AC"<<endl;
  }else{
    cout<<"WA"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------
char ch;
int qry(ll n) {
	cout << "? " << n << endl;
	fflush(stdout);
	cin >> ch;
	return ch == 'Y';
}
ll kpow(ll a, ll b) {
	ll r = 1;
	while (b > 0) {
		if (b & 1) r = r * a;
		a = a * a, b >>= 1;
	}
	return r;
}
bool check() {
	rep(i, 0, 10) 
		if (!qry(kpow(10, i)))
			return false;
	return true;
}
int len() {
	rep(i, 1, 10)
		if (!qry(kpow(10, i)))
			return i;
	return 10;
}
int main() {
	if (check()) {
		rep(p, 0, 10)
			if (qry(kpow(10, p + 1) - 1)) {
				cout << "! " << kpow(10, p) << endl;
				break;
			}
	} else {
		int L = len();
		ll pre = 0;
		rep(i, 0, L - 1) {
			int l = 0, r = 9;
			while (l + 1 < r) {
				int m = (l + r) >> 1;
				!qry(pre * 10  + m) ? r = m - 1 : l = m; 
			}
			int x;
			if (l == r) {
				x = l;
			} else {
				x = qry(pre * 10 + r) ? r : l;
			}
			pre = pre * 10 + x;
		}
		int l = 0, r = 9;	
		while (l + 1 < r) {
			int m = (l + r) >> 1;
			!qry(pre * 100 + m * 10) ? l = m + 1 : r = m;
		}
		int x;
		if (l == r) {
			x = l;
		} else {
			x = qry(pre * 100 + l * 10) ? l : r;
		}
		pre = pre * 10 + x;
		cout << "! " << pre << endl;
	}
	return 0;
}

Measured memory_bytes: 720
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<int>orders(N);
		for (int i = 0; i < N; ++i) {
			cin >> orders[i];
		}
		vector<int>pips(M);
		
		for (int i = 0; i < M; ++i) {
			cin >> pips[i];
		}
		int now = 0;
		int ans = 0;
		for (int i = 0; i < M; ++i) {
			now += pips[i];
			if (now >= N-1) {
				ans = i + 1;
				break;
			}
				now += orders[now];
				if (now >= N-1) {
					ans = i + 1;
					break;
				}
			
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3044
import math
a=[]
first=[]
for i in range(5):
    temp=str(input())
    a.append(temp)
    first.append(int(temp[-1]))
nin=0
nva=9

for i in range(5):
    if first[i]!=0 and first[i]<nva:
        nin=i
        nva=first[i]

ans=0
for i in range(5):
    if i!=nin:
        temmp=int(a[i])
        temmp=math.ceil((temmp-0.5)/10)*10
        ans+=temmp
    else:
        ans+=int(a[i])
print(ans)

Measured memory_bytes: 8932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int dp[100005][13];
const int Mod = 1'000'000'007;

int main() {
    fastio;
    string s;
    cin >> s;
    dp[0][0] = 1;
    const int N = (int)s.size();
    rep(i,N) {
        if (isdigit(s[i])) {
            int n = s[i] - '0';
            rep(j, 13) {
                int r = (j*10 + n)%13;
                dp[i+1][r] += dp[i][j];
                dp[i+1][r] %= Mod;
            }
        } else {
            rep(j, 13) rep(k,10) {
                int r = (j*10 + k)%13;
                dp[i+1][r] += dp[i][j];
                dp[i+1][r] %= Mod;
            }
        }
    }
    cout << dp[N][5] << endl;
}


Measured memory_bytes: 8760
import difflib
import math

S = input()
T = input()

same = 0
for i in range(len(S) - len(T)+1):
    tmp_same = 0
    for j in range(len(T)):
        if S[i+j] == T[j] :
            tmp_same += 1
    if tmp_same > same:
        same = tmp_same


print(len(T) - same)


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

using namespace std;
using ll = long long;
const ll mod = 1000000007;
const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
const vector<vector<int>> dir8 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> s(h, vector<bool>(w));
    vector<vector<bool>> seen(h, vector<bool>(w));
    for(int i = 0; i < h; i++)for(int j = 0; j < w; j++){
        char t; cin >> t; s[i][j] = (t == '#');
    }


    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(!seen[i][j] && s[i][j]){
                int cntx = 1, cnto = 0;
                queue<pair<int,int>> que;
                que.push({i,j});
                seen[i][j] = 1;
                while(que.size()) {
                    int y = que.front().first, x = que.front().second;
                    que.pop();
                    for(auto k : dir4){
                        if(x + k[1] < 0 || x + k[1] >= w || y + k[0] >= h || y + k[0] < 0)continue;
                        if(s[y][x] == s[y + k[0]][x + k[1]] || seen[y + k[0]][x + k[1]])continue;
                        if(!s[y + k[0]][x + k[1]])cnto++;
                        else cntx++;
                        que.push({y + k[0], x + k[1]});
                        seen[y + k[0]][x + k[1]] = true;
                    }
                }
                ans += (ll)cntx * cnto;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384