akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var whn = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[][] rect = Enumerable.Repeat(0, whn[1]).Select(_ => new bool[whn[0]]).ToArray();

        for (int query = 0; query < whn[2]; query++)
        {
            var xya = Console.ReadLine().Split().Select(int.Parse).ToArray();
            switch (xya[2])
            {
                case 1:
                    for (int y = 0; y < whn[1]; y++)
                        for (int x = 0; x < xya[0]; x++)
                            rect[y][x] |= true;                        
                    break;
                case 2:
                    for (int y = 0; y < whn[1]; y++)
                        for (int x = xya[0]; x < whn[0]; x++)
                            rect[y][x] |= true;
                    break;
                case 3:
                    for (int y = 0; y < xya[1]; y++)
                        for (int x = 0; x < whn[0]; x++)
                            rect[y][x] |= true;
                    break;
                case 4:
                    for (int y = xya[1]; y < whn[1]; y++)
                        for (int x = 0; x < whn[0]; x++)
                            rect[y][x] |= true;
                    break;
            }
        }
        Console.WriteLine(rect.Sum(x => x.Count(y => !y)));
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> s(10, vector<int>(0));
vector<int> p(10), k(10);

int dfs(int co, vector<bool> da) {
	int ans=0;
	if (co < n) {
		da[co] = true;
		ans += dfs(co + 1, da);
		da[co] = false;
		ans += dfs(co + 1, da);
	}
	else {
		bool ju = true;
		for (int i = 0;i < m;i++) {
			int ch = 0;
			for (int j = 0;j < k[i];j++) {
				if (da[s[i][j]-1])
					ch++;
			}
			if (ch % 2 != p[i])
				ju = false;
		}
		if (ju)
			ans++;
	}
	return ans;
}

int main() {
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		cin >> k[i];
		for (int j = 0;j < k[i];j++) {
			int x;
			cin >> x;
			s[i].push_back(x);
		}
	}
	for (int i = 0;i < m;i++) {
		cin >> p[i];
	}
	vector<bool> da(n);
	int ans=dfs(0, da);
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 1
if len(a) > 2:
  if a[0] < a[1]: tr = 1
  elif a[0] > a[1]: tr = -1
  else: tr = 0
  ans = 1
  for i in range(2, n):
    if tr == 1 and a[i-1] > a[i]:
      ans += 1
      tr = 0
    elif tr == -1 and a[i-1] < a[i]:
      ans += 1
      tr = 0
    else:
      if a[i-1] > a[i]: tr = -1
      elif a[i-1] < a[i]: tr = 1
print(ans)

Measured memory_bytes: 14436
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    int n;
    cin>> n;
    vec arr(n);
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    vec cav(n);
    for (int i = 0; i < n; i++){
        cav[arr[i] - 1] = i+1;
    }
    for (int i = 0; i < n; i++){
       cts(cav[i]);
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    cout << (a * min(b - 1, n)) / b << endl;
}


Measured memory_bytes: 3624
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner scanner = new Scanner(System.in);
	    String n = scanner.next();
	    
	    int sum = 0;
	    int i = n.length() - 1;
	    while(i >=0){
	    	int num = n.charAt(i) - '0';
	    	sum = (sum + num) % 9;
	    	i--;
	    }
	    
	    if(sum == 0)
	      System.out.println("Yes");
		
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 39768
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()

switch = []
for _ in range(m):
    s = list(li_())
    switch.append(s[1:])

p = list(li())

ans = 0
ok = True

for bit in range(1<<n):
    ok = True
    for i, swi in enumerate(switch):
        flag = 0
        for swij in swi:
            if bit & (1<<swij):
                flag += 1

        if flag % 2 != p[i]:
            ok = False

    if ok:
        ans += 1

print(ans)


Measured memory_bytes: 3064
N = int(input())
h = list(map(int,input().split()))

ans = 0
for i in range(1,max(h)+1):
  ls = [0]*N
  flag = 0
  
  for n in range(N):
    if h[n] >= i:
      ls[n] = 1
  
  for n in range(N):
    if ls[n] ==1:
      if flag == 0:
        ans += 1
        flag = 1
    else:
      flag = 0
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int dp[50][500][500];

int main(){
    rep(i,50)rep(j,500)rep(k,500) dp[i][j][k] = INF;

    int n,ma,mb;
    scanf("%d %d %d",&n,&ma,&mb);
    vector<int> a(n),b(n),c(n);
    rep(i,n) scanf("%d %d %d",&a[i],&b[i],&c[i]);

    dp[0][0][0] = 0;
    for(int i=0;i<n;i++){
        rep(j,500)rep(k,500){
            if(j+a[i]<500&&k+b[i]<500) dp[i+1][j+a[i]][k+b[i]] = dp[i][j][k] + c[i];
            dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);  
        }
    }
    int ans = INF;

    rep(j,500)rep(k,500){
        if(j==0&&k==0) continue;
        if(k*ma==j*mb) ans = min(ans,dp[n][j][k]);
    }

    printf("%d\n",(ans==INF)?-1:ans);

    return 0;
}

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

int main() {
    std::string s{};
    std::cin >> s;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == s[i + 1]) {
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }
    std::cout << "Good" << std::endl;
    return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = sorted(list(map(int, input().split())))
print (sum(sorted(p+q+r)[-X-Y:]))


Measured memory_bytes: 22616
n, m, q = map(int, input().split())
d = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    for i in range(l + 1):
        d[i][r] += 1
for i in range(n):
    for j in range(1, n):
        d[i][j] += d[i][j-1]
for _ in range(q):
    p, q = map(int, input().split())
    print(d[p-1][q-1])

Measured memory_bytes: 78132
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>

using namespace std;

int main()
{
	int x, y;
	while (true) {
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;
		else if(x>y)
			cout << y << " " << x;
		else
			cout << x << " " << y;
		cout << endl;
	}
		return 0;
}

Measured memory_bytes: 1160
//ABC070C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long int> t(n);
	for(int i=0;i<n;i++){
		cin >> t.at(i);
	}
	long long int g = t.at(0);
	long long int ans = t.at(0);
	for(int i=1;i<n;i++){
		g = __gcd(ans,t.at(i));
		ans /= g;
		ans *= t.at(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var result = s[0] == s[1] || s[1] == s[2] || s[2] == s[3];
            Console.WriteLine(result ? "Bad" : "Good");
        }
    }
}


Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main()
{
   int h, w;
   cin >> h >> w;
   vector<string> s(h);
   rep(i,h) cin >> s[i];
   queue<P> que;
   vector<vector<int>> memo(h, vector<int>(w,INF));
   que.push(P(0,0));
   memo[0][0] = 0;
   int sum = -1;
   while(!que.empty())
   {
      P p = que.front(); que.pop();
      int nx, ny;
      rep(i,4){
         nx = p.second + dx[i];
         ny = p.first + dy[i];
         if(nx < 0 || ny < 0 || nx >= w || ny >= h ) continue;
        // cout << nx << " " << ny << endl;
         if(s[ny][nx] == '#') continue;
         if(memo[ny][nx] != INF) continue;
         memo[ny][nx] = memo[p.first][p.second] + 1;
         que.push(P(ny,nx));
         if(ny == h-1 && nx == w-1) 
         {
            sum = memo[ny][nx];
            break;
         }
      }
   }
   if(sum == -1)
   {
      cout << -1 << endl;
      return 0;
   }
   int black =0;
   rep(i,h)rep(j,w) if(s[i][j] == '#') ++black;
   int ans = h*w - black -sum -1;
   cout << ans << endl;

}

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

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

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    vector<string> days { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    auto i = find(days.begin(), days.end(), s) - days.begin();

    cout << 8 - i << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
	int m;
	cin>>m;
		float a[m];
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	sort(a,a+m);
	for(int i=1;i<m;i++){
		a[i]=a[i-1]+a[i];
		a[i]/=2;
	}
	cout<<a[m-1];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  int n;
  cin >> n;
  ll ans=0;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  ans = a[0] ^ a[1];
  for(int i=2;i<n;i++){
    ans = (ans ^ a[i]);
    //cout << ans << "\n";
  }
  if(ans == 0)cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll num;
  ll a,b;
  cin>>num;
  if(num==1) cout<<"Hello World"<<endl;
  else{
  	cin>>a;
    cin>>b;
    cout<<a+b<<endl;
  }
}


Measured memory_bytes: 256
using System;

namespace CSsample
{
    class Program
    {
        static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int C = int.Parse(Console.ReadLine());
            int D = int.Parse(Console.ReadLine());
            int E = int.Parse(Console.ReadLine());
            int ap = A % 10;
            if (ap == 0)
            {
                ap = 10;
            }
            int bp = B % 10;
            if (bp == 0)
            {
                bp = 10;
            }
            int cp = C % 10;
            if (cp == 0)
            {
                cp = 10;
            }
            int dp = D % 10;
            if (dp == 0)
            {
                dp = 10;
            }
            int ep = E % 10;
            if (ep == 0)
            {
                ep = 10;
            }
            int sum = A - ap + B - bp + C - cp + D - dp + E - ep + 40 + Math.Min(ap, Math.Min(bp, Math.Min(cp, Math.Min(dp, ep))));
            Console.WriteLine(sum);
        }
    }
}



Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));
    int ans = 0;
    REP(i,k) ans += a[i];
    cout << ans << endl;

    return 0;
}


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


signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<int> ans(n,1ll);

    vector<int> a(n);

    vector<vector<int>> x(n,vector<int>(14)),y(n,vector<int>(14));

    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
        for(int j = 0;j < a.at(i);j ++){
            cin >> x.at(i).at(j) >> y.at(i).at(j);
        }
    }

    int s,t;
    for(;;){
        s = 1;
        for(int i = 0;i < n;i ++){
            for(int j = 0;j < a.at(i);j ++){
                if(ans.at(i) == 1){
                    if(ans.at(x.at(i).at(j)-1) != y.at(i).at(j)){
                        s = 0;
                        break;
                    }
                }
            }
        }
        if(s == 1) break;

        ans.at(n-1) --;

        for(int i = n-1;i > 0;i --){
            if(ans.at(i) < 0){
                ans.at(i-1) --;
                ans.at(i) = 1;
            }
        }
    }

    int b = 0;
    for(int i = 0;i < n;i ++){
        b += ans.at(i);
    }

    cout << b << endl;
}



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

int main(){
    int a,b,c,q=0;
    cin>>a>>b>>c;
    for(int i=1;i<=c;i++){
        if(c%i==0){
            if(a<=i&&i<=b){
                q++;
            }
        }
    }
    cout<<q<<endl;
}


Measured memory_bytes: 3104
h, w = map(int, input().split())
s = []
d = [[-1,-1], [-1,0], [-1,1], [0,-1], [0,1], [1,-1], [1,0], [1,1]]

for i in range(h):
    a = []
    y = input()
    for j in y:
        a.append(j)
    s.append(a)

for y in range(h):
    for x in range(w):
        c = 0
        if s[y][x] == "#": continue

        for u in d:
            if x + u[0] < 0 or x + u[0] > w-1 or y + u[1] < 0 or y + u[1] > h -1: continue
            if s[y + u[1]][x + u[0]] == "#": c += 1

        s[y][x] = c

for i in s:
    print("".join(list(map(str,i))))

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

int N, M;
vector<int> P;
vector<int> X, Y;
vector<int> par;
vector<int> t_rank;

void init_union_find(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		t_rank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == 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 (t_rank[x] < t_rank[y])
		par[x] = y;
	else {
		par[y] = x;
		if (t_rank[x] == t_rank[y])
			t_rank[x]++;
	}
}

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

void input_data(void) {
	cin >> N >> M;
	P.resize(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> P[i];
	X.resize(M);
	Y.resize(M);
	for (int i = 0; i < M; ++i)
		cin >> X[i] >> Y[i];
}

void init_data(void) {
	par.resize(N + 1);
	t_rank.resize(N + 1);
	init_union_find(N + 1);
}

void make_union_find(void) {
	for (int i = 0; i < M; ++i) {
		if (!same(X[i], Y[i]))
			unite(X[i], Y[i]);
	}
}

int solve(void) {
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		if (same(P[i], i))
			++cnt;
	}
	return cnt;
}

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

	input_data();
	init_data();
	make_union_find();
	int ans = solve();

	cout << ans << '\n';
	return 0;
}


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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  const int mod = 1e9 + 7;
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<int>> dp(H + 1, vector<int>(W, 0));
  dp[0][0] = 1;
  REP(i, H) {
    REP(k, 1 << (W - 1)) {
      bool ok = true;
      REP(j, W - 2) {
        if(((k >> j) & 1) && ((k >> (j + 1)) & 1)) {
          ok = false;
          break;
        }
      }
      if(ok) {
        REP(j, W) {
          if(j >= 1 && (k >> (j - 1)) & 1) {
            dp[i + 1][j - 1] += dp[i][j];
            dp[i + 1][j - 1] %= mod;
          } else if(j <= W - 2 && (k >> j) & 1) {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + 1] %= mod;
          } else {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= mod;
          }
        }
      }
    }
  }
  cout << dp[H][K -1] << endl;
  return 0;
}


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

int main(){
    long N;
    string S;
    long ans = 0;
    char previous = '#';
    cin >> N >> S;

    for(long i=0;i<N;i++){
        if(S[i] != previous){
            ans++;
        }
        previous = S[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#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;

//template<typename T>
#define o_set(T) tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//use it like o_set(ll) x;  --> x.order.....
//-->for pair<ll,ll> : second element as index and for search use INT_MAX...
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


#define fast ios::sync_with_stdio(false);cin.tie(0);cout<<setprecision(25)
#define pb push_back
#define I insert
#define F first
#define S second
#define digit(x) floor(log10(x))+1
const long long M1=1000000007;
const long long  M2=998244353;
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
template<typename T>
void showArr(T a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
bool isValid(ll x,ll y,ll n,ll m){
    return (x>=0 and y>=0 and x<n and y<m);
}
ll power(ll a,ll n,ll m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans%m * a%m)%m;
        }
        n=n>>1;
        a=(a%m*a%m)%m;
    }
    return ans;
}
ll MMI(ll a,ll m){
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1){
        ll q=a/m,t=m;
        m=a%m,a=t,t=y,y=x-q*y,x=t;
    }
    if(x<0) x+=m0;
    return x;
}

ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    fast;
    ll n;
    cin>>n;
    ll ans=0,m=INT_MIN;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m=max(m,x);
        ans+=(m-x);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d,cnt=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
from itertools import permutations, combinations, combinations_with_replacement
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M, Q = map(int, readline().split())
abcd = [list(map(int, readline().split())) for _ in range(Q)]
l = [i for i in range(1, M + 1)]

ans = 0
for v in combinations_with_replacement(l, N):
    acc = 0
    for a, b, c, d in abcd:
        if v[b - 1] - v[a - 1] == c:
            acc += d
    ans = max(ans, acc)

print(ans)


Measured memory_bytes: 9264
def gcd(x,y):
    if x == 0:return y
    return gcd(y % x, x)

n = int(input())
a = list(map(int, input().split()))

lgcd = [0]
rgcd = [0]
for i in a:
    lgcd.append(gcd(lgcd[-1], i))

for i in a[::-1]:
    rgcd.append(gcd(rgcd[-1], i))

rgcd = rgcd[::-1]

ans = 1 << 60
print(max([gcd(lgcd[i],rgcd[i+1]) for i in range(n)]))
    

Measured memory_bytes: 14584
def A(x):
  return x + x**2 + x**3


def B(n, k, p_list):
  pass


def C(N):
  pass


def main():
  print(A(int(input())))
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)


if __name__ == '__main__':
  main()


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

using namespace std;
typedef long long LL;

const int MAXN = 3005;

LL dp[MAXN][MAXN][4];
LL mp[MAXN][MAXN];
int main()
{
    int R, C, K;
    scanf("%d %d %d", &R, &C, &K);
    for (int i = 0; i <= R; i++)
    {
        for (int j = 0; j <= C; j++)
        {
            dp[i][j][0] = dp[i][j][1] = dp[i][j][2] = dp[i][j][3] = 0;
            mp[i][j] = 0;
        }
    }
    for (int i = 1; i <= K; i++)
    {
        int r, c, v;
        scanf("%d %d %d", &r, &c, &v);
        mp[r][c] = v;
    }
    for (int i = 1; i <= C; i++)
    {
        dp[1][i][0] = 0;
        dp[1][i][1] = max(mp[1][i], dp[1][i - 1][1]);
        dp[1][i][2] = max(mp[1][i] + dp[1][i - 1][1], dp[1][i - 1][2]);
        dp[1][i][3] = max(mp[1][i] + dp[1][i - 1][2], dp[1][i - 1][3]);
    }
    for (int i = 1; i <= R; i++)
    {
        // dp[i][1][0] = 0;
        // dp[i][1][1] = max(mp[i][1], dp[i - 1][1][1]);
        // dp[i][1][2] = max(mp[i][1] + dp[i][1][1], dp[i - 1][1][2]);
        // dp[i][1][3] = max(mp[i][1] + dp[i - 1][1][2], dp[i - 1][1][3]);
        dp[i][1][0] = max(dp[i - 1][1][0], dp[i - 1][1][1]);
        dp[i][1][1] = mp[i][1] + max(dp[i - 1][1][0], dp[i - 1][1][1]);
    }
    for (int i = 2; i <= R; i++)
    {
        for (int j = 2; j <= C; j++)
        {
            dp[i][j][0] = max(dp[i - 1][j][3], max(dp[i - 1][j][1], dp[i - 1][j][2]));
            dp[i][j][1] = max(max(dp[i - 1][j][3], max(dp[i - 1][j][1], dp[i - 1][j][2])) + mp[i][j], max(dp[i][j - 1][1], dp[i][j - 1][0] + mp[i][j]));
            dp[i][j][2] = max(dp[i][j - 1][1] + mp[i][j], dp[i][j - 1][2]);
            dp[i][j][3] = max(dp[i][j - 1][2] + mp[i][j], dp[i][j - 1][3]);
        }
    }
    // cout << "dp1 2 2   =   " << dp[1][2][2] << "\n";
    // cout << "mp22 = " << mp[2][2] << "\n"; 
    printf("%lld\n", max(dp[R][C][1], max(dp[R][C][2], dp[R][C][3])));
    // int T;
    // cin >> T;
}

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

int main(){
  bool prime[50000];
  prime[0]=prime[1]=false;
  for(int i=2;i<50000;i++){
    prime[i]=true;
  }

  for(int i=2;i*i<50000;i++){
    if(prime[i]){
      for(int j=i*i;j<50000; j+=i){
        prime[j]=false;
      }
    }
  }

  while(true){
    int min,a,cnt;
    cin >> a;

    if(a==0)
      break;
    cnt=0;
    for(int i=2;i<=a/2;i++){
      if(prime[i]&&prime[a-i]){
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if(a <= b){
        for (int i = 0; i < b; i++)
        {
            cout << a;
        }
    }
    else{
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
    }

    cout << endl;
}

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

int main(){
  unsigned long long a;
  double b;
  cin >> a >> b;
  int f = b * 100 +0.5;
  unsigned long long ans = a * f;
  int h = ans % 100;
  ans = ans - h;
  cout << ans/100 << endl;
}


Measured memory_bytes: 3724
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
	int n, q;
	cin >> n >> q;

	string a;
	cin >> a;
	
	int ac =0;
	vector<int> num;
	num.push_back(0);
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == 'A' && a[i + 1] == 'C') {
			ac++;
			
		}
	num.push_back(ac);
	}
	
	vector<int> ans;
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		ans.push_back(num[r - 1] - num[l - 1]);
	}

	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
	
	return 0;

}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a!=b&&a!=c)
    cout << a << endl;
  if(b!=a&&b!=c)
    cout << b << endl;
  if(c!=b&&c!=a)
    cout << c << endl;
}

Measured memory_bytes: 3608
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main(){
	int n, k;
	cin >> n >> k;
	vi x(n);
	vi vp, vn;

	rep(i,n) {
		cin >> x[i];
		if(x[i] >= 0) vp.pb(x[i]);
		else vn.pb(-x[i]);
	}
	reverse(all(vn));

	int ps = vp.size();
	int ns = vn.size();
	int c = min(ps, ns);

	// cout << "c = " << c << endl;
  
	if(ps > ns) {
		vi t = vn;
		vn = vp;
		vp = t;
	}

	ll ans = LLONG_MAX;
	if(k<=n-c) ans = vn[k-1];
	// cout << "-1: " << ans << endl;

	rep(i,c) {
		if(i>=0 && i<vp.size() && k-2-i>=0 && k-2-i<vn.size()){
			ll temp = vp[i] + vn[k-2-i] + min(vp[i], vn[k-2-i]);
			// cout << i << ": " << temp << endl;
			ans = min(ans, temp);
		}
	}
  
	cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <cstdio>
#define maxn 100005
using namespace std;
int cnt,head[maxn],vis[maxn],ans,n,m;
struct fdfdfd{int next,to;}e[maxn<<1];
void addedge(int x,int y){e[++cnt].to=y; e[cnt].next=head[x]; head[x]=cnt;}
void dfs(int u)
{
	vis[u]=1;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;
		if(!vis[v]) dfs(v);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,u,v,w;i<=m;++i) scanf("%d%d%d",&u,&v,&w),addedge(u,v),addedge(v,u);
	for(int i=1;i<=n;++i)
		if(!vis[i]) ++ans,dfs(i);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9196
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

string calc(string s, string t) {

    bool match(int start) {
        for (int i = 0; i < t.length; i++) {
            if (s[start + i] == '?')
                continue;
            if (s[start + i] != t[i])
                return false;
        }
        return true;
    }

    for (int i = cast(int)(s.length - t.length); i >= 0; i--) {
        if (match(i)) {
            auto cs = new char[s.length];
            for (int j = 0; j < cs.length; j++) {
                cs[j] = s[j] == '?' ? 'a' : s[j];
            }

            for (int j = 0; j < t.length; j++) {
                cs[i + j] = t[j];
            }
            return to!string(cs);
        }
    }
    return "UNRESTORABLE";
}

void main() {
    string s = readln.chomp;
    string t = readln.chomp;

    auto ans = calc(s, t);
    writeln(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

string s;

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

  cin >> s;

  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else if ("Rainy")
    cout << "Sunny" << endl;

  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0,0)
b.insert(0,0)

asum = list(accumulate(a))
bsum = list(accumulate(b))

ans = 0
for i, v in enumerate(asum):
    if v > k:
        break
    index = bisect.bisect_right(bsum, k-v)
    ans = max(ans, i + index-1)
print(ans)

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

using ll = long long;
const int nax = 405;
const ll INF = 1e18L + 5;
ll dp[nax][nax];
//dp[i][j] = the minimum total cost of combining interval i to j into one vertex
void min_self(ll& a, ll b){
    if(a > b){
        a = b;
    }
}
ll sum(int l, int r, vector<int>& a){
    ll s = 0;
    for(int i = l; i<=r; ++i){
        s += a[i];
    }
    return s;
}
int main(){
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    vector<ll> b(n);
    for(int& x : a){
        scanf("%d", &x);
    }b[0] = a[0];
    for(int i = 1; i<n; ++i){
        b[i] = a[i];
        b[i] += b[i-1];
    }

    for(int l = n-1; l>=0; --l){
        for(int r = l; r<n; ++r){
            if(l == r){
                dp[l][r] = 0;
            }else{
                dp[l][r] = INF;
                for(int i = l; i<r; ++i){
                    min_self(dp[l][r], dp[l][i] + dp[i+1][r] + (l == 0 ? b[r] : b[r] - b[l - 1]));
                }
            }
        }
    }
    cout << dp[0][n-1] << "\n";
}



// void min_self(int& a, int b){
//     a = min(a, b);
// }

// int mCost(vector<int>& a, int n){
//     if(n == 1){
//         return 0;
//     }if(n == 2){
//         return a[0] + a[1];
//     }

//     int ans = INT_MAX;

//     for(int i = 0; i<(n-1); i++){
//         vector<int> b(n);
//         b = a;
//         int cost = b[i] + b[i+1];
//         b[i+1] += b[i];
//         b.erase(b.begin() + i);

//         min_self(ans, cost + mCost(b, n-1));
//     }
//     return ans;
// }

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  int count=1;
  for(int i=1;i<3;i++){
    if(a.at(i-1)!=a.at(i))count++;
}
cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = 1001001001;
    rep(i, n-k+1) {
        chmin(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	bool operator<(const struct Info &arg) const{
		if(x != arg.x){
			return x < arg.x;
		}else{
			return y < arg.y;
		}
	}
	double x,y,r;
};

int N;
Info info[100001];

bool compare_y(Info left,Info right){ //順序付け関数

	return left.y < right.y;

}

bool is_OK(int index,double x,double dist){
	if(info[index].x < x){ //基準線より中心が左
		if(info[index].x+info[index].r+dist < x){
			return false;
		}

	}else{ //基準線より中心が右
		if(info[index].x-info[index].r-dist > x){
			return false;
		}
	}

	return true;
}

double calc_dist(int a,int b){
	return sqrt((info[a].x-info[b].x)*(info[a].x-info[b].x)+(info[a].y-info[b].y)*(info[a].y-info[b].y))-(info[a].r+info[b].r);
}

double calc_y_dist(int a,int b){
	return (info[b].y-info[b].r)-(info[a].y+info[a].r);
}

double closest_pair(Info* array,int tmp_N){
	if(tmp_N <= 1)return DBL_MAX;

	int mid = tmp_N/2; //中央のインデックス

	double x = array[mid].x; //基準線x
	double dist = min(closest_pair(array,mid),closest_pair(array+mid,tmp_N-mid)); //集合を2分割し、再帰的に最小距離を求める
	inplace_merge(array,array+mid,array+tmp_N,compare_y); //2つのソート済の範囲をマージ

	vector<int> V; //★★再帰毎にメモリを確保(indexをpush)★★


	int left,right,m,search_left;

	for(int i = 0; i < tmp_N; i++){
		//if(!is_OK(i,x,dist))continue; //基準線より最小距離以上離れている点は無視(★異なる領域間での、新最小値を作り得ないということ★)

		//★★Vはyの昇順に並んでいる:自分よりy座標が小さいもののみ、入っている★★

		//2分探索で、検索範囲を定める
		/*left = 0,right = V.size()-1,m = (left+right)/2;
		search_left = 0;

		while(left <= right){
			if(calc_y_dist(V[m],i) < dist){ //y座標の差がdist未満
				search_left = m;
				right = m-1; //より左へ
			}else{
				left = m+1; //より右へ
			}
			m = (left+right)/2;
		}*/

		/*for(int k = search_left; k < V.size(); k++){
			dist = min(dist,calc_dist(V[k],i));
		}*/

		for(int k = 0; k < min((int)V.size(),2); k++){
			dist = min(dist,calc_dist(V[V.size()-1-k],i));
		}

		V.push_back(i); //可能性あり集合に、iを追加
	}
	return dist;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].r,&info[i].x,&info[i].y);
	}
	sort(info,info+N);

	printf("%.10lf\n",closest_pair(info,N));
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};
ll mod = 1e9+7;

int main(){
    ll n,ans=1;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> ls(26);
    for (int i = 0; i < n; i++)
    {
        ls[s[i]-'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        ans*=ls[i]+1;
        ans%=mod;
    }
    
    cout<<(ans-1+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

//写経

int main(){
  int M,K;cin >> M >> K;
  vector<int> V;
  int num = 0;
  
  //コーナーケース
  if(M == 1 && K == 1){
    cout << -1 << endl;
    return 0;
  }
  if(M == 1 && K == 0){
    cout << "0 0 1 1" << endl;
    return 0;
  }
  if(K>=(1<<M)){ //kが長さ2のM乗(1bitシフトで2乗)をオーバー
    cout << -1 << endl;
    return 0;
  }

  rep(i,1<<M) if(i!=K) cout << i << " ";
  cout << K << " ";
  for(int j=(1<<M)-1;j>=0;j--) if(j!=K) cout << j << " ";
  cout << K;
  cout << endl;
  
  
  
}

Measured memory_bytes: 1792
from decimal import Decimal


def com_interest(n: int) -> int:
    saving = 100
    interest_per = 0.01
    years = 0

    while True:
        years += 1
        saving = int(saving * Decimal('1.01'))
        if saving >= n:
            break
    return years


print(com_interest(int(input())))

Measured memory_bytes: 9960
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll bucket[5] = {0};

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

    int p[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int r[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

    for(int i=0; i<n; i++){
        string s;
        cin>>s;

        if(s[0]=='M'){
            bucket[0]++;
        }else if(s[0]=='A'){
            bucket[1]++;
        }else if(s[0]=='R'){
            bucket[2]++;
        }else if(s[0]=='C'){
            bucket[3]++;
        }else if(s[0]=='H'){
            bucket[4]++;
        }
    }

    ll ans = 0;
    for(int i=0; i<10; i++){
        ans += bucket[p[i]] * bucket[q[i]] * bucket[r[i]];
    }

    cout<< ans <<endl;
    return 0;
}

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

typedef pair<int, int> P;

bool pairCompare(const P &p1, const P &p2)
{
    return p1.second > p2.second;
}

int main(int argc, char const *argv[])
{
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
int main(){
	int n;
	scanf("%d", &n);
	int a[n], c = 1;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (a[i] == c){
			c++;
		}
	}
	if (c == 1){
		printf("-1\n");
	}else{
		printf("%d\n", n - c + 1);
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
const long long int MX = 1e18;

int main() {
  int n;
  cin >> n;
  long long int ans = 1;
  bool ng = false;
  for (int i = 0; i < n; ++i)
  {
    long long int a;
    cin >> a;
    if ( a == 0 ) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || ans*a > MX || MX/ans < a) {
      ng = true;
    }
    ans *= a;
  }

  if (ng) cout << -1 << endl;
  else
  {
     cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    sc.nextInt();
    int k = sc.nextInt();
    sc.nextLine();
    int[] xs = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    int r = 0;
    for (int x : xs) {
      if (x > k - x) {
        r += 2 * (k - x);
      } else {
        r += 2 * x;
      }
    }
    System.out.println(r);
    sc.close();
  }
}


Measured memory_bytes: 36372
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<long long, pair<int, int>> p;
int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0)return 0;
		bool b[20010] = {};
		b[1] = true;
		p a[20010];
		for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second.first >> a[i].second.second;
		sort(a, a + m);
		for (int i = 0; i < m; i++)
			if (b[a[i].second.first])b[a[i].second.second] = true;
		int ans = 0;
		for (int i = 1; i <= n; i++)if (b[i])ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3412
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
s = str(n)
k = len(s)
c = int(s[0])
if s == str(c) + "9"*(k-1):
    print(c + 9*(k-1))
else:
    print(c+9*(k-1)-1)
    

Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    map<ll,ll>mp;
    rep(i,c){
     ll d;
     cin>>d;
     mp[d-1]++;
    }
    rep(i,a){
        if(0<mp[i]+b-c)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 9892
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=2e5+5;
int a[N];
int dp[N];
vector<int> v[N];

int32_t main(){
    int n;
    cin>>n;
    v[0]={0};
    dp[0]=0;
    for(int i=1;i<=n+1;++i){
        if(i<=n)cin>>a[i];
        int d=a[i]-a[i-1];
        vector<int> po;
        for(int j:v[i-1]){
            if(0<=j&&j<=a[i])po.pb(j);
            if(0<=j+d&&j+d<=a[i])po.pb(j+d);
        }
        sort(po.begin(),po.end());
        po.resize(unique(po.begin(),po.end())-po.begin());
        int pv=-1;
        for(int j:po){
            vector<pii> b;
            b.pb(0,dp[i-1]);
            b.pb(j+1,+1);
            b.pb(j-d+1,+1);
            for(int k:v[i-1])if(k)b.pb(k,-1);
            sort(b.begin(),b.end());
            int val=0,cu=b[0].f,res=N;
            for(pii p:b){
                if(p.f!=cu&&cu>=0&&cu<=a[i-1])upn(res,val);
                val+=p.s;
                cu=p.f;
            }
            if(cu>=0&&cu<=a[i-1])upn(res,val);
            if(!j)dp[i]=res;
            if(res!=pv)v[i].pb(j);
            pv=res;
        }
    }
    cout<<dp[n+1]<<'\n';

    return 0;
}


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

#N = 1
#A = [10**9]*N

A_n = [A[i-1] - i for i in range(1,N+1)]

A_n.sort()

if N%2 == 0:
    cent_max = A_n[N//2]
    cent_min = A_n[N//2-1]
else:
    cent = A_n[N//2]
    
if N%2 == 0:    
    sadness1 = sum([abs(A_n[i]-cent_min) for i in range(N)])
    sadness2 = sum([abs(A_n[i]-cent_max) for i in range(N)])
    sadness = min(sadness1, sadness2)

else:
    sadness = sum([abs(A_n[i]-cent) for i in range(N)])

print(sadness)

Measured memory_bytes: 27684
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()
ans = 0

for i in b:
    ans += bisect.bisect_left(a, i)*(n-bisect.bisect_right(c, i))

print(ans)


Measured memory_bytes: 22452
#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 ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
 
ll lca(ll a, ll b) {
    return a * b / __gcd(a , b);
}
void solve(){
    ll a, b;
    cin >> a >> b;
    cout << lca(a , b);
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)      \
	for (auto i : v) \
		cout << i << ' ';

void solve()
{
	int n;
	cin >> n;
	if (n < 1200)
		cout << "ABC";
	else
		cout << "ARC";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 256