akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  int n;
  cin >> n;
  arr(a,n);

  vec ct(3);
  ll ans=1;
  rep(i,n){
    ll tmp=0;
    bool already=false;
    rep(j,3){
      if(ct[j]==a[i]){
        tmp++;
        if(!already) ct[j]++, already=true;
      }
    }
    ans *= tmp;
    ans %= 1000000007;
  }

  prt(ans);
}


Measured memory_bytes: 3784
N=int(input())
A=list(map(int,input().split()))

dp=[[0]*2 for i in range(N)]

dp[0][0]=0
dp[0][1]=-3*10**9

for i in range(N-1):
	dp[i+1][0]=max(dp[i][0]+A[i], dp[i][1]-A[i])
	dp[i+1][1]=max(dp[i][0]-A[i], dp[i][1]+A[i])
 
print(max(dp[-1][0]+A[-1], dp[-1][1]-A[-1]))

Measured memory_bytes: 25512
import bisect
import sys
sys.setrecursionlimit(10**7)

def dfs(v):
 #DFSの行き(子ノードに下っていくとき)の処理
 pos=bisect.bisect_left(dp,arr[v]) #最長増加部分列で更新する場所を2分探索により求める
 changes.append((pos,dp[pos])) #更新した要素とその値を記録しておく
 dp[pos]=arr[v]
 ans[v]=bisect.bisect_left(dp,10**18) #1からvまでの最長増加部分列の長さは、最長増加部分列の10**18以外の値の個数に等しい
 for u in g[v]:
   if checked[u]==0:
     checked[u]=1
     dfs(u)
 #DFSの戻り(親ノードに上っていくとき)の処理
 pos,val=changes.pop() #頂点vで更新した最長増加部分列の値を元に戻す
 dp[pos]=val

n=int(input())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(n-1):
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
ans=[0]*(n+1)
checked=[0]*(n+1)
checked[1]=1
dp=[10**18 for _ in range(n+1)] #最長増加部分列を求めるのに、十分大きな値で初期化しておく
changes=[]
dfs(1)
for i in range(1,n+1):
 print(ans[i])

Measured memory_bytes: 239556
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    cout << S[0] << S.size()-2 << S[S.size()-1];
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp; int n;
	string s;
	cin >> n >> s;
	if (s.size() % 2 == 0 
	&& s.substr(0, s.size()/2) == s.substr(s.size()/2) )cout << "Yes" << endl;
	else cout << "No" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
typedef long long ll;
const ll INF = 1LL << 60;

ll dp[3030][3030];
int N;
ll a[3030];
bool ischecked[3030][3030];
// First maximize |X-Y|
// Second minimize |X-Y|
ll rec(int l, int r,int t){
    if(l > r) return 0;
    if(ischecked[l][r]) return dp[l][r];
    ischecked[l][r] = true;
    ll ret;
    if(t%2==0){
        ret = -INF;
        ret = max(ret,rec(l+1,r,t^1) + a[l]);
        ret = max(ret,rec(l,r-1,t^1) + a[r]);
    } else {
        ret = INF;
        ret = min(ret,rec(l+1,r,t^1) - a[l]);
        ret = min(ret,rec(l,r-1,t^1) - a[r]);
    }
    return dp[l][r] = ret;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    REP(i,N) cin >> a[i];
    ll ans = rec(0,N-1,0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80384
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");
stdin = stdin.trim().split("\n").reverse();
function input(){return stdin.pop()};
var stdout = [];
function print(x){stdout.push(x)};


var n = parseInt(input());
var v = input().split(" ").map(n=>parseInt(n));
var c = input().split(" ").map(n=>parseInt(n));


var ans = 0;
for (i=0; i < n; i++){
    ans += Math.max(0, v[i]-c[i])
}


print(ans);


stdout = stdout.join("\n");
console.log(stdout);

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  ll X;
  cin>>X;
  bool flag=false;
  for(ll a=-1000;a<=1000;a++){
    for(ll b=-1000;b<=1000;b++){
      if(a*a*a*a*a-b*b*b*b*b==X){
        cout<<a<<" "<<b<<endl;
        flag=true;
        break;
      }
    }
    if(flag){
      break;
    }
  }
}


Measured memory_bytes: 3632
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    vector<ll> A_SUM(N+1,0);
    REP(i,N){
        A_SUM[i+1]=A_SUM[i]+A[i];
    }

    ll ans=INF;
    REP2(i,2,N-1){
        int p,q,r,s;
        q=i;
        ll L=INF;
        ll R=INF;
        //1～i
        int j=upper_bound(A_SUM.begin(),A_SUM.end(),A_SUM[i]/2)-A_SUM.begin();
        if(j<i){
            if(abs(A_SUM[i]-2*A_SUM[j])<L){
                p=j;
                L=abs(A_SUM[i]-2*A_SUM[j]);
            } 
        }
        j--;
        if(j>=1){
            if(abs(A_SUM[i]-2*A_SUM[j])<L){
                p=j;
                L=abs(A_SUM[i]-2*A_SUM[j]);
            } 
            
        }

        //i+1～N
        j=upper_bound(A_SUM.begin(),A_SUM.end(),(A_SUM[N]+A_SUM[i])/2)-A_SUM.begin();

        if(j<N){
            if(abs(A_SUM[N]-2*A_SUM[j]+A_SUM[i])<R){
                r=j;
                R=abs(A_SUM[N]-2*A_SUM[j]+A_SUM[i]);
            } 
        }

        j--;
        if(j>=i+1){
            if(abs(A_SUM[N]-2*A_SUM[j]+A_SUM[i])<R){
                r=j;
                R=abs(A_SUM[N]-2*A_SUM[j]+A_SUM[i]);
            } 
        }

        s=N;
        ll ans_min=INF;
        ll ans_max=0;

        ans_min=min(ans_min,A_SUM[p]);
        ans_min=min(ans_min,A_SUM[q]-A_SUM[p]);
        ans_min=min(ans_min,A_SUM[r]-A_SUM[q]);
        ans_min=min(ans_min,A_SUM[s]-A_SUM[r]);

        ans_max=max(ans_max,A_SUM[p]);
        ans_max=max(ans_max,A_SUM[q]-A_SUM[p]);
        ans_max=max(ans_max,A_SUM[r]-A_SUM[q]);
        ans_max=max(ans_max,A_SUM[s]-A_SUM[r]);
        
        ans=min(ans,ans_max-ans_min);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6428
#include <stdio.h>

int main(void) {
	int N, K;
	char S[114154];
	int i;
	int ask[114514];
	int askCnt = 0;
	int current = 0, answer = 0;
	int windowSize;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	if (scanf("%114513s", S) != 1) return 1;
	if (S[0] == '0') {
		/* 1 kara hazimatteru kotoni suru */
		ask[0] = 0;
		askCnt = 1;
	}
	ask[askCnt] = 1;
	for (i = 1; i < N; i++) {
		if (S[i - 1] != S[i]) {
			askCnt++;
			ask[askCnt] = 0;
		}
		ask[askCnt]++;
	}
	askCnt++;
	if (S[N - 1] == '0') {
		/* 1 de owatteru kotoni suru */
		ask[askCnt] = 0;
		askCnt++;
	}
	windowSize = K * 2 + 1;
	for (i = 0; i < askCnt; i++) {
		current += ask[i];
		if (i >= windowSize) current -= ask[i - windowSize];
		if (i % 2 == 0 && current > answer) answer = current;
	}
	printf("%d\n", answer);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
const int N=305;
int dp[N][N][N]={},k;
char s[N];
int main() {
    scanf("%s%d",s+1,&k);int n=strlen(s+1);
    for(int i=1;i<=n;i++) for(int j=0;j<=k;j++) dp[i][i][j]=1,dp[i][i-1][j]=0;
    for(int j=1;j<n;j++) for(int i=1;i+j<=n;i++) for(int r=0;r<=k;r++){
        dp[i][i+j][r]=std::max(dp[i][i+j-1][r],dp[i+1][i+j][r]);
        if(s[i]==s[i+j]) dp[i][i+j][r]=std::max(dp[i][i+j][r],dp[i+1][i+j-1][r]+2);
        if(r) dp[i][i+j][r]=std::max(dp[i][i+j][r],dp[i+1][i+j-1][r-1]+2);
    }
    int ans=dp[1][n][k];
    for(int i=0;i<k;i++) ans=std::max(ans,dp[1][n][k]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 110464
#include <cstdio>
#include <cstring>
using namespace std;
int f,tmp = 1,h,w,n,a[10100],ans[101][101];
int main()
{
	scanf("%d%d",&h,&w);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	for(int i = 1;i <= h;i++)
	{
		if(i % 2)
		{
			for(int j = 1;j <= w;j++)
				{
					ans[i][j] = tmp;
					a[tmp]--;
					if(a[tmp] == 0)tmp++;
				}
		}else
		{
			for(int j = w;j >= 1;j--)
				{
					ans[i][j] = tmp;
					a[tmp]--;
					if(a[tmp] == 0)tmp++;
				}
		}
	}
	for(int i = 1;i <= h;i++)
		for(int j = 1;j <= w;j++)
			printf("%d%c",ans[i][j],j != w ? ' ' : '\n');
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int gcd(int p, int q) {
    if (p % q == 0)return q;
    return gcd(q, p % q);
}

int main()
{

    int k;
    cin >> k;
    int seven = 7;
    int flag = 0;

    if (k % 2 == 0 || k % 5 == 0) {
        cout << "-1";
        return 0;
    }

    for (int i = 0;i<10000000; i++) {
        if (seven%k == 0) {
            flag = 1;
            cout << i + 1;
            break;
        }
        seven = (seven%k) * 10 + 7;

    }

    if (flag == 0) cout << "-1";
    
    
    return 0;

}



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

using namespace std;


int main() {

   int n,m;
   cin>>n>>m;
   const int N = n*2 -1;
   int arr[N];
   arr[0]=m;
   int j=1;

   for(int i=m+1;i<m+n;i++){
       arr[j++]=i;
   }

    for(int i=m-1;i>m-n;i--){
        arr[j++]=i;
    }


    sort(arr,arr+j);

    for(int i=0;i<j;i++)cout<<arr[i]<<" ";

    cout<<endl;
    return 0;
}


Measured memory_bytes: 3532
import numpy as np

def main():
    N, M, C = map(int, input().split())
    b = np.array(list(map(int, input().split())))
    a = np.array([list(map(int, input().split())) for i in range(N)])

    count = 0
    for i in range(N):
        if np.sum(a[i]*b) + C > 0:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

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

double pi = 2 * asin(1);

int main() {
	int N, M;
	cin >> N >> M;
	int ans = 0;
	int a;
	for (int i = 0; i < M; i++) {
		cin >> a;
		ans += a;
	}
	ans = N - ans;
	if (ans < 0)ans = -1;
	cout <<  ans;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include <numeric>
#include <algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int, int> P;

int main(){
  string N;
  int l, sum=0;
  cin >> N;
  l = N.length();
  for(int i=0; i<l; i++){
    sum+=stoi(N.substr(i, 1));
  }
  if(sum%9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int num = 0;
    rep(i, 4){
        if(s[i] == '+'){
            num++;
        }else{
            num--;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
sub = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
N = int(input())

cost = [0] * (N+1)
for i in range(N+1):
    cost[i] = i

for i in range(N+1):
    for j in range(len(sub)):
        if(sub[j] <= i):
            cost[i] = min(cost[i], cost[i-sub[j]] + 1)
print(cost[N])

Measured memory_bytes: 74348
h,w,k=gets.strip.split.map(&:to_i)
if k==0
  puts "Yes"
  exit
end
(0..h).each do |i|
(0..w).each do |j|
  t=i*j+(h-i)*(w-j)
  if t==k
    puts "Yes"
    exit
  end
end
end

puts "No"

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main()
{
    int a[5], k;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    cin >> k;
    for(int i = 0; i < 4; i++){
        for(int j = i + 1; j < 5; j++){
            if(a[j] - a[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
b = [int(i) for i in input().split(' ')]
seq = []
while True:
  if len(b) == 0:
    print('\n'.join(seq[::-1]))
    break
  i = -1
  for j in range(len(b)):
    if b[j] == j + 1:
      i = j
  if i == -1:
    print('-1')
    break
  seq.append(str(i + 1))
  b = b[:i] + b[i+1:]


Measured memory_bytes: 3064
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, X: "List[int]", L: "List[int]"):
    tmp = []
    for i in range(N):
        tmp.append((X[i] + L[i], X[i] - L[i]))
    tmp.sort()
    cur = tmp[0][1] - 1
    ret = 0
    for i in range(N):
        if cur <= tmp[i][1]:
            ret += 1
            cur = tmp[i][0]
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()


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


int main() {
    
    long long n,ans=0;
    cin>>n;
    ans+=(n/500)*1000;
    n=n%500;
    ans+=(n/100)*100;
    n=n%100;
    ans+=(n/50)*50;
    n=n%50;
    ans+=(n/10)*10;
    n=n%10;
    ans+=(n/5)*5;
    cout<<ans;


return 0;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
int N, K;
vector<int> D;

bool iscontain(ll in) {
    string s = to_string(in);
    // cout << "s is" << s << endl;
    REP(j, s.length()) {
        REP(k, K) {
            if(s[j] - '0' == D[k]) {
                return false;
            }
        }
    }
    return true;
}
int main() {
    cin >> N >> K;
    D.resize(K);
    REP(i, K) { cin >> D[i]; }
    // N円以上
    for(ll i = N; i < INF; i++) {
        if(iscontain(i)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 205

using namespace std;

int main()
{
    ll a,b,c;

    scanf("%lld %lld %lld",&a,&b,&c);

    printf("%lld\n",min(a+b, min(a+c, b+c)));

    return (0);
}




Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);

    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){

    int n = 0, tmp = 1, max = 4, qi = 0, qimax = 0;
    std::vector<int> v, Qs;
    while(1){
        std::cin >> tmp;

        if(tmp > max){
            max = tmp;
        }

        if(tmp == 0){
            break;
        }

        v.resize(n+1);
        v[n] = tmp;
        n++;
    }

    for(int i = 3; i <= max; i++){

        if(IsPrime(i) && IsPrime(i+2)){
            Qs.resize(qi + 1);
            //std::cout << i + 2 << std::endl;
            Qs[qi] = (i + 2);
            qi++;
        }

    }
    qi--;
    qimax = qi;
    tmp = 0;
    
    while(tmp < n){

       if( v[tmp] < Qs[qi] ){

            //std::cout << "qi : " << qi << std::endl;    
            qi--;
            continue;

       }else{// v[tmp] >= Qs.top

            v[tmp] = Qs[qi];
            qi = qimax;
            tmp++;

       }

    }
    
    for (int i = 0; i < n; i++){
        std::cout << v[i] - 2 << " " << v[i] << std::endl; 
    }

    
    return 0;
}


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

int main() 
{
    int n;
    cin >> n;
    int a[n], b[n], c[n-1];
    rep(i,n) cin >> a[i]; 
    rep(i,n) a[i]--;
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];

    int prev = -100;
    int ans = 0;
    rep(i,n) {
        int x = a[i];
        ans += b[x];
        if (x == prev +1) ans += c[prev];
        prev = x;
    }   
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e9 + 7 ;

int main(){ skorost ;

	int n ;

	cin >> n ;

	string s ;

	cin >> s ;

	if( s.size() <= n ){

		cout << s << endl ;

	}

	else{

		for( int i = 0 ; i < n ; i ++ ){

			cout << s[i] ;

		}

		cout << "..." << endl ;

	}
	
}

Measured memory_bytes: 3620
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
cnt = 0
ans = []
for i in range(H):
  for j in range(W):
    if i == H-1 and j == W-1:
      continue
    if i == H-1:
      if A[i][j] % 2 == 1:
        A[i][j] -= 1; A[i][j+1] += 1;
        s = " ".join([str(i+1), str(j+1), str(i+1), str(j+2)])
        ans.append(s)
        cnt += 1
    elif A[i][j] % 2 == 1:
      A[i][j] -= 1; A[i+1][j] += 1;
      s = " ".join([str(i+1), str(j+1), str(i+2), str(j+1)])
      ans.append(s)
      cnt += 1
print(cnt)
print(*ans, sep="\n")

Measured memory_bytes: 18396
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
using namespace std;
char s[maxn];
int c[maxn],a[maxn][2],b[maxn][2];
int main()
{
	cin>>s;
	int l=strlen(s);
	a[0][0]=0;
	a[0][1]=0;
	for(int i=1;i<=l;i++)
		if(s[i-1]=='R')
		{
			a[i][0]=a[i-1][1]+1;
			a[i-1][1]=0;
			a[i][1]=a[i-1][0];
			a[i-1][0]=0;
		}
		else
		{
			a[i][1]=0;
			a[i][0]=0;
		}
		
	b[l+1][0]=0;
	b[l+1][1]=0;
	for(int i=l;i>=1;i--)
		if(s[i-1]=='L')
		{
			b[i][0]=b[i+1][1]+1;
			b[i+1][1]=0;
			b[i][1]=b[i+1][0];
			b[i+1][0]=0;
		}
		else
		{
			b[i][1]=0;
			b[i][0]=0;
		}
	for(int i=1;i<=l;i++)
		c[i]=0;
	for(int i=1;i<=l;i++)
		if(s[i-1]=='R')
		{
			c[i]+=a[i][0];
			c[i+1]+=a[i][1];
		}
		else
		{
			c[i]+=b[i][0];
			c[i-1]+=b[i][1];
		}
	for(int i=1;i<l;i++)
		printf("%d ",c[i]);
	printf("%d\n",c[l]);
}

Measured memory_bytes: 3712
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}

const mod = 10^^9+7;
alias mint = FactorRing!mod;

void main()
{
  int n; readV(n);
  string[] s; readC(2, s);

  bool[] b;
  for (auto i = 0; i < n; ++i) {
    if (s[0][i] == s[1][i]) {
      b ~= true;
    } else {
      b ~= false;
      ++i;
    }
  }

  auto nb = b.length.to!int, dp = new mint[][][](nb, 3, 3);
  if (b[0])
    foreach (i; 0..3)
      dp[0][i][i] = 1;
  else
    foreach (i; 0..3)
      foreach (j; 0..3)
        if (i != j)
          dp[0][i][j] = 1;

  foreach (k; 1..nb)
    if (b[k]) {
      foreach (i; 0..3)
        foreach (x; 0..3)
          foreach (y; 0..3)
            if (i != x && i != y)
              dp[k][i][i] += dp[k-1][x][y];
    } else {
      foreach (i; 0..3)
        foreach (j; 0..3)
          foreach (x; 0..3)
            foreach (y; 0..3)
              if (i != j && i != x && j != y)
                dp[k][i][j] += dp[k-1][x][y];
    }

  auto r = mint(0);
  foreach (i; 0..3)
    foreach (j; 0..3)
      r += dp[$-1][i][j];

  writeln(r);
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }
  alias FR = FactorRing!(m, pos);
  @property static init() { return FR(0); }
  @property int value() { return vi; }
  @property void value(int v) { vi = mod(v); }
  alias value this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref auto opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }
  pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }

  static if (!pos) pure ref auto opUnary(string op: "-")() { return FR(mod(-vi)); }

  static if (m < int.max / 2) {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vi"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vi"~op~"r")); return this; }
  } else {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vl"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vl"~op~"r")); return this; }
  }
  pure ref auto opBinary(string op: "*")(int r) { return FR(mod(vl*r)); }
  ref auto opOpAssign(string op: "*")(int r) { vi = mod(vl*r); return this; }

  pure ref auto opBinary(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opBinary!op(r.vi); }
  ref auto opOpAssign(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(r.vi); }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
template<typename T>inline bool chkmin(T&x,T y) { return x > y ? x = y , 1 : 0; }
template<typename T>inline bool chkmax(T&x,T y) { return x < y ? x = y , 1 : 0; }
using namespace std;
typedef long long LL;
inline int read()
{
	int l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
const int N = 100005;
struct Edge
{
	int v, w, next;
}e[N*10];
int n, m, num, cnt, h[N], dis[N], d[N], vis[N];
void insert(int u, int v, int w)
{
	e[++num].v = v, e[num].w = w, e[num].next = h[u], h[u] = num;
	e[++num].v = u, e[num].w = -w, e[num].next = h[v], h[v] = num;
}
bool dfs(int x)
{
	vis[x] = 1;
	for (int i = h[x]; i; i = e[i].next)
	{
		int v = e[i].v;
		if (chkmin(d[v], d[x]+e[i].w))
		{
			if (vis[v]) return 0;
			if (!dfs(v)) return 0;
		}
	}
	vis[x] = 0;
	return 1;
}
int main(int argc, char const *argv[])
{
	n = read(), m = read();
	for (int i = 1; i <= m; ++i)
	{
		int l = read(), r = read(), w = read();
		insert(l, r, w);
	}
	for (int i = 1; i <= n; ++i) e[++num].v = i, e[num].w = 1, e[num].next = h[0], h[0] = num;
	memset(d, 63, sizeof(d));
	d[0] = 0;
	if (dfs(0)) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

int main(void){
    int d,n;
    cin>>d>>n;
    if(n==100) n++;
    int ans=n;
    rep(i,d) ans*=100;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3556
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <queue>
#include <cstdio>
#include <set>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

int f(int h, int m){
  return h * 60 + m;
}

pair<int, int> getTime(){
  char buff[64];
  scanf("%s", buff);

  int h1, m1, h2, m2;
  sscanf(buff, "%02d:%02d-%02d:%02d", &h1, &m1, &h2, &m2);

  return make_pair(f(h1, m1), f(h2, m2));
}

bool includes(pair<int, int> a, pair<int, int> b){
  return a.first <= b.first && b.second <= a.second;
}

int main(){
  const int n = getInt();
  vector<pair<int, int> > tm(n);
  REP(i,n) tm[i] = getTime();

  vector<int> s(n);
  vector<int> t(n);

  const int sc = getInt();
  REP(i,sc){
    const int k = getInt();
    REP(j,k){
      pair<int, int> tt = getTime();
      REP(p,n) if(includes(tt, tm[p])) s[p]++;
    }
  }

  const int tc = getInt();
  REP(i,tc){
    const int k = getInt();
    REP(j,k){
      pair<int, int> tt = getTime();
      REP(p,n) if(includes(tt, tm[p])) t[p]++;
    }
  }

  int ans = 0;
  REP(i,n) ans += min(s[i], t[i]);
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int div2(ll a){
    int ans = 0;
    while (a % 2LL == 0){
        a /= 2LL;
        ans++;
    }
    return ans;
}

int div5(ll b){
    int ans = 0;
    while (b % 5LL == 0){
        b /= 5LL;
        ans++;
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> ar(n);
    rep(i,n) cin >> ar[i];
    vector<int> al(n);
    rep(i,n) al[i] = ar[i];
    sort(al.begin(),al.end());
    int midl = al[n/2 - 1];
    int midr = al[n/2];
    rep(i,n){
        if (ar[i] <= midl) cout << midr << endl;
        else if (ar[i] >= midr) cout << midl << endl;
    }
}

Measured memory_bytes: 4852
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  var C = parseInt(input[0].split(" ")[2]);
  var ans = A*B/2;

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int n = in.nextInt(); in.nextLine();
        List<String> s = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            s.add(in.nextLine());
        }
        int m = in.nextInt(); in.nextLine();
        List<String> t = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            t.add(in.nextLine());
        }
        
        Map<String, List<String>> sMap = s.stream().collect(Collectors.groupingBy(String::toString));
        Map<String, List<String>> tMap = t.stream().collect(Collectors.groupingBy(String::toString));
        OptionalInt ans = sMap.keySet().stream()
                .mapToInt(str -> sMap.get(str).size() - (tMap.containsKey(str) ? tMap.get(str).size() : 0))
                .max();
        System.out.println(Math.max(0, ans.getAsInt()));
    }
}


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

typedef long long ll;

const int MOD = 1000000007;
 
ll dp[100001][13];

int main() {
  string s;
  cin >> s;
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); ++i) {
    char c = s[i];
    if (c == '?') {
      for (int d = 0;d < 10; ++d) {
        for (int m = 0; m < 13; ++m) {
          dp[i+1][(10*m+d)%13] += dp[i][m];
        }
      }
    }
    else {
      int d = c - '0';
      for (int m = 0; m < 13; ++m) {
        dp[i+1][(10*m+d)%13] += dp[i][m];
      }
    }
    for (int m = 0; m < 13; ++m) {
      dp[i+1][m] %= MOD;
    }
  }
  cout << dp[s.size()][5] << endl;
}



Measured memory_bytes: 10624
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

void WF(vector<vector<int> > &dist, int N) {
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
	if (dist[i][j] > dist[i][k] + dist[k][j]) {
	  dist[i][j] = dist[i][k] + dist[k][j];
	}
      }	
    }
  }
}

int main() {
  int N, M, L;
  cin >> N >> M >> L;
  const int kInf = 1001001001;
  vector<vector<int> > dist(N, vector<int>(N, kInf));
  for (int i = 0; i < M; ++i) {
    int A, B, C;
    cin >> A >> B >> C;
    --A; --B;
    dist[A][B] = C;
    dist[B][A] = C;
  }
  WF(dist, N);
  
  vector<vector<int> > D(N, vector<int>(N, kInf));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (dist[i][j] <= L) D[i][j] = 1;
    }
  }
  WF(D, N);

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int S, T;
    cin >> S >> T;
    --S; --T;
    if (D[S][T] != kInf) {
      cout << D[S][T] - 1 << endl;
    } else {
      cout << -1 << endl;
    }
  }
  
  return 0;
}


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

int main() {
  string s;
  while(getline(cin,s)) {
    string t=s;
    for(int i=0; i<=s.size()-5; i++) {
      if(s.substr(i, 5)=="peach") t.replace(i,5,"apple");
      if(s.substr(i, 5)=="apple") t.replace(i,5,"peach");
    }
    cout << t << endl;
  }
  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9 + 7;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

int main(void)
{
	ll n;
	cin >> n;
	vector<ll> xs(n);
	rep(i, n) cin >> xs[i];
	vector<ll> dist(n);
	rep(i, n - 1) dist[i+1] = xs[i + 1] - xs[i];
	vector<ll> modInvs(n,0);

	for (ll i = 1; i < n; i++) {
		modInvs[i] = (modInvs[i-1] + inv_mod(i)) % mod;
	}
	ll sum = 0;
	for (ll i = 1; i < n; i++) {
		ll elem = dist[i] * modInvs[i];
		(sum += elem) %= mod;
	}
	for (ll i = 1; i < n; i++) {
		sum *= i;
		sum %= mod;
	}
	cout << sum << endl;
	return 0;
}


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

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class DWaterBottle {
public:
	void solve(std::istream& in, std::ostream& out) {
	    double a, b, x;
	    in >> a >> b >> x;
	    double l = x / (a * a);
	    double ans;
	    if (l > b/2) {
	        ans = atan((b-l)/(a/2)) / (acos(-1)/180.0);
        } else {
	        ans = atan(b / (2*x/(a*b))) / (acos(-1)/180.0);
	    }
        out << setprecision(12) << ans << '\n';
    }
};


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


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){
  while(u!=NIL){
    if(u->key == k)return u;
    else if(u->key < k) u=u->right;
    else u=u->left;
  }

  return NIL;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
  z->parent = y;

  if(y==NIL)root=z;
  else if(z->key < y->key) y->left =z;
  else y->right = z;
  
}

void inorder(Node u){
  if(u->left!=NIL)inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL)inorder(u->right);
			
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!=NIL)preorder(u->left);
  if(u->right!=NIL)preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


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

int main(){
  long long a,b;
  cin >> a >> b;
  if(a*b<=0){
    cout <<  "Zero";
  }else{
    if(a>0){
      cout << "Positive";
    }else if((b-a)%2==0){
      cout << "Negative"; 
    }else{
      cout << "Positive";
    }
  }
}

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

int main() {
	string S, T;
	cin >> S >> T;
	int judge = 1;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) {
			judge = 0;
			break;
		}
	}
	if (judge == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	return 0;
}

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

#define mod 1000000007

#define rep(i, n) for(int i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N, A[100100] = {}, sum = 0;
	
	cin >> N;
	
	for(int i = 1; i <= N; i++)
		cin >> A[i];
		
	rep(i, N + 1)
		sum += abs(A[i] - A[i + 1]);
	
	for(int i = 1; i <= N; i++)
		cout << sum + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) << endl;
	
	return 0;
}

Measured memory_bytes: 1664
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 3000;
double dp[N + 5][N + 5];
double arr[N + 5];
int n;

double calc(int x,int y) {
	if(x == -1 && n / 2 < y) return 1;
	if(x == -1) return 0;
	double &res = dp[x][y];
	if(res > -0.5) return res;
	res = calc(x - 1,y) * (1.0 - arr[x]) + calc(x - 1,y + 1) * arr[x];
	return res;
}

void hora(int tc) {
	cin>>n;
	memset(dp,-1,sizeof dp);
	for(int i = 0;i < n;i++) cin>>arr[i];
	cout<<calc(n - 1,0)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 71040
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	long long k,x;
	int n;
	scanf("%lld",&x);
	k=100;
	n=0;
	while(1)	{
		if(k>=x)	break;
		k=k*1.01;
		n++;
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 1728
s=input()
if s=="SUN":
  print(7)
elif s=="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s=="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
  
elif s=="SAT":
  print(1)
  

Measured memory_bytes: 2940
// 分からなかったので他の人の回答を見た
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;

double OptimalBSTree(const vector<double>& p, const vector<double>& q, const int n){
    vector<vector<double>> psum(n, vector<double>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n - i; j++){
			if(i == 0){
				psum[j][j] = p[j];
			}
			else{
				psum[j][j + i] = psum[j][j + i - 1] + p[j + i];
			}
		}
	}
	vector<vector<double>> qsum(n + 1, vector<double>(n + 1));
	for(int i = 0; i < n + 1; i++){
		for(int j = 0; j < n + 1 - i; j++){
			if(i == 0){
				qsum[j][j] = q[j];
			}
			else{
				qsum[j][j + i] = qsum[j][j + i - 1] + q[j + i];
			}
		}
	}

	double et = 0.0;
	vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
	for(int i = 0; i < n + 1; i++){
		for(int j = 0; j < n + 1 - i; j++){
			if(i == 0){
				dp[j][j] = q[j];
			}
			else{
				double min;
				for (int k = 0; k < i; k++){
					et = dp[j][j + k] + dp[j + k + 1][j + i] + psum[j][i + j - 1] + qsum[j][i + j];
					if (k == 0 || et < min) min = et;
				}
				dp[j][j + i] = min;
			}
		}
	}
	return dp[0][n];
}

int main(){
	int n;
	cin >> n;
    // n 個の各キーに対して探索が起きる確率 p
    // n+1 個の各ダミーキーで探索が終わる確率 q
	vector<double> p(n), q(n + 1);
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	for(int i = 0; i < n + 1; i++){
        cin >> q[i];
	}

    cout << fixed << setprecision(4) << OptimalBSTree(p, q, n) << endl;

	return 0;
}


Measured memory_bytes: 8992
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

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

int main() {
  int N = 0;
  cin >> N;
  cout << floor(N / 3) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == 'L') { cout << "No\n"; return 0; }
		if (i % 2 == 1 && s[i] == 'R') { cout << "No\n"; return 0; }
	}
	cout << "Yes\n";
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<u32>();

    if v.len() == 1 {
        println!("{}", v[0]);
        return;
    }

    let mut count = 0;
    for i in 0..n {
        if i == 0 {
            if v[i] > 0 && v[i] >= v[i + 1] {
                count += v[i];
            }
        } else if i == n-1 {
            if v[i] > v[i-1] {
                count += v[i];
            }
        } else {
            if v[i] > v[i-1] && v[i] >= v[i+1] {
                count += v[i];
            } else if v[i] <= v[i-1] && v[i] < v[i+1] {
                count -= v[i];
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
ll two[70],a,b,ans,x,y,u,v;
int i,j,k,l,t,n,m,d;
int main(){
    scanf("%lld%lld",&a,&b);
    swap(a,b);
    two[0]=1;
    fo(i,1,62)  two[i]=(ll)two[i-1]*2;
    fd(i,62,0){
        if ((a&two[i])!=(b&two[i])) break;
        if ((a&two[i])>0){
            a^=two[i];
            b^=two[i];
        }
    }
    if (a==b){
        printf("1\n");
        return 0;
    }
    d=i;
    fd(k,i-1,-1)
        if (k==-1||(a&two[k])>0) break;
    x=b;y=two[d]+two[k+1]-1;
    u=two[d]+b;v=two[d+1]-1;
    ans=y-x+1;
    if (u>y) ans+=v-u+1;
    else if (u<=y&&v>y) ans+=v-y;
    printf("%lld\n",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N; cin >> N;
	int ans = 1;
	while (ans*(ans + 1) / 2 < N) ans++;
	while (N > 0) {
		if (N >= ans) {
			cout << ans << endl;
			N -= ans;
		}
		ans--;
	}

	return 0;
}

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll A;
ll B;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> A;
    cin >> B;
    solve();
}

// 入力は全て整数である。
// -100 <= A,\ B <= 100

// ll A, ll B
// A + B, \ A - B, \ A × B の中で最大の数を出力せよ。
void solve(){
    ll ans=A+B;
    chmax(ans,A-B);
    chmax(ans,A*B);
    cout<<ans<<endl;
}


Measured memory_bytes: 256