akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << '*' << x << '\n'
#define ddebug(x , y)  cout << '*' << x << ' ' << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
typedef pair<double , double> pdd ;
const int inf = 0x3f3f3f3f ;
const ll mod = 1e9 + 7 ;
const int maxn = 1e5 + 5 ;
const int maxm = 30 ;
const double eps = 1e-6 ;
const double pi = acos(-1.0) ;
int n , m ;
int h[maxn] ;
vector<int> g[maxn] ;
int main()
{
	rr(n , m) ;
	rep(i , 1 , n)  r(h[i]) ;
	rep(i , 1 , m)
	{
		int u , v ;
		rr(u , v) ;
		g[u].pb(v) ;
		g[v].pb(u) ;
	}
	int ans = 0 ;
	rep(i , 1 , n)
	{
		bool flag = 0 ;
		for(auto v : g[i])
		  if(h[v] >= h[i])  flag = 1 ;
		if(!flag)  ans ++ ;
	}
	w(ans) , en() ;
	  
	  
	return 0 ;
}

Measured memory_bytes: 9340
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	var input0 = input[0].split(" ");
	const N = parseInt(input0[0]);
	const K = parseInt(input0[1]);
	if(K == 1){
		console.log(0);
	}else{
		console.log(N-K);
	}
 }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = a * a;
		int c = a * a * a;
		// 出力
		System.out.println((a+b+c));
	}
}

Measured memory_bytes: 35644
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt_L = 0, cnt_R = 0;

    rep(i, n){      //( Lを数える
        if(s[i] == '(')cnt_L++;
        else if(cnt_L > 0)cnt_L--;
    }

    string t = s;
    reverse(ALL(t));

    rep(i, n){      //( Lを数える
        if(t[i] == ')')cnt_R++;
        else if(cnt_R > 0)cnt_R--;
    }
    deque<char> deq;

    rep(i, n)deq.push_back(s[i]);

    rep(i, cnt_L)deq.push_back(')');
    rep(i, cnt_R)deq.push_front('(');

    while(!deq.empty()){
        cout << deq.front();
        deq.pop_front();
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll first;
    cin>>first;
    a[(n-1)/2]=first;
    int rev=0;
    ll l=(n-1)/2,r=(n-1)/2;
    for(ll i=1;i<n;i++)
    {
        ll t;
        cin>>t;
        if(rev)
        {
            l--;
            a[l]=t;
            
        }
        else
        {
            r++;
            a[r]=t;
            
        }
        rev+=1;
        rev%=2;
    }
    if(n%2==0)
    {
        for(ll i=n-1;i>=0;i--)
        {
            cout<<a[i]<<" ";
        }
    }
    else
    {
        rep(i,n)
        {
            cout<<a[i]<<" ";
        }
    }
    
    
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(void) {
	int x;
	scanf("%d", &x);
	int y;
	for (y = x;; y++) {
		if (y == 2)goto s;
		for (int j = 2; j < x; j++) {
			if (y % j == 0) break;
			if(j == x-1) goto s;
		}
	}
	s:
	printf("%d", y);
}

Measured memory_bytes: 128
# 2020/04/29
# AtCoder Beginner Contest 149 - D

# Input
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

# Init
d = dict()
d['r'] = r
d['s'] = s
d['p'] = p

d['wintr'] = 'p'
d['wints'] = 'r'
d['wintp'] = 's'

ngt = [''] * n

# Calc
ans = 0
for i in range(n-1, -1, -1):
    wint = d['wint' + t[i]]
    if ngt[i] != wint:
        ans = ans + d[wint]
        if i - k >= 0:
            ngt[i-k] = wint

# Output
print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
						using namespace std;
						#define pll pair<ll,ll>
						typedef long long ll;
						#define mod 51123987
						#define fi first
						#define se second
						#define mp make_pair
						#define pb push_back
						#define INF 1e15
						const int N=2e5+5;
						const int LG=21;
						
						int main()
						{
							ll n;
							cin>>n;
							cout<<(ceil)(n*1.0/2);
							
						}


Measured memory_bytes: 256
import sys
buf=[]
op="+-*/"
def f(i):
  b=buf.pop()
  a=buf.pop()
  if i==0:x=a+b
  elif i==1:x=a-b
  elif i==2:x=a*b
  else:x=a/b
  buf.append(x)
  return
for s in sys.stdin:
  for e in s.split():
    if op.count(e):f(op.index(e))
    else:buf.append(float(e))
  print buf.pop()

Measured memory_bytes: 4240
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        StringBuilder builder = new StringBuilder();
        StringTokenizer to;
        int[] nums = new int[3];
        int a = Integer.parseInt(reader.readLine());
        for (int i = 0; i < a; i++) {
            to = new StringTokenizer(reader.readLine());
            for (int j = 0; j < 3; j++) {
                nums[j] = Integer.parseInt(to.nextToken());
            }
            Arrays.sort(nums);
            if (Math.pow(nums[0], 2) + Math.pow(nums[1], 2) == Math.pow(
                    nums[2], 2))
                builder.append("YES\n");
            else
                builder.append("NO\n");
        }
        System.out.print(builder);

    }
}

Measured memory_bytes: 24796
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int []a = new int [3];
		int []b = new int [3];
		
		int max = 0;
		int sum = 0;
		
		for(int i = 0; i < 3 ; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max,a[i]);
			sum += a[i];
		}
		
		if((3 * max) % 2 == sum % 2) {
			int ans = (3 * max  - sum)/2;
			System.out.println(ans);
		}
		else {
			int ans = (3* max + 1 - sum)/2 + 1;
			System.out.println(ans);
		}
		
	}

}


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

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a (n);
    for (int i = 0; i < n; i++) cin >> a[i];

    auto check = [&](int x) -> bool {
        int cut = 0;
        for (int i = 0; i < n; i++) {
            cut += ((a[i] / x) + (a[i] % x != 0) - 1);
        }
        return cut <= k;
    };

    int L = 1, R = (int) 1e9;
    while (L < R) {
        int mid = L + (R - L)/2;
        if (check(mid)) {
            R = mid;
        } else {
            L = mid + 1;
        }
    }
    cout << R << endl;
}

int main() {
    solve();
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  int N = (int)s.size();
  string ans[2] = {"First", "Second"};
  // vec< vec< int > > a(26, vec< int >());
  // vec< pair< int, int > > E;
  // REP(i, N) { a[s[i] - 'a'].pb(i); }
  // REP(i, 26) {
  //   REP(j, (int)a[i].size() - 1) { E.pb(mp(a[i][j + 1], a[i][j])); }
  // }
  // sort(ALL(E));

  // // REP(i, (int)E.size()) { cout << E[i].fst << " " << E[i].snd << "\n"; }
  // int begin = -1;
  // int counttmp = 0;
  // set< int > count;
  // count.insert(0);
  // count.insert(N - 1);
  // REP(i, (int)E.size()) {
  //   if (begin <= E[i].snd) {
  //     begin = E[i].fst;
  //     count.insert(E[i].fst);
  //     count.insert(E[i].snd);
  //     counttmp++;
  //   }
  // }
  // DEBUG((N - count.size() - counttmp));
  // print(ans[(1 + N - count.size() - counttmp) % 2]);
  if (s[0] == s.back()) {
    print(ans[N % 2]);
  } else {
    print(ans[(1 + N) % 2]);
  }
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b / a, c) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,j,m,p,k,q;
	char c,w;
  while(cin>>n,n){
  	int a[26]={0},i,f=1,q=0;
    for(i=1;i<=n;i++){
	  cin>>c;
	  for(a[c-'A']++,m=j=0;j<26;j++)if(max(m,a[j])==a[j]){k=j;m=a[j];}
	  for(p=j=0;j<26;j++)if(j!=k)p=max(p,a[j]);
	  if(m>n-i+p&&f){
	  	q=i;w=k+'A';f=0;
	  }
	}
	if(q>0)cout<<w<<' '<<q<<endl;
	else cout<<"TIE"<<endl;
  }
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  int n = int(sqrt(2 * x));
  int ans = ((1 + n) * n / 2 >= x) ? n : n + 1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        if (Math.abs(a - b) <= k && Math.abs(a - c) <= k && Math.abs(a - d) <= k
                && Math.abs(a - e) <= k && Math.abs(b - c) <= k && Math.abs(b - d) <= k
                && Math.abs(b - e) <= k && Math.abs(c - d) <= k && Math.abs(c - e) <= k
                && Math.abs(d - e) <= k) {
            System.out.println("Yay!");
            return;
        }
        System.out.println(":(");
    }

}


Measured memory_bytes: 23124
inf=10**11
A,B,Q=map(int,input().split())
s=[-inf]+[int(input()) for _ in range(A)]+[inf]
t=[-inf]+[int(input()) for _ in range(B)]+[inf]
x=[[i,int(input())] for i in range(Q)]

x.sort(key=lambda x:x[1])
i,s_i,t_i=0,0,0
ans=[]

for i in range(Q):
    while(1):
        if x[i][1]>=s[s_i]:
            s_i+=1
        else:
            break
    while(1):
        if x[i][1]>=t[t_i]:
            t_i+=1
        else:
            break
    ans.append([x[i][0],x[i][1],s[s_i-1],s[s_i],t[t_i-1],t[t_i]])
ans.sort(key=lambda x:x[0])
for i in range(Q):
    xx=ans[i][1]
    Nb_s0=ans[i][2]
    Nb_s1=ans[i][3]
    Nb_t0=ans[i][4]
    Nb_t1=ans[i][5]

    p1=abs(Nb_s0-xx)
    p2=abs(Nb_s1-xx)
    p3=abs(Nb_t0-xx)
    p4=abs(Nb_t1-xx)
    q1=abs(Nb_t0-Nb_s0)
    q2=abs(Nb_t0-Nb_s1)
    q3=abs(Nb_t1-Nb_s0)
    q4=abs(Nb_t1-Nb_s1)
    print(min(p1+q1,p2+q2,p1+q3,p2+q4,p3+q1,p4+q4,p3+q2,p4+q3))

Measured memory_bytes: 42672
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    if (S[0]==S[1]){
        cout << "1 2" << endl;
        return 0;
    }
    repf(i,2,N){
        if (S[i-2]==S[i]||S[i-1]==S[i]){
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
}


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

using namespace std;

int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n, k; cin >> n >> k;
        int a[n+1];
        for (int i=1; i<=n; i++) cin >> a[i];
        int dp[n+1];
        for (int i=1; i<=n; i++) dp[i] = 1000000000;
        dp[1] = 0;
        for (int i=2; i<=n; i++)
        {
                for (int j=1; j<=k; j++)
                        if (i-j>=1) dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
                        else break;
        }
        cout << dp[n];
        return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

#define NUM 10000
int C[NUM];

#define ELM_NUM 2000000
int A[ELM_NUM];
int B[ELM_NUM];


void CountingSort(int N){
    
    int i, idx;
    
    for (i=0; i < NUM; i++) {
        C[i] = 0;
    }
    
    /* C[i] ??? i ???????????°????¨?????????? */
    for (i=0; i < N; i++) {
        C[A[i]]++;
    }
    
    /* C[i] ??? i ??\????????°???????????°????¨??????????*/
    for (i=1; i < NUM; i++) {
        C[i] = C[i] + C[i-1];
    }
    
    for (i = N-1; i >=0; i--) {
        
        /* A[i]???????´??????????idx?????\??????*/
        idx = C[A[i]] - 1;
        B[idx] = A[i];
        C[A[i]]--;
    }
    
    return;
}

int main( ){
    
    int i,n;
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        scanf("%d", &A[i]);
    }
    
    
    CountingSort(n);
    
    for (i=0; i<n; i++) {
        printf("%d", B[i]);
        if (i != n-1) {
            printf(" ");
        }
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 16268
from collections import deque

reverse = False

S = deque(list(input()))

N = int(input())

for _ in range(N):
    cmd = input()
    if cmd[0] == '1':
        reverse = not reverse
    else:
        cmd = cmd.split()
        if cmd[1] == '1':
            if reverse:
                S.append(cmd[2])
            else:
                S.appendleft(cmd[2])
        else:
            if reverse:
                S.appendleft(cmd[2])
            else:
                S.append(cmd[2])

if reverse:
    S.reverse()

print(''.join(S))

Measured memory_bytes: 8676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
  ll n;
  cin >> n;
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  vector<ll> count(1000);
  for(int i = 0;i < 1000;i++)count[i] = 0;
  for(int i = 2;i <= n;i++){
    ll now = i;
    for(int j = 2;j <= i;j++){
      while(now % j == 0){
        count[j]++;
        now /= j;
      }
    }
  }
  ll res = 0;
  res = 1;
  for(int i = 2;i < 1000;i++){
    res *= count[i] + 1;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

d, n = gets.chomp.split(/ /)
d = d.to_i
n = n.to_i
n += 1 if n == 100
if (d == 0)
  num = n
elsif (d == 1)
  num = n * 100
else
  num = 100 * 100 * n
end

puts num


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    string s;
    int w, l, d;
    bool p = 0;
    while (cin >> n, n)
    {
        if (p)
            cout << endl;
        p = 1;
        multimap<int, string, greater<int>> mp;
        rep(i, n)
        {
            cin >> s >> w >> l >> d;
            mp.insert(make_pair(3 * w + d, s));
        }

        for (auto a : mp)
            cout << a.second << "," << a.first << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long N, K;
long long arr[100005];
long long finalAns;

int main()
{
	scanf("%lld %lld", &N, &K);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	
	int left, ans;
	left = N - K;
	ans = 1;

	while(left > 0) {
		left -= (K - 1);
		ans++;
	}

	printf("%d\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var sum = Console.ReadLine().Split().Select(int.Parse).Sum();
            if (NM[0] - sum < 0 )
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(NM[0] - sum);
            }
        }
    }
}

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

struct node{  
  int to;
  int dis;
};

int N;
int NMAX = 100001;
vector<vector<node>> tree(NMAX);
vector<int> color(NMAX, -1);
vector<bool> check(NMAX);

void dfs(int k, int distance){  
  check[k] = true;
  if(distance % 2 == 0) color[k] = 0;
  else color[k] = 1;
  for(auto n: tree[k]){  
    int to = n.to;
    if(!check[to]){  
      dfs(to, distance + n.dis); 
    }
  } 
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> N;
  for(int i = 0; i < N-1; i++){  
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    node n1 = {v, w};
    node n2 = {u, w};
    tree[u].push_back(n1);
    tree[v].push_back(n2);
  }
  dfs(0, 0);
  for(int i = 0; i < N; i++) cout << color[i] <<endl;
}


Measured memory_bytes: 10936
#include<stdio.h>

int main(){
    int people_count[4][3][10] = {};
    int info_count, wing, floor, room, count;
    scanf("%d", &info_count);
    for(int i=0; i<info_count; i++){
        scanf("%d %d %d %d", &wing, &floor, &room, &count);
        people_count[wing-1][floor-1][room-1] += count;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                printf(" %d",people_count[i][j][k]);
            }
            printf("\n");
        }
        if(i<4-1) printf("####################\n");
    }
    return 0;
}


Measured memory_bytes: 2048
r,c = map(int,input().split())
sheet = [list(map(int,input().split())) for i in range(r)]
for j in range(r):
         sheet[j].append(sum(sheet[j]))
newrow = []
for k in range(c+1):
         tmp = 0
         for l in range(r):
                  tmp  += sheet[l][k]
         newrow.append(tmp)
sheet.append(newrow)
for m in range(r+1):
         print(*sheet[m])




Measured memory_bytes: 6228
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
void check(string&s,int i,int &n){
	int tmp;
	if(s[i]!='a'&&(tmp='z'+1-s[i])<=n){
		s[i]='a';n-=tmp;
	}
}
int main(){
	int n;string s;
	while(cin>>s>>n){
		for(int i=0;i<s.size();i++){
			check(s,i,n);if(n==0)break;
		}
		if(n)s.back()=(s.back()+n-'a')%26+'a';
		cout<<s<<endl;
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
bool index(int s,int k){
  if(s>k) return true;
  else return false;
}
int main(){
  int d,n,m;
  while(cin>>d,d){
    cin >> n >> m;
    int s[n+1],k,ans = 0;
    for(int i=1;i<n;i++) cin >> s[i];
    s[0] = 0;
    s[n] = d;
    sort(s,s+n+1);
    for(int i=0;i<m;i++){
      cin >> k;
      int max = n;
      int mins = 0;
      while(max-mins>1){
 int a = (max+mins) / 2;
 if(index(s[a],k)) max = a;
 else mins = a;
      }
      ans += min(abs(k-s[max]),abs(k-s[mins]));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
ll k,n,a[maxn],pos=1,cnt,res,vis[maxn];
vector<ll>ans;
int main() {
	cin>>n>>k;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	while(true) {
		if(vis[pos]==2) break;
		if(!vis[pos]) {
			cnt++;
			if(k==cnt) return cout<<a[pos],0;
		} else {
			ans.push_back(pos);
			res++;
		}
		vis[pos]++;
		pos=a[pos];
	}
	cout<<ans[(k-cnt+res)%res];
	return 0;
}

Measured memory_bytes: 7196
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	int N, last_A = 0, first_B = 0, answer = 0, sw = false, B_to_A = 0;
	cin >> N;
	char **str;
	str = (char **)malloc(sizeof(char *) * N);
	for (int i = 0; i < N; i++) {
		str[i] = (char *)malloc(sizeof(char) * 10);
		cin >> str[i];
	}
	for (int i = 0; i < N; i++) {
		if (str[i][0] == 'A') {
			sw = true;
		}
		if (str[i][0] == 'B') {
			if (str[i][strlen(str[i]) - 1] == 'A') {
				B_to_A++;
			}
			else {
				first_B++;
			}
		} 
		else if (str[i][strlen(str[i]) - 1] == 'A') {
			last_A++;
		}
		for (int j = 1; j < strlen(str[i]); j++) {
			if (str[i][j] == 'A') {
				sw = true;
			}
			else if (sw && str[i][j] == 'B') {
				answer++;
				sw = false;
			}
			else {
				sw = false;
			}
		}
		sw = false;
	}
	if (B_to_A > 1) {
		answer += B_to_A - 1;
		B_to_A = 1;
	}
	if (B_to_A == 1) {
		if (first_B > 0 && last_A > 0) {
			answer += 2;
			first_B--;
			last_A--;
		}
		else if (first_B == 0) {
			first_B++;
		}
		else if (last_A == 0) {
			last_A++;
		}
		B_to_A--;
	}
	answer += min(first_B, last_A);
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>

using namespace std;

int main()
{
  
  while(true)
    {
      int a,b,cnt = 0;
      cin >> a >> b;
      if(a+b == 0)break;
      map<int,int> exist;
      for(int i=0;i<a;i++)
	{
	  int in;
	  cin >> in;
	  exist[in]++,cnt+=in;
	}


      for(int i=0;i<b;i++)
	{
	  int in;
	  cin >> in;
	  if(!exist[in])
	    {
	      cnt += in;
	    }
	  else 
	    {
	      exist[in]--;
	    }
	}
      cout << cnt << endl;
    }
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstdio>
#include<cstdlib>
//#include<>                                                                                
using namespace std;

long long get_G(long long a,long long b){
  //Eucledean algorithm                                                                     
  if(a%b==0)return b;
  else return get_G(b,a%b);
}

int main(){

  int n,a[1000];
  long long L;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  L=a[0];
  //最大公約数を求める                                                                      
  for(int i=1;i<n;i++){
    L=L*a[i]/get_G(L,a[i]);
  }
  cout<<L<<endl;
  return 0;
}

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

int main()
{
   
     int n;
     cin>>n;
     int ans=0;
     int v[n],c[n];
     for(int i=0;i<n;i++)
     {
         cin>>v[i];
     }  
  for(int i=0;i<n;i++)
     {
         cin>>c[i];
     } 
    for(int i=0;i<n;i++)
     {
       if(v[i]>c[i])
       ans+=(v[i]-c[i]);
     } 
     cout<<ans;
}


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

typedef long long int   ll;
#define int             ll
#define PI              3.1415926535897932384626433832795

#define pb              push_back
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]

#define hell            freopen("input.txt","r", stdin);freopen("output.txt", "w", stdout);freopen("error.txt", "w",stderr);
#define fastasF_boi()   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
//#define cerr            if(false)cerr

int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mulmod(int a,int b){return ((a%mod)*(b%mod))%mod;}
int addmod(int a,int b){return (((a%mod)+(b%mod))+mod)%mod;}

void solve(){
    int n;cin>>n;
    int mx=0;
    int ar[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        ans+=max(0ll,mx-ar[i]);
        mx=max(ar[i],mx);
    }
    cout<<ans<<endl;
}

signed main(){
//    hell;

    fastasF_boi();
    int t=1;
//    cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
}



Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    
    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
}


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

int main(){
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0) ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    int n; cin >> n;
    int a = 0;          // ... A
    int b = 0;          // B ...
    int ba = 0;         // B ... A
    int ab = 0;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        int len = s.length();
        for (int j = 0; j + 1 < len; j++) {
            if (s[j] == 'A' && s[j + 1] == 'B') ab++;
        }
        if (s[0] == 'B' && s[len - 1] == 'A') {
            ba++;
        } else if (s[0] == 'B') {
            b++;
        } else if (s[len - 1] == 'A') {
            a++;
        }
    }
    int ans = ab + min(a, b) + ba;
    if (ba && !a && !b) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():

    N,K = map(int,input().split())
    hList = [int(input()) for _ in range(N)]

    hList.sort()
    it = iter(hList)
    diffList = []
    bady = K-1


    for i in range(N-K+1):

        diff = hList[i]-hList[i+bady]
        diffList.append(abs(diff))
    

    print(min(diffList))







    
if __name__== "__main__":
    main() 




Measured memory_bytes: 11212
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
ll gcd(ll a, ll b){
	while(b){
		ll r=a%b;
		a=b;
		b=r;
		}
	return a;
	}
int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<lcm(a,b)<<nw;
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;
    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));

    bool is_heisei = false;
    is_heisei |= (m <= 4);
    cout << (is_heisei ? "Heisei" : "TBD") << endl;
    return 0;
}


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

int main(){
	int h,w;
	char a[100][100];
	int b[100][100],d;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			d=0;
			for(int k=j;k>=0;k--){
				if(a[i][k]=='c'){
					b[i][j]=d;
					goto Exit;
				}
				d++;
			}
			b[i][j]=-1;
			Exit:
			d=0;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j==w-1){
				cout<<b[i][j]<<endl;
			}
			else{
				cout<<b[i][j]<<' ';
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

int diffField(vs beforeField, vs afterField) {
	int diffPoint = -1;
	REP(i, 8) {
		REP(j, 8) {
			if(beforeField[i][j] != afterField[i][j]) {
				diffPoint++;
			}
		}
	}
	return diffPoint;
}

vs updateField(vs field, int x, int y, char c) {
	REP(d, 8) {
		int nx = x, ny = y, step = 1;
		while(true) {
			nx = x+dx[d]*step, ny = y+dy[d]*step;
			if(nx < 0 || 8 <= nx || ny < 0 || 8 <= ny || field[ny][nx] == '.') {
				break;
			}
			if(field[ny][nx] == c) {
				FOR(i, 1, step) {
					field[y+dy[d]*i][x+dx[d]*i] = c;
				}
				break;
			}
			step++;
		}
	}

	field[y][x] = c;
	return field;
}

pii searchOPoint(vs field) {
	pii res(-1, -1);
	int maxDiff = 0;
	REP(i, 8) {
		REP(j, 8) {
			if(field[i][j] == '.') {
				vs newField = updateField(field, j, i, 'o');
				int newDiff = diffField(field, newField);
				if(maxDiff < newDiff) {
					maxDiff = newDiff;
					res = pii(j, i);
				}
			}
		}
	}

	return res;
}

pii searchXPoint(vs field) {
	pii res(-1, -1);
	int maxDiff = 0;
	for(int i = 7; i >= 0; i--) {
		for(int j = 7; j >= 0; j--) {
			if(field[i][j] == '.') {
				vs newField = updateField(field, j, i, 'x');
				int newDiff = diffField(field, newField);
				if(maxDiff < newDiff) {
					maxDiff = newDiff;
					res = pii(j, i);
				}
			}
		}
	}

	return res;
}

int main() {
	vs field(8);
	REP(i, 8) {
		cin >> field[i];
	}

	bool updated = true;
	while(updated) {
		updated = false;
		pii oPoint = searchOPoint(field);
		if(oPoint.first != -1) {
			updated = true;
			field = updateField(field, oPoint.first, oPoint.second, 'o');
		}

		pii xPoint = searchXPoint(field);
		if(xPoint.first != -1) {
			updated = true;
			field = updateField(field, xPoint.first, xPoint.second, 'x');
		}
	}
	
	REP(i, 8) {
		cout << field[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

using namespace std;
int main(void) {
	long long a = 0, b = 0,c = 0,K = 0,ans = 0;
	scanf("%lld%lld%lld%lld", &a, &b,&c,&K);
	if (a >= c && a >= b) {
		ans += c + b;
		for (long long i = 0; i < K; i++) {
			a *= 2;
		}
		ans += a;
	}else if (b >= c && b >= a) {
		ans += c + a;
		for (long long i = 0; i < K; i++) {
			b *= 2;
		}
		ans += b;
	}else if(c >= a && c >= b) {
		ans += b + a;
		for (long long i = 0; i < K; i++) {
			c *= 2;
		}
		ans += c;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	cin >> N >> K;
	ll ans = 0;
	for (ll k = K; k <= N + 1; k++) {
		ans = (ans + k * N - k * (k - 1) + 1) % MOD;
	}
	cout << ans;
}

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

template <class InputIterator, class OutputIterator>
OutputIterator RLE(InputIterator start, InputIterator end, OutputIterator result)
{
    InputIterator cmp = start;
    size_t cnt = 0;

    while (start != end) {
        start++;
        cnt++;
        if (start == end || *start != *cmp) {
            *result++ = { *cmp, cnt };
            cmp = start;
            cnt = 0;
        }
    }

    return result;
}

void main_()
{
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<pair<char, ll>> S_rle;
    RLE(begin(S), end(S), back_inserter(S_rle));

    // 判定を簡単にするため、左端と右端が'0'の場合は仮想的に0人の'1'を入れる
    if (S_rle.front().first == '0') {
        S_rle.insert(begin(S_rle), { '1', 0 });
    }
    if (S_rle.back().first == '0') {
        S_rle.emplace_back('1', 0);
    }

    vector<ll> psum;
    psum.push_back(0);
    for (auto&& p : S_rle) {
        psum.push_back(psum.back() + p.second);
    }

    if (K >= (ll)psum.size() / 2 - 1) {
        // 全員を'1'にすることが可能
        cout << psum.back() << endl;
        return;
    }

    ll ans = 0;
    for (ll i = 1; i + K * 2 < (ll)psum.size(); i += 2) {
        ans = max(ans, psum[i + K * 2] - psum[i - 1]);
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 3776
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;


int main() {

    int N;
    cin >> N;

    int K;
    cin >> K;

    vector<long long> h(N);
    for (int i = 0; i < N; i++)cin >> h[i];

    vector<long long> dp(N, 1e14);
    dp[0] = 0;

    for (int i = 1; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            int f = max(0, i - j);
            dp[i] = min(dp[i], dp[f] + abs(h[i] - h[f]));
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}



























Measured memory_bytes: 1792
use std::collections::HashMap;

fn read<T: std::str::FromStr>()->T{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();

    s.trim().parse().ok().unwrap()
}


fn main(){
    
    let s: String = read();
    
    let n:i64 = s.parse().unwrap();

    let mut vec: Vec<i64> = Vec::new();

    
    let mut mp:HashMap<i64, i64> = HashMap::new();

    for i in 0..n{
        let tmp: String = read();
        let num: i64 = tmp.parse().ok().unwrap();
        
        let c = mp.entry(num).or_insert(0);
        *c += 1;
    }

  

    println!("{}", mp.iter().filter(|&(k, v)| *v%2==1).count());

}





Measured memory_bytes: 12540
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a = I()
    print(a+a**2+a**3)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65432
#include <bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int> m;
    m["SUN"]=1;
    m["MON"]=2;
    m["TUE"]=3;
    m["WED"]=4;
    m["THU"]=5;
    m["FRI"]=6;
    m["SAT"]=7;
    string s;
    cin>>s;
    cout<<(8-m[s]);
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: u64,
    }
    println!("{}", N*(N+1)/2);
}

Measured memory_bytes: 4352
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"3"# => "2",
r#"1"# => "Hello World",
r#"2 4 5"# => "9",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        x: [usize; if n == 1 { 0 } else { 2 }],
    }

    if n == 1 {
        "Hello World".to_string()
    } else {
        (x[0] + x[1]).to_string()
    }
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  stack<int> S;
  REP(i,s.size()){
    char c = s[i];
    int x = c=='S'?0:1;
    if(S.size()>0 && S.top() == 0 && x==1)S.pop();
    else S.push(x);
  }
  printf("%d\n",S.size());
  return 0;
}


Measured memory_bytes: 1408
N = int(input())
S = input()

left = [0 for _ in range(N)]
cnt = 0
for i in range(0, N):
    left[i] = cnt
    if S[i] == 'W':
        cnt += 1

right = [0 for _ in range(N)]
cnt = 0
for i in range(N - 1, -1, -1):
    right[i] = cnt
    if S[i] == 'E':
        cnt += 1

total = [l + r for l, r in zip(left, right)]
print(min(total))


Measured memory_bytes: 68876
# -*- coding: utf-8 -*-
import numpy as np
import itertools
from copy import deepcopy

H, W , K = [int(i) for i in input().split()]

Arr = np.zeros((H, W))
for i in range(H):
    words = input()
    for j, w in enumerate(words):
        if w == "#":
            Arr[i,j] = 1
#print(Arr)
ans = 0
for t in range(0,H+W):
    Ex = list(itertools.combinations([int(i) for i in range(H+W)],t))
    for j in Ex:
        TMP = deepcopy(Arr)
        for num in j:
            if num < H:
                TMP[num] = np.zeros(W)
            else:
                w = num - H
                #print(TMP)
                TMP[:,w] = np.zeros(H)
                #print(w,TMP[:,w])
        if K == int(np.sum(TMP)):
            ans += 1
print(ans)


Measured memory_bytes: 27508
a,b=list(map(int, input().split()))
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def coprime(a, b):
    return gcd(a, b) == 1

c = md(gcd(a,b))
c.sort()
if len(c)== 1:
    count = 1
else:
    count = 1
    d = c[0]
    for i in c[1:]:
        if coprime(d, i):
            d = d*i
            count += 1
        else:
            continue

print(count)

Measured memory_bytes: 3316