akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(){
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	ll ans;
	if (K%2==0) ans = A-B;
	else ans = B-A;
	if (abs(ans)>1e+18) cout << "Unfair" << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int read() {
	int ans = 0, flag = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') flag = - flag; ch = getchar();}
	while(ch >= '0' && ch <= '9') {ans = ans * 10 + ch - '0'; ch = getchar();}
	return ans * flag;
}
const int N = 100010;
#define mid ((l + r) >> 1)
int n, a[N << 1];
bool vis[N << 1];
bool p[N << 1];
bool check(int x) {
	memset(p, 0, sizeof(p));
	memset(vis, 0, sizeof(vis));
	for(int i = 1; i < 2 * n; ++ i) {
		if(a[i] < x) vis[i] = 0;
		else vis[i] = 1;
		if(i - 1 && vis[i] == vis[i - 1])
			p[i - 1] = p[i] = 1;
	}
	int dis = n, col = 0;
	if(p[n]) return vis[n];
	else {
		for(int i = n - 1; i; -- i)
			if(p[i]) {
				dis = n - i;
				col = vis[i];
				break;
			}
		for(int i = n + 1; i < 2 * n; ++ i) {
			if(p[i]) {
				if(i - n < dis) {
					dis = i - n;
					col = vis[i];
				}
				break;
			}
		}
		if(dis == n) return vis[n] ^ ((n - 1) % 2);
		else return col;
	}
}
int main() {
	n = read();
	for(int i = 1; i < 2 * n; ++ i)
		a[i] = read();
	int l = 1, r = n * 2 - 1, ans;
	while(l <= r) {
		if(check(mid)) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
pair < int , int > d[N];

bool cmp(pair < int , int > a , pair < int , int > b){
    if(a.second < b.second)
        return 1;
    if(a.second == b.second)
        return a.first < b.first;
    return 0;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        d[i] = {a , b};
    }
    sort(d + 1 , d + n + 1 , cmp);
    /*for(int i = 1; i <= n; i++){
        cout << d[i].first << " " << d[i].second << endl;
    }*/
    long long a = 0;
    for(int i = 1; i <= n; i++){
        if(a + d[i].first <= d[i].second){
            a += d[i].first;
        } else {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 1792
public class Main{
    public static void main(String args[]) throws Exception {
    	for(int i=1;i<10;i++){
    		int sum = 0;
    		for(int j=1;j<10;j++){
    			sum = sum + i;
    			System.out.println(i + "x" + j + "=" + sum);
    		}
    	}
    }
}

Measured memory_bytes: 16856
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	string S;
	cin >> S;
	rep(i, S.size() / 2) {
		if (S[i] != S[S.size() - 1 - i]) {
			cout << "No";
			return 0;
		}
	}
	rep(i, (S.size() - 1) / 4) {
		if (S[i] != S[(S.size() - 1) / 2 - 1 - i]) {
			cout << "No";
			return 0;
		}
	}
	rep(i, (S.size() - (S.size() + 3) / 2 + 1) / 2) {
		if (S[(S.size() + 3) / 2 - 1 + i] != S[S.size() - 1 - i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    A = [(i, int(ele)) for i, ele in enumerate(raw_input().split())]
    sortA = sorted(A, key = lambda x: x[1])
    _next = [None] * N
    save = 0

    ## 1. Create _next list
    for i in range(1, N):
        if sortA[i][1] == sortA[save][1]:
            _next[sortA[i-1][0]] = sortA[i][0]
        else:
            _next[sortA[i-1][0]] = sortA[save][0]
            save = i
    _next[sortA[N-1][0]] = sortA[save][0]
    # print "_next: " + str(_next)

    ## 2. Create minimum times N0 to list X return empty list
    start = 0
    minCntToEmpty = 0
    while start != N:
        if _next[start] <= start:
            minCntToEmpty += 1
        start = _next[start] + 1
        # print "start: " +  str(start)
    minCntToEmpty +=1
    # print "minCntToEmpty: " + str(minCntToEmpty)

    ## 3. 4. CntDown = K%N0, run simulated start -> _next(start) + 1 until CntDown becomes 0
    cntDown = K % minCntToEmpty
    if cntDown == 0:
        print
        return
    # print "cntDown: " + str(cntDown)
    start = 0
    while cntDown > 1:
        if _next[start] <= start:
            cntDown -= 1
        start = _next[start] + 1
        # print "start: " +  str(start)

    ## 5. Run simulated to find final answer
    i = start
    # print "i: " + str(i)
    while i < N:
        if _next[i] <= i:
            print A[i][1],
            i += 1
        else:
            i = _next[i] + 1

if __name__ == '__main__':
    solve()


Measured memory_bytes: 67512
import sys
import time
input = sys.stdin.readline

mod = 10 ** 9 + 7


def inv(x):
    return modpow(x, mod - 2)


def modpow(a, x):
    if x == 0:
        return 1
    elif x % 2 == 0:
        return modpow((a * a) % mod, x // 2)
    else:
        return (modpow((a * a) % mod, x // 2) * a) % mod


N, K = map(int, input().strip().split(" "))
A = list(map(int, input().strip().split(" ")))
A.sort()

if K == 1:
    print(0)
else:
    fact = [1, 1]
    inv_fact = [1, 1]

    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv_fact.append(inv(fact[-1]))
    nck = [0 if i < K - 1 else (((fact[i] * inv_fact[K - 1]) % mod) * inv_fact[i - K + 1]) % mod for i in range(0, N + 1)]
    min_sum, max_sum = 0, 0
    for i in range(1, N + 1):
        if 1 <= i <= N - K + 1:
            min_sum += (nck[N - i] * A[i - 1]) % mod
        if K <= i <= N:
            max_sum += (nck[i - 1] * A[i - 1]) % mod

    ans = max_sum - min_sum
    while ans < 0:
        ans += mod
    print(ans % mod)

Measured memory_bytes: 79320
from collections import defaultdict
from bisect import bisect_left

s = input()
n = len(s)
s = s + s
t = input()
if set(t) - set(s):
	print(-1)
	exit()
d = defaultdict(list)
for i in range(2 * n):
	d[s[i]] += [i]
cur = tot = 0
for c in t:
	x = d[c][bisect_left(d[c], cur)]
	if x < n:
		cur = x + 1
	else:
		cur = x - n + 1
		tot += n
tot += cur
print(tot)


Measured memory_bytes: 12200
import sys
input = sys.stdin.readline

def main():
    X, K, D = map(int, input().split())
    X = X if X > 0 else -X
    nK = K - (X // D)
    if nK < 0:
        print(X - K * D)
    else:
        pos = X - ((X // D) * D)
        if nK % 2 != 0:
            print(abs(pos - D))
        else:
            print(pos)


main()

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0, m = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        m = max(x, m);
        ans += x;
    }
    ans += m / 2;
    ans -= m;
    cout << ans;
    return 0;
}

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

#define int int64_t
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define ll long long
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

int q,cnt=0;
string xy[1005];
int lcs[1010][1010];
string s,v;

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

    cin>>q;
    rep(i,q){
        cin>>s>>v;

        rep(j,s.size()){
            rep(k,v.size()){
                if(s[j] == v[k]){
                    lcs[j+1][k+1] = lcs[j][k]+1;
                }else{
                    lcs[j+1][k+1] = max(lcs[j+1][k],lcs[j][k+1]);
                }
            }
        }
        
        cout<<lcs[s.size()][v.size()]<<'\n';
    }
}


Measured memory_bytes: 11112
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<complex>

using namespace std;

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

#define X real()
#define Y imag()

typedef complex<double> P;
struct L : public vector<P>{
	L(P a, P b){
		push_back(a); push_back(b);
	}
};
const int N = 222;
const int INF = 1000000000;
const double EPS = 0.0000001;

int w,n;
vector<P> block[N];


bool input(){
	cin>>w>>n;
	if(w==0)return false;
	
	rep(i,N)block[i].clear();
	rep(i,n){
		int m;
		cin>>m;
		rep(j,m){
			int a,b;
			cin>>a>>b;
			block[i].push_back(P(a,b));
		}
	}
	return true;
}

typedef pair<int,double> E;
vector<E> edge[N];

void mkedge_line(int num, double width){
	
	rep(i,n){
		double mini = INF;
		rep(j,block[i].size()){
			mini = min(mini, abs(block[i][j]-P(width, block[i][j].Y)) );
		}
		edge[num].push_back(E(i,mini));
		edge[i].push_back(E(num,mini));
	}
}

double dot(P a, P b){return a.X*b.X + a.Y*b.Y;}
double cross(P a, P b){return a.X*b.Y - a.Y*b.X;}
double ccw(P a, P b, P c){return cross(b-a, c-a)>0;}

P projection(L a, P b){
	P v1 = b-a[0];
	P v2 = a[1]-a[0];
	
	double t = dot(v1,v2)/abs(v2);
	return a[0]+t*v2/abs(v2);
}
double distLP(L a, P b){
	P pro = projection(a,b);
	if(ccw(b,a[0],pro)==ccw(b,a[1],pro)){
		return min(abs(b-a[0]),abs(b-a[1]));
	}
	return abs(b-pro);
}
double distLL(L a, L b){
	double s = min(distLP(a,b[0]), distLP(a,b[1]));
	double t = min(distLP(b,a[0]), distLP(b,a[1]));
	return min(s,t);
}

void mkedge_block(){
	
	rep(i,n){
		reps(j,i+1,n){
			double mini = INF;
			int m1 = block[i].size();
			int m2 = block[j].size();
			rep(k,m1){
				rep(p,m2){
					mini = min(mini, distLL(L(block[i][k], block[i][(k+1)%m1]), L(block[j][p], block[j][(p+1)%m2])));
				}
			}
			edge[i].push_back(E(j,mini));
			edge[j].push_back(E(i,mini));
		}
	}
}

void mkedge(){
	rep(i,N)edge[i].clear();
	
	edge[n].push_back(E(n+1,w));
	edge[n+1].push_back(E(n,w));
	
	
	mkedge_line(n, 0);
	mkedge_line(n+1, w);
	
	mkedge_block();
}

void printedge(){
	rep(i,n+2){
		printf("i=%d  ",i);
		rep(j,edge[i].size())printf("(%d %lf)",edge[i][j].first, edge[i][j].second);puts("");
	}
}

double dijk(){
	
	int visit[N]={0};
	
	typedef pair<double,int> R;
	priority_queue<R> que;
	que.push(R(0,n));
	
	while(!que.empty()){
		
		R u = que.top();
		que.pop();
		
		if(visit[u.second]==1)continue;
		visit[u.second]=1;
		
		if(u.second==n+1)return -u.first;
		
		rep(i,edge[u.second].size()){
			E e = edge[u.second][i];
			que.push(R(u.first-e.second, e.first));
		}
	}
	
	return 0.0;
}

double solve(){
	
	mkedge();
	
	return dijk();
}

int main(){
	while(input()){
		printf("%.9lf\n",solve());
		
		//printedge();
	}
}

/*
5 2
4
1 1
1 2
2 2
2 1
4
3 3
3 4
4 4
4 3
6 2
4
1 1
1 3
2 3
2 1
3
3 2
5 1
5 3
0 0
*/

Measured memory_bytes: 3556
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder {

    class MainClass {

        public static void Main(string[] args) {

            var array1 = Console.ReadLine().Split(' ');
            var s = array1[0];
            var t = array1[1];

            var array2 = Console.ReadLine().Split(' ');
            var a = int.Parse(array2[0]);
            var b = int.Parse(array2[1]);

            var u = Console.ReadLine();

            if(u == s) {

                a -= 1;

            } else {

                b -= 1;

            }

            Console.WriteLine("{0} {1}", a, b);

        }

        

    }
}


Measured memory_bytes: 27500
#include <chrono>

#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>

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")

int n, m;
vector<int> a, pref;

int check(int mid) { // количество залуп с суммой >= x
    int ptr = n - 1, ans = 0;
    for (int i = 0; i < n; i++) {
        while (ptr >= 0 && a[ptr] + a[i] < mid) ptr--;
        ans += ptr + 1;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    cin >> n >> m;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    pref.resize(n);
    pref[0] = a[0];
    for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + a[i];
    int l = 0, r = INF, mid;
    while (r - l > 1) {
        mid = (l + r) / 2;
        if (check(mid) > m) l = mid;
        else r = mid;
    }
    int ptr = n - 1, ans = 0;
    for (int i = 0; i < n; i++) {
        while (ptr >= 0 && a[i] + a[ptr] < l) ptr--;
        if (ptr >= 0) {
            ans += pref[ptr] + a[i] * (ptr + 1);
        }
    }
    ans -= (check(l) - m) * l;
    cout << ans;
}
/*

*/


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    int n,r;
    cin>>n>>r;
    if(n>=10)
        cout<<r;
    else
        cout<<r+100*(10-n);
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll ans = 0;
    rep(i,n-1){
        if (a[i] > a[i+1]){
            ans += a[i]-a[i+1];
            a[i+1] = a[i];
        }
    }
    PRINT(ans);
}



Measured memory_bytes: 4780
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256



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

	
	int a = N;
	int count = 0;

	while (N > 0) {
		if (N % 10 == 2) {
			count++;
		}
		N /= 10;
	}
	printf("%d\n", count);
	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    while(h != 0 && w != 0){
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j) cout << "#";
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  printf("%d",MAX(a,MAX(b,c))-MIN(a,MIN(b,c)));
  return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt(), m = fs.nextInt();
        int[][] a = new int[n][2];
        int[][] b = new int[m][2];
        for(int i = 0; i < n; i++) {
            a[i][0] = fs.nextInt(); a[i][1] = fs.nextInt();
        }
        for(int i = 0; i < m; i++) {
            b[i][0] = fs.nextInt(); b[i][1] = fs.nextInt();
        }

        for(int i = 0; i < n; i++) {
            int res = 0, best = (int)2e9+1000;
            for(int j = 0; j < m; j++) {
                int diff = Math.abs(a[i][0] - b[j][0]) + Math.abs(a[i][1] - b[j][1]);
                if(diff < best) {
                    best = diff;
                    res = j;
                }
            }
            out.println(res+1);
        }


        out.close();
    }


    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

int main(){
	int n; cin >> n;
	vector<pair<int,int>> plus, minus;
	Rep(n){
		string s; cin >> s;
		int m = 0;
		int stack = 0;
		for(char k: s){
			if(k == '('){
				stack++;
			}else{
				stack--;
				m=min(m,stack);
			}
		}
		if(stack >= 0){
			plus.push_back(make_pair(m, stack));
		}else{
			minus.push_back(make_pair(m-stack, -stack));
		}
	}
	sort(plus.rbegin(), plus.rend());
	sort(minus.rbegin(), minus.rend());

	int now = 0;
	int top;
	for(auto [m, sa]: plus){
		if(now+m < 0){
			goto wrong;
		}
		now+=sa;
	}
	top = now;
	now = 0;
	for(auto [m, sa]: minus){
		if(now+m < 0){
			goto wrong;
		}
		now+=sa;
	}
	if(top == now){
		cout << "Yes\n";
		return 0;
	}
	wrong:
		cout << "No\n";
		return 0;
}


Measured memory_bytes: 11304
#include <iostream>
#include <stdio.h>
#include <cmath>
//#include <string>
using namespace std;

int main(void){
    unsigned long long A, tmp, lim;
    int i,N,err;
    cin >> N;
    A=1;
    err=1;
    lim = (unsigned long long) 1e18;
    for (i = 1; i <=N; i++)
    {
        cin >> tmp;
        //cout << log10(tmp) << endl;
        if(tmp==0){
            cout << 0 << endl;
            return 0;
        }else if(log10(A)+log10(tmp)>18 && err>0){
            err = -1;
        }else if(err>0){
            A *= tmp;
            if(log10(A) >= 18){
                if(A%lim>0){
                    err = -1;
                }
                
                //cout << 111 << endl;
            }
        }
        //cout << "A= " << A << endl;
        
    }
    //cout << (int)1e18 << endl;
    if(err>0) cout << A << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3952
#include<iostream>
    #include<algorithm>
    using namespace std;
     
    int n,v[100010];
    int vmin=1,vmax=100000;
    bool ismono=true;
    int monotmp;
    int odd[100001],even[100010];
    int oddmax,evenmax;
    int oddmaxi,evenmaxi;
     
    bool check()
    {
    	bool ret=true;
    	int i,tmp;
    	tmp=v[1];
    	for(i=1;i<=n;i+=2)
    	{
    		if(v[i]!=tmp)
    		{
    			ret=false;
    			break;
    		}
    	}
    	tmp=v[2];
    	for(i=2;i<=n;i+=2)
    	{
    		if(v[i]!=tmp)
    		{
    			ret=false;
    			break;
    		}
    	}
    	return ret;
    }
     
     
    int main()
    {
    	cin >> n;
    	cin >> v[1];
    	vmin=v[1];
    	vmax=v[1];
    	monotmp=v[1];
    	odd[v[1]]++;
    	for(int i=2;i<=n;i++)
    	{
    		cin >> v[i];
    		if(v[i]<vmin)vmin=v[i];
    		if(v[i]>vmax)vmax=v[i];
    		
    		if(i%2==0)even[v[i]]++;
    		else odd[v[i]]++;
    		
    		if(v[i]!=monotmp)ismono=false;
    	}
    	
    	if(ismono)
    	{
    		cout << n/2 << endl;
    		return 0;
    	}
    	
    	if(check())
    	{
    		cout << 0 << endl;
    		return 0;
    	}
    	//main
    	oddmax=odd[0];
    	for(int i=vmin;i<=vmax;i++)
    	{
    		if(odd[i]>oddmax)
    		{
    			oddmax=odd[i];
    			oddmaxi=i;
    		}
    	}
    	evenmax=even[0];
    	for(int i=vmin;i<=vmax;i++)
    	{
    		if(even[i]>evenmax)
    		{
    			evenmax=even[i];
    			evenmaxi=i;
    		}
    	}
    	if(oddmaxi==evenmaxi)
    	{
    		if(odd[oddmaxi]<even[evenmaxi])
    		{
    			odd[oddmaxi]=0;
    			oddmax=odd[0];
    			for(int i=vmin;i<=vmax;i++)
    			{
    				if(odd[i]>oddmax)
    				{
    					oddmax=odd[i];
    					oddmaxi=i;
    				}
    			}
    		}
    		else if(odd[oddmaxi]>even[evenmaxi])
    		{
    			even[evenmaxi]=0;
    			evenmax=even[0];
    			for(int i=vmin;i<=vmax;i++)
    			{
    				if(even[i]>evenmax)
    				{
    					evenmax=even[i];
    					evenmaxi=i;
    				}
    			}
    		}
			else
			{
				odd[oddmaxi]=0;
				even[evenmaxi]=0;
				int oddmaxx=odd[0],evenmaxx=even[0];
				for(int i=vmin;i<=vmax;i++)
				{
					if(odd[i]>oddmaxx)
					{
						oddmaxx=odd[i];
						//oddmaxi=i;
					}
				}
				//evenmax=even[0];
				for(int i=vmin;i<=vmax;i++)
				{
					if(even[i]>evenmaxx)
					{
						evenmaxx=even[i];
						//evenmaxi=i;
					}
				}
				if(evenmaxx>=oddmaxx)evenmax=evenmaxx;
				if(evenmaxx<oddmaxx)oddmax=oddmaxx;
			}
    	}
    	cout << n-oddmax-evenmax << endl;
    	return 0;
    }

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String args[]) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        
        String output = input.replaceAll("peach","value");
        
        output = output.replaceAll("apple", "peach");
        
        output = output.replaceAll("value", "apple");
        
        System.out.println(output);

	}

}

Measured memory_bytes: 16900
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n);
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	min, max := n, 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
		if a[i] < min {
			min = a[i]
		}
		if a[i] > max {
			max = a[i]
		}
	}
	
	if max - min == 0 {
		if max == n - 1 || 2 * max <= n {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else if max - min == 1 {
		k := 0
		for i := 0; i < n; i++ {
			if a[i] == max - 1 {
				k++
			}
		}
		if max > k && 2 * (max - k) <= n - k {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {
		fmt.Println("No")
	}
}


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

int main() {
  int A, B, T, P1, P2;
  cin >> T >> A >> B;
  P1 = A*T;
  P2 = B;
  
  if(A*T < B) {
    cout << P1 << endl;
  } else if( P1 > P2) {
    cout << P2 << endl;
  } else {
    cout << P2 << endl;
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

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

  double l; cin >> l;
  double a;
  a = l/3.0;

  Dcout(a*a*a);

  return 0;
}


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

int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(abs(c-a)  <= d) cout << "Yes\n";
	else if(abs(a-b) <= d && abs(c-b) <=d)cout << "Yes\n";
	else cout <<"No\n";
	return 0;
}

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

#define fastio        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll            long long
#define fl            long double
#define pll           pair<ll,ll>
#define onebits(x)    __builtin_popcountll(x)
#define pb            push_back
#define mk            make_pair
#define endl          "\n"
#define ff            first
#define ss            second
#define mt            make_tuple
#define np            next_permutation
#define pi            3.141592653589793238
#define deb(x)        cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define vll           vector<ll>
#define vp            vector<pair<ll,ll>>
#define all(x)        x.begin(),x.end()
#define revpq         priority_queue <int, vector<int>, greater<int>>
#define ps(x,y)       fixed<<setprecision(y)<<x
const ll mod = 1e9 + 7;
const ll INF = 1e18;
ll power(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod % mod; a = a * a % mod;} return res;}
int main()
{
    fastio;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll i, j, t, k , n , m, l;
    cin >> t;
    if (t >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            Map<Integer, Integer> a = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int tmp = Integer.parseInt(in.next());
                if (!a.containsKey(tmp)) {
                    a.put(tmp, 1);
                } else {
                    a.put(tmp, a.get(tmp) + 1);
                }
            }
            int ans = 0;
            for (Map.Entry<Integer, Integer> entry : a.entrySet()) {
//            out.println(entry.getKey() + " => " + entry.getValue());
                if (entry.getKey() == entry.getValue()) {
                    continue;
                } else {
                    if (entry.getKey() > entry.getValue()) {
                        ans += entry.getValue();
                    } else {
                        ans += Math.abs(entry.getKey() - entry.getValue());
                    }
                }
            }


            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 62576
#include <iostream>
using namespace std;
long long solve(long long n) {
	if (n % 4 == 0) {
		return n;
	} else if (n % 4 == 1) {
		return 1;
	} else if (n % 4 == 2) {
		return n + 1;
	} else {
		return 0;
	}
}
int main() {
	long long a, b;
	cin >> a >> b;
	cout << (solve(a - 1) ^ solve(b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;


int a[N];

map<int, int> cnt;

void solve() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        ++cnt[a[i]];
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
    }
    printf("%d\n", ans);
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 47488
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val a = List.fill(n)(sc.nextInt)
    val b = List.fill(n)(sc.nextInt)
    val c = List.fill(n - 1)(sc.nextInt)
    sc.close

    val ans = (0 until n - 1).foldLeft(b.sum)((acc, cur) => {
      if (a(cur) + 1 == a(cur + 1)) acc + c(a(cur) - 1)
      else acc
    })

    println(ans)
  }
}

Measured memory_bytes: 27336
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()


int gcd(int x, int y){
    if (x > y)
        return gcd(y, x);
    int m = 1;
    while(m != 0){
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

int main(){
    int a,b,k; cin>>a>>b>>k;
    int g = gcd(a,b); int c = 0;
    for(int i = g; i>=1; i--){
        if (g%i == 0) c++;
        if (c == k){
            cout<<i<<endl; return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

    class xyh {
         int x;
         int y;
         int h;
        xyh(int x, int y, int h) {
            this.x = x;
            this.y = y;
            this.h = h;
        } 

        int getX() {return x;}
        int getY() {return y;}
        int getH() {return h;}
     }

public class Main {



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int result = 0;
        int resultx = 0;
        int resulty = 0;
        List<xyh> list = new ArrayList<>();
        for (int i = 0; i<N; i++) {
            list.add(new xyh(sc.nextInt(), sc.nextInt(), sc.nextInt()));
        }

        for (int x=0; x <= 100; x++) {
            for (int y=0; y <= 100; y++) {
                int estimationH = judge(x, y, list);
                if (estimationH > 0) {
                    result = estimationH;
                    resultx = x;
                    resulty = y;
                }
            }
        }

        System.out.println(resultx + " " + resulty + " " + result);
    }

    public static int judge(int x, int y, List<xyh> list) {
        int refH = -1;
        for(xyh l : list) {
            int estimationDiff = Math.abs(x - l.getX()) + Math.abs(y - l.getY());
            int estimationH = 0;
            if (l.getH() == 0) {
                estimationH = l.getH() + estimationDiff;
                if (refH > estimationH) {
                    return -1;
                }
            }
            else {
                estimationH = l.getH() + estimationDiff;
                if (refH < 0) {
                    refH = estimationH;
                }
                else if (refH != estimationH) {
                    return -1;
                }
            }
        }

        return refH;
    }

    public static boolean calcHight(int x, int y, List<xyh> list) {
        return true;
    }

}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string w; cin >> w;
    map<char,int> c{};
    for(int i=0;i<w.size();i++){
        if(c.count(w[i])==0){
            c[w[i]]=1;
        }else{
            c[w[i]]=c[w[i]]+1;
        }
    }
    bool f=true;
    for(auto i=c.begin();i!=c.end();i++){
        //cerr << i->first << " " << i->second << endl;
        if(i->second%2!=0){
            f=false;
            break;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s="$"+s;
    vector<int> a(n+2,0);
    for(int i=1;i<=n;i++) a[i]=a[i-1]+(s[i]=='W');
    vector<int> b(n+2,0);
    for(int i=n;i>=1;i--) b[i]=b[i+1]+(s[i]=='R');
    int res=n;
    for(int i=0;i<=n;i++) res=min(res,max(a[i],b[i+1]));
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 5004
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    x = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 1 if x==0 else 0
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

int main() {
  int N, M, C;
  int B[21];
  int A[21][21];

  cin >> N >> M >> C;
  REP(i, M) cin >> B[i];
  REP(i, N) REP(j, M) cin >> A[i][j];

  int cnt = 0;
  REP(i, N) {
    int sum = C;
    REP(j, M) sum += A[i][j] * B[j];
    if (sum > 0) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){t.in();var e=t.in(),n=t.inr().split("").map(function(t){return parseInt(t,36)-10});n[e-1]+=32;var r=n.map(function(t){return String.fromCharCode(t+97-32)});console.log(r.join(""))}}]);

Measured memory_bytes: 21064
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize, m: usize,
        xyz_: [(i64,i64,i64); n]
    }

    let mut xyz = xyz_.clone();
    let mut ret = i64::min_value();
    for i in 0..(1<<3) {
        let x_sign = if i >> 0 & 1 == 1 {-1} else {1};
        let y_sign = if i >> 1 & 1 == 1 {-1} else {1};
        let z_sign = if i >> 2 & 1 == 1 {-1} else {1};

        xyz.sort_by_key(|&(x,y,z)| x*x_sign+y*y_sign+z*z_sign);
        xyz.reverse();
        ret = std::cmp::max(
            ret,
            xyz.iter().take(m).fold(0, |acc, &(x,y,z)| acc + x*x_sign+y*y_sign+z*z_sign)
        );
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
n=int(input())
ans=0
import itertools
for i in range(1,n+1):
    p,q=str(i)[0],str(i)[-1]
    if int(p)*int(q)==0:
        continue
    if len(str(i))>=3:
        if p<q:
            ans+=int("1"*(len(str(i))-2))*2
        elif p>q:
            ans+=int("1"*(len(str(i))-1))*2
        else:
            ans+=int("1"*(len(str(i))-2))*2
            ans+=(int(str(i)[1:-1])+1)*2
            ans+=1
    elif len(str(i))==1:
        ans+=1
    else:
        if p>q:
            ans+=2
        elif p==q:
            ans+=3
print(ans)


Measured memory_bytes: 42088
/* ****TUSHAR_SEN IITR**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll n,i;
		cin>>n;
		string s;
		set<string>st;
		for(i=0;i<n;i++)
		{
			cin>>s;
			st.insert(s);
		}
		cout<<st.size();

	}
	return 0;
}

Measured memory_bytes: 19244
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    int k,n;scanf("%d %d",&k,&n);
    int a[200000];for(int i=0;i<n;i++)scanf("%d",&a[i]);
    ll dist[200001];
    int max=-1;
    int x,y;
    for(int i=1;i<n;i++){
        dist[i]=a[i]-a[i-1];
        if(dist[i]>max){
            x=i;y=i-1;
            max=dist[i];
        }
    }

    ll sum1,sum2;
    sum1=sum2=0;
    for(int i=1;i<n;i++){
        sum1+=dist[i];
    }

    for(int i=x+1;i<n;i++){
        sum2+=a[i]-a[i-1];
    }
    sum2+=k-a[n-1]+a[0];
    for(int i=1;i<=y;i++){
        sum2+=a[i]-a[i-1];
    }
    printf("%lld\n",sum1<sum2?sum1:sum2);
    
}

Measured memory_bytes: 2560
import java.util.*;

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

    Map<Integer, Integer> fibCache;

    public void main() {
        this.fibCache = new HashMap<>();

        int n = new Scanner(System.in).nextInt();
        System.out.println(this.fib(n));
    }

    private int fib(int n) {
        if (this.fibCache.containsKey(n)) {
            return this.fibCache.get(n);
        }

        int result;
        if (n <= 1) {
            result = 1;
        } else {
            result = this.fib(n - 1) + this.fib(n - 2);
        }
        this.fibCache.put(n, result);
        return result;
    }
}



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

using namespace std;

int main() {
    int n;
    string st1,st2;
    cin>>n;
    cin>>st1>>st2;
    for(int i=0 ; i<n ; i++){
        cout<<st1[i]<<st2[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll sp[100010],sm[100010];

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

    int z=0;
    vector<ll> x(n);

    vector<ll> p,m;

    rep(i,n){
        cin>>x[i];
        if(x[i]==0) z++;
        else if(x[i]>0){
            p.push_back(x[i]);
        }
        else{
            m.push_back(-x[i]);
        }
    }

    reverse(all(m));
    ll ans=1LL<<60;
    if(z==1){
        k--;
        if(k==0){
            cout<<0<<endl;
            return 0;
        }
    }
    if(p.size()>=k){
        ans=min(ans,p[k-1]);
    } 
    if(m.size()>=k){
        ans=min(ans,m[k-1]);
    }

    for(int i=1;i<k;i++){
        if(m.size()<i) break;
        if(p.size()<k-i) continue;
        ans=min(ans,2*m[i-1]+p[k-i-1]);
    }

    for(int i=1;i<k;i++){
        if(p.size()<i) break;
        if(m.size()<k-i) continue;
        ans=min(ans,2*p[i-1]+m[k-i-1]);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 5220