akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main()
{
    auto nx = readln.chomp.split.to!(ulong[]);
    auto n = nx[0];
    auto x = nx[1];
    auto a = readln.chomp.split.to!(ulong[]);
    sort(a);
    int ans = 0;

    foreach(i, e; a) {
        if(e > x)
            break;
        x -= e;
        ans++;
        if(i + 1 == n  && x > 0)
            ans--;
    }

  ans.writeln;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
ll n, m, k, y, x, h, w = -1, num=0, sum, ans = 0; string s;
template <typename T>
vector<T> compress(vector<T>& C1, vector<T>& C2) {
	vector<T> vals;
	int N = C1.size();
	rep(i, N) {
		rep(d, 1) {
			T tc1 = C1[i] + d, tc2 = C2[i] + d;
			vals.push_back(tc1);
			vals.push_back(tc2);
		}
	}sort(ALL(vals));
	vals.erase(unique(ALL(vals)), vals.end());
	rep(i, n) {
		C1[i] = lower_bound(ALL(vals), C1[i]) - vals.begin();
		C2[i] = lower_bound(ALL(vals), C2[i]) - vals.begin();
	}return vals;
}
int main(void) {
	cin >> n; vector<ll> X1(n), X2(n), Y1(n), Y2(n);
	rep(i, n) cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
	vector<ll> X = compress(X1, X2), Y = compress(Y1, Y2);
	w = X.size(); h = Y.size();
	vector<vector<int>> G(w, vector<int>(h));
	rep(i, n) {
		G[X1[i]][Y1[i]]++;
		G[X2[i]][Y2[i]]++;
		G[X1[i]][Y2[i]]--;
		G[X2[i]][Y1[i]]--;
	}req(i, w - 1) {
		rep(j, h) {
			G[i][j] += G[i - 1][j];
		}
	}
	rep(i, w) {
		req(j, h - 1) {
			G[i][j] += G[i][j - 1];
		}
	}
	rep(i, w - 1) {
		rep(j, h - 1) {
			if (G[i][j]) ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
		}
	}cout << ans << endl;
}


Measured memory_bytes: 65684
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define deb(x) cout << #x << " = " << x << ' ';
#define rep(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 1e5+2;

ll dp[102][N];
ll wt[102], val[102];

int main()
{
   int n; ll W;
   scn(n); lscn(W);

   rep(i, 1, n+1) {
      scanf("%lld%lld", &wt[i], &val[i]);
   }
   
   rep(i, 0, 102) {
      rep(j, 0, N) {
         dp[i][j] = INT_MAX;
      }
   }

   rep(i, 0, n+1) {
      dp[i][0] = 0;
   }

   rep(i, 1, n+1) {
      rep(j, 1, N) {
         if(val[i] <= j and dp[i-1][j - val[i]] != INT_MAX) {
            dp[i][j] = min(wt[i] + dp[i-1][j-val[i]], dp[i-1][j]);
         } else {
            dp[i][j] = dp[i-1][j];
         }
      }
   }

   ll mx = 0;

   rep(i, 1, N) {
      if(dp[n][i] <= W) {
         mx = i;
      }
   }
   
   lprin(mx);
   return 0;
}

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

int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    string s;

    cin >> s;

    for(i=0;i<3;i++) cout << s[i];

}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
using namespace std;

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(int64_t A, int64_t B, vector<int64_t> &h, int64_t t){
    int64_t count = 0;
    for(int i = 0; i < h.size(); i++){
        int64_t hp = h[i] - t * B;
        if(hp <= 0) continue;
        count += ceil((h[i] - 1.0 * B * t) / (A - B));
    }
    return count <= t;
}

int main(){

    int64_t N, A, B;
    cin >> N >> A >> B;
    vector<int64_t> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];

    int64_t ng = -1, ok = 1e12;
    while(abs(ng -ok) > 1){
        int64_t t = (ok + ng) / 2;
        if(check(A, B, h, t)) ok = t;
        else ng = t;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int main() {
 string  b;
  in(b);
  int N =  sz(b);
  rep(i,N){
   if(b[i] == 'A') out('T');
    else if(b[i] == 'T') out('A');
    else if(b[i] == 'C') out('G');
    else out('C');
  }
      }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    ll max_val = max(a, b);
    ll min_val = min(a, b);

    ll amari = max_val % min_val;
    if (amari == 0) return min_val;
    return gcd(min_val, amari);
}

int main() {
    ll N, X;
    cin >> N >> X;

    vector<ll> x(N, 0);
    ll gcd_val;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        x[i] -= X;
        x[i] = abs(x[i]);
        if(i == 0) {
            gcd_val = x[0];
            continue;
        }
        gcd_val = gcd(gcd_val, x[i]);
    }

    cout << gcd_val << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 998244353
#define pi 3.141592653589793
const int N = 2000001;
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n;
    cin >> n;
    cout << n / 500 * 1000 + ((n % 500) / 5) * 5;



}


Measured memory_bytes: 256
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)

print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; 

const int N = 1e5+9;
vector<int> adjList[N];
int dp[N];

int dfs(int n)
{
    if (dp[n] != 0){
        return dp[n];
    }
    for (int i = 0; i<adjList[n].size(); i++){
        dfs(adjList[n][i]);
        dp[n] = max(dp[n], dp[adjList[n][i]] + 1);
    }
    return dp[n];
}

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    int n, m;
    cin >> n >> m;
    int u, v;
    while (m--){
        cin >> u >> v;
        adjList[u].pb(v);
    }
    for (int i = 1; i<=n; i++){
        dfs(i);
    }
    int ans = 0;
    for (int i = 1; i<=n; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}



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

struct input{
	int a;
	int b;
	char order[8];
	char p[1001];
};

void replace(char str[1001],struct input *x){
	int i,j=0;
	for (i = x->a; i < (x->b) + 1; i++){
		str[i] = x->p[j];
		j++;
	}
}
void reverse(char str[1001], struct input *x){
	int i;
	char s;
	for (i = 0; i < ((x->b)-(x->a)+1)/2; i++){
		s = str[(x ->a) +i];
		str[(x->a)+i] = str[(x->b)-i];
		str[(x->b)-i] = s;
	}
}
void print(char str[1001], struct input *x){
	int i;
	for (i = x->a; i < (x->b) + 1; i++){
		printf("%c", str[i]);
	}
	putchar('\n');
}

void conning(char str[1001],struct input *x,int q){
	int i;
	for (i = 0; i < q; i++){
		if (strcmp((x->order), "replace") == 0){
			replace(str, x);
		}
		else if (strcmp((x->order), "reverse") == 0){
			reverse(str, x);
		}
		else if ((strcmp((x->order), "print") == 0)){
			print(str, x);
		}
		else
			;
		x++;
	}
}

int main(void){
	int q;
	char str[1001];
	struct input x[100];
	scanf("%s", str);
	scanf("%d", &q);
	int i;
	for (i = 0; i < q; i++){
		scanf("%s %d %d", x[i].order,&x[i].a,&x[i].b);
		if (strcmp(x[i].order, "replace") == 0){
			scanf("%s", x[i].p);
		}
		else
			;
	}

	conning(str, x, q);


	return 0;
}


Measured memory_bytes: 2148
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int[] minutes = new int[5];
		int swap;
		int total = 0;
		int mini;
		
		for (int i = 0; i < 5; i++) {
			minutes[i] = stdIn.nextInt();
		}
		
		mini = 9;
		
		for (int i = 0; i < 4; i++) {
			if ((minutes[i] % 10 < mini) && (minutes[i] % 10 != 0)) {
				swap = minutes[i];
				minutes[i] = minutes[4];
				minutes[4] = swap;
				mini = swap % 10;
			}
		}
		
//		System.out.println(minutes[4]);
			
		for (int i = 0; i < 5; i++) {
//			if(minutes[i] % 10 != 0) {
			while (minutes[i] % 10 != 0 && i != 4) {
				minutes[i]++;
			}
//			}
			total += minutes[i];
//			System.out.println(total);
		}
		
		System.out.println(total);
		
	
	}
}

Measured memory_bytes: 22228
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  string S;
  cin >> S;
  int N=S.size();
  vector<int> dp(2020,0);
  dp[0]=1;
  int now=0;
  int k=1;
  for(int i=N-1;i>=0;i--){
    now=(now+k*(S[i]-'0'))%2019;
    dp[now]++;
    k=k*10%2019;
  }
  ll ans=0;
  for(int i=0;i<=2018;i++){
    ans+=dp[i]*(dp[i]-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;
 
 
int main()
{
	int n;
	long long sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
			sum += i;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstring>
const int N=5e5+5;
int n;

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

inline void bigmul(int *a,int &len,int b){
	int p=0;
	for(int i=0; i<len; ++i){
		a[i]=a[i]*b+p;
		p=a[i]/10;
		if(p) a[i]-=p*10;
	}
	if(p) a[len++]=p;
}

int main(){
	static char ch[N];
	static int s[N];
	scanf("%s",ch+1);
	n=strlen(ch+1);
	for(int i=0; i<n; ++i){
		s[i]=ch[n-i]-'0';
	}
	bigmul(s,n,9);
	int cbit=0;
	for(int i=0; i<n; ++i){
		cbit+=s[i];
	}
	for(int i=1; i<=n; ++i){
		cbit+=9;
		int p=9;
		for(int j=0; p; ++j){
			s[j]+=p;
			p=s[j]/10;
			if(p){
				s[j]-=p*10;
				cbit-=9;
			}
		}
		if(cbit<=i*9){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(0);
    ain(a,3);
    sort(a,a+3);
    cout<<10*a[2]+a[1]+a[0];
    return 0;
}


Measured memory_bytes: 892
from collections import Counter

N = int(input())
al = list(map(int, input().split()))
C = Counter(al)
# print(C)
# print(C.values())
ans = 0
for i in C.values():
    ans += i * (i - 1) / 2

for a in al:
    k = C[a]
    print(int(ans - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2))


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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int Mod = 1e9 + 7;

int Pow(int x, int e){
	int ret = 1;
	while(e){
		if(e & 1) ret = 1ll * ret * x % Mod;
		x = 1ll * x * x % Mod;
		e >>= 1;
	}
	return ret;
}

int n, k, ans;

map<int, int> M;

void calc(int l){
	int ret = Pow(k, (l + 1) / 2);
	for(int i = 1; i * i <= l; ++i)
		if(l % i == 0){
			ret = (ret + Mod - M[i]) % Mod;
			if(i * i != l && i != 1) ret = (ret + Mod - M[l / i]) % Mod;
		}
	int re = l;
	M[re] = ret;
	if(re % 2 == 0) ret = 1ll * ret * Pow(2, Mod - 2) % Mod;
	ans = (ans + 1ll * ret * l) % Mod;
}

int main(){
	scanf("%d%d", &n, &k);
	int i = 1;
	for(; i * i <= n; ++i)
		if(n % i == 0) calc(i);
	for(--i; i; --i)
		if(n % i == 0 && i * i != n) calc(n / i);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#import "stdio.h"
int main(){
  int n,h,a,i;
  scanf("%d%d",&h,&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    h=h-a;
    if(h<=0){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n+1];
    int ans=0;
    a[0] = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans += abs(a[i-1]-a[i]);
    }
    ans+=abs(a[n]);
    for(int i=1;i<n;i++)
    {
        cout<<ans - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] -a[i-1])<<endl;
    }
    cout<<ans-abs(a[n] - a[n-1])-abs(a[n]) + abs(a[n-1]);
    return 0;
}
/*
3 5 -1 = 12
12 - a[i] - prev[i] = 12 - (3 - 0)*/


Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APair solver = new APair();
        solver.solve(1, in, out);
        out.close();
    }

    static class APair {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt();
            int odd = 0, even = 0;
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 0) {
                    odd++;
                } else {
                    even++;
                }
            }
            out.println(odd * even);
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22612
import sys
sys.setrecursionlimit(1<<30)
def dfs(x,dis):
    for y in Tree[x]:
        if parent[x] != y:
            parent[y] = x
            dis[y] = dis[x]+1
            dfs(y,dis)

N,u,v = map(int,input().split())
Tree = [[] for _ in range(N+1)]
for i in range(N-1):
    A,B = map(int,input().split())
    Tree[A].append(B)
    Tree[B].append(A)
disT = [-1]*(N+1)
disA = [-1]*(N+1)
disT[u] = 0
disA[v] = 0
parent = [-1]*(N+1)
dfs(u,disT)
parent = [-1]*(N+1)
dfs(v,disA)
ans = 0
for i in range(1,N+1):
    if disT[i] <= disA[i]:
        ans = max(ans,disA[i]-1)
print(ans)

Measured memory_bytes: 102656
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(x%2==0){
		if(x%3!=0&&x%5!=0) {
			puts("DENIED");
			return 0;
		}
	}
	}
	puts("APPROVED");
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in(),l=in();
    int s=(l*2+n-1)*n/2;
    int k=l;
    if(l<0&n+l-1>=0) k=0;
    else if(l<0)k=n+l-1;
    cout<<s-k<<endl;
}

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

int main(){
    int n, k, a[200000];
    cin >> n >> k;
    for(int i=0;i<n;++i){
        cin >> a[i];
        --a[i];
    }

    int64_t ans = 0;
    map<int,int64_t> mp;
    int sum[200001];
    sum[0] = 0;
    for(int i=0;i<n;++i){
        sum[i+1] = (sum[i] + a[i]) % k;
    }
    int pos = 0, target = 0;
    for(;pos<k-1;++pos){
        if(pos > n) break;
        ++mp[sum[pos]];
    }

    for(pos=0;pos<n;++pos){
        target = sum[pos];
        --mp[sum[pos]];
        if(pos+k-1<=n) ++mp[sum[pos+k-1]];
        ans += mp[target];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <complex>
using namespace std;

typedef complex<double> cd;

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

double dot(cd a,cd b){
    return (a*conj(b)).X;
}

double cross(cd a,cd b){
    return -((a*conj(b)).Y);
}

int main(){
    double x,y;

    while(cin>>x>>y){
        vector<cd> v,vec;
        v.push_back(cd(x,y));
        for(int i=1;i<3;i++){
            cin>>x>>y;
            v.push_back(cd(x,y));
        }

        v.push_back(v[0]);

        for(int i=0;i<3;i++){
            vec.push_back(v[i+1]-v[i]);
        }

        cin>>x>>y;

        int all_p=1,all_n=1;

        for(int i=0;i<3;i++){
            double crs=cross(vec[i],cd(x,y)-v[i]);
            all_p &= crs>0;
            all_n &= crs<0;
        }

        if(all_p || all_n){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
using namespace std;
  
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int num;
  int i = 1;
  while (cin >> num) {
    if( num == 0){
      break;
    }
    cout << "Case "<< i <<": " <<num<< endl;
    i++;
  }
  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
char c;
string s;

string changes(int i){
	string res;
	stringstream ss;
	ss << i;
	ss >> res;
	return res;
}

int main(){
	cin >> n;
	REP(i, n){
		cin >> c;
		s += c;
	}
	ll co = 0;
	while (1){
		//string t = changes(co);
		//cout << t << endl;
		//cout << s.find(t) << endl;
		if (s.find(changes(co)) == -1){
			cout << co << endl;
			break;
		}
		co++;

	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll w, h, n;
  cin >> w >> h >> n;
  ll xl = 0, xr = w, yl = 0, yr = h;
  rep(i, n) {
    ll x, y, a;
    cin >> x >> y >> a;
    if(a == 1)
      xl = max(xl, x);
    else if(a == 2)
      xr = min(xr, x);
    else if(a == 3)
      yl = max(yl, y);
    else
      yr = min(yr, y);
  }
  if(xr - xl <= 0 || yr - yl <= 0)
    cout << 0 << endl;
  else
    cout << (xr - xl) * (yr - yl) << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;

typedef struct node {
    ll key;
    struct node *left;
    struct node *right;
    struct node *p;
}Node;

typedef struct BinarySearchTree{
    ll size;
    Node* root;
}Bst;

Bst* Bstinit(){;
    Bst *bst=(Bst *)malloc(sizeof(Bst));
    bst->size=0;
    bst->root=NULL;
    return bst;
}

Node* generate(ll key){
    Node *node=(Node *)malloc(sizeof(Node));
    node->key=key;
    node->left=NULL;
    node->right=NULL;
    node->p=NULL;
    return node;
}

Node* insert(Bst *bst,ll key){
    Node *node=generate(key);
    Node *cmp=bst->root;;
    while(cmp!=NULL){
        ll cmpkey=cmp->key;
        if(cmpkey<=key){
            if(cmp->right==NULL){
                cmp->right=node;
                node->p=cmp;
                break;
            }
            else cmp=cmp->right;
        }
        else {
            if(cmp->left==NULL){
                cmp->left=node;
                node->p=cmp;
                break;
            }
            else cmp=cmp->left;
        }
    }
    if(bst->size==0)bst->root=node;
    bst->size++;
    return node;
}
void inorder(Node *n){
    if(n->left!=NULL)inorder(n->left);
    cout<<" "<<n->key;
    if(n->right!=NULL)inorder(n->right);
}

void preorder(Node *n){
    cout<<" "<<n->key;
    if(n->left!=NULL)preorder(n->left);
    if(n->right!=NULL)preorder(n->right);
}

void print(Node* root){
    if(root==NULL)return;
    inorder(root);
    cout<<endl;
    preorder(root);
    cout<<endl;
}

int main( ){
    int m;
    cin>>m;
    Bst *bst=Bstinit();
    rep(i,0,m){;
        string cmd;
        cin>>cmd;
        if(cmd=="insert"){
            ll key;
            cin>>key;
            insert(bst,key);
        }
        if(cmd=="print"){
            print(bst->root);
        }
    }
    return 0;
}





Measured memory_bytes: 26660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var n = int.Parse(s.Split(' ').First());
            var k = int.Parse(s.Split(' ').Last());

            var tmp = Console.ReadLine();

            if (n == k)
            {
                Console.WriteLine(1);
            }
            else
            {
                if ((n - 1) % (k - 1) == 0)
                {
                    Console.WriteLine((n - 1) / (k - 1));
                }
                else
                {
                    Console.WriteLine((n - 1) / (k - 1) + 1);
                }
            }
        }
    }
}

Measured memory_bytes: 13280
def ABS(a,b):
  c = a - b
  if c < 0:
    c = c * -1
  return c

str = input()
nli = list(map(int,str.split()))

if ABS(nli[0],nli[1]) < ABS(nli[0],nli[2]):
  print("A")
else:
  print("B")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <queue>
using namespace std;
 
#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
typedef pair<int,int> P;
 
vector<int> bfs(vector< vector<int> > adj_list, int start){
  int N = adj_list.size(); // Number of Vertex
  queue<int> que;
  vector<int> dist(N, -1); // distance
  
  // init
  dist[start] = 0;
  que.push( start );
  
  // main loop
  while( !que.empty() ){
    int v = que.front(); que.pop();
    
    REP(i, adj_list[v].size()){
      int nv = adj_list[v][i];
      if(dist[nv] != -1) continue;
      
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }
  
  return dist;
}
 
int main()
{
  int N, X, Y; cin >> N >> X >> Y;
  vector< vector<int> > adj_list(N);
  REP(i,N-1){
    adj_list[i].push_back(i+1);
    adj_list[i+1].push_back(i);
  }
  adj_list[X-1].push_back(Y-1);
  adj_list[Y-1].push_back(X-1);
 
  vector< vector<int> > dist_matrix(N);
  REP(start, N){
    dist_matrix[start] = bfs(adj_list, start);
  }
 
  vector<int> counts(N);
  REP(i, N){
    rep(j,i+1,N){
      counts.at( dist_matrix[i][j] ) += 1;
    }
  }
  
  rep(i,1,N){
    cout << counts[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 16128
#include<iostream>
using namespace std;
int gcd(int n, int m){
    if(m == 0){
        return n;
    }
    return gcd(m, n%m);
}

int main(){
    int a,b,k,num,i=2,ans;
    cin >> a >> b >> k;
    num = gcd(a,b);
    ans = num;
    while(k != 1){
        if(num % i == 0){
            ans = num / i;
            k--;
        }
        i++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


const int inf=2e9+5;

int main(){
    string s,t; cin>>s>>t;
    int n=s.size(), m=t.size();
    int ans=inf;
    rep(i,n-m+1){
        string kari=s.substr(i,m);
        int a=0;
        rep(j,m){
            if(kari[j]!=t[j]){
                a++;
            }
        }
        ans=min(ans,a);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

use std::collections::HashSet;

fn main() {
    input! {
        k: i32
    }

    let mut cnt = 1;
    let mut m = HashSet::new();
    let mut amari = 7%k;
    let mut is_end: bool;
    loop {
      	is_end = m.insert(amari);
        if amari == 0 { break; }
        if is_end == false {
            break;
        }
        amari = (amari*10+7)%k;
        cnt += 1;
    }

    if m.contains(&0) {
        println!("{}", cnt)
    } else {
        println!("{}", -1)
    }
}

Measured memory_bytes: 17356
; B - 1 Dimensional World's Tale
; https://beta.atcoder.jp/contests/abc110/tasks/abc110_b

(defun split-and-parse-integer (string)
  (loop for i = 0 then (1+ j)
    as j = (position #\Space string :start i)
    collect (parse-integer (subseq string i j))
    while j))

(defun input-format ()
  (let ((n (read)) (m (read)) (x (read)) (y (read)))
    (let ((xs (split-and-parse-integer (read-line)))
          (ys (split-and-parse-integer (read-line))))
      (let ((xx (cons x xs))
            (yy (cons y ys)))
        (list xx yy)))))

(defun solve (lis)
  (let ((xx (car lis))
        (yy (car (cdr lis))))
    (let ((biggest-x  (car (sort (copy-list xx) #'>)))
          (smallest-y (car (sort (copy-list yy) #'<))))
      (if (< biggest-x smallest-y)
          "No War"
          "War"))))

(format t "~A" (solve (input-format)))


Measured memory_bytes: 4068
a,b,c,d = map(int, input().split())


m = [a,b]
n = [c,d]

if a < 0 and 0 < b:
    m.append(0)

if c < 0 and 0 < d:
    n.append(0)

mx = -float('inf')

for ms in m:
    for ns in n:
        j = ms * ns
        if mx < j:
            mx = j



print(mx)

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

int main(){
	string s; cin>>s;
	int k=s.size();
	if(s[k-1]!='s') cout<<s+"s"<<endl;
	else cout<<s+"es"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  char s;
  for (int i = 0; i < n; i++){
    cin >> s;
    if (s == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  
  cout << "Three" << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
int c=0,i,l;
string s,t;
cin>>s;
cin>>t;
l=s.length();
for(i=0;i<l;i++){
    if(s[i]!=t[i])
        c++;
}
cout<<c;
}


Measured memory_bytes: 3876
def solve(N,M, array):
    sum_ = sum(array)
    array.sort()

    for i in range(N-1, N-M-1, -1):
        if array[i] < (1/(4*M))*sum_:
            return "No"

    return "Yes"


if __name__=="__main__":
    N, M = map(int, input().split())
    arr = list(map(int, input().split()))

    print(solve(N, M, arr))

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; int i; bool used; };
 
int MOD = 1000000007;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y]; v[y] = x;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

bool kr_cmp(const edge& l, const edge& r) { return ll_i(l.w, l.i) < ll_i(r.w, r.i); }

ll kruskal(int n, vector<edge>& E) {
	sort(E.begin(), E.end(), kr_cmp);
	union_find uf(n);
	ll res = 0;
	for (int i = 0; i < E.size(); i++) {
		edge& e = E[i];
		if (uf.same(e.u, e.v)) continue;
		e.used = true;
		uf.unite(e.u, e.v);
		res += e.w;
	}
	return res;
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> S(M), D(M), C(M);
	for (int i = 0; i < M; i++)
		cin >> S[i] >> D[i] >> C[i];
	vector<bool> a(M, true);
	for (;;) {
		vector<edge> E(M);
		for (int i = 0; i < M; i++) {
			E[i].i = (a[i] ? i : -1);
			E[i].u = S[i] - 1;
			E[i].v = D[i] - 1;
			E[i].w = C[i];
			E[i].used = false;
		}
		kruskal(N, E);
		bool updated = false;
		for (int i = 0; i < M; i++)
			if (E[i].i != -1 && !E[i].used) {
				a[E[i].i] = false;
				updated = true;
			}
		if (!updated) break;
	}
	int cnt = 0, sum = 0;
	for (int i = 0; i < M; i++)
		if (a[i]) {
			cnt++;
			sum += C[i];
		}
	cout << cnt << ' ' << sum << endl;
} 

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

int main(){
  string str;
  while(1){
    int temp[50] = {}, n, sum, count, f = 0, ans = 0;

    cin>>n;

    if(n == 0) break;

    for(int i = 1; i <= n; i++){
      cin>>str;
      temp[i] = str.size();//cout<<temp[i]<<endl;
      // temp[i] += tmep[i-1];
    }

    for(int i = 1; i <= n; i++){
      sum = 0;count = 0;
      for(int j = i; j <= n; j++){//cout<<"-------"<<j<<endl;
	sum += temp[j];//cout<<sum<<endl;
	if(sum == 5 && (count == 0 || count == 2)){count++;sum = 0;}
	if(sum == 7 && (count == 1 || count == 3 || count == 4)){count++;sum = 0;}
	//	if(sum == 5 && count == 2){count++;sum = 0}
	//	if(sum == 7 && count == 3){count++;sum = 0}
	//	if(sum == 7 && count == 4){count++;sum = 0}
	if(count == 5){f = 1; break;}
      }
      if(f == 1){ans = i; break;}
    }

    cout<<ans<<endl;

  }
  return 0;
}



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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int x;
  cin >> x;

  if (x < 1200) cout << "ABC" << "\n";
  else cout << "ARC" << "\n";

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())

    d = collections.defaultdict(int)
    for a in map(int, input().split()):
        d[a] += 1

    #l = sorted(d.items(), key=lambda item: item[1], reverse=True)
    cands = filter(lambda item: item[1] >= 2, d.items())
    l = sorted(cands, key=lambda item: item[0], reverse=True)
    #print(l)

    if len(l) == 0:
        print(0)
    elif len(l) == 1 and l[0][1] < 4:
        print(0)
    elif l[0][1] >= 4:
        print(l[0][0] ** 2)
    else:
        print(l[0][0] * l[1][0])

if __name__ == "__main__": main()


Measured memory_bytes: 24616
#include <bits/stdc++.h>
#define ll long long 
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define dd double
#define ull unsigned int long long
const int INF = INT_MAX;
#define all(x) x.begin(),x.end()
#define mod 1000000007
using namespace std;
int main()
{
    
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    int flag=0;
    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
        {
            flag=1;
            cout<<"OK"<<endl;
            break;
        }
    }
    if(flag==0)
    {
        cout<<"NG"<<endl;
    }
      
}

Measured memory_bytes: 3596
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use std::collections::VecDeque;
use std::io::stdin;
use std::str::FromStr;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let s = sc.next_string();
    if s.chars().last().unwrap() == 's' {
        println!("{}es", s);
    } else {
        println!("{}s", s);
    }
}

pub struct Scanner {
    buf: VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect_vec()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn fill_vec_line<T: FromStr>(&mut self, v: &mut Vec<T>) {
        for vi in v {
            *vi = self.next();
        }
    }

    pub fn fill_vec<T: FromStr>(&mut self, v: &mut Vec<Vec<T>>) {
        for vi in v {
            for vii in vi {
                *vii = self.next();
            }
        }
    }

    pub fn make_vec_line<T: FromStr + Default + Clone>(&mut self, i: usize) -> Vec<T> {
        let mut v = vec![Default::default(); i];
        self.fill_vec_line(&mut v);
        v
    }

    pub fn make_vec<T: FromStr + Default + Clone>(&mut self, i: usize, j: usize) -> Vec<Vec<T>> {
        let mut v = vec![vec![Default::default(); j]; i];
        self.fill_vec(&mut v);
        v
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for ( int i = 0; i < N; ++i){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    
    int l,s;
    s = d.at(N/2-1);
    l = d.at(N/2);
    cout << l - s << endl;
    
    return 0;
}


Measured memory_bytes: 640
n = int(input())
sl = list(int(input()) for _ in range(n))
sl_sum = sum(sl)
sl.sort()

ans = 0

if sl_sum % 10 != 0:
    ans = sl_sum
else:
    for s in sl:
        if (sl_sum - s)%10 != 0:
            ans = max(sl_sum - s, ans)

print(ans)

Measured memory_bytes: 3060
n=int(input())
def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

from collections import defaultdict
d = defaultdict(int)
for i in range(1,n+1):
    for itm in fact(i):
        if itm[0]!=1:
            d[itm[0]]+=itm[1]
keys = d.keys()
a=0
for p in keys:
    if d[p]>=74:
        a+=1
    for q in keys:
        if p==q:
            continue
        if d[p] >=2 and d[q]>=24:
            a+=1
        if d[p] >=4 and d[q]>=14:
            a+=1
        for r in keys:
            if q==r or r==p:
                continue
            if d[p] >=2 and d[q]>=4 and d[r]>=4:
                a+=0.5

print(int(a))

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;

using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;

using tll = tuple<ll,ll,ll>;
using vtl = vector<tll>;

using vb = vector<bool>;
using vvb = vector<vb>;

using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

#define R(a,i) for(ll a=0; a < (i); (a)++)
#define FOR(a,i,j) for(ll a=(i); a < (j); (a)++)
#define RD(a,i) for(ll a=(i)-1; (a) >= 0; (a)--)
#define FORD(a,i,j) for(ll a=(j)-1; (a) >= (i); (a)--)

#define xx first
#define yy second
#define pb push_back
#define eb emplace_back

#define all(X) begin(X),end(X)
#define sz(X) (X).size()

const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;

#define DBG 0
#define TR(X) {if(DBG) cerr << (#X) << " = " << (X) << "\n";}
#define TRM(X,i,j) {if(DBG) cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n";}
#define TRP(X,i,j) {if(DBG) cerr << (#X) << "[" << i << "][" << j << "] = (" << (X[i][j]).xx << ", " << (X[i][j]).yy << ")\n";}
#define hline {if(DBG) cerr << "----------------------------------------------------------------------" << "\n";}
#define PK(X) {if(DBG) cerr << (X) << "\n";}

const ll mod = 1e9+7;

template <class T>
void myMin(T& a, T b){
	a = min(a,b);
}

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

	ll N;
	cin >> N;

	map<ll,ll> stack;
	vl h(N);
	vl a(N);
	vtl val(N);

	FOR(i,0,N) {
		cin >> h[i];
	}

	FOR(i,0,N) {
		cin >> a[i];
	}

	FOR(i,0,N) {
		val[i] = make_tuple(h[i], i+1, a[i]);
	}

	sort(all(val));

	stack[0] = 0;
	// xx is neg height
	// yy is sum value

	FOR(i,0,N) {
		ll height, value, idx;
		tie(height, idx, value) = val[i];

		TR(height);
		TR(value);
		TR(idx);

		if(stack.rbegin()->xx < idx){
			ll foo = stack.rbegin()->yy + value;
			stack[idx] = foo;
		} else {
			auto it = stack.lower_bound(idx);
			ll foo = prev(it)->yy + value;
			stack[idx] = foo;

			it = stack.upper_bound(idx);
			while(stack[idx] >= it->yy){
				stack.erase(it);
				it = stack.upper_bound(idx);
				if(it == stack.end())
					break;
			}
		}

#if DBG
		cerr << i << ": ";
		for(const auto &it : stack){
			cerr << "(" << it.xx << ", " << it.yy << ") ";
		}
		cerr << endl;
#endif
	}

	cout << stack.rbegin()->yy << endl;
}


Measured memory_bytes: 20608
// finish date: 2018/03/16

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    ll push_count = 0;
    vl A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    rep(i, N) {
        A[i] += push_count;
        push_count += ((A[i] + B[i] - 1) / B[i]) * B[i] - A[i];
    }
    cout << push_count << endl;


    return 0;
}

Measured memory_bytes: 1920
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    long n = cin.nextLong();
    long a = cin.nextLong();
    long b = cin.nextLong();
    long count = n/(a+b);
    long remain = n%(a+b);
    if (remain >= a)
      remain = a;
  
    System.out.println(count*a+remain);
  }

}

Measured memory_bytes: 23124