akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define F first
#define S second
#define en "\n"
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;



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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

Matrix mIdentity(ll n) {
	Matrix A(n, Array(n));
	for (int i = 0; i < n; ++i) A[i][i] = 1;
	return A;
}

Matrix mMul(const Matrix& A, const Matrix& B, ll mod) {
	Matrix C(A.size(), Array(B[0].size()));
	for (int i = 0; i < C.size(); ++i)
		for (int j = 0; j < C[i].size(); ++j)
			for (int k = 0; k < A[i].size(); ++k)
				(C[i][j] += (A[i][k] % mod) * (B[k][j] % mod)) %= mod;
	return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix& A, ll e, ll mod) {
	return e == 0 ? mIdentity(A.size()) :
		e % 2 == 0 ? mPow(mMul(A, A, mod), e / 2, mod) : mMul(A, mPow(A, e - 1, mod), mod);
}


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

	ll l, a, b, m;
	cin >> l >> a >> b >> m;

	ll max_d = 18;
	Array con(max_d + 1);
	ll d = 9;
	rep(i,1,max_d+1) {
		if (d >= a) {
			con[i] = (d - a) / b + 1;//a+b*i<=dとなる最大のi
			if (con[i] >= l) {
				con[i] = l;
				break;
			}
		}
		d = d * 10 + 9;
	}

	Array cd(max_d + 1);
	rep(i, 1, max_d + 1) cd[i] = con[i] - con[i - 1];

	Matrix f = mIdentity(3);//(X,s,1)->(X',s',1)
	Matrix g = mIdentity(3);
	g[0][1] = 1;
	g[1][2] = b%m;
	
	rep(i, 1, max_d + 1) {
		(g[0][0] *= 10) %= m;
		f = mMul(mPow(g, cd[i], m), f, m);
		if (con[i] == l) break;
	}
	
	Matrix x(3);
	x[0].push_back(0);
	x[1].push_back(a%m);
	x[2].push_back(1);

	Matrix ans = mMul(f, x, m);
	cout << ans[0][0] << endl;

	return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a, b;
	cin >>a >>b;
	if(a>9 || b>9){ puts("-1"); return 0;}
	cout << a*b <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< pii > A(N);
	rep(i, N) cin >> A[i].first >> A[i].second;
	sort(A.begin(), A.end());
	vector< int > y(N);
	rep(i, N) y[i] = A[i].second;
	sort(y.begin(), y.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	M = y.size();
	int ans = LINF;
	for (int i = 0; i < M - 1; i++)
		for (int j = i + 1; j < M; j++) {
			int y1 = y[i], y2 = y[j];
			vector< int > xs;
			rep(i, N) if (y1 <= A[i].second && A[i].second <= y2) xs.push_back(A[i].first);
			int J = xs.size();
			queue< int > q;
			rep(k, J) {
				q.push(xs[k]);
				if (q.size() >= K) {
					chmin(ans, (y2 - y1) * (xs[k] - q.front()));
					q.pop();
				}
			}
		}
	cout << ans << endl;
	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

ll n, m, l, q;
VVL d;
constexpr ll INF = 1e15;

void warshall(VVL &d){
    rep(i, 0, n){
        rep(j, 0, n){
            rep(k, 0, n){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

int main(){

    // input
    cin >> n >> m >> l;
    d.resize(n, VL(n, INF));
    rep(i, 0, n) d[i][i] = 0;
    rep(i, 0, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    
    // warshall 1
    warshall(d);

    // warshall 2
    VVL ans(n, VL(n, INF));
    rep(i, 0, n) rep(j, 0, n) {
        if(i == j) ans[i][j] = 0;
        else if(d[i][j] <= l) ans[i][j] = 1;
    }
    warshall(ans);

    // query
    cin >> q;
    rep(i, 0, q){
        ll s, t;
        cin >> s >> t;
        s--; t--;
        cout << (ans[s][t] >= INF ? -1 : ans[s][t]-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 5076
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;

const int mxn = 100005;
int n, h[mxn], ff[mxn];

int main()
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++)
  {
    scanf("%d", h + i);
  } 
  h[n + 1] = 0;
  ff[n] = 0, ff[n + 1] = 1e6; 
  for(int i = n - 1; i >= 1; i--)
  {
    ff[i] = min(abs(h[i + 1] - h[i]) + ff[i + 1], abs(h[i + 2] - h[i]) + ff[i + 2]);
  }
  printf("%d\n", ff[1]);
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e5+111;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n;
        ll ans=0;
        for(i=1;i<=n;i++){
                ans+=(i*(i+1))/2;
        }
        
        for(i=1;i<n;i++){
                cin>>x>>y;
                
                if(x<y)swap(x,y);
                
                ans-= y*(n+1-x);
        }
        cout<<ans<<endl;
        
        
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
if(a>8||b>8){
    cout<<":("<<endl;
}
else{
    cout<<"Yay!"<<endl;
}

//system("pause");
return 0;
}

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

using namespace std;

int main(){
    int N,mini=0;
    double T,A,mi=1e8;
    cin>>N>>T>>A;

    vector<double> h(N);
    for(int i=0;i<N;i++){
        int tmp;
        cin>>tmp;
        h[i] = abs(A-(T - tmp * 0.006));
        if(mi>h[i]){
            mi = h[i];
            mini = i+1;
        }
    }
    cout<<mini;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

int a[100001];

bool check (int n, int c, int k, int mid) {
	ll tmp = mid, cnt = 0, last = -1;
	for (int i = 0; i < n; i++) {
		if (a[i] > last or cnt == 0) {
			last = a[i] + k;
			tmp --;
			cnt = c - 1;
		}
		else {
			cnt --;
		}
	}
	return (tmp >= 0);
}

int main() {
	ios_base::sync_with_stdio (false);
	int n, c, k;
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort (a, a + n);
	int lo = 0, hi = n;
	while (hi - lo > 1) {
		int mid = (hi + lo) >> 1;
		if (check(n, c, k, mid))
			hi = mid;
		else
			lo = mid;
	}
	cout << hi << endl;
}


Measured memory_bytes: 640
s = list(input()) #sys.stdin.readlineは最後が改行
k = int(input())

now = 0

while k>0 and now<len(s):
    if s[now]=='a':
        now+=1
        continue
    tmp = ord('z')-ord(s[now])+1
    if tmp<=k:
        s[now] = 'a'
        k -= tmp
        now+=1
    else:
        now+=1

if k>0:
    s[-1] = chr(ord(s[-1])+k%26 )

print(*s,sep='')


Measured memory_bytes: 6968
N,M = map(int,input().split())

# 約数列挙
def enum_div(N):
    ret = []
    i = 1
    while True:
        if i**2 > N:
            break
        if N % i == 0:
            ret.append(i)
            if i**2 != N:
                ret.append(N / i)
        i += 1
    return ret

ans = 0
for i in enum_div(M):
    if i >= N:
        ans = max(ans,M / i)

print(int(ans))

Measured memory_bytes: 9056
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S/3600;
        int m = (S-h*3600)/60;
        int s = S-h*3600 - m*60;
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26192
n,K = map(int,input().split())

x,y = [],[]
xx,yy = [],[]

for i in range(n):
    X,Y = map(int,input().split())

    x.append(X)
    xx.append(X)
    y.append(Y)
    yy.append(Y)



xx.sort()
yy.sort()
ans = 10**20

for i in range(n):
    for j in range(i):
        lx,rx = xx[j],xx[i]

        num = [0 for _ in range(n+1)]

        for k in range(n):
            if lx <= x[k] <= rx:
                num[yy.index(y[k])+1] += 1

        for k in range(n):
            num[k+1] += num[k]


        for k in range(n):
            for l in range(k):
                by,ty = yy[l],yy[k]

                if num[k+1] - num[l] >= K:
                    ans = min(ans,(rx-lx)*(ty-by))



print(ans)

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

int main() { 
  int n;
  cin >> n;
  int i = n / 111;
  if(n % 111 != 0) i++;
  cout << i*111 << endl;
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define REP(i,n) for (int i = 0; i <(n); ++i)
  #define ALL(v) v.begin(), v.end()
  using namespace std;
  using ll = long long;
  using P = pair<int,int>;
  static const double PI = acos(-1);



  int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    REP(i,n){
      int x;
      cin >> x;
      a[i] = 100000000/x;
    }

    double sum = 0;
    REP(i,n) sum += a[i];

    double ans = 100000000/sum;
    //ans *= 1000;

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
  }

Measured memory_bytes: 3748
import java.util.*;

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

        List<Integer> array = new ArrayList<Integer>();
        for (int i=0; i<3; i++){
        	array.add(Integer.parseInt(sc.next()));
        }
        Collections.sort(array);

        if (array.get(0) + array.get(1) == array.get(2)){
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 21332
program main
    implicit none
    INTEGER :: i, n, ans = 1e9, ans1 = 0
    INTEGER, ALLOCATABLE :: a(:)
    read(*, *) n
    ALLOCATE(a(n))
    READ(*, *) (a(i), i = 1, n)
    do i = 1, n
        do while(mod(a(i), 2) == 0)
            ans1 = ans1 + 1
            a(i) = a(i) / 2
        enddo
        ans = min(ans, ans1)
        ans1 = 0
    enddo
    write(*, *) ans
end program main

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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

// SOLUTION

int main () {
	CPPIO;
	int n;
    cin >> n;
    int arr[n], br[n];
    for (int i = 0; i < n; i++) cin >> arr[i], br[i] = arr[i];
    sort (br, br + n);
    for (int i = 0; i < n; i++) {
        int x = lower_bound (br, br + n, arr[i]) - br;
        if (x < (n / 2)) cout << br[n / 2] << "\n";
        else cout << br[(n / 2) - 1] << "\n";
    }
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int a[30][100010];
int main() {
    int N,C;
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        s--;
        a[c][s]++;
        a[c][t]--;
    }
    
    for (int i = 0; i < C; i++) {
        for (int j = 1; j <= 100000; j++) {
            a[i][j] += a[i][j - 1];
        }
    }

    int res = 0;
    for (int j = 0; j <= 100000; j++) {
        int sum = 0;
        for (int i = 0; i < C; i++) {
            if (a[i][j] > 1) a[i][j] = 1;
            sum += a[i][j];
        }
        res = max(res, sum);
    }
    
    cout << res << endl;
    
}

Measured memory_bytes: 11904
#include <stdio.h>
#include <string.h>
int main(void) {
	int a, b;
	char op[5];

	do{
		scanf("%d %s %d", &a, op, &b);
		if (strcmp(op, "+") == 0){
			printf("%d\n", a + b);
		}
		else if (strcmp(op, "-") == 0){
			printf("%d\n", a - b);
		}
		else if (strcmp(op, "*") == 0){
			printf("%d\n", a * b);
		}
		else if (strcmp(op, "/") == 0){
			printf("%d\n", a / b);
		}
	} while (strcmp(op, "?") != 0);

	return 0;
}

Measured memory_bytes: 600
def combination_mod(n,r,MOD=10**9+7):
    n_=1
    for i in range(1,n+1):
        n_=(n_*i)%MOD
    r_=1
    for i in range(1,r+1):
        r_=(r_*i)%MOD
    nr_=1
    for i in range(1,n-r+1):
        nr_=(nr_*i)%MOD

    power_r=pow(r_,MOD-2,MOD)
    power_nr=pow(nr_,MOD-2,MOD)

    return (n_*power_r*power_nr)%MOD


def main():
    N,M,K=map(int,input().split())

    MOD=10**9+7
    num=combination_mod(N*M-2,K-2)

    col_ans=0
    row_ans=0

    for i in range(1,M):
        col_ans+=pow(N,2)*(M-i)*num*i

    for i in range(1,N):
        row_ans+=pow(M,2)*(N-i)*num*i

    ans=(col_ans+row_ans)%MOD

    print(ans)

if __name__=="__main__":
    main()



Measured memory_bytes: 9256
import Data.List (sortBy, groupBy)
import Control.Monad (forM_)

readTestcase :: IO [(String, Int)]
readTestcase = do
    nStr <- getLine
    readData (read nStr :: Int) []

readData :: Int -> [(String, Int)] -> IO [(String, Int)]
readData 0 res = do return res
readData n res = do
    line <- getLine
    let [id, numStr] = words line
    let num = read numStr :: Int
    readData (n - 1) ((id, num) : res)

-- False < True
compare' :: (String, Int) -> (String, Int) -> Ordering
compare' (a, _) (b, _)
    | (length a) /= (length b) = compare (length a) (length b)
    | otherwise = compare a b

sort' :: [(String, Int)] -> [(String, Int)]
sort' = sortBy compare'

equalFirst :: (String, Int) -> (String, Int) -> Bool
equalFirst x y = (fst x) == (fst y)

groupBy' :: [(String, Int)] -> [[(String, Int)]]
groupBy' = groupBy equalFirst

sum' :: [(String, Int)] -> (String, Int)
sum' xs = (id, acc)
    where
        id = fst $ head xs
        acc = sum $ map snd xs

main = do
    dat <- readTestcase
    let res = (map sum' (groupBy' (sort' dat)))
    forM_ res (\ (id, num) -> putStrLn (id ++ " " ++ (show num)))



Measured memory_bytes: 12224
import heapq

n, m = [int(v) for v in input().split()]
ab_ = [[int(v) for v in input().split()] for _ in range(n)]

ab = sorted(ab_, key=lambda x: (x[0], x[1])) 
#print(ab)
ans = 0

h = []
idx = 0
for i in range(m + 1):
  while idx < len(ab):
    if ab[idx][0] == i:
      heapq.heappush(h, -ab[idx][1])
      idx += 1
    else:
      break
  if len(h) > 0:
    #print(i, h)
    ans -= heapq.heappop(h)

print(ans)

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

int main() {
	int n, a;
	cin >> n >> a;
	if (n * n - a >= 0) cout << n * n - a << endl;
	else cout << 0 << endl;
	return 0;
}

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

int solve(int, int);

int n, *arryA;

main(){
  int i, q, m;

  scanf("%d", &n);
  arryA = (int *)malloc(sizeof(int)*n);
  for(i=0; i<n; i++) scanf("%d", arryA+i);

  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &m);
    if(solve(0, m)) printf("yes\n");
    else printf("no\n");
  }

  free(arryA);
  return 0;
}

int solve(int i, int m){
  int res;

  if(m==0) return 1;
  if(i>=n) return 0;

  res = solve(i+1, m) | solve(i+1, m - arryA[i]);
  return res;
}

Measured memory_bytes: 580
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn main() {
    input!(n:isize, k: usize, mut p: [isize; n]);
    p.sort();
    let mut ans = 0;
    for i in 0..k {
        ans += p[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2204
#include <stdio.h>

int main(void)
{
    int n, total = 0, max = 0, i, num;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf ("%d", &num);
        total += num;
        if (max < num) max = num;
    }
    printf ("%d", total - (max / 2));
    return (0);
}


Measured memory_bytes: 128
#include <cstdio>
#include <string.h>

using namespace std;

namespace {

const size_t kHashSize = 244140624;

class Dictionary {
 public:
  Dictionary() : table_(new int[kHashSize]) {
    ps_[0] = 1;
    for (int i = 1; i < 12; ++i) {
      ps_[i] = 5 * ps_[i - 1];
    }
  }

  ~Dictionary() { delete[] table_; }

  void insert(const char* k, size_t n) {
    const size_t i = Encode(k, n);
    table_[i] = 1;
  }

  bool find(const char* k, size_t n) const {
    return table_[Encode(k, n)] > 0;
  }

 private:
  static int Id(char c) {
      switch (c) {
        case 'A':
          return 1;
        case 'C':
          return 2;
        case 'G':
          return 3;
        case 'T':
          return 4;
      }
      // should not reach here.
      return 0;
  }

  size_t Encode(const char* k, size_t n) const {
    size_t h = 0;
    for (size_t i = 0; i < n; ++i) {
      h += ps_[i] * Id(k[i]);
    }
    return h;
  }

  size_t ps_[12];
  int* table_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s %s", op, str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 40420
from collections import deque

n, m = [0] * 2
a = []
b = []

def format_input(filename = None):
	global n, m
	global a, b
	if filename == None:
		n, m = list(map(int, input().split()))
		ab = [list(map(int, input().split())) for i in range(m)]
		for i in ab:
			a.append(i[0])
			b.append(i[1])

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 10**5)
		m = rng(1, 2 * 10**5)
		a = [rng(1, n) for i in range(m)]
		b = [rng(1, n) for i in range(m)]
		print(n, m)
		[print(a[i], b[i]) for i in range(m)]

def get_answer():
	answer = 'No'
	parent = [0] * (n+1)
	child = [[] for i in range(n+1)]
	for i in range(m):
		child[a[i]].append(b[i])
		child[b[i]].append(a[i])

	visited = [False] * (n+1)
	q = deque()
	q.append(1)
	visited[1] = True
	while len(q) > 0:
		node = q.popleft()
		for i in child[node]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				parent[i] = node

	if parent.count(0) == 2:
		answer = 'Yes'

	print(answer)
	if answer == 'Yes':
		for i in range(n-1):
			print(parent[i+2])
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()


Measured memory_bytes: 50260
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9)
    {
        cout<<"hon";
    }
    else if(n==0||n==1||n==6||n==8)
    {
        cout<<"pon";
    }
    else
    {
        cout<<"bon";
    }
}

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

using namespace std;

typedef long long int int64;

int main() {
	int64 n;
	cin >> n;
	int64 ans = 1e18;
	for(int64 i = 1; i*i <= n; i++) {
		if(n % i == 0) {
			ans = min(ans, (i - 1) + ((n / i) - 1));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String T = scan.next();
        if (T.startsWith(S) && S.length() + 1 == T.length()) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35656
import java.util.*;
import java.text.DecimalFormat;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), no = N, i = 0;
		double min = Double.MAX_VALUE, s = 0, t = 0;
		double[] a = new double[N];
		while (N-->0) {
			double b = sc.nextDouble();
			a[i++] = b; s+=b;
		}
		N = no;
		for (i=N-1; i>0; i--) {
			t+=a[i];
			min = Math.min(Math.abs(s-(2*t)), min);
		}
		System.out.println(new DecimalFormat("#").format(min));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

bool compare(pair<int, int> &a, pair<int, int> &b) {
	return a.second < b.second;
}
int main() {
	int n, M;
	cin >> n >> M;
	int i;
	vector<pair<int, int> > v;
	for (i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end(), compare);

	int end = v[0].second;
	int cnt = 1;
	for (i = 1; i < v.size(); i++) {
		if (v[i].first < end) {
			continue;
		} else {
			end = v[i].second;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long sum = 0;

		for(int i = 1; i <= N; i++) {

			if(i % 3 != 0 && i % 5 != 0) {
				sum = sum + i;
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 27176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);
  
  string S;
  cin >> S;
  if(S == "ABC"){
    cout << "ARC" << endl;
  }
  else{
    cout << "ABC" << endl;
  }

  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
int v[3][10];
int main(){
    FILE*fi,*fout;
    int i,j,k,x,y;
    //fi=fopen("A.in" ,"r");
   // fout=fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%d" ,&x,&y);
    v[0][0]=1;
    v[0][1]=3;
    v[0][2]=5;
    v[0][3]=7;
    v[0][4]=8;
    v[0][5]=10;
    v[0][6]=12;
    v[1][0]=4;
    v[1][1]=6;
    v[1][2]=9;
    v[1][3]=11;
    v[2][0]=2;
    for(i=0;i<3;i++){
       for(j=0;j<10;j++)
        for(k=0;k<10;k++)
          if(v[i][j]==x&&v[i][k]==y){
             fprintf(fout,"Yes\n");
             return 0;
          }
    }
    fprintf(fout,"No\n");
    //fclose(fi);
   // fclose(fout);
}


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

int main()
{
    int k;
    cin >> k;
    
    if(k%2 == 0){
        cout << pow(k/2,2) << endl;
    }
    else{
        cout << pow(k/2,2) + k/2 << endl;
    }
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());
    auto start = clock();


    vector<char> a(26);
    for (int i = 0; i < 26; ++i) {
        a[i] = i + 'A';
    }
    int n; cin >> n;
    string s; cin >> s;
    for (auto c : s) {
        cout << a[((c - 'A') + n) % 26];
    }


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b";
	}
	if(a>b){
		cout<<"a > b";
	}
	if(a==b){
		cout<<"a == b";
	}
	cout<<endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define lp(i, a, b) for (int i=a;i<=(int)b;++i)
#define lp2(i, a, b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define pr(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define clr(c, x) memset(c,x,sizeof(c));
template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int N = (int) 2e5 + 5;
const ll mod = 998244353;
priority_queue<ll> d;
priority_queue<ll, vl, greater<ll> > u;

int main() {
    FAST;
    int n;
    cin >> n;
    ll z = 0, us = 0, ds = 0;
    while (n--) {
        int x;
        cin >> x;
        if (x == 1) {
            ll a, b;
            cin >> a >> b;
            z += b;
            if (d.empty() || a < d.top()) {
                d.push(a);
                ds += a;
            } else {
                u.push(a);
                us += a;
            }
            while (d.size() > u.size() + 1) {
                u.push(d.top());
                us += d.top();
                ds -= d.top();
                d.pop();
            }
            while (d.size() < u.size()) {
                d.push(u.top());
                us -= u.top();
                ds += u.top();
                u.pop();
            }
        } else {
            cout << d.top() << " ";
            ll t = (ll) d.size() * d.top() - ds + us - (ll) u.size() * d.top() + z;
            cout << t << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <cmath>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<long int> H(N);
    vector<int> A(M);
    vector<int> B(M);
    rep(i,N)cin>>H.at(i);
    rep(i,M)cin>>A.at(i)>>B.at(i);
    vector<int> T(N,1);
    rep(i,M){
        if(H.at(A.at(i)-1)>H.at(B.at(i)-1)){
            T.at(B.at(i)-1)=0;
        }else if(H.at(A.at(i)-1)==H.at(B.at(i)-1)){
            T.at(A.at(i)-1)=0;
            T.at(B.at(i)-1)=0;
        }else{
            T.at(A.at(i)-1)=0;
        }
    }
    int count=0;
    rep(j,N){
        int ok=1;
        if(T.at(j)==0){
            ok=0;
        }
        if(ok==1){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 5032
#include<stdio.h>

int linearSearch(int S[], int T[],int n,int q){
   int i,j;
   int sum = 0;
  for(i = 0;i < q;i++){
    for(j = 0;j<n;j++){
      if(T[i] == S[j]){
	sum++;
	break;
      }
      
    }
  }
  return sum;
}



int main(){
  int i,n;
  int S[10001];
  int q,T[10001];
  int sum = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0;i<q;i++){
    scanf("%d",&T[i]);
  } 
   sum = linearSearch(S,T,n,q);
    
  printf("%d\n",sum);
    return 0;
  
}



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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadDirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge({v1, v2}));
  }
  return graph;
}

vector<double> Solve(const vector<vector<Edge>>& graph) {
  int n = graph.size();
  vector<double> dp(n, DBL_MAX);
  dp[n - 1] = 0.0;
  for (int i = n - 2; i >= 0; i--) {
    double sum = 0.0;
    for (const auto& e : graph[i]) {
      sum += dp[e.to];
    }
    dp[i] = sum / graph[i].size() + 1.0;
  }
  return dp;
}

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

  cout << fixed << setprecision(10);

  int n, m;
  cin >> n >> m;

  auto graph = ReadDirectedGraph(n, m, true);
  auto dp = Solve(graph);

  double ans = dp[0];
  for (int i = n - 2; i >= 0; i--) {
    if (graph[i].size() <= 1) continue;

    int max_to = -1;
    double max = 0.0;
    for (const auto& e : graph[i]) {
      if (dp[e.to] > max) {
        max_to = e.to;
        max = dp[e.to];
      }
    }

    vector<vector<Edge>> new_graph(n);
    for (int v = 0; v < n; v++) {
      for (const auto& e : graph[v]) {
        if (v != i || e.to != max_to) {
          new_graph[v].push_back(e);
        }
      }
    }
    auto new_dp = Solve(new_graph);
    if (new_dp[0] < ans) {
      ans = new_dp[0];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4504
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
    int a, b, h, w;
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ((i < b) ^ (j < a));
        }
        cout << endl;
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int func(int a,int b){
    //if(a<b)return func(b,a);
    if(b==0)return a;
    return func(b,a%b);
}

int main(){
    int n;
    cin>>n;
    vll a(n);
    int check=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]<=0){
            check=1;
        }
    }
    sort(all(a));
    reverse(all(a));
    ll sum=a[n-1];
    int id=1;
    vector<pair<int,int>> table;
    reps(i,1,n-1){
        if(a[i]<0){
            break;
        }
        table.pb(mp(sum,a[i]));
        sum-=a[i];
        id=i+1;
    }
    table.pb(mp(a[0],sum));
    sum=a[0]-sum;
    if(id<n-1){
        reps(i,id,n-1){
            table.pb(mp(sum,a[i]));
            sum-=a[i];
        }
    }
    cout<<sum<<endl;
    rep(i,table.size()){
        cout<<table[i].first<<" "<<table[i].second<<endl;
    }


}

Measured memory_bytes: 3572
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		final int INF = 999999;
		char[][] maze = new char[H][W];
		int[][] dp = new int[H][W];
			
		for(int i=0; i<H; i++) {
			String s = sc.next();
			for(int j=0; j<W; j++) {
				maze[i][j] = s.charAt(j);
				dp[i][j] = INF;
			}
		}
		
		if(maze[0][0] == '.') 
			dp[0][0] =0;
		else 
			dp[0][0] = 1;
		//ある升目に到達する経路の最短値
		for(int i=1; i<W; i++) {
			dp[0][i] = dp[0][i-1];
			if (maze[0][i-1] == '.' && maze[0][i] == '#') {
				dp[0][i]++;
			}
		}
		for(int i=1; i<H; i++) {
			dp[i][0] = dp[i-1][0];
			if(maze[i-1][0] == '.' && maze[i][0]  == '#') {
				dp[i][0]++;
			}
		}
		for(int i=1; i<H; i++) {
			for(int j=1; j<W; j++) {
				int up = dp[i-1][j];
				if(maze[i-1][j] == '.' && maze[i][j] == '#') {
					up++;
				}
				int left = dp[i][j-1];
				if(maze[i][j-1] == '.' && maze[i][j] == '#') {
					left++;
				}
				dp[i][j] = min(dp[i][j], up);
				dp[i][j] = min(dp[i][j], left);
			}
		}
out.println(dp[H-1][W-1]);	
	}
}


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



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

	int a;
	int b;
	int c;
	int d;

	d = z % 10;
	z -= d;
	c = (z % 100) / 10;
	z -= c * 10;
	b = (z % 1000) / 100;
	a = (z - b * 100) / 1000;

	int eq;
	char o1, o2, o3;
	for (int bit = 0; bit < (1 << 3); bit++) {
		if (bit & (1 << 0)) {
			eq = a + b;
			o1 = '+';
		}
		else {
			eq = a - b;
			o1 = '-';
		}
		if (bit & (1 << 1)) {
			eq = eq + c;
			o2 = '+';
		}
		else {
			eq = eq - c;
			o2 = '-';
		}
		if (bit & (1 << 2)) {
			eq = eq + d;
			o3 = '+';
		}
		else {
			eq = eq - d;
			o3 = '-';
		}
		if (eq == 7) {
			cout << a << o1 << b << o2 << c << o3 << d << "=7" << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3588
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  //input();
  int n;
  cin>>n;
  cout<<(!n)<<endl;
}

//

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
int main() {
	int a, b, c, k; scanf("%d%d%d%d", &a, &b, &c, &k);
	if (a >= k) {
		printf("%d", k);
		return 0;
	}
	else {
		k -= a;
		k -= b;
		if (k <= 0) printf("%d", a);
		else printf("%d", a - k);
	}
	return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>
#pragma warning (disable:4996)

int main() {
	//input
	char S[1003] = {};
	(void)scanf("%s", S);
	
	//output
	int i = 0;
	while (S[i] != '\0') i++;
	if (S[i - 1] == 's') {
		S[i] = 'e';
		S[i + 1] = 's';
	}
	else {
		S[i] = 's';
	}
	printf("%s", S);
}

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

string s;

bool check(string s, char c){
  bool ret = true;
  for(char x : s){
    if(x != c) ret = false;
  }
  return ret;
}

int main(){
  cin >> s;
  int n = s.size();
  int res = 100000;
  for(int c = 'a'; c <= 'z'; c++){
    string t = s;
    int cnt = 0;
    while(!check(t, c)){
      for(int i = 0; i < t.size() - 1; i++){
        if(t.at(i) == c || t.at(i + 1) == c){
          t.at(i) = c;
        }else{
          t.at(i) = 'X';
        }
      }
      t.erase(t.end() - 1);
      cnt++;
    }
    //cerr << t << endl;
    res = min(cnt, res);
  }
  cout << res << endl; 
  return 0;
}


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

int main()
{
    string str, str2;
    cin >> str;
    if(str == "ABC"){
        cout << "ARC";
    }else{
        cout << "ABC";
    }
    return 0;
}

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

struct Card{char suit,value;};

void bubble(struct Card A[],int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
	swap(A[j],A[j-1]);
      }
    }
  }
}

void selection(struct Card A[],int N){
  int min;
  for(int i=0;i<N;i++){
    min=i;
    for(int j=i;j<N;j++){
      if(A[min].value>A[j].value) min=j;
    }
    swap(A[i],A[min]);
  }
}

void print(struct Card A[],int N){
  for(int i=0;i<N;i++){
    if(i>0)cout<<" ";
    cout<<A[i].suit<<A[i].value;
  }
  cout<<endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit) return false;
  }
  return true;  
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin>>N;

  for(int i=0;i<N;i++){
    cin>>C1[i].suit>>C1[i].value;
  }
  for(int i=0;i<N;i++) C2[i]=C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout<<"Stable"<<endl;
  print(C2,N);
  if(isStable(C1,C2,N))  cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;

  return 0;
}




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

int F[100];
int n;
int main() {
  F[0] = 1;
  F[1] = 1;
  cin >> n;
  for (int i=2; i<45; ++i) {
    F[i] = F[i-2]+F[i-1];
  }
  cout << F[n] << endl;
}

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

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;



vector<char> vs;
string s;
int k;
deque<char> dq;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (char c = '0'; c <= '9'; ++c)
    vs.push_back(c);
  cin >> s >> k;
  for (int i = 0; i < k; ++i)
    {
      char ch;
      cin >> ch;
      vs.erase(find(vs.begin(), vs.end(), ch));
    }
 
  for (int i = 0; i < s.size(); ++i)
    dq.push_back(s[i]);
  for (int i = 0; i < dq.size(); ++i)
    {
      auto it = lower_bound(vs.begin(), vs.end(), dq[i]);
      if (it == vs.end())
	{
	  int pos = i;
	  --i;
	  while (i >= 0)
	    {
	      auto it = lower_bound(vs.begin(), vs.end(), dq[i]+1);
	      if (it != vs.end())
		{
		  dq[i] = *it;
		  pos = i+1;
		  break;
		}
	      --i;
	    }
	  
	  if (i < 0)
	    {
	      for (int j = 0; j < dq.size(); ++j)
		dq[j] = vs.front();
	      dq.push_front(*lower_bound(vs.begin(), vs.end(), '1'));
	    }
	  else
	    {
	      for (int j = i+1; j < dq.size(); ++j)
		dq[j] = vs.front();
	    }
	  break;
	}
      else if (*it > dq[i])
	{
	  dq[i] = *it;
	  for (int j = i+1; j < dq.size(); ++j)
	    dq[j] = vs.front();
	  break;
	}
    }
  for (int i = 0; i < dq.size(); ++i)
    putchar(dq[i]);
  puts("");
}


Measured memory_bytes: 256
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n = int(input())
	arr = list(map(int,input().split(' ')))
	dp = [0 for i in range(n)]
	dp[1] = abs(arr[0]-arr[1])
	for i in range(2,n):
		dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],\
					abs(arr[i]-arr[i-2])+dp[i-2])
	print(dp[n-1])

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################


Measured memory_bytes: 14536
#include<bits/stdc++.h>
#define N 200005
#define pii pair<int,int>
using namespace std;
#define low(x) ((x)&(-(x)))
int bits[N];
void modify(int x,int val){
    for(;x<N;x+=low(x)) bits[x]=max(bits[x],val);
}
int query(int x){
    int ret=0;
    for(;x!=0;x-=low(x)) ret=max(ret,bits[x]);
    return ret;
}
vector<pii> p;
vector<int> val;
int x1,y_1,x2,y2,n,fx,fy;
int main(){
    scanf("%d%d%d%d%d",&x1,&y_1,&x2,&y2,&n);
    fx = x1<x2? 1:-1;x1*=fx,x2*=fx;
    fy = y_1<y2? 1:-1;y_1*=fy,y2*=fy;
    for(int i=1,x,y;i<=n;i++) {
        scanf("%d%d",&x,&y);x*=fx,y*=fy;
        if(x1<=x&&x<=x2&&y_1<=y&&y<=y2)
            p.push_back(make_pair(x,y)),
            val.push_back(y);
    }
    sort(val.begin(),val.end());
    val.erase(unique(val.begin(),val.end()),val.end());
    for(pii &x:p)
        x.second=lower_bound(val.begin(),val.end(),x.second)-val.begin()+1;
    sort(p.begin(),p.end());
    int len=0;
    for(pii x:p){
        int v=query(x.second)+1;
        len=max(len,v);
        modify(x.second,v);
    }
    long double pi5=5*acos((long double)-1);
    int num=len+(len>=min(x2-x1,y2-y_1)+1? 1:0);
    double ans=(x2-x1+y2-y_1)*100.0-20*len+pi5*num;
    printf("%.15lf\n",ans);
    return 0;
}

Measured memory_bytes: 4336
package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int{
  sc.Scan()
  i, e :=strconv.Atoi(sc.Text())
  if e!=nil{
    panic(e)
  }
  return i
}
func main(){
  var i int
  sc.Split(bufio.ScanWords)
  n:=nextInt()
  ans:=0
  a:=make([]int, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  for i=0;i<n;i++{
    if i%2==0&&a[i]%2==1{
      ans++
    }
  }
  fmt.Println(ans)
}


Measured memory_bytes: 1776
import math
import copy




def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l

n=nCast(input())
a=nCast(input().split())
b=nCast(input().split())
c=list()
def func():
    result=0
    if sum(a)<sum(b):
        return -1
    for idx in range(0,len(a)):
        c.append(a[idx]-b[idx])
    c.sort()
    need=0
    result=0

    for number in c:
        if number<0:
            need+=number
            result+=1
        else:
            break

    if need==0:
        return 0
    for number in reversed(c):
        result+=1
        need+=number
        if need>=0:
            break
    return result

print(func()) 


Measured memory_bytes: 16756