akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int X;
int A, B, C, D;

int main(){
    
    cin>>X;
    
    A = X/1000;
    B = (X/100)%10;
    C = (X/10)%10;
    D = X%10;
    
    if( A+B+C+D == 7 ){printf("%d+%d+%d+%d=7", A, B, C, D);}
    else if( A+B+C-D == 7 ){printf("%d+%d+%d-%d=7", A, B, C, D);}
    else if( A+B-C+D == 7 ){printf("%d+%d-%d+%d=7", A, B, C, D);}
    else if( A+B-C-D == 7 ){printf("%d+%d-%d-%d=7", A, B, C, D);}
    else if( A-B+C+D == 7 ){printf("%d-%d+%d+%d=7", A, B, C, D);}
    else if( A-B+C-D == 7 ){printf("%d-%d+%d-%d=7", A, B, C, D);}
    else if( A-B-C+D == 7 ){printf("%d-%d-%d+%d=7", A, B, C, D);}
    else if( A-B-C-D == 7 ){printf("%d-%d-%d-%d=7", A, B, C, D);}
    
    puts("");
    
    return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N,A,B,x,y;
  
  cin >> N >> A >> B;
  
  y = N * A;
  
  if (y > B) {
    x = B;
  }
  else {
    x = y;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h,w,name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end()) //昇順
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
ll gcd(ll a, ll b);//最大公約数
ll lcm(ll a, ll b);//最小公倍数
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
    int K;
    cin>>K;
    string k;
    k ="ACL";
    rep(0,i,K-1){
        k += "ACL";

    }
    cout<<k<<endl;
  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//最大公約数
ll gcd(ll a, ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

//最小公倍数
ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}

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

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a;
	for (int i = 0; i < n; ++i)
	{
		long long int x;
		cin >> x;
		a.push_back(x);
	}
	a.push_back(a[0] + k);
	
	int l = 0;
	for (int i = 0; i < n; ++i)
	{
		l = max(l, abs(a[i+1] - a[i]));
	}
	
	cout << k - l << endl;
	
	return 0;
}


Measured memory_bytes: 1400
//#######################     Starting_with_name_of_ALLAH     ##############################
//#######################     Bismillahir_rahmair_raheem      ##############################
 
//                      coded in 2020
//
//                   Shamim Ahammad Rasel
//                  Begum Rokeya University
//                 shamim.brur.cse@gmail.com
//                    I love your thinking 


#include<bits/stdc++.h>
#define tc()         int tc;cin>>tc;while(tc--)

using namespace std;

void shomoy();

int main(){
    int i,j,k,x,y,a,b,n,total,count,sum,temp,len;

    cin>>n;
    cout<<!n<<endl;





shomoy();

return 0;
}






















void shomoy(){
    #ifndef ONLINE_JUDGE
        cerr<<"---------END OF OUTPUT---------------\n";
        cerr<<"---------Time  :"<<1.0*clock()/CLOCKS_PER_SEC<<"s------------\n";
        
    #endif
 
}


Measured memory_bytes: 3632
#include <cstdio>

int main()
{
	char s[200001], t[200001];
	scanf("%s%s", s, t);
	int ans = 0;
	for (int i = 0; s[i]; ++i)
	{
		if (s[i] != t[i])
		{
			ans += 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2120
n = int(input())
p = list(map(int, input().split()))

swap = 0
flag = 0
while True:
    flag = 0
    for i in range(n-1):
        if p[i] == i+1:
            p[i], p[i+1] = p[i+1], p[i]
            flag = 1
            swap += 1
    if p[n-1] == n:
            p[n-1], p[n-2] = p[n-2], p[n-1]
            flag = 1
            swap += 1

    if flag == 0:
        print(swap)
        break

Measured memory_bytes: 13880
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

# mark sheep with 0, wolf with 1
# x -> 1, o -> 0
# si = ai-1^ai^ai+1

def cvt(c):
    if c == 'o':
        return 0
    else:
        return 1

def mxor(x1,x2,x3):
    return (x1+x2+x3) % 2

def test():
    a[n] = a[0]
    for i in range(2,n):
        a[i] = mxor(a[i-2],s[i-1],a[i-1])
    if a[0] != mxor(a[n-1],s[0],a[1]):
        return False
    if a[n-1] != mxor(a[n-2],s[n-1],a[n]):
        return False
    return True

def no_answer():
    for a[0] in range(0,2):
        for a[1] in range(0,2):
            if test():
                st = ""
                for x in range(0,n):
                    if a[x] == 0: st = st + 'S'
                    else: st = st + 'W'
                print(st)
                return False
    return True

n = int(input())
s = list(map(cvt,str(input())))
a = [0 for i in range(0,n+1)]
if no_answer():
    print(-1)

# [1, 0, 1, 1, 0, 1, 0, 1, 1, 0]


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    cout << N * 800 - N / 15 * 200 << endl;
    return 0;
}


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

using namespace std;
bool les(long double a, long double b, long double c) {
  //cout << ((c - a - b) / 2 - sqrt(a * b)) << endl;
  return (c - a - b) / 2 - sqrt(a * b) > 1e-18;
}
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c - a - b <= 0) {
    //cout << c-a-b << endl;
    //cout << "??" << endl;
    cout << "No\n";
    return 0;
  }
  cout << (les(a, b, c) ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

#include <utility>

namespace n91 {

template <class T> constexpr T gcd(T m, T n) noexcept {
  while (n != static_cast<T>(0)) {
    m %= n;
    std::swap(m, n);
  }
  return m;
}

template <class T> constexpr T lcm(const T &m, const T &n) noexcept {
  return m / gcd(m, n) * n;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>

namespace n91 {

bool solve() {
  usize n;
  std::cin >> n;
  struct task {
    u32 a, b;
  };
  std::vector<task> tasks(n);
  for (auto &t : tasks) {
    std::cin >> t.a >> t.b;
  }
  std::sort(tasks.begin(), tasks.end(),
            [](const auto &l, const auto &r) { return l.b < r.b; });
  u32 now = static_cast<u32>(0);
  for (const auto &t : tasks) {
    now += t.a;
    if (now > t.b) {
      return false;
    }
  }
  return true;
}

void main_() { std::cout << (solve() ? "Yes" : "No") << std::endl; }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

int main() {
  int n;
  
  cin >> n;
  
  vector<int>a(n);
  
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  int result = -1;
  int num = 1;
  
  for (int i = 0; i < n; i++) {
    if (a.at(i) == num) {
      num++;
    }
  }
  if (num > 1) {
    result = n - (num - 1);
  }
  cout << result << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

xor = 0
ans = 0

right = 0

for l in range(n):
    if l>0:
        xor -= a[l-1]
    for r in range(right,n):
        if xor^a[r] == xor+a[r]:
            if r==n-1:
                ans += r-l+1
                right = max(r,l+1)
            else:
                xor += a[r]
        else:
            ans += r-l
            right = max(r,l+1)
            break

print(ans)

Measured memory_bytes: 77900
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(int i=s;i<=n;i++)
#define ford(j,s,n) for(int i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
	cin>>a>>b;
    if((b.size()==a.size()+1)&&(b.substr(0,a.size())==a))
      cout<<"Yes";
   else cout<<"No";
    return 0;
}


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


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep3(i, n, m) for (int i = n; i <= m; i++)

using ll = long long;

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> ;
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //126-d

int main() {
  ll N,M,count=0;
  cin >> N >> M;
  vector<vector<ll>> have(N);
  rep(i,M){
    int x,y,z;
    cin >> x >> y >> z;
    x--;
    y--;
    have.at(x).push_back(y);
    have.at(y).push_back(x);
  }

  vector<bool> find(N,false);
  rep(i,N){
    if(find.at(i)) continue;
    count++;
    find.at(i)=true;

    queue<int> que;
    que.push(i);

    while(!que.empty()){
      int a = que.front();
      que.pop();
      rep(l,have.at(a).size()){
        int b = have.at(a).at(l);
        if(find.at(b)) continue;
        find.at(b)=true;
        que.push(b);
      }
    }
  }
  cout << count << endl;

}

Measured memory_bytes: 6900
#include<iostream>
using namespace std;
int main ()
{ 
	int w[100],n,by=0,bs=0,mi=100;
	cin>>n;
	for(int t=0;t<n;t++)
	{
		cin>>w[t];
		bs=bs+w[t];
	}
	for(int t=0;t<n;t++)
	{
		bs=bs-w[t];
		by=by+w[t];
		//cout<<by<<" "<<bs<<" ";
		if(bs>by)
		{
			if(bs-by<mi)
			{ 
				mi=bs-by;
			} 
		}
		else
		{ 
			if(by-bs<mi)
			{
			mi=by-bs;
			}
		} 
	//cout<<mi<<" ";
	} 
	cout<<mi;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    long long b[a];
    b[0]=1;
    b[1]=3;
    for(int i=2;i<a;i++) b[i]=b[i-1]+b[i-2];
    cout<<b[a-1]<<endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int j = 0; j < m; j++) {
        cin >> t[j];
    }
    ll dp[n + 1][m + 1];
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i <= m; i++) {
        dp[0][i] = 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            } else {
                dp[i + 1][j + 1] =
                    (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[n][m] << endl;
}


Measured memory_bytes: 31488
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % 1000000007
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % 1000000007
            i += i & -i


n, m = list(map(int, input().split()))
sss = list(map(int, input().split()))
ttt = list(map(int, input().split()))

bit = Bit(n + 1)
bit.add(1, 1)

for t in ttt:
    for i in range(n - 1, -1, -1):
        s = sss[i]
        if s != t:
            continue
        bit.add(i + 2, bit.sum(i + 1))

print(bit.sum(n + 1))


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
  int n;
  cin >> n;
  vector<bool>b(n,true);
  vector<int>cost(n);
  vector<int>dp(n, 0);
  rep(i, 0, n){
      cin >> cost[i];
  }
  dp[0]=0;
  dp[1]=abs(cost[1]-cost[0]);
  rep(i, 2, n){
      dp[i] = min(abs(cost[i]-cost[i-2])+dp[i-2], 
      abs(cost[i]-cost[i-1])+dp[i-1]);
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::vector;
using std::cin;
using std::map;
using std::multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << ((k % 2 == 0) ? a - b : b - a) << endl;
}

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

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

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
typedef struct{
  int parent;
  int left;
  int right;
}Node;

int main(){
  int n,k,id,h,r,depth,p,i,j;
  Node *T;

  scanf("%d", &n);

  T=malloc(sizeof(Node)*n);

  for(i=0;i<n;i++){
    T[i].parent=-1;
    T[i].left=-1;
    T[i].right=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d %d", &id, &k);
    for(j=0;j<k;j++){
      scanf("%d",&h);
      T[h].parent=id;

      if(j==0) T[id].left=h;
      else if(j>0) T[r].right = h;
      r=h;
    }
  }

  for(j=0;j<n;j++){
    depth=0;
    p=T[j].parent;

    while(p!=-1){
      p=T[p].parent;
      depth++;
    }

    if(depth==0){
      printf("node %d: parent = -1, depth = 0, root, [", j);
    }
    
    else if(T[j].left == -1){
      printf("node %d: parent = %d, depth = %d, leaf, [", j, T[j].parent, depth);
    }
    else{
      printf("node %d: parent = %d, depth = %d, internal node, [", j, T[j].parent, depth);
    }
 
    p = T[j].left;
    if(p != -1) printf("%d", p);
 
    while(p != -1){
      p = T[p].right;
      if(p != -1) printf(", %d", p);
    }
    printf("]\n");
  }
 
  return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b, c;
  int x, y;
  cin >> a >> b >> c;
  x = a.size();
  y = b.size();
  if(a[x - 1] == b[0] && b[y - 1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef vector<int>::iterator vit;

ll a[100001];
ll m[100001];
map<int,int> ma;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; ll t;
	cin>>n>>t;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		ma[a[i]]++;
	}
	ll maxdiff = 0; int ans = 0; int ans2 = 0;
	for(int i = n - 1; i >= 0; i--)
	{
		m[i] = a[i];
		if(i<n-1) m[i]=max(m[i],m[i+1]);
	}
	set<int> s;
	for(int i = 0; i < n - 1; i++)
	{
		ma[a[i]]--;
		ll m2 = m[i+1];
		if(m2 - a[i] > maxdiff)
		{
			s.clear();
			maxdiff = m2 - a[i];
			ans = ma[m2];
			s.insert(m2);
			ans2 = 1;
		}
		else if(m2 - a[i] == maxdiff)
		{
			ans2++;
			if(s.find(m2)==s.end())
			{
				s.insert(m2);
				ans += ma[m2];
			}
		}
	}
	cout<<min(ans,ans2)<<'\n';
}


Measured memory_bytes: 8960
import math

N, M = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7

divisor = []
dict = {}

m = M
d = 2
while d*d <= m:
    while m % d == 0:
        m //= d
        dict[d] = dict.get(d, 0) + 1
    d += 1
if m > 1:
    dict[d] = dict.get(m, 0) + 1

C = dict.values()
ret = 1


# def combinations_count(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def combinations_count(n, r):
    a = max(r, n-r)
    b = min(r, n-r)
    r = 1
    for i in range(a+1, n+1):
        r *= i
    return r // math.factorial(b)


for c in C:
    ret *= combinations_count(c + N - 1, c)
    ret %= MOD

print(ret)


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

using namespace std;
//using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);

signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	ll ans = max({ a*c,a*d,b*c,b*d });
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
n=int(input())
action=[list(map(int,input().split())) for _ in range(n)]
# happy[i][j] i日目にaction j を選んだ場合の幸福度の最大値
happy=[[0,0,0]for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        for k in range(3):
            if j!=k:
                happy[i][j]=max(happy[i][j],happy[i-1][k]+action[i-1][j])
# print(happy)
print(max(happy[n]))


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

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

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

int main(){
  long long A,B,C,D;
  cin >> A >> B >> C >> D;
  long long LCM=lcm(C,D);

  cout << B-A+1 -(B/C-(A-1)/C)-(B/D-(A-1)/D)+(B/LCM-(A-1)/LCM);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll res = 0;
    map<int, ll> freq;
    int n, a, b, c, q;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        res += a;
        freq[a]++;
    }
    cin >> q;
    while (q--) {
        cin >> b >> c;
        res -= (b * freq[b]);
        res += (c * freq[b]);
        freq[c] += freq[b];
        freq[b] = 0;
        cout << res << '\n';
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

const int MAX_E = 400005, MAX_V = 10005;
const int INF = 1e+9+1;

typedef pair<int, int> P;

struct edge{
    int to,dist,cost;
    edge(int to,int dist, int cost):to(to),dist(dist), cost(cost){};
};


int V,E;

vector<edge> G[MAX_V];
int d[MAX_V];
int costs[MAX_V];

void dijkstra(int s){
    //O(ElogV),更新和取出的操作O(E)次,每次堆中取最小值O(logV)
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    fill(costs,costs+V, INF);
    d[s] = 0;
    costs[0] = 0;
    que.push(P(0, s));   //(d[s], s)

    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;

        if(d[v] < p.first) continue;
        //已经更新过更小的d了,出来就continue,不用小于等于号是因为可能还没用v来更新其它点,而且更新时等于也不会更新

        for(int i = 0;i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.dist){
                // 更新时把更新得到的e.to的d进堆(后续可能有更小的会进堆,在更小边出来后它才能出来,出来就continue,算法可证明不会先出来
                d[e.to] = d[v] + e.dist;
                que.push(P(d[e.to], e.to));
                costs[e.to] = e.cost;
            }else if(d[e.to] == d[v] + e.dist){
                costs[e.to] = min(costs[e.to], e.cost);
            }
        }
    }
}

void solve(){
    dijkstra(0);
    int sum = 0;
    for(int i = 0;i < V;i++){
        sum+=costs[i];
    }
    printf("%d\n", sum);
}


int main() {
    while(~scanf("%d%d", &V, &E)){
        if(V==0&&E==0) break;
        for(int i = 0;i < V;i++){
            G[i].clear();
        }
        for(int i = 0;i < E;i++){
            int s,t,d,c;
            scanf("%d%d%d%d", &s,&t,&d,&c);
            s--;t--;
            G[s].push_back(edge(t, d, c));
            G[t].push_back(edge(s, d, c));
        }
        solve();
    }
    return 0;
}



/*
3 3
1 2 1 2
2 3 2 1
3 1 3 2
5 5
1 2 2 2
2 3 1 1
1 4 1 1
4 5 1 1
5 3 1 1
5 10
1 2 32 10
1 3 43 43
1 4 12 52
1 5 84 23
2 3 58 42
2 4 86 99
2 5 57 83
3 4 11 32
3 5 75 21
4 5 23 43
5 10
1 2 1 53
1 3 1 65
1 4 1 24
1 5 1 76
2 3 1 19
2 4 1 46
2 5 1 25
3 4 1 13
3 5 1 65
4 5 1 34
0 0
 */


Measured memory_bytes: 5140
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] NQ = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            NQ[cont] = Integer.parseInt(s);
            cont++;
        }
        String S = br.readLine();
        String[] s = S.split("");
        int[] cumulative_sum = new int[NQ[0]+1];
        cont = 0;
        for (int i=1;i<NQ[0];i++){
            if (s[i].equals("C") && s[i-1].equals("A")){
                cont += 1;
            }
            cumulative_sum[i+1] = cont;
        }
        int[] lr = new int[2];
        for (int i=0;i<NQ[1];i++){
            str = br.readLine();
            cont = 0;
            for (String t:str.split(" ")){
                lr[cont] = Integer.parseInt(t);
                cont++;
            }
            System.out.println(cumulative_sum[lr[1]]-cumulative_sum[lr[0]]);
        }
    }
}

Measured memory_bytes: 49320
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010], mxx[100010];
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        bool l=1;
        mxx[0]=1;
        for(ll i=0; i<=n; ++i){
            scanf("%lld",a+i);
            // a[i]=0;
            if(i>0){
	            mxx[i]=mxx[i-1]*2-a[i];
	            // if(mxx[i]<0){
	            // 	l=0;
	            // }
	            mxx[i]=min(mxx[i], (ll)1e14);
            }
        }
        // a[n]=1;
        // ans=1;
        ll tmp;
        ll sm=0;
        for(ll i=n; i>=1; --i){
        	tmp=mxx[i-1];
        	ans+=a[i];
        	a[i]+=sm;
        	if(a[i]>mxx[i-1]*2 || mxx[i-1]<0){
        		l=0;
        		break;
        	}
        	ans+=min(tmp, a[i]);
        	sm=min(tmp, a[i]);
        }
        if(a[0]>0){
        	l=0;
        }
        if(n==0){
        	if(a[0]==1){
        		l=1;
        		ans=1;
        	}
        	else{
        		l=0;
        	}
        }
        if(l==0){
        	printf("-1\n");
        }
        else{
        	printf("%lld\n",ans);
        }
    }
  return 0;
}




Measured memory_bytes: 5296
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	}
}

Measured memory_bytes: 101092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int n,k;
    cin>>n;
    string s;
    cin>>s;
    vector<char> c(26);
    k=s.size();
    c[0]='A';
    c[1]='B';
    c[2]='C';
    c[3]='D';
    c[4]='E';
    c[5]='F';
    c[6]='G';
    c[7]='H';
    c[8]='I';
    c[9]='J';
    c[10]='K';
    c[11]='L';
    c[12]='M';
    c[13]='N';
    c[14]='O';
    c[15]='P';
    c[16]='Q';
    c[17]='R';
    c[18]='S';
    c[19]='T';
    c[20]='U';
    c[21]='V';
    c[22]='W';
    c[23]='X';
    c[24]='Y';
    c[25]='Z';
    rep(i,k){
        rep(j,26){
            if(s[i]==c[j]) {s[i]=c[(j+n)%26];
            break;
            }
        }
    }
    cout<<s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a], q[b], r[c];
    rep(i, 0, a) cin >> p[i];
    rep(i, 0, b) cin >> q[i];
    rep(i, 0, c) cin >> r[i];

    sort(p, p + a, greater<ll>());
    sort(q, q + b, greater<ll>());
    sort(r, r + c, greater<ll>());
    priority_queue<ll> pq;
    rep(i, 0, x) pq.push(p[i]);
    rep(i, 0, y) pq.push(q[i]);
    rep(i, 0, c) pq.push(r[i]);

    ll ans = 0;
    rep(i, 0, x + y) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
multiset<ll> V;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>x;
		V.insert(x);
	}
	FOR(i,M) {
		x=*V.rbegin();
		V.erase(V.find(x));
		V.insert(x/2);
	}
	ll ret=0;
	FORR(v,V) ret+=v;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

bool check(string s)
{
    if (s[0] != 'A') {
        return false;
    }

    if (count(begin(s) + 2, end(s) - 1, 'C') != 1) {
        return false;
    }

    s.erase(find(begin(s) + 2, end(s) - 1, 'C'));

    return all_of(begin(s) + 1, end(s),
        [](char ch) { return ::islower(ch); });
}

void main_()
{
    string S;
    cin >> S;
    cout << (check(S) ? "AC" : "WA") << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main() {
  string s[3];
  for (int i = 0; i < 3; i++) cin >> s[i];

  // s[i]の長さ, current
  int idx[3] = {};
  int cur = 0;

  while (idx[cur] < s[cur].length()) {
    int next = s[cur][idx[cur]] - 'a';
    idx[cur]++;
    cur = next;
  }

  cout << char('A' + cur) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
//桁
int kt(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  priority_queue<int> c;
  rep(i,a){
    int d;
    cin>>d;
    c.push(d);
  }
  rep(i,b){
    int e=c.top();
    c.pop();
     e/=2;
    c.push(e);
  }
  int f=0;
  rep(i,a){
    f+=c.top();
    c.pop();
  }
  cout<<f;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	int a[4];
	int sum=0;
	for(int i=0;i<4;i++){
		cin >> a[i];
		sum+=a[i];
	}
	cout << sum/60 << endl;
	cout << sum%60 << endl;
}


Measured memory_bytes: 3048
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}


int32_t main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();
    int d,t,s;
    cin>>d>>t>>s;
    float x = (d*1.0)/s;
    if(x<=t){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3628
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_7_A: Rooted Trees

#include <cstdio>

struct Node {
  // id is index of nodes
  int parent = -1;
  int left_child = -1;
  int right_sibling = -1;
  unsigned int depth = 0;

  const char* type() const
  {
    auto type =
      parent == -1 ? "root" :
      left_child == -1 ? "leaf" :
      "internal node";
    return type;
  }    
};

class RootedTree {
  unsigned int n_;
  Node* nodes_;

public:
  RootedTree(unsigned int n) : n_(n), nodes_(new Node[n]) { }

  ~RootedTree() { delete[] nodes_; }

  Node& operator[](unsigned int id) { return nodes_[id]; }

  void set_depth()
  {
    set_depth_internal(root(), 0u);
  }

  void print_nodes() const
  {
    for (auto i = 0u; i < n_; ++i) {
      auto node = nodes_[i];
      std::printf("node %u: parent = %d, depth = %u, ", i, node.parent, node.depth);
      std::printf("%s, [", node.type());
      int next_c = node.left_child;
      auto sep = "";
      while (next_c != -1) {
        std::printf("%s%d", sep, next_c);
        sep = ", ";
        next_c = nodes_[next_c].right_sibling;
      }
      std::printf("]\n");
    }
  }

private:
  unsigned int root() const
  {
    for (auto i = 0u; i < n_; ++i) {
      if (nodes_[i].parent == -1) {
        return i;
      }
    }
    return -1;
  }

  void set_depth_internal(unsigned int i, unsigned int depth)
  {
    nodes_[i].depth = depth;
    if (nodes_[i].right_sibling != -1) {
      set_depth_internal(nodes_[i].right_sibling, depth);
    }
    if (nodes_[i].left_child != -1) {
      set_depth_internal(nodes_[i].left_child, depth+1);
    }
  }
};

int main()
{
  unsigned int n;
  std::scanf("%u", &n);
  RootedTree tree(n);

  for (auto i = 0u; i < n; ++i) {
    unsigned int id, k, c;
    std::scanf("%u %u", &id, &k);

    int* next_p = &tree[id].left_child;
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u", &c);
      tree[c].parent = id;
      *next_p = c;
      next_p = &tree[c].right_sibling;
    }
  }

  tree.set_depth();
  tree.print_nodes();
}

// eof

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a.at(i);
    
    int pos = 0;
    int diff = 0;
    int count = 1;
    for (int i = 1; i < N; i++) {
        diff = a.at(i) - a.at(i - 1);
        if (pos == 0) {
            if (diff > 0) pos = 1;
            if (diff < 0) pos = -1;
        } else if (pos == 1) {
            if (diff < 0) {
                pos = 0;
                count++;
            }
        } else {
            if (diff > 0) {
                pos = 0;
                count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
  char palindrome[100];
  int i,length,hug=0;
  scanf("%s",palindrome);
  length=strlen(palindrome);
  for(i=0;i<length;i++)
  {
    if(palindrome[i]==palindrome[length-1])
    {
      length--;
      continue;
    }
    else
    {
      palindrome[i]=palindrome[length-1];
      hug++;
      length--;
  	}
  }
  printf("%d",hug);
  return 0;
}

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

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

ll gcd(ll a,ll b){
    ll res;
    if(a==0||b==0){
        cout<<"Error"<<endl;
        return 0;
    }
    while((res=a%b)!=0){    
        a=b;
        b=res;
    }
    return b;
}

int main(){
    ll N,X;
    cin>>N>>X;
    vector<ll> v(N+1);
    v[0]=X;
    for(ll i=1;i<N+1;i++){
        cin>>v[i];
    }
    
    sort(v.begin(),v.end());
    
    ll ans=v[1]-v[0];
    for(ll i=1;i<N;i++){
        ans=__gcd(ans,v[i+1]-v[i]);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll A,B;
ll gcd(ll a,ll b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int main(){
    cin >> A >> B;
    ll u = gcd(A,B);
    ll j = 0;
    for(ll i=2;i*i<=u;i++){
        if(u%i==0){
            j++;
            while(u%i==0){
                u/=i;
            }
        }
    }
    if(u!=1){
        j++;
    }
    cout << j+1 << endl;
 
    return 0;
 
}

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

int main() {
	int D, N;
	cin >> D >> N;
	vector<int> days(D);
	for_each(days.begin(), days.end(), [](int& x) {cin >> x; });
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++)cin >> A[i] >> B[i] >> C[i];

	vector<vector<int> > dp(D, vector<int>(N, -1));
	for (int i = 0; i < N; i++) {
		if (A[i] <= days[1] && days[1] <= B[i]) {
			int tmp = 0;
			for (int j = 0; j < N; j++) {
				if (A[j] <= days[0] && days[0] <= B[j]) {
					if (tmp < abs(C[j] - C[i]))tmp = abs(C[j] - C[i]);
				}
			}
			dp[1][i] = tmp;
		}
	}

	for (int i = 1; i < D - 1; i++) {
		for (int j = 0; j < N; j++) {
			if (dp[i][j] == -1)continue;
			for (int k = 0; k < N; k++) {
				if (A[k] <= days[i + 1] && days[i + 1] <= B[k]) {
					if (dp[i + 1][k] < dp[i][j] + abs(C[j] - C[k]))dp[i + 1][k] = dp[i][j] + abs(C[j] - C[k]);
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (ans < dp[D - 1][i]) ans = dp[D - 1][i];
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,d,r;
    double f;
    cin >>a>>b;
    d=a/b;
    r=a%b;
    f=double(a)/b;
    printf("%d ",d);
    printf("%d ",r);
    printf("%lf\n",f);
}


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

int main()
{
    int64_t n;
    std::cin >> n;
    std::unordered_map<int64_t, int64_t> numMap;
    int64_t x = n;
    for (int64_t i = 2; i * i <= x; ++i)
    {
        while(n % i == 0)
        {
            numMap[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        numMap[n]++;
    }
    int64_t ans = 0;
    for(auto num : numMap)
    {
        int64_t tmp = num.second;
        int64_t sub = 1;
        while (tmp - sub >= 0)
        {
            ans++;
            tmp -= sub;
            sub++;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diverta2019_D
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            long ans = 0;

            var factors = divisor(n);

            foreach(var tmp in factors)
            {
                if ((n - tmp) % tmp == 0)
                {
                    long x = (n - tmp) / tmp;
                    if (x != 0 && n % x == n / x) { ans += x; }
                }
            }

            Console.WriteLine("{0}", ans);
        }

        public static IEnumerable<long> divisor(long n)
        {
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    yield return i;
                    if (i != 1 && i * i != n) yield return (n / i);
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#define INF 10e10

using namespace std;

//  #define y cout << "yes"<< endl
  #define Y cout << "YES" << endl
  #define y cout << "Yes" << endl
//  #define n cout << "no"<< endl
  #define N cout << "NO" << endl
  #define n cout << "No" << endl
  #define pu(q) cout << q ;
  #define put(q) cout << q << " ";
  #define puts(q) cout << q << endl;
  
  
	long a,b,c,d,e,f,g,h,ans,res;
//	char a,b,c,d,e,f,g,h,ans,res;
//	string a,b,c,d,e,f,g,h,ans,res;
//	double a,b,c,d,e,f,g,h,ans,res;
	
void take(int x);
  
int main(void){
	take(2);//数
	if(a==0 || b==0){puts("IMPOSSIBLE");}
	
	else if((a%2&&b%2) || (!(a%2)&&!(b%2))){puts((a+b)/2);}
	else {puts("IMPOSSIBLE");}
	/*
	if(a==b){
		puts(0);
		
	//	y;	//Yes
	//	Y;	//YES
	//	n;	//No
	//	N;	//NO
	}
	if(a>b)swap(a,b);//a<b
	else if((a+b)/2){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	else if(){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	else if(){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	
	else{
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}*/
//	cout << ans << endl;
	
	return 0;
}
void take(int x){
	if(x==1)
		cin >> a;
	else if(x==2)
		cin >> a >> b;
	else if(x==3)
		cin >> a >> b >> c;
	else if(x==4)
		cin >> a >> b >> c >> d;
	else if(x==5)
		cin >> a >> b >> c >> d >> e;
	else if(x==6)
		cin >> a >> b >> c >> d >> e >> f;
	else if(x==7)
		cin >> a >> b >> c >> d >> e >> f >> g;
	else if(x==8)
		cin >> a >> b >> c >> d >> e >> f >> g >> h;
	return ;
}


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

int a, X, N, res, mindif;
int arr[105];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin >> X >> N;
    res = 200;
    mindif = 200;
    if(N == 0) cout << X;
    else {
        for(int i = 0; i < N; i++) {
            cin >> a;
            arr[a]++;
        }
        for(int i = 0; i <= 101; i++) {
            if(arr[i] == 0) {
                if(abs(X - i) < mindif) {
                    res = i;
                    mindif = abs(X - i);
                }
                else if(abs(X - i) == mindif) {
                    res = min(res, i);
                }
            }
        }
        cout << res;
    }
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    A = Scanner.int()
    print(A + A ** 2 + A ** 3)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10380