akhauriyash/Code-Regression huggingface dataset:
/**
>>> In The Name Of GOD
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


bool cmp_pair_F_2(pair <int,int> x, pair <int,int> y)
{
    return x.F>y.F;
}
bool cmp_pair_S_2(pair <int,int> x, pair <int,int> y)
{
    return x.S>y.S;
}
bool cmp_pair_S_1(pair <int,int> x, pair <int,int> y)
{
    return x.S<y.S;
}

bool cmp(int x, int y)
{
	return x>y;
}



int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //int i,j;
	int n,k;
	cin >> n >> k;
	int a[n];
	for (int i=0;i<n;i++)
        cin >> a[i];
    int cost=0;
    for (int i=min(k,n);~i;i--)
    {
        for (int j=0;j<i;j++)
        {
            int c=0;
            vector <int> v;
            for (int o=0;o<=j;o++)
            {
                c+=a[o];
                if (a[o]<0)
                    v.pb(a[o]);
            }
            for (int o=n-1;o>n-(i-j);o--)
            {
                c+=a[o];
                if (a[o]<0)
                    v.pb(a[o]);
            }
            sort(all(v));
           // cout << c << endl;
            for (int o=0;o<min(sz(v),k-i);o++)
                c-=v[o];
            //cout << i << ' ' << j << ' ' << c << endl;
            smax(cost, c);
        }
        {
            int c=0;
            vector <int> v;
            for (int j=n-1;j>=n-i;j--)
            {
                c+=a[j];
                if (a[j]<0)
                    v.pb(a[j]);
            }
            sort(all(v));
            for (int o=0;o<min(sz(v),k-i);o++)
                c-=v[o];
            //cout << 111 << ' ' << c << endl;
            smax(cost, c);
        }

        //cout << i << ' ' << c << ' ' ;
    }
    cout << cost;
    return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin >> a[i] >> b[i];


  vector<pair<ll, ll>> v;
  rep(i, n) v.push_back({b[i], a[i]});

  sort(all(v));

  ll t = 0;
  rep(i, n){
    t += v[i].second;
    if(t <= v[i].first) continue;
    cout << "No" << endl;
    return 0;
  }
  
  cout << "Yes" << endl;
  

  return 0;
}


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

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

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end());
    cout << accumulate(H.begin(), H.begin() + max(0LL, N - K), 0LL) << endl;
    return 0;
}


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

#define ll long long int
#define llu unsigned long long int
#define f(n) for(ll i=0;i<n;i++)
#define fr(n) for(ll i=n-1;i>=0;i--)
#define endl "\n"
#define mod 1000000007

using namespace std;

int main()
{
	//#ifdef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	std::ios_base::sync_with_stdio(false);

	string s,t,u;
	ll a,b;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(u==s)
	{
		cout<<a-1<<" "<<b;
	}
	else
	{
		cout<<a<<" "<<b-1;
	}
	
	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD


ll ans= 0;
int x, y;

const ll COMBMAX = 1000010;
ll fact[COMBMAX];
ll inv[COMBMAX];
ll finv[COMBMAX];

void combinit(){
    fact[0]=finv[0]=1;
    inv[1]=1;
    for(int i=2;i<COMBMAX;i++){
        inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
    }
    for(int i=1;i<COMBMAX;i++){
        fact[i]=fact[i-1]*i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll comb(int a,int b){
    if(a<b||b<0)return 0;
    return fact[a]*finv[b]%MOD*finv[a-b]%MOD;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>x>>y;
    combinit();
    //n= count(1,2)  m=count(2,1) 
    int n,m;

    //n+2m=x, 2n+m=y
    //y=2(x-2m)+m
    //y=2x-3m
    //m = (2x-y)/3
    if((x+y)%3 != 0){
        cout<<"0"<<endl;
        return 0;
    }
    m = (x*2-y) / 3;
    n = x - m*2;

    ans = comb(m+n, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23680
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]

c=[[0]*3 for _ in range(3)]
for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j]==b:
        c[i][j]=1

for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:
    print('Yes')
    exit()
  if c[0][i] and c[1][i] and c[2][i]:
    print('Yes')
    exit()
    
    
if c[0][0] and c[1][1] and c[2][2]:
  print('Yes')
  exit()
if c[0][2] and c[1][1] and c[2][0]:
  print('Yes')
  exit()

print('No')

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

int next;
int S[1000];

void push(int x)
{
	S[next++] = x;
}

int pop()
{
	return S[--next];
}

// scanf関数はファイルの終了に達するとEOF(-1)を返す
int main()
{
	int next = 0;

	char s[1000];
	int a, b;
	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '+')
		{
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-')
		{
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*')
		{
			a = pop();
			b = pop();
			push(a * b);
		}
		else
		{
			push(atoi(s));
		}
	}
	printf("%d\n", pop());

	return 0;
}


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

int main() {
    long long n, a, b, ans = 0;
    cin >> n >> a >> b;
    ans += a * (n / (a + b));
    if (n % (a + b) <= a) ans += n % (a + b);
    else ans += a;
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    lp=[list(map(int, input().split())) for i in range(n)]
    lb=[list(map(int, input().split())) for i in range(m)]

    for x in range(n):
        kyorimin=4*10**8
        ans=m
        for y in range(m):
            kyori = abs(lp[x][0] - lb[y][0]) + abs(lp[x][1] - lb[y][1])
            if kyori<kyorimin:
                kyorimin=kyori
                ans=y+1
        print(ans)
resolve()

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
        int[] s = new int[n];
        int sum = 0;
        for (int i=0; i<n; i++) {
            s[i] = in.nextInt();
            sum += s[i];
        }
        Arrays.sort(s);
        if (sum%10 != 0) {
            out.println(sum);
        } else {
            for (int i=0; i<n; i++) {
                if (s[i] % 10 != 0) {
                    sum -= s[i];
                    break;
                }
            }
            if (sum % 10 == 0) {
                out.println(0);
            } else {
                out.println(sum);
            }
        }
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 21972
fn main(){
	let v = read_vec::<i32>();
	let a = v[0];
	let b = v[1];
	println!("{} {}", a * b, 2 * a + 2 * b);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5028
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << "[DBG] " << #X << "=" << (X) << '\n';
	#define SAY(X) cout << "[SAY] " << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }
const int MAXN = (int)1e5 + 7;
vector<int> g[MAXN];
int n, m, used[MAXN], color[MAXN];
int dfs(int v, int& flag) {
	used[v] = 1;
	int sz = 1;
	for(auto& u: g[v]) if(!used[u]) {
		color[u] = color[v] ^ 1;
		sz += dfs(u, flag);
	}
	for(auto& u: g[v]) if(color[v] == color[u]) {
		flag = 0;
		break;	
	}
	return sz;
}
void solve() {
	cin >> n >> m; for(int i = 0; i < m; ++i) {
		int v = fetch<int>() - 1;
		int u = fetch<int>() - 1;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	ll single = 0, good = 0, bad = 0;
	for(int v = 0; v < n; ++v) if(!used[v]) {
		int flag = 1;
		int sz = dfs(v, flag);
		if(sz == 1) ++single;
		if(sz > 1 && flag) ++good;
		if(sz > 1 && !flag) ++bad;
	}
	DBG(single); DBG(good); DBG(bad);
	ll answ = 2 * good * good + good * bad + bad * good + bad * bad + single * (n - single) + (n - single) * single + single * single;
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 12288
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

///////////////////////////
////Prime Creator//////////
///////////////////////////
//bool Prime[100001] = {};
//void createPrime() {
//	ll n = 100001;
//	rep(i, 0, n) Prime[i] = true;
//	Prime[0] = false;
//	Prime[1] = false;
//	rep(i, 2, n) {
//		if (Prime[i]) {
//			rep(j, 2, n) {
//				if (j*i >= n)break;
//				Prime[j*i] = false;
//			}
//		}
//	}
//}
///////////////////////////
///////////////////////////

//Minimum Value
static const ll MIN_LL = (ll)1 << 55;

////Warshall Floyid
////All value should be initialized by MIN_LL
//static const ll wf_size = 300;
//ll wf[wf_size][wf_size];
//void WarshalFloyid() {
//	rep(k, 0, wf_size)rep(i, 0, wf_size)rep(j, 0, wf_size)wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
//}

int main() {
	string s = {}; cin >> s;

	if (s.size() <= 2) {
		if (s[0] == s[1]) {
			cout << 1 << " " << 2 << endl;
			return 0;
		}
	}
	else {
		rep(i, 0, s.size() - 2) {
			if (s[i] == s[i + 1] || s[i + 1] == s[i + 2] || s[i] == s[i + 2]) {
				cout << i + 1 << " " << i + 3 << endl;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n,ans;
    ans = 0;
    string s;
    cin >> n >> s;
    REP(i,n){
	string ss;
	cin >> ss;
	for(int j=0;j<=ss.size();j++){
	    bool flg = true;
	    REP(k,ss.size()){
		flg = true;
		REP(l,s.size()){
		    if(k+l+j*l >= ss.size()) {
			flg = false;
			break;
		    }

		    if(s[l] != ss[k+l+j*l]){
			flg = false;
			break;
		    }
		}
		if(flg) break;
	    }
	    if(flg){
		ans++;
		break;
	    }
	}
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1208
from heapq import *

def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    lower_heap = []
    higher_heap = []
    median = constant = sum_lower = sum_higher = 0
    for _ in range(read_int()):
        ar = read_int_array()
        if len(ar) == 3:
            constant += ar[2]
            x = ar[1]
            if not lower_heap:
                lower_heap.append(-x)
                sum_lower += x
                median = x
            elif not higher_heap:
                heappush(lower_heap, -x)
                sum_lower += x

                x = -heappop(lower_heap)
                sum_lower -= x
                heappush(higher_heap, x)
                sum_higher += x
                median = -lower_heap[0]
            elif x <= -lower_heap[0]:
                heappush(lower_heap, -x)
                sum_lower += x

                if len(lower_heap) - len(higher_heap) > 1:
                    x = -heappop(lower_heap)
                    sum_lower -= x
                    heappush(higher_heap, x)
                    sum_higher += x
                median = -lower_heap[0]
            else:
                heappush(higher_heap, x)
                sum_higher += x
                if len(higher_heap) > len(lower_heap):
                    x = heappop(higher_heap)
                    sum_higher -= x
                    heappush(lower_heap, -x)
                    sum_lower += x
                median = -lower_heap[0]
        else:
            write(median, constant + abs(sum_lower - median * len(lower_heap)) + abs(sum_higher - median * len(higher_heap)))
main()


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

int main() {
    int n, m, x, y;
    cin >> n >> m;
    vector<int> num(n, 1);
    int red[n] = {0};
    red[0] = 1;
    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        x--, y--;
        if(red[x] == 1) {
            num[x]--;
            num[y]++;
            red[y] = 1;
            if(num[x] == 0) {
                red[x] = 0;  
            }
        } else {
            num[x]--;
            num[y]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += red[i]; 
    }

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


Measured memory_bytes: 1024
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll a,b;
  std::cin>>a>>b;

  if(a<b){
    rep(i,0,b)std::cout<<a;
    std::cout<<"\n";
  }else if(a>=b){
    rep(i,0,a)std::cout<<b;
    std::cout<<"\n";
  }

  return 0;
}

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 5000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

long com2(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * mpow(y, MOD - 2) % MOD;
}

long inv(long a) {
  long b = MOD, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  init();
  int K;
  string S;
  cin >> K >> S;
  int N = S.size();
  K += N;
  long ans = 0;
  for (int i = N; i <= K; i++) {
    long tmp = com(i - 1, N - 1);
    tmp *= mpow(25, i - N);
    tmp %= MOD;
    tmp *= mpow(26, K - i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 121444
#include<set>
#include<map>
#include<cmath>
#include<deque>
#include<stack>
#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<ctime>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
using namespace std;
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 300000
#define INF 0x3f3f3f3f
#define Mod 998244353
void Add(int &x,int &y){if(x)x--,y++;return ;}
int cnt[10];
char S[MAXN+5];
int main(){
	int n=read();
	scanf("%s",S+1);
	LL ans=1;
	for(int i=1;i<=3*n;i++){
		int opt=(S[i]=='R'?1:S[i]=='G'?2:3);
		if(cnt[7-opt]) ans=ans*cnt[7-opt]%Mod,cnt[7-opt]--;//a b c ab ac bc
		else if(opt==1&&(cnt[2]+cnt[3])) ans=ans*(cnt[2]+cnt[3])%Mod,Add(cnt[2],cnt[4]),Add(cnt[3],cnt[5]);
		else if(opt==2&&(cnt[1]+cnt[3])) ans=ans*(cnt[1]+cnt[3])%Mod,Add(cnt[1],cnt[4]),Add(cnt[3],cnt[6]);
		else if(opt==3&&(cnt[1]+cnt[2])) ans=ans*(cnt[1]+cnt[2])%Mod,Add(cnt[1],cnt[5]),Add(cnt[2],cnt[6]);
		else cnt[opt]++;
	}
	for(int i=1;i<=n;i++)
		ans=ans*i%Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
int main () {
  
  int N ;
  cin >> N ;
  ll a[N],b[N] ,tot = 0;
  for(int i = 0 ; i < N + 1 ;i++){
    cin >> a[i] ;
    tot+=a[i];
  }
  for(int i = 0 ; i < N ;i++)
    cin >> b[i] ;
  for(int i = 0; i < N ; i++)
  {
    ll t = min(a[i],b[i]) ;
    a[i]-=t;b[i]-=t ;
    t = min(b[i],a[i+1]);
     a[i+1]-=t;b[i]-=t ;
  }
  ll sum =0 ;
  for(int i=0 ; i < N + 1;i++)
    sum+=a[i];
  cout<<tot-sum<<endl;
    
 
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N,Q;
	cin>>N>>Q;
	string S;
	cin>>S;
	vi l(Q),r(Q);
	rep(i,0,Q){
		cin>>l[i]>>r[i];
		l[i]--;r[i]--;
	}
	vi total(N);
	if(S[0]=='A' && S[1]=='C') total[0]=1;
	rep(i,1,N){
		if(S[i-1]=='A' && S[i]=='C'){
			total[i]=total[i-1]+1;
		}
		else{
			total[i]=total[i-1];
		}
	}

	rep(i,0,Q){
		cout<<total[r[i]]-total[l[i]]<<endl;
	}
	return 0;
}


Measured memory_bytes: 2256
N = int(input())
flag = True
t_0,x_0,y_0 = 0,0,0

for i in range(N):
    t_1,x_1,y_1 = map(int,(input().split()))
    dt = t_1 - t_0
    dx = abs(x_1 - x_0)
    dy = abs(y_1 - y_0)
    if dx+dy<=dt and (dx+dy+dt)%2==0:
        t_0,x_0,y_0 = t_1,x_1,y_1
    else:
        flag = False
        break

print("Yes") if flag else print("No")

Measured memory_bytes: 46056
#include <stdio.h>
#include <ctype.h>
int main(){
	
	char m[1201]={'0'},b[27]={ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
                     'u', 'v', 'w', 'x', 'y', 'z' };
	int i,a[27]={0};
	
	i=0;
	/*while (scanf("%c", &m[i++]) != EOF){
	}
	*/
	for(i=0;scanf("%c",&m[i])!=EOF;i++){
	}
	
	for(int t=0;t<i;t++){
		if(isupper(m[t])){
			m[t]=tolower(m[t]);
		}
	}
	//printf("%s",m);
	for(int t=0;t<i;t++){
		if(m[t]>='a'&&m[t]<='z'){
			a[m[t]-'a']++;
		}
	}
	for(int t=0;t<26;t++){
		printf("%c : %d\n",b[t],a[t]);
	}
	return 0;
}

Measured memory_bytes: 2720
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vint a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(all(a),greater<int>());
  cout<<a[0]*10+a[1]+a[2];
  return(0);
}


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



int main(void){
    int N;
    cin>>N;
    vector<string> W(N);
    for(int i=0;i<N;i++){
        cin>>W[i];
    }
    map<string,int> dict;
    for(int i=0;i<N;i++){
        dict[W[i]]++;
    }
    bool flag=true;
    for(int i=0;i<N;i++){
        if(dict[W[i]]>1){
            flag=false;
            break;
        }
    }
    for(int i=0;i<N-1;i++){
        if(W[i][W[i].size()-1]!=W[i+1][0]){
            flag=false;
            break;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,j;
  int n,k;
  scanf("%d %d",&n,&k);
  
  int p[n];
  for(i=0;i<n;i++) scanf("%d",&p[i]);

  int buf;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(p[i]>p[j]){
        buf=p[i];
        p[i]=p[j];
        p[j]=buf;
      }
    }
  }
  
  int ans=0;
  
  for(i=0;i<k;i++) ans+=p[i];
  
  printf("%d\n",ans);
  
  return 0;
}

  

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll k,x;
   cin>>k>>x;
   x-=k*500;
   if(x <= 0)
        cout<<"Yes";
   else cout<<"No";        
   
   return 0;        
}  
   

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 764
import sys
from string import digits
MOD = 10 ** 9 + 7

def main():
    n, *a = map(int, sys.stdin.read().split())

    res = 1
    rgb = [0, 0, 0]
    for i in range(n):
        cur = a[i]
        res = res * rgb.count(cur) % MOD
        if rgb[0] == cur:
            rgb[0] += 1
        elif rgb[1] == cur:
            rgb[1] += 1
        elif rgb[2] == cur:
            rgb[2] += 1
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14884
from collections import*
n,m=map(int,input().split())
outs=defaultdict(list)
ins=defaultdict(int)
for _ in range(m):
    a,b=map(int,input().split())
    outs[a-1]+=b-1,
    ins[b-1]+=1
q=deque(i for i in range(n)if ins[i]==0)
res=[]
while q:
    v=q.popleft()
    res+=v,
    for w in outs[v]:
        ins[w]-=1
        if ins[w]==0:
            q.append(w)
print(-(len(res)==n))

Measured memory_bytes: 45400
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmp(pair<lli, lli> left, pair<lli, lli> right) {
	if (left.first != right.first)return left.first < right.first;
	else return left.second < right.second;
}

int main() {
	lli n, e=0, w=0;
	string s;
	cin >> n >> s;
	rep0(i, n) {
		if (s[i] == 'E')e++;
		else w++;
	}
	lli we = 0, ww = 0;
	vector<lli>vec(n);
	rep0(i, n) {
		vec[i] = ww + e - we;
		if (s[i] == 'E') {
			we++;
			vec[i]--;
		}
		else ww++;
	}
	sort(all(vec));
	cout << vec[0];

}


Measured memory_bytes: 2948
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	n--;
	cout << (n * (n + 1)) / 2 << endl;
}


Measured memory_bytes: 384
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int R, N;
    while(cin >> R >> N, R) {
        int x[50] = {};
        int *a = x + 25;

        rep(i,0,N) {
            int xl, xr, h; cin >> xl >> xr >> h;
            repq(k,xl+1,xr) chmax(a[k], h);
        }

        double ans = INF;
        repq(k,-R+1, R) {
            int x = min(abs(k-1), abs(k));
            double val = a[k] + R - sqrt(R*R - x*x);
            chmin(ans, val);
        }
        printf("%.12f\n", ans);
    }
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   vector<int>t(n);
   int sum=0;
    for (int i = 0; i < n; ++i) {
        cin >>t[i];
        sum+=t[i];
    }
    int m;cin >>m;
    int d=0;
    for (int i = 0; i < m; ++i) {
        int p,x;cin >>p>>x;
        p--;
        d=t[p]-x;
        cout <<sum-d<<endl;
    }
}


Measured memory_bytes: 3652
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int t=sc.nextInt();
    HashMap<String,Integer> map=new HashMap<String,Integer>();
    LinkedList<String> s1=new LinkedList<String>();
    map.put("AC",0);
    s1.add("AC");
    
    map.put("WA",0);
     s1.add("WA");
     map.put("TLE",0);
     s1.add("TLE");
     map.put("RE",0);
     s1.add("RE");
	for(int i=0;i<t;i++)
    {
      String s=sc.next();
      

        map.put(s,map.get(s)+1);
     
    }
    for(int k=0;k<map.size();k++)
    {
      System.out.println(s1.get(k)+" x "+map.get(s1.get(k)));
    }
  }
}

Measured memory_bytes: 58676
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();
        if (k % 2 == 0) {
            System.out.println(a - b);
            return;
        }
        System.out.println(b - a);
    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
 
int main(){
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<'1'<<endl;
	}
	if(n>1&&n<4)
	{
		cout<<'2'<<endl;
	}
	if(n>=4&&n<8)
	{
		cout<<'4'<<endl;
	}
	if(n>=8&&n<16)
	{
		cout<<'8'<<endl;
	}
	if(n>=16&&n<32)
	{
		cout<<"16"<<endl;
	}
	if(n>=32&&n<64)
	{
		cout<<"32"<<endl;
	}
	if(n>=64&&n<=100)
	{
		cout<<"64"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){
    int n, k, d, a, cnt=0;
    int x[100+1]={0};
    scanf("%d %d", &n, &k);

    for(int i=0; i<k; i++){
        scanf("%d", &d);
        for(int j=0; j<d; j++){
            scanf("%d", &a);
            x[a-1]++;
        }
    }

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

Measured memory_bytes: 1732
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int x = Integer.parseInt(br.readLine());
            int i = 0;
            while (i < x) {
                String str = br.readLine();
                String[] num = str.split(" ", 0);
                ArrayList<Integer> al = new ArrayList<>();
                for (int j = 0; j < 3; j++) {
                    al.add(Integer.parseInt(num[j]));
                }
                Collections.sort(al);
                int a = al.get(0);
                int b = al.get(1);
                int c = al.get(2);
                if(c*c==a*a+b*b){
                    System.out.println("YES");
                }else{
                    System.out.println("NO");
                }
                i++;
            }
        } catch (IOException ex) {
            System.out.println("error");
        }
    }
}

Measured memory_bytes: 26044
import itertools
N=int(input())
nameM=0
nameA=0
nameR=0
nameC=0
nameH=0
for a in range(N):
    S=input()
    ss=[]
    for b in S:
        ss.append(b)
        if ss[0]=='M':
            nameM+=1
            break
        elif ss[0]=='A':
            nameA+=1
            break
        elif ss[0]=='R':
            nameR+=1
            break
        elif ss[0]=='C':
            nameC+=1
            break
        elif ss[0]=='H':
            nameH+=1
            break
        else:
            break
list=[nameM,nameA,nameR,nameC,nameH]
answers=[a for a in list if a!=0]
b=1
if len(answers)<=2:
    print(0)
elif len(answers)==3:
    for a in answers:
        b*=a
    print(b)
elif len(answers)>=4:
    answer=0
    for x in itertools.combinations(answers,3):
        c=1
        for y in x:
            c*=y
        answer+=c
    print(answer)
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
char field[1001][1001];
int dp[1001][1001] = { 0 };

int main() {
	int n;

	while (cin >> n, n) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cin >> field[i][j];
				if (field[i][j] == '*') dp[i][j] = 0;
			}
		}

		for (int i = 0; i < n; ++i) {
			if (field[0][i] == '.') dp[0][i] = 1;
		}

		for (int i = 0; i < n; ++i) {
			if (field[i][0] == '.') dp[i][0] = 1;
		}

		int min, msquare = 0;
		for (int i = 1; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (field[i][j] == '*') continue;
				min = dp[i - 1][j - 1];
				if (dp[i][j - 1] < min) min = dp[i][j - 1];
				if (dp[i - 1][j] < min) min = dp[i - 1][j];
				dp[i][j] = min + 1;
				if (dp[i][j] > msquare) msquare = dp[i][j];
			}
		}
		cout << msquare << endl;
		
	}

	return 0;
}

Measured memory_bytes: 6052
#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //ハッシュ関数
#include <fstream> //ifstream, ofstream


using namespace std;

//デバッグ時はTESTを定義する。本番時はこの行をコメントアウトする
#define TEST //*******************************************************************************************************************************************
//そうすることで、以下に定義する、デバッグ時にのみ標準出力する、doutコマンドが実現できる。本番時はダミーストリームに出力
//ただダミーストリームに出力する処理も結構CPU時間食うようなので、TLEを引き起こす原因になる可能性には注意
#ifdef TEST
#define dout cout
#else
stringstream dummy; //デバッグ時のdoutコマンドのダミー出力先
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummyを毎回リセットしておかないとメモリ溢れちゃう。
//どうせ表示しないからgoodbitしなくていいけど、表示する場合はこれしておかないとバグるらしいので、勉強のために。詳しくは http://d.hatena.ne.jp/linden/20060427/p1
#endif

//標準出力先をテキストファイルにしたい場合はOUTPUT2TEXTFILEを定義する。本番時はこの行をコメントアウトする
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //というのはTLE問題でどうせdoutを全部コメントアウトしなくちゃいけなくなるので上記方式は却下して、代わりに出力先を標準出力からファイルに切り替えできるようにする
//TESTが定義されていると、outputfileに出力するようになる
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif



#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl


int main(){
 
    int N;
    cin >> N;
    
    int K;
    cin >> K;
    
    int x[N];
    rep(i,0,N) cin >> x[i];
    
    int sum = 0;
    rep(i,0,N) {
        sum += min( x[i], K-x[i] );
    }
    
    cout << 2*sum << endl;
    
    
    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



int main()
{
	int n;
	ll c;
	cin >> n >> c;
	vector<pair<ll, ll>> sushi(n+1);
	sushi[0] = make_pair(0, 0);
	for (int i = 1; i <=n; i++) {
		ll x, v;
		cin >> x >> v;
		sushi[i] = make_pair(x, v);
	}

	sushi.emplace_back(make_pair(c, 0));

	ll sum_cal = 0;
	vector<ll> mc_r(n+1);
	

	for (int i = 1; i <= n; i++) {
		sum_cal += sushi[i].second - abs(sushi[i].first - sushi[i - 1].first);
		mc_r[i] = max(mc_r[i - 1], sum_cal);
		//cout << mc_r[i] << endl;
	}

	sum_cal = 0;
	ll maxCal_l= mc_r[n];

	for (int i = n; i > 0; i--) {
		sum_cal += sushi[i].second - 2*abs(sushi[i].first - sushi[i + 1].first);
		if (maxCal_l < sum_cal+ mc_r[i-1]) {
			maxCal_l = sum_cal + mc_r[i-1];
			//cout << maxCal_l << endl;
			
		}
	}




	sum_cal = 0;
	vector<ll> mc_l(n + 2);
	

	for (int i = n; i >0; i--) {
		sum_cal += sushi[i].second - abs(sushi[i].first - sushi[i + 1].first);
		mc_l[i] = max(mc_l[i + 1], sum_cal);
		//cout << mc_l[i] << endl;
	}

	sum_cal = 0;
	ll maxCal_r = mc_l[1];
	
	for (int i = 1; i <= n; i++) {
		sum_cal += sushi[i].second - 2 * abs(sushi[i].first - sushi[i - 1].first);
		if (maxCal_r < sum_cal + mc_l[i+1]) {
			maxCal_r = sum_cal + mc_l[i+1];
			//cout << maxCal_r << endl;
		}
	}


	cout << max(maxCal_r, maxCal_l) << endl;

	
}  



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    string S;
    cin >> S;
    char pre;
    int bc = 0;
    int ans = 0;
    rep(i, S.size()) {
        if (i == 0) {
            pre = S[0];
            if (S[0] == 'B')bc++;
            continue;
        }
        if (S[i] == 'B') {
            bc++;
        } else {
            ans += bc;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	int a,b ;
	cin >> a >> b;
	if(a*b % 2 == 0) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 3616
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

def f(n, a, b, c):
    if n == N:
        if a == 0 or b == 0 or c == 0:
            return 1000000
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    x = f(n + 1, a, b, c)
    y = f(n + 1, a + l[n], b, c) + 10
    z = f(n + 1, a, b + l[n], c) + 10
    w = f(n + 1, a, b, c + l[n]) +10
    return min(x, y, z, w)

print(f(0, 0, 0, 0))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
bool used[SIZE];
LL times[SIZE];
LL solve(){
	cin >> N >> M;
	LL ac=0,ans=0;
	REP(i,M){
		string s;
		int x;
		cin >> x >> s; 
		if(used[x]) continue;
		if(s=="WA") times[x]++;
		else{
			used[x]=true;	
			ans+=times[x];
			ac++;
		} 
	
	}
	cout << ac << " " << ans << endl;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;

	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)
    {
       cout<<"delicious"<<NL;
    }
    else if(b-a<=x)
    {
        cout<<"safe"<<NL;
    }
    else
    {
        cout<<"dangerous"<<NL;
    }
    return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] cost = new int[n + 1][3], dp = new int[n + 1][3];

        for (int i = 1; i <= n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());

            for (int j = 0; j < 3; j++)
                cost[i][j] = Integer.parseInt(st.nextToken());
        }

        for (int i = 1; i <= n; i++) {
            dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + cost[i][0];
            dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + cost[i][1];
            dp[i][2] = Math.max(dp[i - 1][1], dp[i - 1][0]) + cost[i][2];
        }

        System.out.println(Math.max(Math.max(dp[n][0], dp[n][1]), dp[n][2]));
    }
}


Measured memory_bytes: 51364
#include <iostream>
using namespace std;
typedef long long int lli;
int main(){
    lli k,a,b;
    cin >> k >> a >> b;
    if(a >= k){
        cout << 1 << endl;
    }else if(a-b <= 0){
        cout << -1 << endl;
    }else{
        cout << (k-b-1)/(a-b)*2 +1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define px(x) cout << x << endl
#define pfi(x) printf("%d\n", x)
#define pfs(x) printf("%s\n", x)
#define sfi(x) scanf("%d", &x)
#define sfs(x) scanf("%s", x)


int main() {
    unordered_map<int, int> mp;
    int n;
    cin >> n;

    int val;
    for(int i=0; i<n; i++){
        cin >> val;
        mp[val] += 1;
    }

    bool flag = false;
    for(auto v : mp){
        if(v.second > 1){
            flag = true;
            break;
        }
    }

    if(!flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



	return 0;
}

Measured memory_bytes: 8520