akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int []problems= new int[N];
        
        int []low = new int[N];
        int []mid = new int[N];
        int []high = new int[N];
        int lowc = 0;
        int midc = 0;
        int highc = 0;
        int min = Integer.MAX_VALUE;
        for(int i = 0; i<N; ++i) {
            int val = sc.nextInt();
            if(val <= A) {
                low[lowc] = val;
                ++lowc;

            }else if (val > A && val <=B) {
                mid[midc] = val;
                ++midc;

            }else if (val > B) {
                high[highc] = val;
                ++highc;  

            }
            problems[i] = val;
            
        }
      /*
        int total = (lowc+1) * (midc+1) * (highc+1);
        for(int i : low) {
            
            if(i == 0) {
                break;
            }
            System.out.println(i +" is less than "+A);
        }
        for(int i : mid) {
            
            if(i == 0) {
                break;
            }            
            System.out.println(i +" is between "+A +" and "+B);
        }
        for(int i : high) {
            
            if(i == 0) {
                break;
            }
          System.out.println(i +" is higher than "+B);
        }*/
		min = Math.min(Math.min(lowc, midc), highc);
        System.out.println(min);
/*      System.out.println(lowc);
      System.out.println(midc);
      System.out.println(highc);*/
    }

}



Measured memory_bytes: 21076
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
h = []
for _ in range(N):
  h.append(int(input()))
h.sort()
def explosive(x):
  c = 0
  for i in range(N):
    if h[i] > x * B:
      c += -(-(h[i] - x * B) // (A - B))
  if c <= x: return True
  else: return False
ng = 0
ok = 10 ** 9
m = 0
while ok - ng > 1:
  m = (ng + ok) // 2
  #print(m, explosive(m))
  if explosive(m):
    ok = m
  else:
    ng = m
print(ok)

Measured memory_bytes: 44892
import sys
input = sys.stdin.readline
mod = 10**9+7
rng = 100001
fctr = [1]
finv = [1]
for i in range(1,rng):
    fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
    finv.append(pow(fctr[i],mod-2,mod))
n,k = map(int,input().split())
ab = [list(map(int, input().split(' '))) for i in range(n-1)]
graph = [[] for i in range(n+1)]
parent = [0 for i in range(n+1)]
cnum = [0 for i in range(n+1)]
root = 1
stack = [root]
ans = 1
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if parent[x] == y:
            continue
        parent[y] = x
        cnum[x] += 1
        stack.append(y)
for x in range(1,n+1):
    if x == 1:
        y = cnum[1]
        if k-y-1<0:
            print(0)
            exit()
        ans = ans*fctr[k]*finv[k-y-1]%mod
        continue
    if cnum[x] == 0:
        continue
    y = cnum[x]
    if k-y-2<0:
        print(0)
        exit()
    ans = ans*fctr[k-2]*finv[k-2-y]%mod
print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a*2 > b || a*4 < b || b%2==1) {
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;
}

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

int main() {
  int n = 3;
  int sum = 0;
  while ( n-- ) {
    int a;
    cin >> a;
    sum += a;
  }
  string ans = ( sum > 21 ) ? "bust" : "win";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include <deque>

using namespace std;
typedef long long ll;

ll L, R, ans = 2020;

int main() {
	cin >> L >> R;
	for (ll i = L; i < R && i < L + 2019; i++) {
		for (ll j = i + 1; j <= R && j <= i + 2019; j++) {
			ans = min(ans, ((i % 2019)*(j % 2019)) % 2019);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const double EPS = 1e-7;
const int N = 20, M = 1e4+5, OO = 0x3f3f3f3f;

int a,b, c, d,e,k;

int main(){
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
    if(b-a > k || c-b > k|| c-a > k|| d-a> k ||d-b > k || d-c > k|| e-a > k|| e-b > k|| e-c > k||e-d > k){
        printf(":(");
    }else
    {
        printf("Yay!");
    }
    return 0;
}


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

#define N 50

using namespace std;

int main(){
	int fpx, ppx, px, fpy, ppy, py;
	int n;
	int sum;
	int cnt = 1;

	while(1){
		cin >> n;

		if(n == 0){
			break;
		}

		sum = 0;

		cin >> fpx >> fpy;

		ppx = fpx;
		ppy = fpy;

		for(int i = 0; i < n - 1; i ++){
			cin >> px >> py;
			sum += (ppx - px) * (ppy + py);
			ppx = px;
			ppy = py;
		}
		sum += (ppx - fpx) * (ppy + fpy);

		printf("%d %.1f\n", cnt, abs(sum) / 2.0);
		cnt ++;
	}

	return 0;
}

Measured memory_bytes: 1192
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

ll get_max_rate(const multiset<ll>& s) {
	if (s.size() == 0) return (1LL << 60LL);
	auto iter = s.end();
	--iter;

	return *iter;
}

int solve() {
	ll N;
	cin >> N;

	vector<ll> as(N);
	for (ll i = 0; i < N; ++i) {
		cin >> as[i];
	}
	sort(as.begin(), as.end());

	vector<bool> exists(1000001, false);
	ll res = 0;
	ll prev_a = -1;
	for (ll i = 0; i < N; ++i) {
		if (as[i] == prev_a) continue;
		if (exists[as[i]]) continue;
		if (i + 1 == N || as[i + 1] != as[i]) ++res;
		for (ll j = 1; as[i] * j <= 1000000; ++j) {
			exists[as[i] * j] = true;
		}
		prev_a = as[i];
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


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

int main() {
    int x;
    int n, m, l;
    cin >> n >> m >> l;

    int a[n][m];
    int b[m][l];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> x;
            a[i][j] = x;
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> x;
            b[i][j] = x;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            long sum = 0;
            for (int k = 0; k < m; k++) {
                sum += a[i][k] * b[k][j];
            }
            cout << sum;
            if (j < l-1) {
                cout << " ";
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std ;
#define N 120000
map<int,int > mp;
int a[N];
int qian[N];
int hou[N];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	qian[1]=a[1];hou[n]=a[n];
	for(int i=2;i<=n;i++){
		qian[i]=__gcd(a[i],qian[i-1]);
	}
	for(int i=n-1;i>=1;i--){
		hou[i]=__gcd(a[i],hou[i+1]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(i==1){
			ans=max(ans,hou[2]);
		}
		else if(i==n){
			ans=max(ans,qian[n-1]);
		}
		else{
			ans=max(ans,__gcd(qian[i-1],hou[i+1]));
		} 
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if (x - r >= 0 && y - r >= 0){
		if (x + r <= W&&y + r <= H){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1788
#include <queue>
#include <cstdio>
using namespace std;
main(){
	int n,m,x,y;
	scanf("%d%d",&m,&n);
	vector<vector<int> >v(m+1);
	vector<int>c(m+1);
	queue<int>q;
	for(;n--;)scanf("%d%d",&x,&y),v[x].push_back(y),c[y]++;
	for(x=1;x<=m;x++)if(!c[x])q.push(x);
	for(;!q.empty();)for(printf("%d\n",n=q.front()),q.pop(),x=0;x<v[n].size();x++)if(--c[v[n][x]]==0)q.push(v[n][x]);
}

Measured memory_bytes: 1056
#include <iostream>
#include <iomanip>
#include <cmath>
//#include <fstream>

int main(int argc, char **argv){
	//std::ifstream ifs("test.txt");
	double a = 0;
	double b = 0;
	double c = 0;
	double d = 0;
	double e = 0;
	double f = 0;

	while(std::cin >> a >> b >> c >> d >> e >> f){
	//while(ifs >> a >> b >> c >> d >> e >> f){
		double det = a * e - b * d;
		double x = (c * e - b * f) / det;
		double y = (a * f - c * d) / det;
		
		x = std::round(x * 1000) / 1000.0;
		y = std::round(y * 1000) / 1000.0;

		if(x == - 0){ x = 0; }
		if(y == - 0){ y = 0; }
		std::cout << std::fixed << std::setprecision(3) << x << " " << y << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3324
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 20)

int mmove[MAXN];
string s;
int a[MAXN];
int n, m;

int main() {
	cin >> n >> m;
	cin >> s;
	for (int i = 0; i <= n; i++) {
		a[i] = s[i] - '0';
	}
	int cur = max(0, n - m);
	while (a[cur]) {
		cur++;
	}
	mmove[n] = cur;
	
	for (int i = n - 1; i >= 0; i--) {
		int cur = i - m;
		if (a[cur] || (cur < 0)) {
			mmove[i] = mmove[i + 1];
		} else {
			mmove[i] = cur;
		}
	}
/*	for (int i = 0; i <= n; i++) {
		cerr << mmove[i] << " ";
	}
	cerr << endl;
*/
	vector<int> ret;
	int pos = n;
	while (pos != 0) {
		int nnext = mmove[pos];
		if (nnext >= pos) {
			cout << -1 << endl;
			return 0;
		}
		ret.push_back(pos - nnext);
		pos = nnext;
	}
	reverse(ret.begin(), ret.end());
	for (int i = 0; i < ret.size(); i++) {
		cout << ret[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 4168
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double x1,y1,x2,y2;
    cin >>x1>>y1>>x2>>y2;
    double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%lf\n",d);
    return 0;
}


Measured memory_bytes: 3264
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
//A - Changing a Character
int main(void){
    int n,k;
    string s;
    std::cin >> n >> k >>s;
    transform(s.begin()+k-1, s.begin()+k, s.begin()+k-1, ::tolower);
    std::cout << s << std::endl;

    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>
#include <algorithm>

using namespace std;

double calcDist(double x, double y) {
    return sqrt(x * x + y * y);
}

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

    int n;
    cin >> n;
    vector<int> a(n, 0);
    set<int> b;
    int oddCardss = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        // cout << a[i] << endl;
        if(b.count(a[i]) != 0) {
            oddCardss += 1;
        }
        b.insert(a[i]);
    }
    if(oddCardss%2 == 0) {
        cout << b.size() << endl;
    } else {
        cout << b.size() - 1 << endl;
    }



    return 0;
}


Measured memory_bytes: 5376
# ABC161D
def f(k):
    if 1 <= k <= 9:
        print(k)
    else:
        nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
        cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
        for length, begin in enumerate(cum_npi):
            if k < begin:
                found = cum_npi[length - 1]
                break
        begin = 10 ** (length - 1)
        length, begin, found
        k -= found
        x = [[]] * (length + 1)
        x[1] = list(range(1, 10))
        x

        terminate = False
        i = 1
        while True:
            #print(f"a) i = {i}  x = {x}")
            if len(x[i]): # len(x[i])
                digit = x[i][0]
                if i < length: # i, length
                    i += 1
                    x[i] = nxt[digit].copy()
                    #print(f"x) digit = {digit}  nxt[digit] = {nxt[digit]}  i = {i}  x[i] = {x[i]}")
                    #print(f"b) i = {i}  x = {x}")
                    if i == length: # i, length
                        while len(x[i]): # i, x[i]
                            k -= 1
                            #print(f"c) i = {i}  x = {x}, k = {k}")
                            if k == 0:
                                x.pop(0)
                                #print("answer =", x)
                                ans = "".join([str(j.pop(0)) for j in x])
                                print(ans)
                                terminate = True
                                break
                            else:
                                x[i].pop(0)
                            #print(f"d) i = {i}  x = {x}")
                        else:
                            #print(f"e) i = {i}  x = {x}")
                            while len(x[i]) == 0:
                                i -= 1
                                x[i].pop(0)
                        if terminate:
                            break

f(int(input()))


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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MOD = 1e9 + 7;

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

    string k;
    int d;
    cin >> k >> d;
    int n = k.size();

    // dp[i][j] = number of ways to choose i digits such that sum = j (mod d)
    vector<vi> dp(n + 1, vi(d, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            if (!dp[i][j]) continue;

            for (int v = 0; v < 10; ++v) {
                int jj = (j + v) % d;

                dp[i + 1][jj] += dp[i][j];
                if (dp[i + 1][jj] >= MOD)
                    dp[i + 1][jj] -= MOD;
            }
        }
    }

    int ans = 0;
    int cur_sum = 0;
    for (int i = 0; i < n; ++i) {
        for (int v = 0; v < k[i] - '0'; ++v) {
            int have = (cur_sum + v) % d;
            int want = d - have;
            if (want == d)
                want = 0;
            ans += dp[n - i - 1][want];
            if (ans >= MOD)
                ans -= MOD;
        }

        cur_sum += k[i] - '0';
        cur_sum %= d;
    }
    if (cur_sum == 0) {
        ++ans;
        if (ans >= MOD)
            ans -= MOD;
    }

    --ans;
    if (ans < 0)
        ans += MOD;

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


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

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> taste(N);

    for (int i = 0; i < N; i++) {
        taste.at(i) = L + i;
    }

    int S = 0;

    for (int i = 0; i < N; i++) {
        S += taste.at(i);
    }

    int t = 300;
    int k = 0;

    for (int i = 0; i < N; i++) {
        int u = taste.at(i);
        if (u < 0) {
            u = u * -1;
        }

        if (t >= u) {
            t = u;
            k = i;
        }

    }

    S -= taste.at(k);

    cout << S << endl;

}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X.sort()
x_min = X[0]
x_max = X[-1]

ans = 10**20
for xi in range(x_min, x_max+1):
  temp = 0
  for xj in X:
    temp += (xi - xj)**2
  
  ans = min(ans, temp)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
ll maxRectangleInHistogram(vector<int> &v) {
    int n = v.size();
    stack<int> s;
    vector<int> L(n), R(n);
    rep(i, 0, n) {
        while (s.size() && v[s.top()] >= v[i]) s.pop();
        L[i] = s.size() ? (s.top() + 1) : 0;
        s.push(i);
    }
    while (s.size()) s.pop();
    rrep(i, n - 1, 0) {
        while (s.size() > 0 && v[s.top()] >= v[i]) s.pop();
        R[i] = s.size() ? s.top() : n;
        s.push(i);
    }
    ll res = 0;
    rep(i, 0, n) res = max(res, 1LL * (v[i] + 1) * (R[i] - L[i] + 1));
    return res;
}
ll maxRectangle(vector<vector<int>> &v) { // 0:can use, 1:can't use
    int h = v.size();
    int w = v[0].size();

    ll res = 0;
    vector<int> vv(w, 0);
    rep(y, 0, h) {
        rep(x, 0, w) {
            if (v[y][x]) vv[x] = 0;
            else vv[x]++;
        }
        res = max(res, maxRectangleInHistogram(vv));
    }
    return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/










int H, W;
string S[2020];
int A[2020][2020];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W; rep(y, 0, H) cin >> S[y];
    rep(y, 0, H) rep(x, 0, W) {
        if (S[y][x] == '#') A[y][x] = 1;
        else A[y][x] = 0;
    }

    vector<vector<int>> v(H - 1, vector<int>(W - 1, 0));
    rep(y, 0, H - 1) rep(x, 0, W - 1) v[y][x] = A[y][x] ^ A[y + 1][x] ^ A[y][x + 1] ^ A[y + 1][x + 1];
    ll ans = maxRectangle(v);
    ans = max(ans, (ll)max(H, W));
    cout << ans << endl;
}

Measured memory_bytes: 36096
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int K;
long double P;
long double rec(const int n, const long double l, const long double r, const long double tl, const long double tr, const long double t)
{
    const long double mid = (l + r) / 2;
    if (n == K) {
        return (tl <= mid and mid <= tr) ? 1 : 0;
    }
    if (tl <= l and r <= tr) {
        return 1;
    } else if (tr < l) {
        return 0;
    } else if (tl > r) {
        return 0;
    }
    if (tr <= mid) {
        return (1 - P) * rec(n + 1, l, mid, tl, tr, t);
    } else if (mid <= tl) {
        return (1 - P) * rec(n + 1, mid, r, tl, tr, t);
    } else {
        return ((t <= mid) ? 1 - P : P) * rec(n + 1, l, mid, tl, mid, t) + ((t > mid) ? 1 - P : P) * rec(n + 1, mid, r, mid, tr, t);
    }
}

int main()
{
    cin >> K;
    long double R, L, E, T;
    cin >> R >> L >> P >> E >> T;
    const long double TL = T - E;
    const long double TR = T + E;
    cout << fixed << setprecision(15) << rec(0, R, L, TL, TR, T) << endl;

    return 0;
}

Measured memory_bytes: 3288
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75252
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define type 26

int constant(int day)//1~26 順番
{
  return day%type+1;
}
int get_random()//1~26 ランダム
{
  return rand()%type+1;
}
void cal(int select,int c[type+1],int last[type+1],int s[][type+1],int day,int sum[])
{
  int i;
  sum[day]=sum[day-1]+s[day][select];
  for(i=1;i<=type;i++){
    sum[day]-=c[i]*(day-last[i]);
  }
}
void change(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
{
  int d,t,old,total=0,i,j;
  d=rand()%D+1;
  t=rand()%type+1;
  old=schedul[d];
  schedul[d]=t;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
  //  printf("change\n");
    sum[D]=total;
  }
  else{
    schedul[d]=old;
  }
}
int main(void)
{
  int D,c[type+1],i,j;
  clock_t start,stop;
  srand((unsigned int)time(NULL));
  scanf("%d",&D);//D=365
  int s[D+1][type+1],last[type+1],sum[D+1],schedul[D+1];
  for(i=0;i<=D;i++) sum[i]=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=type;i++) scanf("%d",&c[i]);
  for(i=1;i<D+1;i++){
    for(j=1;j<=type;j++) scanf("%d",&s[i][j]);
  }
  start=clock();
  for(i=1;i<D+1;i++){
    int select;
    select=constant(i);
    last[select]=i;
    schedul[i]=select;
    cal(select,c,last,s,i,sum);
    //printf("%d\n",sum[i]);
  }
  int count=0;
  stop=start;
  while((double)(stop - start) / CLOCKS_PER_SEC<1.98){
    change(c,last,s,sum,schedul,D);
    count++;
    stop=clock();
  }
  /*
  printf("count:%d\n",count);
  printf("time:%f\n",(double)(stop - start) / CLOCKS_PER_SEC);
  printf("%d\n",sum[D]);
  printf("確認\n");
  int total=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  printf("%d\n",total);
  */

  for(i=1;i<=D;i++) printf("%d\n",schedul[i]);
  return 0;
}


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

ll a[100001];


int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; cin >> n;
    ll mx = 0;
    int mx_idx;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (mx < a[i]) {
            mx = a[i];
            mx_idx = i;
        }
    }

    sort(a, a + n, greater<>());

    ll diff_mn = LLONG_MAX, num;
    for (int i = 0; i < n; i++) {
        if (i == mx_idx) continue;
        if (diff_mn > abs(mx / 2 - a[i])) {
            diff_mn = abs(mx / 2 - a[i]);
            num = a[i];
        }
    }

    cout << mx << ' ' << num << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <cstdint>
#include <iostream>

using namespace std;

int main()
{
    int64_t h, w;
    cin >> h >> w;

    auto res = ((h + 1) / 2) * ((w + 1) / 2);
    res += (h / 2) * (w / 2);

    if (h == 1 || w == 1) {
        res = 1;
    }

    cout << res << "\n";
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int v;
    cin >> v;
    int tmp = v;
    int ans = 0, cnt = 0;
    for (int i = 1; i < n; i++)
    {
        cin >> v;
        if (v <= tmp)
        {
            cnt += 1;
            tmp = v;
        }
        else
        {
            cnt = 0;
            tmp = v;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N; cin >> N;
  ll A[N][N];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }

  bool graph[N][N];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      graph[i][j] = true;
    } 
  }
  

  bool flag = true;
  for (int k = 0; k < N; k++){
    for (int i = 0; i < N; i++){
      for (int j = 0; j < N; j++){
        if (A[i][j] > A[i][k] + A[k][j]){
          flag = false;
        }else if(A[i][j] == A[i][k] + A[k][j] && A[i][k] != 0 && A[k][j]){
          graph[i][j] = false;
        }
      }
    }
  }
  
  if (flag == false){
    cout << -1 << endl;
  }else{
    ll ans = 0;
    for (int i = 0; i < N - 1; i++){
      for (int j = i + 1; j < N; j++){
        if (graph[i][j] == true) ans += A[i][j];
      }
    }
    cout << ans << endl;
  }
  

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int N;
int A[20];
int x[20][20];
int y[20][20];
 
int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
  
int main(){
 int n;
 cin>>n;
  vector<int> V={};
 bool flg=1;
 for(int i=2;i<1000;i++){
   flg=1;
   for(int j=2;j<=sqrt(i);j++){
     if(i%j==0) flg=0;
   }
   if(flg) V.push_back(i);
 }
  
  int a[1000]={0};
  int j=0,k;
  for(int i=2;i<=n;i++){
    j=0;
    k=i;
    while(k>1){
      if(k%V[j]==0){
        a[V[j]]++;
        k/=V[j];
      }
      else{
        j++;
      }
    }
    
  }
  long long ans=1;
  for(int i=0;i<1000;i++){
    if(a[i]!=0){
      ans*=(a[i]+1);
      ans%=MOD;
    }
  }

  cout<<ans<<endl;
  
}

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

using ll = long long;
using ld = long double;

int main()
{
    int n,k,now=1;
    cin >> n >> k;
    
    for(int i = 0; i < n; i++)
    {
        if(now > k)
        {
            now+=k;
        }        
        else
        {
            now*=2;
        }        
    }
    cout << now << endl;
 
    return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
like = []
for _ in range(n):
  ka = list(map(int, input().split()))
  k = ka[0]
  a = ka[1:]
  for e in a:
    like.append(e)

ans = 0
for i in range(1, m + 1):
  if like.count(i) == n:
    ans += 1

print(ans)


Measured memory_bytes: 3060
def main():
    N, K = (int(i)for i in input().split())
    x = [int(i) for i in input().split()]
    ans = 3 * (10**8)
    
    for i in range(N-K+1):
        dist = min(abs(x[i]),abs(x[i+K-1])) + abs(x[i+K-1] - x[i])
        ans = min(ans,dist)
    print(ans)

if __name__ == "__main__":
    main()

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define forn(i , n) for(int i=0;i<n;i++)


int main(){
    int a;
    int b;
    
    cin >> a >> b;
    
    if(a == b) cout << "a" << " == " << "b" << endl;
    if(a > b) cout << "a" << " > " << "b" << endl;
    if(a < b) cout << "a" << " < " << "b" << endl;
    return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>
int main()
{
  int n ;
  scanf("%d",&n) ;

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

  for( i=0 ; i<n ; i++ ){
    if( i>0 ){
      printf(" ") ;
    }
    printf("%d",a[n-1-i]) ;
  }
  printf("\n") ;

  return 0;
}


Measured memory_bytes: 2036
import collections

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

result = 0
ai = [0]*n
aj = [0]*n

for i in range(n):
    ai[i] = a[i]+i+1
    aj[i] = i+1-a[i]
aj_num = collections.Counter(aj)
    
for i in range(n-1):
    aj_num[aj[i]] -= 1
    result += aj_num[ai[i]]
    
print(result)

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

#define ll long long
using namespace std;
const int N = 200 + 9;
ll mod = 1e9L + 9;

const int MAX_VALUE = 1e5;
const ll OO = 1e13;

void test() {
    int n, w;
    cin >> n >> w;
    vector<ll> weights(n), values(n);
    for (int i = 0; i < n; i++)cin >> weights[i] >> values[i];
    /*
     * dp[i]= min weight ale ana h4eloh 3l4an awsl value i
     *
     *   15 ,3
     *   value => 10
     *   value => 7 +3  => dp[10] =min(dp[i],dp[i-cur_val]+cur_weg)
     */
    vector<ll> dp(MAX_VALUE + 1, OO);
    dp[0] = 0;
    for (int item = 0; item < n; item++) {
        int cur_w = weights[item], cur_v = values[item];
        for (int value = MAX_VALUE; value >= cur_v; value--) {
            dp[value] = min(dp[value], dp[value - cur_v] + cur_w);
        }
    }
    ll ans = 0;
    for (int i = MAX_VALUE; i >= 0; i--) {
        if (dp[i] <= w) {
            ans = i;
            break;
        }
    }
    cout<<ans<<endl;

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //    freopen("input.in", "r", stdin);
    int t = 1;
//    cin >> t;
//    scanf("%d", &t);
    for (int cas = 1; cas <= t; cas++) {
//        printf("Case %d: ", cas);
        test();
    }
}

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

int main() {
    int X; cin >> X;
    if (400 <= X && X <= 599) {
        cout << 8 << endl;
    } else if (600 <= X && X <= 799) {
        cout << 7 << endl;
    } else if (800 <= X && X <= 999) {
        cout << 6 << endl;
    } else if (1000 <= X && X <= 1199) {
        cout << 5 << endl;
    } else if (1200 <= X && X <= 1399) {
        cout << 4 << endl;
    } else if (1400 <= X && X <= 1599) {
        cout << 3 << endl;
    } else if (1600 <= X && X <= 1799) {
        cout << 2 << endl;
    } else {
        cout << 1 << endl;
    }
    
}

Measured memory_bytes: 3632
#include <cstdio>

using namespace std;
typedef long long llong;

#define MAX
const llong mod = 1000000000 + 7;

int main()
{
  char S[3];
  scanf("%s", S);
  if (S[0] == 'A' && S[1] == 'A' && S[2] == 'A')
    printf("No\n");
  else if (S[0] == 'B' && S[1] == 'B' && S[2] == 'B')
    printf("No\n");
  else
    printf("Yes");
  return 0;
}

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

using namespace std;

int main (){
    
    string s = "";
    cin >> s;
    size_t size = s.length();
    int h = size;

    if (h % 2 == 1){
        cout << "No" << endl;
    } else {
        int n = h / 2;
        int suc = 0;
        for (int i = 0; i < n; i++){
            string d = s.substr(i * 2, 2);
            if (d != "hi"){
                break;
            }
            if (i == n - 1){
                suc = 1;
            }
        }
        if (suc == 1){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

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

int main(){
	int n, q;
	cin >> n >> q;
	queue< pair<string, int> > que;
	for (int i=0; i<n; i++){
		string name;
		int t;
		cin >> name >> t;
		que.push(make_pair<string, int>(name, t));
	}
	int count = 0;
	while(!que.empty()){
		pair<string, int> p = que.front();
		que.pop();
		if (p.second <= q){
			count += p.second;
			cout << p.first << " " << count << endl;
		}
		else{
			p.second -= q;
			count += q;
			que.push(p);
		}
	}
	return 0;
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M,x; cin>>N>>M;
	multiset<int> A;
	for (int i=0; i<N; i++)
		cin>>x, A.insert(x);
	vector<ii> v(M);
	for (int i=0; i<M; i++)
		cin>>v[i].second>>v[i].first;
	sort(v.rbegin(),v.rend());
	int iter=0;
	for (int i=0; i<M; i++) {
		for (int j=0; j<v[i].second; j++) {
			if(iter==N)
				break;
			A.insert(v[i].first); iter++;
		}
	}
	ll ret=0;
	while(N--) {
		int cur=*A.rbegin();
		ret+=cur; A.erase(A.find(cur));
	}
	cout<<ret<<"\n";
	return 0;
}


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

typedef long long ll;
using namespace std;
const int maxn = 1e6+5;
void tlfclwx()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}


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


Measured memory_bytes: 256
#include<stdio.h>
#define SMAX 10001
#define TMAX 500
#define FOUND 1
#define NOT_FOUND 0

int search(int *, int, int);

int main(){
  int n, q, cnt = 0;
  int s[SMAX], t[TMAX];
  int i;

  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]);
    cnt += search(s, t[i], n);
  }

  printf("%d\n", cnt);
  
  return 0;
}

int search(int *s, int key, int n){
  int i = 0;
  s[n] = key;
  while(s[i] != key){
    i++;
    if(i == n) return NOT_FOUND;
  }
  return FOUND;
}



Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func main() {
	scanner.Split(bufio.ScanWords)

	dist := nextInts(3)
	sort.Sort(sort.IntSlice(dist))

	fmt.Println(dist[0] + dist[1])
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main() {
    int n;
    cin >> n;
    if (n % 2 != 0) {
        cout << "No";
        return 0;
    }
    string s;
    cin >> s;
    string a = s.substr(0, n / 2);
    string b = s.substr(n / 2);
    cout << ((a == b) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans,x=0,n
for i in a:
	ans+=b[i-1]
	if x==i-1:
		ans+=c[x-1]
	x=i
print(ans)

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

typedef long long ll;
typedef long double ld;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll k,n,ans=INT64_MAX,f,b;
    cin>>k>>n;
    vector<ll> v(n);
    for(auto &x:v)cin>>x;
    for(int i=0;i<n;i++){
        f=v[n-1]-v[i];
        if(i!=0)f+=k+v[i-1]-v[n-1];
        b=v[i]-0;
        if(i!=n-1)b+=k-v[i+1];
        ans=min(ans,min(f,b));
    }
    cout<<ans<<endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define M 1000000007
int main()
{
	ll n,m,num;
	cin >> n>>m;
	while(m--){
		cin >> num;
		n=n-num;
	}
	if(n<0)
		cout << "-1";
	else
		cout << n << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int x,a;
    cin>>x>>a;
    cout<<(x<a?0:10)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int Min(int,int);

int main(){
  int n,i,j,k,l;
  int f[101],s[101][101];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&f[i-1],&f[i]);
  }
  for(i=1;i<=n;i++){
    s[i][i]=0;
  }
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      s[i][j]=1E+9;
      for(k=i; k<=j-1;k++){
    s[i][j] = Min(s[i][j],s[i][k]+s[k+1][j]+f[i-1]*f[k]*f[j]);
      }
    }
  }
    printf("%d\n",s[1][n]);
    return 0;
}

int Min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}



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

int main(){
	int m,n,count,x;
	while(1){
	cin >> m >> n;
	if(m == 0)break;
	count = 0;
	x = m;
	bool a[8000000] = {};
	while(count != n){
		if(!a[x]){
			for(int i = 1;i*x < 8000000;i++){
				a[i * x] = true;
			}
			count++;
		}
		x++;
	}
	while(1){
		if(!a[x])break;
		x++;
	}	
	cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 10900
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[201];
    char t[101];
    char p[101];
    scanf("%s", s);
    scanf("%s", p);
 
    strcpy(t, s);
    strcat(s, t);
 
    if (strstr(s, p) == NULL){
        printf("No");
    }else{
        printf("Yes");
    }
    printf("\n");
     
    return 0;
}

Measured memory_bytes: 552
#include<stdio.h>

#define Max 100
#define Infty (1<<21)
#define W 0
#define G 1
#define B 2

int n, m[Max][Max];

int prim(){
  int i, u, minv, v;
  int d[Max], p[Max], color[Max];

  for(i = 0 ; i < n ; i++){
    d[i] = Infty;
    p[i] = -1;
    color[i] = W;
  }

  d[0] = 0;

  while(1){
    minv = Infty;
    u = -1;

    for(i = 0 ; i < n ; i++){
      if(minv > d[i] && color[i] != B){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = B;
    for(v = 0 ; v < n ; v++){
      if(color[v] != B && m[u][v] != Infty){
	if(d[v] > m[u][v]){
	  d[v] = m[u][v];
	  p[v] = u;
	  color[v] = G;
	}
      }
    }
  }
  int sum = 0;
  for(i = 0 ; i < n ; i++){
    if(p[i] != -1) sum += m[i][p[i]];
  }

  return sum;
}


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

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      scanf("%d", &e);
      m[i][j] = (e == -1) ? Infty : e;
    }
  }

  printf("%d\n", prim());

  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

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

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    ll l, r;
    cin >> l >> r;
    if (r - l >= 2019) {
        std::cout << 0 << '\n';
        return 0;
    }
    if (r % 2019 < l % 2019) {
        std::cout << 0 << '\n';
        return 0;
    }
    l = l % 2019;
    r = r % 2019;
    int mini = 1e9;
    REP2(i, l, r) REP2(j, i+1, r+1) {
        mini = min(mini, i*j%2019);
    }
    std::cout << mini << '\n';

    return 0;
}


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

const int INF = 2000000000;

int dp[100010];
int h[100010];

int main()
{
    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
    {
        cin >> h[i];
    }
    for (int i = 2; i <= N; i++)
    {
        int min = INF;
        for (int j = max(1, i - K); j < i; j++)
        {
            if ((dp[j] + abs(h[i] - h[j])) < min)
            {
                min = dp[j] + abs(h[i] - h[j]);
            }
        }
        dp[i] = min;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
n= int(input())
a=[]
a=list(map(int, input().split()))


if 0 in a :
    print(0)
    exit() ##インタラクティブシェルを終了させる関数

y=1
for i in range(n):
   y*=a[i]
   if(y>10**18):
       print(-1)
       exit()
print(y)

Measured memory_bytes: 21648
from collections import Counter

n = int(input())
num_list = list(map(int,input().split()))
plus_list  = [num+1 for num in num_list]
minus_list = [num-1 for num in num_list]
result_list = num_list+plus_list+minus_list
result_cntr = Counter(result_list).most_common()
print(result_cntr[0][1])

Measured memory_bytes: 32964
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){
    double x1,y1,x2,y2,x3,y3,a,b;
    while(cin>>x1){
        cin>>y1>>x2>>y2>>x3>>y3>>a>>b;
        double c=abs((x1-a)*(y2-b)-(x2-a)*(y1-b))/2;
        double d=abs((x2-a)*(y3-b)-(x3-a)*(y2-b))/2;
        double e=abs((x1-a)*(y3-b)-(x3-a)*(y1-b))/2;
        double f=abs((x1-x3)*(y2-y3)-(x2-x3)*(y1-y3))/2;
        if(f==c+d+e){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        
        
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3052
//Integer Cards

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, ll>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m;cin>>n>>m;
    priority_queue<int,vector<int>,greater<int>>a;
    rep(i,0,n){
        int c;cin>>c;
        a.push(c);
    }
    vector<p>memo;
    priority_queue<int>yo;
    rep(i,0,m){
        int b,c;cin>>b>>c;
        memo.pb(mp(c,b));
    }
    sort(range(memo));
    for(int i=memo.size()-1;i>=0;i--){
        int b=memo[i].second,c=memo[i].first;
        if(yo.size()>n)break;
        rep(i,0,b){
            yo.push(c);
            if(yo.size()>n)break;
        }
    }
    int ans = 0;
    while(!a.empty()){
        int c = a.top();
        a.pop();
        if(yo.empty()||c>=yo.top()){
            ans+=c;
        }else{
            ans+=yo.top();
            yo.pop();
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 7428
/**
 *  author: mahfuzz
 *  created: 13.04.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << "\n"
typedef long long ll;


int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n, m; cin >> n >> m;
    
    double arr[n+1], sum = 0.;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    
    double x = ceil(sum / (4 * m));
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] < x)
            continue;
        ++cnt;
    }
    
    cout << (cnt >= m ? "Yes\n" : "No\n");
    
    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())

    heights = [int(x) for x in input().split()]

    dp = [float('inf')] * N
    dp[0] = 0

    for i in range(N):
        for j in [i+1, i+2]:
            if j < N:
                dp[j] = min(dp[j], dp[i] + abs(heights[i] - heights[j]))

    print(dp[-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	int n;
	cin >> n;
	v64 arr(n, 0);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	map<ll, ll> hashMap1;
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ll temp = i - arr[i];
		ans += hashMap1[temp];
		hashMap1[i + arr[i]]++;
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


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


ll f(ll H){
  if(H==1) return 1;
  
  return 2*f(H/2) +1;
}

int main(){
  ll H;cin>>H;
  cout<<f(H)<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  string s;
  cin>>s;
  s[5]=' ';
  s[13]=' ';
  cout<<s<<endl;
}

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

using namespace std;

int main()
{
  string T, P;

  cin >> T;
  cin >> P;

  vector< int > latte[26];
  for(int i = 0; i < T.size(); i++) {
    latte[T[i] - 'a'].push_back(i);
  }

  vector< int > beet(P.size(), -1);
  int last = 0;
  for(int i = 0; i < P.size(); i++) {
    auto &p = latte[P[i] - 'a'];
    auto q = lower_bound(begin(p), end(p), last);
    if(end(p) == q) {
      cout << "no" << endl;
      return (0);
    }
    beet[i] = *q;
    last = *q + 1;
  }

  last = T.size() - 1;
  for(int i = P.size() - 1; i >= 0; i--) {
    auto &p = latte[P[i] - 'a'];
    auto q = upper_bound(begin(p), end(p), last);

    if(begin(p) == q) {
      cout << "no" << endl;
      return (0);
    }
    --q;

    if(beet[i] != *q) {
      cout << "no" << endl;
      return (0);
    }
    last = *q - 1;
  }

  cout << "yes" << endl;

}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c;
    cin >> n >> m >> c;
    int b[20], a[20][20];
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < m; j++) {
            sum += a[i][j] * b[j];
        }
        if (sum + c > 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

void Print(vector<int> v)
{
  for(auto i: v)
  {
    cout << i << ' ';
  }
  cout << endl;
}

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

  vector<int> P(n);
  vector<int> Q(n);
  for (int i = 0; i < n; i++) cin >> P.at(i);
  for (int i = 0; i < n; i++) cin >> Q.at(i);

  vector<int> V(n);
  for (int i = 0; i < n; i++) V.at(i) = i+1;
  int count = 1;
  int orderP, orderQ;
  do {
    if(P == V) orderP = count;
    if(Q == V) orderQ = count;
    count++;
  } while (next_permutation(V.begin(), V.end()));
  int dif = orderP - orderQ;
  if (dif < 0) cout << -dif << endl;
  else cout << dif << endl;
}


Measured memory_bytes: 256