akhauriyash/Code-Regression huggingface dataset:
class SegmentTree
  def initialize(nums)
    return if nums.nil? || nums.empty?
    size = nums.size
    @n = 1
    while @n < size
      @n *= 2
    end
    @a = Array.new(@n*2-1){new_obj}

    size.times do |i|
      @a[@n + i - 1] = new_obj(nums[i])
    end
    (@n-2).downto(0) do |i|
      @a[i] = compare(@a[i*2+1], @a[i*2+2])
    end
    # p ['initialize', @a]
  end

  def update(i, val)
    i += @n - 1
    @a[i] = new_obj(val)
    while i > 0
      i = (i-1)/2
      @a[i] = compare(@a[i*2+1], @a[i*2+2])
    end
    # p ['update', @a]
  end

  def query(a, b, k=0, l=0, r=-1)
    r = @n-1 if r < 0
    # p [[a,b],k,[l,r], b <= l || r <= a, a <= l && r <= b]
    return new_obj if b < l || r < a # not cover
    return @a[k]   if a <= l && r <= b # cover all

    lvalue = query(a, b, 2*k+1, l, (l+r)/2)
    rvalue = query(a, b, 2*k+2, (l+r)/2+1, r)
    return compare(lvalue, rvalue)
  end

  def compare(x, y)
    x | y
  end

  def new_obj(obj=0)
    obj
  end
end

require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
s = gets.chomp
q = gets.chomp.to_i

init_a = Array.new(n)
n.times do |i|
  cnum = s[i].ord - 97
  init_a[i] = 1 << cnum
end

st = SegmentTree.new(init_a)
q.times do
  type, i, c = gets.chomp.split

  if type == '1'
    st.update(i.to_i - 1, 1 << (c.ord - 97))
  else
    r = st.query(i.to_i - 1, c.to_i - 1)
    puts r.to_s(2).split(//).map{|num| num.to_i}.inject(&:+)
  end
end


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

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        char[] str = scanner.next().toCharArray();
        if (n % 2 == 1) out.println("No");
        else {
            boolean bad = false;
            for(int i = 0; i < n/2; i++) {
                if (str[i] != str[i + n/2]) bad = true;
            }
            if (bad) out.println("No");
            else out.println("Yes");
        }
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

f([X|Xs],[Y|Ys],1) :- Xs = Ys, to_lower(Y, C), char_code(C2, C), X = C2.
f([X|Xs],[Y|Ys],I) :- X = Y, I2 is I - 1, f(Xs, Ys, I2).

main :-
    get_number(N),
    get_number(K),
    get_string(S),
    string_chars(S, S2),
    f(Xs, S2, K),
    string_chars(S3, Xs),
    writeln(S3).


Measured memory_bytes: 8060
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if(a <= c && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(a,j,n) for(ll i=a;i<j;i=i+n )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    string s;
    cin>>s;
    ll q;
    cin>>q;
    ll rev=1;
    string sa="",sb="";
    
    for(ll j=0;j<q;j++){
        ll t;
        cin>>t;
        if(t==1)rev*=-1;
        else{
            ll f;
            char c;
            cin>>f>>c;
            if(rev==1&&f==1)sa=c+sa;
            else if(rev==1&&f==2)sb=sb+c;
            else if(rev==-1&&f==1)sb=sb+c;
            else sa=c+sa;
        }
        
    }
    if(rev==1)cout<<sa<<s<<sb;
    else{
        reverse(sa.begin(),sa.end());
        reverse(s.begin(),s.end());
        reverse(sb.begin(),sb.end());
        cout<<sb<<s<<sa;
    }
    cout<<endl;

}


Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	string A, B;
	cin >> A >> B;

	int ans = 0;

	for (int i = 0; i < 3; i++) {
		if (A[i] == B[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        string prev, curr;
        map<string, ll> m;
        for(i = 0; i < n; i++){
            cin >> curr;
            if(m[curr] == 1){
                cout << "No";
                return 0;
            }
            m[curr] = 1;
            if(i > 0){
                if(prev[prev.size() - 1] != curr[0]){
                    cout << "No";
                    return 0;
                }
            }
            prev = curr;
        }
        cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>

int main(void){
	int i, j;
	
	for(i = 1; i <= 9; i++){
		for(j = 1; j <= 9; j++){
			
			printf("%dx%d=%d\n",i, j, i * j);
			
		}
	}
	return 0;
}

Measured memory_bytes: 524
def main():
  r=input()
  l=len(r)-1
  k = int(r)
  s=0
  for i in range(0,l):
    s=(s*10+7)
  for i in range(l,k):
    s=(s*10+7)%k
    if s==0:
      print(i+1)
      exit()
  print(-1)
main()

Measured memory_bytes: 9100
function main(input) {
  const arr = input.split(" ")
  const x = Math.ceil(arr[0] / arr[1]) * arr[2];
  const y = Math.ceil(arr[0] / arr[3]) * arr[4];

  x > y ? console.log(y) : console.log(x);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    char x,y;
    cin >> x >> y;
    if(x == y){
        cout << "=" << endl;
    }else if(x < y){
        cout << "<" << endl;
    }else{
        cout << ">" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //__gnu_pbds::gp_hash_table<int, int> table;
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;  //min heap

typedef int OwO;
typedef double UwU;

#define int long long
#define double long double
#define INF 1000000000
#define PI 3.14159265358979323846
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vi vector<int>

using namespace std;

vi coloring;
vi visited;

void dfs(vector<vector<pair<int, int>>>& graph, int x, int sum){
//  watch(x);
//  watch(sum);
//  cout << endl;
  if(visited[x])
    return;
  visited[x]=1;

  if(sum%2==0)
    coloring[x]=0;

  for(auto e:graph[x]){
    int to = e.first;
    int w = e.second;
    dfs(graph, to, sum+w);
  }
   return;
}


OwO main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> graph(N, vector<pair<int, int>>());
  coloring = vector<int>(N, 1);
  visited = vector<int>(N, 0);
  for(int x = 0; x<N-1; x++){
    int u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v,w});
    graph[v].push_back({u,w});
  }
  dfs(graph, 0, 0);

  for(auto e: coloring)
    cout << e << endl;

  return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1234567;

const int N = 303;
const int M = 634;
int dp[N][M];
int nx[N][M];

int main(){
    int n,x,y;
    cin >>n >>x >>y;

    rep(j,N)rep(k,M) dp[j][k] = -INF;
    dp[x][N+y] = 0;

    rep(i,n){
        int a,b,c,d;
        cin >>a >>b >>c >>d;

        rep(j,N)rep(k,M) nx[j][k] = dp[j][k];
        rep(j,N)rep(k,M){
            if(j-a>=0 && k+b<M) nx[j-a][k+b] = max(nx[j-a][k+b], dp[j][k]);
            if(k-c>=0) nx[j][k-c] = max(nx[j][k-c], dp[j][k]+d);
        }

        rep(j,N)rep(k,M) dp[j][k] = nx[j][k];
    }

    int ans = 0;
    rep(i,N)for(int j=N; j<M; ++j) ans = max(ans, dp[i][j]);
    cout << ans << endl;
    return 0;
}



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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

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

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long ans = 0, rem = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) && rem) A.at(i)--, rem--, ans++;
    rem = 0;
    ans += A.at(i) / 2;
    A.at(i) %= 2;
    rem = A.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3728
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  vector< int > a[26], b[26];
  for(int i = 0; i < s.length(); i++){
    a[t[i] - 'a'].push_back(i);
    b[s[i] - 'a'].push_back(i);
  }

  bool ans = true;
  for(int i = 0; i < 26; i++){
    if(a[i].empty()) continue;
    if(a[i].size() != b[s[a[i][0]] - 'a'].size()){
      ans = false;
      break;
    }
    for(int j = 0; j < a[i].size(); j++){
      if(a[i][j] != b[s[a[i][0]] - 'a'][j]){
        ans = false;
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 3068
const fs = require('fs');

function main(input) {
  var s = input.trim();
  var set = new Set(s);
  
  if (set.size == 1) {
    var res = 'No';
  } else {
    var res = 'Yes';
  }
  console.log(res);
}

input = fs.readFileSync('/dev/stdin', 'utf8');
main(input);

Measured memory_bytes: 7372
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A <= B:
  print('YES' if (A + V * T) >= (B + W * T) else 'NO')
else:
  print('YES' if (A - V * T) <= (B - W * T) else 'NO')

Measured memory_bytes: 9184
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define INF 100000000
using namespace std;


int main() {
    int k, s, ans = 0;
    cin >> k >> s;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (0 <= z&&z <= k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
string s;
int dp[234567][10];
signed main() {
	cin >> s;
	int n = s.size();
	dp[0][1] = 1; dp[0][2] = 0;
	dp[1][1] = (s[0] != s[1]) * 2; dp[1][2] = 1;
	for (int i = 2; i < n; i++) {
		if (s[i] != s[i - 1])dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]) + 1;
		else dp[i][1] = dp[i - 1][2] + 1;
		dp[i][2] = dp[i - 2][1] + 1;
	}
	cout << max(dp[n - 1][1], dp[n - 1][2]) << endl;
}

Measured memory_bytes: 16900
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	int pos;
	double t,a,h[1003];
	double val,min = 200000.00;
	scanf("%d",&n);
	scanf("%lf%lf",&t,&a);
	for (int i = 0; i < n; ++i)
	{
		scanf("%lf",&h[i]);
		if((val = fabs(t - h[i] * 0.0060 - a)) < min){
			min = val;
			pos = i;
		}
	}
	printf("%d\n", pos + 1);

}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();

        int cnt = 0;
        long sum = 0L;
        for (int i=1;i<30000;i++) {
            if (i%2==0 || i%3==0 || i%5==0) {
                set.add(i);
                sum+=i;
                cnt++;
            }
            if (cnt==N-2) break;
        }

        for (int i=1;3*i<30000;i++) {
            if (set.contains(3*i)) continue;
            if ((sum+3*i)%5!=0) continue;
            set.add(3*i);
            sum+=3*i;
            break;
        }

        for (int i=1;5*i<30000;i++) {
            if (set.contains(5*i)) continue;
            if ((sum+5*i)%3!=0 || (sum+5*i)%2!=0) continue;
            set.add(5*i);
            sum+=5*i;
            break;
        }

        ArrayList<Integer> ans = new ArrayList<Integer>(set);
        for (int i=0;i<ans.size();i++) {
            if (i!=ans.size()-1) {
                System.out.print(ans.get(i));
            } else {
                System.out.println(ans.get(i));
            }
            if (i!=ans.size()-1) System.out.print(" ");
        }
        // System.out.println(set);
    }
}

Measured memory_bytes: 29584
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<pair<int, int>> a(n);
    for (auto i = 0; i < n; i++) cin >> a[i].first >> a[i].second;

    sort(a.begin(), a.end());
    int64_t ans = 0; int i = 0;
    while (m > 0) {
        ans += (int64_t)a[i].first * min(a[i].second, m);
        m -= a[i].second;
        i++;
    }

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


Measured memory_bytes: 1024
import sys

N, K = map(int, input().split())
candles = list(map(int, input().split()))

ans = sys.maxsize

for i in range(N-K+1):
    minNum = candles[i]
    maxNum = candles[i+K-1]
    l = abs(minNum) + abs(minNum - maxNum)
    r = abs(maxNum) + abs(maxNum - minNum)
    ans = min(ans, min(l, r))

print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <queue>

#define MAX_RANGE 500

struct POS
{
	int X,Y,far;
};

POS move(POS &now, POS &power)
{
	POS ans = {now.X+power.X, now.Y+power.Y, now.far+1};
	return ans;
}
bool eq(POS &a, POS &b){return a.X == b.Y && a.Y == b.Y;}

POS mpow[6]={{0,1},{1,1},{1,0},{0,-1},{-1,-1},{-1,0}};
bool list[MAX_RANGE][MAX_RANGE];

int movenum(POS &start, int t, int n);

int main()
{
	int t,n,x,y;
	POS start;
	while(true){
		std::cin >> t >> n;
		if(t == 0 && n == 0) break;
		for(int i=0; i<MAX_RANGE; i++)
			for(int j=0; j<MAX_RANGE; j++) list[i][j] = false;
		for(int i=0; i<=n; i++){
			std::cin >> x >> y;
			list[x+MAX_RANGE/2][y+MAX_RANGE/2] = true;
		}
		start.X = x;
		start.Y = y;
		start.far = 0;
		std::cout << movenum(start, t, n) << std::endl;
	}
	return 0;
}

int movenum(POS &start, int t, int num)
{
	int n = num, mnum=1;
	POS now = start;
	std::queue<POS> q;
	for(;;){
		if(now.far != t){
			for(int j=0; j<6; j++){
				POS s = move(now, mpow[j]);
				if(!list[s.X+MAX_RANGE/2][s.Y+MAX_RANGE/2]){
					mnum++;
					list[s.X+MAX_RANGE/2][s.Y+MAX_RANGE/2] = true;
					q.push(s);
				}
			}
		}
		if(q.empty()) break;
		now = q.front();
		q.pop();
	}
	return mnum;
}

Measured memory_bytes: 1464
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void pr(int x, int y, int a, int b){
  cout << x << ' ' << y << ' ' << a << ' ' << b;
}
void solve(){
  int x, y, a, b;
  cin >> x >> y >> a >> b;
  int d1 = a - x;
  int d2 = b - y;
  pr(a - d2, b + d1, x - d2, y + d1);
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

 */

Measured memory_bytes: 256
A = list(map(int , input().split()))
sc = [list(map(int, input().split())) for i in range(A[1])]
a = []
b = []
for i in sc:
    a.append(i[0])
    b.append(i[1])
if max(a) <= min(b):
    ans = min(b) - max(a) + 1
else:
    ans = 0
print(ans)

Measured memory_bytes: 29092
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, xyh: [(i64, i64, i64); n]);
    for cx in 0..101 {
        for cy in 0..101 {
            let mut real_h = -1;
            let mut ok = true;
            for &(x, y, h) in xyh.iter() {
                if h == 0 {
                    continue;
                }
                let t = (x - cx).abs() + (y - cy).abs();
                if real_h == -1 {
                    real_h = h + t;
                } else if real_h != h + t {
                    ok = false;
                    break;
                }
            }
            if !ok || real_h <= 0 {
                continue;
            }
            for &(x, y, h) in xyh.iter() {
                let obs = cmp::max(real_h - (x - cx).abs() - (y - cy).abs(), 0);
                if obs != h {
                    ok = false;
                }
            }
            if ok && real_h > 0 {
                println!("{} {} {}", cx, cy, real_h);
                return;
            }
        }
    }

    unreachable!();
}


Measured memory_bytes: 4352
def resolve():
    n = int(input())
    p = list(map(int,input().split()))
    ans = 0
    for i in range(n-2):
        if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
            ans = ans + 1
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function iter(d::Int, pc::Array{Int, 2}, g::Int)
    if g <= 0 return(0) end
    ret = typemax(Int)
    for i in d:-1:1
        if pc[i,1]==0 continue end
        if g <= pc[i,1] * 100i
            ret = min(ret, ceil(Int, g / 100i))
        else
            pcNext = copy(pc)
            pcNext[i, 1] = 0
            ret = min(ret, pc[i,1] + iter(d, pcNext, g - ((100i * pc[i,1]) + pc[i,2])))
        end
    end
    return(ret)
end

function main()
    d, g = readline() |> split |> parseMap

    pc = zeros(Int, d, 2)
    for i in 1:d
        pc[i, 1], pc[i, 2] = readline() |> split |> parseMap
    end

    ans = iter(d, pc, g)
    println(ans)

end

main()


Measured memory_bytes: 175896
n=int(input())
a=list(map(int,input().split()))
s=sum(a)//n
ans_1=0
ans_2=0
for i in range(n):
    ans_1+=(a[i]-s)**2
    ans_2+=(a[i]-s-1)**2
print(min(ans_1,ans_2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            swap(a,b);
            u-=t*v;
            swap(u,v);
        }
        return ModInt(u);
    }
    friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend istream &operator>>(istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};

const int mod=1e9+7;
using mint=ModInt<mod>;
int main(){
    int n;
    cin>>n;
    string st;
    cin>>st;
    map<char,int> ma;
    REP(i,n){
        ma[st[i]]++;
    }
    mint ans=1;
    for(auto itr:ma){
        ans*=itr.se+1;
    }
    cout<<ans-1<<endl;
    return 0;
}

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

int main(){
    
    int n, k;
    
    while(cin >> n >> k, n || k){
        int a[111111] = {0};
        
        for(int i = 0; i < k; i++){
            int tmp; cin >> tmp;
            a[tmp]++;
        }
        
        int dp[2][111111] = {0};
        for(int i = 1; i <= n; i++){
            if(a[i]){
                dp[0][i] = dp[0][i - 1] + 1;
                dp[1][i] = dp[1][i - 1] + 1;
            }
            else{
                dp[0][i]  = 0;
                dp[1][i] = dp[0][i - 1] + 1;
            }
        }
        cout << *max_element(dp[a[0]] + 1, dp[a[0]] + n + 1) << endl;
    }
}

Measured memory_bytes: 2468
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func rs() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	var h, w int
	fmt.Scan(&h, &w)

	for i := 0; i < h; i++ {
		c := rs()
		fmt.Println(c)
		fmt.Println(c)
	}
}


Measured memory_bytes: 640
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()

k -= 1
if s[k]=='A':
  ans = s[0:k] + "a" + s[k+1:n]
elif s[k]=='B':
  ans = s[0:k] + "b" + s[k+1:n]
elif s[k]=='C':
  ans = s[0:k] + "c" + s[k+1:n]

print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, N) for (int i = 0; i < (N); i++)
#define REP(i, a, N) for (int i = a; i < (N); i++)
#define rrep(i, N, k) for (int i = (N); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), sum(N);
    cin >> A;
    sum[0] = A[0];
    for (int i = 1; i < N; i++) sum[i] = sum[i - 1] + A[i];
    auto calc = [&](int left, int right) {
        ll allSum = sum[right];
        ll minus = 0;
        if (left != 0) minus = sum[left - 1];
        while (right - left > 1) {
            int mid = left + (right - left) / 2;
            ll leftSum = sum[mid] - minus;
            ll rightSum = allSum - leftSum - minus;
            if (leftSum < rightSum) left = mid;
            else right = mid;
        }
        ll leftSum = sum[left] - minus;
        ll rightSum = allSum - leftSum - minus;
        return make_pair(left, right);
    };
    ll ans = INFLL;
    for (int i = 1; i + 2 < N; i++) {
        auto left = calc(0, i);
        auto right = calc(i + 1, N - 1);
        for (int a = 0; a <= 1; a++) {
            if (left.first + a >= i) continue;
            for (int b = 0; b <= 1; b++) {
                if (right.first + b >= N - 1) continue;
                vector<ll> temp(4);
                temp[0] = sum[left.first + a];
                temp[1] = sum[i] - temp[0];
                temp[2] = sum[right.first + b] - (temp[0] + temp[1]);
                temp[3] = sum[N - 1] - (temp[0] + temp[1] + temp[2]);
                sort(temp.begin(), temp.end());
                ans = min(ans, temp[3] - temp[0]);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

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

	int okIndex = -1;

	if (S.size() < T.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (size_t i = 0; i <= S.size() - T.size(); i++) {
		bool isOK = true;
		string sb = S.substr(i, T.size());
		for (size_t j = 0; j < T.size(); j++) {
			if (sb[j] != T[j] && sb[j] != '?') {
				isOK = false;
			}
		}
		if (isOK) {
			okIndex = i;
		}
	}

	if (okIndex != -1) {
		for (size_t k = 0; k < S.size(); k++) {
			if ((size_t)okIndex <= k && k < okIndex + T.size()) {
				cout << T[k - okIndex];
			} else if (S[k] == '?') {
				cout << 'a';
			} else {
				cout << S[k];
			}
		}

		cout << "\n";

		return 0;
	}

	cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
k = int(input())

lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(lst[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

void outputVector(const vector<int> &array, const char delim = ' ')
{
	for(size_t i = 0; i < array.size(); i++)
	{
		if(i != 0){ cout << delim; }
		cout << array[i];
	}
	cout << endl;
}


int main()
{
    int r, c;
    cin >> r >> c;

    typedef vector<int> VI;
    vector<VI> v(r + 1, VI(c + 1, 0));

    for(int i = 0; i < r; i++)
    {
        for(int j = 0; j < c; j++)
        {
            cin >> v[i][j];
        }
    }

    for(int i = 0; i < r; i++)
    {
        for(int j = 0; j < c; j++)
        {
            v[i][c] += v[i][j];
            v[r][j] += v[i][j];
        }
        v[r][c] += v[i][c];
    }
    for(int i = 0; i <= r; i++)
    {
        outputVector(v[i]);
    }
    return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    int a, b, n; cin>>a>>b>>n;
    int ans = 0;
    while(n--){
        int s, f; cin>>s>>f;
        if(f <= a || b <= s) continue;
        ans = 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int N;
	cin >> N;
	vector<int>X(N);
	rep(i, N) {
		cin >> X[i];
	}
	vector<int>Y(N);
	rep(i, N) {
		Y[i] = X[i];
	}
	sort(X);
	int a = X[N / 2 - 1];
	int b = X[N / 2];
	rep(i, N) {
		if (Y[i] <= a) {
			cout << b << endl;
		}
		else {
			cout << a << endl;
		}
	}
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

int main()
{
	cout << fixed << setprecision(18);

	string s;

	cin >> s;

	while (!s.empty())
	{
		if (s.size() > 10 && s.substr(0, 7) == "dreamer" && s.substr(5, 5) != "erase")
			s.erase(0, 7);
		else if (s.size() == 7 && s == "dreamer")
			s.erase(0);
		else if (s.size() > 10 && s.substr(0, 6) == "eraser" && s.substr(5, 5) != "ereas")
			s.erase(0, 6);
		else if (s.size() == 6 && s == "eraser")
			s.erase(0);
		else if (s.size() > 4 && s.substr(0, 5) == "erase")
			s.erase(0, 5);
		else if (s.size() > 4 && s.substr(0, 5) == "dream")
			s.erase(0, 5);
		else
			break;
	}

	if (s.empty())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 512
from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self.top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())



Measured memory_bytes: 6004
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
struct Node
{
	int value;
   Node* prev,* next;
};
Node* head;
void Init()
{
    head=(Node*)malloc(sizeof(Node));
    head->next=head;
    head->prev=head;
}

Node* FindNode(int x)
{
	Node*temp=head->next;
	while(temp!=head&&temp->value!=x)
        temp=temp->next;
    return temp;
}
void Insert(int x)
{
	Node*temp=(Node*)malloc(sizeof(Node));
    temp->value=x;
    head->next->prev=temp;
    temp->next=head->next;
    head->next=temp;
    temp->prev=head;
}

void Delete(Node*temp)
{
	if(temp==head)
        return ;
	temp->next->prev=temp->prev;
	temp->prev->next=temp->next;
    free(temp);
}

void DeleteFirst()
{
    Delete(head->next);
}
void DeleteLast()
{
	Delete(head->prev);
}

void PrintList()
{
    /*
    Node*temp=head->next;
    int flag=0;
    while(1)
    {
        if(temp==head)
            break;
        else
        {
            if(flag++>0)
                printf(" ");
            printf("%d",temp->value);
            temp=temp->next;
        }
    }
    printf("\n");
    */
     Node* temp=head->next;
    while(temp->next!=head)
    {
        printf("%d ",temp->value);
        temp=temp->next;
    }
    printf("%d\n",temp->value);
}
int main()
{
	int n;
	int i;
	scanf("%d",&n);
	char str[12];
	int x;
	Init();
    /*
	while(n--)
	{
		scanf("%s%d",str,&x);
		if(str[0]=='i'){Insert(x);}
		else if(str[0]=='d'&&str[6]=='F')DeleteFirst();
		else if(str[0]=='d'&&str[6]=='L')DeleteLast();
		else if(str[0]=='d'){Delete(FindNode(x));}
	}
    */

	for(i = 0; i < n; i++) {
        scanf("%s %d", str, &x);
        if (str[0] == 'i') {
            Insert(x);
        }
        else if(str[0] == 'd') {
            if(str[6] == 'F')
                DeleteFirst();
            else if(str[6] == 'L')
                DeleteLast();
            else
                //DeleteValue(x);
                Delete(FindNode(x));
        }
    }
    /*
    Node* temp=head->next;
    while(temp->next!=head)
    {
        printf("%d ",temp->value);
        temp=temp->next;
    }
    printf("%d\n",temp->value);
    */
    PrintList();
	return 0;
}

Measured memory_bytes: 34424
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  const int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

  int n,p,pn;
  while(true){
    cin >> n >> p;
    if (n==-1)
      break;
    int sum[p*p];
    for(int i=0;i<p*p;i++)
      sum[i] = 0;
    pn = n+1;
    for(int i=0;i<p;i++){
      while(!prime[pn])
	pn++;
      for(int j=0;j<p;j++){
	sum[j*p+i] += pn;
	sum[i*p+j] += pn;
      }
      pn++;
    }
    for(int i = 0;i<p*p;i++){
      if(i/p>i%p)
	sum[i] = 1000000;
    }
    
    sort(sum,sum+p*p);
    cout << sum[p-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1880
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    string i_str;
    int cnt=0;
    for(int i=a;i<b+1;i++){
        i_str=to_string(i);
        if(i_str[0]==i_str[4]&i_str[1]==i_str[3]){
          cnt++;  
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc") cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from collections import deque

X, K, D = map(int, input().split())

# まずは何回目で符号が逆転するかを算出
num_reverse = abs(X) // D + 1
if num_reverse > K:
    print(abs(X) - (K * D))
else:
    K -= num_reverse
    ans = abs(X) - (num_reverse * D)
    if K % 2 == 0:
        print(abs(ans))
    else:
        print(abs(abs(ans) - D))




Measured memory_bytes: 64952
// AOJ 2600: Koto Distance
// 2017.10.31 bal4u@cc
// 2017.11.24

#include <stdio.h>

int width0[300010], height0[300010];
int *width = width0+100002, *height = height0+100002;

char buf[30], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int check(int *a, int sz)
{
	int s = 0;
	while (sz--) {
		s += *a++;
		if (s <= 0) return 0;
	}
	return 1;
}

int main()
{
	int n, w, h, x, y, k;

	fgets(p=buf, 30, stdin);
	n = getint(), p++, w = getint(), p++, h = getint();

	while (n--) {
		fgets(p=buf, 30, stdin);
		x = getint(), p++, y = getint(), p++, k = getint();

		width[x-k]++; if (x < k) width[0]++;
		width[x+k]--;

		height[y-k]++; if (y < k) height[0]++;
		height[y+k]--;
	}

	puts(check(width, w) || check(height, h) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")`  

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
    return 0;
}
/*

*/  

Measured memory_bytes: 3652
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let line = get_input();
    let mut split = line.split_whitespace();
    let mut abc:Vec<i64> = Vec::new();
    abc.push(split.next().unwrap().parse().unwrap());
    abc.push(split.next().unwrap().parse().unwrap());
    abc.push(split.next().unwrap().parse().unwrap());

	let mut ans = 1000000;
	for i in 0..abc.len() {
    	for j in i..abc.len() {
        	if j == i {
            	continue;
            }
            let s = abc[i] + abc[j];
            if ans > s {
            	ans = s;
            }
        }
    }

	println!("{}", ans);
}

Measured memory_bytes: 4352
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for x, y, z in zip(A, B, C):
    x, y, z = sorted([x, y, z])
    if x != y and y != z:
        ans += 2
    elif x == y and y != z:
        ans += 1
    elif x != y and y == z:
        ans += 1
print(ans)

Measured memory_bytes: 38512
/* 
****	
	AUTHOR :- @soham01 
****
*/
#include "bits/stdc++.h"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int k , a, n, i, j, sum=0;
	cin>>n>>k;
	long long int arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n,greater<int>());
	if(k>=n)
	{
		cout<<"0"<<endl;
	}
	else
	{
		for(i=(k);i<n;i++)
		{
			sum+=arr[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 1792