akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const long long MD = 1e9+7;

inline long long ADD(long long a, long long b) {
	return (a + b) % MD;
}

inline long long SUB(long long a, long long b) {
	return ((a - b) % MD + MD) % MD;
}

inline long long MUL(long long a, long long b) {
	return (a * b) % MD;
}

inline long long powMod(long long a, long long p) {
	long long res = 1;
	for (; p; p >>= 1, a = MUL(a,a)) {
		if (p & 1) res = MUL(res,a);
	}
	return res;
}

int main() {
	long long N;
	cin >> N;
	printf("%lld\n", ADD(SUB(powMod(10, N), MUL(powMod(9, N),2)), powMod(8,N)));
	return 0;
}

Measured memory_bytes: 3692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C_DubiousDocument2
{
    class Program
    {
        static void Main(string[] args)
        {
            string strS = Console.ReadLine();
            string strT = Console.ReadLine();

            int intLenS = strS.Length;
            int intLenT = strT.Length;

            const string CST_NGMSG = "UNRESTORABLE";


            if (intLenS < intLenT)
            {
                Console.WriteLine(CST_NGMSG);
                return;
            }


            string strReplacedS = strS;
            string strReplacedS2 = strS;
            string strComp = "z";
            bool blnChk = false;
            for (int i = 0; i <= intLenS - intLenT; i++) {
                int intChkCnt = 0;
                for (int j = 0; j < intLenT; j++) {
                    if (strS.Substring(i + j, 1) == strT.Substring(j, 1) || strS.Substring(i + j, 1) == "?") { 
                        intChkCnt++;
                        if (intChkCnt == intLenT)
                        {
                            var sbS = new StringBuilder(strS); // strS → sbS
                            string strOld = strS.Substring(i, intLenT);
                            strReplacedS = sbS.Replace(strOld, strT, i, intLenT).ToString(); // sbS → strReplacedS
                            blnChk = true;
                        }
                    } else {
                        break;
                    }
                }
                if (blnChk) { 
                    strReplacedS2 = strReplacedS.Replace("?", "a");
                    int intVal = strReplacedS2.CompareTo(strComp);
                    if (intVal < 0)
                    {
                        strComp = strReplacedS2;
                    }
                }

            }

            if (blnChk) {
                Console.WriteLine(strComp);
            } else { 
                Console.WriteLine(CST_NGMSG);
            }

            return;
        }
    }
}


Measured memory_bytes: 13408
# ABC075C - Bridge
# find the number of bridges in a given undirected connected graph
# bridge := an edge whose removal disconnects a graph
import sys
from copy import deepcopy

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


def dfs(v: int, g: "List[List[int]]", seen: "List[int]") -> None:
    seen[v] = 1  # make vertex v searched
    for u in g[v]:
        if not seen[u]:
            dfs(u, g, seen)


def main():
    N, M = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]
    for v, u in E:  # construct a graph
        G[v] += [u]
        G[u] += [v]
    bridges = 0
    for v, u in E:
        g = deepcopy(G)  # subgraph of G withiout E(v, u)
        g[v].remove(u)
        g[u].remove(v)
        seen = [0] * (N + 1)
        dfs(1, g, seen)
        bridges += 1 if 0 in seen[1:] else 0
    print(bridges)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int i = vs[1];
			Console.WriteLine(n - i + 1);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll N;
vector<ll> A(200010);
vector<ll> sum(200010, 0);
ll ans = 0;

int main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        sum[A[i] - 1]++;
    }

    rep(i, N) {
        ans += (sum[i] - 1) * sum[i] / 2;
        //cout << ans << endl;
    }

    rep(i, N) {
        ll tmp = sum[A[i] - 1];
        //ll ans_k = ans - (tmp - 1) * tmp / 2 + (tmp - 1) * (tmp - 2) / 2;
        ll ans_k = ans - (tmp - 1);
        cout << ans_k << endl;
    }
}

Measured memory_bytes: 6280
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}
void sort(int A[],int n){
  int i,j,v;
  for(i=1;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    
    A[j+1]=v;
    trace(A,n);
  }
}
int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
 
  sort(A, n);
 
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int n;

    scanf("%d", &n);

    int x;
    bool is_a[128] = {false};
    scanf("%d", &x);
    while (x--){
        int a;
        scanf("%d", &a);
        is_a[a] = true;
    }

    int y;
    bool is_b[128] = {false};
    scanf("%d", &y);
    while (y--){
        int b;
        scanf("%d", &b);
        is_b[b] = true;
    }

    int z;
    scanf("%d", &z);
    int cnt = 0;
    while (z--){
        int c;
        scanf("%d", &c);
        cnt += !is_a[c] || is_b[c];
    }

    printf("%d\n", cnt);

    return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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


double dis(pii a , pii b){
    return sqrt(1LL * (a.fr - b.fr) * (a.fr - b.fr) + 1LL * (a.sc - b.sc) * (a.sc - b.sc));
}

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin >> n;
    vii v(n);
    for(auto &p : v)cin >> p.fr >> p.sc;

    double sum = 0;
    int cnt = 0;
    sort(ALL(v));
    do{
        cnt++;
        double cur = 0;
        loop(i,n-1){
            cur += dis(v[i],v[i+1]);
        }
        sum += cur;
    }while(next_permutation(ALL(v)));

    cout << fixed << setprecision(12) << sum / cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

  return 0;
}

Measured memory_bytes: 2508
# bit全探索の解法
s = input()
# "+"は数字の間にしか入らないので、n-1で調べる
n = len(s) -1

ans = 0
for bit in range(1<<(n)):
    f = s[0]
    for i in range(n):
        if (bit >> i) & 1 :
            f += "+"
        f += s[i + 1]
    #print(f)
    ans += eval(f)

print(ans)


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

int main() {
  int n;
  cin >> n;
  vector<int> ct(100005, 0);
  long long sum = 0;
  for ( int i = 0; i < n; i++ ) {
    int a;
    cin >> a;
    ct[a]++;
    sum += a;
  }

  int q;
  cin >> q;
  while ( q-- > 0 ) {
    long long b, c;
    cin >> b >> c;
    long long num = ct[b];
    ct[b] = 0;
    sum -= b*num;
    sum += c*num;
    ct[c] += num;
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <cmath>

int main(int argc, char *argv[])
{
    int a,b,c;
    std::cin >> a >> b >> c;

    if(a > b)std::swap(a,b);
    if(b > c)std::swap(b,c);
    if(a > b)std::swap(a,b);

    std::cout << a << " " << b << " " << c << std::endl;

}

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
using ll = long long;

int main(){
        ll i,N,x,y,maxw=-2e9,maxz=-2e9,minw=2e9,minz=2e9;
        cin >> N;
        for(i=0;i<N;++i){
                cin >> x >> y;
                maxw = max(maxw,x+y);
                minw = min(minw,x+y);
                maxz = max(maxz,x-y);
                minz = min(minz,x-y);
        }
        cout << max(maxw-minw,maxz-minz) << endl;
        return 0;
}

Measured memory_bytes: 3572
#include<iostream>

using namespace std;
using ll = long long;
int main(){
  int c[3][3];
  for (int i = 0; i < 3; i++){
    cin >> c[i][0] >> c[i][1] >> c[i][2];
  }
  if((c[1][0] + c[0][1]) != (c[0][0] + c[1][1])){
    cout << "No\n";
  }else if((c[2][0] + c[0][2]) != (c[0][0] + c[2][2])){
    cout << "No\n";
  }else if((c[2][1] + c[1][2]) != (c[1][1] + c[2][2])){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }

  return 0;
}

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;


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

  ll ans = 0;
  while (1) {
    ll mi = INF;
    REP(i, N) {
      if (h[i] > 0) mi = min(mi, h[i]);
    }
    ll cnt = 0;
    bool cont = false;
    REP(i, N) {
      if (cont == false && h[i] > 0) {
        cont = true;
      }
      if (cont == true && h[i] == 0) {
        cont = false;
        cnt++;
      }
    }
    if (cont) cnt++;
    bool flag = true;
    REP(i, N) {
      if (h[i] > 0) {
        h[i] -= mi;
        if (h[i] > 0) flag = false;
      }
    }
    ans += mi * cnt;
    if (flag) break;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

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

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

int main()
{
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	if ((a+b)&1) puts("Borys"); else puts("Alice");
	return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    long long N;
    cin >> N;
    
    long long a[3*N];
    for (long long i=0; i < 3 * N; ++i)  cin >> a[i];
    
    sort(a, a+3*N, greater<int>());
   
    long long sum = 0;
    for (long long i=0; i < N; ++i) {
        sum += a[2*i + 1];
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
S = list(input())[: -1]
if (S.count("N") > 0 and (S.count("S") > 0)) or (S.count("N") == 0 and (S.count("S") == 0)):
  if (S.count("E") > 0 and (S.count("W") > 0)) or (S.count("E") == 0 and (S.count("W") == 0)):
    print("Yes")
    exit(0)
print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    string s, t;
    cin >> s >> t;
    if(s.size() < t.size()) {
        cout << "UNRESTORABLE" << '\n';
        return 0;
    }
    bool flag = false;
    int I = -1, ii = 0;
    for(int i = s.size()-1; i >= 0; --i) {
        ii = i+1;
        if(flag) break;
        for(int j = t.size()-1; j >= 0; j--) {
            I = i - (t.size() - j - 1);
            if(I < 0) break;
            if(s[I] == t[j] || s[I] == '?') {
                    if(j == 0) {
                    flag = true;
                }
            } else {
                break;
            }
        }
    }

    if(flag) {
        for(int i = 0; i < s.size(); ++i) {
            if(i >= I && i <= ii) {
                s[i] = t[i - I];
            } else {
                if(s[i] == '?') s[i] = 'a';
            }
        }
        cout << s << '\n';
    } else cout << "UNRESTORABLE" << '\n';

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

bool compare(string a, string b) {
  if (a.size() > b.size()) return true;
  else if (a.size() < b.size()) return false;
  return a > b;
}

string dp[10010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, m;
  cin >> n >> m;
  rep(i, 10010) dp[i] = "0";
  vi32 a(m);
  rep(i, m) cin >> a[i];
  sort(all(a));
  map<int, char> mp;
  rep(i, m) {
    switch (a[i]) {
      case 1: mp[1] = 2; break;
      case 2: mp[2] = 5; break;
      case 3: mp[3] = 5; break;
      case 4: mp[4] = 4; break;
      case 5: mp[5] = 5; break;
      case 6: mp[6] = 6; break;
      case 7: mp[7] = 3; break;
      case 8: mp[8] = 7; break;
      case 9: mp[9] = 6; break;
    }
  }
  dp[0] = "";
  reps(i, n) {
    string str = dp[i];
    rep(j, m) {
      char c = a[j] + '0';
      if (i - mp[a[j]] >= 0 && dp[i - mp[a[j]]] != "0" && compare(dp[i - mp[a[j]]] + c, str)) {
        str = dp[i - mp[a[j]]] + c;
      }
    }
    dp[i] = str;
  }
  cout << dp[n] << endl;
  return 0;
}


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

int main(){
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(),v.end());
  cout << v[0] << " " << v[1] << " "<< v[2] << endl;
  return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		int n,m; cin >> n >> m;
		if (n + m == 0) break;
		vi infected(n,0);
		infected[0] = 1;

		vector<pair<int ,pair<int,int>>> data;
		for (int i = 0; i < m; i++){
			int t,s,d; cin >> t >> s >> d;
			data.pb(make_pair(t,make_pair(s,d)));
		}
		sort(data.begin(),data.end());

		for (int i = 0; i < m; i++){
			if (infected[data[i].second.first-1] == 1){
				infected[data[i].second.second-1] = 1;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++){
			ans += infected[i];
		}
		
		cout << ans << endl;


	}

	return 0;
}

Measured memory_bytes: 3432
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int solve(vector<vector<int>> lights, vector<int> ps, int N, int M) {
    int count = 0;

    for (int bits = 0; bits <= ((1 << N) - 1); bits++) {
        bool ok = true;
        for (int i = 0; i < M; i++) {
            int c = 0;
            for (int j = 0; j < (int) lights[i].size(); j++) {
                int s = lights[i][j];
                if (bits & (1 << s)) {
                    c++;
                }
            }
            // printf("bits: 0x%x, i: %d, c: %d\n", bits, i, c);
            if (c % 2 != ps[i]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            count++;
        }
    }

    return count;
}

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

    vector<vector<int>> lights;
    lights.resize(M);
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            s--;
            lights[i].push_back(s);
        }
    }

    vector<int> ps;
    ps.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> ps[i];
    }

    cout << solve(lights, ps, N, M) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int r;
    int g;
    int b;
    scanf("%d",&r);
    scanf("%d",&g);
    scanf("%d",&b);
    int A;
    A=r*100+g*10+b;
    if(A%4==0)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    return 0;
}

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

int conv(char c){
    for (int i = 50; i<=57; i++){
        if (c == i){
            return i-48;
        }
    }
}

int main(){

    string s;
    cin >> s;

    int64_t k;
    cin >> k;

    int answer = 1;
    for (int64_t i = 0; i<k; i++){
        if (s.at(i) != '1'){
            answer = conv(s.at(i));
            break;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 3608
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

def f(perm, ord):
    n = len(perm)
    if n == 2:
        if perm == ord:
            return 1
        else:
            return 2
    else:
        i = ord.index(perm[0])
        ord.pop(i)
        return math.factorial(n-1)*i + f(perm[1:], ord)

print(abs(f(Q, [i+1 for i in range(N)]) - f(P, [i+1 for i in range(N)])))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,w[1000],ans=10000;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>w[i];
		}
	for(int i=0;i<n;i++){
		int ans1=0;
		for(int j=0;j<n;j++){
			if(j<=i)
				ans1+=w[j];
			else
				ans1-=w[j];
		}
		if(ans>abs(ans1))
			ans=abs(ans1);
	}
	cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  int count=0;
  for(int i=1;i<N-1;i++){
    if(p.at(i-1)<p.at(i)&&p.at(i)<p.at(i+1)){count++;}
    if(p.at(i-1)>p.at(i)&&p.at(i)>p.at(i+1)){count++;}
}
  cout<<count<<endl;
  return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;


    int A,B;
    char S[101][101];

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>A>>B;
    std::cout << "100 100" <<'\n';
    REP(i,50){
        std::fill(S[i],S[i]+100,'#');
        std::fill(S[i+50],S[i+50]+100,'.');
    }
    A--,B--;
    REP(i,50){
        if(i%2)continue;
        REP(j,100){
            if(j%2)continue;
            if(A>0){
                S[i][j]='.';
                A--;
            }
            if(B>0){
                S[i+51][j]='#';
                B--;
            }
        }
    }
    REP(i,100){
        REP(j,100){
            cout<<S[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


signed main(){
  int n, d;
  cin >> n >> d;
  // vector<int> x(n), y(n);
  int ans = 0;
  rep(i, 0, n) {
    long double x, y;
    cin >> x >> y;
    long double r = sqrt(x * x + y * y);
    if(r <= d){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=__gcd(a[0],a[1]);
    for(int i=1;i<n;i++){
        ans=__gcd(ans,a[i]);
    }
    cout<<ans<<endl;
   return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int a,b,c;
    bool flag = false;
    cin >> a >> b >> c;
    if(a == b){
        if(a != c){
            flag = true;
        }
    }else if(a == c){
        if(a != b){
            flag = true;
        }
    }else if(b == c){
        if(a != b){
            flag = true;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

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

using namespace std;

int main()
{
	int a, b;

	scanf("%d %d", &a, &b);

	if (b % 2 || b<a * 2 || b>a * 4)
	{
		printf("No\n");
	}

	else
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vector<long long> a(3030, 0);
long long dp[3030][3030];

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a.at(i);

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

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

            if((n-len) % 2 == 0) {
                dp[i][j] = max(dp[i+1][j]+a.at(i), dp[i][j-1]+a.at(j-1));
            }else {
                dp[i][j] = min(dp[i+1][j]-a.at(i), dp[i][j-1]-a.at(j-1));
            }
        }
    }

    cout << dp[0][n] << endl;
}

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

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

#define int long long
#define endl '\n'
#define x first
#define y second
const int N = 1001;

vector<pair<int,int> > vp[2][2];
int n;
pair<int,int> po[N];
int ds(int x, int y){
	return x*x + y*y;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0 ; i < n ; i ++){
		cin >> po[i].x >> po[i].y;
		vp[po[i].x <= 0][po[i].y <= 0].push_back(po[i]);
	}
	pair<int,int> rec = {0, 0};
	for(int i = 0 ; i < 2 ; i ++)
		for(int j = 0 ; j < 2 ; j ++){
			int _x = 0, _y = 0;
			for(pair<int,int> px: vp[i][j])
				_x += px.x, _y += px.y;
			if(ds(_x, _y) > ds(rec.x, rec.y)) rec = {_x, _y};
		}
	srand(time(NULL));
	int test = 1000;
	while(test --){
		random_shuffle(po, po + n);
		int _x = 0, _y = 0;
		for(int i = 0 ; i < n ; i ++)
			if(ds(_x + po[i].x, _y + po[i].y) > ds(_x, _y))
				_x += po[i].x, _y += po[i].y;
		if(ds(_x, _y) > ds(rec.x, rec.y)) rec = {_x, _y};
	}
	cout << setprecision(14) << sqrt(rec.x*rec.x + rec.y*rec.y) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<bool> color(8);
	rep(i,8) color[i]=false;
	rep(i,n) cin >> a[i];
	int cnt=0;
	rep(i,n){
		int b = a[i];
		if(b>=1&&b<=399) color[0]=true;
		if(b>=400&&b<=799) color[1]=true;
		if(b>=800&&b<=1199) color[2]=true;
		if(b>=1200&&b<=1599) color[3]=true;
		if(b>=1600&&b<=1999) color[4]=true;
		if(b>=2000&&b<=2399) color[5]=true;
		if(b>=2400&&b<=2799) color[6]=true;
		if(b>=2800&&b<=3199) color[7]=true;
		if(b>=3200) cnt++;
	}
	int ans=0;
	rep(i,8){
		if(color[i]==1) ans++;
	}
	int ans2;
	ans2 = ans+cnt;
	if(ans==0){
		ans=1;
	}
	cout << ans << ' ' << ans2 << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:sorted(list(map(int,stdin.readline().split())))
from bisect import bisect_left, bisect_right

n=int(input())
a=lnii()
b=lnii()
c=lnii()

ans=0
for i in range(n):
  m=b[i]
  num1=bisect_left(a,m)
  num2=n-bisect_right(c,m)
  ans+=num1*num2

print(ans)

Measured memory_bytes: 29208
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(int a,int b)
{	
	return a>b;
}
void printQ(vector<int> q)
{   
    cout<<"v->  ";
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}

int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<n;i++)
    {
    	if(i+2<n && s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    	{
    		i+=2;
    		ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long 
ll dp[2][100001];
int main()
{
    ll n,k;
    cin>>n>>k;
    ll arr[n+1];
    for(int i=1;i<=n;++i)cin>>arr[i];
    ll prev[k+1];
    dp[0][0]=1;
    dp[1][0]=0;
    for(int i=1,j=1;i<=k;++i)
    {
        dp[0][i]=1;
        dp[1][i]=0;
        for(int j=1;j<=n;++j)
        {
            if(i-arr[j]>=0)
            {
                if(dp[1][i-arr[j]] == 0)
                {
                    //cout<<"OK";
                    dp[0][i] = 0;
                    j=n+1;
                }
                
            }
            else break;
        }

        for(int j=1;j<=n;++j)
        {
            if(i-arr[j]>=0)
            {
                if(dp[0][i-arr[j]] == 1)
                {
                    dp[1][i] = 1;
                    j=n+1;
                }
                
            }
            else break;
        }
    }
  
    

    
    string ans =(dp[0][k]==0)?"First":"Second";
    cout<<ans;

}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
	static boolean bElapsed = false;
	List<String> list = new ArrayList<>();
	Set<String> set = new HashSet<>();
	Map<String,String> map = new HashMap<>();

	void solve(BufferedReader br) throws Exception {
		String line = br.readLine();
		int n = Integer.parseInt(line);
		line = br.readLine();
		int k = Integer.parseInt(line);
		line = br.readLine();
		int x = Integer.parseInt(line);
		line = br.readLine();
		int y = Integer.parseInt(line);
		long sum = 0;
		if (n > k) {
			sum += k*x;
			sum += (n-k)*y;
		} else {
			sum += n*x;
		}
		pln(sum);
	}

	void p(char c) {
		System.out.print(c);
	}
	void pln(char c) {
		System.out.println(c);
	}
	void p(long l) {
		System.out.print(l);
	}
	void pln(long l) {
		System.out.println(l);
	}
	void p(String s) {
		System.out.print(s);
	}
	void pln(String s) {
		System.out.println(s);
	}
	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		new Main().solve(br);
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.out.println((end-start) + "ms");
		}
	}
}


Measured memory_bytes: 8276
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char s[] = sc.next().toCharArray();
		int cnt = 0;
		char start = s[0];
		for (int i = 1; i < s.length; i++) {
			if (s[i] != start) {
				cnt++;
				start = s[i];
			}
		}
		System.out.println(cnt);
	}
}


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

int main() {
  ll n,m;
  cin>>n>>m;
  vector<ll> a(n+1);
  vector<ll> b(n+1);

  rep(i,n)cin>>a[i];
  b[0]=0;
  map<ll,ll> mp;

  rep(i,n){
    b[i+1]=(b[i]+a[i])%m;
    mp[b[i+1]]++;
  }
  ll cnt=0;
  for( auto i = mp.begin(); i != mp.end() ; ++i ) {
      ll m1=i->first;
      ll m2=i->second;
      if (m1==0)cnt+=m2;
      cnt+=(m2*(m2-1))/2;
   }
   cout<<cnt;

}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
ll P(ll x, ll y)
{
	if (y % 2)
		return x * P(x, y - 1) % mod;
	if (y)
		return P(x * x % mod, y / 2);
	return 1;
}
ll M(ll x, ll y)
{
	return x * y % mod;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll x, y;
	cin >> x >> y;
	if ((x + y) % 3)
	{
		cout << 0;
		return 0;
	}
	int z = (x + y) / 3;
    if (x < z || y < z || x > z * 2 || y > z * 2)
	{
		cout << 0;
		return 0;
	}
	int a = x - z;
	vector <int> c(a), d(a);
	iota(c.begin(), c.end(), z - a + 1);
	iota(d.begin(), d.end(), 1);
	cout << accumulate(c.begin(), c.end(), 1, M) * P(accumulate(d.begin(), d.end(), 1, M), mod - 2) % mod;
}

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

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    int m = (S - h * 3600) / 60;
    int s = S - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
}


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

int main()
{
    int r;
    cin >> r;
    cout << 2*r * 3.141592 << endl;
    return 0;
}

Measured memory_bytes: 3784
package main

import (
	"fmt"
)

func main() {
	var s, t string
	var a, b int
	fmt.Scan(&s, &t, &a, &b)
	m := make(map[string]int, 2)
	m[s], m[t] = a, b

	var u string
	fmt.Scan(&u)
	m[u] -= 1

	fmt.Println(m[s], m[t])
}


Measured memory_bytes: 512
S = input()
n = len(S)
res = 0
for i in range(1 << (n-1)):
	l = []
	for j in range(n-1):
		if (i >> j) & 1:
			l.append(j+1)	
	l.insert(0,0)
	l.append(n)	
	for i in range(len(l)-1):
		res += int(S[l[i]:l[i+1]])
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

vector<int> A[20];
vector<int> C;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x; cin>>n>>m>>x;
    rep(i,n){
        int c; cin>>c;
        C.push_back(c);
        rep(j, m){
            int a; cin>>a;
            A[i].push_back(a);
        }
    }
    ll ans = 1LL<<60;
    for(int bit=0; bit<(1<<n); bit++){
        int now_power[20] = {0};
        ll t_sum = 0;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                for(int j=0; j<m; j++){
                    now_power[j] += A[i][j];
                }
                t_sum += C[i];
            }
        }
        bool isok = true;
        for(int j=0; j<m; j++){
            if(now_power[j]<x) isok = false;
        }
        if(isok){
            // 金額
            ans = min(t_sum, ans);
        }
    }
    if(ans == (1LL<<60)) ans = -1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3660
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn check(s: &Vec<(isize, isize)>) -> bool {
    let mut h = 0;
    for p in s.iter() {
        let b = h + p.0;
        if b < 0 {
            return false;
        }
        h += p.1;
    }
    true
}

fn main() {
    let mut io = IO::new(stdin(), stdout(), stderr());
    // ===================================== //
    let n: usize = io.read();
    let mut ls: Vec<(isize, isize)> = Vec::new();
    let mut rs: Vec<(isize, isize)> = Vec::new();
    let mut total = 0;
    for i in 0..n {
        let mut s = io.chars();
        let mut h: isize = 0;
        let mut b: isize = 0;
        for &c in s.iter() {
            if c == '(' {
                h += 1;
            } else {
                h -= 1;
            }
            b = min(b, h);
        }
        if h > 0 {
            ls.push((b, h));
        } else {
            rs.push((b - h, -h));
        }
        total += h;
    }
    ls.sort_by(|a, b| b.cmp(a));
    rs.sort_by(|a, b| b.cmp(a));
    if check(&ls) && check(&rs) && total == 0 {
        io.writeln("Yes");
    } else {
        io.writeln("No");
    }
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
}


Measured memory_bytes: 18056
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////
 
#define fs first
#define sc second
#define pb push_back
//#define int long long
#define len(x) (int)(x).size()     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;
 
inline ll gcd(ll a, ll b){while(b){ a %= b; swap(a, b); } return a; }
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

int32_t main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n+1, 0);
  for(int i = 1; i <= n; i++){
    cin >> v[i];
  }
  vector<vector<int>> dp(n+5, vector<int>(k+5, 0));
  for(int i = n; i >= 1; i--){
    for(int j = k; j >= 0; j--){
      if(i == n){
        if(j <= v[i]) dp[i][j] = 1;
      }
      dp[i][j] = mod(dp[i][j] + (dp[i+1][j-min(j, v[i])] - dp[i+1][j+1]), MOD);
      dp[i][j] = mod(dp[i][j] + dp[i][j+1], MOD);
    }
  }
  cout << dp[1][k]%MOD << endl;
  return 0; 
}

Measured memory_bytes: 44876
n = int(input())
a = [int(i) for i in input().split()]
a.insert(0, 0)
a.append(0)

gap = []
for i in range(n + 1):
  gap.append(a[i + 1] - a[i])

base = sum([abs(i) for i in gap])

for j in range(n):
  answer = base - (abs(gap[j]) + abs(gap[j + 1])) + abs(gap[j] + gap[j + 1])
  print(answer)


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

int euklid(int, int);

int main(void)
{
	int N;
	cin >> N;
	vector<int> A(N), M(N);
	vector<int> L(N, 0), R(N+1, 0);
	for (int i = 0; i < N; i++)cin >> A[i];
	//cout << euklid(0, A[1]) << endl;
	for (int i = 0; i < N-1; i++) {
		L[i + 1] = euklid(L[i], A[i]);
		R[N - i - 1] = euklid(R[N - i], A[N - i - 1]);
		//cout << L[i + 1] << " " << R[N - i - 1] << endl;
 	}
	for (int i = 0; i < N; i++)M[i] = euklid(L[i], R[i + 1]);
	sort(M.begin(), M.end());
	cout << M[N-1] << endl;

	return 0;
}

int euklid(int x, int y)
{
	int a, b, re;
	if (x == 0 || y == 0)b = x + y;
	else {
		if (x > y) {
			a = x;
			b = y;
			re = a % b;
		}
		else {
			a = y;
			b = x;
			re = a % b;
		}
		while (re > 0) {
			a = b;
			b = re;
			re = a % b;
		}
	}
	return b;
}

Measured memory_bytes: 1792
#include <iostream>
#include <map>
#

using namespace std;
map <int, double> m,mv;
int n,i;
double p,ans;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>p;
        m.clear();
        if(i==1)
        {
            m[1]=p;
            m[-1]=1-p;
        }
        else
        {
            for(auto it : mv)
            {
                m[it.first+1]+=it.second*p;
                m[it.first-1]+=it.second*(1-p);
            }
        }
        mv=m;
    }
    for(auto it : m)
    {
        if(it.first>0)
            ans+=it.second;
    }
    cout.precision(10);
    cout << fixed <<ans;
    return 0;
}


Measured memory_bytes: 640
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast int fvariable = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
vector<ll>ans2(ms);
vector<vector<ll>>vc;
ll n,m,x;
bool chk()
{
    for(int i=1;i<=m;i++)
    {    if(ans2[i]<x)
            return 0;}
    return 1;
}
void fun(int i,ll cost)
{
   // cout<<i<<" "<<cost<<endl;
    if(chk())
        {ans=min(ans,cost);return;}
    if(i==n)
        return;
    fun(i+1,cost);
    for(int j=1;j<=m;j++)
    {    ans2[j]+=vc[i][j];}
    fun(i+1,cost+vc[i][0]);
    for(int j=1;j<=m;j++)
    {    ans2[j]-=vc[i][j];}
    return;
}
void solve()
{
    cin>>n>>m>>x;
    ans=maxval;
    //cout<<n<<m<<x<<endl;
    for(int i=0;i<n;i++)
    {
        vector<ll>vcc(m+1);
        for(int j=0;j<=m;j++)
            cin>>vcc[j];
        vc.pb(vcc);
    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<=m;j++)
            cout<<vc[i][j]<<" ";
        cout<<endl;
    }*/
    fun(0,0);
    if(ans==maxval)
        cout<<-1<<endl;
    else    
        cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int main(){


  while(1){
    int x,h;
    double s,a,b;
    
    scanf("%d %d",&x,&h);
    if(x==0 && h==0) break;

    s=x*x;
    a=x/2.;
    b=sqrt(a*a+h*h);
    
    s+=x*b*2;

    printf("%f\n",s);
  }

  return 0;
}

Measured memory_bytes: 1216
r, c = map(int, input().split())
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    l = list(map(int, input().split()))
    for j in range(c):
        a[i][j] = l[j]
        a[i][c] += a[i][j]

for i in range(c+1):
    for j in range(r):
        a[r][i] += a[j][i]

for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(str(a[i][j]))
        else:
            print(str(a[i][j]) + " ", end="")

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

typedef long long ll;

ll x[200005];

int main()
{
ll n,k;
cin>>n>>k;

for(ll i=0;i<n;i++)
{
    cin>>x[i];
}
sort(x,x+n);
reverse(x,x+n);

ll ans=0;
for(ll i=k;i<n;i++)
{
    ans+=x[i];
}
cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb emplace_back
#define pi pair<int,int>
using namespace std;
const int maxn = 3e3 + 4;

string s, t;
int dp[maxn][maxn];

int main(){
	cin>>s>>t;
	int les = s.size();
	int let = t.size();
	for (int i = 1; i <= les; ++i){
		for (int j = 1; j <= let; ++j){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if (s[i-1] == t[j-1]){
				dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
			}
		}
	}
	int cnt = dp[les][let];
	string res(cnt, 'a');
	int i = les, j = let;
	while (i > 0 && j > 0){
		if (s[i-1] == t[j-1]){
			res[--cnt] = s[i-1];
			--i, --j;
		}
		else{
			if (dp[i-1][j] == dp[i][j])
				--i;
			else
				--j;
		}
	}
	cout<<res<<'\n';
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n+1);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) > vec.at(i+1)) {
      sum++;
    }
    else if (vec.at(i) = vec.at(i+1)) {
      continue;
    }
    else {
      break;
    }
  
  }
  cout << sum << endl;

}

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

int main() {
    int n;
    int mx=0, sum=0;
    cin >> n;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a; 
        sum+=a;
        mx=max(mx,a);
    }
    if ( mx<sum-mx ) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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

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

long long int dp[51][51] = {};

int main(void) {
	string s, t;
	bool flag = true;
	vector<int> first(26, 0), second(26, 0);

	cin >> s >> t;

	FOR(i, 0, s.size() - 1) {
		first[s[i] - 'a']++;
	}

	FOR(i, 0, t.size() - 1) {
		second[t[i] - 'a']++;
	}

	sort(first.begin(), first.end());
	sort(second.begin(), second.end());

	FOR(i, 0, 25) {
		if (first[i] != second[i]) {
			flag = false;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 776
N = int(input())
csum = list(0 for _ in range(2000+1))
L = []
for l in map(int,input().split()):
    L.append(l)
    csum[l] += 1
for i in range(1,len(csum)): csum[i] += csum[i-1]
ans = 0
for ib in range(N):
    b = L[ib]
    for ia in range(ib):
        a = L[ia]
        minL, maxL = abs(a-b), a+b
        ans += csum[maxL-1] - csum[minL]
        if minL < a < maxL: ans -= 1
        if minL < b < maxL: ans -= 1
print(ans//3)

Measured memory_bytes: 3188