akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  bool valid = true;

  for (int i = 0, size = S.size(); i < size; i ++) {
    char c = S[i];

    if (i % 2 == 0) {
      if (c == 'L')
        valid = false;
    }
    else {
      if (c == 'R')
        valid = false;
    }
  }

  std::cout << (valid ? "Yes" : "No") << std::endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = 2e5+500;

vector<int >A[maxn];
int son[maxn];
int father[maxn];

int main()
{
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		A[x].push_back(y);
		father[y]=x;
	}
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		son[x]+=y;
	}
	ll sum = 0;
	for(int i=1;i<=n;i++){
		son[i] += son[father[i]];
		cout<<son[i]<<" ";
	}
}


Measured memory_bytes: 14848
s=input()
t=""
i=0
while i<len(s):
    if s[i:i+2]=="BC":
        t+="T"
        i+=2
    else:
        t+=s[i]
        i+=1
ans=0
Acnt=0
for i in t:
    if i=="A":
        Acnt+=1
    elif i=="T":
        ans+=Acnt
    else:
        Acnt=0
print(ans)


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  cout << ((a * b) & 1 ? "Odd" : "Even") << endl;
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    cities = []
    for _ in range(3):
        cities.extend(get_int_list())

    counter = Counter()
    for c in cities:
        counter[c] += 1
    c2 = Counter()
    for v in counter.values():
        c2[v] += 1
    if list(c2.values()) == [2, 2]:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

typedef long long LL;
const int M=305;
const LL INF=(LL)M*(1000000000);

LL dp[M]; // dp[i][j] i block end at j
// if k=0 ans=\sum_{1~n} {h[i]-h[i-1]} (h[0]=0)
// if k>0 should change k blocks as the left one of themselves

LL h[M];

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&h[i]);
	for(int i=1;i<=n;i++)
		dp[i]=INF;
	for(int i=1;i<=n-k;i++)
	{
		for(int j=n;j>=i;j--)
		{
			dp[j]=INF;
			for(int k=i-1;k<j;k++)
				dp[j]=min(dp[j],dp[k]+max(0LL,h[j]-h[k]));
			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	LL ans=INF;
	for(int i=n-k;i<=n;i++)
		ans=min(ans,dp[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<long long> S(N + 1, 0);
    rep(i, N) S[i + 1] = S[i] + A[i];
    sort(S.begin(), S.end());
    long long ans = 0;
    rep(i, N + 1) {
        auto iter0 = lower_bound(S.begin(), S.begin() + i, S[i]);
        auto iter1 = upper_bound(S.begin(), S.begin() + i, S[i]);
        ans += distance(iter0, iter1);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	int prime[n+1];
	int pr[n+1],x=0;
	int pri[n+1];
	for(int i=1;i<=n;i++){
		prime[i]=0;
		pri[i]=0;
	}
	for(int i=2;i<=n;i++){
		if(!prime[i]){
			x++;
			pr[x]=i;
			for(int j=i+i;j<=n;j+=i){
				prime[j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		int p=i;
		for(int j=1;j<=x;j++){
			while(p%pr[j]==0){
				p/=pr[j];
				pri[pr[j]]++;
			}
		}
	}
	long long p=1;
	for(int i=1;i<=n;i++){
		p*=(pri[i]+1);
		p%=1000000007;
	}
	cout<<p<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline int arrcmp(int As, S A[], int Bs, T B[]){
  int i;
  for(i=0;;i++){
    if(i==As && As==Bs){
      break;
    }
    if(i==As){
      return -1;
    }
    if(i==Bs){
      return 1;
    }
    if(A[i] < B[i]){
      return -1;
    }
    if(A[i] > B[i]){
      return 1;
    }
  }
  return 0;
}
char S[100002];
int N;
int main(){
  N = rd(S);
  while(N){
    if(N>=5 && arrcmp(5, S+N-5, 5, "dream")  ==0){
      N -= 5;
      continue;
    }
    if(N>=7 && arrcmp(7, S+N-7, 7, "dreamer")==0){
      N -= 7;
      continue;
    }
    if(N>=5 && arrcmp(5, S+N-5, 5, "erase")  ==0){
      N -= 5;
      continue;
    }
    if(N>=6 && arrcmp(6, S+N-6, 6, "eraser") ==0){
      N -= 6;
      continue;
    }
    break;
  }
  if(N){
    wt_L("NO");
    wt_L('\n');
  }
  else{
    wt_L("YES");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190829-1

// --- original code ---
// char S[100002];
// int N;
// {
//   rd(S@N);
//   while(N){
//     if(N>=5 && arrcmp(5, S+N-5, 5, "dream")  ==0) N -= 5, continue;
//     if(N>=7 && arrcmp(7, S+N-7, 7, "dreamer")==0) N -= 7, continue;
//     if(N>=5 && arrcmp(5, S+N-5, 5, "erase")  ==0) N -= 5, continue;
//     if(N>=6 && arrcmp(6, S+N-6, 6, "eraser") ==0) N -= 6, continue;
//     break;
//   }
//   wt(if[N,"NO","YES"]);
// }


Measured memory_bytes: 384
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string s = inp1;
    sort(ALL_OF(s));
    cout << Yes(s == "abc") << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
// kurikazu
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
// #include<unordered_set>
using namespace std;
typedef pair<int, int> pii;
int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<pii> > g(n);
  set<pii> s;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(pii(b, c));
    g[b].push_back(pii(a, c));
  }
  
  for (int i = 0; i < n; ++i) random_shuffle(g[i].begin(), g[i].end());
  priority_queue<pii, vector<pii>, greater<pii> > que;
 
  for (int i = 0; i < n; i++) {
    vector<int> cost(n, 1e9);
    vector<int> parent(n, -1);
    que.push(pii(0, i));
    while(not que.empty()){
      int v = que.top().second;
      int c = que.top().first;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        int to = g[v][i].first;
        if(cost[to] > c + g[v][i].second){
          cost[to] = c + g[v][i].second;
          que.push(pii(cost[to], to));
          parent[to] = v;
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if(i == j)continue;
      s.insert(pii(j, parent[j]));
      s.insert(pii(parent[j], j));
    }
  }
  std::cout << m - s.size()/2 << std::endl;
  return 0;
}

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

int main(){
    int N, M, K, S;
    cin >> N >> M;
    vector<int> cnt(N);

    for(int i = 0; i < M; i++){
        cin >> S >> K;
        cnt.at(S-1)++;
        cnt.at(K-1)++;
    }

    for(int i  = 0; i < N; i++){
        cout << cnt.at(i) << endl;
    }
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    ll A,B; cin>>A>>B;
    ll Gcd = __gcd(A,B);

    ll ans = 1;
    for (ll i = 2; i*i <= Gcd; ++i) {
        if(Gcd % i == 0){
            ans++;
            while(Gcd % i == 0){
                Gcd /= i;
            }
        }
    }
    if(Gcd>1){
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	rs := map[string]int{
		"RRR": 3,
		"RRS": 2,
		"RSR": 1,
		"RSS": 1,
		"SRR": 2,
		"SRS": 1,
		"SSR": 1,
		"SSS": 0,
	}
	fmt.Println(rs[s])
}


Measured memory_bytes: 1828
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main()
{
    FAST
    int r,g,b,k;
    cin>>r>>g>>b;
    cin>>k;
    if(g>r && b>g){
        cout<<"Yes"<<endl;
    }
    else{
        while(k--){
            if(g<=r){
                g*=2;
                continue;
            }
            if(b<=g){
                b*=2;
                continue;
            }
        }
        if(g>r && b>g){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    }

    return 0;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int a = Integer.parseInt(in.readLine());
    System.out.println(n*n-a);
  }
}

Measured memory_bytes: 32564
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<int>p(N);
  for (int i=0; i<N; i++) cin >> p[i];
  for (int i=0; i<N; i++) p[i]++;
  int s=0, mx=0;
  queue<int>q;
  for (int i=0; i<N; i++){
    s += p[i];
    q.push(p[i]);
    if (q.size() > K){
      s -= q.front();
      q.pop();
    }
    if (q.size() == K){
      mx = max(s, mx);
    }
  }
    double ans = mx;
    ans /= 2;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main() {
    fast_io

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll c1=(a*c);
    ll c2=(a*d);
    ll c3=(b*c);
    ll c4=(b*d);
    cout<<max(max(c1,c2),max(c3,c4));

    return 0;
}


Measured memory_bytes: 3648
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # pre_sum
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check & pre_len
for i in range(mn):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        cyc = (sum_p - P[X[x]]) * ((n - X[x]) // cyc_len)
        remain = P[X[x] + (n - X[x]) % cyc_len] 
        print(cyc + remain)
        exit()
    P.append(sum_p)
    sum_p += x
    X[x] = i
    x = x*x % m
print(sum_p)


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

int main(){
  int n;
  long long c;
  cin >> n >> c;

  vector<long long> x(n+1);
  vector<long long> v(n+1);

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

  //時計回り→反時計回り
  vector<long long> f(n+1);
  f[0]=0;
  long long dis;
  long long calo=0;
  for (int i = n; i >= 1; i--)
  {
    dis = c-x[i];
    calo += v[i];
    f[i]=calo-dis;
  }

  vector<long long> g(n+1);
  g[0]=0;
  long long maxcal=0;
  for (int i = n; i >= 1; i--)
  {
    g[i]=max(maxcal,f[i]);
    maxcal=g[i];
  }
  long long ans1 = 0;
  long long sumcalr = 0;
  for (int i = 0; i < n; i++)
  {
    sumcalr = v[i]+sumcalr;
    long long res = sumcalr - x[i]*2 + g[i+1];
    ans1 = max(ans1,res);
  }

  //反時計回り→時計回り
  f[0]=0;
  calo=0;
  for (int i = 1; i <= n; i++)
  {
    dis = x[i];
    calo += v[i];
    f[i]=calo-dis;
  }

  maxcal=0;
  for (int i = 1; i <= n; i++)
  {
    g[i]=max(maxcal,f[i]);
    maxcal=g[i];
  }

  long long ans2 = 0;
  sumcalr = 0;
  for (int i = n; i >= 0; i--)
  {
    long long res;
    if (i==0) {
      res = g[n];
    }
    else 
    {    
      sumcalr = v[i]+sumcalr;
      res = sumcalr - (c-x[i])*2 + g[i-1];
    }
    ans2 = max(ans2,res);
  }
  cout << max(ans1,ans2) << endl;
}

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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    ll n;
    cin >> n;
    vector<bool> B(n + 1, true);
    vector<ll> mf(n + 1, -1);
    for (ll i = 2; i <= n; ++i) {
        if (!B[i])continue;
        mf[i] = i;
        for (ll j = i * 2; j <= n; j += i) {
            B[j] = false;
            if (mf[j] == -1)mf[j] = i;
        }
    }
    ll ans = 0;
    for (ll k = 2; k <= n; ++k) {
        map<int, int> m;
        ll x = k;
        while (x != 1) {
            ll pr = mf[x];
            while (mf[x] == pr)x /= pr, m[pr]++;
        }
        ll p = 1;
        for (auto l:m)p *= (l.second + 1);
        ans += k * p;
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 82728
from bisect import bisect_left, bisect_right
a, b, q = list(map(int, input().split()))
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
for i in range(q):
  x = int(input())
  ss = bisect_left(s, x)
  tt = bisect_left(t, x)
  d1, d2, d3, d4 = 1e12, 1e12, 1e12, 1e12
  if ss-1>=0 and tt-1>=0:
    d1 = max((x-s[ss-1]), (x-t[tt-1]))
  if ss-1>=0 and tt<b:
    d2 = (x-s[ss-1])+(t[tt]-x)+min((x-s[ss-1]), (t[tt]-x))
  if ss<a and tt-1>=0:
    d3 = (s[ss]-x)+(x-t[tt-1])+min((s[ss]-x), (x-t[tt-1]))
  if ss<a and tt<b:
    d4 = max((s[ss]-x), (t[tt]-x))
  ans = min(d1, d2, d3, d4)
  print(ans)

Measured memory_bytes: 12076
#include <iostream>

using namespace std;

int main(void){
    
    int A, B;
    int flag = 0; //flagの初期化を忘れた結果、flagに1が最初から入っていた場合失敗する?
    
    cin >> A >> B;
    if(A % 3 == 0 ) flag = 1;
    if(B % 3 == 0 ) flag = 1;
    if((A+B)%3 == 0 )flag = 1;
   
    if(flag == 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    
    return 0;
}



Measured memory_bytes: 256
//4
#include <bits/stdc++.h>
using namespace std;
int nxt[30005][10];

int main(){
	int n;
	string str;
	cin>>n>>str;
	for(int i=0;i<10;i++) nxt[n][i]=n;
	for(int i=n-1;i>=0;i--) 
	{
		for(int j=0;j<10;j++) nxt[i][j]=nxt[i+1][j];
		int a=str[i]-'0';
		nxt[i][a]=i;
	}
//	for(int i=0;i<=n;i++){
//		for(int j=0;j<10;j++){
//			printf("%3d",nxt[i][j]);
//		}
//		printf("\n");
//	}
	int ret=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			for(int k=0;k<10;k++)
			{
				int now=nxt[0][i];
				now++;
				now=nxt[min(now,n)][j];
				now++;
				now=nxt[min(now,n)][k];
				if(now<n){
					//cout<<i<<" "<<j<<" "<<k<<endl;
					ret++;
				} 
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}

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

typedef long long int int64;
static const int64 mod = 1000000007LL;

int n,m;
char s[200003];
int64 dp[200003],rdp[200003];
int64 solve(int n,int m) // divide circle of n into sections not longer than m
{
	dp[0] = rdp[0] = 1;
	for(int i = 1;i <= n;++i) {
		dp[i] = (rdp[i-1] - (i>=m+1?rdp[i-m-1]:0)) % mod;
		rdp[i] = (rdp[i-1] + dp[i]) % mod;
	}
	int64 ans = 0;
	for(int i = 1;i <= m;++i) {
		ans += (n-i>=0?rdp[n-i]:0) - (n-m-1>=0?rdp[n-m-1]:0);
	}
	return ans % mod;
}
int main()
{
	scanf("%d%d ",&n,&m);
	for(int i = 0;i < m;++i) {
		s[i] = getchar() == 'R' ? 0 : 1;
	}
	int len = 1;
	int maxlen = -1;
	for(int i = 1;i < m;++i) {
		s[i] ^= s[0];
		if(s[i] == 0) ++len;
		else {
			if(len == i) maxlen = (len%2==0?len+1:len);
			else if(len % 2 == 1) maxlen = std::min(maxlen,len);
			len = 0;
		}
	}
	int64 ans;
	if(len == m) {
		switch(n) {
		case 1: {
			ans = 1;
			break;
		}
		case 2: {
			ans = 3;
			break;
		}
		default: {
			dp[0] = dp[1] = 1;
			for(int i = 2;i <= n+1;++i) {
				dp[i] = (dp[i-1] + dp[i-2]) % mod;
			}
			ans = dp[n+1]-dp[n-3];
			break;
		}}
	} else {
		if(n%2==1) {
			ans = 0;
		} else {
			ans = solve(n/2,(maxlen+1)/2)*2;
		}
	}
	ans %= mod;
	if(ans < 0) ans += mod;
	printf("%lld\n", ans);
}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main() {
	int n;
	int i;
	int card[4][13] = { {} };
	cin >> n;
	char a;
	int b;
	for (i = 0; i < n; i++) {
		cin >> a >> b;
		switch (a) {
		case 'S':
			card[0][b - 1] = 1;
			break;
		case 'H':
			card[1][b - 1] = 1;
			break;
		case 'C':
			card[2][b - 1] = 1;
			break;
		case 'D':
			card[3][b - 1] = 1;
			break;
		}
	}
	for (i = 0; i < 52; i++) {
		switch (i / 13) {
		case 0:
			if (card[0][i % 13] == 0) cout << "S " << i + 1 << endl;
			break;
		case 1:
			if (card[1][i % 13] == 0) cout << "H " << i % 13 + 1 << endl;
			break;
		case 2:
			if (card[2][i % 13] == 0) cout << "C " << i % 13 + 1 << endl;
			break;
		case 3:
			if (card[3][i % 13] == 0) cout << "D " << i % 13 + 1 << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
 
// Shabdan Batyrkulov
 
using namespace std;
 
#define MAX 1007
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double
#define vi vector <int>
#define pii pair <int, int>
#define OK puts("OK");
 
const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
                  
int main () {        
	int n; cin >> n;
	int a[n + 1];
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; sum += a[i];
	}
	sort(a + 1, a + n + 1);
	if (sum % 10 == 0) {   
		for (int i = 1; i <= n; i++) {
			if (a[i] % 10 != 0) {
				cout << sum - a[i];
				return 0;
			}
		}
		cout << 0;
	} else {
		cout << sum;
	}
}


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

int a[105][105];
int match[N];
int vis[N];
int n;
struct Node{
    int x,y;
}node[N],node1[N];

bool Hungary(int x){
    for(int i=0;i<n;i++){
        if(!vis[i]&&a[x][i]){
            vis[i]=1;
            if(match[i]<0||Hungary(match[i])){
                match[i] = x;
                return true;
            }
        }
    }
    return false;
}

int solve(){
    int ans = 0;
    memset(match,-1,sizeof(match));
    for(int i=0;i<n;i++){
        memset(vis,0,sizeof(vis));
        if(Hungary(i))
            ans++;
    }
    return ans;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>node[i].x>>node[i].y;
    }
    for(int i=0;i<n;i++)
        cin>>node1[i].x>>node1[i].y;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(node[i].x<node1[j].x&&node[i].y<node1[j].y){
                a[i][j] = 1;
            }
        }
    cout<<solve()<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt(), M = fs.nextInt();
		int a[] = new int[M+1];
		for(int i=0;i<M;i++)a[i] = fs.nextInt();
		a[M]=(int)1e9;
		Arrays.sort(a);
		
		int cnt = 0;
		
		long dp[] = new long[N+1];
		dp[0] = 1;
		if(a[0]==1) {
			dp[1]=0;
			cnt++;
		}else {
			dp[1]=1;
		}
		for(int i=1;i<N;i++) {
			if(cnt<M&&a[cnt]==i+1) {
				dp[i+1]=0;
				cnt++;
			}else {
				dp[i+1] += dp[i];
				dp[i+1] %= mod;
				dp[i+1] += dp[i-1];
				dp[i+1] %= mod;
			}
		}
		System.out.println(dp[N]);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 34420
[*$<][0..-2].map{|s|
    c=0;t=0;
    s.split.map(&:to_i).map{|a|c+=1 if a==1;t+=[a,10].min if a>1;};
    p [*0..c].map{|i|a=t+i+(c-i)*11;a=0 if a>21;a}.max
}


Measured memory_bytes: 6912
A, B, C = list(map(int, input().split()))
K = int(input())

count = 0
count2 = 0

for i in range(100):
    if A < B:
        break
    B = B * 2
    count += 1

for i in range(100):
    if B < C:
        break
    C = C * 2
    count2 += 1

if K >= count + count2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9192
#include <stdio.h>
#include <string.h>
#include <utility>
#include <queue>
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> PP;

P ls, rs, lg, rg;
int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0}, h, w;
bool f[52][52][52][52];
char lf[52][53],rf[52][53]; 

int range(int a,int b){
	return a >= 0 && a < h && b >= 0 && b < w;
}

int bfs(){
	int i, lx, ly, rx, ry;
	queue<PP> que;
	que.push(PP(ls,rs));
	while(que.size()){
		lx = que.front().first.second,ly = que.front().first.first,rx = que.front().second.second, ry = que.front().second.first;
		que.pop();
		if(lg.first == ly && lg.second == lx || rg.first == ry && rg.second == rx){
			if(lg.first == ly && lg.second == lx && rg.first == ry && rg.second == rx)
				return 1;
			else
				continue;
		}
		for(i = 0;i < 4;i++){
				if(lf[ly + dy[i]][lx + dx[i]] != '#' && rf[ry + dy[i]][rx - dx[i]] != '#' && f[ly + dy[i]][lx + dx[i]][ry + dy[i]][rx - dx[i]]){
					f[ly + dy[i]][lx + dx[i]][ry + dy[i]][rx - dx[i]] = 0;
					que.push(PP(P(ly + dy[i],lx + dx[i]),P(ry + dy[i],rx - dx[i])));
				}
				else if(lf[ly + dy[i]][lx + dx[i]] != '#' && rf[ry + dy[i]][rx - dx[i]] == '#' && f[ly + dy[i]][lx + dx[i]][ry][rx]){
					f[ly + dy[i]][lx + dx[i]][ry][rx] = 0;
					que.push(PP(P(ly + dy[i],lx + dx[i]),P(ry,rx)));
				}//
				else if(lf[ly + dy[i]][lx + dx[i]] == '#' && rf[ry + dy[i]][rx - dx[i]] != '#' && f[ly][lx][ry + dy[i]][rx - dx[i]]){
					f[ly][lx][ry + dy[i]][rx - dx[i]] = 0;
					que.push(PP(P(ly,lx),P(ry + dy[i],rx - dx[i])));
				}
		}
	}
	return 0;
}

int main(void){
	int i, j;
	while(1){
		scanf("%d%d%*c",&w,&h);
		if(w == 0 && h == 0) break;
		for(i = 0;i < h;i++){
			for(j = 0;j < w;j++){
				lf[i + 1][j + 1] = getchar();
				if(lf[i + 1][j + 1] == 'L'){
					ls = P(i + 1,j + 1);
					lf[i + 1][j + 1] = '.';
				}
				else if(lf[i + 1][j + 1] == '%'){
					lg = P(i + 1,j + 1);
					lf[i + 1][j + 1] = '.';
				}
			}
			getchar(); // 空白読み飛ばし
			for(j = 0;j < w;j++){
				rf[i + 1][j + 1] = getchar();
				if(rf[i + 1][j + 1] == 'R'){
					rs = P(i + 1,j + 1);
					rf[i + 1][j + 1] = '.';
				}
				else if(rf[i + 1][j + 1] == '%'){
					rg = P(i + 1,j + 1);
					rf[i + 1][j + 1] = '.';
				}
			}
			getchar(); // 改行文字読み飛ばし
		}
		for(i = 0;i < h + 2;i++){
			lf[i][0] = rf[i][0] = '#';
			lf[i][w + 1] = rf[i][w + 1] = '#';
		}
		for(i = 0;i < w + 2;i++){
			lf[0][i] = rf[0][i] = '#';
			lf[h + 1][i] = rf[h + 1][i] = '#';
		}
		memset(f,-1,sizeof(f));
		f[ls.first][ls.second][rs.first][rs.second] = 0;
		if(bfs())
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 9252
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toLong() }
    var a = n[0]
    var b = n[1]
    if (n[2] > a + b){
        println("0 0")
    } else if (n[2] > a){
        var x = n[2] - a
        b = b - x
        println("0 ${b}")
    } else {
        a = a - n[2]
        println("${a} ${b}")
    }
}

Measured memory_bytes: 37948
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#define F first
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP; //PP(P(SM,SD),P(S_time,E_time)
typedef pair<P,int> hP;

int main(){
  int n;
  string s,ss,sss,ssss;
  multimap<string,PP> info;
  map<string,hP> index;
  map<string,int> Final;
  while(cin >> n && n){
    info.clear();
    rep(i,n){
      cin >> s >> ss >> sss >> ssss;
      int Mo,Da,st,ed;
      st = ed = 0;
      rep(j,s.length()){ // string to int (Month/Day)
	if(s[j] == '0' && st == 0){
	  st = j+1;
	  continue;
	}     
	if(s[j] == '/'){
	  Mo = (atoi)(s.substr(st,j-st).c_str() );
	  st = j+1;
	}
	else if(j == s.length()-1){
	  Da = (atoi)(s.substr(st,j-st+1).c_str() );
	}
      }// string to int (Month/Day)
 
      st = ed = 0;
      int time_h,time_m;
      rep(j,ss.length() ){ // string to int (time:time)
	if(st == 0 && ss[0] == '0'){
	  st = j+1;
	  continue;
	}
	if(ss[j] == ':'){
	  time_h = (atoi)(ss.substr(st,j-st).c_str() );
	  st = j+1;
	}
	else if(j == ss.length()-1 ){
	  time_m = (atoi)(ss.substr(st,j-st+1).c_str() );
	}
      }// string to int (time:time)
      if(sss == "I"){
	index[ssss] = hP(P(Mo,Da),time_h*60+time_m);
	//cout << index[ssss].F.F << endl;
      }
      else if(sss == "O"){
	info.insert(multimap<string,PP>::value_type(ssss,PP(P(index[ssss].F),P(index[ssss].S,time_h*60+time_m ) )) );
	//map<string,PP>::iterator it = index[ssss];
	index.erase(ssss);
      }
    }
    multimap<string,PP>::iterator it = info.begin();

    Final.clear();

    while((*it).F == "000"){   
      
      multimap<string,PP>::iterator it2 = info.begin();
      while(it2 != info.end() ){
	if((*it2).F == "000"){
	  it2++;
	  continue;
	}

	if( (*it).S.F.F == (*it2).S.F.F && (*it).S.F.S == (*it2).S.F.S && ( ( ((*it).S.S.F <= (*it2).S.S.F && (*it2).S.S.F <= (*it).S.S.S  )   ||        ( (*it).S.S.F <= (*it2).S.S.S && (*it2).S.S.S <= (*it).S.S.S  )   )  || ( ((*it2).S.S.F <= (*it).S.S.F  ) && ((*it).S.S.S <= (*it2).S.S.S )  )   )  ){ //女神がいる時間帯に君はいたか？

	  if( ( ((*it2).S.S.F <= (*it).S.S.F  ) && ((*it).S.S.S <= (*it2).S.S.S )  ) ){//女神がでてくる前から待機しててかつ女神が消えた後もそのにいた場合
	    Final[(*it2).F] += (*it).S.S.S - (*it).S.S.F;
	  }
	  else if( ( ((*it).S.S.F <= (*it2).S.S.F && (*it2).S.S.F <= (*it).S.S.S  )     &&    ( (*it).S.S.F <= (*it2).S.S.S && (*it2).S.S.S <= (*it).S.S.S  )   )  ){//女神が存在する間にきて、その間で帰った場合
	    Final[(*it2).F] += (*it2).S.S.S - (*it2).S.S.F;
	  } 
	  else if( ((*it).S.S.F <= (*it2).S.S.F && (*it2).S.S.F <= (*it).S.S.S  )  ){//女神がきたあとに入ってきて、女神が消えたあともそこにいた場合
	    Final[(*it2).F] += (*it).S.S.S - (*it2).S.S.F;
	  }
	  else if( ( (*it).S.S.F <= (*it2).S.S.S && (*it2).S.S.S <= (*it).S.S.S  ) ){//女神がくるまえから待っていて、女神が消える前に帰った場合
	    Final[(*it2).F] += (*it2).S.S.S - (*it).S.S.F; 
	  }
	}
	it2++;
      }
      it++;
    }

    int ans = 0;
    map<string,int>::iterator IT = Final.begin();
    while(IT != Final.end() ){
      ans = max(ans,(*IT).S);
      IT++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include<stdio.h>
int main(void)
{
	int a,b[10000],c[10000],d,e,i,m,mp;
	while(1){
		m=0;
		scanf("%d",&a);
		if(a==0){
			break;
		}
		for(i=0;i<a;i++){
			scanf("%d%d%d",&b[i],&d,&e);
			c[i]=d+e;
		}
		for(i=0;i<a;i++){
			if(m<c[i]){
				m=c[i];
				mp=b[i];
			}
		}
		printf("%d %d\n",mp,m);
	}
	return 0;
}

Measured memory_bytes: 676
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

a,b=MI()

print(max(a+b,max(a*2-1, b*2-1)))




Measured memory_bytes: 3316
#include <stdio.h>


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

	return 0;
}

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll N, K;
vector<ll> p, q;
vector<vector<ll>> init(7);

vector<ll> comp(vector<ll> s, vector<ll> t) {
  vector<ll> result(N+1);
  for (ll i = 1; i <= N; i++)  result.at(i) = s.at(t.at(i));
  return result;
}

vector<ll> inv(vector<ll> s) {
  vector<ll> result(N+1);
  for (ll i = 1; i <= N; i++)  result.at(s.at(i)) = i;
  return result;
}

vector<ll> unit() {
  vector<ll> result(N+1);
  for (ll i = 1; i <= N; i++)  result.at(i) = i;
  return result;
}

vector<ll> funcf(vector<ll> s, vector<ll> t) {
  return comp(t, inv(s));
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N >> K;
  p.resize(N+1);
  q.resize(N+1);
  for (ll i = 1; i <= N; i++)  cin >> p.at(i);
  for (ll i = 1; i <= N; i++)  cin >> q.at(i);
  init.at(1) = vector<ll>(p);
  init.at(2) = vector<ll>(q);
  for (ll i = 3; i <= 6; i++)  init.at(i) = funcf(init.at(i-2), init.at(i-1));
  ll n = (K-1) / 6;
  ll k = (K-1) % 6;
  vector<ll> alpha = comp(q, comp(inv(p), comp(inv(q), p)));
  ll pwlen = 32;
  vector<vector<ll>> powA(pwlen);
  powA.at(0) = unit();
  powA.at(1) = vector<ll>(alpha);
  for (ll j = 1; j < pwlen - 1; j++)  {
    powA.at(j+1) = comp(powA.at(j), powA.at(j));
  }
  vector<ll> beta = unit();
  for (ll j = 1, x = n; x > 0; j++, x /= 2) {
    if (x % 2 == 1)  beta = comp(beta, powA.at(j));
  }
  vector<ll> answer = comp(beta, comp(init.at(k+1), inv(beta)));
  for (ll i = 1; i <= N - 1; i++)  cout << answer.at(i) << " ";
  cout << answer.at(N) << endl;

  return 0;
}



Measured memory_bytes: 39200
#include<bits/stdc++.h>
#define itn int
#define REP(i,n) for(int i=0;i<(n);i++)
#define IREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(n);i++)
#define REPEACH(itr,k) for(auto&& itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
typedef pair<double,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int goukei=0;
  REP(i,n){
    cin >> a[i];
    if(i==0){
      goukei=abs(a[i]);
    }
    else{
      goukei+=abs(a[i-1]-a[i]);
    }
  }
  goukei+=abs(a[n-1]);
  REP(i,n){
    int mae,usiro;
    if(i==0){
      mae=0;
      usiro=a[i+1];
    }
    else if(i==n-1){
      mae=a[i-1];
      usiro=0;
    }
    else{
      mae=a[i-1];
      usiro=a[i+1];
    }
    int ans=goukei-abs(a[i]-mae)-abs(a[i]-usiro)+abs(mae-usiro);
    cout << ans << endl;
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N;
ll a[100100], ans;

int main () {
        scanf("%d", &N);
        fo(i, 0, N) scanf("%lld", &a[i]);
        fo(i, 0, N) {
                ans += a[i]/2, a[i] %= 2;
                if (a[i] && a[i+1]) ans++, a[i+1]--;
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){ ;
int main() {
int x,y;
cin>>x>>y;
char d;
char e;
vector<int>A(7);
vector<int>B(4);
vector<int>C(1);
A={1,3,5,7,8,10,12};
B={4,6,9,11};
C={2};
for(int i=0; i<7; i++){
    if(x==A.at(i)){
        d='A';
    }
    if(y==A.at(i)){
        e='A';
    }
}
for(int i=0; i<4; i++){
    if(x==B.at(i)){
        d='B';
    }
    if(y==B.at(i)){
        e='B';
    }
}
if( x==2){
    d='C';
}
if(y==2){
    e='C';
}
if(d==e){
    cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;
 }


Measured memory_bytes: 3624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
#include "string"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	vector<ll> tmp;
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			tmp.push_back(a[i]);
			a[i + 1] = -1;
		}
	}
	if (tmp.size() >= 2) cout << tmp[0] * tmp[1] << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<setprecision(6); cout<<fixed;
  #ifdef DEBUG
  freopen("ip.txt","r",stdin);
  clock_t tStart = clock();
  #endif

  ll n,a,b; cin>>n>>a>>b;
  if(n*a<b) cout<<n*a<<'\n';
  else cout<<b;


  #ifdef DEBUG
	cout<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)<<"s.\n";
	#endif
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
}

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

#define TOUMAX 4
#define KAIMAX 3
#define ROOMMAX 10

int main(void)
{
	int r,c;
	int i,j;
	int **array;
	int sum;

	cin >> r;
	cin >> c;

	array = new int*[r];
	for (i=0; i<=r; i++) {
		array[i] = new int[c+1];
	}

	for (i=0; i<r; i++) {
		sum = 0;
		for (j=0; j<c; j++) {
			cin >> array[i][j];
			sum += array[i][j];
		}
		array[i][c] = sum;
	}

	for (i=0; i<=c; i++) {
		sum = 0;
		for (j=0; j<r; j++) {
			sum += array[j][i];
		}
		array[r][i] = sum;
	}

	for (i=0; i<=r; i++) {
		for (j=0; j<=c; j++) {
			cout << array[i][j];
			if(j < c) {
				cout << " ";
			}
			else {
				cout << endl;
			}
		}
	}

	for (i=0; i<=r; i++) {
		delete[] array[i];
	}
	delete[] array;

	return 0;
}



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

int main()
{
	string s;
	getline(cin,s);
	int a[200]={0};
	for(int i=0;i<s.size();i++)
	{
		a[s[i]]++;
	 } 
	int sum=0; 
	int sum2=0;
	 for(int i=0;i<200;i++)
	 {
	 	if(a[i]>=1)
	 	{
	 		sum2++;
		 }
	 	if(a[i]==2)
	 	{
	 		sum++;
		 }
	 }
	 if(sum2==2&&sum==2)
	 {
	 	cout<<"Yes"<<endl;
	 }
	 else{
	 	cout<<"No"<<endl;
	 }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=300+100;
int g[maxn][maxn];
int ans[maxn][maxn];
char s[maxn];
int vis[maxn];
void solve()
{
	int n,m,k;
	scddd(n,m,k);
	rep1(i,n){
		scanf("%s",s+1);
		rep1(j,m){
			if(s[j]!='.')g[i][j]=1,vis[i]=1;
		}
	}
	int now=0;
	rep1(i,n)if(vis[i]){
		int flag=0;
		now++;
		rep1(j,m){
			if(g[i][j]){
				if(!flag)flag=1;
				else now++;
			}
			ans[i][j]=now;
		}
	}
	rep1(i,n){
		if(i>1&&!vis[i]){
			rep1(j,m)ans[i][j]=ans[i-1][j];
		}
	}
	for(int i=n-1;i;i--){
		if(!vis[i]){
			rep1(j,m)ans[i][j]=ans[i+1][j];
		}
	}
	rep1(i,n){
		rep1(j,m){
			if(j>1)printf(" ");
			printf("%d",ans[i][j]);
		}
		printf("\n");
	}
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18



int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if (a[0]==a[1] || a[1]==a[2]){
		if (a[0]==a[2]){
			cout << "No\n";
		}
		else cout << "Yes\n";
	}
	else cout << "No" << endl;
}

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

using namespace std;

int main(){

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

	int maxab = max(x * 2, y * 2);

	int price;
	int minprice=2000000000;
	for (int i = 0; i <= maxab; i++) {
		price = c * i + max((x - (int)i / 2)*a,0) + max((y - (int)i / 2)*b,0);
		minprice = min(minprice, price);
	}
	cout << minprice << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  printf("%.16f %d\n", w*h/2.0, (x+x == w && y+y == h));
  return 0;
}

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

int main() {

    vector< int > a(3);
    for(int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int n = a[2] - a[0], m = a[2] - a[1];
    int ans = min(n, m);
    int rem = max(n, m) - ans;

    if(rem % 2) ans += rem / 2 + 2;
    else ans += rem / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

const int L=1e5+1;
int dp[L][11];
vector<int> ps[L];
int cs[L];
int main() {
	int N,M,Q;
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		ps[a].push_back(b);
		ps[b].push_back(a);
	}
	cin >> Q;
	for(int i=1;i<=Q;i++){
		int v,d,c;
		cin >> v >> d >> c;
		cs[i]=c;
		dp[v][d]=i;
	}
	for(int d=9;d>=0;d--){
		for(int i=1;i<=N;i++){
			dp[i][d]=max(dp[i][d],dp[i][d+1]);
			for(int p:ps[i]){
				dp[i][d]=max(dp[i][d],dp[p][d+1]);
			}
		}
	}
	for(int i=1;i<=N;i++){
		cout << cs[dp[i][0]] << endl;
	}



	return 0;
}



Measured memory_bytes: 11128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[] = { 3,13,23,43,53,73,83,103,113,163,173,193,223,233,263,283,293,313,353,373,383,433,443,463,503,523,563,593,613,643,653,673,683,733,743,773,823,853,863,883,953,983,1013,1033,1063,1093,1123,1153,1163,1193,1213,1223,1283,1303,1373 };
	for (ll i = 0; i<N; ++i) {
		cout << a[i]<<" ";
	}
	cout<<""<< endl;
}

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

namespace abc_060_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long ans = 0;
            for(int i = 0; i < n[0]-1; i++)
            {
                while (true)
                {
                    if (i >= n[0] - 1) { break; }
                    if (a[i] + n[1] > a[1+i]) { ans += a[i+1]-a[i]; }
                    else { ans += n[1]; break; }
                    i++;
                }
            }
            Console.WriteLine(ans+n[1]);
            Console.ReadLine(); }
    }
}


Measured memory_bytes: 26720