akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
input = input.split("\n");

var n =Number(input[0]);
var d =Number(input[1].split(" ")[0]);
var x =Number(input[1].split(" ")[1]);
var array=[];
for(var i =0; i<input.length-2; i++){
    array.push(Number(input[i+2]));
}

var total=[];
for(var j =0; j<n; j++){
    for(var k=1; k<=100;k++){
    if(d>=k*array[j]+1){
        total.push(k*array[j]+1);
}
    }
}
var result =total.length+n+x;
console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		int AB = A*B;
		int CD = C*D;
		
		if(A * B > C * D){
			System.out.println(AB);
		}
		else if(A * B < C * D){
			System.out.print(CD);
		}
		else if(A*B == C*D){
			System.out.print(AB);
		}

	}

}


Measured memory_bytes: 21588
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scan.nextInt();
        }
        int v;
        int j;
        for(int i=1;i<N;i++){
            for(int k=0;k<N-1;k++){
                System.out.print(A[k]+" ");
            }
            System.out.println(A[N-1]);
            v = A[i];
            j = i-1;
            for(; A[j]>v;){
                A[j+1]=A[j];
                j--;
                if(j<0) break;
            }
            A[j+1]=v;
        }
        for(int k=0;k<N-1;k++){
            System.out.print(A[k]+" ");
        }
        System.out.println(A[N-1]);
    }
}


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

using namespace std;

int main(void) {
	string S;
	cin >> S;
	int md = (1 << 28);
	for (int i = 0; i < S.length()-2; ++i) {
		int score = abs(753-stoi(S.substr(i,3)));
		if (score < md) {
			md = score;
		}
	}
	cout << md << endl;
	return 0;
}


Measured memory_bytes: 256
// atcoder/abc161/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int n, k, c;
  str s;
  while (cin >> n >> k >> c >> s) {

    vec<int> a;
    {
      int x = -1;
      int y = 0;
      for (int i = 0; i < s.size(); ++i) {
        if (x < i && s[i] == 'o') {
          ++y;
          x = i + c;
          a.push_back(i);
        }
      }
      if (y != k) a.clear();
    }
    vec<int> b;
    {
      reverse(s.begin(), s.end());
      int x = -1;
      int y = 0;
      for (int i = 0; i < s.size(); ++i) {
        if (x < i && s[i] == 'o') {
          ++y;
          x = i + c;
          b.push_back(i);
        }
      }
      reverse(s.begin(), s.end());
      reverse(b.begin(), b.end());
      if (y != k) b.clear();
      each (i, b) i = n - i - 1;
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    each (i, a) {
      if (binary_search(b.begin(), b.end(), i)) {
        cout << i + 1 << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3468
#include "iostream"
#include "string"
using namespace std;

int main()
{
	int n,cnt,ans=0;
	string s;
	bool lef[26],rig[26];
	cin >> n;
	cin >> s;
	for (int i = 0; i < n - 1; i++) {
		for (int i = 0; i < 26; i++)
			lef[i] = rig[i] = false;
		for (int j = 0; j <= i; j++)
			lef[s[j] - 'a'] = true;
		for (int j = i + 1; j < n; j++)
			rig[s[j] - 'a'] = true;
		cnt = 0;
		for (int j = 0; j <= 26; j++) {
			if (lef[j] == true && rig[j] == true)
				cnt++;
		}
		if (cnt > ans)
			ans = cnt;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],l,m;
bool f;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),l=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<n;++i){
		if(a[i]+a[i+1]>=l){
			f=1;
			puts("Possible");
			for(int j=1;j<i;++j) printf("%d\n",j);
			for(int j=n-1;j>=i;--j) printf("%d\n",j);
			return 0;
		}
	}
	puts("Impossible");
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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; }

map<lli,lli> makePrimeList2(lli n){
    map<lli,lli> m;
    lli a = 2;
    while(n>=a*a){
        if(n%a==0){
            m[a]++;
            n /= a;
        }
        else a++;
    }
    if(n!=1)m[n]++;
    return m;
}


int main(){

    lli n;
    cin>>n;

    lli ans = 0;
    REP(i,1,n+1){
        if(i%2==0)continue;
        map<lli,lli> prime = makePrimeList2(i);

        lli cnt = 1;
        for(auto e:prime){
            cnt *= (e.second+1);
        }
        LOG2(i,cnt);
        if(cnt==8)ans++;
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int ll;
#define MOD (1000000007);
#define INF (2e9)

int main(void){
	int n,m;
	cin>>n>>m;
//	int *x=new int[n];
//	int *y=new int[m];
	ll sumx=0 ,sumy=0;
	ll x,y;
	for(int i=0;i<n;i++){
		cin>>x;
		sumx+=(i*x-(n-1-i)*x)%MOD;
		sumx=sumx%MOD;
	}
	for(int i=0;i<m;i++){
		cin>>y;
		sumy+=(i*y-(m-1-i)*y)%MOD;
		sumy=sumy%MOD;
	}
	ll ans=(sumx*sumy)%MOD
	cout<< ans <<endl;
	return 0;
}

Measured memory_bytes: 384
a,b,c,d=map(int,input().split())
import fractions
lcm=c*d//fractions.gcd(c,d)
#1~Bの中
count=b-(b//c+b//d)+b//lcm

#1~A-1の中
temp_count=a-1-((a-1)//c+(a-1)//d)+(a-1)//lcm
print(count-temp_count)


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

int main() {
  int N, j;
  cin >> N;  // 4
  vector<int> vec(N + 1);  //vec {0, 0, 0, 0, 0}
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);  //vec {10, 8, 8, 6, 0}
  }
  
  sort(vec.begin(), vec.end());  //vec {0, 6, 8, 8, 10}
  
  for (int i = 0; i < N; i++) {
    if (vec.at(i + 1) > vec.at(i)) {
        j += 1;
    }
  }
  
  cout << j << endl;  // 3
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

long long gcd(long long a, long long b)
{
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main()
{
  ll N; cin >> N;
  vector<ll> a(N); REP(i, N) cin >> a[i];

  ll g = a[0];
  for (int i = 1; i < N; i++) {
    g = gcd(g, a[i]);
  }
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;

const int N = 55;
const int MOD = 1e9 + 7;
ll n, k;

void add(int& a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int mul(int a, int b) {
    int res = 0;
    while (b) {
        if (b & 1) add(res, a);
        add(a, a);
        b >>= 1;
    }
    return res;
}

int temp[N][N];

struct Matrix {
    int a[N][N];

    explicit Matrix() {}

    void read() {
        memset(a, 0, sizeof a);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                scanf("%d", a[i] + j);
            }
        }
    }

    void identity() {
        memset(a, 0, sizeof a);
        for (int i = 0; i < n; ++i) a[i][i] = 1;
    }

    void mul(const Matrix& b) {
        memset(temp, 0, sizeof temp);
        for (int i = 0; i < n; ++i) {
            for (int k = 0; k < n; ++k) {
                for (int j = 0; j < n; ++j) {
                    add(temp[i][j], ::mul(a[i][k], b.a[k][j]));
                }
            }
        }
        memcpy(a, temp, sizeof a);
    }

    void print() const {
        for (int i = 0; i < n; ++i, putchar('\n')) {
            for (int j = 0; j < n; ++j) {
                printf("%d ", a[i][j]);
            }
        }
    }
};

void pow(ll k) {
    Matrix a, res;
    a.read();
    res.identity();
    while (k) {
        if (k & 1) res.mul(a);
        a.mul(a);
        k >>= 1;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            add(ans, res.a[i][j]);
        }
    }
    printf("%d\n", ans);
}

int main() {
    while (~scanf("%lld%lld", &n, &k)) {
        pow(k);
    }
    return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    ll n=s.size();
    ll ans=1;
    vector<int> count(26,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            if(s[i]-'a'==j)continue;
            ans+=count[j];
        }
        count[s[i]-'a']++;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 720
def main():
    n, a, b = map(int, input().split())
    if (bin(a).count("1")+bin(b).count("1")) % 2 == 0:
        print("NO")
        return
    print("YES")

    def calc(a, b, k):
        if k == 1:
            return [a, b]
        for i in range(k):
            if ((a >> i) & 1) ^ ((b >> i) & 1):
                break
        a2 = (a & (2**i-1))+((a >> (i+1)) << i)
        b2 = (b & (2**i-1))+((b >> (i+1)) << i)
        a3 = ((a >> i) & 1)
        b3 = ((b >> i) & 1)
        c = a2 ^ 1
        q = calc(a2, c, k-1)
        r = calc(c, b2, k-1)
        q = [((t >> i) << i+1)+(a3 << i)+(t & (2**i-1)) for t in q]
        r = [((t >> i) << i+1)+(b3 << i)+(t & (2**i-1)) for t in r]
        return q+r
    print(*calc(a, b, n))


main()


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

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


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int a, b;
    cin>>a>>b;
    cout<<max(0ll,(a-2*b));
}


int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <bitset>
#include <utility> 
using namespace std;

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a==b&&b==c) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

ans = 0
A1s = [A1[0]]
for n in range(1, N):
    A1s.append(A1s[-1] + A1[n])


for i in range(N):
    ans = max(ans, A1s[i] + sum(A2[i:]))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

using pll = pair<ll,ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,s,t;
    cin >> N >> M >> s >> t;
    s--;t--;
    vector<vector<pll>> G(N);
    for(int i=0; i<M; i++){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;
        G[a].emplace_back(b,d);
        G[a].emplace_back(c,d);
        G[b].emplace_back(a,d);
        G[b].emplace_back(c,d);
        G[c].emplace_back(a,d);
        G[c].emplace_back(b,d);
    }
    priority_queue<pll,vector<pll>,greater<pll>> que;
    vector<ll> dist(N,INF);
    que.emplace(0,s);
    dist[s] = 0;
    while(que.size()){
        int v = que.top().second;
        ll cost = que.top().first;
        que.pop();
        if(dist[v] < cost) continue;
        for(auto hoge: G[v]){
            int nv = hoge.first;
            ll ncost = hoge.second;
            if(cost+ncost < dist[nv]){
                dist[nv] = cost+ncost;
                que.emplace(dist[nv],nv);
            }
        }
    }
    cout << dist[t] << "\n";
    return 0;
}



Measured memory_bytes: 23656
// AOJ ALDS1_9_C Priority Queue
// 2018.4.27 bal4u

#include <stdio.h>

#define QSIZE 2000002

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int t; } QUE;
QUE que[QSIZE+5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	QUE qt;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t > que[i].t) max = l; else max = i;
	if (r < qsize && que[r].t > que[max].t) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

int deq()
{
	int r = que[0].t;
	que[0] = que[--qsize];
	max_heapify(0);
	return r;
}

void enq(int t)
{
	int i, max;
	QUE qt;

	i = qsize++;
	que[i].t = t;
	while (i > 0 && que[max = PARENT(i)].t < que[i].t) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}

// バッファを経ずstdinから数値を得る
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i = 0;
	if (n == 0) buf[i++] = '0';
	else while (n) buf[i++] = n%10 + '0', n/=10;
	while (i) pc(buf[--i]);
	pc('\n');
}
			
int main()
{
	int k;

	qsize = 0;
	while (1) {
		if (gc() == 'e') {
			if (gc() == 'n') break;
			k = 6; while (k--) gc();
			mypr(deq());
		} else {
			k = 6; while (k--) gc();
			enq(in());
		}
	}
	return 0;
}



Measured memory_bytes: 5460
#include <iostream>
#define N 2000000
using namespace std;
int A[N], B[N];
void countSort(int A[], int B[], int n){
    int i;
    int C[10000];
    for (i = 0; i < 10000; i++)
        C[i] = 0;
    for (i = 0; i < n; i++)
        C[A[i]]++;
    for (i = 1; i < 10000; i++)
        C[i] += C[i-1];
    for (i = n-1; i >= 0; i--){
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }
}
int main()
{
    int i, n;

    cin >> n;
    for (i = 0; i < n; i++)
        cin >> A[i];
    countSort(A, B, n);
    for (i = 0; i < n; i++){
        if (i) cout << ' ';
        cout << B[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 18760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))
#define mod               1000000007

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 105;
const int K = 1e5 + 5;
int a[N];
int dp[N][K];
int presum[K];
int n, k;

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i <= a[0]; i++)
    {
        dp[0][i] = 1;
    }
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = 1;
        memset(presum, 0, sizeof(presum));
        presum[0] = dp[i - 1][0];
        for (int j = 1; j <= k; j++) {
            presum[j] = presum[j - 1] + dp[i - 1][j];
        }
        for (int j = 1; j <= k; j++)
        {
            if (j >= a[i] + 1)
                dp[i][j] += presum[j] - presum[j - a[i] - 1];
            else
                dp[i][j] += presum[j];
            dp[i][j] %= mod;
        }
    }
    cout << dp[n - 1][k] << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 80128
/*
    ☁ ☁         ☀     ☁☁
            ☁ ✈    ☁☁

🌳🌲_________🌳___🌳____🌲___🌳
     /    |    \
    /       🚔\
    /     |      \ С ДОРОГИ МЕНТЫ ЕДУТ ПАЦАНЫ
   /        🚘  \
   /             \ 
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define ppb pop_back
#define re return
#define forn(i, n) for (int i = 1; i <= (int)(n); i++)
#define fore(i, n) for (int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n); i >= 1; i--)
#define forde(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forr(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define fz(a) memset((a), 0, sizeof((a)))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SZ(x) (int)((x).size())
#define zhfs main

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

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

void gn(int &x) { scanf("%d", &x); }
void gn(long long &x) { scanf("%lld", &x); }
void pi(int x) { printf("%d ", x); }
void pi(long long x) { printf("%lld ", x); }

int cnt[26];
char buf[1007];
int zhfs() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=  0; i < n; i++){
    scanf("%s", buf);
    for (int j= 0; j < m; j++){
      cnt[buf[j]-'a']++;
    }
  }
  if (n % 2 == 0 && m % 2 == 0) {
    for (int i= 0; i< 26; i++) {
      if (cnt[i] % 4){
        puts("No");
        return 0;
      }
    }
    puts("Yes");
  } else {
    int g2 = 0, g1  =0;
    if (n % 2 == 1 && m % 2 == 1) {
      g2 = n / 2 + m / 2;
      g1 = 1;
    } else if (n % 2) {
      g2 = m / 2;
    } else {
      g2 = n / 2;
    }
    for (int i = 0; i< 26; i++) {
      if (cnt[i] % 2 == 1 && g1) {
        cnt[i]--;
        g1--;
      }
    }
    for (int i =0; i <26;i++){
      if (cnt[i] % 4 == 2 && g2) {
        cnt[i] -= 2;
        g2--;
      }
    }
    if (g2 % 2) {
      puts("No");
      return 0;
    }
    for (int i = 0; i < 26; i++) {
      if (cnt[i] % 4) {
        puts("No");
        return 0;
      }
    }
    puts("Yes");
  }
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {
    lli N, M;
    cin >> N >> M;

    vector<lli> L(M);
    vector<lli> R(M);

    for (int i = 0; i < M; ++i) {
        cin >> L[i];
        cin >> R[i];
    }

    lli lMax = *max_element(L.begin(), L.end());
    lli rMin = *min_element(R.begin(), R.end());

    if (lMax <= rMin) {
        cout << rMin - lMax + 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #pragma GCC optimization ("unroll-loops")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
    string s;
    cin >> s;
    int n = s.size();
    int len=0;
    int ans=0;
    for(int i=0;i<n;i++){
    	if(s[i]=='R'){
    		len++;
    	}
    	else{
    		ans = max(ans,len);
    		len=0;
    	}
    }
    ans = max(ans,len);
    cout << ans;
  }

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying

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

int main()
{
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    ll sum_a = 0l;
    rep(i, n) sum_a += a.at(i);

    if (h - sum_a <= 0l)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int n;
    cin >> n;
    ve<vi> a(10,vi(10,0));
    
    reps(i,1,n+1){
        string s = to_string(i);
        a[s.front()-'0'][s.back()-'0']++;
    }
    ll ans = 0;
    
    for (int i = 1; i <= 9; i++) {
        for (int j = i; j <= 9; j++) {
            if(i==j) ans += (ll)a[i][j]*(ll)a[j][i];
            else ans += (ll)a[i][j]*(ll)a[j][i]*2;
        }
    }
    //reps(i,1,10) {reps(j,1,10) cout << a[i][j] << " ";cout << endl;}
    out(ans);



    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
YPI = []
for i in range(M):
  P, Y = map(int, input().split())
  YPI.append([Y, P, i])

YPI.sort()
ans = [''] * M
num_city = {}
for y, p, i in YPI:
  if p in num_city:
    num_city[p] += 1
  else:
    num_city[p] = 1
  
  ans[i] = str(p).zfill(6) + str(num_city[p]).zfill(6)

print(*ans, sep='\n')

Measured memory_bytes: 38956
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
        ll N;
        cin >> N;
        vector<ll> A(N+1);
        vector<ll> B(N);
        for(ll i=0; i<N+1; i++){
                cin >> A[i];
        }
        for(ll i=0; i<N; i++){
                cin >> B[i];
        }
        ll Count =0;
        for(ll i=0; i<N; i++){
                if(A[i] >= B[i]){
                        Count += B[i];
                        B[i] = 0;
                }
                else{
                        B[i] -= A[i];
                        Count += A[i];
                        if(A[i+1] >= B[i]){
                                A[i+1] -= B[i];
                                Count += B[i];
                        }
                        else{
                                Count += A[i+1];
                                A[i+1] = 0;
                        }
                }
        }
        cout << Count ;


}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

constexpr ll mod = 1e9+7;

struct Edge {
  int to;
  int cost;
};
std::vector<std::vector<Edge>> G;
std::vector<std::vector<ll>> dp;

ll dfs(int v, int p, bool w) {
  ll rtn = 1;
  if ( dp[v][w] != -1 ) return dp[v][w];
  //std::cout << p << " -> " << v << " : " << (w ? "white" : "black") << std::endl;
  for(auto&& g : G[v]) {
    if ( g.to == p ) continue;
    if ( w ) rtn *= ((dfs(g.to, v, true ) % mod) + (dfs(g.to, v, false) % mod)) % mod;
    else     rtn *= (dfs(g.to, v, true ) % mod);
    rtn %= mod;
  }
  return dp[v][w] = rtn%mod;
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N; G.resize(N);
  rep(i, N-1) {
    int x, y; std::cin >> x >> y; x--,y--;
    G[x].push_back( Edge({y, 1}) );
    G[y].push_back( Edge({x, 1}) );
  }
  dp.resize(N); rep(i,N) dp[i].assign(2, -1);
  std::cout << (dfs(0, -1, true) + dfs(0, -1, false)) % mod << std::endl;

  return 0;
}



Measured memory_bytes: 19584
#include<iostream> 
using namespace std; 
  
int main ()
{
  int a,b,c,p1,p2;
  cin>>a>>b>>c;
  p1=b-a;
  p2=c-b;
  if (p1==p2)
  {
      cout<<"YES\n";
  }
  else
  {
      cout<<"NO\n";
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>   
using namespace std;
#define N 3005
#define REP(i, n) for(int i=0; i<n; i++)

int cou;
int a,b,c,x;
int main(){
    cin >>a >>b >>c >>x;

    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50==x)cou++;
            }
        }
    }
    cout << cou <<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000
using namespace std;
int n,m,q;
char Map[MAXN+5][MAXN+5];
int sum1[MAXN+5][MAXN+5];
int sum2[MAXN+5][MAXN+5],sum3[MAXN+5][MAXN+5];
int main()
{
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",Map[i]+1);
		for(int j=1;j<=m;j++)
		{
			sum1[i][j]=sum1[i-1][j]+sum1[i][j-1]-sum1[i-1][j-1]+Map[i][j]-'0';
			int add2=0,add3=0;
			if(Map[i][j]=='1')
			{
				if(Map[i][j-1]=='1')	add2++;
				if(Map[i-1][j]=='1')	add3++;
			}
			sum2[i][j]=sum2[i-1][j]+sum2[i][j-1]-sum2[i-1][j-1]+add2;
			sum3[i][j]=sum3[i-1][j]+sum3[i][j-1]-sum3[i-1][j-1]+add3;
		}
	}
	int x1,y1,x2,y2;
	for(int i=1;i<=q;i++)
	{
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		int poicnt=sum1[x2][y2]-sum1[x1-1][y2]-sum1[x2][y1-1]+sum1[x1-1][y1-1];
		int edcnt2=sum2[x2][y2]-sum2[x1-1][y2]-sum2[x2][y1]+sum2[x1-1][y1];
		int edcnt3=sum3[x2][y2]-sum3[x1][y2]-sum3[x2][y1-1]+sum3[x1][y1-1];
		int edcnt=edcnt2+edcnt3;
		printf("%d\n",poicnt-edcnt);
	}
	return 0;
}

Measured memory_bytes: 52736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		for(int i = 0; i < s.length(); i++)
		{
			if(i >= 1 && s.charAt(i) == s.charAt(i-1))
			{
				System.out.println(i + " " + (i+1));
				return;
			}
			else if(i>=2 && s.charAt(i) == s.charAt(i-2))
			{
				System.out.println((i-1) + " " + (i+1));
				return;
			}
		}
		System.out.println("-1 -1");
	}

}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

char s[1234567];
int cnt[30];
const int mod = 1e9 + 7;

int main() {
	make(n);
	scanf("%s", s);
	FOR(i,0,n) cnt[s[i]-'a']++;
	int ans = 1;
	FOR(i,0,27) ans = (ans *1LL*(cnt[i] + 1)) % mod;
	printf("%d\n", (ans+mod -1) % mod);
}






Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
char mas[13][13];
int dx[5] = {0,0,1,-1,0};
int dy[5] = {1,-1,0,0,0};
void island(int x, int y);
int main(){
  while(1){
    int ans = 0;
    for(int i = 0; i < 12; i++){
      cin >> mas[i];
    }
    if(cin.eof()){
      break;
    }
    for(int i = 0; i < 12; i++){
      for(int j = 0; j < 12; j++){
	if(mas[i][j] == '1'){
	  island(j,i);
	  ans++;
	}
      }
    }
    printf("%d\n",ans); 
  }
}
void island(int x, int y){
  mas[y][x] = '0';
  for(int i = 0; i < 5; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(mas[ny][nx] == '1' && ny < 12 && nx < 12 && ny >= 0 && nx >= 0){
      island(nx,ny);
    }
  }
}

Measured memory_bytes: 1124
import math

n = int(input())

for i in range(n):
	x1, y1, x2, y2, x3, y3 = map(float, input().split()) # Get variables
	a = 2 * (x2 - x1)
	b = 2 * (y2 - y1)
	c = math.pow(x2, 2) + math.pow(y2, 2) - math.pow(x1, 2) - math.pow(y1, 2)
	d = 2 * (x3 - x1)
	e = 2 * (y3 - y1)
	f = math.pow(x3, 2) + math.pow(y3, 2) - math.pow(x1, 2) - math.pow(y1, 2)
	px = (c * e - b * f) / (a * e - b * d)
	py = (a * f - c * d) / (a * e - b * d)
	r = math.sqrt(math.pow(x1 - px, 2) + math.pow(y1 - py, 2))
	print('{:.3f}'.format(px) + ' ' + '{:.3f}'.format(py) + ' ' + '{:.3f}'.format(r))

Measured memory_bytes: 7720
/*
                        ********************
			**  MANAN DIYORA  **
			**    DA-IICT     **
			**   diyora13     **
			********************
*/
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define gcd(a,b) __gcd(a,b)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define len length()
#define all(v) v.begin(),v.end()

typedef long long int ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) { return (a.second < b.second); }
#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0;

int main()
{
	IOS
	ll t=1;
//		cin>>t;
	while(t--)
	{
		ll n; cin>>n;
		vpll v(n);
		fr(i,0,n) cin>>v[i].F;
		v[0].S=1000;
		fr(i,1,n)
		{
			v[i].S=v[i-1].S;
			rf(j,i,0)
			{
				if(v[j].F<=v[i].F)
				{
					ll pro=(v[j].S/v[j].F)*(v[i].F-v[j].F);
					v[i].S=max(v[j].S+pro,v[i].S);
				}
			}
//			cout<<i<<"***"<<v[i].S<<endl;
		}
		cout<<v[n-1].S;
	}
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>
#include <algorithm>

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

using namespace std;

int main(){
	int n;
	int a[100005];
	
	cin >> n;
	a[0] = 0;
	a[n+1] = 0;
	REP(i,n) cin >> a[i+1];
	
	long long int cost = 0;
	
	REP(i,n+1){
		cost += abs(a[i]-a[i+1]);
	}
	
	for(int i=1; i<=n; i++){
		if ((a[i-1]<=a[i] && a[i]<=a[i+1]) || (a[i+1]<=a[i] && a[i]<=a[i-1])){
			cout << cost << endl;
		}else{
			cout << cost-2*(min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))) << endl;
		}
	}
	
	return 0;
	
}


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

A_abs = [abs(i) for i in A]
A_abs_sum = sum(A_abs)
if 0 in A or len([i for i in A if i < 0]) % 2 == 0:
  print(A_abs_sum)
else:
  print(A_abs_sum - min(A_abs) * 2)


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

int main(){
    int n,k;
    cin >> n>>k;
    vector<int> ans(n);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            ans.at(a-1)++;
        }
    }
    int res = 0;
    rep(i,ans.size()){
        if(ans.at(i)==0) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3604
using System;
using System.Linq;

namespace AtCoder09_06
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] upperRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] lowerRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int column;
            //t row=0;
            int max=0;
            int upperSum = 0;
            int lowerSum = 0;
            for (column = 0; column < n; column++)
            {
                upperSum = upperSum + upperRow[column];
                for (int i = 0; i < n - column; i++)
                {
                    lowerSum = lowerSum + lowerRow[i+column];

                }
                if (lowerSum + upperSum > max) max = lowerSum + upperSum;
                lowerSum = 0;
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
const ll mod = 1e9 + 7;
vector<int>g[maxn];
int n;

ll ifact[maxn], fact[maxn];
ll sbtsize[maxn];
ll dp[maxn];
ll result[maxn];

ll power(ll a, ll b) {
	if(b == 0) return 1LL;
	else if(b == 1LL) return 1LL * a % mod;
	else {
		if(b % 2 == 0) {
			ll half = power(a, b / 2);
			return (half*half)%mod;
		}
		else return (a*power(a, b-1))%mod;
	}
}

void preprocess() {
	ifact[0] = fact[0] = 1LL;
	for(int i=1;i<maxn;i++) {
		fact[i] = (1LL * fact[i-1] * i) % mod;
		ifact[i] = power(fact[i], mod-2); ifact[i] %= mod;
	}
}

void zero_dfs(int node, int p) {
	sbtsize[node] = 1LL;
	dp[node] = 1LL;
	for(int i:g[node]) {
		if(i == p) continue;
		zero_dfs(i, node);
		sbtsize[node] += sbtsize[i];
		dp[node] *= dp[i]; dp[node] %= mod;
		dp[node] *= ifact[sbtsize[i]]; dp[node] %= mod;
	}
	dp[node] *= fact[sbtsize[node] - 1]; dp[node] %= mod;
}

void second_dfs(int node, int p) {
	result[node] = dp[node];

	for(int i:g[node]) {
		if(i == p) continue;

		dp[node] *= ifact[sbtsize[node] - 1]; dp[node] %= mod;
		sbtsize[node] -= sbtsize[i];

		dp[node] *= fact[sbtsize[i]]; dp[node] %= mod;
		dp[node] *= power(dp[i], mod-2); dp[node] %= mod;
		dp[node] *= fact[sbtsize[node] - 1]; dp[node] %= mod;

		dp[i] *= ifact[sbtsize[i] - 1]; dp[i] %= mod;

		sbtsize[i] += sbtsize[node];
		dp[i] *= dp[node]; dp[i] %= mod;
		dp[i] *= ifact[sbtsize[node]]; dp[i] %= mod;
		dp[i] *= fact[sbtsize[i] - 1]; dp[i] %= mod; 

		second_dfs(i, node);

		dp[i] *= ifact[sbtsize[i] - 1]; dp[i] %= mod;
		dp[i] *= fact[sbtsize[node]]; dp[i] %= mod;
		dp[i] *= power(dp[node], mod - 2); dp[i] %= mod;

		sbtsize[i] -= sbtsize[node];

		dp[i] *= fact[sbtsize[i] - 1]; dp[i] %= mod;

		dp[node] *= ifact[sbtsize[node] - 1]; dp[node] %= mod;
		dp[node] *= dp[i]; dp[node] %= mod;
		dp[node] *= ifact[sbtsize[i]]; dp[node] %= mod;

		sbtsize[node] += sbtsize[i];
		dp[node] *= fact[sbtsize[node] - 1]; dp[node] %= mod;
	}
}

int main() {
	cin>>n;

	int a, b;
	for(int i=0;i<n-1;i++) {
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}

	preprocess();
	zero_dfs(1, -1);
	second_dfs(1, -1);

	for(int i=1;i<=n;i++) {
		cout<<result[i]<<"\n";
	}
}

Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,m,k;
vector<P1>edgea,edgeb;

struct uf{
	int par[205],ran[205];
	void init(){
		rep(i,205) par[i]=i,ran[i]=0;
	}
	int find(int x){
		if(x==par[x]) return x; else return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x == y) return;
		if(ran[x] < ran[y]){
			par[x] = y;
		}
		else{
			par[y] = x;
			if(ran[x] == ran[y]) ran[x]++;
		}
	}
	bool same(int x,int y){ return find(x) == find(y); }
	
}kaede;

bool cmp(const pair<P1,int> &a,const pair<P1,int> &b){
    if(a.fi.fi != b.fi.fi) return a.fi.fi < b.fi.fi;
    else return a.sc < b.sc;
}
int main(){
	while(1){
		cin >> n >> m >> k;
		if(n == 0) return 0;
		edgea.clear(); edgeb.clear();
		for(int i=0;i<m;i++){
			int u,v,w; char c; scanf("%d%d%d %c",&u,&v,&w,&c);
			if(c == 'A'){
				edgea.pb(mp(w,mp(u,v)));
			}
			else{
				edgeb.pb(mp(w,mp(u,v)));
			}
		}
		SORT(edgea); SORT(edgeb);
		int lb = -200, ub = 200;
		int ans = INF;
		while(ub-lb > 1){
			int mid = (lb+ub)/2;
			vector<pair<P1,int> >vec;
			for(int i=0;i<edgeb.size();i++) vec.pb(mp(edgeb[i],0));
			for(int i=0;i<edgea.size();i++) vec.pb(mp(mp(edgea[i].fi+mid,edgea[i].sc),1));
			sort(vec.begin(),vec.end(),cmp);
			kaede.init();
			int cnt = 0,ch = 0;
			for(int i=0;i<vec.size();i++){
				int u = vec[i].fi.sc.fi, v = vec[i].fi.sc.sc;
				if(kaede.same(u,v) == false){
					kaede.unite(u,v);
					if(vec[i].sc == 1) cnt++;
					ch++;
				}
			}
			if(ch != n-1){
				ans = INF;
				break;
			}
			vector<pair<P1,int> >vecc;
			for(int i=0;i<edgeb.size();i++) vecc.pb(mp(edgeb[i],2));
			for(int i=0;i<edgea.size();i++) vecc.pb(mp(mp(edgea[i].fi+mid,edgea[i].sc),1));
			sort(vecc.begin(),vecc.end(),cmp);
			kaede.init();
			int cnt2 = 0, anss = 0;
			for(int i=0;i<vecc.size();i++){
				int u = vecc[i].fi.sc.fi, v = vecc[i].fi.sc.sc;
				if(kaede.same(u,v) == false){
					kaede.unite(u,v);
					anss += vecc[i].fi.fi;
					if(vecc[i].sc == 1) cnt2++;
				}
			}
			assert(cnt <= cnt2);
			//cout << cnt << " " << cnt2 << " " << mid << endl;
			if(k < cnt){
				lb = mid;
			}
			else if(k > cnt2){
				ub = mid;
			}
			else{
				ans = min(ans,anss-mid*k);
				break;
			}
		}
		if(ans == INF) puts("-1");
		else printf("%d\n",ans);
	}
}


Measured memory_bytes: 3268
def main(X, K, D):
    x = abs(X)
    k = K

    shou, amari = x // D, x % D
    if shou >= k:   # 0付近までたどり着かないとき
        x -= k * D
        k = 0
    else:
        k -= (shou + 1)
        x -= (shou + 1) * D

    if k % 2:    # 奇数のとき
        print(abs(x + D))
    else:   # 偶数の時
        print(abs(x))

if __name__ == '__main__':
    X, K, D = list(map(int, input().split()))
    main(X, K, D)

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

/*
 *  最大公約数を求める
 *  ユークリッドの互除法
 * */

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main() {
    int N;
    int A[100001];
    cin >> N;
    rep(i,N) {
        cin >> A[i];
    }
    int ans = gcd(A[0], A[1]);
    for(int i=2; i<N; ++i) {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import itertools
def w_f(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

n, m, r = map(int,input().split())
LR = map(int,input().split())
d = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 

D = w_f(d)
lr = list(itertools.permutations(LR))
ans = float("inf")
for li in lr:
    jd = 0
    for i in range(r-1):
        jd += D[li[i]-1][li[i+1]-1]
    
    if jd < ans:
        ans = jd
print(ans)

Measured memory_bytes: 65880
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(2));
  for (int i = 0; i < n; i++){
    cin >> a[i][0];
    a[i][1] = i + 1;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++){
    cout << a[i][1] << " ";
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 6272