akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 == m2) cout << 0 << endl;
    else cout << 1 << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
datemax = int(input())
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for l in range(datemax):
    k,j,i,v = [int(x) for x in input().split()]
    count[k - 1][j - 1][i - 1] += v
for k in range(4):
    for j in count[k]:
        print(" "+" ".join([str(x) for x in j]))
    if k != 3:
        print("".join(["#" for x in range(20)]))


Measured memory_bytes: 5608
n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]

red.sort(key=lambda x: x[0], reverse=True)
blue.sort(key=lambda x: x[1])

paired = [0] * n
for a, b in red:
    for i, (c, d) in enumerate(blue):
        if a < c and b < d and not paired[i]:
            paired[i] = 1
            break

print(sum(paired))

Measured memory_bytes: 3064
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const h = arg[1].split(" ").map(n=>parseInt(n));
    
    const state = [...Array(N)].fill(0);
    let answer  = 0;
    let action  = 0;
    
    for(let i=0; i<N; i++) {
        if(action >= h[i]) {
            action = h[i];
        } else {
            answer += h[i] - action;
            action = h[i];
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  long long n, k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  std::vector<long long> f(n);
  for (int i = 0; i < n; ++i)
    std::cin >> a[i];
  for (int i = 0; i < n; ++i)
    std::cin >> f[i];

  std::sort(a.begin(), a.end(), std::greater<long long>());
  std::sort(f.begin(), f.end());

  auto isOK = [&](long long val) {
    long long res = 0;
    for (int i = 0; i < n; ++i) {
      long long current = a[i] * f[i];
      long long vol = std::max(current - val, 0LL);
      long long tmp = (vol + f[i] - 1) / f[i];
      res += std::min(tmp, a[i]);
    }
    if (res <= k)
      return true;
    else
      return false;
  };

  long long ng = -1;
  long long ok = LINF;
  while (ok - ng > 1) {
    long long mid = ng + (ok - ng) / 2;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }

  std::cout << ok << std::endl;

  return 0;
}


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

const int MAX_N = 30;
const int MAX_M = 30;

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

    int N, M, K;
    cin >> N >> M;
    int A[MAX_M] = {};

    int tmp1;
    for (int i = 0; i < N; i++) {
        cin >> K;
        for (int j = 0; j < K; j++) {
            cin >> tmp1;
            A[tmp1 - 1]++;
        }
    }
    int count = 0;
    for (int i = 0; i < M; i++) {
        if (A[i] == N) count++;
    }

    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 256
N = int(input())

s = []
for i in range(N):
    s.append(int(input()))

s.sort()
res = sum(s)

if res%10 != 0:
    print(res)
    exit()
else:
    for i in range(N):
        if s[i]%10 != 0:
            print(res-s[i])
            exit()

print(0)

Measured memory_bytes: 2940
# ABC158D

s = input()
q = int(input())
ht = 1
head = ''
tail = ''
count = 0
for i in range(q):
    txt3 = input().split()
    if txt3[0] == '1':
        ht = 3 - ht
        count += 1
    else:
        if int(txt3[1]) == ht:
            head = txt3[2] + head
        else:
            tail = tail + txt3[2]
s = head + s + tail
if count % 2 == 1:
    s = s[::-1]
print(s)


Measured memory_bytes: 10036
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<vecint> g(n);
  for(int i:irange(0,m)) {
    int s,t;
    cin>>s>>t;
    --s;--t;
    g[s].push_back(t);
  }
  vector<vector<double>> coeff(n, vector<double>(n, 0.0));
  for(int i:irange(0,n)) {
    coeff[i][i] = 1.0;
  }
  constexpr double INF = 1e18;
  vector<double> e(n, INF);
  e.back() = 0.0;
  for (int i=n-2; i>=0; --i) {
    double sum = 0.0;
    for(int nx:g[i]) {
      sum += e[nx] / g[i].size();
      for(int j:irange(0,n)) {
        coeff[i][j] += coeff[nx][j] / g[i].size();
      }
    }
    e[i] = sum + 1.0;
  }
  double mx = 0.0;
  for (int i:irange(0,n-1)) {
    if (g[i].size() < 2) continue;
    double localmx = 0.0;
    double sum = 0.0;
    for (int nx:g[i]) {
      double val = e[nx] / g[i].size();
      localmx = std::max(localmx, val);
      sum += val;
    }
    double tmp = sum - localmx;
    double scaled = tmp * g[i].size() / (g[i].size() - 1);
    mx = std::max(mx, coeff[0][i] * (sum - scaled));
  }
  cout<<fixed<<setprecision(10)<<e[0] - mx<<endl;
  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int lists[2][n];
    int a;
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin >> a;
            lists[i][j] = a;
            if(i>0){
                if(j>0)
                    lists[i][j] += max(lists[i][j-1], lists[i-1][j]);
                else lists[i][j] += lists[i-1][j];
            }else if(j>0)
                lists[i][j] += lists[i][j-1];
        }
    }
    
    cout << lists[1][n-1] << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
from collections import deque 
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
INF = 1 << 32
d = [INF] * n
d[0] = 0
q = deque([0])
while q:
    v = q.popleft()
    for e in es[v]:
        if d[e] == INF:
            d[e] = d[v] + 1
            q.append(e)
d2 = [INF] * n
q.append(n - 1)
d2[n - 1] = 0
while q:
    v = q.popleft()
    for e in es[v]:
        if d2[e] == INF and d2[v] + 1 < d[e]:
            d2[e] = d2[v] + 1
            q.append(e)

print("Fennec" if 2 * sum(1 for i in d2 if i < INF) < n else "Snuke")

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

using namespace std;

struct Edge {
    int u, v, c;
    Edge(int u_, int v_, int c_) {
        u = u_; v = v_; c = c_;
    }
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int l; cin >> l; --l;

    int n = 1;
    vector <Edge> ans;
    vector <pair <int, int> > add;
    while (l) {
        if (l % 2 == 0) {
            ans.push_back(Edge(n, n + 1, 0));
            add.push_back({n, (l >> 1)});
            ans.push_back(Edge(n, n + 1, (l >> 1) + 1));
            l = (l >> 1) - 1;
        }
        else {
            ans.push_back(Edge(n, n + 1, 0));
            ans.push_back(Edge(n, n + 1, (l >> 1) + 1));
            l = (l >> 1);
        }
        ++n;
    }

    cout << n << ' ' << ans.size() + add.size() << '\n';
    for (auto e : ans) {
        cout << e.u << ' ' << e.v << ' ' << e.c << '\n';
    }
    for (auto e : add) {
        cout << e.first << ' ' << n << ' ' << e.second << '\n';
    }

    return 0;
}


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

int main(){
    int n, j, v = 0;
    cin >>n;
    int num[n];
    for(int i = 0; i < n; i++){
        cin >>num[i];
        if(i != 0)cout << " ";
        cout << num[i];
    }
    cout << endl;
    for(int i = 1; i < sizeof(num)/sizeof(int); i++){
        v = num[i];
        j = i - 1;
        while(j >= 0 && num[j] > v){
            num[j + 1] = num[j];
            j--;

        }
        num[j + 1] = v;
        for(int k = 0; k < sizeof(num)/sizeof(int); k++){
            if(k != 0)cout << " ";
            cout << num[k];
        }
        cout << endl;
    }

}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using ll = long long;
using namespace std;


bool good(string t) {
   bool ok = true;
   for(auto &c: t) {
      bool found = false;
      for(auto &e: vector <int> ({'A', 'C', 'G', 'T'})) {
         if(c == e) found = true;
      }
      ok &= found;
   }
   return ok;
}

void solve() {
   string s;
   cin >> s;
   int n = s.length();
   int ans = 0;
   for(int i = 0; i < n; i++) {
      for(int j = i; j < n; j++) {
         string t = s.substr(i, j - i + 1);
         if(good(t)) {
            ans = max(ans, j - i + 1);
         }
      }
   }
   cout << ans << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
typedef long long ll;

ll f(ll a) {
	ll n = (a + 1) / 2;
	ll x = (n & 1) ? 1 : 0;
	x ^= (a & 1) ? 0 : a;
	return x;
}

int main() {
	ll a, b; cin >> a >> b;
	cout << (f(a - 1) ^ f(b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 10001;

int main(void){
    vector<bool> isP(N);
    fill(ALL(isP), true);
    rep(i, 2) isP[i] = false;
    for(int i = 2; i * i < N; i ++) if(isP[i]) for(int j = i * i; j < N; j += i) isP[j] = false;

    for(int n, cnt; cnt = 0, cin >> n; cout << cnt << endl)
        rep(i, n) if(isP[1 + i] && isP[n - i]) cnt ++;

    return 0;
}

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

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

ostream &operator<<(ostream &os, const pair<char, int> &unit) {
  return os << unit.first << "^" << unit.second;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 200010;

int n;
vector<int> g[N];
int prt[N], mx[N], ans[N];
bool vis[N];

void dfs(int u) {
  vis[u] = true;
  for (int v : g[u])
    if (!vis[v]) {
      prt[v] = u;
      mx[v] = max(mx[u], u);
      dfs(v);
    }
}

int f(int u, int x) {
  static map<pair<int, int>, int> memo;
  auto it = memo.find(make_pair(u, x));
  if (it == memo.end()) {
    int ret = 1;
    for (int v : g[u])
      if (prt[v] == u && v < x)
        ret += f(v, x);
    it = memo.insert(make_pair(make_pair(u, x), ret)).first;
  }
  return it->second;
}

void dfs2(int u) {
  if (u != 1) {
    if (u > mx[prt[u]])
      ans[u] = ans[prt[u]] + f(u, mx[u]);
    else
      ans[u] = ans[prt[u]] + f(u, mx[u]) - f(u, mx[prt[u]]);
  }
  for (int v : g[u])
    if (prt[v] == u)
      dfs2(v);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  dfs2(1);
  cout << vi(ans + 2, ans + n + 1);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
      -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
ll dp[2][100010];

int main() {
  string s;
  cin>>s;
  dp[0][0] = 1;
  dp[1][0] = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      dp[1][i + 1] = dp[1][i] * 3 % mod;
      dp[0][i + 1] = dp[0][i];
    } else {
      dp[1][i + 1] = (dp[1][i] * 3 + dp[0][i]) % mod;
      dp[0][i + 1] = 2 * dp[0][i] % mod;
    }
  }
  ll ans = (dp[0][s.size()] + dp[1][s.size()]) % mod;
  cout<<ans<<endl;
  return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, a;
  cin >> n >> a;

  vll x(n);
  REP(i, n)
    cin >> x[i];

  vector<vector<vll>> dp(n+2, vector<vll>(n+2, vll((n+2)*50, 0)));


  dp[0][0][0] = 1; 
  for(int i = 1; i <= n; i++){
    for(int j = 0; j <= i; j++){
      if(j == 0){
        dp[i][j][0] = 1;
        continue;
      }
      for(int s = 1*j; s <= 50*j; s++){
        //x[i-1] is index, but i means pick mount.
        if(s >= x[i-1])
          dp[i][j][s] = dp[i-1][j-1][s-x[i-1]] + dp[i-1][j][s];
        else
          dp[i][j][s] = dp[i-1][j][s];
      }
    }
  }

  ll ans = 0;
  for(int j = 1; j <= n; j++){
    ans += dp[n][j][a*j];
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 56320
import java.util.Scanner;

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

            String s  = sc.nextLine();
            String alp = "abcdefghijklmnopqrstuvwxyz";
            int count = 0;

            for(int i = 0; i < alp.length(); i++){
                if(s.indexOf(alp.substring(i,i+1)) == -1){
                    System.out.println(alp.substring(i,i+1));
                    count++;
                    break;
                }
                else{
                    continue;
                }
            }
            if(count == 0){
                System.out.println("None");
            }   

            sc.close();
		  }
}

Measured memory_bytes: 28208
#include <iostream>

using namespace std;
typedef long long lint;

void resolve()
{
    lint a, b, c;
    cin >> a >> b >> c;

    lint d = c - a - b;
    if (d < 0) {
        cout << "No" << endl;
        return;
    }

    lint tmp1 = 4 * a * b;
    lint tmp2 = d * d;

    string ans = (tmp1 < tmp2) ? "Yes" : "No";
    cout << ans << endl;
}

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


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

int main(){
  int N; cin >> N;
  string s;cin >> s;
  int r=0, b=0;
  for(auto k: s){
    if (k=='B') b++;
    else r++;
  }
  if (r>b) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let n: usize = iter.read();
	let d: usize = iter.read();

	let mut dots: Vec<Vec<i64>> = vec![vec![0; d]; n];

	for m in 0..n {
		for t in 0..d {
			let p = iter.read();
			dots[m][t] = p;
		}
	}
	let mut c = 0;
	for m1 in 0..n - 1 {
		for m2 in m1 + 1..n {
			let mut p = 0;
			for t in 0..d {
				let q = dots[m1][t] - dots[m2][t];
				p += q * q;
			}
			let q = (p as f64).sqrt() as i64;
			if q * q == p {
				c += 1;
			}
		}
	}

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


Measured memory_bytes: 4352
#define MAX(a,b) (a > b) ? a : b
int main(){
   int a,b;scanf("%d %d",&a,&b);
   if(a == 1)a += 13;
   if(b == 1)b += 13;
   if(a == b)printf("Draw\n");
   else if(a > b)printf("Alice\n");
   else printf("Bob\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>>
using namespace std;
int main()
{
    int h,n,k,sum=0;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        cin>>k;
        sum=sum+k;
    }
    if(sum>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K;
  string S;
  cin>>K>>S;
  if(S.size()<=K){
    cout<<S<<endl;
  }else{
    string s;
    for(int i;i<K;i++){
      s=s+S[i];
    }
    cout<<s<<"..."<<endl;
  }
}   

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
class Solution
{
public:
    void solve()
    {
        int n;
        cin >> n;
        list<ll> l;
        list<ll>::iterator it = l.begin();
        while(n--)
        {
            int t;
            cin >> t;
            if(!t)
            {
                ll x;
                cin >> x;
                l.insert(it, x);
                --it;
            }
            else if(t & 1)
            {
                ll x;
                cin >> x;
                if(x > 0 )for(int i = 0; i < x && it != l.end(); ++i)++it;
                else for(int i = 0; i < (-x) && it != l.begin(); ++i)--it;
            }
            else
            {
                list<ll>::iterator temp = it;
                if(temp != l.end())++temp;
                l.erase(it);
                it = temp;
            }
        }
        it = l.begin();
        while(it != l.end())
        {
            cout << *it << endl;
            ++it;
        }
    }
};
int main()
{
    Solution s;
    s.solve();
    return 0;
}



Measured memory_bytes: 18640
#include<iostream>
#include<math.h>
using namespace std;

int main(void){
  int n;
  int x[100];
  double m = 0;
  int power = 0;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>x[i];
    m += x[i];
  }
  m = round(m/n);
  for(int i=0; i<n; i++){
    power += (x[i]-m)*(x[i]-m);
  }
  cout<<power<<endl;
  return 0;
}

Measured memory_bytes: 512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum PS = [300000, 200000, 100000];

void main()
{
    auto xy = readln.split.to!(int[]);
    auto X = xy[0];
    auto Y = xy[1];
    int r;
    if (X <= 3) r += PS[X-1];
    if (Y <= 3) r += PS[Y-1];
    if (X == 1 && Y == 1) r += 400000;
    writeln(r);
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll N, X;
ll dp1[51], dp2[51];

ll f(ll n, ll x){
    if(n == 0){
        return 1;
    }

    if(x == 1){
        return 0;
    }else if(x <= dp1[n-1] + 1){
        return f(n - 1, x - 1);
    }else if(x == dp1[n-1] + 2){
        return 1ll + dp2[n-1];
    }else if(x <= 2ll * dp1[n-1] + 2){
        return f(n - 1, x - dp1[n-1] - 2) + 1 + dp2[n-1];
    }
    return 2ll * dp2[n-1] + 1;
}

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

    dp1[0] = 1; // 層数
    dp2[0] = 1; // パティの個数

    for(int i=1;i<=50;++i){
        dp1[i] = 2ll * dp1[i-1] + 3;
        dp2[i] = 2ll * dp2[i-1] + 1;
    }

    std::cin >> N >> X;

    ll res = f(N, X);
    std::cout << res << std::endl;
}


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

int a[100002];
int ans[100002];
int main() {
	int n;
	cin>>n;
	int i;
	for(i=1;i<=n;i++) {
	    cin>>a[i];
	}
	for(i=1;i<=n;i++) {
	    int temp = a[i];
	    if(i%2==0) temp*=-1;
	    ans[1]+=temp;
	}
	for(i=2;i<=n;i++) {
	    ans[i] = 2*a[i-1]-ans[i-1];
	}
	for(i=1;i<=n;i++) cout<<ans[i]<<" ";
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 2048
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

fn main() {
    input!{
        s: chars
    }
    let mut red = 0;
    let mut blue = 0;
    for i in 0..s.len() {
        if s[i] == '0' {
            red += 1;
        } else if s[i] == '1' {
            blue += 1;
        }
    }
    let ans = std::cmp::min(red,blue) * 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
S = list(str(input()))

count = [0]*3

for i in range(N):
    if S[i] == "R":
        count[0] += 1
    elif S[i] == "G":
        count[1] += 1
    else:
        count[2] += 1

ans = count[0]*count[1]*count[2]

for i in range(N):
    for j in range(1,(N-i-1)//2+1):
        if S[i] != S[i+j] and S[i+j] != S[i+2*j] and S[i+2*j] != S[i]:
            ans -= 1
            #print(i,i+j,i+2*j)

print(ans)

Measured memory_bytes: 9216
#include <vector>
#include <map>
#include <iostream>
#include <string>

using namespace std;

string encode(string name, int k){
    string s;
    s+=name[0];
    for(int i=0;i<name.length();i++){
        if(s.length()==k) return s;
        if(name[i]=='a'||name[i]=='i'||name[i]=='u'||name[i]=='e'||name[i]=='o'){
            s+=name[i+1];
        }
    }
    return s;
}

int main(){
    int n;
    vector<string> S;
    map<string,int> M;
    while(cin>>n,n){
        S.clear();
        for(int i=0;i<n;i++){
            string str;
            cin>>str;
            S.push_back(str);
        }
        int k=1;
        while(true){
            M.clear();
            for(auto &s:S){
                string code=encode(s,k);
                if(M.find(code)!=M.end()){
                    M.clear();
                    break;
                }else{
                    M[code]=0;
                }
            }
            if(!M.empty()){
                cout<<k<<endl;
                break;
            }else{
                k++;
                if(k>50){
                    cout<<-1<<endl;
                    break;
                }else{
                    continue;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 1000005;

vector<int> freq(N,0);
vector<bool> mark(N,true);


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS


    int n;
    cin >> n;

    vector<int> v(n);

    for(int i = 0; i < n; i++)
    {
    	cin >> v[i];
    	freq[v[i]]++;
    }

    int ans = 0;

    for(int i = 1; i < N; i++)
    {
    	if(freq[i])
    	{
    		if(freq[i] > 1)mark[i] = false;
    		for(int j = 2*i; j < N; j+= i)mark[j] = false;
    	}
    }


    for(auto i : v)ans += mark[i];


   	cout << ans;





    return 0;
}


Measured memory_bytes: 12676
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
const int INF = 1e9 + 5;
#define ll long long
#define EMPTY (LONG_MAX)
int main() {
	int N, W;
	cin>>N>>W;
	vector<ll> w(N), v(N);
	ll maxV = 0;
	for(int i=0;i < N; i++) {
		cin>>w[i]>>v[i];
		maxV += v[i];
	}
	// this time value <= 10^3  --> N*v[i] is maximum value
	// 10^5 --> dp[V] = minimum weight with which a value V can be created
	// dp[j] --> min weight to create j
	// dp[j + v[i] ] <-- min(dp[j+v[i]], dp[j] + w[i]) 
	//  ALL EMPTY
	// dp[0] = 0;
	// 0 = 0
	// 3  1000
	// 2   5
	// 1   2
	// 0 ->0 3 --> 1000
	// 2 --> 5, 3 -> 1000, 5--> 1005
	// 1 --> 2 , 2--> 5, 3--> 7, 5--> 1005
	//dp[V] = min(dp[V], dp[V - v[i]] + w[i]);
	vector<ll> dp (maxV+1, EMPTY);
	dp[0] = 0;
	for(int i=0;i<N; i++) {
		for(int j = maxV; j >=0; j --) {
			if(j-v[i]>=0 && dp[j-v[i]] != EMPTY)
			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
		}
	}
	for(int j = maxV; j>=0; j--) {
		if(dp[j] != EMPTY && dp[j] <= W) {
			cout<<j<<endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    int n,i,num=0;
    cin >> n;
    char s[n];
    for (i=0;i<n;i++){
        cin >> s[i];
    }
    for (i=0;i<n-2;i++){
        if (s[i] == 'A'&& s[i+1] == 'B' & s[i+2] == 'C'){
            num++;
        }
    }
    cout << num;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

int MOD = 1000000007;
template<typename T>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
};
template<typename T>
ostream& operator<<(ostream &os,Mint<T> m){os<<m.v;return os;}

//INSERT ABOVE HERE

using M = Mint<int>;
M dp[202][11][1<<10]={};
M nx[202][11][1<<10]={};

signed main(){
  int n,k;
  cin>>n>>k>>MOD;

  for(int i=0;i<k;i++)
    dp[1][i][1<<i]=1;

  for(int i=1;i<n;i++){
    for(int a=0;a<202;a++)
      for(int b=0;b<11;b++)
        for(int c=0;c<(1<<10);c++)
          nx[a][b][c]=M(0);

    for(int a=0;a<202;a++){
      for(int b=0;b<11;b++){
        for(int c=0;c<(1<<10);c++){
          if(dp[a][b][c].v==0) continue;
          int na=a+1;
          while((c>>(na-(a+1)))&1) na++;
          if(na>a+k) continue;

          int nc=c>>(na-a);
          for(int nb=0;nb<k;nb++){
            if((nc>>nb)&1) continue;
            if(a+1+b>=na+1+nb) continue;
            if(a+1+b+k<na+1+nb) continue;
            nx[na][nb][nc|(1<<nb)]+=dp[a][b][c];
          }
        }
      }
    }

    for(int a=0;a<202;a++)
      for(int b=0;b<11;b++)
        for(int c=0;c<(1<<10);c++)
          dp[a][b][c]=nx[a][b][c];
  }

  M ans{0};
  for(int a=0;a<202;a++){
    for(int b=0;b<11;b++){
      for(int c=0;c<(1<<10);c++){
        if(dp[a][b][c].v==0) continue;
        int na=a+1;
        while((c>>(na-(a+1)))&1) na++;
        int nc=c>>(na-a);
        if((a+1+b==2*n)&&(na==2*n+1)&&(nc==0)) ans+=dp[a][b][c];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 20912
import math
I=int
j=input
q=I(j())
for i in[0]*q:
	a,b=map(I,j().split())
	c=I(math.sqrt(a*b))
	if c*(c+1)<a*b:print(2*c-1)
	elif (a*b==c*c)*(a!=b):print(2*c-3)
	else:print(2*c-2)


Measured memory_bytes: 3060
import sys
import numba

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@numba.njit
def main(N):
    x = 0
    for a in range(1, N+1):
        for b in range(1, N//a+1):
            x += a*b
    return x

N = int(read())
print(main(N))


Measured memory_bytes: 109164
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

const p = 10^9+7

function main()
	n,k = readline() |> split |> parseMap
	ans = 0
	b = zeros(Int,n+2)
	for i in 1:n+1
		b[i+1] = b[i]+i-1
	end
	for i in k:n+1
		ans = (ans+(b[n+2]-b[n+2-i]-b[i+1]+1)%p)%p
	end
	println(ans)
end

main()

Measured memory_bytes: 166648
H, W = map(int, input().split())
a = [[int(x) for x in input().split()] for _ in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        jj = j if i % 2 == 0 else W - 1 - j
        k = 1 if i % 2 == 0 else -1
        if a[i][jj] % 2 == 1:
            if 0 <= jj+k <= W-1:
                ans.append((i+1, jj+1, i+1, jj+k+1))
                a[i][jj+k] += 1
            else:
                if i+1 == H:
                    break
                ans.append((i+1, jj+1, i+1+1, jj+1))
                a[i+1][jj] += 1
print(len(ans))
for i in ans:
    for j in range(4):
        print(i[j], end="")
        if j != 3:
            print("", end=" ")
        else:
            print("")


Measured memory_bytes: 27116
#include <bits/stdc++.h>
using namespace std;
int len[250];
int n,sum=0;
int main(){
	cin>>n;
	for (int i=1;i<=2*n;i++)
	    cin>>len[i];
	sort(len+1,len+n*2+1);
	for (int i=1;i<=n;i++)
	sum=sum+len[2*i-1];
	cout<<sum;
}

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

Measured memory_bytes: 256
/*
 * 
 * */

#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

#define s_time clock_t time_start = clock()
#define t_time cout << double(clock() - time_start) / 1000 << endl

using namespace std;
using namespace __gnu_pbds;

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

const int N = 16;
const int M = 1 << N;

int n;
int a[N][N];
ll group[M], dp[M];

int main(int argc, char** argv) {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(dp, 128, sizeof dp);
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) cin >> a[i][j];
	}
	
	for (int mask = 1; mask < M; ++mask) {
		group[mask] = 0;
		for (int i = 31 - __builtin_clz(i); i >= 0; --i) {
			if (mask >> i & 1) {
				for (int j = i - 1; j >= 0; --j) {
					if (mask >> j & 1) group[mask] += (ll)a[i][j];
				}
			}
		}
	}
	
	dp[0] = 0;
	for (int mask = 1; mask < M; ++mask) {
		dp[mask] = group[mask];
		for (int sub = mask; sub != 0; sub = (sub - 1) & mask) {
			dp[mask] = max(dp[mask], group[sub ^ mask] + dp[sub]);
		}
	}
	cout << dp[M-1];
	
	return 0;
}

/*
 * 
 * */


Measured memory_bytes: 1280
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int A[100][3];
	int max;
	for (int i=0;i<100;i++){
		for (int j=0;j<3;j++){
			cin >> A[i][j];
		}
		if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1 ) {
			max = i;
			break;
		}
	}

	for (int i=0;i<max;i++){
		int sum = (A[i][0]+A[i][1]);
		char grade;
		
		if (A[i][0]*A[i][1]<0)grade = 'F';
		else if (sum >= 80)grade = 'A';
		else if (sum >= 65)grade = 'B';
		else if (sum >= 50)grade = 'C';
		else if (sum >= 30){
			if (A[i][2] >= 50) grade = 'C';
			else grade = 'D';}
		else grade = 'F';
		cout << grade << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
def F(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x
dic = [0]*(10**4+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            temp = F(x,y,z)
            if temp<10**4+1:
                dic[temp] += 1

N = int(input())
for x in range(1,N+1):
    print(dic[x])


Measured memory_bytes: 74612
a_max=0
a_max_next=0
A=[]
N=int(input())

for i in range(N):
    A.append(int(input()))
    if A[i]>a_max:
        a_max=A[i]
    elif A[i]>=a_max_next:
        a_max_next=A[i]

for i in range(N):
    if A[i]==a_max:
        print(a_max_next)
    else:
        print(a_max)

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

int main() {
	int a,b;
	while (cin >> a >> b) {
		int n = 1;
		int sum = a+b;
		while (sum / 10 >= 1){
			n++;
			sum /= 10;
		}
		cout << n << endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0;
  string s;
 
  cin >> n >> m;
  vector<vector<ll>> path(n);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    path[a].pb(b);
    path[b].pb(a);
  }
  vector<bool> flag(n,false);
  vector<ll> ans(n);
  
  queue<ll> q;
  
  q.push(0);
  flag[0]=true;
  while(!q.empty()){
    ll a = q.front();
    q.pop();
    ll size = path[a].size();
    rep(i,size){
      ll b = path[a][i];
      if(flag[b]) continue;
      q.push(b);
      flag[b]=true;
      ans[b]=a;
    }
  }
  bool f=true;
  rep(i,n){
    if(!flag[i]){
      f=false;
      break;
    }
  }
  if(!f) cout << "No" << endl;
  else{
    cout << "Yes" << endl;
    rep2(i,n-1) cout << ans[i]+1 << endl;
  }
 
}

Measured memory_bytes: 12932
import itertools

N, M = (int(i) for i in input().split())
sides = []
for i in range(M):
    a, b = (int(i) for i in input().split())
    sides.append((a-1,b-1))
kouhos = list(itertools.permutations(range(N)))
count = 0

for kouho in kouhos:
    Judge = True
    if kouho[0] != 0:
        break
    else:
        for i in range(N-1):
            if (kouho[i] , kouho[i+1]) in sides:
                pass
            elif (kouho[i+1] , kouho[i]) in sides:
                pass
            else:
                Judge = False
                break
    
    if Judge:
        count += 1

print(count)


    

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

int main(){
    int n, w[101];
    cin >> n;
    for(int i=0;i<n;i++) cin >> w[i];

    int ans = 1000;
    int cumsum[102], rev_cumsum[102];
    cumsum[0] = 0;
    cumsum[1] = w[0];
    rev_cumsum[n-1] = w[n-1];
    for(int i=1;i<=n;i++){
        cumsum[i+1] = cumsum[i] + w[i];
        rev_cumsum[n-i-1] = rev_cumsum[n-i] + w[n-i-1];
    }

    for(int i=0;i<=n;i++){
        // cout << rev_cumsum[i] << endl;
        ans = min(ans, abs(cumsum[i]-rev_cumsum[i]));
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
   int h, w; cin >> h >> w;
   char s[h][w];
   char ans[h][w];

   rep(i, h){
       rep(j, w) cin >> s[i][j];
   }
   
   rep(i, h){
       rep(j, w){
           ans[i][j] = s[i][j];
       }
   }

   int sx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
   int sy[8] = {0, 1, -1, 1, -1, 0, 1, -1};

   rep(i, h){
       rep(j, w){
           int cnt = 0;
           if(s[i][j]=='#'){
               cout << '#';
               continue;
           };
           rep(k, 8){
               if(i+sy[k]<0||i+sy[k]>=h||j+sx[k]<0||j+sx[k]>=w){
                   continue;
               }
               else if(s[i+sy[k]][j+sx[k]]=='#') cnt++;
           }
           cout << cnt;
       }
       cout << endl;
   }
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
char s[maxn];
int n;
int main(){
	scanf("%s",s+1);n=strlen(s+1);

	vector<char>vec;
	vec.push_back(s[1]);
	for(int i=2;i<=n;i++){
		if(s[i]!=s[i-1]){
			vec.push_back(s[i]);
		}
	}
		cout<<vec.size()-1<<endl;


	return 0;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) {
    while(a[i] % 2 == 0) {
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define ll long long
ll calcsub(ll a,ll b,ll m,ll n){
	//x=0,x=n,y=(-ax+b)/m,y=0で囲まれる領域内の格子点
	//ただし、軸上は含まず他の境界は含む
	ll ans=0;
	ll r=(-a*n+b)/m;
	ans=r*n;
	b-=r*m;
	ll d=a/m;
	ans+=n*(n-1)/2*d;
	a-=d*m;
	b-=d*m*n;
	if(a==0)return ans;
	return ans+calcsub(m,b,a,b/m);
}

ll calc(ll a,ll b,ll m,ll n){
	//x=0,x=n,y=(ax+b)/m,y=0で囲まれる領域内の格子点
	//ただし、x=n,y=0上は含まず、x=0,y=(ax+b)/m上は含む
	return calcsub(a,a*n+b,m,n);
}

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b,m,n;
		scanf("%d%d%d%d",&n,&m,&a,&b);
		printf("%lld\n",calc(a,b,m,n));
	}
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, c;
  cin >> a >> b >>c;
  cout << a * b / 2 << endl;
}


Measured memory_bytes: 256
#coding: utf-8
from collections import defaultdict, deque

N = int(input())
G = {}
for i in range(1, N+1):
    G[i] = []

for i in range(N-1):
    u, v, w = (int(n) for n in input().split())
    G[u].append((v, w))
    G[v].append((u, w))

ret = [-1] * (N+1)

que = deque()
que.append((1, 0))

while len(que) > 0:
    node, distance = que[0]
    que.popleft()

    ret[node] = distance % 2
    for next_node, next_distance in G[node]:
        if ret[next_node] == -1:
            que.append((next_node, distance + next_distance))

for i in range(N):
    print(ret[i+1])



Measured memory_bytes: 50576
package main

import (
	"fmt"
	"sort"
)

// TriangleKind kind of triangle
type TriangleKind int

const (
	// Nothing not triangle
	Nothing TriangleKind = iota
	// RightTriangle the right triangle
	RightTriangle
	// SharpTriangle the sharp triangle
	SharpTriangle
	// ObtuseTriangle the obtuse triangle
	ObtuseTriangle
) // const for Triangle kind

type result struct {
	rTriangle int
	sTriangle int
	oTriangle int
}

func (res *result) String() string {
	return fmt.Sprintf("%d %d %d %d", res.rTriangle+res.sTriangle+res.oTriangle, res.rTriangle, res.sTriangle, res.oTriangle)
}

func checkTriangleType(a int, b int, c int) TriangleKind {
	p := []int{a, b, c}
	sort.Sort(sort.IntSlice(p))
	if !(p[0]+p[1] > p[2] && p[1]+p[2] > p[0] && p[2]+p[0] > p[1]) {
		return Nothing
	}

	c = (p[0] * p[0]) + (p[1] * p[1]) - (p[2] * p[2])
	if c == 0 {
		return RightTriangle
	}
	if c > 0 {
		return SharpTriangle
	}
	return ObtuseTriangle
}

func main() {
	var res = new(result)
	var a, b, c int
	var hasNext = true
	for hasNext {
		fmt.Scanf("%d %d %d", &a, &b, &c)
		switch checkTriangleType(a, b, c) {
		case Nothing:
			hasNext = false
		case RightTriangle:
			res.rTriangle++
		case SharpTriangle:
			res.sTriangle++
		case ObtuseTriangle:
			res.oTriangle++
		}
	}
	fmt.Println(res.String())
}



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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n+1);
    a[0]=0;
    FOR(i,1,n+1) {
        cin >> a[i];
    }

    int ans = 0,max=1;
    FOR(i,1,n+1){
        if(max<a[i]){
            ans += a[i]/max;
            a[i] %=max;
            if(max==1){
                a[i]=max;
                ans--;
                max++;
            }else {
                if (a[i] == 0) {
                    a[i] = max-1;
                    ans--;
                }
            }
        }else if(max==a[i]){
            max=a[i]+1;
        }
    }

    cout << ans << ENDL;
    
    return 0;
}

Measured memory_bytes: 1280