akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  ll a[n];
  REP(i,n){
    cin>>a[i];
  }
  ll b4,b1,b2;
  b4 =0;
  b1 =0;
  b2 =0;
  REP(i,n){
    if(a[i]%2==1){
      b1++;
    }else if(a[i]%4==0){
      b4++;
    }else if(a[i]%2==0){
      b2++;
    }
  }
  if(b4>=b1){
    cout<<"Yes"<<endl;
  }else if(b4==b1-1&&b2%2==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
a,b = map(int,input().split())
mx = 100000000
sum = 0
flag = False
for i in range(1,a+1):
    if mx > abs(b+i-1):
        mx = abs(b+i-1)
    if b+i-1 < 0 :
        flag = True
    sum+=b+i-1
if flag:
    print(sum+mx)
else:
    print(sum-mx)
  


Measured memory_bytes: 3316
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {

	ll N; cin >> N;
	map<ll, ll> po;
	rep(i, N) {
		ll tmp;
		cin >> tmp;
		++po[tmp];
	}

	ll ans = 0;
	for (auto p : po) {
		if (p.first <= p.second) ans += p.second - p.first;
		else ans += p.second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) chmax(ans, uf.size(i));
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(string S) {
    long long A = count(S.begin(), S.end(), '1');
    long long B = count(S.begin(), S.end(), '0');
    cout << S.size() - abs(A-B) << endl;

}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 512
X = int(input())

def prime(x,number):
    return x % number 


if X == 2:
    print(2)
elif X == 3:
    print(3)

else:
    ## X is prime, or not.
    for number in range(2, X+1):
        if prime(X,number) == 0 and number != X:
            break
        elif prime(X,number) == 0 and number == X:
            print(X)
            quit()

    ## find prime number larger than X
    flag = True
    while flag:
        X = X + 1
        for number in range(2, X+1):
            if prime(X,number) == 0 and number != X:
                break
            elif prime(X,number) == 0 and number == X:
                flag = False
                print(X)


Measured memory_bytes: 3064
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;


int main(){
    ll n,p,ans=1,ret=0;
	string s;
	bool x = false;
	cin >> n >> p;
	ans = (ll)pow(p,1. / n);
	//cout << ans << endl;
	ans++;
	while(true){
		if(p % (ll)(pow(ans,n)) == 0) break;
		else ans--;
	}
	cout << ans << endl;
    return 0;
}  


Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B, C, D;
  ci(A, B, C, D);
  int a = 0;
  repi(i, A, B){
    repi(j, C, D){
      if(i == j){
        a++;
      }
    }
  }
  co(a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;

int n, a[N], m, b[N];

bool Judge () {
	int l = n, r = n;
	while (l > 1 && b[l - 1] ^ b[l]) --l;
	while (r < m && b[r] ^ b[r + 1]) ++r;
	int x = min(n - l, r - n);
	return b[n] ^ (x & 1);
}

int main () {
	scanf("%d", &n);
	int l = 1, r = m = n * 2 - 1, mid;
	for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
	while (l <= r) {
		mid = (l + r) >> 1;
		for (int i = 1; i <= m; ++i) b[i] = (a[i] <= mid);
		if (Judge()) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

const int MOD=1e9+7;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,K;
  cin >> N >> K;
  vector<ll> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  vector<vector<ll>> dp(N+1,vector<ll>(K+1,0));
  dp.at(0).at(0)=1;
  for(int i=0;i<N;i++){
    ll sum=0;
    for(int j=0;j<K+1;j++){
      sum+=dp.at(i).at(j);
      if(j-a.at(i)>0) sum-=dp.at(i).at(j-a.at(i)-1);
      sum=(sum+MOD)%MOD;
      dp.at(i+1).at(j)+=sum;
      dp.at(i+1).at(j)%=MOD;
    }
  }
  cout << dp.at(N).at(K) << endl;

  return 0;
}

Measured memory_bytes: 80256
#include <iostream>

int main(int argc, const char * argv[]) {
    int h, w;
    for ( ; std::cin >> h >> w && !(h == 0 && w ==0); ) {
        for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i++) {
                if ((i + j) % 2 == 0) {
                    std::cout << "#";
                } else {
                    std::cout << ".";
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3092
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    void solve(Scanner in, PrintWriter out) {
        int t = in.nextInt();
        int cpt = 0;

        for (int i = 0; i < t; ++i) {
            int a1 = in.nextInt();
            int b1 = in.nextInt();
            if (a1 == b1) {
                cpt++;
            } else {
                cpt = 0;
            }

            if (cpt == 3) {
                out.println("Yes");
                break;
            }
        }
        if (cpt != 3)
            out.println("No");
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 36288
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
int main() {
	int N;
	scanf("%d", &N);
	auto A = new int[N];
	for (int i = 0; i < N; i++)scanf("%d", A + i);
	int min = mod;
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] < min) {
			min = A[i];
			res++;
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 1024
N=int(input())
a=input().split()
A=[int(b) for b in a]

money=1000
kabu=0
number=0

answers=[1000]

for n in range(N-1):
    if A[n]<A[n+1]:
        suuji=money//A[n]
        money-=A[n]*suuji
        kabu+=suuji
    elif A[n]>A[n+1]:
        money+=kabu*A[n]
        kabu=0
    answers.append(money)

money+=kabu*A[-1]

answers.append(money)

print(max(answers))



Measured memory_bytes: 61932
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n=0,l,b,ans=1;
	string s;
	cin>>s;
    l=s.size();
    rep(i,l){
        if(i%2&&s[i]=='R')ans=0;
        if(!(i%2)&&s[i]=='L')ans=0;
    }
    if(ans)cout<<"Yes";
    else cout<<"No";
	return 0;
}

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

int n, k, root = 0;
vector<vector<int>> g;
vector<int> res, l, r;

bool solve();
bool dfs(int now, int par, int dist);

int main() {
  cin >> n;
  g.resize(n);
  l.assign(n, -3000000);
  r.assign(n, 3000000);
  res.resize(n, -1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g[--a].push_back(--b);
    g[b].push_back(a);
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int node, p;
    cin >> node >> p;
    --node;
    l[node] = r[node] = res[node] = p;
    root = node;
  }
  if (solve()) {
    cout << "Yes" << endl;
    for (auto &p : res) cout << p << endl;
  } else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  if (!dfs(root, -1, res[root] & 1)) return 0;
  queue<int> qu;
  qu.push(root);
  res.assign(n, -100000000);
  res[root] = l[root];
  while (qu.size()) {
    int now = qu.front();
    qu.pop();
    for (auto to : g[now])
      if (res[to] == -100000000) {
        int num = res[now] - 1;
        if (l[to] <= num && num <= r[to])
          res[to] = num;
        else
          res[to] = num + 2;
        qu.push(to);
      }
  }
  return 1;
}
bool dfs(int now, int par, int dist) {
  if (res[now] >= 0 && ((res[now] ^ dist) & 1)) return 0;
  for (auto to : g[now])
    if (to != par) {
      if (!dfs(to, now, dist ^ 1)) return 0;
      l[now] = max(l[now], l[to] - 1);
      r[now] = min(r[now], r[to] + 1);
    }
  return l[now] <= r[now];
}


Measured memory_bytes: 17700
while 1:
	n=input()
	if n==0:break
	p=raw_input().split()+["end"]
	sp=p[0]
	ans=[]
	for i in range(n):
		if str(int(p[i])+1)!=p[i+1]:
			if sp!=p[i]:
				ans.append(sp+"-"+p[i])
			else:
				ans.append(sp)
			sp=p[i+1]
	print " ".join(ans)

Measured memory_bytes: 4220
#2019-04-09 2100 start

N,M,C= map(int, input().split())
B = input().split()
sumN = 0
count = 0

for i in range(N):
    A = input().split()
    for j in range(M):
        sumN = sumN + int(A[j])* int(B[j])
    if sumN + C > 0:
        count = count + 1
    sumN = 0


print(count)







Measured memory_bytes: 3060
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using static System.Console;

namespace Allocation
{
    
    internal class Program
    {
        private static int n, k;
        public static void Main(string[] args)
        {
            var input = ReadLine().Split(' ').Select(int.Parse).ToList();
            n = input[0];
            k = input[1];
            var w = new List<int>();
            for (var i = 0; i < input[0]; i++)
            {
                w.Add(int.Parse(ReadLine()));
            }

            var left = 0;
            var right = 100000 * 10000;
            var mid = 0;
            while (right - left > 1)
            {
                mid = (left + right) / 2;
                var v = CheckStackNum(mid, w);
                if (v >= n) right = mid;
                else left = mid;
            }

            WriteLine(right);
        }

        private static int CheckStackNum(int max, List<int> weight)
        {
            var i = 0;
            for (var  j = 0; j < k; j++)
            {
                var s = 0;
                while (s + weight[i] <= max)
                {
                    s += weight[i];
                    i++;
                    if (i == n) return n;
                }
            }

            return i;
        }
    }
    
}


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

const ll MOD = 1000000007;
const ll MAX = 100100;
const double PI = 3.1415926;

#define vll vector<ll>
#define max_heap priority_queue<int>
#define min_heap priority_queue<int , vector<int>, greater<int> >
#define pb push_back
#define all(container) container.begin(), container.end()
#define pll pair<ll,ll>
// #define traverse( container, it) for( typeof(container.begin()) it = container.begin(); it!=container.end(); it++)
ll n;
ll arr[3003];
pll dp[3003][3003][2];

pll fill(ll ptr1, ll ptr2, bool t)
{
	if (ptr1 > ptr2)
		return make_pair((ll)0,(ll)0);
	if (dp[ptr1][ptr2][t] != make_pair((ll)-1,(ll)-1))
		return dp[ptr1][ptr2][t];
	// cout << ptr1 << " " << ptr2 << " " << t << endl; 
	pll fi = fill(ptr1 + 1, ptr2, !t);
	pll se = fill(ptr1, ptr2 - 1, !t);

	if (!t)
	{
		fi.first += arr[ptr1];
		se.first += arr[ptr2];
		if (fi.first - fi.second > se.first - se.second)
			dp[ptr1][ptr2][t] = fi;
		else
			dp[ptr1][ptr2][t] = se;
		return dp[ptr1][ptr2][t];
	}
	else
	{
		fi.second += arr[ptr1];
		se.second += arr[ptr2];
		if (fi.first - fi.second <= se.first - se.second)
			dp[ptr1][ptr2][t] = fi;
		else
			dp[ptr1][ptr2][t] = se;
		return dp[ptr1][ptr2][t];
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for(int i = 0; i < 3003; i++)
		for(int j = 0; j < 3003; j++)
			for(int h = 0; h < 2; h++)
				dp[i][j][h] = make_pair(-1,-1);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> arr[i];

	pll c = fill(0,n-1,0);
	cout << c.first - c.second << endl;
	return 0;
}

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

char map[101][101];
int h, w;

void dfs(int x, int y) {
	char now;
	int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, -1, 0, 1 }, i;
	now = map[x][y];
	map[x][y] = '.';
	for (i = 0; i < 4; i++){
		if (0 <= x + dx[i] && x + dx[i] <= h && 0 <= y + dy[i] && y + dy[i] <= w && map[x + dx[i]][y + dy[i]] == now) {
			dfs(x + dx[i], y + dy[i]);
		}
	}
}

int main() {
	int i, j, count=0;
	while (cin >> h >> w, h&&w){
		count = 0;
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				cin >> map[i][j];
			}
		}
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				if (map[i][j] != '.'){
					dfs(i, j);
					count++;
				}
			}
		}
		cout << count << endl;
	}
}

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

bool acgt(char c) {
    if(c == 'A' || c == 'C' || c == 'G' || c == 'T') return true;
    else return false;
}

int main() {
    string S;
    cin >> S;

    int maxlen = 0;
    int len = 0;
    int f = 0;
    rep(i, S.size()) {
        if(f) {
            if(acgt(S[i])) len++;
            else {
                maxlen = max(maxlen, len);
                len = 0;
                f = 0;
            }
        } else {
            if(acgt(S[i])) {
                f = 1;
                len = 1;
            }
        }
    }
    if(f) maxlen = max(maxlen, len);

    cout << maxlen << endl;
    return 0;
}

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

int main(void){
    string s;
    cin>>s;
    int res = 700;
    rep(i,3) if(s[i] == 'o') res += 100;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    int max = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == 'I') cnt++;
      else cnt--;
      max = Math.max(max, cnt);
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N,i=1;
  cin>>N;
  if(N==4||N==2||N==1){
    cout<<i+3<<endl;
    return 0;
  }
  while(true){
      if(N%2==0){
          N=N/2;
      }
      else{
          N=3*N+1;
      }
      i++;
      if(N==4||N==2||N==1){
          cout<<i+3<<endl;
          return 0;
      }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	char a[10];
	int n,i,sum,c,len;
	cin>>a;
	len=strlen(a);
	c=len; sum=0; n=0;
	for(i=0;i<len;i++){
		sum+=a[i]-'0';
		n=n*10+a[i]-'0';
	}
	if(n%sum==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//RollerCoaster
int main(){
  int friends_num;
  float required_height;
  std::cin>>friends_num>>required_height;
  float height[friends_num];
  int ACmember=0;
  for (int i=0;i<friends_num;i++){
    std::cin>>height[i];
    if(height[i]>=required_height){
      ACmember++;
    }
  }
  std::cout<<ACmember<<std::endl;
return 0;
}


Measured memory_bytes: 640
def F(A,B):
    if A <= B:
        B = str(B)
        return len(B)
    else:
        A = str(A)
        return len(A)

if __name__ == '__main__':
    import math
    N = int(input())
    min = F(1,N)
    for i in range(1,int(math.sqrt(N))+1):
        if N % i == 0:
            a = F(i,N//i)
            if a < min:
                min = a

    print(a)


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

int main() {
    int n;
    cin>>n;
    int a[n];for(int i=0;i<n;i++) cin>>a[i];
    int b[n];for(int i=0;i<n;i++) cin>>b[i];
    int c[n-1];for(int i=0;i<n-1;i++) cin>>c[i];

    int sati=0;
    for(int i=0;i<n;i++) {
        sati+=b[a[i]-1];
        if(i>=1&&a[i]==a[i-1]+1) sati+=c[a[i-1]-1];
    }
    cout<<sati<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> l(n);
    REP(i,n) cin >> l[i];
    int sum = 0;
    sort(l.begin(), l.end());
    REP(i,n-1) sum += l[i];
    if (l[n-1] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double kyori(int mae,int ato,int *X,int *Y){
    double a=pow(X[ato]-X[mae],2);
    double b=pow(Y[ato]-Y[mae],2);
    double ans=pow(a+b,0.5);
    return ans;
}

int main() {
    int N;cin>>N;
    vector<int> mae(N),ato(N);
    for(int i=0;i<N;i++)cin>>mae[i];
    for(int i=0;i<N;i++)cin>>ato[i];

    int a,b;

    vector<int> v(N);
    iota(v.begin(),v.end(),1);
    int count=0;

    do{
        if(v==mae)a=count;
        if(v==ato)b=count;
        count++;
    }while(next_permutation(v.begin(),v.end()));

    int ans=abs(a-b);

    cout<<ans<<endl;

    }






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

int main(){
    int n,a,b,c,D[100];

    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++){
	cin>>D[i];
    }

    sort(D,D+n);
    int ans=0,cost,calorie;
    int k;

    for(int i=0;i<=n;i++){
	k=n-1;
	cost=a+b*i;
	calorie=c;
	for(int j=0;j<i;j++){
	    calorie+=D[k--];
	}
	if(calorie/cost>ans) ans=calorie/cost;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;

int	card[40320];
vector<int> tmp(10);
queue<vector<int> > qu;

int perm2num(vector<int> perm){
	int num=0;
	for(int i=0;i<8;i++){
		num *= 8-i;
		num += perm[i];
		for(int j=i+1;j<8;j++) if(perm[j]>perm[i])perm[j]--;
	}
	return num;
}

void qu_push(int a){
		swap(tmp[tmp[8]],tmp[tmp[8]+a]);			
		tmp[9]++;
		tmp[8]+=a;
		int p2n=perm2num(tmp);
		if (card[p2n]==-1){
			qu.push(tmp);
			card[p2n] = tmp[9];
		}
		tmp[9]--;
		tmp[8]-=a;
		swap(tmp[tmp[8]],tmp[tmp[8]+a]);
}

void solve(){
	vector<int> bgn(10);
	for(int i=0;i<8;i++) bgn[i] = i;
	qu.push(bgn);
	while(!qu.empty()){
		tmp = qu.front();
		qu.pop();
		if(tmp[8]<4)qu_push(4);
		else qu_push(-4);
		if(tmp[8]%4>0)qu_push(-1);
		if(tmp[8]%4<3)qu_push(1);
	}
}

int main(){
	card[0] = 0;
	for(int i=1;i<40320;i++) card[i] = -1;
	solve();
	vector<int> perm(8);
	while(true){
		int i=0;
		for(;i<8;i++)if(!(scanf("%d",&perm[i])+1))break;
		if(i<8)break;
		printf("%d\n",card[perm2num(perm)]);
	}
  return 0;
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,m,a,b,ans=0;cin>>n>>m;
    vector<pair<int,int>> vec(n,pair<int,int>(0,0));
    for(int i=0;i<n;i++){
        cin>>a>>b;
        vec[i]=make_pair(a,b);
    }
    sort(all(vec));
    priority_queue<int> pq;
    bool allok=false;
    int pnt=0;
    for(int i=1;i<=m;i++){
        if(!allok){
            while(vec[pnt].first<=i){
                pq.push(vec[pnt].second);
                pnt++;
                if(pnt>=n){
                    allok=true;break;
                }
            }
        }
        if(!pq.empty()){
            ans+=pq.top();pq.pop();
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4648
#include<bits/stdc++.h>
#define maxn 100010
#define ll long long
#define mod 1000000007
using namespace std;
int val[maxn], n, pre[maxn], fac[maxn], inv[maxn];
int C(int n, int m) {return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;}
int calc(int a, int k)
{
	int ans = 1;
	while (k)
	{
		if (k % 2) ans = (ll)ans * a % mod;
		a = (ll)a * a % mod;
		k /= 2;
	}
	return ans;
}
int solve(int tp)
{
	int res = 0;
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	for (int i = 0; i <= n; i++)
		inv[i] = calc(fac[i], mod - 2);
	for (int i = 1; i <= n; i++)
		pre[i] = (pre[i - 1] + val[i]) % mod;
	for (int i = 1; i <= n; i++)
	{
		int tmp = pre[n - i + 1];
		if (i == 1)
		{
			if (tp) res = (res + (ll)tmp * fac[n] % mod) % mod;
		}
		else
		{
			int sum = i - 1, xs;
			xs = (ll)fac[n - i] * fac[sum] % mod * C(n, i) % mod;
			res = (res + (ll)tmp * xs % mod) % mod;
		}
	}
	return res;
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &val[i]);
	int res = solve(0);
	reverse(val + 1, val + n + 1);
	res = (res + solve(1)) % mod;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1792
def dfs(i,f):
    #n個回目なら合計値を返す
    if i == len(s)-1: 
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1]) + dfs(i+1,f+"+"+s[i+1])
s = list(input())
print(dfs(0,s[0]))

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	while(1)
	{
		int n, x, cnt;
		scanf("%d %d", &n, &x);
		if((n == 0) && (x == 0))
		{
			break;
		}

		cnt = 0;
		for(int i =     1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
		for(int k = j + 1; k <= n; ++k)
		{
			if(i + j + k == x)
			{
				++cnt;
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string.h>

typedef unsigned long long ll;

char s[100000];

bool calc()
{
  ll len;

  std::cin >> s;

  len = strlen(s);

  return !((len % 2 == 0) ^ (s[0] == s[len-1]));
}

int main(void)
{
  if (calc())
    std::cout << "First" << std::endl;
  else
    std::cout << "Second" << std::endl;

  return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

lli sumA[100100],sumB[100100];

lli conv(char A){
	if(A=='A')return 2;
	else return 1;
}

signed main(){

	string s,t;
	cin>>s>>t;

	sumA[0]=0,sumB[0]=0;
	REP(i,0,s.size()){
		sumA[i+1] = sumA[i]+conv(s.at(i));
	}
	REP(i,0,t.size()){
		sumB[i+1] = sumB[i]+conv(t.at(i));
	}

	lli q;
	cin>>q;

	REP(i,0,q){
		lli a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,b--,c--,d--;

		lli sB = sumA[b+1]-sumA[a];
		lli tB = sumB[d+1]-sumB[c];

		if(DEBUG)cout<<"sB="<<sB<<"tB="<<tB<<endl;

		if(sB%3 == tB%3)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}


	return 0;
}

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

#define N 1000000

int main() {

    int n;
    cin>>n;

    int a[N];
    for(int i = 0; i < n; i++) cin>>a[i];

    int i, j = 0;
    for(i = 0; i < n-1; i++) {
        if(a[i] <= a[n-1]) {
            if(i != j) {
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
            j++;
        }
    }

    for(int k = 0; k < j; k++) cout<<a[k]<<' ';
    cout<<'['<<a[n-1]<<']'<<' ';
    int k;
    for(k = j+1; k < i; k++) cout<<a[k]<<' ';
    cout<<a[j]<<endl;

    return 0;
}



Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int H,N;cin >> H >> N;
    vector<int> A(N);rep(i,N)cin >> A[i];

    int ans = 0;
    rep(i,N)ans += A[i];

    if(H > ans)cout << "No" << endl;
    else cout << "Yes" <<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define REFOR(i,m,n) for(int i=int(n-1); i>=int(m); i--)
#define ALL(obj) (obj).begin(),(obj).end()
 
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>
 
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>
 
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

#define PB push_back
#define Cout(str) cout << str << endl

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const ll EPS = (ll)1e-8;

int main(){
	int n,m;
	int a,b,c;
	int sum;
	string str;
	string s,t;
	char ch;
	VI vi;
	vector<char> vc;
	VS vs;
	int reserve_vi = 100;
	map<int, int> table; 
	string str2, str3;
	map<char, string> vowel;
	vector<char> vowel_vec = {'a', 'e', 'i', 'o', 'u'};

	//cin >> n >> m;
	//cin >> a >> b;
	//cin >> a >> b >> c;
	//cin >> str;
	//cin >> str >> str2 >> str3;
	//cin >> n;
	
	//cin >> s >> t;
	//cin >> ch;
	cin >> a >> ch >> b;
	if(ch == '+') cout << a+b << endl;
	else cout << a-b << endl;

	//cout << accumulate(vi.begin(), vi.begin()+n, 0) << endl;

	//swap(a, b);
	//vi.resize(N);
	//fill(vi.begin(), vi.end(), 1);
	//vi.reserve(reserve_vi);
	//vi.PB(n);

	//vc.resize(5);
	//vc[i] = (str[i]);

	//sort(vc.begin(), vc.end(), greater<char>());
	//sort(vc.begin(), vc.end());

	//for(auto itr = table.begin(); itr != table.end(); ++itr) {
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m; cin >> n >> m;
    ll a[m], b[m];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vector<P> vec;
    rep(i, m){
        vec.push_back({b[i], a[i]});
    }

    sort(vec.begin(), vec.end());

    ll ans = 0;
    ll pos = 0;
    rep(i, m){
        ll anow = vec[i].second;
        ll bnow = vec[i].first;

        if(anow < pos) continue;

        pos = bnow;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

struct edge {
    int to;
    ll len;
    edge(int to,ll l):to(to),len(l) {}
};

vl dijkstra(int start,const vector<vector<edge>>& v) {
    int n = v.size();
    vector<ll> dist(n,linf);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
    q.emplace(0LL,start);
    dist[start] = 0;
    while(!q.empty()) {
        auto p = q.top();
        q.pop();
        if(dist[p.second] < p.first) continue;
        for(auto e : v[p.second]) {
            if(chmin(dist[e.to],p.first+e.len)) {
                q.emplace(p.first+e.len,e.to);
            }
        }
    }
    return dist;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<edge>> yen(n),snk(n);
    rep(_,m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        yen[u].eb(v,a);
        yen[v].eb(u,a);
        snk[u].eb(v,b);
        snk[v].eb(u,b);
    }
    auto dy = dijkstra(s,yen);
    auto ds = dijkstra(t,snk);
    vl ans(n);
    ans[n-1] = dy[n-1]+ds[n-1];
    rrep(i,n-1) {
        ans[i] = min(ans[i+1],dy[i]+ds[i]);
    }
    rep(i,n) cout << 1000000000000000-ans[i] << '\n';
}


Measured memory_bytes: 21084
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn=1000000+10;

int top=0;
char s[maxn],t[maxn];

#define mp make_pair
typedef pair<int,int> pii;
pii a[maxn];

inline int calc(int i,int p1,int p2)
{
	if(p1==p2) return 0;
	int l=1,r=i-1,mid,ans=-1;
	while(l<=r)
	{
		mid=(l+r)>>1;
		int pos=a[i-mid].first-mid;
		if(pos>=p2) ans=mid,r=mid-1;
		else l=mid+1;
	}
	if(ans==-1) ans=i;
	return ans;
}

int main()
{
	int n;
	scanf("%d%s%s",&n,s+1,t+1);
	
	int pos=n;
	for(int i=n;i>=1;--i)
	{
		pos=min(pos,i);
		while(pos > 0 && s[pos]!=t[i]) 
			--pos;
		if(pos==0) return puts("-1"),0;
		a[++top]=mp(pos,i);
		while(t[i-1]==t[i] && i-1>=pos) --i;
	}
	
//	for(int i=1;i<=top;++i) printf("#%d: p1:%d p2:%d\n",i,a[i].first,a[i].second);

	int ans=0;	
	for(int i=1;i<=top;++i)
		ans=max(ans,calc(i,a[i].first,a[i].second));

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

Measured memory_bytes: 9984
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
#define inf 1000000007
signed main(){
    int n;cin>>n;
    int a,b,c;cin>>a>>b;
    c=a-b;
    int hea[114514];
    int count=0;
    rep(i,0,n){
        cin>>hea[i];
        count+=hea[i]/a+1;
    }
    int left,right,mid=0;
    left=-1;
    right=count;
    rep(i,0,100){
        count=0;
        mid=(left+right)/2;
        rep(i,0,n){
            int h=hea[i];
            if(h<=b*mid)continue;
            count+=((h-(b*mid))+c-1)/c;
        }
        if(count<=mid){
            right=mid;
        }
        else left=mid;
    }
    cout<<mid+1<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;

int main()
{
	ll A,B,C,K;
	scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
	if(K&1)printf("%lld\n",B-A);
	else printf("%lld\n",A-B);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if ((S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' || S.at(6) == '4') && S.at(5) == '0') {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}

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

int main() {
    string w;
    map<char, int> num;
    bool b = true;

    cin >> w;
    for (int i=0; i < w.length(); i++) {
        if (num.count(w[i])) {
            num[w[i]]++;
        } else {
            num[w[i]] = 1;
        }
    }

    for (auto p : num) {
        auto v = p.second;
        if (v % 2 == 1) {
            b = false;
            break;
        }
    }

    if (b) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 3624
N = int(input())
a = list(map(int, input().split()))

dp = [0] * N
dp[0] = a[0]

a_sum = sum(a)
a_min = float('inf')
for i in range(N-1):
    if (i == 0):
        dp[0] = a[0]
    else:
        dp[i] = dp[i-1] + a[i]
    if (a_min > abs((a_sum-dp[i]) -dp[i])):
        a_min = abs((a_sum-dp[i]) -dp[i])

print(a_min)

Measured memory_bytes: 24832
#include <stdio.h>

int main(void)
{
	int a,b,c,d,n;
	int i,j,l,k;
	int p = 0;
	
	while(scanf("%d",&n) != EOF){
	
		for(a = 0;a <= 9;a++){
			for(b = 0;b <= 9;b++){
				for(c = 0;c <= 9;c++){
					for(d = 0;d <= 9;d++){
						if(a+b+c+d == n){
							p++;
						}
					}
				}
			}
		}
		printf("%d\n",p);
		p = 0;
	}
	return(0);
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll ans = 0;
    rep(i, n) {
        ll x;
        cin >> x;
        ans += min(x, k - x);
    }
    ans *= 2;
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
X,K,D = map(int,input().split())
if X < 0:
    X *= (-1)
tmp = X -K*D
if X == 0:
    if K%2 == 0:
        ans = 0
    else:
        ans = abs(D)
elif tmp >= 0:
    ans = tmp
else:
    dif  = X//D
    buf = X - D*dif
    if (K-dif) % 2  == 0:
        ans = abs(buf)
    else:
        ans = abs(buf - D)
print(ans)


Measured memory_bytes: 9180
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a>=2 && b>=2){
        if(a==b){cout <<"Draw";}
        else if(a>b){cout<< "Alice";}
        else if(a<b){cout<< "Bob";}

    }


    if(a==1 or b==1){
        if(a==b){cout <<"Draw";}
        else if(a>b){cout<< "Bob";}
        else if(a<b){cout<< "Alice";}
    }

    return 0;
}


Measured memory_bytes: 256
var
	a,b,n,i,s:longint;
function fac(x:longint):longint;
var
	sum:longint;
begin
	sum:=0;
	while x<>0 do
	begin
		sum:=sum+x mod 10;
		x:=x div 10;
	end;
	exit(sum);
end;
begin
	read(n,a,b);
	s:=0;
	for i:=1 to n do
		if (fac(i)>=a) and (fac(i)<=b) then s:=s+i;
	writeln(s);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    int i = 1;
    ll cnt = 0;
    cin >> n;
    vector<string> s(n);
    for(int j = 0; j < n; j++)
    {
        cin >> s[j];
        sort(s[j].begin(), s[j].end());
    }
    sort(s.begin(), s.end());
    while(i < n)
    {
        ll tempcnt = 0;
        while(i < n && s[i] != s[i - 1])
        {
            i++;
        }
        while(i < n && s[i] == s[i - 1])
        {
            tempcnt++;
            cnt += tempcnt;
            i++;
        }
    }
    cout << cnt;

    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i, N)
  cin >> h[i];
  sort(ALL(h));
  int ans = INT32_MAX;
  for (int i = 0; i + (K - 1) < N; i++)
  {
    int tmp = h[i + (K - 1)] - h[i];
    if (tmp < ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    long long int n,a,b;
    cin >> n >> a >> b;
    if(!a)
    {
        cout << 0 << endl;
        return 0;
    }
    long long int amari;
    if(n%(a+b)>a) amari=a;
    else amari=n%(a+b);
    cout << (n/(a+b))*a+amari << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin >> s;
	if(s[0]==s[2]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
入力 = input()
for i in range(len(入力)-1):
  if 入力[i]==入力[i+1]:
    print(i+1, i+2)
    exit()
  elif i<len(入力)-2 and 入力[i]==入力[i+2]:
    print(i+1, i+3)
    exit()
print(-1, -1)

Measured memory_bytes: 3188
N,K = map(int,input().split())
XY = [list(map(int,input().split())) for _ in [0]*N]

iX = sorted(x for x,y in XY)
iY = sorted(y for x,y in XY)
X = {x:i for i,x in enumerate(iX)}
Y = {y:i for i,y in enumerate(iY)}

c = [[0]*(N+1) for i in [0]*(N+1)]
for x,y in XY:
    c[Y[y]+1][X[x]+1] = 1

for i in range(N):
    ci1 = c[i+1]
    for j in range(N):
        ci1[j+1] += ci1[j]
for i in range(N):
    ci1 = c[i+1]
    ci = c[i]
    for j in range(N):
        ci1[j+1] += ci[j+1]

ans = 10**20
for u in range(N):
    for d in range(u+K-1,N):
        l = 0
        r = 1
        dY = iY[d]-iY[u]
        cd = c[d+1]
        cu = c[u]
        while r<N:
            if cd[r+1]+cu[l]-cu[r+1]-cd[l] >=K:
                ans = min(ans, (iX[r] - iX[l])*dY)
                l+=1
            else:r+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for(int i = 0; i < n; i++)
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    string S; cin >> S;
    int dmin = 1000;
    for (int i = 0; i < S.size() - 2; i++) {
        int n = (S[i] - '0') * 100 + (S[i+1] - '0')*10 + S[i+2] - '0';
        dmin = min(dmin, abs(n - 753));
    }
    cout << dmin << endl;
}

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

string s[105];
int fa[100005];
int sum = 0;

void build(int qwq) {for(int i=1;i<=qwq;i++) fa[i]=i;sum = qwq;return ;}
int find(const int &x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
bool che(const int &x,const int &y){return find(x)==find(y);}
void mer(const int &x,const int &y) {if(!che(x,y)){ fa[fa[x]]=fa[y];sum--;}return ;}

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0&&m==0)break;
		build(n*m);
		for(int i=0;i<n;i++){
			cin>>s[i];
			for(int j=0;j<m;j++){
				if(i!=0&&s[i][j]==s[i-1][j])mer(i*m+j,(i-1)*m+j);
				if(j!=0&&s[i][j]==s[i][j-1])mer(i*m+j,i*m+j-1);
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3140
<?php
$input = trim(fgets(STDIN));
$stations = str_split($input);
$hasA = false;
$hasB = false;
foreach ($stations as $station) {
  if ($station == "A") $hasA = true;
  else $hasB = true;
}
echo (($hasA && $hasB) ? "Yes" : "No") . "\n";


Measured memory_bytes: 3828
#include<stdio.h>
int main(){
	int d,n,sum=1;
	scanf("%d%d",&d,&n);
	for(int i=0;i<d;i++){
		sum=sum*100;
	}
if(n==100){
printf("%d",101*sum);
}
else{
	printf("%d",sum*n);
}
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, pll> ppll;

#define MOD 1000000007
#define f(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define rep(i, n) f(i, 0, n)
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define wh(t) while (t--)
#define inf (ll)1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n";
#define pv(i,v) rep(i,v.size()) cout<<v[i]<<" "; pp("");
#define pa(i,n,v) rep(i,n) cout<<v[i]<<" "; pp("");
#define K 1001
const ll N = 1e7 + 5;

ll binpow(ll a, ll n)
{
	ll i = 1;
	while (n > 0)
	{
		if (n & 1)
			i = (i * a) % MOD;
		a = (a * a) % MOD;
		n = n >> 1;
	}
	return i % MOD;
}

ll isprime(ll n)
{
	if (n == 0 || n == 1)
		return n;
	if (n % 2 == 0)
		return (ll)2;
	if (n % 3 == 0)
		return (ll)3;
	else
	{
		for (ll i = 5; i * i <= n; i += 6)
		{
			if (n % i == 0)
				return i;
			if (n % (i + 2) == 0)
				return (i + 2);
		}
		return n;
	}
}
ll spf[N];
void precalc() {
	for (ll i = 2; i < N; ++i) {
		if (spf[i] == -1) {
			spf[i] = i;
			for (ll j = i * i; j < N; j += i) {
				if (spf[j] == -1) spf[j] = i;
			}
		}
	}
}

int main() {
	fast;
	ll l, r, n, m, i, j, k, x, y, t, q;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(spf, -1, sizeof(spf));
	precalc();

	ll ans = 0;
	cin >> n;
	f(i, 1, n + 1) {
		x = i;
		ll res = 1;
		while (x != 1) {
			ll cnt = 0;
			y = spf[x];
			while (x % y == 0) {
				++cnt; x /= y;
			}
			res *= (cnt + 1);
		}
		ans += i * res;
	}
	pp(ans);
}

Measured memory_bytes: 81748
def e_dist_max():
    N = int(input())
    Pos_z, Pos_w = [], []  # editorial に準ずる
    for _ in range(N):
        x, y = [int(i) for i in input().split()]
        Pos_z.append(x + y)
        Pos_w.append(x - y)
    Pos_z.sort()
    Pos_w.sort()
    return max(Pos_z[-1] - Pos_z[0], Pos_w[-1] - Pos_w[0])

print(e_dist_max())

Measured memory_bytes: 25552