akhauriyash/Code-Regression huggingface dataset:
s = list(input())
p = str(input())

x = len(p)

for i in range(len(s)):
    if i + x <= len(s):
        inner = s[i : i + x]
        
    else:
        inner = s[i : ] + s[0: (i + x) - len(s)]
 
    if inner == list(p):
        print("Yes")
        break
        
if inner != list(p):
    print("No")


Measured memory_bytes: 5556
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d; 
}

ll mod_inverse(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M, K; cin >> N >> M >> K;
  ll A = 0, B = 0;
  for(ll i = 1LL; i <= N - 1; i++) {
      A += i * (N - i);
      A %= mod;
  }
  A *= M;
  A %= mod;
  A *= M;
  A %= mod;
  for(ll i = 1LL; i <= M - 1; i++) {
      B += i * (M - i);
      B %= mod;
  }
  B *= N;
  B %= mod;
  B *= N;
  B %= mod;
  ll C = 1;
  for(ll i = 0 ; i < K - 2; i++) {
      C *= (N * M - 2 - i);
      C %= mod;
  }
  for(ll i = 1 ; i <= K - 2; i++) {
      C *= mod_inverse(i, mod);
      C %= mod;
  }
  ll ans = A + B;
  ans %= mod;
  ans *= C;
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
L.sort(key = itemgetter(1))
count = 0
for i in range(len(L)):
    if count + L[i][0] > L[i][1]:
        print('No')
        exit()
    else:
        count += L[i][0]
print('Yes')

Measured memory_bytes: 53732
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
a=0
for i in range(n):
  a+=l[i]
#  print('i:',i,'a:',a)
  if a>x:break
if x<a:print(i+1)
else:print(i+2)

Measured memory_bytes: 3060
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/



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

Graph G(N+1);
int a,b;
rep(i,M){
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);

}
rep(i,G[1].size()){
    rep(j,G[G[1][i]].size()){
        if(G[G[1][i]][j]==N){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
}
cout<<"IMPOSSIBLE"<<endl;
return 0;
}


Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll n;
	cin >> n;
	n--;
	int cnt = 1;

	while (true) {
		if (n < (ll)pow(26, cnt))break;
		n -= (ll)pow(26, cnt);
		cnt++;
	}
	//cout << cnt << endl;
	string s;
	for (int i = 1; i <=cnt; i++) {
		if (n / (ll)pow(26, cnt - i) == 0) {
			s += 'a';
			continue;
		}
		ll c = n / (ll)pow(26, cnt - i);
		n %= (ll)pow(26, cnt - i);
		s += 97 + c;
	}
	cout << s << endl;

}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main{
    static Scanner scan = new Scanner(System.in);
    public static void main(String[]args){
        int x = scan.nextInt();
        int y = scan.nextInt();
        int luas = x *y;
        int keliling = 2*(x+y);
        System.out.printf("%d %d\n",luas,keliling);
    }
}


Measured memory_bytes: 26296
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#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 t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  set<int> s;
  for(int i=-100;i<=200;i++) s.insert(i);
  int x,n;
  cin >> x >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++) 
  {
    cin >> v[i];
    s.erase(v[i]);
  }

  pair<int,int> ans = mp(INF,INF);
  for(auto it : s)
  {
    pair<int,int> p = mp(abs(it-x),it);
    ans = min(ans,p);
  }
  cout << ans.se << endl;
  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define input(array) \
	repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int h, w;
	int ans = 0;
	cin >> h >> w;
	vector<string> s(h);
	vector<vector<int>> has(h, vector<int>(w, INF));
	input(s);
	rep(i, h) {
		rep(j, w) { ans += (s[i][j] == '#'); }
	}
	int turn   = 0;
	bool clear = true;
	queue<Pi> q;
	//q.push(mp(INF, INF));
	q.push(mp(0, 0));
	has[0][0] = 1;
	Pi at;
	while (!q.empty()) {
		at = q.front();
		//clog << at.F << " " << at.S << endl;
		q.pop();
		
		if (at == mp(h-1, w-1)) {
			break;
		}
		for (int ni = max(0, at.F - 1); ni < min(at.F + 2, h); ni++) {
			for (int nj = max(at.S - 1, 0); nj < min(at.S + 2, w); nj++) {
				if (s[ni][nj] == '#') continue;
				if (has[ni][nj]!=INF) continue;
				if (not((ni == at.F) xor (nj == at.S))) continue;
				clear = true;
				q.push(mp(ni, nj));
				chmin(has[ni][nj], has[at.F][at.S] + 1);
			}
		}
	}
//	clog << turn << endl;
	clog << has[h - 1][w - 1] << endl;
	clog << ans << endl;
	clog << (h * w) << endl;
	if (has[h-1][w-1]==INF) {
		cout << -1 << endl;
	} else {
		cout << (h * w - has[h-1][w-1] - ans) << endl;
	}
	/*
	rep(i, h) {
	
		rep(j, w) { clog << has[i][j] << " "; }
		clog << endl;
	}
	*/
}
/*
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................
*/

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

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 input(){
  ll a;
  cin >> a;
  return a;
}

vi sub(vector<bool> fin,ll n) {
  vi ret;
  REP(i,n) {
    if(fin.at(i))continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vi result = sub(cp,n);
    ret.insert(ret.end(),result.begin(),result.end());
  }
  return ret;
}

int main() {
  ll n,m;
  cin >> n >> m;
  ll cnt=0;
  while(n) {
    cnt++;
    n/=m;
  }
  cout << cnt << endl;
}

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

const int MAX = 1000000000;
const int MIN = -1000000000;

int main()
{
	while (true) {
		int n;

		cin >> n;

		if (n == 0) {
			break;
		}

		vector<int> data(n);
		vector<bool> f(n, true);
		vector<int> check;
		int min_check = MAX;
		int max_check = MIN;

		for (int i = 0; i < n; i++) {
			string temp;

			cin >> temp;

			if (temp == "x") {
				f[i] = false;
			}
			else {
				data[i] = stoi(temp);

				bool maxflag = true;

				for (int j = 0; j < check.size(); j++) {
					if (check[j] == data[i] + 1) {
						maxflag = false;
						break;
					}
				}
				
				if (maxflag == true) {
					check.push_back(data[i] + 1);
				}

				bool minflag = true;

				for (int j = 0; j < check.size(); j++) {
					if (check[j] == data[i] - 1) {
						minflag = false;
						break;
					}
				}
				
				if (minflag == true) {
					check.push_back(data[i] - 1);
				}

				max_check = max(max_check, data[i] + 1);
				min_check = min(min_check, data[i] - 1);
			}
		}

		int count = 0;
		int ans;

		for (int i = 0; i < check.size(); i++) {
			for (int j = 0; j < n; j++) {
				if (f[j] == false) {
					data[j] = check[i];
				}
			}

			bool flag = true;

			for (int j = 1; j < n; j++) {
				if (j % 2 == 0) {
					if (data[j] >= data[j - 1]) {
						flag = false;
						break;
					}
				}
				else {
					if (data[j] <= data[j - 1]) {
						flag = false;
						break;
					}
				}
			}

			if (flag == true) {
				count++;
				ans = check[i];
			}
		}

		if (count == 0) {
			cout << "none" << endl;
		}
		else if (count == 1) {
			if (ans == min_check || ans == max_check) {
				cout << "ambiguous" << endl;
			}
			else {
				cout << ans << endl;
			}
		}
		else {
			cout << "ambiguous" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// fst == 1 -> odd plus, even minus
long long f(const vector<long long>& data, int n, int fst)
{
    vector<long long> a = data;
    long long s = 0, ret = 0, k;
    for(int i = 0; i < n; i++){
        k = (s + a[i]) * fst;
        if(k <= 0 &&   i & 1){
            ret  += (1 - k);
            a[i] += (1 - k) * fst;
        }
        if(k >= 0 && !(i & 1)){
            ret  += (k + 1);
            a[i] -= (k + 1) * fst;
        }
        s += a[i];
    }
    return ret;
}
int main()
{
    long long n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        scanf("%lld", &a[i]);
    }
    cout << min(f(a, n, 1), f(a, n, -1)) << endl;
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n,k;
  cin>>n>>k;
  ll mod=998244353;
  vector<Pll> s(0);
  rep(i,k){
    ll l,r;
    cin>>l>>r;
    s.pb(mp(l,r));
  }
  vl dp(n+1,0);
  dp[1]=1;
  dp[2]=-1;
  for(ll i=1;i<=n;i++){
    dp[i]+=dp[i-1];
    dp[i]%=mod;
    for(ll j=0;j<k;j++){
      if(i+s[j].F<=n){
        dp[i+s[j].F]+=dp[i];
      }
      if(i+s[j].S+1<=n){
        dp[i+s[j].S+1]-=dp[i];
      }
    }
  }
  dp[n]%=mod;
  dp[n]=(dp[n]+mod)%mod;
  print(dp[n]);
}


Measured memory_bytes: 4820
#include<iostream>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    map<int,ll> m;
    ll sum=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        sum+=a;
        m[a]++;
    }
    
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        sum-=m[b]*b;
        sum+=m[b]*c;
        cout<<sum<<endl;
        m[c]+=m[b];
        m[b]=0;
    }
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

vi es[1010];
int n, m;
const int inf = (1 << 30);

vi bfs(int sv) {
    vi dist(n, inf), pre(n, -1);
    queue<int> q;
    dist[sv] = 0;

    q.push(sv);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u: es[v]) {
            if (dist[u] != inf) continue;
            pre[u] = v;
            dist[u] = dist[v] + 1;
            q.push(u);
        }
    }

    pair<int, int> best(inf, -1);
    rep(v, n) {
        if (v == sv) continue;
        for (int u: es[v]) {
            if (u == sv) {
                best = min(best, make_pair(dist[v], v));
            }
        }
    }

    // cout << sv << " " << best.second << " " << best.first << endl;

    if (best.first == inf) return vector<int>(n + 1);

    int v = best.second;
    vector<int> res;
    while(v != -1) {
        res.push_back(v);
        v = pre[v];
    }

    return res;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    cin >> n >> m;

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es[a].push_back(b);
    }

    vi ans(n + 1);
    rep(s, n) {
        auto now = bfs(s);
        if (now.size() < ans.size()) ans = now;
    }

    if (ans.size() == n + 1) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << ans.size() << endl;
        for (auto v: ans) cout << v + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
import java.*;
import java.util.*;

public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	circleInRect cr = new circleInRect(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
	cr.judge();
	}
}
class circleInRect{
	int width;
	int height;
	int centx;
	int centy;
 	int rad;
	public circleInRect(int w, int h, int cx,int cy,int r){
		width=w;
		height=h;
		centx=cx;
		centy=cy;
		rad=r;
	}
	public void judge(){
		if(centx-rad<0 || centy-rad<0 || centx+rad>width || centy+rad > height)
			System.out.printf("No\n");
		else
			System.out.printf("Yes\n");
	}
}

Measured memory_bytes: 17360
#include <stdio.h>

#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int N,K;
    scanf("%d %d",&N,&K);
    int H[N];
    for (int i=0;i<N;i++) {
        scanf("%d",&H[i]);
    }
    qsort(H, N, sizeof(int), compare_int);
    /*一回小さい順にソート*/

    long int hp_total=0;
    for (int i=0;i<N-K;i++) {
        hp_total+=H[i];
    }
    printf("%ld",hp_total);
    return 0;
}


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

typedef long long int ll;



int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
    
    string s;
    cin >> s;

    for (ll i=0 ; i<s.size() ; i++) {
    	if (s[i]=='?') cout << 'D';
    	else cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;




int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin>> a[i];
    }
    vector<ll>s(n);
    map<ll,ll>u;
    rep(i,n){
        s[i]=i+1+a[i];
        ll U = i+1-a[i];
        u[U]++;
    }
    ll ans = 0;
    rep(i,n){
        ll now = s[i];
        ans+=u[now];
    }
    cout << ans << endl;
    
    return 0;
}


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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1){ }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

long long N, M;
long long res[100100];
int A[100100], B[100100];

int main() {
    cin >> N >> M;
    for (int i=0; i<M; ++i) {
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
    }

    UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    for (int i=0; i<M; ++i) {
        res[i] = cur;

        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;

        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }

    for (int i=M-1; i>=0; --i) cout << res[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>


using namespace std;


typedef unsigned int uint;


uint gcd_arr(uint A[], uint now, int i, int N)
{
    if (i == N - 1) {
        return __gcd(A[i], now);
    }
    return gcd_arr(A, __gcd(now, A[i]), i + 1, N);
}


uint A[100000];
int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> A[i];

    cout << gcd_arr(A, A[0], 1, N) << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100001;
int main()
{
  int n,i;
  long long t,res=0;
  long long a[N_MAX];
  cin >> n;
  for(i=0;i<=n;i++)
    cin >> a[i];
  for(i=0;i<n;i++){
    cin >> t;
    if(t<=a[i]){
      res+=t;
    } else {
      res+=min(a[i]+a[i+1],t);
      a[i+1]=max(a[i]+a[i+1]-t,(long long)0);
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#https://atcoder.jp/contests/abc110/tasks/abc110_b
# B - 1 Dimensional World's Tale
n, m, x, y = gets.split(" ").map{|d|d.to_i}
xlist = gets.split(" ").map{|d|d.to_i}.push(x)
ylist = gets.split(" ").map{|d|d.to_i}.push(y)

(x...y).map{|i|
   if xlist.select{|xi| xi < i }.size == xlist.size && ylist.select{|yi| yi >= i }.size == ylist.size
      puts "No War"
      exit
   end
}
puts "War"


Measured memory_bytes: 1916
N, K = map(int, input().split())
D = list(map(int, input().split()))
dislike = []
for i in range(0, 10):
	dislike.append(False)
for i in range(0, K):
	dislike[D[i]] = True
while True:
	S = str(N)
	flag = True
	for i in range(0, len(S)):
		if dislike[int(S[i])]:
			flag = False
			break
	if flag:
		print(N)
		break
	N += 1

Measured memory_bytes: 40924
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll comb(ll n,ll r){
  ll res=1;
  for(ll i=n-r+1;i<=n;i++)res*=i;
  for(ll i=1;i<=r;i++)res/=i;
  return res;
}
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl bibun;
  rep(i,n-1){
    if(a[i+1]-a[i]>0){
      bibun.push_back(1);
    }
    if(a[i+1]-a[i]<0){
      bibun.push_back(-1);
    }
  }
  ll count=0;
  rep(i,bibun.size()-1){
    if(bibun[i]!=bibun[i+1]){
      count++;
      i++;
    }
  }
  cout<<count+1<<endl;
}


Measured memory_bytes: 2168
from itertools import permutations
n = input()
l1 = [int(i) for i in raw_input().split(" ")]
l2 = [int(i) for i in raw_input().split(" ")]
per = list(permutations(range(1,n+1)))
a = 0
b = 0
cnt = 0;
for i in per:
	# print i
	i = list(i)
	if(i == l1): a = cnt
	if(i == l2): b=cnt
	cnt+=1;
print abs(a-b)

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

int main(){
    int N;
    cin >> N;
    vector<tuple<double, ll, ll>> en;
    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) continue;
        else en.emplace_back(atan2(y, x), x, y);
    }
    if (en.empty()) {
        cout << 0 << endl;
        return 0;
    }
    sort(en.begin(), en.end());
    N = (int)en.size();
    vector<ll> xsum(N+1, 0), ysum(N+1, 0);
    for (int i = 0; i < N; i++) {
        xsum[i+1] = xsum[i] + get<1>(en[i]);
        ysum[i+1] = ysum[i] + get<2>(en[i]);
    }
    double ans = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = i+1; j <= N; j++) {
            double s, t, u, v;
            s = (xsum[j]-xsum[i]);
            t = (ysum[j]-ysum[i]);
            u = xsum[N]-s;
            v = ysum[N]-t;
            double cand = max(sqrt(s*s+t*t), sqrt(u*u+v*v));
            ans = max(ans, cand);
        }
    }
    printf("%.20lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        long [] L = new long[n];
        Arrays.fill(L,0);
        for(int i=0;i<q;i++){
            int cmd = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(cmd==0)L[x-1]+=y;
            else{
                long sum = 0;
                for(int j=x-1;j<y;j++)sum+=L[j];
                System.out.println(sum);
            }
        }
    }
}


Measured memory_bytes: 102612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n,res = 0;
	string s,str;

	cin >> str >> n;

	rep(i,n){
		cin >> s;
		s += s;
		if(s.find(str) != string::npos) res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1212
#!/usr/bin/env python3
#ABC117 D
#桁DP

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,k = map(int,input().split())
a = list(map(int,input().split()))

size = 40
dp = [[-1]*2 for _ in range(size+1)]
dp[0][0] = 0

#dp[i][j(=0,1)] := 上から40-i-1桁決めて
#            j = 1 := k未満であることが確定
#            j = 0 := 今のところkと一致
#            のときのf(x)の最大値

for i in range(size):
    #上位桁から見る
    #biti:=(40-i-1)bitが1
    biti = 2**(size - i - 1)
    #nbit:=A1~Anのうち(40-i-1)bitが1である数の個数
    nbit = sum([1 for aa in a if aa & biti])
    #xの(40-i-1)bitを0にして得られるスコア
    score0 = biti * nbit
    #xの(40-i-1)bitを1にして得られるスコア
    score1 = biti * (n - nbit)
    #print(biti,nbit,score0,score1)

    #i:=equal -> i:=equal
    #kの(40-i-1)bitが1 <-> +=score1
    if k & biti:
        dp[i+1][0] = max(dp[i+1][0],dp[i][0] + score1)
    #kの(40-i-1)bitが0 <-> +=score0
    else:
        dp[i+1][0] = max(dp[i+1][0],dp[i][0] + score0)

    #i:=equal -> (i+1):=small(k未満であることが確定(j=1))
    #k未満であることが確定 <-> kの(i+1)bitが1かつbit(i+1)が0 <-> += score0
    if k & biti:
        dp[i+1][1] = max(dp[i+1][1],dp[i][0] + score0)

    #small -> small
    #まだ更新していない(まだ見ていなければ)
    #score0でもscore1でもよい
    if dp[i][1] != -1:
        dp[i+1][1] = max(dp[i+1][1],dp[i][1] + max(score0,score1))
print(max(dp[size]))


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

int main() {
    int N;
    cin >> N;
    vector<int> G[N], cost[N];
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(v); G[v].push_back(u);
        cost[u].push_back(w); cost[v].push_back(w);
    }

    vector<int> res(N, -1);
    res[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            int w = cost[v][i];

            if (res[u] != -1) continue;
            res[u] = (res[v] + w) % 2;
            q.push(u);
        }
    }
    for (int i = 0; i < N; i++)
        cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 11904
#include<cstdio>
#include<cmath>
using namespace std;

int n;
int main()
{
	scanf("%d",&n);
	int nowa=0,nowb=0,nowt=0;
	for(register int i=1;i<=n;i++)
	{
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		int tt=t-nowt;
		int aa=a-nowa;
		int bb=b-nowb;
		int dis=abs(aa)+abs(bb);
		if((dis&1)==(tt&1)&&(dis<=tt))
		{
			nowt=t,nowa=a,nowb=b;
		}else{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    if (b <= a)
        cout << "delicious";
    else if (b <= a + x)
        cout << "safe";
    else
        cout << "dangerous";
}


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

int main() {
    int n;
    cin >> n;
    long long sum = 0;
    vector<int> vec(n);
    
    for(int i; i < n; i++) {
        cin >> vec.at(i);
        sum += vec.at(i);
    }
    
    cout << *min_element(vec.begin(), vec.end()) << " " << *max_element(vec.begin(), vec.end()) << " " << sum << endl;
    
}


Measured memory_bytes: 3120
import scala.collection.immutable._
import scala.io.StdIn._
import scala.collection.mutable.Set
object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt
    var set = Set[String]()
    for(i <- 0 until n){
      var temp = readLine.split(" ")
      if(temp(0) == "insert") set.add(temp(1))
      else if(set.contains(temp(1))) println("yes");
      else  println("no");
      
    }
   
  }
}

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

int main(){

  string s;
  char c,p = ' ';
  int cnt = -1;

  cin >> s;

  for(int i=0;i<s.size();i++){
    if(i % 2 == 0) p = s[i];
    else if(i % 2 == 1){
      c = s[i];

      if(c == 'U' && p == '0') cout << "nn";
      else if(c == 'T' && p == '0') cout << "wa";
      else if(c == 'D' && p == '0') cout << "wo";

      else {
	switch(p){
	case '2': cout << 'k';
	  break;
	case '3': cout << 's';
	  break;
	case '4': cout << 't';
	  break;
	case '5': cout << 'n';
	  break;
	case '6': cout << 'h';
	  break;
	case '7': cout << 'm';
	  break;
	case '8': cout << 'y';
	  break; 
	case '9': cout << 'r';
	}

	switch(c){
	case 'T': cout << 'a';
	  break;
	case 'L': cout << 'i';
	  break;
	case 'U': cout << 'u';
	  break;
	case 'R': cout << 'e';
	  break;
	case 'D': cout << 'o';
	}
      }
    }

  }
  cout << endl;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main(){
    string str;
    cin >> str;
    stack<int> s;
    int g = 0;
    while(g < str.size()){
        if(str[g] == 'S'){
            s.push(g);
        }else{
            if(s.size() && str[s.top()] == 'S'){
                s.pop();
            }
            else{
                s.push(g);
            }
        }
        g++;
    }
    cout << s.size() << "\n";
}

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

using namespace std;

int main()
{
	int n, m;
	int D[1024], C[1024];
	int dp[1024];

	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++) scanf("%d", D + i);
	for (int i = 0; i < m; i++) scanf("%d", C + i);

	for (int i = 1; i <= n; i++) dp[i] = 1001001001;
	dp[0] = 0;

	for (int i = 0; i < m; i++){
		for (int j = n; j >= 1; j--){
			dp[j] = min(dp[j], dp[j - 1] + D[j - 1] * C[i]);
		}
	}

	printf("%d\n", dp[n]);

	return (0);
}

Measured memory_bytes: 1200
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <bitset>
typedef unsigned long long int ll;
const ll INF = 876543210987654321;
const int MOD = 1000000007;
#define REP(i,n) for(int i=0;i<n;++i)
#define pd(x) cout<<x<<endl
using namespace std;
//vector<vector<int>>(h, vector<int>(w, f));


int main() {
	string s;
	cin >> s;
	ll a[26] = {};
	ll n = s.size();
	for (int i = 0; s[i]; ++i) {
		a[s[i] - 'a']++;

	}
	ll ans = n*(n - 1) / 2;
	for (int i = 0; i < 26; ++i) {
		if (a[i] > 1)ans -= a[i] * (a[i] - 1) / 2;
	}
	cout << ans+1 << endl;
	int aa;
	cin >> aa;
	return 0;

}

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

using namespace std;

#define ll long long

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

	ll year = 0;
	ll currnet = 100;
	while (currnet < X) {
		currnet *= 1.01;
		year++;
	}

	cout << year << endl;

	return 0;
}


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

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

	vector<ll> ans;
	ll s = 0; 
	for(int i=0; i<N; i++){
		if(i%2 == 0){ s += D[i]; }
		else { s -= D[i]; }
	}
	ans.push_back(s);

	for(int i=1; i<N; i++){
		 s = ans[i-1];
		 s = -s + D[i-1]*2;
		 ans.push_back(s);
	}

	for(int i=0; i<N; i++){
		if(i)cout<<" ";
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 2676
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll a, b, c;

int main()
{
    cin >> a >> b >> c;
    if (c - a - b <= 0)
    {
        cout << "No" << endl;
        return 0;
    }

    if (a * b < ((c - a - b) * (c - a - b) + 3) / 4)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
bingo = []
for _ in range(3):
    bingo.append(list(map(int, input().split())))


N = int(input())

for i in range(N):
    n = int(input())
    for p in range(3):
        for q in range(3):
            if bingo[p][q] == n:
                bingo[p][q] = 101
                break

ans = False

#print(bingo)
for a in bingo:
    if a[0] == a[1] and a[1] == a[2]:
        ans = True

for i in range(3):
    if bingo[0][i] == bingo[1][i] and bingo[1][i] == bingo[2][i]:
        ans = True

if bingo[0][2] == bingo[1][1] and bingo[1][1] == bingo[2][0]:
    ans = True

if bingo[0][0] == bingo[1][1] and bingo[1][1] == bingo[2][2]:
    ans = True

print("Yes") if ans else print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

vll dx = {1, 0, -1, 0};
vll dy = {0, 1, 0, -1};

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

    ll n;
    cin >> n;
    ll a, b;
    vvll g(n);
    REP(i, n - 1) {
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vll d(n, -1);
    ll s = 0;
    d[s] = 0;
    queue<ll> que;
    que.push(s);
    while (!que.empty()) {
        ll cur = que.front();
        que.pop();
        for (auto to : g[cur]) {
            if (d[to] != -1) continue;
            d[to] = d[cur] + 1;
            que.push(to);
        }
    }
    vll c1, c2;
    REP(i, n) {
        if (d[i] % 2) c1.push_back(i);
        else c2.push_back(i);
    }
    vll res(n, -1), used(n + 1);
    if (c1.size() <= n / 3) {
        ll t3 = 3;
        for (auto cc1 : c1) {
            res[cc1] = t3;
            used[t3] = 1;
            t3 += 3;
        }
        ll num = 1;
        REP(i, n) {
            if (res[i] == -1) {
                while (used[num]) num++;
                res[i] = num;
                num++;
            }
        }
    }
    else if (c2.size() <= n / 3) {
        ll t3 = 3;
        for (auto cc2 : c2) {
            res[cc2] = t3;
            used[t3] = 1;
            t3 += 3;
        }
        ll num = 1;
        REP(i, n) {
            if (res[i] == -1) {
                while (used[num]) num++;
                res[i] = num;
                num++;
            }
        }
    }
    else {
        ll q1 = 1, q2 = 2;
        for (auto cc1 : c1) {
            res[cc1] = q1;
            used[q1] = 1;
            q1 += 3;
            if (q1 > n) break;
        }
        for (auto cc2 : c2) {
            res[cc2] = q2;
            used[q2] = 1;
            q2 += 3;
            if (q2 > n) break;
        }
        ll num = 1;
        REP(i, n) {
            if (res[i] == -1) {
                while (used[num]) num++;
                res[i] = num;
                num++;
            }
        }
    }
    REP(i, n) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 22888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  vector<int> A(5);
  rep(i, 0, 5) cin >> A[i];
  sort(A.begin(), A.end());
  int mx = 0;
  int ans = 0;
  rep(i, 0, 5) {
    int t = A[i] % 10;
    if(t == 0) t = 10;
    t = 10 - t;
    ans += A[i] + t;
    mx = max(mx, t);
  }
  cout << ans - mx << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
bool prime[N];
void seive(){
	memset(prime,true,sizeof(prime));
	prime[0] = false;
	prime[1] = false;
	for(int i=2;i<=N;i++){
		if(prime[i]){
			for(int j=2*i;j<=N;j+=i){
				prime[j] = false;
			}
		}
	}
}

bool issimilare(int x){
	if(x%2!=0){
		if(prime[x] && prime[(x+1)/2])
			return true;
		return false;
	}
	return false;
}
int similar[N];
int main(){
//	freopen("input","r",stdin);
	int q,l,r;
	seive();
	memset(similar,0,sizeof(similar));
	for(int i=3;i<=N;i++){
		similar[i] = similar[i-1] + issimilare(i);
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&l,&r);
		printf("%d\n",similar[r]-similar[l-1]);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll a;cin>>a;
		cout<<a+a*a+a*a*a<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=10e9+7;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    string N;
    cin>>N;
    int a,z,ssize;
    ssize=N.size();
    rep(i,ssize){
        if(N.at(i)=='A'){
            a=i;
            break;
        }
    }
    rep(i,ssize){
        if(N.at(ssize-i-1)=='Z'){
            z=ssize-i-1;
            break;
        }
    }
    cout<<z-a+1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s;
bool a[1005];
int main()
{
	cin>>s;
	for(int j=0; j<s.size(); j++)
	{
		if(s[j]=='C')
		{
			for(int k=j; k<s.size(); k++)
			{
				if(s[k]=='F')
				{
					cout<<"Yes";
					return 0;
				}
					
			}
		}
		
		
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
 
const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
 
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N,Y;
    cin >> N >> Y;
    rep(a,N+1)rep(b,N+1){
        if(a+b>N)continue;
        ll t = a*1e4 + b*5e3;
        if(t>Y)continue;
        else {
            ll c = (Y - t) / 1000;
            if( a+b+c == N){
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> cells(h + 1, vector<int>(w + 1, 0));

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            cin >> cells[y][x];
            cells[y][w] += cells[y][x];
        }
    }
    for (int x = 0; x <= w; x++) {
        for (int y = 0; y < h; y++) {
            cells[h][x] += cells[y][x];
        }
    }
    for (int y = 0; y <= h; y++) {
        for (int x = 0; x <= w; x++) {
            if (x > 0) {
                cout << " ";
            }
            cout << cells[y][x];
        }
        cout << endl;
    }
}

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

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

typedef long long ll;

#define eb emplace_back
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
template<typename T> using oset = tree <T, null_type, less_equal <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}
 

const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int fac[N],invf[N];
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int sub(int x, int y) { return x - y >= 0 ? x - y : x - y + mod; }
inline int power(int x, int y, int res = 1) {
    for (; y; y >>= 1, x = 1ll * x * x % mod) {
        if (y & 1) { res = 1ll * res * x % mod; }
    } return res;
}
void initcombi(int n) {
    for (int i = fac[0] = 1; i <= n; i++) { fac[i] = 1ll * fac[i - 1] * i % mod; }
    invf[n] = power(fac[n], mod - 2);
    for (int i = n; i; i--) { invf[i - 1] = 1ll * invf[i] * i % mod; }
}
 
inline int NCR(int n, int m) {
    if (n < m) { return 0; }
    return 1ll * fac[n] * invf[m] % mod * invf[n - m] % mod;
}


int main() {
    io();

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), pre(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        if(i) {
            pre[i] += pre[i - 1] + a[i];

        }
        else {
            pre[i] = a[i];
        }

    }
    for(int i = 0; i < n; i++) {
        pre[i] -= (1LL * (i + 1) * k);
    }

    oset<ll> s;
    ll ans = 0;
    s.insert(0);
    for(int i = 0; i < n; i++) {
        ans += s.order_of_key(pre[i] + 1);
        s.insert(pre[i]);

    }
    cout << ans;

}

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

int main() {
  string s;
  cin >> s;
  string code = "CODEFESTIVAL2016";
  int count = 0;

  for(int i = 0; i < code.size(); i++) {
    if(s[i] != code[i] ) {
      count ++;
    }
  }
  cout << count << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ld p[3005],dp[3005],amount[3005];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;

    int N; cin >> N;

    F0R(i,N) cin >> p[i];

    dp[0] = 1.0;
    F0R(i,N) {
        R0F(w,i+2) {
            dp[w] = ((w == 0) ? 0 : dp[w-1]*p[i])+(dp[w]*(1-p[i]));
        }
    }

    ld res = 0.0;
    F0R(i,N+1) {
        if (N-i < i) res += dp[i];
    }

    cout << res << "\n";

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,i=0,count=1;
    cin>>a>>b;
    if(b!=1){
        for(i=1;count<b;i++){
            count=count+a-1;
        }
    i--;
    }
    cout<<i<<endl;
    return 0;
}


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

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;
  if (A == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll rest = N % (A+B);
  ll sho = N / (A+B);
  ll ans = sho * A;
  if (rest <= A) {
    ans += rest;
  }else{
    ans += A;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256