akhauriyash/Code-Regression huggingface dataset:
import sys
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

h, w, k = nm()
mod = 10 ** 9 + 7

dp = [[0 for _ in range(w)] for __ in range(h + 1)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        for m in range(2 ** (w - 1)):
            count1 = 0
            count2 = 0
            count3 = 0
            mm = bin(m)[2:].zfill(w - 1)
            if '11' in mm:
                continue
            if j > 0:
                if mm[j - 1] == '1':
                    count1 += 1
                else:
                    if j < w - 1:
                        if mm[j] == '1':
                            count3 += 1
                        else:
                            count2 += 1
                    else:
                        count2 += 1
            else:
                if j < w - 1:
                    if mm[j] == '1':
                        count3 += 1
                    else:
                        count2 += 1
                else:
                    count2 += 1
            if j > 0:
                dp[i + 1][j - 1] += (dp[i][j] * count1) % mod
            if j < w - 1:
                dp[i + 1][j + 1] += (dp[i][j] * count3) % mod
            dp[i + 1][j] += (dp[i][j] * count2) % mod

print(dp[-1][k - 1] % mod)


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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if(u == s) cout << a-1 << " " << b << endl;
    if(u == t) cout << a << " " << b-1 << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
box=list(map(int,input().split()))
print(*box)
for i in range(1,n):
    while 1:
        if i==0:break
        elif box[i]<box[i-1]:
            box[i],box[i-1]=box[i-1],box[i]
            i -=1
        else:break
    print(*box)


Measured memory_bytes: 5984
import java.util.Scanner;
class Main{
	
    public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
 
System.out.println(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible");
 }
}

Measured memory_bytes: 23120
def gca(x, y):
    if x == 0:
        return y
    return gca(y % x, x)

N = int(input())
A = [int(i) for i in input().split()]

L = [0] * N
R = [0] * N
L[0] = A[0]
R[N - 1] = A[N - 1]

for i in range(1, N):
    L[i] = gca(A[i], L[i - 1])
for i in range(N - 2, -1, -1):
    R[i] = gca(A[i], R[i + 1])
maxg = 0
for i in range(1, N - 1):
    maxg = max(maxg, gca(L[i - 1], R[i + 1]))

print(max(L[N - 2], R[1], maxg))



Measured memory_bytes: 14428
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    char a, b;
    cin >> a >> b;
    string s, t;
    int a_ = a-'0';
    int b_ = b-'0';
    for(int i = 0; i < b_; i++){
        s += a;
    }
    for(int i = 0; i < a_; i++){
        t += b;
    }
    if(s > t){
        cout << t << endl;
    }else{
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
ll n,h[110];
int main(){
    cin>>n;
    lol(i,n)cin>>h[i+1]; h[n+1]=h[0]=-1;
    ll ans=0;
    for(int k=1;k<110;k++){
      ll cnt=0;
      for(int i=0;i<=n;i++){
	if(h[i]>=k&&h[i+1]<k)cnt++;
      }
      ans+=cnt;
    }cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
n = 5
t = [int(input()) for i in range(n)]
l = 0
ans = 0
min = 10
l = 0
index = 0
for i in t:
    s = str(i)
    if int(s[len(s)-1]) != 0 and int(s[len(s)-1]) < min:
        min = int(s[len(s)-1])
        index = l
    l += 1
l = 0
for i in t:
    if l == index:
        ans += i
    else:
        ans += math.ceil(i/10) * 10
    #print(ans)
    l += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Lesen std::ios::sync_with_stdio(false);std::cin.tie(0);

int N, maxi = 0;
map <int, int> mp;

void solve(void){
	scanf("%d\n", &N);
	rep(N, i) {
		int d;
		scanf("%d\n", &d);
		mp[d] = mp[d-1]+1;
		maxi = max(maxi, mp[d]);
	}
	printf("%d\n", N - maxi);
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

int w[107];
vector<pair<int,int> > g[107];
void add(int u, int v, int w){
    g[u].push_back(make_pair(v,w));
    g[v].push_back(make_pair(u,w));
}
int findTheCity(int n, vector<vector<int>>& edges, int dt) {
    for(int i = 0; i < (int)edges.size();i++){
        int u = edges[i][0];
        int v = edges[i][1];
        int w = edges[i][2];
        add(u,v,w);
    }
    
	
	int ans = inf;
	for(int i = 0; i < n; i++){
		clr(w,inf);
		w[i] = 0;
		for(int k = 1; k <= n-1; k++){
			for(int j = 0; j < n; j++){
				for(int l = 0; l < (int)g[j].size(); l++){
					int u = j;
					int v = g[j][l].first;
					int weigth = g[j][l].second;
					if(w[u] + weigth < w[v]){
						w[v] = w[u] + weigth;
					}
				}
			}
		}
		int cont = 0;
		cout<<i<<":\n";
        for(int k = 0; k < n; k++){
            if(k != i && w[k] <= dt){
				cout<< k<<"-"<<w[k];
                cont++;
            }
            cout<<endl;
        }
        
		ans = min(cont, ans);
	}
	
	return ans;
}

int main(){
	int h, n; cin>> h >> n;
	int sum = 0; int x;
	for(int i = 0; i < n; i++){
		cin>> x;
		sum += x;
	}
	if(sum >= h)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}












Measured memory_bytes: 256
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const ll N = 1e3, MOD =  998244353;

void solve() {
    ll a;
    double b;
    cin >> a >> b;
    ll c = b*100 + 0.5;
    ll ans = (a*c)/100;
    cout << setprecision(20) << ans;
}

int main()  {
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A[6]; rep(i, 5) cin >> A[i+1];
    for(int i = 1; i <= 5; i++) if(A[i] != i) cout << i << endl;
    return 0;
}

Measured memory_bytes: 3644
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)



Measured memory_bytes: 5980
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 1000000
#define INF   1000000000

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

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

    ll A, B, N;
    cin >> A >> B >> N;

    ll x;
    if (N < B - 1) x = N;
    else x = B - 1;

    cout << floor(A*x/B) - A*floor(x/B) << endl;
    
    return 0;
}


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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp(x, y)  make_pair(x, y);
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second
#define mod       1000000007

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
  ioThings();

  int n, k;
  cin >> n >> k;

  si s;
  rep(i, k) {
    int d;
    cin >> d;

    while (d--) {
      int x;
      cin >> x;
      s.insert(x);
    }
  }

  cout << n - sz(s);

  return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    s.erase(4,1);
    s.erase(6,1);
    long long int ans=atoi(s.c_str());
    if(ans<=20190430) cout<<"Heisei";
    else cout<<"TBD";
}

Measured memory_bytes: 3616
from queue import deque

H, W = map(int,input().split())
S = list(list(input()) for _ in range(H))
ans = 0

for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      D = [[-1] * W for _ in range(H)]
      D[h][w] = 0
      Q = deque()
      Q.append((h, w))
      
      while Q:
        y, x = Q.popleft()

        for i, j in (1, 0), (-1, 0), (0, 1), (0, -1):
          y2, x2 = y + i, x + j

          if 0 <= y2 < H and 0 <= x2 < W and S[y2][x2] == "." and D[y2][x2] == -1:
            Q.append((y2, x2))
            D[y2][x2] = D[y][x] + 1

      for i in range(H): ans = max(ans, max(D[i]))

print(ans)

Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    V(string) G(H);
    int bl = 0;
    rep(i, H) {
        cin >> G[i];
        rep(j, W) if(G[i][j]=='#') bl++;
    }

    int res = 0;
    rep(i, 1<<H) {
        vi done;
        int ti = i;
        int tsum = 0;
        rep(j, H) {
            if(ti&1) {
                rep(k, W) if(G[j][k]=='#') tsum++;
                done.pb(j);
            }
            ti >>= 1;
        }
        rep(j, 1<<W) {
            int tt = tsum;
            int tj = j;
            rep(k, W) {
                if(tj&1) {
                    rep(l, H) if(G[l][k]=='#') tt++;
                    rep(l, done.size()) if(G[done[l]][k]=='#') tt--;
                }
                tj >>= 1;
            }
            if(bl-tt==K) res++;
        }
        
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

// S <= D + X < T, case block
// S-X <= D < T-X
int main() {
    int n, q;
    int s, t, x, d;
    cin >> n >> q;
    vector<vector<int>> arr;
    for(int i = 0; i < n; i++) {
        cin >> s >> t >> x;
        arr.push_back({s, t, x});
    }
    map<int, vector<int>> axis;
    for(int i = 0; i < n; i++) {
        int s2 = arr[i][0] - arr[i][2];
        int t2 = arr[i][1] - arr[i][2];
        axis[s2].push_back(i+1);
        axis[t2].push_back(-(i+1));
    }
    multiset<int> dis = {INT_MAX};
    map<int, int> cache;
    for(auto p: axis) {
        int pos = p.first;
        for(int val: p.second) {
            if (val > 0) {
                dis.insert(arr[val-1][2]);
            } else {
                auto it = dis.find(arr[abs(val)-1][2]);
                dis.erase(it);
            }
        }
        cache[pos] = *dis.begin();
        if (cache[pos] == INT_MAX)
            cache[pos] = -1;
    }
    while(q--) {
        cin >> d;
        auto it = cache.upper_bound(d);
        cout << prev(it)->second << endl;
    }
    return 0;
}




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

int main() {
  int A,B;
cin>>A>>B;
  if(A>9){
   cout<<-1<<endl; 
  }
  else if(B>9){
   cout<<-1<<endl; 
  }
  else{
   cout<<A*B<<endl; 
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import kotlin.math.abs

fun main(){
    val n = readLine()!!.toInt()
    val plan = MutableList(n){
        readLine()!!.split(" ").map{it.toInt()}
    }
    var nt = 0
    var nx = 0
    var ny = 0

    plan.forEach{
        var dt = abs(it[0] - nt)
        var dx = abs(it[1] - nx)
        var dy = abs(it[2] - ny)
        if(dt < dx + dy){
            println("No")
            return
        }
        else if(dt % 2 == (dx + dy) % 2){
            nt = it[0]
            nx = it[1]
            ny = it[2]
        }
        else{
            println("No")
            return
        }
    }
    println("Yes")
}

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

int main(){
  char hoge;
  std::string str;
  std::cin >> str;
  if(str.length() == 3){
    hoge = str[0];
    str[0] = str[2];
    str[2] = hoge;
  }
  std::cout << str << std::endl;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"

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

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n;
P r[110], b[110];
bool used[110];
int cnt;

int main(void){
	cin>>n;
	for(int i=0;i<n;i++) cin>>r[i].first>>r[i].second;
	for(int i=0;i<n;i++) cin>>b[i].first>>b[i].second;

	sort(r, r + n, [&](P a, P b) { return a.second > b.second; });
	sort(b, b + n);

	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(r[j].first < b[i].first && r[j].second < b[i].second) {
				cnt++;
				r[j].first = INF; r[j].second = INF;
				break;
			}
		}
	}

	cout<< cnt <<endl;

	return 0;
}


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

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  for (int i=0; i<N; i++) {
    if (i!=N-1) cout << S.at(i) << T.at(i);
    else cout << S.at(i) << T.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct square {
	int s, t, u; // solved, time, team
	square() : s(0), t(0), u(0) {}
	square(int p, int q, int r) : s(p), t(q), u(r) {}
};
bool operator==(square s1, square s2) { return s1.s == s2.s && s1.t == s2.t; }
bool operator!=(square s1, square s2) { return !(s1 == s2); }
bool operator<(square s1, square s2) {
	if(s1.s != s2.s) return s1.s > s2.s;
	if(s1.t != s2.t) return s1.t < s2.t;
	return s1.u > s2.u;
}
int T, N, P, Q, t, n, p, q;
int main() {
	while(scanf("%d%d%d%d", &T, &N, &P, &Q), N) {
		square d[50]; int v[50][10]; memset(v, 0, sizeof(v));
		for(int i = 0; i < N; i++) d[i] = square(0, 0, i + 1);
		for(int i = 0; i < Q; i++) {
			scanf("%d%d%d%d", &t, &n, &p, &q);
			if(q != 0) v[n - 1][p - 1]++;
			else d[n - 1].s++, d[n - 1].t += t + v[n - 1][p - 1] * 20;
		}
		sort(d, d + N);
		printf("%d", d[0].u);
		for(int i = 1; i < N; i++) {
			if(d[i - 1] != d[i]) printf(",%d", d[i].u);
			else printf("=%d", d[i].u);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3120
S = str(input())
T = str(input())
n = len(S)
m = len(T)
ans = m
for i in range(n-m+1):
    x = m
    s = S[i:i+m]
    for j in range(m):
        if s[j] == T[j]:
            x -= 1
    ans = min(ans, x)

print(ans)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define inf (1LL<<61)
#define MOD 1000000007
const ll N=2e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
ll n,w;
ll weight[N];
ll value[N];
ll cache[105][100005];
ll dp(ll i,ll rem)
{
    if(rem<0)
        return -inf;
    if(i==n)
    {
        if(rem<0)   
            return -inf;
        else
        {
            if(rem-weight[n]>=0)
                return value[n];
            else
                return 0;
        }
    }
    
    ll &ans=cache[i][rem];
    if(ans!=-1)
        return ans;
    ans=0;
    ans=max(ans,dp(i+1,rem-weight[i])+value[i]);
    ans=max(ans,dp(i+1,rem));
    
    return ans;
    
}
int main()
{
    IOS;
    cin>>n>>w;
    for(ll i=1;i<=n;i++)
    {
        cin>>weight[i]>>value[i];
    }
    memset(cache,-1,sizeof(cache));
    ll ans=dp(1,w);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 84224
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define nn 3008
#define ll long long
#define mod 1000000007
#define lf double
using namespace std;
ll dp[nn][nn];
ll qpow(ll x,ll y)
{
	ll res=1;
	while(y)
	{
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}
ll d2;
int org[nn];
ll tmp1[nn],tmp2[nn];
int main()
{
	d2=qpow(2,mod-2);
	ll n,m;scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&org[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(org[i]>org[j]) dp[i][j]=1;
	for(int ytl=1;ytl<=m;ytl++)
	{
		int x,y;scanf("%d%d",&x,&y);
		for(int i=1;i<=n;i++) tmp1[i]=(dp[x][i]+dp[y][i])*d2%mod;
		for(int i=1;i<=n;i++) tmp2[i]=(dp[i][x]+dp[i][y])*d2%mod;
		ll tmp3=(dp[x][y]+dp[y][x])*d2%mod;
		for(int i=1;i<=n;i++) 
			dp[i][y]=dp[i][x]=tmp2[i];
		for(int i=1;i<=n;i++)
			dp[x][i]=dp[y][i]=tmp1[i];
		dp[x][x]=dp[y][y]=0;
		dp[x][y]=dp[y][x]=tmp3;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=dp[i][j],ans%=mod;
	cout<<ans*qpow(2,m)%mod;
    return 0;
}

Measured memory_bytes: 70784
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<int> P(N), id(N);
    for (int i = 0; i < N; i++) {
      cin >> P[i];
      --P[i];
      id[P[i]] = i;
    }
    vector<int> dp(N, 1);
    for (int i = 0; i < N; i++) {
      int pre = P[i] - 1;
      if (pre >= 0 && id[pre] < i) {
        dp[i] = dp[id[pre]] + 1;
      }
    }
    int res = N - *max_element(dp.begin(), dp.end());
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    map <char,ll> m1;
    m1['r']=p;
    m1['s']=r;
    m1['p']=s;
    ll ans=0;
    ve <ll> a(n,0);//a[i]=0 means we are done and =1 means draw
    rep (i,0,k)
    {
        ans+=m1[t[i]];
    }
    bool flag=false;

    rep (i,k,n)
    {
        if (a[i-k]==0&&t[i]==t[i-k])
        {
            // ans+=0;
            a[i]=1;
        }
        else
        {
            ans+=m1[t[i]];
            a[i]=0;
        }
    }
    cout<<ans<<"\n";
}


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

int main()
{
    char v[101];
    cin.getline(v,101);
    int C=-1,F=-1;
    for(int i=0;i<strlen(v);i++)
    {
        if(v[i]=='C')
            {C=i;
        break;}
    }
    for(int i=0;i<strlen(v);i++)
    {
        if(v[i]=='F')
            {F=i;}
    }
    if(C!=-1 && F!=-1 && C<F)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static class Pair {
		int a, b;

		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		
	}
	static class Graph {
		int N;
		ArrayList<ArrayList<Integer>> node;
		public Graph(int N) {
			this.N = N;
			node = new ArrayList<>();
			for(int i=0; i<N; i++)
				node.add(new ArrayList<Integer>());
		}
		
		public void addEdge(int from, int to) {
			node.get(from).add(to);
		}
		
		public int distance(int s, int t) {
			boolean[] visited = new boolean[N];
			LinkedList<Pair> q = new LinkedList<>();
			q.add(new Pair(s, 0));
			
			while(q.size()>0) {
				Pair p = q.poll();
				if(p.a==t)
					return p.b;
				if(visited[p.a])
					continue;
				for(int to : node.get(p.a)) {
					if(!visited[to])
						q.add(new Pair(to, p.b+1));
				}
				visited[p.a] = true;
			}
			
			return -3;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Graph g = new Graph(N*3);
		for(int i=0; i<M; i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			g.addEdge(u*3, v*3+1);
			g.addEdge(u*3+1, v*3+2);
			g.addEdge(u*3+2, v*3);
		}
		int S = sc.nextInt()-1;
		int T = sc.nextInt()-1;
		
		System.out.println(g.distance(S*3, T*3)/3);

		sc.close();
	}
}


Measured memory_bytes: 118940
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  int[] B = new int[N-1];
	  for(int i = 0; i < B.length; i++)
		  B[i] = Integer.parseInt(sc.next());
	  
	  int A = B[0] + B[B.length-1];
	  for(int i = 1; i < B.length; i++) {
		  A += Math.min(B[i-1], B[i]);
	  }
	  System.out.println(A);
	  sc.close();
	  
  }
}


Measured memory_bytes: 23892
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

bool A[1000001], B[1000001];

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


	int N = getint();

	rep(i, N) {
		int a = getint();
		if (A[a]) B[a] = 1;
		else A[a] = 1;
	}

	if (A[1]) {
		if (!B[1]) co(1);
		else co(0);
		return 0;
	}
	if (A[2]) {
		int kotae = !B[2];
		for (int i = 3; i <= 500000; i += 2) {
			if (A[i]) {
				kotae += !B[i];
				for (int j = i + i; j <= 1000000; j += i) {
					A[j] = 0;
				}
			}
		}
		for (int i = 500001; i <= 1000000; i += 2) kotae += (A[i] && !B[i]);
		co(kotae);
		return 0;
	}

	int kotae = 0;
	for (int i = 2; i <= 500000; i++) {
		if (A[i]) {
			kotae += !B[i];
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] && !B[i]);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 5724
/*input
1000000000 141421 173205
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=5e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
ll inv(ll z){
    if(z==1) return 1;
    return (MOD-MOD/z)*inv(MOD%z)%MOD;
}
ll c(ll n,ll k){
    ll z=1;
    for(ll i=n-k+1;i<=n;i++) z=(z*i)%MOD;
    ll b=1;
    for(ll i=1;i<=k;i++) b=(b*i)%MOD;
    return z*inv(b)%MOD;
}
int main(){
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    ll ans=mypow(2,n)-1;
    ans=(ans-c(n,a)+MOD)%MOD;
    ans=(ans-c(n,b)+MOD)%MOD;
    cout<<ans;
}

Measured memory_bytes: 256
<?php
  
 $s = explode(' ',trim(fgets(STDIN)));
$point= $s[1]-$s[2] ;
$win=[] ;
for($i=0;$i<$s[0];$i++){
  $win[$i+1] = $point ;
}
for($i=0;$i<$s[2];$i++){
  $win[trim(fgets(STDIN))]++ ;
}

for($i=0;$i<$s[0];$i++){
if($win[$i+1]>0){
echo "Yes\n" ;
}else{
echo "No\n" ;
}

}


Measured memory_bytes: 16756
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			int i=1;
			for(;;)
			{
				if(n<=Math.pow(3, i))
					break;
				i++;
			}
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 12000
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll ans=0;
    ans +=n/500*1000;
    n = n - (n / 500) * 500;
    ans+=n/5*5;
    cout << ans << "\n";
}


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

int main(void){
  long long r,d,x;cin >> r >> d >> x;
  for(int i = 0;i<10;i++){
    x = r*x-d;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int w; cin >> w;
	for (int i = 0; i < (int)s.length(); i += w)
		cout << s[i];
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l,r,ans=0;
	string s;
	cin>>n>>s;
	l=0,r=n-1;
	while (l<r)
	{
		while (l<=n-1&&s[l]=='R')   l++;
		while (r>=0&&s[r]=='W')   r--;
		if (l<r)
		{
			swap(s[l],s[r]);
			ans++;
		} 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3692
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int y, m, d;
  char slash;
  while (cin >> y >> slash >> m >> slash >> d) {
    vector<int> S = {y, m, d};
    vector<int> threshold = {2019, 4, 30};
    bool res = S <= threshold;
    cout << (res ? "Heisei" : "TBD") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]
alpha = "abcdefghijklmnopqrstuvwxyz"
ans = ''
for i in alpha:
    min_ = float('Inf')
    for sj in s:
        cnt = 0
        for elem in sj:
            if elem == i:
                cnt += 1
        min_ = min(min_, cnt)
    ans += i * min_
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void)
{
	int num;
	int b, f, r, v;
	int heya[4][3][10];
	int ii, jj, kk;
	char c;

	memset(&heya[0][0][0], (int)0, sizeof(int) * 4 * 3 * 10);

	scanf("%d", &num);
	scanf("%c", &c);

	for (ii = 0; ii < num; ii++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		heya[b - 1][f - 1][r - 1] += v;
		scanf("%c", &c);
	}

	for (ii = 0; ii < 4; ii++) {
		for (jj = 0; jj < 3; jj++) {
			for (kk = 0; kk < 10; kk++) {
				printf(" %d", heya[ii][jj][kk]);
			}
			printf("\n");
		}
		if (ii != 3) {
			printf("####################\n");
		}
	}

	return 0;
}

Measured memory_bytes: 612
N = int(input()) - 1

LARGE = 10**9+7

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
 
    while c1 != 0:
        m = c0 % c1
        q = c0 // c1
 
        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)
 
    return c0, a0, b0
# precompute
fac_list = [1]*(N+1)
fac = 1
for i in range(1, N+1):
    fac = (fac * i) % LARGE
    fac_list[i] = fac
    
fac_inv_list = [1]*(N+1)
for i in range(N+1):
    fac_inv_list[i] =  pow(fac_list[i], LARGE-2, LARGE)
    
def nCr(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE

def pat(n, r):
    return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE


pat = 0
score = 0

for k in range(N+1):
    if k-1 >= N-k:
        res = (((fac_list[k-1]*fac_list[k]) % LARGE) * fac_inv_list[k-1-N+k]) % LARGE
        score = (score + (res - pat) * k) % LARGE
        # print(k, pat, res)
        pat = res
print(score)

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

using namespace std;

long long BIT[300001];

long long Sum(int I)
{
    I++;
    long long S = 0;
    while (I >= 1)
    {
        S += BIT[I];
        I -= I & (-I);
    }
    return S;
}

void Update(int I)
{
    I++;
    while (I <= 300000)
    {
        BIT[I]++;
        I += I & (-I);
    }
}

int main()
{
    int n, a, x;
    cin >> n;
    int L=-1, R=n, t, A[n], B[n];
    vector <int> V;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        V.push_back(A[i]);
    }
    sort(V.begin(),V.end());
    while (R - L > 1)
    {
        t = (L+R) / 2;
        x = V[t];
        for (int i = 0; i < n; i++)
        {
            if (A[i] >= x)
            {
                B[i] = 1;
            }
            else
            {
                B[i] = -1;
            }
        }
        for (int i = 0; i <= 300000; i++)
        {
            BIT[i] = 0;
        }
        long long In = 0, s=0;
        Update(100001);
        for (int i = 0; i < n; i++)
        {
            s += B[i];
            In += Sum(100001+s);
            Update(100001+s);
        }
        long double b = n;
        long long r = ceil((b+1)*b/4);
        if (In >= r)
        {
            L = t;
        }
        else
        {
            R = t;
        }
    }
    cout << V[L];
    return 0;
}


Measured memory_bytes: 3832
#include <cassert>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <vector>

int n, a, b, c;
std::vector<int> master;

bool next_candidate(std::vector<int>& candidate)
{
  for (int i = 0; i < (int)candidate.size(); i++) {
    if (candidate[i] < 3) {
      candidate[i]++;
      return true;
    }
    candidate[i] = 0;
  }
  return false;
}

int try_solve(const std::vector<int>& candidate)
{
  assert(candidate.size() == master.size());
  int a_candidate = 0;
  int b_candidate = 0;
  int c_candidate = 0;
  int cost = 0;
  bool a_cat_flag = false;
  bool b_cat_flag = false;
  bool c_cat_flag = false;
  for (int i = 0; i < (int)candidate.size(); i++) {
    if (candidate[i] == 0) {
      continue;
    } else if (candidate[i] == 1) {
      a_candidate += master[i];
      if (a_cat_flag) {
        cost += 10;
      }
      a_cat_flag = true;
    } else if (candidate[i] == 2) {
      b_candidate += master[i];
      if (b_cat_flag) {
        cost += 10;
      }
      b_cat_flag = true;
    } else if (candidate[i] == 3) {
      c_candidate += master[i];
      if (c_cat_flag) {
        cost += 10;
      }
      c_cat_flag = true;
    } else {
      std::cerr << "Unknown candidate value: " << candidate[i] << '\n';
      exit(1);
    }
  }
  if (a_cat_flag && b_cat_flag && c_cat_flag) {
    return cost + abs(a-a_candidate) + abs(b-b_candidate) + abs(c-c_candidate);
  } else {
    return INT_MAX;
  }
}

int main()
{
  std::cin >> n >> a >> b >> c;
  master.resize(n);
  for (int i = 0; i < n; i++) {
    std::cin >> master.at(i);
  }
  std::vector<int> candidate(n, 0);
  int result = INT_MAX;
  do {
    result = std::min(try_solve(candidate), result);
  } while (next_candidate(candidate));
  std::cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
import collections
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
c = [list(map(int,input().split())) for i in range(N)]
L1 = [c[i-1][j-1] for i in range(1,N+1) for j in range(1,N+1) if (i + j) % 3 == 1]
L2 = [c[i-1][j-1] for i in range(1,N+1) for j in range(1,N+1) if (i + j) % 3 == 2]
L3 = [c[i-1][j-1] for i in range(1,N+1) for j in range(1,N+1) if (i + j) % 3 == 0]
c1 = collections.Counter(L1)
c2 = collections.Counter(L2)
c3 = collections.Counter(L3)
result = 10**9
for i in range(1,C+1):
    for j in range(1,C+1):
        if i == j:
            continue
        for k in range(1,C+1):
            if i == k or j == k:
                continue
            tmp = 0
            for l in range(1,C+1):
                tmp += c1[l] * D[l-1][i-1]
                tmp += c2[l] * D[l-1][j-1]
                tmp += c3[l] * D[l-1][k-1]
            result = tmp if result > tmp else result

print(result)

Measured memory_bytes: 8004
n = int(input())
a,bm = [0 for i in range(n)],1234567890
flag = True
for i in range(n):
	a[i],b = map(int,input().split())
	if a[i] > b:
		flag = False
		bm = min(bm,b)
print(0 if flag else sum(a)-bm)

Measured memory_bytes: 3828
W, H = list(map(int, input().split()))
p = sorted([int(input()) for _ in range(W)], reverse=True)
q = sorted([int(input()) for _ in range(H)], reverse=True)
ans = 0
while len(p) > 0 and len(q) > 0:
    #print("p:{}, q:{}, ({},{})".format(p[-1], q[-1], W, H))
    if p[-1] < q[-1]:
        ans += p[-1] * (H + 1)
        #print("ans += {} * {} -> {}".format(p[-1], H+1, p[-1] * (H+1)))
        p.pop()
        W -= 1
    else:
        ans += q[-1] * (W + 1)
        #print("ans += {} * {} -> {}".format(q[-1], W+1, q[-1] * (W+1)))
        q.pop()
        H -= 1
ans += sum(p) + sum(q)
print(ans)


Measured memory_bytes: 12112
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    a,b,c = INTM()
    if (a+c)/2 == b:
        print('YES')
    else:
        print('NO')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// range maximum query segment tree;
#define ll long long int
using namespace std;
 
ll tree[800005] = {0};
 
ll query(int tidx,int lo,int hi,int i,int j){
	if(lo > j || hi < i)return 0;
	if(i <= lo && hi <= j)return tree[tidx];
 
	int mid = (lo+hi)/2;
	// if(i > mid){
	// 	return query(2*tidx+2,mid+1,hi,i,j);
	// }
	// else if(j<=mid){
	// 	return query(2*tidx+1,lo,mid,i,j);
	// }
	return max(query(2*tidx+1 , lo,mid,i,j),query(2*tidx+2,mid+1,hi,i,j));
}
 
void update(int tidx,int lo,int hi,int i,ll val){
	if(lo == hi){
		tree[tidx] = val;
		return;
	}
	int mid = (lo + hi)/2;
 
	if(i > mid){
		update(2*tidx+2,mid+1,hi,i,val);
	}
	else{
		update(2*tidx+1,lo,mid,i,val);
	}
	tree[tidx] = max(tree[2*tidx+1],tree[2*tidx+2]);
}
 
int main(){
	int n;cin >> n;
	vector<int> arr(n,0);
	vector<ll> beauty(n,0);
	int maximum = 0;
	for(int i = 0;i<n;i++){
		cin >> arr[i];
		maximum = max(maximum,arr[i]);
	}
	for(int i = 0;i<n;i++)cin >> beauty[i];
 
	for(int i = 0;i<n;i++){
		ll temp = beauty[i]+query(0,0,200000,0,arr[i]-1);
		//cout << temp << " ";
		update(0,0,200000,arr[i],temp);
	}
	cout << query(0,0,200000,0,maximum) << endl;
	return 0;
}


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

int main(){
  int a,b,c;
  
  cin >> a >> b >> c;
  
  if((a == 1 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1)){
  	cout << "Open" << endl;
  }else{
  	cout << "Close" << endl;
  }
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
vector <ll> h(110000,0);
 ll K;  ll N;ll dp[100010];// 1 indexed
ll get_cost(ll a,ll b);

ll solve(ll n);

int main(){

  cin>>N;
 
  cin>>K;
  for(int in = 1;in <= N; in++ ){
    cin >> h[in];
  }
  
  dp[1] = 0;
  for (int n = 2; n<=N ; n++){
    dp[n] = solve(n);
  }
  cout<<dp[N]<<endl;
  return 0;
}

ll get_cost(ll a,ll b){
  return abs(h[a]-h[b]);
}

ll solve(ll n){
  ll ans=999999999;
  if(n-K <= 0){
    for(int i=1;i<=n-1;i++){
      ans = min (ans,dp[i]+get_cost(n,i));
    }
  } else {
    for(int i = n-K;i<=n-1;i++){
      ans = min (ans,dp[i]+get_cost(n,i));
    }
  }
  return ans;
}




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

int main () {
  
  vector<long long> dx = {1, 1, 1, 1, -1, -1, -1, -1};
  vector<long long> dy = {1, 1, -1, -1, 1, 1, -1, -1};
  vector<long long> dz = {1, -1, 1, -1, 1, -1, 1, -1};
  
  long long N, M; cin >> N >> M;
  vector<vector<long long>> vec(N, vector<long long>(3));
  
  for (long long i = 0; i < N; i++) {
    cin >> vec[i][0] >> vec[i][1] >> vec[i][2];
  }
  
  vector<long long> ans(8);
  
  for (long long sgn = 0; sgn < 8; sgn++) {
    
    vector<long long> vec2(N);
    
    for (long long i = 0; i < N; i++) {
      vec2[i] = dx[sgn] * vec[i][0] + dy[sgn] * vec[i][1] + dz[sgn] * vec[i][2];
    }
    
    sort(vec2.begin(), vec2.end());
    
    for (long long i = 0; i < M; i++) {
      ans[sgn] += vec2[N - i - 1];
    }
    
  }
  
  sort(ans.begin(), ans.end());
  
  cout << ans[7] << endl;
  
}

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

using namespace std;

int main(void){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0;i < n;i++) cin >> a[i];
  
  map<int, int> mp;
  
  for(int i = 0;i < n;i++){
    mp[a[i]]++;
  }
  
  int ans = 0;
  for(auto p : mp){
    int x = p.first;
    int n = p.second;
    
    if(n < x) ans += n;
    else ans += n - x;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	string s;
	cin >> s;
	int rec = 0;
	int Rec = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A') {
			rec = i;
			break;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			Rec = i;
			break;
		}
	}
	cout << Rec - rec + 1 << endl;
	return 0;
}

Measured memory_bytes: 3760
#include <stdio.h>
int main(){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if(a > b){
      d = a;
      a = b;
      b = d;
     }
    if(a > c){
      d = a;
      a = c;
      c = d;
     }
    if(b > c){
      d = b;
      b = c;
      c = d;
     }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
# coding: utf-8
# Your code here!
N,K = map(int,input().split())
h = list(map(int,input().split()))

h.sort()
if h[len(h)-1]<K:
    print(0)
else:
    for i in range(len(h)):
        if h[i]>=K:
            print(N-i)
            break


Measured memory_bytes: 11908
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))







Measured memory_bytes: 14060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 510; 
const int INF = 1000000000;

int n;
int main()
{
	scanf("%d",&n);
	if(n < 1200)
	{
		printf("ABC\n");
	}
	else if(n>= 1200 && n <2800)
	{
		printf("ARC\n");
	}
	else
	{
		printf("AGC\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

int a=0,b=0,c=0,d=0;

cin >> a >> b >> c;

if(a > b){
swap(a,b);
}

if(b > c){
swap(b,c);
}

if(a > b){
swap(a,b);
}

/*
if(a>b){
d = a;
a = b;
b = d;
}

if(b>c){
d = b;
b = c;
c = d;
}

if(a>b){
d = a;
a = b;
b = d;
}
*/
cout << a << " " << b << " " << c << endl;

return 0;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI  3.1415926535
#define rep(i, k, n) for(ll i = k; i < n; i++)

int main(){
  ll n; cin >> n;
  vll a(n);
  rep(i, 0, n){cin >> a[i];}
  
  vll f(n,0);
  rep(i, 0, n){
    f[0] += pow(-1, i) * a[i];
  }
  
  rep(i, 1, n){
    f[i] = f[i-1] * (-1) + 2 * a[i-1];
  }
  
  for(auto x:f){cout << x << " ";}
}



Measured memory_bytes: 4912