akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
from itertools import combinations
N = int(input())
C = [0, 0, 0, 0, 0]
march = set(list("MARCH"))
for _ in range(N):
    S = input()[0]
    if S in march:
        C["MARCH".index(S)] += 1

ans = 0
for a, b, c in combinations(range(5), r=3):
    ans += C[a]*C[b]*C[c]
print(ans)


Measured memory_bytes: 3064
from collections import deque

def bfs(maze, visited, x):
    queue = deque([x])
    visited[x] = 1
    ans_list[x] = 0
    while queue:
      #queueには訪れた地点が入っている。そこから、移動できるか考え、queueから消す。
        y = queue.popleft()#queueに入っていたものを消す。
        r = maze[y - 1][2:]
        for i in r:
            if visited[i] == 0:
              if ans_list[i] >= 10 ** 10:
                ans_list[i] = ans_list[y] + 1
                queue.append(i)
    return 0
              

                
if __name__ == "__main__":
  N = int(input())
  A = [0] * N
  for i in range(N):
    A[i] = list(map(int, input().split()))
  visited = [0] * (N + 1)
  ans_list = [float("inf")] * (N + 1)
  bfs(A, visited, 1)
  #print(bfs(A, visited, 1))
  for i in range(1, N + 1):
    if ans_list[i] >= 10 ** 10:
      print(i, -1)
    else:
      print(i, ans_list[i])
                
  
  
  
  
  
  


Measured memory_bytes: 6040
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
typedef pair<int,int> pii;
#define fast   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;
//priority_queue<pii, vector<pii>, greater<pii> > pq;



inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

/**

 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */


int main(){
    int n;
    cin>>n;
    ll ans=0;
    ll cnt=0;
    n--;
        for(int j=1;j<=n;++j){
                ans+=n/j;
        }
        
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define For(i,n) for(int i=0;i<n;i++)
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans=0,end=-1e9;
    cin>>n;
    vector<int>x(n),l(n);
    vector<P>xL(n);
    rep(i,0,n){
        cin>>x[i]>>l[i];
    }
    //sort(xl.begin(),xl.end());
    For(i,n){
        xL[i].first=x[i]+l[i];
        xL[i].second=x[i]-l[i];
    }
    sort(xL.begin(),xL.end());
    For(i,n){
        if(end<=xL[i].second){
            ans++;end=xL[i].first;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Input.num;
        var heights = Input.ar;
        var dp = new long[num];
        dp[0] = 0;
        dp[1] = Abs(heights[0] - heights[1]);
        for (var i = 2; i < num; i++)
            dp[i] = Min(dp[i - 2] + Abs(heights[i] - heights[i - 2]), dp[i - 1] + Abs(heights[i] - heights[i - 1]));
        WriteLine(dp[num - 1]);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 19424
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<bits/stdc++.h>
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n;
  cin >> n;
  vector<pair<ll,ll>>v(n);
  for (int i = 0; i < n; ++i)
  {
    ll a,b;
    cin >> a >> b;
    v[i].first = b;
    v[i].second = a;
  }
  ll f = 0,c = 0;
  sort(v.begin(),v.end());
  for (int i = 0; i < n; ++i)
  {
    c += v[i].second;
    if (v[i].first < c)
    {
      f = 1;
      break;
    }
  }
  if(f == 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3328
n,k = map(int,input().split())

sunuke = list(range(1, n+1))

#print(sunuke)

for i in range(k):
  d = int(input())
  #print(d)
  A = list(map(int, input().split()))
  #print(A)
  for id, s in enumerate(sunuke):
    if s in A:
      sunuke[id] = 0
      #print(str(s) + "が0になったよ")
      #print(sunuke)

count = 0
for s in sunuke:
  if s != 0:
  	count += 1
print(count)

Measured memory_bytes: 9196
input_line = input().split(" ")
X=input_line[0]
Y=input_line[1]
Z=input_line[2]

ram=X
X=Y
Y=ram

ram=X
X=Z
Z=ram



input_line[0]=X
input_line[1]=Y
input_line[2]=Z

input_line=' '.join(input_line)
print(input_line)

Measured memory_bytes: 3060
# キューを使ったアプローチ

from collections import deque

S = deque(input())
Q = int(input())

T = 0
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        m = Query[2]
        if Query[1] == '1':
            S.appendleft(m)
        else:
            S.append(m)
    else:
        m = Query[2]
        if Query[1] == '2':
            S.appendleft(m)
        else:
            S.append(m)

if T==1:
    S.reverse()

print(''.join(S))


Measured memory_bytes: 8436
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <boost/math/common_factor_rt.hpp>

long solve(long a, long b)
{
  return boost::math::lcm(a, b);
}

int main()
{
  long a, b;
  std::cin >> a >> b;

  std::cout << solve(a, b) << std::endl;
}


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

long a[100000];

int main()
{
	memset(a, 0, sizeof(a));

	int n, j = 0;
	cin >> n >> a[0];

	for (int i = 1; i < n; i++) {
		long k;
		cin >> k;

		if (k > a[j]) {
			a[j + 1] = k;
			j++;
		}
	}

	for (int i = 0; i < j; i++) {
		cout << a[i] << " ";
	}
	cout << a[j] << endl;

	return 0;
}


Measured memory_bytes: 3852
while True:
    [n, m] = [int(x) for x in raw_input().split()]
    if [n, m] == [0, 0]:
        break

    data = []
    for x in range(n, 2, -1):
        for y in range(x - 1, 1, -1):
            for z in range(y - 1, 0, -1):
                s = x + y + z
                if s < m:
                    break
                if s == m:
                    data.append(s)

    print(len(data))

Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin>>n;
    pair<ll,ll> arr[n];
    for(int i=0;i<n;i++){
        ll a,b; cin>>a>>b;
        arr[i].ff=a-b;
        arr[i].ss=a+b;
    }
    sort(arr,arr+n);
    set<ll> s; s.insert(arr[0].ss);
    for(int i=1;i<n;i++){
        auto it=--s.end();
        ll x=*it;
        if(x<=arr[i].ff){
            s.insert(arr[i].ss);
            continue;
        }
        s.erase(it);
        s.insert(min(x,arr[i].ss));
    }
    cout<<sz(s)<<endl;
}

Measured memory_bytes: 6528
import java.util.*;
import java.util.Map;
import java.util.HashMap;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            if(map.containsKey(A[i])){
                map.remove(A[i]);
            }
            else{
                map.put(A[i], 0);
            }
        }

        System.out.println(map.size());
    }
}

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

int main(void){

  string S;
  cin >> S;
  string MM1 = "";
  string MM2 = "";
  MM1 += S[0];
  MM1 += S[1];
  MM2 += S[2];
  MM2 += S[3];

  if(stoi(MM1) >= 1 && stoi(MM1) <= 12 && stoi(MM2) >= 1 && stoi(MM2) <= 12){
    cout << "AMBIGUOUS" << endl;
  }else if(stoi(MM1) >= 1 && stoi(MM1) <= 12){
    cout << "MMYY" << endl;
  }else if(stoi(MM2) >= 1 && stoi(MM2) <= 12){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
long N,i,ans;
vector<long> sum1,sum2,a;

inline void solve(){
  IN(N);
  a.resize(N);
  sum1.resize(N);
  sum2.resize(N);
  ans=1LL<<61;
  INS(i,N,a);
  sum1[0]=a[0];
  sum2[N-1]=a[N-1];
  UP(i,1,N-1){
    sum1[i]=sum1[i-1]+a[i];
    sum2[N-1-i]=sum2[N-i]+a[N-1-i];
  }
  REP(i,N-1)chmin(ans,abs(sum1[i]-sum2[i+1]));
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 200011

int n, i;
char s[maxN];
int cnt[maxN];
ll ans;

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (i = 1; i <= n; i++) cnt[s[i] - 'a']++;


    ans = (1LL * n * (n - 1)) / 2LL;
    for (i = 0; i < 26; i++)
        ans -= 1LL * (1LL * cnt[i] * (cnt[i] - 1)) / 2LL;

    cout << ans + 1;


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
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;}
 
int main(){
  string s,t;
  cin >> s >> t;
  int cnt = 0;
  REP(i, 3){
    if(s[i] == t[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
from sys import stdin
import fractions

class SegmentTree():

    def __init__(self, n):
        self.n = 1
        # nに最も近い2のべき乗を計算
        while self.n < n:
            self.n *= 2

        self.N0 = 2**(n-1).bit_length()

        # ノードの個数は2n-1個
        # 初期化はモノイドで
        self.dat = [0] * (self.n * 2 - 1)
        
    def update(self, i, x):
        i = i + self.n - 1
        self.dat[i] = x

        while(i > 0):
            i = (i-1) // 2
            self.dat[i] = fractions.gcd(self.dat[i * 2 + 1], self.dat[i * 2 + 2])

    def query(self, l, r):
        L = l + self.N0
        R = r + self.N0
        ret = 0
        
        while L < R:
            if R & 1:
                R -= 1
                ret = fractions.gcd(ret, self.dat[R-1])
                
            if L & 1:
                ret = fractions.gcd(ret, self.dat[L-1])
                L += 1
                
            L >>= 1; R >>= 1
        return ret


if __name__ == "__main__":
    N = int(stdin.readline().rstrip())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    st = SegmentTree(N)
    for i in range(N):
        st.update(i, A[i])
    
    ans = - (10 ** 10)
    for i in range(N):
        if i == 0:
            leftv = 0
        else:
            leftv = st.query(0, i)
        
        if i == N-1:
            rightv = 0
        else:
            rightv = st.query(i+1, N)

        # for Debug    
        #print("**{0}** | {1} {2}".format(i, leftv, rightv))
        ans = max(ans, fractions.gcd(leftv, rightv)) 

    # for Debug
    #print(st.dat)

    print(ans)

Measured memory_bytes: 91044
#include <stdio.h>

const int N = 123;

int a[N];

int main() {
  int n;
  scanf("%d", &n);
  n++;
  a[0] = 0;
  int sum = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d", a + i);
    sum += a[i];
  }
  int ans = 0;
  while (sum > 0) {
    for (int i = 1; i < n; i++) {
      if (a[i - 1] == 0 && a[i] > 0) {
        ans++;
      }
    }
    for (int i = 1; i < n; i++) {
      if (a[i] > 0) {
        a[i]--;
        sum--;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int d, g;cin >> d >> g;
  int p[d+10], c[d+10];
  rep(i,d)cin >> p[i] >> c[i];

  ll ans = 1e9;
  for(int mask = 0; mask < (1 << d); ++mask){
      ll s = 0, num = 0, rest_max = -1;
      for(int i = 0; i < d; ++i){
          if(1&mask >> i){
              s += 100 * (i+1) * p[i] + c[i];
              num += p[i];
          }else{
              rest_max = i;
          }
      }
      if(s < g){
          int s1 = 100 * (rest_max + 1);
          int need = (g - s + s1 - 99) / s1;

          if(need >= p[rest_max])continue;

          num += need;
      }
      ans = min(ans, num);
  }
  cout << ans << endl;

  return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, int A, vi& x) {
    // すべて1-50
    int NN = N*N;
    ll cnt[51][2501]; //50^3
    mset(cnt, 0);
    cnt[0][0] = 1;

    rep(i,N){ // 50
        int xi = x[i];
        // x[i]を使う、使わない
        for (int m=i; m>=0; --m) {
            for (int k=50*m; k>=0; --k) {
                if (cnt[m][k] == 0) continue;
                if (IN(m+1,0,50) && IN(k+xi,0,2500)) {
                    cnt[m+1][k+xi] += cnt[m][k];
                }
            }
        }
    }
    ll ans = 0;
    for (int m=1; m<=N; ++m){
        // cerr << m << " " << cnt[m] << endl;
        ans += cnt[m][m*A];
    }
    return ans;
}

int main() {
    vi x;
    loadvec(x,2);
    int N=x[0],A=x[1];
    loadvec(x,N);
    cout << solve(N,A,x) << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int N;
string S[10000];

int main() {
	cin >> N;
	int cnt = 0;
	int acnt = 0, bcnt = 0;
	int cnt_ = 0;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		for (int j = 0; j < S[i].size() - 1; j++) {
			if (S[i][j] == 'A' && S[i][j + 1] == 'B')cnt++;
		}
		if (S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A') {
			cnt_++;
			continue;
		}
		if (S[i][0] == 'B')bcnt++;
		else if (S[i][S[i].size() - 1] == 'A')acnt++;
	}
	ll ans = 0;
	ans = cnt;
	ans += min(acnt, bcnt);
	ans += cnt_;
	if (acnt == bcnt && acnt == 0 && cnt_ > 0)ans--;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define N 100010
int n,sum,a[N];
int Abs(int x) {return x>0?x:-x;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		sum+=Abs(a[i]-a[i-1]);
	}
	sum+=Abs(a[n]);
	for(int i=1;i<=n;++i) 
	{
		sum-=Abs(a[i]-a[i-1]);
		sum-=Abs(a[i]-a[i+1]);
		sum+=Abs(a[i+1]-a[i-1]);
		printf("%d\n",sum);
		sum+=Abs(a[i]-a[i-1]);
		sum+=Abs(a[i]-a[i+1]);
		sum-=Abs(a[i+1]-a[i-1]);
	}
	return 0;
}


Measured memory_bytes: 1664
def main():
    N = int(input())
    ans = []

    for i in range(1, N+1):
        s, p = [ele for ele in input().split()]
        ans.append([int(p), s, i])

    ans.sort(reverse=True)  # Point
    ans.sort(key=lambda x: x[1])  # Alphabet

    for row in ans:
        print(row[2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int a[200001],dp[200001],ans[200001];
vector<int> Graph[200001];

void dfs(int now,int parent,int mx){
  int ng=0,ok=mx,mid;
  while(ok-ng>1){
    mid = ng + (ok - ng)/2;
    if(dp[mid]<a[now]) ng = mid;
    else ok = mid;
  }
  int save = dp[ok];
  dp[ok] = a[now];
  ans[now] = (ok==mx?mx++:mx-1);
  for(int child:Graph[now]) if(child != parent) dfs(child,now,mx);
  dp[ok] = save;
}

int main() {
  int n,u,v;
  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n-1;i++){
    cin >> u >> v;
    Graph[u].push_back(v);
    Graph[v].push_back(u);
  }
  for(int i=1;i<=n;i++) dp[i]=2e9;
  dfs(1,-1,1);
  for(int i=1;i<=n;i++) cout << ans[i] << endl;
}


Measured memory_bytes: 31288
#define TEST_MODE true
     
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
     
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;			\
							   c > 0 ? i < b : i > b;	\
							   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
     
#ifdef LOCAL_ENV
     
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif
     
#else
const bool test = false;
#define dump(x) 
#endif
     
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
     
//.....................
const int MAX = (int)2e5 + 5;
     
// vector<string> split(const string &str, char sep)
// {
//   vector<string> v;
//   stringstream ss(str);
//   string buffer;
//   while (getline(ss, buffer, sep))
// 	{
// 	  v.push_back(buffer);
// 	}
//   return v;
// }
     
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
     
void solve();
     
signed main()
{
  cout << fixed << setprecision(20);
  solve();
  while (true)
	{
	  char s[MAX];
	  if (scanf("%s", s) == EOF)
		break;
	  int n = strlen(s);
	  for (int i = n - 1; i > -1; i--)
		{
		  ungetc(s[i], stdin);
		}
	  solve();
	}
  return 0;
}

int r, g, b;

void solve() {
  cin >> r >> g >> b;
  if ((g * 10 + b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? printf("0") : ((flag) ? printf("-1") : printf("%lld\n", prod));
  return 0;
}

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

int main() {
  string s, p;
  cin >> s >> p;

  string s2 = s + s;

  bool flag = false;
  for (int i = 0; i < s2.size(); i++) {
    if (s2.substr(i, p.size()) == p) flag = true;
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3184
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> V1, V2;
  rep(i, n / 2) {
    int v1, v2;
    cin >> v1 >> v2;
    V1.push_back(v1);
    V2.push_back(v2);
  }

  int count = 0;

  map<int, int> M1;
  for (int num : V1) {
    if (M1.count(num) == 0) {
      M1[num] = 1;
    } else {
      M1[num]++;
    }
  }

  map<int, int> M2;
  for (int num : V2) {
    if (M2.count(num) == 0) {
      M2[num] = 1;
    } else {
      M2[num]++;
    }
  }

  int max_key_11 = 0;
  int max_value_11 = 0;
  for (auto it = M1.begin(), end = M1.end(); it != end; ++it) {
    if (max_value_11 < it->second) {
      max_key_11 = it->first;
      max_value_11 = it->second;
    }
  }
  M1.erase(max_key_11);

  int max_key_12 = 0;
  int max_value_12 = 0;
  for (auto it = M1.begin(), end = M1.end(); it != end; ++it) {
    if (max_value_12 < it->second) {
      max_key_12 = it->first;
      max_value_12 = it->second;
    }
  }

  int max_key_21 = 0;
  int max_value_21 = 0;
  for (auto it = M2.begin(), end = M2.end(); it != end; ++it) {
    if (max_value_21 < it->second) {
      max_key_21 = it->first;
      max_value_21 = it->second;
    }
  }
  M2.erase(max_key_21);

  int max_key_22 = 0;
  int max_value_22 = 0;
  for (auto it = M2.begin(), end = M2.end(); it != end; ++it) {
    if (max_value_22 < it->second) {
      max_key_22 = it->first;
      max_value_22 = it->second;
    }
  }

  // cout << max_key_11 << endl;
  // cout << max_key_12 << endl;
  // cout << max_key_21 << endl;
  // cout << max_key_22 << endl;

  int result = 0;
  if (max_key_11 == max_key_21) {
    if (max_value_11 + max_value_22 > max_value_21 + max_value_12) {
      max_value_21 = max_value_22;
    } else {
      max_value_11 = max_value_12;
    }
  }
  result += V1.size() - max_value_11;
  result += V2.size() - max_value_21;

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 5372
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut s = Vec::new();
    for _ in 0..h {
        s.push(vecchar());
    }

    let mut dp = Vec::new();
    for _ in 0..h {
        dp.push(vec![0usize; w])
    }
    if s[0][0] == '#' {
        dp[0][0] = 1;
    }
    for x in 1..w {
        dp[0][x] = if (dp[0][x - 1] % 2 == 0) ^ (s[0][x] == '.') {
            dp[0][x - 1] + 1
        } else {
            dp[0][x - 1]
        }
    }
    for y in 1..h {
        dp[y][0] = if (dp[y - 1][0] % 2 == 0) ^ (s[y][0] == '.') {
            dp[y - 1][0] + 1
        } else {
            dp[y - 1][0]
        }
    }
    // dbg!(&dp);

    for y in 1..h {
        for x in 1..w {
            let yy = if (dp[y - 1][x] % 2 == 0 && s[y][x] == '#')
                || (dp[y - 1][x] % 2 == 1 && s[y][x] == '.')
            {
                dp[y - 1][x] + 1
            } else {
                dp[y - 1][x]
            };
            let xx = if (dp[y][x - 1] % 2 == 0) && (s[y][x] == '#')
                || (dp[y][x - 1] % 2 == 1) && (s[y][x] == '.')
            {
                dp[y][x - 1] + 1
            } else {
                dp[y][x - 1]
            };
            // dbg!(&y, &x, &yy, &xx);
            dp[y][x] = min(xx, yy)
        }
    }

    //   dbg!(&s);
    // dbg!(&dp);
    println!("{}", (dp[h - 1][w - 1] + 1) / 2)
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

int main()
{
    int num, rad = 90, keep;
    double x = 0, y = 0;
    
    while(1){
        scanf("%d,%d", &num, &keep);
        if (num == 0 && keep == 0) break;
        
        x += cos(rad * M_PI / 180) * num;
        y += sin(rad * M_PI / 180) * num;
        
        rad -= keep;
    }
    printf("%d\n%d\n", (int)x, (int)y);
    
    return 0;
}

Measured memory_bytes: 604
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=srin(3)
  out(a[a.length-1]==b[0]&&b[b.length-1]==c[0]?'YES':'NO')
}
main()


Measured memory_bytes: 7372
#!/usr/bin/perl
use POSIX qw(floor);

my ($a,$b,$c,$d) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $mx = -( 10 ** 18 - 10);

foreach my $x ( ($a,0,$b) ){
  next unless ($a <= $x and $x <= $b);
  foreach my $y ( ($c,0,$d) ){
    next unless ($c <= $y and $y <= $d);
    my $v = $x * $y ;
    $mx = $v if $v > $mx;
  }
}
print "$mx\n";



Measured memory_bytes: 7028
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
const ll INF=1e18;
using namespace std;
ll n,k,p[5005],c[5005];
bool used[5005];
vector<ll> sum;
ll ans=-INF;
void dfs(int i,ll cnt)
{
	if (used[i]==1)
		return;
	used[i]=1;
	cnt+=c[p[i]];
	sum.pb(cnt);
	dfs(p[i],cnt);
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		--p[i]; 
	}
	for(int i=0;i<n;i++)
		cin>>c[i];
	for(int i=0;i<n;i++)
	{
		memset(used,0,sizeof(used));
		sum.clear();
		dfs(i,0);
		int sz=sum.size();
		if (sum[sz-1]>0&&k>sz)
		{
			int q=k/sz;
			if (q>1)
			{
				ll mx=-INF;
				for(int j=0;j<sz;j++)
					mx=max(mx,sum[j]);
				ans=max(ans,mx+(q-1)*sum[sz-1]);
			}
			int r=k%sz;
			ll mx=-INF;
			for(int j=0;j<r;j++)
				mx=max(mx,sum[j]);
			ans=max(ans,mx+q*sum[sz-1]);
		}
		else
		{
			for(int j=0;j<k&&j<sz;j++)
				ans=max(ans,sum[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const int MAX_N = 1e5 + 5;
const lint MOD = 1e9 + 7;
lint N, A[MAX_N], fact[MAX_N], fact_inv[MAX_N];

lint mod_pow(lint x, lint n){
    lint res = 1;
    while(n){
        if(n & 1) res = res * x % MOD;
        x = x * x % MOD; n >>= 1;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N; lint t = 0;
    for(int i=0;i<=N;i++){
        int a; cin >> a;
        if(A[a]) {t = i - A[a] + 1; break;}
        A[a] = i + 1;
    }

    fact[0] = 1;
    for(int i=1;i<=N+1;i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[N+1] = mod_pow(fact[N+1], MOD-2);
    for(int i=N;0<=i;i--) fact_inv[i] = fact_inv[i+1] * (i+1) % MOD;

    for(int i=1;i<=N+1;i++){
        lint ans = fact[N+1] * fact_inv[i] % MOD * fact_inv[N-i+1] % MOD;
        if(i<=N+1-t){
            lint diff = fact[N-t] * fact_inv[i-1] % MOD * fact_inv[N-t-i+1] % MOD;
            ans = (ans-diff+MOD) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  int count=0;
  if (s[0]=='1') ++count;
  if (s[1]=='1') ++count;
  if (s[2]=='1') ++count;
  cout<<count<<endl;
}

Measured memory_bytes: 256
while True:
    a,b = (int(x) for x in input().split())
    if a == 0 and b == 0:
        break
    for i in range(a):
        for j in range(b):
            if i % 2 == 0:
                if j % 2 == 0:
                    print("#",end='')
                elif j % 2 == 1:
                    print(".",end='')
            else:
                if j % 2 == 0:
                    print(".",end='')
                elif j % 2 == 1:
                    print("#",end='')
        print()
    print()


Measured memory_bytes: 7012
#include <cstdio>

using namespace std;

int main() {
	char str[256];
	
	scanf("%s", str);
	
	for (int i = 0; i < 4; i++){
		printf("%c", str[i]);
	}
	printf(" ");
	for (int i = 4; i < 12; i++){
		printf("%c", str[i]);
	}
	puts("");
	
	return (0);
}

Measured memory_bytes: 128
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    VI a(n);
    rep(i, n){
        cin >> a[i];
    }
    bool flag = true;
    int ans = 0;
    rep(i, n-1){
        if(a[i] == a[i+1] && flag){
            ans++;
            flag = false;
            continue;
        }
        flag = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Measured memory_bytes: 20052
a1=input()
res=[i for i in a1.split()]
K,X=[float(res[i]) for i in (0,1)]
k,x=K.is_integer(),X.is_integer()
if k and x == True and 1<=K<=100 and 0<=X<=100:
    K,X=int(K),int(X)
    a=X-K+1
    b=X+K-1
    if -1000000<=(a and b)<=1000000:
        for i in range(a,b+1):
            print(i,end=' ')

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

int main()
{
  int n,m,x,sum=0;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
    cin>>x;
    sum+=x;
  }

  
  if(sum>n)cout<<-1;
  else cout<<n-sum;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define sz(a) (int)a.size()
#define int long long

using namespace std;

int a[5010];

vector <pair <int, int>> v;

int kok[5010];
int pref[5010];

vector <int> sok;

int ans = 1e18;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v.pb({a[i], i});
    }
    sort(v.begin(), v.end());
    for (int i = 0; i <= n - q; i++) {
        int l = i, r = i + q;
        while (l > 0 && v[l].first == v[l - 1].first)
            --l;
        while (r < n && v[r - 1].first == v[r].first)
            ++r;
        sok.clear();
        for (int j = 0; j < l; j++)
            sok.pb(v[j].second);
        sort(sok.begin(), sok.end());
        for (int j = 0; j <= n; j++) {
            kok[j] = 0;
            pref[j] = 0;
        }
        for (int j = l; j < r; j++) {
            kok[v[j].second] = 1;
        }
        for (int j = 1; j <= n; j++) {
            pref[j] = pref[j - 1] + kok[j - 1];
        }
        int nch = 0;
        int tot = 0;
        for (int j = 0; j < sz(sok); j++) {
            if (pref[sok[j]] - pref[nch] > 0 && sok[j] - nch - pref[sok[j]] + pref[nch] < k - 1) {
                tot += min(((k - 1) - (sok[j] - nch - pref[sok[j]] + pref[nch])), pref[sok[j]] - pref[nch]);
            }
            nch = sok[j] + 1;
        }
        if (pref[n] - pref[nch] > 0 && n - nch - pref[n] + pref[nch] < k - 1) {
            tot += min((k - 1) - (n - nch - pref[n] + pref[nch]), pref[n] - pref[nch]);
        }
        if (r - l - tot >= q)
            ans = min(ans, v[r - 1].first - v[l].first);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
puls=[]
minu=[]
for i in range(n):
    puls.append(a[i]+1)
    minu.append(a[i]-1)
a.extend(puls)
a.extend(minu)
import collections
data=collections.Counter(a)
data=sorted(data.items(),key=lambda x:x[1],reverse=True)
print(data[0][1])


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

using namespace std;
using ll = long long;

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

ll ts = 1000000007;

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

  ll a, b, k;
  cin >> a >> b >> k;

  if (k <= a) {
    cout << a - k << ' ' << b << endl;
  } else if (k <= a + b) {
    cout << 0 << ' ' << b - (k - a) << endl;
  } else {
    cout << 0 << ' ' << 0 << endl;
  }
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


#define all(x) x.begin(),x.end()
#define ip vector<int,pair<int,int>>
#define vii vector<pair<int,int>>
#define vi  vector<int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define tt int t; cin>>t;while(t--)
#define FOR(i,j,k) for(int i=0;i<j;i++)
#define endl "\n"
#define pb push_back
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);






signed main(){
	
	int a;
	cin>>a;
	int b=a*a;
	cout<<a+b+b*a<<endl;

}


Measured memory_bytes: 3636
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Double[] v = new Double[n];
        for(int i =0;i<n;i++){
            v[i] = sc.nextDouble();
        }
        Arrays.sort(v);
        for(int i = 0;i<n-1;i++){
            v[i+1] = (v[i]+v[i+1])/2;
        }
        System.out.println(v[n-1]);
    }
}

Measured memory_bytes: 25172
#include <cstdio>

const int MOD = 998244353;
const int INV2 = (MOD + 1) >> 1;

int add(int x, int y) {return (x + y >= MOD ? x + y - MOD : x + y);}
int sub(int x, int y) {return (x - y < 0 ? x - y + MOD : x - y);}
int mul(int x, int y) {return 1LL*x*y%MOD;}

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=mul(b,b))
		if( i & 1 ) ret = mul(ret,b);
	return ret;
}

struct node{
	int k, b;
	node() : k(0), b(0) {}
	node(int _k, int _b) : k(_k), b(_b) {}
	int get(int x) {return add(mul(k, x), b);}
	friend node operator + (node a, node b) {
		return node(add(a.k, b.k), add(a.b, b.b));
	}
	friend node operator - (node a, node b) {
		return node(sub(a.k, b.k), sub(a.b, b.b));
	}
	friend node operator * (node a, int k) {
		return node(mul(a.k, k), mul(a.b, k));
	}
	friend node operator / (node a, int k) {
		return a * pow_mod(k, MOD - 2);
	}
};

void fwt(node *A, int m, int type) {
	int n = (1 << m), f = (type == 1 ? 1 : INV2);
	for(int i=1;i<=m;i++) {
		int s = (1 << i), t = (s >> 1);
		for(int j=0;j<n;j+=s)
			for(int k=0;k<t;k++) {
				node x = A[j+k], y = A[j+k+t];
				A[j+k] = (x + y)*f, A[j+k+t] = (x - y)*f;
			}
	}
}

node A[1<<18], B[1<<18], C[1<<18], f[1<<18];

int main() {
	int N, M, S = 0; scanf("%d", &N), M = (1 << N);
	for(int i=0;i<M;i++) scanf("%d", &A[i].b), S = add(S, A[i].b);
	S = pow_mod(S, MOD - 2);
	for(int i=0;i<M;i++) A[i].b = sub(i == 0 ? 1 : 0, mul(A[i].b, S));
	for(int i=0;i<M;i++) B[i].b = 1;
	C[0].b = MOD - 1;
	fwt(A, N, 1), fwt(B, N, 1), fwt(C, N, 1);
	int tmp = mul(B[0].b, pow_mod(C[0].b, MOD-2));
	for(int i=1;i<M;i++)
		f[i] = (B[i] - C[i]*tmp) / A[i].b;
	f[0].k = 1; fwt(f, N, -1);
	int x = sub(0, mul(pow_mod(f[0].k, MOD-2), f[0].b));
	for(int i=0;i<M;i++) printf("%d\n", f[i].get(x));
}

Measured memory_bytes: 10880
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
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 exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n, a, b, c;
vl v;
vl L;
ll ans = INF;

void check(vl &v) {
    ll now = 0;
    ll lA = 0, lB = 0, lC = 0;
    rep(i, n) {
        if(v[i] == 1) {
            if(lA > 0) {
                now += 10;
            }
            lA += L[i];
        }
        else if(v[i] == 2) {
            if(lB > 0) {
                now += 10;
            }
            lB += L[i];
        }
        else if(v[i] == 3) {
            if(lC > 0) {
                now += 10;
            }
            lC += L[i];
        }
    }
    if(lA == 0 || lB == 0 || lC == 0) {
        return;
    }
    now += abs(lA - a) + abs(lB - b) + abs(lC - c);
    chmin(ans, now);
}

void dfs(ll depth) {
    if(depth == n) {
        check(v);
        return;
    }
    rep(i, 4) {
        v[depth] = i;
        dfs(depth+1);
    }
}
 
int main() {
    
    cin >> n >> a >> b >> c;

    L.resize(n);
    rep(i, n) {
        cin >> L[i];
    } 

    v.resize(n);
    dfs(0);

    out(ans);
    re0;
}

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() {
    int N; cin >> N;
    vector<int> x(N), y(N), perm(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
        perm[i] = i;
    }
    
    double ans = 0;
    int count = 0;
    do {
        count++;
        int xx = 0, yy = 0;
        for (int i = 1; i < N; i++)
            ans += hypot(x[perm[i]] - x[perm[i - 1]], y[perm[i]] - y[perm[i - 1]]);
    } while (next_permutation(perm.begin(), perm.end()));

    printf("%.12f\n", ans / count);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27188
#include <stdio.h>

int main(void){
  int N,a;
  int max,min;

  scanf("%d",&N);
  scanf("%d",&a);
  max = min = a;
  for(int i = 1;i < N;i++){
    scanf("%d",&a);
    if(max < a) max = a;
    if(min > a) min = a;
  }

  printf("%d\n",max-min);


  return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        char c = in.next().charAt(0);
        if (c >= 'A' && c <= 'Z') {
            out.println('A');
        } else {
            out.println('a');
        }
    }

    final int mod = 998244353;

    int mul(int x, int y) {
        return (int) ((x * 1L * y) % mod);
    }

    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 32680