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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ull k;
  cin >> k;
  bool is_ok {false};
  ull c {7%k};
  ull tmp {7%k};
  ull ans {1};
  for (ans = 1;ans <= k;++ans) {
    if (c%k == 0) {
      is_ok = true;
      break;
    }
    tmp = (tmp*10)%k;
    c += tmp;
  }
  if (is_ok == true) {
    cout << ans << '\n';
  } else {
    cout << "-1\n";
  }
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int N,K;
 long long int sum=1;

 cin>>N>>K;
 cout<<N-K+1<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    char F,G,H,I;
  cin>>F>>G>>H>>I;
  int A='0'+F-96;
  int B='0'+G-96;
  int C='0'+H-96;
  int D='0'+I-96;
    vector<char>E(2);
    E={'+','-'};
    rep(i,2){
        rep(j,2){
            rep(k,2){
                int cnt=A;
                if(E[i]=='+'){
                    cnt+=B;
                }
                else{
                    cnt-=B;
                }
                if(E[j]=='+'){
                    cnt+=C;
                }
                else{
                    cnt-=C;
                }
                if(E[k]=='+'){
                    cnt+=D;
                }
                else{
                    cnt-=D;
                }
                if(cnt==7){
                    cout<<A<<E[i]<<B<<E[j]<<C<<E[k]<<D<<"="<<7<<endl;
                	i+=100;
                  j+=100;
                  k+=100;
                  break;
                }
            }
        }
    }
}










Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

using ll = long long;
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}

int arr[100][100];
signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    fac[0]=1;
    FOR(i,1,MX) fac[i]=fac[i-1]*i;
    sort(a.begin(), a.end());
    mint ma=0;
    FOR(i,k-1,n) {
        ma += (mint)(a[i])*comp(i,k-1);
    }

    sort(a.begin(),a.end(),greater<int>());
    mint mi=0;
    FOR(i,k-1,n) {
        mi += (mint)(a[i])*comp(i,k-1);
    }
    cout << (ma-mi) << endl;

    return 0;
}


Measured memory_bytes: 19360
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
a b c 10^9
 */
ll a,b,c;

int main(){
  cin>>a>>b>>c;
  if(c <= a+b){
    cout<< c+b;
  } else {
    cout<< a+2*b +1;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long ll;

int main() {
	ll a, b;
	cin >> a >> b;
	if (a > 0)
		cout << "Positive" << endl;
	else if (a == 0 || b == 0 || (a < 0 && b > 0)) {
		cout << "Zero" << endl;
	}
	else {
		ll tmp = abs(b) - abs(a);
		if (tmp & 1) {
			cout << "Positive" << endl;
		}
		else {
			cout << "Negative" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;
int main()
{
  int n;
  cin >> n;
  vector<ll> a(3*n);
  for(int i=0;i<3*n;i++) cin >> a[i];

  priority_queue<ll,vector<ll>,greater<ll>> q_fr;

  ll q_fr_sum = 0;
  for(int i=0;i<n;i++){
    q_fr.push(a[i]);
    q_fr_sum += a[i];
  }

  vector<ll> fr_sum(n+1);
  fr_sum[0] = q_fr_sum;

  for(int k = n;k<2*n;k++){
    if(q_fr.top() < a[k]){
      q_fr_sum -= q_fr.top();
      q_fr.pop();
      q_fr_sum += a[k];
      q_fr.push(a[k]);
    }

    fr_sum[k-n+1] = q_fr_sum;
  }

  priority_queue<ll,vector<ll>,less<ll>> q_bc;
  ll q_bc_sum = 0;
  for(int i=0;i<n;i++){
    q_bc.push(a[3*n-i-1]);
    q_bc_sum += a[3*n-i-1];
  }

  vector<ll> bc_sum(n+1);
  bc_sum[0] = q_bc_sum;
  int sum_index = 1;

  for(int k = 2*n-1;k>=n;k--){
    if(q_bc.top() > a[k]){
      q_bc_sum -= q_bc.top();
      q_bc.pop();
      q_bc_sum += a[k];
      q_bc.push(a[k]);
    }

    bc_sum[sum_index++] = q_bc_sum;
  }

  ll ans = fr_sum[0] - bc_sum[n];
  for(int k = 1;k<=n;k++){
    ans = max(fr_sum[k] - bc_sum[n-k],ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 8892
object Main extends App {

  override def main(args: Array[String]): Unit = {
    val input = io.StdIn.readLine
    val tree = Tree.of(input)

    val q = io.StdIn.readLine.toInt

    (1 to q).map(_ => io.StdIn.readLine.split(' ')).foldLeft(tree)((z, list) => {
//      z.print(0, input.length() - 1)
      list(0) match {
        case "print"   => z.print(list(1).toInt, list(2).toInt)
        case "replace" => z.replace(list(1).toInt, list(2).toInt, list(3))
        case "reverse" => z.reverse(list(1).toInt, list(2).toInt)
      }
    })

  }

  class Tree(val inner: Array[Char]) {
    def print(n: Int, m: Int): Tree = {
      val str = (n to m).foldLeft("")((z, k) => z + inner(k));
      println(str)
      this
    }
    def replace(n: Int, m: Int, str: String): Tree = {
      new Tree((0 until inner.length).map(i => i match {
        case j if (n to m).contains(j) => str.charAt(j - n)
        case j                         => inner(j)
      }).toArray)
    }
    def reverse(n: Int, m: Int): Tree = {
      new Tree((0 until inner.length).map(i => i match {
        case j if (n to m).contains(j) => inner(n + m - j)
        case j                         => inner(j)
      }).toArray)
    }
  }
  object Tree {
    def of(input: String): Tree = {
      new Tree(input.toCharArray())
    }
  }
}

Measured memory_bytes: 68420
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _017_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] np = ReadInts();
            int n = np[0];
            int p = np[1];
            int[] array = ReadInts();

            long zeroCnt = 0;
            long oneCnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (array[i] % 2 == 0) zeroCnt++;
                else oneCnt++;
            }
            long zeroPats = (long)Math.Pow(2, zeroCnt);
            long onePats = 0;
            for(long i = 0; i <= oneCnt; i += 2)
            {
                long val = 0;
                long m = Math.Min(oneCnt - i, 0);
                onePats += Combination(oneCnt, i);
            }

            long allPat = (long)Math.Pow(2, n);
            if (p == 0)
            {
                Console.WriteLine(zeroPats * onePats);
            }
            else
            {
                Console.WriteLine(allPat - zeroPats * onePats);
            }
        }

        static long Combination(long n, long m)
        {
            if (n - m < m) m = n - m;

            long val = Permutation(n, m);
            long div = Permutation(m, m);
            return val / div;
        }

        static long Permutation(long n, long m)
        {
            long val = 1;
            for (long i = 0; i < m; i++)
            {
                val *= (n - i);
            }
            return val;
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	deque<int> dq;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		if(i&1){
			dq.push_front(x);
		}else{
			dq.push_back(x);
		}
	}
	if(n&1)reverse(dq.begin(), dq.end());
	for(auto x : dq){
		cout<<x<<" ";
	}

	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> a(h);
    REP(i, h){
        cin >> a.at(i);
    }

    ll i = 0, j = 0;
    a.at(i).at(j) = '.';
    while(true){
        const vector<ll> di = {-1, 1, 0, 0};
        const vector<ll> dj = {0, 0, -1, 1};
        ll count = 0;
        ll nxt_idx = -1;
        REP(k, 4){
            if(i + di.at(k) < 0 || i + di.at(k) >= h ||
               j + dj.at(k) < 0 || j + dj.at(k) >= w){
                continue;
            }
            if(a.at(i + di.at(k)).at(j + dj.at(k)) == '#'){
                count++;
                nxt_idx = k;
            }
        }
        if(count >= 2 ||
           (count == 1 && (nxt_idx == 0 || nxt_idx == 2))){
            cout << "Impossible" << endl;
            return 0;
        }else if(count == 0){
            break;
        }else{
            a.at(i + di.at(nxt_idx)).at(j + dj.at(nxt_idx)) = '.';
            i = i + di.at(nxt_idx);
            j = j + dj.at(nxt_idx);
        }
    }
    cout << "Possible" << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

int main(){
	int a,b;
	cin >> a >> b;
	if(a > b)cout << 2*a-1 << endl;
	else if(a == b)cout << 2*a << endl;
	else cout << 2*b-1 << endl;
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(String a;!(a=s.nextLine()).equals("#");){int i=0,r=0;for(char c:a.toCharArray())if(103<c&&c<113||c==121||c==117){r+=i<0?1:0;i=1;}else{r+=i>0?1:0;i=-1;}System.out.println(r);}}}

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

vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	int n, c, k, a;
	cin >> n >> c >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int ans = 1, cnt = 1, last = v[0];
	for (int i = 1; i < v.size(); i++) {
		if (cnt == c || v[i]-last > k) {
			ans++, cnt = 1, last = v[i];
		} else {
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}


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


int main() {
    int N; cin >> N;
    set<int> A; 
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        A.insert(a);
    }
    if (N == A.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 9600
import numpy as np


n=int(input())
aList=[]
for i in range(n):
    aList.append(int(input()))


maxIndex = np.argmax(aList)
maxVal = aList[maxIndex]
del aList[maxIndex]
secondMaxVal= max(aList)


for i in range(n):
    if i==maxIndex:
        print(secondMaxVal)
    else:
        print(maxVal)


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
    unsigned long long n, k;
    vector<pair<int , int> > v;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    for(int i=0;i<n;i++){
        if(k<=v[i].second){
            cout << v[i].first << endl;
            break;
        }
        else{
            k-=v[i].second;
        }
    }
}

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

int main() {
  int a, b;
  1 <= a , b <= 10000;
  cin >> a >> b;
  
  if ( a * b % 2 == 0 ){
  cout << "Even" << endl;
  }
  
  else {
  cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  
  int n,l,ideal,real;
  cin>>n>>l;
  ideal=n*l;
  for (int i=0;i<n;i++) {
    ideal=ideal+i;
  }
  if (l<=0 && l+n>0) {
    real=ideal;
  }
  else if (l<=0 && l+n<=0) {
    real=ideal-l-n+1;
  }
  else {
    real=ideal-l;
  }
  cout <<real<<endl;
}

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

int main() {
  int h, w; cin >> h >> w;
  vector<string> a(h);
  for (auto& e: a) cin >> e;

  for (int i = 0; i < w + 2; i++) cout << '#'; cout << endl;
  for (auto& e: a) cout << '#' << e << '#' << endl;
  for (int i = 0; i < w + 2; i++) cout << '#'; cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[10005];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans=1,t=a[1];
    for(int i=2;i<=n;i++)
    {
        if(a[i]>=t) ans++,t=a[i];
    }
    cout<<ans<<endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto & s : S) cin >> s;
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            if (S[h][w] == '#') continue;
            int c = 0;
            for (auto dh : {-1, 0, 1}){
                if (dh + h < 0 or dh + h >= H) continue;
                for (auto dw : {-1, 0, 1}){
                    if (dw + w < 0 or dw + w >= W) continue;
                    if (S[h + dh][w + dw] == '#') ++c;
                }
            }
            S[h][w] = (char)('0' + c);
        }
    }
    for (auto & s : S) cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {

            int N =int.Parse(Console.ReadLine());
            string[] line = Console.ReadLine().Split();
            List<int> intList = new List<int>();
            List<int> checkList = new List<int>();
            int noMatch = 0;

            for(int i=0 ; i<N ; i++)
            {
                intList.Add(int.Parse(line[i]));
                checkList.Add(i+1);
                if (intList[i] != checkList[i])
                {
                    noMatch++;
                }
            }
            if (noMatch <= 2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }



Measured memory_bytes: 13140
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = [0] + LI()

for i in range(1, n + 1):
    A[i] = (A[i] + A[i - 1] - 1) % k


ans = 0
D = defaultdict(int)
for j in range(n + 1):
    if j >= k:
        D[A[j - k]] -= 1
    ans += D[A[j]]
    D[A[j]] += 1



if k == 1:
    print(0)
else:
    print(ans)


Measured memory_bytes: 86332
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

using ll = long long;

int main()
{
    ll N, M;
    scanf("%lld %lld\n", &N, &M);
    ll result = min(N, M / 2);
    M -= result * 2;
    result += M / 4;
    printf("%lld\n", result);
}


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

int main(){
  long long int n,m;
  long long int answer;
  cin >> n >> m;
  vector<pair<long long int,long long int>> pairs(n);
  for(int i = 0;i < n;i++){
    cin >> pairs[i].first >> pairs[i].second;
  }
  sort(pairs.begin(),pairs.end());
  for(long long int i = 0;;i++){
    answer += pairs[i].second*pairs[i].first;
    m -= pairs[i].second;
    if(m < 0){
      answer -= pairs[i].second*pairs[i].first;//一個戻す
      m += pairs[i].second;
      answer += m*pairs[i].first;
      break;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 1792
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var s = input.ReadLine();


        if(s[0]=='R' && s[1] == 'R' && s[2] == 'R') {
            return 3;
        }
        if(s[0] == 'R' && s[1] == 'R') {
            return 2;
        }
        if (s[1] == 'R' && s[2] == 'R') {
            return 2;
        }
        if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
            return 1;
        }
        return 0;
    }
}


Measured memory_bytes: 25776
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    ww=input().split()
    stack=[]
    for w in ww:
        if w.isdecimal():
            stack.append(w)
        else:
            b=stack.pop()
            a=stack.pop()
            stack.append(str(eval(a+w+b)))
    print(stack[0])

    # aa = list(map(int, input().split()))

main()



Measured memory_bytes: 5580
from operator import itemgetter
n = int(input())
sp = []
for i in range(n):
         s,p = input().split()
         tmp = [s,100-int(p),i]
         sp.append(tmp)
sp = sorted(sp,key = itemgetter(0,1))
for i in range(n):
         print(sp[i][2]+1)


Measured memory_bytes: 3060
/*input
3
1 2 3
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	int arr[n];
	int i;
	for(i=0;i<n;++i)
		cin >> arr[i];
	int ct = 0;
	for(i=0;i<n-1;++i){
		if(arr[i] == i+1){
			swap(arr[i],arr[i+1]);
			ct++;
		}
	}
	if(arr[n-1] == n){
		ct++;
	}
	cout << ct << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

class UnionFind {

	int[] par;

	public UnionFind(int size) {
		par = new int[size];
		Arrays.fill(par, -1);
	}

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

	public boolean same(int a, int b) {
		return root(a) == root(b);
	}

	public void unite(int a, int b) {
		if (!same(a, b)) {
			int ra = root(a);
			int rb = root(b);

			if (par[ra] < par[rb]) {
				par[ra] += par[rb];
				par[rb] = ra;
			} else {
				par[rb] += par[ra];
				par[ra] = rb;
			}
		}
	}

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

}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		UnionFind uf = new UnionFind(N);

		for (int i = 0; i < M; i++) {
			uf.unite(sc.nextInt() - 1, sc.nextInt() - 1);
			sc.nextInt();
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (uf.par[i] < 0)
				ans++;
		}
		out.println(ans);

		sc.close();

	}

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

}


Measured memory_bytes: 90068
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n,v;
    cin>>n>>v;
    vector<vector<ll>> A(4);
    for(int i=0;i<4;i++){
        for(int t=0;t<n;t++){
            ll b;
            cin>>b;
            A[i].push_back(b);
        }
    }
    map<ll,ll> AB,CD;
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            AB[A[0][i]+A[1][t]]++;
        }
    }
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            CD[A[2][i]+A[3][t]]++;
        }
    }
    ll ans=0;
    for(auto i=AB.begin();i!=AB.end();i++){
        ll g=(*i).F;
        if(CD.find(v-g)!=CD.end()){
            ans+=(*i).S*CD[v-g];
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 128064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
  string s;
  cin >> s;
  
  if(s == "ABC")
    printf("ARC");
  
  else if(s == "ARC")
    printf("ABC");
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

int main(){
    long H, W, N;
    cin >> H >> W >> N;
    long sr, sc;
    cin >> sr >> sc;
    string S;
    string T;
    cin >> S;
    cin >> T;

    long G_L = sc;
    long G_R = sc;
    long G_U = sr;
    long G_D = sr;

    bool flag = true;
    for(int i = 0; i < N; i++){
        if(S[i] == 'L')G_L--;
        if(S[i] == 'R')G_R++;
        if(S[i] == 'U')G_U--;
        if(S[i] == 'D')G_D++;

        if(G_L < 1){
            cout << "NO";
            return 0;
        }
        if(G_R > W){
            cout << "NO";
            return 0;
        }
        if(G_U < 1){
            cout << "NO";
            return 0;
        }
        if(G_D > H){
            cout << "NO";
            return 0;
        }

        if(T[i] == 'L')G_R--;
        if(T[i] == 'R')G_L++;
        if(T[i] == 'U')G_D--;
        if(T[i] == 'D')G_U++;

        if(G_L>W) G_L--;
        if(G_R<=0) G_R++;
        if(G_U>H) G_U--;
        if(G_D<=0) G_D++;
    }

    cout << "YES";
    return 0;
}

Measured memory_bytes: 776
N, *A = map(int, open(0).read().split())
negative_num = sum(1 if a < 0 else 0 for a in A)
positive_num = list(abs(n) for n in A)

if negative_num % 2 == 0:
    print(sum(positive_num))
else:
    print(sum(positive_num) - 2*min(positive_num))


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

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

    int N, M;
    cin >> N >> M;

    int a = M;
    rep(i, 0, (M + 1) / 2) {
        cout << i + 1 << " " << M - i + 1 << endl;
    }
    rep(i, 0, M / 2) {
        cout << M + i + 2 << " " << M + M - i + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <numeric>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    int m=max(a,max(b,c));
    for(int i=0;i<k;i++)m*=2;
    cout<<a+b+c+m-max(a,max(b,c));
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.util.Stack;

public class Main {
	
	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			Stack<Character> st = new Stack<Character>();
			char[] carr = sc.scanString().toCharArray();
			for(int i = 0, end = carr.length; i < end; ++i){
				char curr = carr[i];
				if(st.empty())
					st.add(curr);
				else {
					if (st.peek() == 'S' && curr == 'T')
						st.pop();
					else
						st.add(curr);
				}
			}
			System.out.println(st.size());
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 37060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a,b,ans,x,y,z;
int main(void){
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        ll p;
        cin>>p;
        if(p<=a)x++;
        else if(p<=b)y++;
        else z++;
    }
    printf("%lld\n",min(x,min(y,z)));
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
struct UnionFind{
    vector <int> par;
    UnionFind(int N) : par(N, -1){}
    void unite(int x, int y){
        x = root(x); y = root(y);
        if(x != y){
            par[x] += par[y];
            par[y] = x;
        }
    }
    int root(int x){ return par[x] < 0 ? x : par[x] = root(par[x]);}
    bool same(int x, int y){ return root(x) == root(y);}
};
typedef pair<bool, int> pbt;
typedef  long long int ll;
bool marked[100000];
int p[100000];
#define rep(i,n) for(int i = 0;i <n;i++)
#define REP(i,a,b) for(int i = a; i <b;i++)
int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int N, Q, _t;char _c;
    while(cin >> N >> Q && N){
        memset(marked, 0, sizeof(marked));
        marked[0] = true;
        UnionFind uf(N);vector<pbt> query;
        REP(i, 1, N){ cin >> p[i]; --p[i];}
        rep(i, Q){
            cin >> _c >>_t; --_t;
            if(_c == 'Q')
              query.push_back(pbt(1, _t));
            else if(!marked[_t]){
                query.push_back(pbt(0, _t));
                marked[_t] = true;
            }
        }
        rep(i, N)
          if(!marked[i])
            uf.unite(p[i], i);
        ll sum = 0LL;
        for(int i = query.size() - 1; i >= 0; --i){
            int v = query[i].second;
            if(query[i].first)
              sum += uf.root(v) + 1;
            else
              uf.unite(p[v], v);
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 5480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder output = new StringBuilder();
        boolean[][] card = new boolean[4][13];

        String input = br.readLine();

//      ???????????????????????????????????????????????°
        int n = Integer.parseInt(input);

        for(int i = 0; i < n; i++){
            input = br.readLine();
            String[] strArray = input.split(" ");

            String egara = strArray[0]; //?????????????????????
            int number = Integer.parseInt(strArray[1]); //?????????????????°???

            if(egara.equals("S")){
                card[0][number-1] = true;

            }else if(egara.equals("H")){
                card[1][number-1] = true;

            }else if(egara.equals("C")){
                card[2][number-1] = true;

            }else if(egara.equals("D")){
                card[3][number-1] = true;

            }else{
                break;
            }
        }

        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                if(card[i][j] == false){
                    if(i == 0){
                        output.append("S");

                    }else if(i == 1){
                        output.append("H");

                    }else if(i == 2){
                        output.append("C");

                    }else if(i == 3){
                        output.append("D");
                    }
                    output.append(" ").append(j+1).append("\n");
                }
            }
        }
        System.out.print(output);
    }
}

Measured memory_bytes: 24424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  vector<bool> d;
  d.push_back(1);
  int p=0;
  for(int i=1;i<n;i++){
    if(s.at(i)==s.at(i-1))
      d.at(p)=0;
    else{
      d.push_back(1);
      p++;
    }
  }
  int64_t c=(d.at(0)?3:6);
  for(int i=1;i<d.size();i++){
    if(d.at(i-1)&&d.at(i))
      c*=2;
    if(d.at(i-1)&&!d.at(i))
      c*=2;
    if(!d.at(i-1)&&d.at(i))
      c*=1;
    if(!d.at(i-1)&&!d.at(i))
      c*=3;
    c%=1000000007;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long

int main(){
    ll n;
    cin >> n;
    for(ll i = sqrt(n); i > 0; --i ){
        if(n%i == 0){
            cout << i + n/i -2 << endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

map<string,int> mp;

string s[10101];

int main(){
	int n=read();
	int ans=0;
	cin>>s[1];
	mp[s[1]]=1;
	for(int i=2;i<=n;i++){
		cin>>s[i];
		if(mp[s[i]]==1) ans=1;
		mp[s[i]]=1;
		if(s[i-1][s[i-1].size()-1]!=s[i][0]) ans=1;
	}
	if(ans==1) printf("No\n");
	else printf("Yes\n");	
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hashmap = new HashMap<>();
        String[] a = sc.next().split("");
        hashmap.put("a", 1);
        hashmap.put("b", 2);
        hashmap.put("c", 3);
        
        if (hashmap.get(a[0]) + hashmap.get(a[1]) + hashmap.get(a[2]) == 6) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#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;


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;

#define fi first
#define se second

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const ll inf = ll(1e18);
const int MOD = (1e9 + 7);

int main() 
{

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
		clock_t start = clock();
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	//code begins here

	ll n;
	cin >> n;
	ll arr[n];
	
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	
	vll arr1[n];
	ll sum[n][60];
	ll pw[60];
	pw[0] = (ll)1;
	for(int i=1;i<60;i++){
		pw[i] = (pw[i-1]*((ll)2))%MOD;
		//cout<<pw[i]<<" ";
	}
	//cout<<"\n";
	for(int i=0;i<n;i++){
		
		ll temp =  arr[i];
		while(temp){
			if(temp%2==1) arr1[i].push_back(1);
			else arr1[i].push_back(0);
			temp = temp >>1 ;
		}
		//reverse(arr1[i].begin(),arr1[i].end());
		while(arr1[i].size()<60){
			arr1[i].push_back(0);
		}
		
	}
	for(int j=n-1;j>=0;j--){
		for(int k=0;k<60;k++){
			sum[j][k] = arr1[j][k];
		}
		// for(int i=0;i<60;i++)
		// cout<<sum[j][i];
		// cout<<"\n";
	}

	for(int j=n-2;j>=0;j--){
		for(int k=0;k<60;k++){
			sum[j][k] = sum[j][k] + sum[j+1][k];
		}
		// for(int i=0;i<60;i++)
		// cout<<sum[j][i];
		// cout<<"\n";
	}

	ll ans = 0;
	
	for(int i=0;i<n-1;i++){
		for(int j=0;j<60;j++){
			ll cnt = 0;
			if(arr1[i][j]==1){
				assert((n-1-i-sum[i+1][j]) >= 0);
				cnt = (n-1-i-sum[i+1][j]);
			}
			else cnt = sum[i+1][j];
			ans += (pw[j]*cnt)%MOD;
		}
		//cout<<i<<" "<<ans<<"\n";
	}
	cout<<ans%MOD<<"\n";
	//End of code 
	#ifdef DEBUG_
		cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}



Measured memory_bytes: 304896
use std::io::Read;

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

    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 0;
    let mut i = 0;
    while i < n {
        if i + 1 < n && a[i] == a[i+1] {
            ans += 1;
            i += 2;
        } else {
            i += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int[] start = new int[26];
		int[] goal = new int[26];
		Arrays.fill(start, -1);
		Arrays.fill(goal, -1);
		for (int i = 0; i < s.length; i++) {
			int a = s[i] - 'a';
			int b = t[i] - 'a';
			if (start[a] != -1 || goal[b] != -1) {
				if (start[a] != b || goal[b] != a) {
					System.out.println("No");
					return;
				}
			}
			start[a] = b;
			goal[b] = a;

			//			for (int j = 0; j < 26; j++) {
			//				System.out.print((char) (start[j] + 'a') + " ");
			//			}
			//			System.out.println();
			//			for (int j = 0; j < 26; j++) {
			//				System.out.print((char) (goal[j] + 'a') + " ");
			//			}
			//			System.out.println();
			//			System.out.println();
		}
		System.out.println("Yes");
	}
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n;	
    cin >> n;
    vector<vector<pll>> nums(n);
    FOR(i, n)
    {
        ll q;
        cin >> q;
        while (q--)
        {
            ll x, y;
            cin >> x >> y;
            nums[i].pb({x - 1, y});
        }
    }
    ll m = 0;
    FOR(i, 1 << n)
    {
        bool works = true;
        FOR(j, n)
        {
            if (i & (1 << j))
            {
                FORE(k, nums[j]) if (((i & 1 << k.first) ^ (k.second << k.first))) works = false;
            }
        }
        if (works) m = max(m, (ll)__builtin_popcount(i));
    }
    cout << m << '\n';
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  bool CAN=true;
  ll A[N+1],SUM[N+1],B[N+1],ANS[N+1];
  REP(i,N+1){
    cin>>A[i];
    SUM[i]=0;
  }
  SUM[N]=A[N];
  for(int i=N-1; i>=0; --i){
    SUM[i]=SUM[i+1]+A[i];
  }
  
  B[0]=1;
  for(int i=1; i<=N; ++i){
    B[i]=min((B[i-1]-A[i-1])*2,INF*INF);
  }
  
  for(int i=0; i<=N; ++i){
    ANS[i]=min(B[i],SUM[i]);
    ans+=ANS[i];
  }
  
  if(N==0){
    if(A[0]==1) co(1);
    else co(-1);
    return 0;
  }
  
  if(ANS[0]!=1) CAN=false;
  for(int i=1; i<=N; ++i){
    if((ANS[i-1]-A[i-1])*2<A[i]) CAN=false;
  }
  if(ANS[N]!=A[N]) CAN=false;
  
  
  if(CAN) co(ans);
  else co(-1);
  return 0;
}

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

int main(int argc, const char * argv[]) {
    int a, b;
    int d, r;
    double f;
    
    cin >> a >> b;
    
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    
    cout << fixed;
    cout << setprecision(6);
    
    cout << d << " " << r << " " << f << endl;
    
    return 0;
}


Measured memory_bytes: 3268
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

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

		Map<Integer,Integer> o=new HashMap<>();
		Map<Integer,Integer> e=new HashMap<>();
		o.put(0,0);
		e.put(0,0);

		for(int i = 0;i < n;i++)
			(i%2==0 ? e : o).merge(sc.nextInt(),1,Integer::sum);
		sc.close();

		Comparator<Entry<Integer,Integer>> comp = Entry.comparingByValue();
		Entry<Integer,Integer> O = o.entrySet().stream()
				.max(comp)
				.get();
		Entry<Integer,Integer> E = e.entrySet().stream()
				.max(comp)
				.get();
		o.remove(O.getKey());
		e.remove(E.getKey());
		Entry<Integer,Integer> O2=o.entrySet().stream()
				.max(comp)
				.get();
		Entry<Integer,Integer> E2=e.entrySet().stream()
				.max(comp)
				.get();
		n -= O.getKey().equals(E.getKey())
				? Math.max(O.getValue()+E2.getValue(),
						E.getValue()+O2.getValue())
				: O.getValue()+E.getValue();
		System.out.println(n);
	}
}

Measured memory_bytes: 64848
def check(orijinal,A):
    A2 = [int(x[1]) for x in A]
    orijinal2 = [int(x[1]) for x in orijinal]
    B=[x for x in set(A2) if  A2.count(x)>1]
    flag=True
    if len(B)!=0:
        count=0
        soeji=[]
        for fig in B:
            a=[i for i, x in enumerate(orijinal2) if x == fig]
            b=[i for i, x in enumerate(A2) if x == fig]
            orijinal3=[orijinal[k] for k  in a]
            A3 = [A[k] for k in b]
            if orijinal3!=A3:
                flag=False
                break
    if flag:
        print("Stable")
    else:
        print("Not stable")
def selectSort(N,A):
    count=0
    orijinal=A[:]
    B=[ int(x[1]) for x in A]
    C=list(range(N))
    for i in range(N):
        min=i
        for j in range(i,N):
            if B[j] < B[min]:
                min=j
        if i<=min:
            count+=1
            # for k in range(N): print(A[k], end=' \n'[k + 1 == N])
            A[i],A[min]=A[min],A[i]
            B[i], B[min] = B[min], B[i]

    for k in range(N):print(A[k],end=' \n'[k+1==N])
    check(orijinal,A)



def bubbleSort(N,A):
    i=0
    flag=True
    count=0
    orijinal = A[:]
    B = [int(x[1]) for x in A]
    while flag:
        flag=False
        for j in range(N-1,i,-1):
            if B[j]<B[j-1]:#ソート必須
                A[j],A[j-1]=A[j-1],A[j]
                B[j], B[j - 1] = B[j-1], B[j]
                count+=1
                flag=True


        i += 1
    for i in range(N):print(A[i],end=' \n'[i+1==N])
    check(orijinal, A)

N=int(input())
A=[(x) for x in input().split()]
B=A[:]
bubbleSort(N,A)
selectSort(N,B)




Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    char s;
    cin>>s;
    if(s>='A'&&s<='Z'){
        cout<<"A\n";
    }else{
        cout<<"a\n";
    }





return 0;
}


//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll x;
    cin >> x;
    if(x >= 30)cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3632