akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if((C+B-1)/B <= (A+D-1)/D){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

different = 10 ** 5
minpoint = 1
for i in range(N):
	ave = T - (H[i] * 0.006)
	differ = abs(A - ave)
	if different > differ:
		different = differ
		minpoint = i + 1
print(minpoint)

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

int main(void){

  int n;
  cin >> n;
  int i = 0;
  int sum = 1;
  for(i = 0;i < 3 ;i++){
    sum = sum * n;
  }

  cout << sum << endl;
  
  return 0;

}


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

using int64 = long long;

int main() {
    int64 N, M;
    cin >> N >> M;

    if (N == 1 and M == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (N == 1) {
        cout << M - 2 << endl;
        return 0;
    }

    if (M == 1) {
        cout << N - 2 << endl;
        return 0;
    }

    // 周の数を数え上げる
    cout << N * M - 2 * N - 2 * M + 4 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;

ll pow_mod(ll a,ll b,ll m){
	if(b == 0)return 1;
	else if(b % 2 == 0){
		ll t = pow_mod(a,b/2,m);
		return t * t % m;
	}
	return a  * pow_mod(a,b-1,m) % m;
}

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

	vector<ll> num(k+1,0);
	ll ans = 0;
	for(ll i = k;i >= 1;i--){
		ll cnt = (pow_mod(k/i,n,MOD) - num[i] + MOD) % MOD;
		ans += i * cnt;
		ans %= MOD;
		for(ll j = 2;j * j <= i;j++){
			if(i % j == 0){
				if(j * j == i){
					num[j] += cnt;
					num[j] %= MOD;
				}
				else{
					num[j] += cnt;
					num[j] %= MOD;
					num[i/j] += cnt; 
					num[i/j] %= MOD;
				}
			}
		}
		num[1] += cnt;
		num[1] %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int K = scan.nextInt();
        String S = scan.next();
        scan.close();
        if (K < S.length()) {
            System.out.println(S.substring(0, K) + "...");
        } else {
            System.out.println(S);
        }
    }
}

Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const ll INF = LLONG_MAX / 3;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef ll Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll r, c, n;
	cin >> r >> c >> n;
	vector<vector<pii>> v(r);
	vector<vector<pii>> w(c);
	REP(i, n)
	{
		ll x, y, a;
		cin >> x >> y >> a;
		x--; y--;
		v[x].emplace_back(y, a);
		w[y].emplace_back(x, a);
	}
	REP(i, r) sort(ALL(v[i]));
	Graph g(c);
	REP(i, r)
	{
		REP(j, v[i].size() - 1)
		{
			ll pl = v[i][j].first, sl = v[i][j].second;
			ll pr = v[i][j + 1].first, sr = v[i][j + 1].second;
			add_edge(g, pl, pr, sr - sl);
			add_edge(g, pr, pl, sl - sr);
		}
	}
	bool f = true;
	Array dist(c, -INF);
	REP(i, c)
	{
		if (dist[i] != -INF) continue;
		dist[i] = 0;
		queue<int> que;
		set<int> st;
		st.insert(i);
		que.push(i);
		while (!que.empty())
		{
			int t = que.front();
			que.pop();
			for (auto j : g[t])
			{
				int nx = j.to;
				int cost = j.cost;
				if (dist[nx] == -INF)
				{
					dist[nx] = dist[t] + cost;
					que.push(nx);
					st.insert(nx);
				}
				else if (dist[nx] != dist[t] + cost)
				{
					f = false;
					break;
				}
			}
		}
		ll mn = INF;
		for (auto j : st)
		{
			chmin(mn, dist[j]);
		}
		for (auto j : st)
		{
			int pot = dist[j] - mn;
			REP(k, w[j].size())
			{
				if (w[j][k].second < pot) f = false;
			}
		}
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 16128
def d_CardEater(N, A):
    from collections import Counter, defaultdict
    a = Counter(A)  # a[i]は数列の中にiが何回出たか
    a = sorted(a.items(), key=lambda x: x[0])
    d = defaultdict(int)  # aのうち2回以上出た値の一覧
    for k, v in a:
        if v >= 2:
            d[k] = v - 1  # あとの計算の便宜のため、1引いておく
    n = sum(d.values())  # 少なくとも値が重複したn枚分は捨てることになる
    if n % 2 == 0:
        ans = N - n
    else:
        # nが奇数だと、山札dの中のカードのうち1枚を、値の重複がないカードからなる
        # 山の中の1枚を道連れにして捨てる必要があるため、さらに1引く
        ans = N - n - 1
    return ans

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

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

int n;
vector<int> to[200010];
bool odd[200010];
int on = 0, en = 0;

void bfs(){
    vector<int> dist(n,INF);
    dist[0] = 0;
    odd[0] = false;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        if(odd[v]) on++;
        else en++;
        for(auto tv : to[v]){
            if(dist[tv]!=INF) continue;
            dist[tv] = dist[v]+1;
            odd[tv] = !odd[v];
            q.push(tv);
        }
    }
}
int main(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    bfs();
    int n3 = n/3;
    int n2 = n/3 + (n%3)/2;
    int n1 = n/3;
    if(n%3!=0) n1++;
    vector<int> ans(n);
    int ct1=0, ct2=0, ct3=0;
    if(on>=n1 && en>=n2){
        rep(i,n){
            if(odd[i]) {
                if(ct1<n1){
                ans[i] = ct1*3+1;
                ct1++;
                }else{
                    ans[i] = ct3*3+3;
                    ct3++;
                }
            }else{
                if(ct2<n2){
                    ans[i] = ct2*3+2;
                    ct2++;
                }else{
                    ans[i] = ct3*3+3;
                    ct3++;
                }
                
            }
        }     
    }else if(on<=n3){
        rep(i,n){
            if(odd[i]){
                ans[i] = ct3*3+3;
                ct3++;
            }else{
                if(ct1<n1){
                    ans[i] = ct1*3+1;
                    ct1++;
                }else if(ct2<n2){
                    ans[i] = ct2*3+2;
                    ct2++;
                }else{
                    ans[i] = ct3*3+3;
                    ct3++;
                }
            }
        }
    }else if(en<=n3){
        rep(i,n){
            if(!(odd[i])){
                ans[i] = ct3*3+3;
                ct3++;
            }else{
                if(ct1<n1){
                    ans[i] = ct1*3+1;
                    ct1++;
                }else if(ct2<n2){
                    ans[i] = ct2*3+2;
                    ct2++;
                }else{
                    ans[i] = ct3*3+3;
                    ct3++;
                }
            }
        }
    }
    rep(i,n) printf("%d%c",ans[i],i==n-1?'\n':' ');
    return 0;
}

Measured memory_bytes: 14316
#include <iostream>

using namespace std;

int main(void){

  int array[102];
  int n;
  for( int i = 0 ; i <= 101 ; i++ )array[i] = 0;

  while( cin >> n ){
    array[n]++;
  }

  int yano = 0;
  for( int i = 1 ; i <= 100 ; i++ ){
    yano = max( array[i] , yano );
  }

  for( int i = 1 ; i <= 100 ; i++ ){
    if( yano == array[i] ){
      cout << i << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s;
    string str,str1;
    cin>>n;
    ll cr[n]={0};
    ll cb[n]={0};
    ll cg[n]={0};
    string s1;
    cin>>s1;
    repr
    {
        if(s1[i]=='R')
        {
            cr[i]+=1;
        }
        if(s1[i]=='G')
        {
           cg[i]+=1;  
        }
        if(s1[i]=='B')
        {
            cb[i]+=1;
        }
    }
    for(int i=n-2;i>=0;i--)
    {
        cr[i]=cr[i]+cr[i+1];
        cg[i]=cg[i]+cg[i+1];
        cb[i]=cb[i]+cb[i+1];
    }

    ll ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            if(s1[i]=='R' && s1[j]=='G')
            {
                ans+=cb[j+1];
                if(s1[j+(j-i)]=='B' && ((2*j)-i<n))
                    ans--;
            }
            if(s1[i]=='R' && s1[j]=='B')
            {
               ans+=cg[j+1];
               if(s1[j+(j-i)]=='G' && ((2*j)-i<n))
                    ans--;
            }
            if(s1[i]=='G' && s1[j]=='B')
            {
               ans+=cr[j+1];
               if(s1[j+(j-i)]=='R' && ((2*j)-i<n))
                    ans--;
            }
            if(s1[i]=='G' && s1[j]=='R')
            {
               ans+=cb[j+1];
               if(s1[j+(j-i)]=='B' && ((2*j)-i<n))
                    ans--;
            }
            if(s1[i]=='B' && s1[j]=='G')
            {
                ans+=cr[j+1];
                if(s1[j+(j-i)]=='R' && ((2*j)-i<n))
                    ans--;
            }
            if(s1[i]=='B' && s1[j]=='R')
            {
                ans+=cg[j+1];
                if(s1[j+(j-i)]=='G' && ((2*j)-i<n))
                    ans--;
            }


        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 3680
#include<stdio.h>

int com(int n,int r);

int main(void){
  int N =0,M =0,sum = 0;
  scanf("%d %d\n",&N,&M );
  if(N > 1){
    sum += com(N,2);
  }
  if(M > 1){
    sum += com(M,2);
  }
  printf("%d\n",sum );
  return 0;
}

int com(int n,int r){
  if(n == 0|| r == 0){
    return 1;
  }else{
    return com(n,r-1)*(n-r+1)/r;
  }
}

Measured memory_bytes: 128
from collections import defaultdict

s = int(input())
L = defaultdict(int)
m = 1
a = s
L[a] += 1
while True:
	m += 1
	if a % 2 == 0:
		a = int(a / 2)
	else:
		a = 3 * a + 1
	L[a] += 1
	if L[a] == 2:
		print(m)
		break


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


int main(void){
  ll x; cin >> x;
  ll kotae = x/500 * 1000;
  kotae += (x%500)/5 * 5;
  cout << kotae << endl;
  return 0;
}


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

int main(){
    ll h, n;
    cin >> h >> n;
    ll mx = 0;
    rep(i, 0, n){
        ll t; cin >> t;
        mx += t;
    }
    if(mx >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int H, N;
  cin >> H >> N ;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  if (std::accumulate(vec.begin(), vec.end(), 0) >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;
 
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
 
template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);
 
struct edge{int to, cost;};
 
class Graph
{
public:
    int V;
    vector<vector<edge>> G;
    //int l;
 
    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
        //l = 0 ;
    }
 
    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }
 
    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }
 
    void dfs_free(int v, int c, int n, vec &d, vector<set<int>> &label, queue<int> &que){
        if(n > d[v] || label[v].count(c) > 0) return;
        if(d[v] > n){
            d[v] = n;
            if(v == V - 1){
                cout << d[v];
                exit(0);
            }
            que.push(v);
        }
        label[v].insert(c);
        REP(k, G[v].size()) if(G[v][k].cost == c)
        dfs_free(G[v][k].to, c, n, d, label, que);
    }
 
    void dfs(int v, vec &d, vector<set<int>> &label, queue<int> &que){
        int n = d[v];
        //label[v] = l;
        REP(k, G[v].size()){
            //label[v].insert(G[v][k].cost);
            dfs_free(G[v][k].to, G[v][k].cost, n + 1, d, label, que);
        }
        //l++;
    }
 
};
 
signed main(){
 
    int N, M; cin >> N >> M;
    Graph G(N);
    int p, q, c;
    REP(i, M){
        cin >> p >> q >> c;
        G.add_edge2(p - 1, q - 1, c);
    }
    vec d(N, INF);
    vector<set<int>> label(N);
    d[0] = 0;
    queue<int> que;
    que.push(0);
    vector<bool> used(N, false);
 
    while(!que.empty()){
        int v = que.front(); que.pop();
        if(v == N - 1) break;
        if(used[v]) continue;
        used[v] = true;
        G.dfs(v, d, label, que);
    }
    if(d[N - 1] == INF) d[N - 1] = -1;
    cout << d[N - 1];
    
    return 0;
}
 
 
template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 22992
#include<stdio.h>

int main()
{
	int b[4]={0};
	int d;
	char c[2];

	while(scanf("%d,%c%c",&d,c,c+1)!=EOF)
	{
		if(c[1]=='B')
		{
			b[2]++;
			continue;
		}
		switch(c[0])
		{
		case 'A':
			b[0]++;break;
		case 'B':
			b[1]++;break;
		case 'O':
			b[3]++;break;
		}
	}
	for(d=0;d<4;d++)
		printf("%d\n",b[d]);

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2e5 + 10;

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  vector<int> h(n+1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  int inf = 1 << 30;
  vector<int> dp(n+1, inf);
  dp[1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n && j - i < 3; ++j) {
      dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n];
return 0;
}


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

using namespace std;

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

    vector<long long> p(n);
    long long ans = 0, a;

    for (long long i = 0; i < n; i++) {
        cin >> a;

        if ((i + a) < (n - 1)) {
            p[i + a]++;
        }

        if ((i - a) > 0) {
            ans += p[i - a];
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(void)
{
	int N,i,r,R,o;
	string ivent;
	cin >> N;
	i=0;
	r=0;
	R=0;
	o=0;
	
	while(1) {
		cin >> ivent;
		if(ivent=="HIT"){
			r++;
			if(r==4) {
				r--;
				R++;
			}
		}
	
		else if(ivent=="HOMERUN"){
			R+=r+1;
			r=0;
		}
	
		else if(ivent=="OUT"){
			o++;
			if(o==3){
				r=0;
				o=0;
				i++;
				cout << R << endl;
				R=0;
				if(i==N) return 0;
			}
		}
	}
}

Measured memory_bytes: 3168
#include <iostream>

using namespace std;

const int MAX_SIZE = 21;
int w, h;

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

char field[MAX_SIZE][MAX_SIZE];

bool ok(int x, int y) {
	return (x >= 0 && x < w && y >= 0 && y < h) && field[y][x] == '.';
}

int solve(int x, int y) {
	int ret = 0;
	for (int i = 0; i < 4; ++i) {
		int curx = x + dx[i],
			cury = y + dy[i];

		if (ok(curx, cury)) {
			field[cury][curx] = '#';
			ret += solve(curx, cury) + 1;
		}
	}
	return ret;
}

int main() {
	while (true) {
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		int x = -1, y = -1;
		for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
			cin >> field[i][j];
			if (field[i][j] == '@') {
				field[i][j] = '#';
				x = j;
				y = i;
			}
		}

		cout << solve(x, y) + 1 << endl;

	}

	return 0;
}

Measured memory_bytes: 1176
import sys
from collections import deque
import copy
import heapq
import math

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    A_list = []
    input_raw = read_func().strip().split()
    for i in range(3* N):
        A_list.append(long(input_raw[i]))

    AL_list = A_list[:N]
    L_sum = [0 for i in range(N + 1)]
    L_sum[0] = sum(AL_list)
    heapq.heapify(AL_list)
    for i in range(N, 2 * N):
        if AL_list[0] < A_list[i]:
            heapq.heappush(AL_list, A_list[i])
            min_L = heapq.heappop(AL_list)
            L_sum[i + 1- N] = L_sum[i - N] - min_L + A_list[i]
        else:
            L_sum[i + 1- N] = L_sum[i - N]

    AR_list = [-A_list[i] for i in range(2 * N, 3 * N)]
    R_sum = [0 for i in range(N + 1)]
    R_sum[N] = sum(AR_list)
    heapq.heapify(AR_list)
    for i in range(2 * N - 1, N - 1, -1):
        if AR_list[0] < -A_list[i]:
            heapq.heappush(AR_list, -A_list[i])
            min_R = heapq.heappop(AR_list)
            R_sum[i - N] = R_sum[i - N + 1] - min_R + (-A_list[i])
        else:
            R_sum[i - N] = R_sum[i - N + 1]

    max_score = -long(sys.maxint * sys.maxint)
    for i in range(N + 1):
        max_score = max(max_score, L_sum[i] + R_sum[i])


##    for i in range(N + 1):
##        if i == 0:
##            AL_list = A_list[:N + i]
##            AR_list = A_list[N + i:]
##            AL_list = sorted(AL_list, reverse=True)
##            AR_list = sorted(AR_list)
##            L_sum = sum(AL_list[:N])
##            R_sum = sum(AR_list[:N])
##            max_score = max(max_score, (L_sum - R_sum))
##            L_min = AL_list[0]
##            R_min = AR_list[0]
##        else:
##            A = A_list[N + i]
##            if L_min < A:
##                L_index += 1
##                L_sum = (L_sum - L_min) + A
##                L_min(AL_list[L_index])
##            if R_max > A:
##                R_sum = R_sum - A +

    print max_score


if __name__ == '__main__':
    main()


Measured memory_bytes: 52892
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+10;
int n,a[maxn],cnt[40],ans[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<40;i++)
		for(int j=0;j<n;j++)
			if(a[j]&(1ll<<i))
				cnt[i]++;
	int power=1;
	for(int i=0;i<40;i++)
	{
		if(cnt[i]==0)
		{
			power*=2;
			continue;
		}
		bool tmp=a[0]&(1ll<<i);
		if(tmp)
			cnt[i]--;
		if((cnt[i]%2==0&&!tmp)||(cnt[i]%2&&tmp))
		{
			for(int j=0;j<n;j++)
				if(a[j]&(1ll<<i))
					ans[j]+=power;
		}
		else
		{
			for(int j=0;j<n;j++)
				if(!(a[j]&(1ll<<i)))
					ans[j]+=power;
		}
		power*=2;
	}
	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}
/*
2
1000000000 1000000000
*/

Measured memory_bytes: 6680
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;


int main() {
  int N,K;
  cin>>N>>K;
  cout<<(N-K+1)<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] NW = ReadLineParseIntArray();
        int N = NW[0];
        int W = NW[1];
        long[,] dp = new long[N + 1, W + 1];
        for(int i = 0; i  < N; i++)
        {
            int[] wv = ReadLineParseIntArray();
            for(int w = 0; w <= W; w++)
            {
                if (w >= wv[0])
                    dp[i + 1, w] = Max(dp[i, w - wv[0]] + wv[1], dp[i, w]);
                else
                    dp[i + 1, w] = dp[i, w];
            }
        }
        WriteLine(dp[N, W]);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 91232
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
map<int,int>mp; 
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		mp[x]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
		if(it->second>=it->first)
			ans+=it->second-it->first;
		else
			ans+=it->second;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4736
x,y=map(int, input().split())
l=[]
flag = True
left = x
l.append(left)
l_max = y
mul = 2
current_value = left
while flag:
    a = current_value * mul
    if l_max < a:
        flag=False
        break
    l.append(a)
    current_value = a
print(len(l))    

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll a, b;
    cin >> a >> b;
    if (a < b) {
        REP(i, b) {
            cout << a;
        }
    }
    else {
        REP(i, a) {
            cout << b;
        }
    }
    cout << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll f(ll a){
  ll res=0;
  while(a>0){
    res++; a/=10;
  }
  return res;
}

ll S;

int main(){
  cin>>S;
  ll res=0;
  {
    ll l=1,r=1;
    ll crtS=0;
    for(;f(l)<=7;){
      while(crtS<S){
        crtS+=f(r);
        r++;
      }
      if(crtS==S){
        res++;
      }
      crtS-=f(l);
      l++;
    }
  }
  res%=mod;

  {
    repl(i,1,S/8+1){
      if(S%i!=0)(res+=1)%=mod;
      else{
        ll nd=(9*mod_pow(10,(S/i)-1)%mod-i+1+mod)%mod;
        (res+=nd)%=mod;
      }
    }
  }

  cout<<res%mod<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
     
    using namespace std;
     
    int l ;
    char s[13];
     
    void init()
    {
    	scanf("%s", s);
    	l = strlen(s);
    	if(l <= 12) {//printf("0\n");
    	//else 
    	for (int i = 0; i < 4; ++i)
    	{	
    		printf("%c", s[i]);
    	}
    	printf(" ");
    	for (int i = 4; i < l; ++i)
    	{
    			printf("%c", s[i]);
    	}
    }
    	else {
    		printf("0\n");
    	}
    	printf("\n");
    	//printf(" %c", s[l - 4]);
    }
     
    int main()
    {
     
    	//#ifndef ONLINE_JUDGE
    		//freopen("input.txt","r",stdin);
    		//freopen("output.txt","w",stdout);
    	//#endif
     
    	init();
     
    	return 0;
    }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    final static long MOD = 1000000007;

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

        int n = fs.nextInt();
        int k = fs.nextInt();
        int [] h= fs.nextIntArray(n);

        int [] dp = new int[n];

        dp[0] = 0;

        for(int i = 1; i < n; i++) {
            int minValue = Integer.MAX_VALUE;
            for(int j = 1; j <= k && i -j >= 0; j++) {
                minValue = Math.min(minValue, Math.abs(h[i] - h[i - j]) + dp[i - j]);
            }
            dp[i] += minValue;
        }

        //System.out.println(Arrays.toString(dp));
        System.out.println(dp[n-1]);

        out.flush();
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                //                br = new BufferedReader(new FileReader("file2.txt"));

                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 char nextChar() {
            return next().charAt(0);
        }

        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 long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

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

}




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

int main()
{    string str;
    cin>>str; int countzero=0; int countone=0; 
   int arrstint[6];
    for (int i = 0; i < 6; ++i)
     {
        arrstint[i]=int(str[i])-'0';
     } 
     for (int i = 0; i < 6; ++i)
     {
         if(arrstint[i]==0){countzero++;}
         else {countone++;}
     }
  cout<<countone;
    return 0;
}  



Measured memory_bytes: 256
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
print(chr(ord(s) + 1))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int mn[maxn<<2];
void Push_up(int id)
{
    mn[id]=min(mn[id<<1],mn[id<<1|1]);
}
void build(int id,int l,int r)
{
    mn[id]=100000000;
    if(l==r) {
        if(l==0) mn[id]=0;
        return;
    }
    int mid=(l+r)>>1;
    build(id<<1,l,mid);
    build(id<<1|1,mid+1,r);
    Push_up(id);
}
void up(int id,int l,int r,int v,int w)
{
    if(l==r){
        mn[id]=min(mn[id],w);
        return;
    }
    int mid=(l+r)>>1;
    if(v<=mid) up(id<<1,l,mid,v,w);
    else up(id<<1|1,mid+1,r,v,w);
    Push_up(id);
}
int q(int id,int l,int r,int tl,int tr)
{
    if(l==tl&&r==tr)
    {
        return mn[id];
    }
    int mid=(l+r)>>1;
    if(tr<=mid) return q(id<<1,l,mid,tl,tr);
    else if(tl>mid) return q(id<<1|1,mid+1,r,tl,tr);
    else return min(q(id<<1,l,mid,tl,mid),q(id<<1|1,mid+1,r,mid+1,tr));
}
int b[maxn];
struct SHIT
{
    int l,r;
}shit[maxn];
bool cmp(SHIT a,SHIT b)
{
    if(a.l!=b.l) return a.l<b.l;
    return a.r>b.r;
}
void Debug(int id,int l,int r)
{
    if(l==r){
        printf("%d ",mn[id]);
        return;
    }
    int mid=(l+r)>>1;
    Debug(id<<1,l,mid);
    Debug(id<<1|1,mid+1,r);
}
int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        ans+=(1-b[i]);
    }
    int Q;
    scanf("%d",&Q);
    build(1,0,n);
    for(int i=1;i<=Q;i++)
    {
        scanf("%d%d",&shit[i].l,&shit[i].r);
    }
    sort(shit+1,shit+1+Q,cmp);
    for(int i=1,j=1;i<=n;i++)
    {
        int tmp=q(1,0,n,i-1,i-1);
        while(j<=Q&&shit[j].l==i){
           //printf("%d %d\n",shit[j].l,shit[j].r);
            up(1,0,n,shit[j].r,q(1,0,n,i-1,shit[j].r));
            j++;
        }
        up(1,0,n,i,tmp+(b[i]==1?1:-1));
        //Debug(1,0,n);
        //printf("\n");

    }
    ans+=q(1,0,n,n,n);
    printf("%d\n",ans);
    return 0;
}


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

ll n, m, ans, A[100001];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		ans += A[i];
	}
	sort(A, A + n, greater<int>());
	cout << ans - A[0] / 2 << endl;
	return 0;
}

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

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

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

ll mod(1000000007);
double pi(acos(-1.0));

ll modexp2(int e) {
  ll r = 1, b = 2;
  while (e) {
    if (e & 1) r = r * b % mod;
    b = b * b % mod;
    e /= 2;
  }
  return r;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n;
  cin >> n;

  map<pair<ll, ll>, ii> m;
  int cnt00 = 0;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == b && !a) cnt00++;
    else if (!a) {
      m[{0, 0}].fi++;
    } else if (!b) {
      m[{0, 0}].se++;
    } else {
      ll g = __gcd(a, b);
      ll x = a / g, y = b / g;
      if (y < 0) x *= -1, y *= -1;

      if (x > 0) m[{x, y}].fi++;
      else m[{y, -x}].se++;
    }
  }

  ll cnt = 1;
  for (auto& i : m) {
    cnt = (modexp2(i.se.fi) + modexp2(i.se.se) + mod - 1) % mod * cnt % mod;
  }

  cout << (cnt + cnt00 + mod - 1) % mod;

  return 0;
}


Measured memory_bytes: 16104
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream &os, const pair<F, S> &p) {
	return os << "(" << p.first << ", " << p.second << ")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

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

const ll mod = 1e9 + 7;

int32_t main () {
	// freopen("in", "r", stdin);
	int n; cin >> n;
	string s; cin >> s;
	vector<int> cnt(26, 0);
	for(char c : s) cnt[c - 'a']++;
	ll ans = 1;
	for(int i = 0; i < 26; i++) {
		ans = ans * (cnt[i] + 1) % mod;
	}
	cout << ans - 1 << endl;
}

Measured memory_bytes: 512
N = int(input())

isok = False
for i in range(0,101,4):
    for j in range(0,101,7):
        if i+j==N:
            #print(i,j)
            isok = True
            break
    if isok: break
        
if isok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
typedef long long ll;
int main()
{
	ll r,n,i,cnt=0;
	scanf("%lld %lld",&n,&r);
	for (i=0; ; )
	{
		i=(i+1)+(r*2); cnt++;
		/*printf("i=%lld\n",i);*/
		if (i>=n) break;
	}
	printf("%lld\n",cnt);
	return 0;
}
	

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main() {
  int N, Y;
  cin >> N >> Y;
  Y /= 1000;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N - i; j++){
      int k = N - i - j;
      if(i * 10 + j * 5 + k == Y && k > -1) {
        cout << i << ' ' << j << ' ' << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

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

using namespace std;

void dumpres(vector<int>& ticket, vector<char>& ops) {
    for (int i = 0; i < 4; i++) {
        cout << ticket[i];
        if (i != 3)
            cout << ops[i];
    }
    cout << "=7\n";
    exit(0);
}

void visit(vector<int>& ticket, vector<char>& ops, int idx, int accum) {
    int res;

    res = accum + ticket[idx];
    ops.push_back('+');
    if (idx < 3) {
        visit(ticket, ops, idx + 1, res);
    } else if (idx == 3 && res == 7) {
        dumpres(ticket, ops);
    }
    ops.erase(ops.end() - 1);

    res = accum - ticket[idx];
    ops.push_back('-');
    if (idx < 3) {
        visit(ticket, ops, idx + 1, res);
    } else if (idx == 3 && res == 7) {
        dumpres(ticket, ops);
    }
    ops.erase(ops.end() - 1);
}

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

    vector<int> ticket;

    int d = 0;
    while (d < 4) {
        int digit = n[d] - '0';
        ticket.push_back(digit);
        d++;
    }

    vector<char> ops;
    visit(ticket, ops, 1, ticket[0]);
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};

ll i,j,k;
ll a,b;
ll n,m,ans=0;
bool used[100005];
ll st,en;
ll v;
stack <ll> s;
queue <ll> q;

int main(){
	cin>>n>>m;
	for(i=1;i<=n;i++){
		used[i]=false;
	}
	for(i=1;i<=m;i++){
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
		if(i==1){
			st=a;
			en=b;
		}
	}
	s.push(st);
	q.push(en);
	used[st]=used[en]=true;
	while(true){
		for(i=0;i<G[st].size();i++){
			v=-1;
			if(!used[G[st][i]]){
				used[G[st][i]]=true;
				st=G[st][i];
				s.push(st);
				ans++;
				
				v=0;
				break;
			}
		}
		if(v==-1)break;
	}
	while(true){
		for(i=0;i<G[en].size();i++){
			v=-1;
			if(!used[G[en][i]]){
				used[G[en][i]]=true;
				en=G[en][i];
				q.push(en);
				ans++;
				v=0;
				break;
			}
		}
		if(v==-1)break;
	}
	cout<<ans+2<<endl;
	while(!s.empty()){
		cout<<s.top()<<" ";
		s.pop();
	}
	while(!q.empty()){
		cout<<q.front()<<" ";
		q.pop();
	}
	cout<<endl;



	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
int main()
{
	 int n,m,i,j,k,s,l;
	 char a[150];
	 char b[150];
	 char t;
	 
	while(scanf("%s",a)!=EOF)
	{
		scanf("%s",b);
		l=strlen(a);
		for(i=0;i<=l-2;i++)
		  {
		  	 for(j=l-1;j>i;j--)
		  	  {
		  	  	 if(a[j]<a[j-1])
		  	  	 {
		  	  	 	 t=a[j];
		  	  	 	 a[j]=a[j-1];
		  	  	 	 a[j-1]=t;
		  	  	 }
		  	  }
		  }
		  l=strlen(b);
		  for(i=0;i<=l-2;i++)
		  {
		  	 for(j=l-1;j>i;j--)
		  	  {
		  	  	 if(b[j]>b[j-1])
		  	  	 {
		  	  	 	 t=b[j];
		  	  	 	 b[j]=b[j-1];
		  	  	 	 b[j-1]=t;
		  	  	 }
		  	  }
		  }
		  if(strcmp(a,b)<0)
		  printf("Yes\n");
		  else
		  printf("No\n");
		  memset(a,'\0',sizeof(a));
		  memset(a,'\0',sizeof(b));
	}
} 

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

function main()
	n,x = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	a = sort(a)
	count = 0
	for i in 1:n
		if x<a[i]
			break
		else
			count += 1
			x -= a[i]
		end
	end
	if x > 0 && count==n
		count-=1
	end
	println(count)
end
main()

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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    VI p(a),q(b),r(c);
    rep(i,0,a)cin>>p[i];
    rep(i,0,b)cin>>q[i];
    rep(i,0,c)cin>>r[i];
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    reverse(p.begin(),p.end());
    reverse(q.begin(),q.end());
    ll ans=0;
    VI v;
    rep(i,0,x)v.pb(p[i]);
    rep(i,0,y)v.pb(q[i]);
    rep(i,0,c)v.pb(r[i]);
    sort(v.begin(),v.end(),greater<int>());
    rep(i,0,x+y)ans+=v[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
#include <math.h>

int main(){
	int i,j,p;
	int n,d;
	int x[10][10];
	int dist,cont=0;
	scanf("%d %d",&n,&d);
	
	for(i=0;i<n;i++){
		for(j=0;j<d;j++){
			scanf("%d",&(x[i][j]));
		}
	}
	
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			dist=0;
			for(p=0;p<d;p++){
				dist+=(x[j][p]-x[i][p])*(x[j][p]-x[i][p]);
			}
			if(sqrt((double)dist)-(double)((int)sqrt((double)dist))==0.0){
				cont++;
			}
		}
	}
	printf("%d\n",cont);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int m = scan.nextInt();
		int n = scan.nextInt();
		int matrix[][] = new int[m][n];
		int last[] = new int[m];
		int small[] = new int[n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				matrix[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < n; i++) {
			small[i] = scan.nextInt();
		}
		int sum = 0;
		for (int i = 0; i < m; i++) {
			for (int p = 0; p < n; p++) {
				sum += matrix[i][p] * small[p];
			} last[i] = sum;
			sum = 0;
		}

		for (int i = 0; i < m; i++) {
			System.out.println(last[i]);
		}
}
}



Measured memory_bytes: 40336
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


w = gc
h = Hash.new
'a'.upto 'z' do |i|
	h[i] = 0
end
w.each do |ww|
	h[ww] += 1
end
ans = true
h.each do |k,n|
 if n % 2 != 0
 	ans = false
 	break
 end
end

puts ans ? 'Yes' : 'No'

Measured memory_bytes: 2044
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left < right) {
		mid = (left + right) / 2;
		if(A[mid] == key) return 1;
		if(key < A[mid]) right = mid;
		else if(key > A[mid]) left = mid+1; 
	}
	return 0;	
}

int main() {
	int i, q, key, sum = 0;
	
	scanf("%d", &n);
    for(int i = 0; i < n; i++) { 
        scanf("%d", A+i);
    }
    
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
	    scanf("%d", &key);
		if( binarySearch(key)) sum++; 
	}
	printf("%d\n", sum);
	
	return 0;    
}

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

const int N = 1e3+5;
long long powers[N];

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

    int n;
    cin>>n;

    map<int, int> mp;
    long long ans = 0;

    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        ans += mp[i-x];
        mp[i+x]++;
    }
    cout<<ans<<endl;
}


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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 3e3 + 3;	

ll dp[N][N][4] = {};
ll ar[N][N] = {};
int main()
{
	fastio;

	int r, c, k;
	cin >> r >> c >> k;

	for (int i = 1; i <= k; ++i)
	{
		int x, y, v;
		cin >> x >> y >> v;
		ar[x][y] = v;
	}

	for (int i = 1; i <= r; ++i)
	{
		for (int j = 1; j <= c; ++j)
		{
			//No pick
			for (int k = 0; k < 4; ++k)
				dp[i][j][k] = max(dp[i-1][j][3], dp[i][j-1][k]);

			//Pick
			if (ar[i][j])
			{
				for (int k = 3; k >= 1; --k)
					dp[i][j][k] = max(dp[i][j][k], ar[i][j] + dp[i][j][k-1]);
			}

			//Put the maximum at k = 3
			for (int k = 1; k < 4; ++k)
				dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1]);
		}
	}

	cout << dp[r][c][3] << '\n';
	return 0;
}

Measured memory_bytes: 355436
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
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(){
int N,M,Zf,Zl;
cin>>N>>M>>Zf>>Zl;
vector<int> X(N),Y(M);
for(int i=0;i<N;i++){
    cin>>X.at(i);
}
for(int i=0;i<M;i++){
    cin>>Y.at(i);
}
bool war=false;
for(int i=Zf+1;i<=Zl;i++){
    if(war) break;
    war=true;
    for(int j=0;j<N;j++){
       if(X.at(j)>=i){
         war=false;
         break;
       }
    }
    for(int k=0;k<M;k++){
        if(Y.at(k)<i){
            war=false;
            break;
        }
    }
}
if(war)cout<<"No War"<<endl;
else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  /*body*/
  int K;
  string S;
  cin >> K >> S;
  if (size(S) <= K)
    cout << S << endl;
  else {
    S.erase(K);
    cout << S << "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3616