akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct State{
  int result,backpos;
  State(int a,int b){
    result=a;
    backpos=b;
  }
};

bool is_numchar(char c){
  if('1'<=c&&c<='9') return true;
  if(c=='0') return true;
  return false;
}

int strtoint(std::string s){
  int result=0;
  for(int i=0;i<s.size();i++){
    result+=(s[i]-'0')*(int)std::pow(10,s.size()-1-i);
  }
  return result;
}



State expr(const std::string& s,int frontpos);
State factor(const std::string& s,int frontpos);
State term(const std::string& s,int frontpos);
State number(const std::string& s,int frontpos);

State expr(const std::string& s,int frontpos){
  State state=term(s,frontpos);
  while(1){
    int op_pos=state.backpos+1;
    if(op_pos<s.size()&&s[op_pos]=='+'){
      State new_state=term(s,op_pos+1);
      state.result+=new_state.result;
      state.backpos=new_state.backpos;
    }else if(op_pos<s.size()&&s[op_pos]=='-') {
      State new_state = term(s, op_pos + 1);
      state.result -= new_state.result;
      state.backpos = new_state.backpos;
    }else break;
  }
  return state;
}

State term(const std::string& s,int frontpos){
  State state=factor(s,frontpos);
  while(1){
    int op_pos=state.backpos+1;
    if(op_pos<s.size()&&s[op_pos]=='*'){
      State new_state=factor(s,op_pos+1);
      state.result*=new_state.result;
      state.backpos=new_state.backpos;
    }else if(op_pos<s.size()&&s[op_pos]=='/') {
      State new_state = factor(s, op_pos + 1);
      state.result /= new_state.result;
      state.backpos = new_state.backpos;
    }else break;
  }
  return state;
}

State factor(const std::string& s,int frontpos){
  if(s[frontpos]=='('){
    State result=expr(s,frontpos+1);
    result.backpos++;// ')'を読み飛ばす
    return result;
  }else{
    return number(s,frontpos);
  }
}

State number(const std::string& s,int frontpos){
  int result;
  int backpos=frontpos;
  std::string numstr;
  for(int i=frontpos;i<s.size();i++){
    if(is_numchar(s[i])){
      numstr+=s[i];
      backpos++;
    }else {
      backpos--;
      break;
    }
  }
  result=strtoint(numstr);
  return State(result,backpos);
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    std::string s;
    cin>>s;
    std::string throw_s;
    for(int j=0;j<s.size()-1;j++){
      throw_s+=s[j];
    }
    cout<<expr(throw_s,0).result<<endl;

  }





  



  return 0;
}



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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    s[k - 1] += 32;
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 892
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: String,
    }

    let bx100: i64 = b.replace(r".", r"").parse().unwrap();
    let ab = a * bx100;
    let s = ab.to_string();
    let ans = if s.len() < 2 { "0" } else { &s[..s.len() - 2] };

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


Measured memory_bytes: 2180
#include <iostream>

using namespace std;

int main()
{

    int aux;
    int x,y,z;
    cin>>x>>y>>z;
    int a,b,c;

    aux=x;
    x=y;
    y=aux;

    aux=x;
    x=z;
    z=aux;

    cout<<x<<" "<<y<<" "<<z<<endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){
    
    return;
}


int main(){
    int n;
    cin >> n;
    vec arr (n);
    int64 rs = 0;
    map <int64, int64> mp;
    for (int  i= 0; i < n; i++){
        cin >> arr[i];
        mp[arr[i]]++;
        rs+=arr[i];
    }
    int q;
    cin >> q;
    while (q--){
        int64 a,b;
        cin >> a >> b;
        rs-= mp[a] * a;
        rs-= mp[b] * b;
        mp[b]+= mp[a];
        mp[a] = 0;
        rs+= mp[b] * b;
        // for (auto i: mp){
        //     cts(i.second);
        // }
        // nn;
        ctn(rs);
    }
    return 0;
}


Measured memory_bytes: 9420
from collections import defaultdict
import heapq
import math

H, W = map(int, input().split())

edges = defaultdict(list)
field = []

for _ in range(H):
    field.append(input())

weight = 1
for i in range(H):
    for j in range(W):
        if j + 1 < W and field[i][j] == '.' and field[i][j + 1] == '.':
            edges[W * i + j].append((W * i + j + 1, weight))
            edges[W * i + j + 1].append((W * i + j, weight))
        if i + 1 < H and field[i][j] == '.' and field[i + 1][j] == '.':
            edges[W * i + j].append((W * (i + 1) + j, weight))
            edges[W * (i + 1) + j].append((W * i + j, weight))


def dijkstra(s):
    que = []
    dist = [float('inf')] * (H * W)
    dist[s] = 0
    heapq.heappush(que, (0, s))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for i in range(len(edges[v])):
            e = edges[v][i]
            if dist[e[0]] > dist[v] + e[1]:
                dist[e[0]] = dist[v] + e[1]
                heapq.heappush(que, (dist[e[0]], e[0]))

    dist = [0 if d == float('inf') else d for d in dist]
    return dist


ans = 0
for i in range(H*W):
    ans = max(ans, max(dijkstra(i)))

print(ans)

Measured memory_bytes: 3572
#include<stdio.h>
int main(void){
  int a,b,max=0,i;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  for(i=0;i<2;i++){
      if(a>=b){
          max=a+max;
          a=a-1;
         }else if(b>a){
          max=b+max;
          b=b-1;
         }
  }
  printf("%d\n",max);
  return 0;
}

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

int main() {
	int N, ans = 0;
	cin >> N;

	vector<int> p(N);
	for (int i = 0; i < N; i++) cin >> p.at(i);

	sort(p.begin(), p.end());

	for (int i = 0; i < N; i++) {
		if (i == N - 1) {
			ans += p.at(i) / 2;
		}
		else ans += p.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, Q = map(int, input().split())
S = input()

ac_pos = []
p = 0
while p < N-1:
    if S[p]=="A" and S[p+1]=="C":
        ac_pos.append(p+1)
        p+=2
    else:
        p+=1

for _ in range(Q):
    l, r = map(int, input().split())
    p = bisect_left(ac_pos, l)
    q = bisect_left(ac_pos, r)
    print(q-p)

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

#define mod 1000000007

int main(){
    int n;
    cin >> n;
    long long pow = 1;

    for(int i = 1; i <= n; i++){
        pow = (pow * i) % mod;
    }
    cout << pow << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(raw_input())
H = map(int, raw_input().split())

if H[0] > 1:
    H[0] -= 1

is_non_descend = True
for i in xrange(N-1):
    if H[i+1] > H[i]:
        H[i+1] -= 1
    if H[i+1] < H[i]:
        is_non_descend = False
        break

if is_non_descend:
    print "Yes"
else:
    print "No"
    

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi p(n);
    for(int & i : p)
        cin >> i;
    int cnt = 0;
    for(int  i=1; i + 1 < n; i++)
        cnt += (p[i - 1] < p[i] && p[i] < p[i + 1]) , cnt += (p[i- 1] > p[i] && p[i] > p[i + 1]);
    cout << cnt << '\n';


    return 0;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (2147483647)
#define MOD (int)(1e9 + 7) 

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<ll> ball(n+5, 0);
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
        ball[arr[i]]++;
    }
    vector<ll> pre(n+5, 0);
    ll res = 0;
    for(int i = 0; i <= n; ++i) {
        pre[i] = ball[i] * (ball[i] - 1) / 2;
        res += pre[i];
    }
    for(int i = 0; i < n; ++i) {
        cout << res - pre[arr[i]] + ((ball[arr[i]] - 1) * (ball[arr[i]] - 2) / 2) << '\n';
    }
    return 0;
}

Measured memory_bytes: 7136
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[105][100005];
ll weight[105];
ll value[105];
ll n , w ;
ll solve(ll item , ll remaining ){
    if(item < 0 )
        return 0 ;

    if(dp[item][remaining]!=-1)
        return dp[item][remaining];

    ll res = 0 ;
    if (weight[item] > remaining){
        res=solve(item-1,remaining);
    }else{
        res=max(solve(item-1,remaining) , value[item] + solve(item-1,remaining-weight[item]));
    }
    dp[item][remaining]=res;
    return res ;
}
int main()
{
    cin >> n >> w ;
    for(ll i=0;i<n;i++){
        cin >> weight[i] >> value[i];
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<=w;j++){
            dp[i][j]=-1;
        }
    }
    ll res = solve(n-1,w);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 80128
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		scanner.Scan()
		buf_ := strings.Split(scanner.Text(), " ")
		items := make([]int, n)
		for i := 0; i < n; i++ {
			items[i], _ = strconv.Atoi(buf_[i])
		}
		sort.Ints(items)
		sum := 0
		for _, v := range items {
			sum += v
		}
		for i := n-m; i >= 0; i -= m {
			sum -= items[i]
		}
		fmt.Println(sum)
	}
}


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

int main() {
    int n, k, d;
    cin >> n >> k;
    set<int> s;
    for (int i = 0; i < k ;i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            s.insert(a);
        }
    }

    cout << n - s.size() << endl;

}

Measured memory_bytes: 3628
N=int(input())
k=0

AB=[list(map(int, input().split())) for i in range(N)]

for i in range(N)[::-1]:
    if (AB[i][0] + k) % AB[i][1] != 0:
        k += AB[i][1] - ((AB[i][0] + k) % AB[i][1])
    
print(k)

Measured memory_bytes: 27508
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class B01Unbalanced {
public:

    ll f(int m, string& s, int n, vector<int>& dp) {
      int changed = 0;
      int now = 0;
      int mi = 0;
      for(int i=0; i<n; i++) {
        if (s[i] == '?') {
          if (dp[i] + 2*(changed+1) <= m) {
            changed++;
            now++;
          } else {
            now--;
          }
        } else if (s[i] == '1') {
          now++;
        } else {
          now--;
        }
        chmin(mi, now);
      }
      return mi;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;

      string s; cin >> s;
      int n = s.size();

      int z = 0;
      vector<int> dp(n);
      int now = 0;
      rep(i, n) {
        if (s[i] == '1') {
          now++;
        } else {
          now--;
        }
        dp[i] = now;
        chmax(z, now);
      }

      for(int i=n-1; i>0; i--) {
        chmax(dp[i-1], dp[i]);
      }
      int fz = f(z, s, n, dp);
      int fz1 = f(z+1, s, n, dp);
      debug(z, fz, z+1, fz1);
      cout << min(z-fz, z+1-fz1) << endl;
    }
};

signed main() {
  B01Unbalanced solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 8224
#!/usr/bin/env python3
import sys

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    count = 1
    now = 0
    visited = [1]
    set_v = set()
    set_v.add(1)
    l = -1
    while count < N:
        x = A[now]
        if x in set_v:
            l = visited.index(x)
            break
        else:
            count += 1
            visited.append(x)
            set_v.add(x)
            now = x-1
    r = count
    # print(l,r,visited)
    
    if K < l:
        print(visited[K])
    else:
        print(visited[l + (K-l) % (r-l)])

if __name__ == '__main__':
    main()


Measured memory_bytes: 32400
N=int(input())
ac=0
wa=0
tle=0
re=0

S=[input() for i in range(N)]
for s in S:
    if s =='AC':
        ac=ac+1
    elif s == 'WA':
        wa = wa + 1
    elif s == 'TLE':
        tle = tle + 1
    else:
        re = re + 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 16188
import sys


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードを示す。負は自身が親ということ。親だった場合は−(その集合のサイズ)
        self.parent = [-1] * N

    def root(self, A):
        # Aがどのグループに属しているか調べる
        # ノード番号を受けとって一番上の親ノードの番号を返す
        # print(A)
        if self.parent[A] < 0:
            return A
        self.parent[A] = self.root(self.parent[A])
        return self.parent[A]

    def size(self, A):
        # 自分のいるグループの頂点数を調べる
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # AとBをくっつける
        # AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = self.root(A)
        B = self.root(B)

        if A == B:
            return False  # すでにくっついてるからくっつけない

        if self.size(A) < self.size(B):
            # 大きい方(A)に小さいほう(B)をくっ付けたい
            # 大小が逆だったらひっくり返しちゃう。
            A, B = B, A

        # Aのサイズを更新する
        self.parent[A] += self.parent[B]
        # Bの親をAに変更する
        self.parent[B] = A

        return True

    def same(self, A, B):
        return self.root(A) == self.root(B)



input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        uf.unite(a, b)

    group = set()
    for i in range(N):
        # print(uf.root(i))
        group.add(uf.root(i))
    # print(group)
    ans = len(group) - 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18032
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    int n;
    cin >> n;

    if(n == 1)
    {
        cout << "Hello World" << endl;
        return 0;
    }

    int a,b;
    cin >> a >> b;
    cout << (a+b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
 string s,t;
  cin >> s >>t;
  s+=s;
  
  bool res=false;
  for(int i=0;i<s.length();i++){
   if(s.substr(i,t.length())==t){
    res=true;
     break;
   } 
  }
 
  if(res) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w,i,j;cin >> h >> w;
  char a[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++) cin >> a[i][j];
  }
  for(i=0;i<h+2;i++){
    for(j=0;j<w+2;j++){
      if(i!=0 && i!=h+1 && j!=0 && j!=w+1) cout << a[i-1][j-1];
      else cout << '#';
    }
    cout << endl;
  }
}
    

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

int main() {
    string input;
    while(cin>>input) {
        if(input == "#") break;
        int dp[2][2] = {} ,tn = 0;

        for(int i=1; i<input.length(); ++i) {
            int next = tn^1;
            if((input[i]-'0'-1)%3 == (input[i-1]-'0'-1)%3) {
                dp[next][0] = min(dp[tn][0]+1, dp[tn][1]);
                dp[next][1] = min(dp[tn][1]+1, dp[tn][0]);
            }else if((input[i]-'0'-1)%3 > (input[i-1]-'0'-1)%3) {
                dp[next][0] = dp[tn][0]+1;
                dp[next][1] = min(dp[tn][0],dp[tn][1]+1);
            }else if((input[i]-'0'-1)%3 < (input[i-1]-'0'-1)%3) {
                dp[next][0] = min(dp[tn][0]+1, dp[tn][1]);
                dp[next][1] = dp[tn][1]+1;
            }
            tn = next;
        }

        cout<<min(dp[tn][0],dp[tn][1])<<endl;
    }
}

Measured memory_bytes: 1132
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int n;
    cin>>n;
    cout<<n*n<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as) {
        cin >> a;
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << as[n - 1 - i];
    }
    cout << endl;
}

Measured memory_bytes: 1196
package main

import (
        "fmt"
)

func solution(x, n int, p []int) int {
        if len(p) == 0 {
                return x
        }

        var memo [102]int
        for i := range p {
                memo[p[i]]--
        }

        lo := 1 << 31
        for i := 0; i <= 101; i++ {
                if memo[i] == 0 {
                        memo[i] = abs(x - i)
                        lo = min(lo, memo[i])
                }
        }

        out := 0
        for i := 0; i <= 101; i++ {
                if memo[i] != -1 && lo == memo[i] {
                        out = i
                        break
                }
        }
        return out
}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

func main() {
        var x, n int
        fmt.Scan(&x, &n)
        p := make([]int, n)
        for i := range p {
                fmt.Scan(&p[i])
        }
        fmt.Println(solution(x, n, p))
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin>>n;
	long long ans = 0;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			if(i*1LL*j>=n)
				break;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>

int top;
int stack[100];

int pop(){
    return stack[top--];
}

void push(int num){
    stack[++top] = num;
}

int main(){
    int a, b;
    char s[7];
    top = -1;

    while(scanf("%s", s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }
        else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }
        else if(s[0] == '-'){
            a = pop();
            b = pop();
            push(b-a);
        }
        else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}


Measured memory_bytes: 2712
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

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

  int s = 0;
  rep(i, N) { s ^= a[i]; }

  rep(i, N) { cout << (s ^ a[i]) << " "; }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4004
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

Measured memory_bytes: 20436
import math
a,b,c=map(int,input().split())
aa=math.sqrt(a)
bb=math.sqrt(b)
cc=math.sqrt(c)
ans=a**2+b**2+c**2-2*(a*b+b*c+a*c)
ans2=((aa+bb+cc)*(c-a-b+2*math.sqrt(a*b)))
print("Yes" if 0<ans/ans2 else "No")

Measured memory_bytes: 38256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<functional>
#include<queue>
#include<math.h>
#define INF 999999

using namespace std;

int main()
{
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3088
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S, T;
  cin >> S >> T;

  bool r = S == T.substr(0, T.size() - 1);

  cout << (r ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 () {
  int n, k;
  cin >> n >> k;
  vi v(n);
  rep(i,n) cin >> v[i];
  int ans = 0;
  rep(l,k+1) {
    rep(r,k-l+1) {
      if (l+r > n) continue;
      int d = k-l-r;
      int now = 0;
      vi s;
      rep(i,l) {
        now += v[i];
        s.push_back(v[i]);
      }
      for (int i = n-r; i < n; ++i) {
        now += v[i];
        s.push_back(v[i]);
      }
      SORT(s);
      rep(i,d) {
        if (i >= s.size()) break;
        if (s[i] > 0) break;
        now -= s[i];
      }
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    int ans = a[n - 1] - a[0];
    rep(i, n - 1) {
        ans = min(ans, a[i] + k - a[i + 1]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	string s;
	cin >> s;
	vector<char> search ={'C','F','a'};
	int count = 0;
	rep(i,s.size()){
		if(s[i] == search[count]){
			count ++;
		}
	}
	if(count >= 2){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,k;
int sum;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int a;cin>>a;
		sum=sum+min(2*a,2*abs(k-a));
	}
	cout<<sum;
	return 0;
}

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

int main() {
    string S; cin >> S;
    if (S[0]!=S[1] && S[1]!=S[2] && S[2]!=S[3]) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k,l;
  cin >>n>>k;
  vector <ll> v;
  for(ll i=0;i<n;i++) {
    cin >>l;
    v.push_back(l);
  }
  ll m=min(n,k),ans=0,sum=0;
  for(ll i=0;i<=m;i++){
    for(ll j=0;j<=(m-i);j++){
      sum=0;
      vector <ll> q;
      if(i!=0){
      for(ll p=0;p<i;p++) {
        sum+=v[p];
        q.push_back(v[p]);
      }
     }
      ll c=0;
      if(j!=0){
       for(ll p=n-1;c<j;p--) {
        c++;
        sum+=v[p];
        q.push_back(v[p]);
       }
      }
      if(q.size()==0){
        ll y=0;
        ans=max(ans,y);
        continue;
      }
      sort(q.begin(),q.end());
      for(ll p=0;p<k-(i+j);p++){
        if(p==q.size()-1) break;
        if(q[p]<0) sum-=(q[p]);
        else break;
      }
      ans=max(sum,ans);
    }
  }
  cout <<ans<<endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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 modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  llvec a(N), S(N+1, 0);
  rep(i, N){
    cin >> a[i];
    S[i+1] = S[i] + a[i];
  }

  llvec d(50, 0);
  llvec A;
  for(ll i=0;i<=N;i++){
    for(ll j=i+1;j<=N;j++){
      ll t= S[j]-S[i];
      rep(k, 50){
        if(t>>k&1)d[k]++;
      }
      A.push_back(t);
    }
  }

  llvec tmp = A;
  for(ll i=49;i>=0;i--){
    if(d[i]>=K){
      llvec tmp2;
      llvec d2(50, 0);
      for(auto itmp:tmp){
        if(itmp>>i&1){
          tmp2.push_back(itmp);
          rep(k, i){
            if(itmp>>k&1){
              d2[k]++;
            }
          }
        }
      }
      d=d2;
      tmp=tmp2;
    }
    //cerr << i << " ";DUMP(s, tmp);cerr << endl;
    if(tmp.size()==K){
      break;
    }
  }
  ll ans =tmp[0];
  rep(i, K){
    ans = ans & tmp[i];
  }

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


Measured memory_bytes: 12888
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int a, b;
    cin >> a >> b;
    if (a%3==0 || b%3==0 || (a+b)%3==0)
        cout << "Possible" << "\n";
    else
        cout << "Impossible" << "\n";
    return 0;
}

Measured memory_bytes: 256
x=int(input())
if x < 600:
    print(8)
elif x<800:
    print(7)
elif x<1000:
    print(6)
elif x<1200:
    print(5)
elif x<1400:
    print(4)
elif x<1600:
    print(3)
elif x<1800:
    print(2)
elif x<2000:
    print(1)

Measured memory_bytes: 9176
s=input()
ans=[0]*(len(s))
temp=[]
for i in range(len(s)):
    if(s[i]=='R'):
        temp.append(i)
    else:
        while(len(temp)):
            curr = temp.pop()
            diff = i-curr
            if(diff%2):
                ans[i-1]+=1
            else:
                ans[i]+=1
for i in range(len(s)-1,-1,-1):
    if(s[i]=='L'):
        temp.append(i)
    else:
        while(len(temp)):
            curr = temp.pop()
            diff = curr-i
            if(diff%2):
                ans[i+1]+=1
            else:
                ans[i]+=1
print(*ans)


Measured memory_bytes: 7932
#include <stdio.h>
#include <math.h>
#include <float.h>
#define N 100
#define P_MAX 3
#define imax(a,b) (a>b?a:b)

int input(double x[],double y[])
{
  int n;
  fscanf(stdin,"%d",&n);

  int i;
  for(i=0;i<n;i++)  fscanf(stdin,"%lf",&x[i]);
  for(i=0;i<n;i++)  fscanf(stdin,"%lf",&y[i]);
  return n;
}

double solve(double p,int n,double x[],double y[])
{
  double ans;
  if(p<4) ans=0;
  else ans=DBL_MIN;

  int i;
  for(i=0;i<n;i++){
    if(p<4) ans +=pow(fabs(x[i]-y[i]),p);
    else ans=imax(ans,fabs(x[i]-y[i]));
  }
  if(p<4) ans=pow(ans,1/p);
  return ans;
}

int main()
{
  double x[N],y[N];
  int n=input(x,y);

  double p=0;
  do{
    p++;
    fprintf(stdout,"%.6f\n",solve(p,n,x,y));
  }while(p<4);
  
  return 0;
}

Measured memory_bytes: 1980
import java.util.Scanner;
 
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int h, m, s;
    s = scan.nextInt();
 
    h = s / 3600;
    m = (s % 3600) / 60;
    s = s % 60;
    System.out.println(h + ":" + m + ":" + s);
  }
}


Measured memory_bytes: 26352
import java.math.BigDecimal

fun main(args: Array<String>) {
    val X = readLine()!!.toLong()
    outer@for(i in 0..200) {
        for(j in 0..200) {
            val a = BigDecimal(i)
            val b = BigDecimal(j)
            if(a.pow(5)-b.pow(5) == BigDecimal(X)) {
                println("${a} ${b}")
                break@outer
            }
            if(a.pow(5)+b.pow(5) == BigDecimal(X)) {
                if(j == 0) {
                    println("${a} ${b}")
                } else {
                    println("${a} -${b}")
                }
                break@outer
            }
        }
    }
 }

Measured memory_bytes: 52896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {  
    int n; cin >> n;
    vector<int> red(n*2, -1), blue(n*2, -1);
    vector<bool> check_red(n*2);
    rep(i, n){
        int a, b; cin >> a >> b;
        red[a] = b;
    }
    rep(i, n){
        int c, d; cin >> c >> d;
        blue[c] = d;
    }
    int res = 0;
    rep(i, n*2){
        if(blue[i] == -1) continue;
        int bx = i, by = blue[i];
        int rx = INF, ry = -1;
        rep(i, bx){
            if(red[i] > ry && red[i] < by && !check_red[i]){
                rx = i; ry = red[i];
            }
        }
        if(rx != INF){
            res++;
            check_red[rx] = true;
        }
    }
    cout << res << ln;
}




Measured memory_bytes: 256
//A - AtCoder Contest Scheduling
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  long long int d,c[30],i,j,tmp;
  scanf("%lld", &d);
  for(i = 1; i <= 26; i++) {
    scanf("%lld", &c[i]);
  }
  long long int s[d+2][30];
  for(i = 1; i <= d; i++) {
    for(j = 1; j <= 26; j++) {
          scanf("%lld", &s[i][j]);
    }
  }


  long long int r[367]={};
  for (i=1; i<=d; ++i) {
    r[i]=1;
    for (j=2; j<=26; ++j) {
      //for (k=i+1; k<=total; ++k) {
          if (s[i][1] < s[i][j]) {
            tmp =  s[i][1];
            s[i][1] = s[i][j];
            s[i][j] = tmp;
            r[i]=j;
          }
      //}
    }
  }
  //printf("aaa\n");
srand((unsigned int) time(0));
  for (i=1; i<=d; ++i) {
    printf("%d\n", (rand()%26)+1);
  }

  return 0;
}


Measured memory_bytes: 1820
n=int(input())
b=[0 for i in range(n+1)]
for i in range(n):
    b[i+1]=int(input())
now=1
ans=0
while ans<n+1:
    next=b[now]
    ans+=1
    now=next
    if next==2:
        print(ans)
        exit()
print(-1)

Measured memory_bytes: 12840
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
const int MAX = 200010;
const long long INF = 1 << 30;
 
 
 
int main() {
	int N;
	long long a[MAX];
 
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}
 
	sort(a, a + N);
 
	long long mid = a[N / 2];
	long long ans = 0;
 
	for (int i = 0; i < N; i++) {
		ans += abs(mid - a[i]);
	}
 
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
  int K,S,cnt = 0;
  scanf("%d %d",&K,&S);
  for(int i = 0;i <= K;i++){
    for(int j = 0;j <= K;j++){
      if(0 <= S - i - j && S - i - j <= K){
        cnt++;
      }
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
 #define int long long
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int n;
  cin >> n;
  if(n > 81)  {
    cout << "No" << endl;
    return 0;
  }
  for(int i = 1; i < 10; i++) {
    if(n % i == 0 && n / i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 3e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
ll gcd(ll a, ll b) {
	if (b == 0LL) return a;
	return gcd(b, a % b);
}
int A[MAXN];
int seg_max[4 * MAXN];

int update_max(int node, int l, int r, int pos, int val) {
	if (pos > r || pos < l) return seg_max[node];
	if (l == r) return seg_max[node] = val;
	int mid = (l + r) >> 1;
	return seg_max[node] = max(update_max(2 * node, l, mid, pos, val), update_max(2 * node + 1, mid + 1, r, pos, val));
}

int query_max(int node, int l, int r, int ql, int qr) {
	if (qr < l || ql > r) return -INF;
	if (ql <= l && r <= qr) return seg_max[node];
	int mid = (l + r) >> 1;
	return max(query_max(2 * node, l, mid, ql, qr), query_max(2 * node + 1, mid + 1, r, ql, qr));
}

int main()
{
	int i, j;
	scanf("%d%d", &N, &K);
	int maxA = 0;
	for (i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		maxA = max(maxA, A[i]);
	}
	int maxi = 0;
	for (i = 1; i <= N; ++i) {
		int l = max(0, A[i] - K);
		int r = min(maxA, A[i] + K);
		// query
		int val = query_max(1, 0, maxA, l, r) + 1;
		maxi = max(maxi, val);
		// update
		update_max(1, 0, maxA, A[i], val);
	}
	printf("%d", maxi);
}

Measured memory_bytes: 9100
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
a = list(map(int,input().split()))
ans = 0
for x,y in itertools.combinations(a,2):
    ans += x*y
print(ans)

Measured memory_bytes: 6696
#include<stdio.h>

int main(){
                 int A,B,C;

                 scanf("%d %d %d",&A,&B,&C);

                 if(A==B) printf("%d",C);
                 if(B==C) printf("%d",A);
                 if(C==A) printf("%d",B);
             
                 return 0;
}



Measured memory_bytes: 128
import itertools
N, C = map(int, input().split())
X = []
V = []
for n in range(N):
    x, v = map(int,input().split())
    X.append(x)
    V.append(v)
Xr = X[::-1]
Vr = V[::-1]
Xl = [0] + X
Vl = [0] + V
Xr = [0] + [C-x for x in Xr] # 逆に回るのでCから引く
Vr = [0] + Vr

Vl = list(itertools.accumulate(Vl)) # xは累積した値なので、vも累積和に統一
Vr = list(itertools.accumulate(Vr))

def update_mx(ls):
    mx = 0
    for i in range(len(ls)):
        mx = max(mx, ls[i])
        ls[i] = mx
    return ls

def create(V,X,k):
    ls = []
    for n in range(N+1):
        ls.append(V[n]-k*X[n]) # 往復する場合はk=2
    return update_mx(ls)

L = create(Vl,Xl,1) # 最良の値[左端として許容される位置]（片道）
Lt = create(Vl,Xl,2) # 最良の値[左端として許容される位置]（往復）
R = create(Vr,Xr,1)
Rt = create(Vr,Xr,2)

ans = 0
for n in range(N+1):
    #print (n,N-n)
    ans = max(ans, Lt[n] + R[N-n])
    ans = max(ans, Rt[n] + L[N-n])
print (ans)
    


Measured memory_bytes: 40296
#include<stdio.h>
double abs(double p)
{
    if (p >= 0)
        return p;
    else
        return -p;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[200005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    double sum = 0;
    for (i = 0; i < n; i++)
        sum += a[i];
    double min = 20000000000;
    double x = 0;
    for (i = 0; i < n - 1; i++)
    {
        x += a[i];
        if (abs(sum - x - x) < min)
            min = abs(sum - x - x);
    }
    printf("%.0lf\n",min);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    cin >> N;
    VLL C(N),S(N),F(N);
    rep(i,N-1){
        cin >> C[i] >> S[i] >> F[i];
    }
    rep(i,N){
        ll time=S[i];
        time+=C[i];
        rept(j,i+1,N-1){
            if(time<S[j]){
                time=S[j];
                time+=C[j];
                continue;
            }
            else{
                if((time-S[j])%F[j]==0){
                    time+=C[j];
                    continue;
                }
                else{
                    time+=F[j]-(time-S[j])%F[j];
                    time+=C[j];
                    continue;
                }
            }
        }
        cout << time << endl;
    }
}

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

int main(){
	string S;
	cin >> S;
	int cnt, min_cnt, n;
	n = S.length();
	cnt = 0;
	for(int i=0; i<n; i++){
		if(i%2==0 && S[i]=='0'){
			cnt++;
		}
		if(i%2==1 && S[i]=='1'){
			cnt++;
		}
	}
	min_cnt = cnt;
	cnt = 0;
	for(int i=0; i<n; i++){
		if(i%2==0 && S[i]=='1'){
			cnt++;
		}
		if(i%2==1 && S[i]=='0'){
			cnt++;
		}
	}
	min_cnt = min(min_cnt, cnt);
	cout << min_cnt << endl;
	return 0;
}


Measured memory_bytes: 512
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
f=lambda x:(x[0],int(x[1]),x[2])
A=[(*e.split(),i)for i,e in enumerate(sys.stdin)]
A=list(map(f,A))
k(A,0,n-1)
for e in[[s(A)+'table']]+A:print(*e[:2])


Measured memory_bytes: 33684
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

A, B, C, D = map(int, input().split())

a = (A - 1) // C
b = B // C

c = (A - 1) // D
d = B // D

l = lcm(C, D)

e = (A - 1) // l
f = B // l
    
res = (B - A + 1) - ((b - a) + (d - c) - (f - e))

print(res)

Measured memory_bytes: 3064