akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)
		puts("Alice");
	else
		puts("Borys");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

int main(){
    int n, y;
    cin >> n >> y;
    int aa = 0, bb = 0, cc = 0;
    bool z = false;
    for(int b = 0; b <= n; b++){
        for(int c = 0; c <= n; c++){
            if(n - b - c < 0) continue;
            if(y == (10000*n - 5000*b - 9000*c)){
                aa = n-b-c; bb = b; cc = c;
                z = true;
                break;
            }
        }
        if(z) break;
    }

    if(z) cout << aa << " " << bb << " " << cc << endl;
    else cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
# D - RGB Triplets

N = int(input())
S = str(input())
R_cnt = S.count('R')
G_cnt = S.count('G')
B_cnt = S.count('B')
total = R_cnt * G_cnt * B_cnt

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        k = j + (j - i)
        if k < N and (S[i] != S[j] and S[j] != S[k] and S[k] != S[i]):
            cnt += 1

print(total - cnt)


Measured memory_bytes: 9208
#include <vector>
#include <iostream>
using namespace std;
int H, W, N, x, y;
int main() {
	while (cin >> W >> H, H) {
		vector<vector<bool> > d(H, vector<bool>(W, false));
		cin >> N;
		for (int i = 0; i < N; i++) {
			cin >> x >> y; x--, y--;
			d[y][x] = true;
		}
		vector<vector<int> > dp(H, vector<int>(W, 0));
		dp[0][0] = 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (d[i][j]) continue;
				if (i >= 1) dp[i][j] += dp[i - 1][j];
				if (j >= 1) dp[i][j] += dp[i][j - 1];
			}
		}
		cout << dp[H - 1][W - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    in_arr(int, l, n);
    sort(l.begin(), l.end());
    int sum = 0;
    for(int i = n - k; i < n; i++){
        sum += l[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,k;
    int i;
    char s[50];

    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%s",s);
    
    s[k-1] = s[k-1] + 0x20;
    for(i=0; i<n; i++){
        printf("%c",s[i]);
    }
    printf("\n");
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll n, k;

    cin >> n >> k;

    vector<ll> w(n+1, INT_MAX), v(n+1, INT_MAX);

    vector<vector<ll>> sol(2, vector<ll>(k+1, INT_MIN));

    for (ll i=1; i<=n; i++) {
        cin >> w[i] >> v[i];
    }

    for (ll i=0; i<=1; i++) {
        sol[i][0] = 0;
    }

    for (ll i=0; i<=k; i++) {
        sol[0][i] = 0;
    }

    for (ll i=1; i<=n; i++) {
        for (ll j=1; j<=k; j++) {
            if (w[i] > j) {
                sol[1][j] = sol[0][j];
            } else {
                sol[1][j] = max(sol[0][j], v[i] + sol[0][j-w[i]]);
            }
        }

        for (ll j=1; j<=k; j++) {
            sol[0][j] = sol[1][j];
        }
    }

    cout << sol[0][k] << endl;
    
    return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  if (N <= K / 2) {
    cout << N;
  }
  else if (N <= K) {
    cout << K - N;
  }
  else {
    if (N % K <= K / 2) {
      cout << N % K;
    }
    else {
      cout << K - N % K;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    int p = w * ch + cw, q = w * dh + dw;
    vector<vector<vector<int>>> g(2, vector<vector<int>>(h * w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i != h - 1) {
                if (s[i][j] == '.' && s[i + 1][j] == '.') {
                    int x = i * w + j;
                    int y = x + w;
                    g[0][x].emplace_back(y);
                    g[0][y].emplace_back(x);
                }
            }
            if (j != w - 1) {
                if (s[i][j] == '.' && s[i][j + 1] == '.') {
                    int x = i * w + j;
                    int y = x + 1;
                    g[0][x].emplace_back(y);
                    g[0][y].emplace_back(x);
                }
            }
            for (int k = max(0, i - 2); k <= min(h - 1, i + 2); k++) {
                for (int l = max(0, j - 2); l <= min(w - 1, j + 2); l++) {
                    if (s[i][j] == '.' && s[k][l] == '.') {
                        int x = i * w + j;
                        int y = k * w + l;
                        g[1][x].emplace_back(y);
                        g[1][y].emplace_back(x);
                    }
                }
            }
        }
    }
    int inf = 1e9;
    vector<int> d(h * w, inf);
    d[p] = 0;
    deque<int> deq;
    deq.emplace_back(p);
    while (!deq.empty()) {
        int v = deq.front();
        deq.pop_front();
        for (int k = 0; k < 2; k++) {
            for (int to : g[k][v]) {
                if (d[to] > d[v] + k) {
                    d[to] = d[v] + k;
                    if (k == 0) {
                        deq.emplace_front(to);
                    } else {
                        deq.emplace_back(to);
                    }
                }
            }
        }
    }
    cout << (d[q] == inf ? -1 : d[q]) << '\n';
    return 0;
}

Measured memory_bytes: 143660
import itertools
from math import sqrt

N = int(input())
data = []
for _ in range(N):
	data.append(list(map(int, input().split())))

ite = list(itertools.permutations(data))
sum_num = 0
for D in ite:
	tmp = D[0]
	for i in range(1, N):
		sum_num += sqrt((tmp[0] - D[i][0]) ** 2 + (tmp[1] - D[i][1]) ** 2)
		tmp = D[i]

print(sum_num/len(ite))


Measured memory_bytes: 7972
def BinarySearch(n,key,A):
    left=0
    right=n
    while left<right:
        mid=(int)((left+right)/2)
        if A[mid]==key:
            return 2
        if key<A[mid]:
            right=mid
        if key>A[mid]:
            left=mid+1
    return 1
cnt=0
n=int(input())
S=[0 for i in range(n)]
S=input().split()
for i in range(n):
    S[i]=(int)(S[i])
q=int(input())
T=[0 for i in range(q)]
T=input().split()
for i in range(q):
    T[i]=(int)(T[i])
    a=BinarySearch(n,T[i],S)
    if a==2:
        cnt+=1
print(cnt)



Measured memory_bytes: 13904
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
#ans=min(n,9)
l=n.to_s.length

# c[先頭][末尾][桁数]=数
c=Array.new(10){Array.new(10,0)}

1.upto(n) do |i|
  b=i.to_s
  c[b[0].to_i][b[-1].to_i]+=1
end
#c.each{|i|puts i.to_s}

cnt=0
1.upto(n) do |i|
  b=i.to_s
  cnt+= c[b[-1].to_i][b[0].to_i]
  #puts "i:#{i},cnt:#{cnt}"
end
puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>

#define PI 3.14159265359
#define R  1.41421356237

using namespace std;

int sq(int a){
return a*a;
}

int main(){
	int l[3],t;
	int m,n,c=0;
	int r[10000];

	while(1){

		cin >> l[0] >> l[1] >> l[2];

		if((l[0]+l[1]+l[2])==0)break;

		cin >> n;

		//sort length
		sort(l,l+3);

		for(int i=0;i<n;i++){
			cin >> t;

			if((2*t > l[0]) && (sq(t*2)-sq(l[0]) > sq(l[1]))){
				r[i] = 1;
			}else{
				r[i] = 0;
			}
		}

		for(int i=0;i<n;i++){
			if(r[i]==0){
				cout << "NA" << endl;
			}else{
				cout << "OK" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1172
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int X=nextInt();
		if(X>=30)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	static boolean isOK(int index,int key,int[]a){
		if (a[index]>=key) return true;
	    else return false;
	}
	static int binary_search(int key,int[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 32552
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
 
const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};
 
#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
 
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
 
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
 
//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}
 
//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}
 
//ll nHr(int n,int r){ret nCr(n+r-1,r);}
 
///////////////////////////////////////////////////////////////////////////
 
 
ll v[35][100005] = {};

int main(){
    int n,c;
    cin >> n>> c;
 
    rep(i,0,n){
        int s,t,ca;
        cin >> s >> t >> ca;
        v[ca][s]++;
        v[ca][t]--;
    }
 
    ll ans = 0;
    rep(i,1,c+1){
        rep(j,0,100003){
            v[i][j+1] += v[i][j];
        }
    }
    rep(i,1,100005){
        ll t = 0;
        rep(j,1,c+1){
            t += v[j][i];
            if(v[j][i] == 0 && v[j][i-1] == 1)t++;
        }
        ans = max(ans,t);
    }
	P(ans);
	return  0;
}

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

string fwd, bwd;
int q, t, f;
char c;
int main(){
  bool back = false;
  cin >> fwd >> q;
  while (q--) {
    cin >> t;
    if (t==1) {
      back = !back;
      swap(fwd, bwd);
    } else {
      cin >> f >> c;
      (f==1 ? bwd : fwd) += c;
    }
  }
  reverse(bwd.begin(), bwd.end());
  cout << bwd << fwd << endl;
}


Measured memory_bytes: 960
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] T = new long[N];
		long ans = 1;
		for(int i=0;i<N;i++) {
			T[i] = sc.nextLong();
			ans = lcm(ans,T[i]);
		}
		System.out.println(ans);
	}

	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	public static long lcm(long a,long b) {
		if(a > b) return (a/gcd(a,b))*b;
		else return (b/gcd(a,b))*a;
	}
}


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

/*
素因数分解をする(エラトステネスの篩)
return はvectorで素因数が入っている
*/
vector<bool>eratosthenes(int n) {
	vector<bool>prime(n + 1, 1);
	prime[0] = prime[1] = false;
	for (int i = 2;i*i <= n;++i) {
		if (prime[i] == true) {
			for (int j = 2 * i;j <= n;j += i) {
				prime[j] = false;
			}
		}
	}
	return prime;
}

int main() {
	vector<bool>v = eratosthenes(100100);
	vector<int>ans(101000, 0);
	for (int i = 0;i < 100100;++i) {
		if (i % 2 == 1 && v[i] == true && v[(i + 1) / 2] == true) {
			ans[i]++;
		}
		ans[i + 1] += ans[i];
	}
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int l, r;
		cin >> l >> r;
		cout << ans[r] - ans[l - 1] << endl;
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    ll ret = 0;
    rep(i,n){
        ll a; cin >> a;
        ret += a-1;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc136_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            bool r = true;

            for (int i = 0; i < N - 1; i++) 
                if (H[i + 1] - H[i] > 0) H[i+1] -= 1;

            for (int i = 0; i < N - 1; i++)
                if (H[i + 1] - H[i] < 0)
                {
                    r = false;
                    break;
                }

            Console.WriteLine(r ? "Yes" : "No");
        }
    }
}


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

using namespace std;

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

  long long a, b;
  cin >> a >> b;
  vector<long long> div;
  long long c = __gcd(a, b);
  int ans = 1;
  for (long long i = 2; i * i <= c; ++i) {
    if (c % i == 0) {
      ++ans;
      while (c % i == 0) {
        c /= i;
      }
    }
  }
  cout << ans + (c != 1);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vl a(n); cin>>a;
    sort(all(a));
    vl b(n+1,0); rep(i,n)b[i+1]=a[i];
    partial_sum(all(b),b.begin());
    ll ans=0, acnt;
    // puta(a);
    // 値がmid以上のものがいくつあるか？が，ちょうどmになるmが存在
    ll ok=0, ng=200001;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        // puta("mid : ",mid);
        ll cnt=0, val=0;
        rep(i,n){
            ll p = lower_bound(all(a),mid-a[i])-a.begin();
            // puta(a[i],n-p, p, ":", (b[n]-b[p]), (b[n]-b[p])+a[i]*(n-p));
            cnt+=n-p;
            val += (b[n]-b[p])+a[i]*(n-p); //-(i+n-p >= n?1:0)
        }
        // puta("cnt : ", cnt, val);
        if(cnt>=m){
            ok=mid;
            ans=val;
            acnt=cnt;
            // puta("ans : ", ans);
        }else{
            ng=mid;
        }
        // puta("=======");
    }

    puta(ans - ok*(acnt-m));
    return 0;
}

Measured memory_bytes: 1792
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
 
int n,m,b[li],a[li],k,flag,t;
int cev;
string ss,s;
vector<int> v;
 
int main(void){
	cin>>s;
	cin>>ss;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]==ss[i])cev++;
	}
	printf("%d\n",cev);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<pair<int, int>> pair(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
        pair[i].first = p[i];
        pair[i].second = i+1;
    }

    int ans = 0;
    vector<int> tmp(n);
    int tmp2 = p[0];
    for(int i = 0; i < n; i++) {
        tmp[i] = min(p[i], tmp2);
        tmp2 = tmp[i];
    }
    for(int i = 0; i < n; i++) {
        //cout << tmp[i] << " " ;
        if(tmp[i] == p[i]) {
            ans++;
        }
    }
    //cout << endl;
    cout << ans << endl;
    return 0;

}

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

const int MAXN = 3002;

double dp[MAXN][MAXN],P[MAXN];
int vis[MAXN][MAXN],N;

double solve(int pos,int heads){
	
	if(heads < 0) return 0.0;

	if(pos == 0){
		return (heads == 0);
	}

	if(vis[pos][heads]) return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> P[i];
	}

	double tot = 0;
	for(int heads = 0;heads<=N;heads++){
		int tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

	printf("%.9lf\n",tot);

	return 0;

}

Measured memory_bytes: 105156
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

bool ask(int x, int y) {
  printf("? %d %d\n", x, y);
  fflush(stdout);
  char c;
  scanf(" %c", &c);
  fflush(stdin);
  if (c == 'Y') {
    return true;
  } else {
    return false;
  }
}

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  fflush(stdin);
  int n = a + b;
  if (a <= b) {
    printf("Impossible\n");
    fflush(stdout);
    return 0;
  }
  deque<int> q;
  rep (i, n) {
    if (q.empty()) {
      q.push_back(i);
      continue;
    }
    if (ask(q.back(), i)) {
      q.push_back(i);
    } else {
      q.pop_back();
    }
  }
  assert(!q.empty());
  vi ans(n, 0);
  int judge = q.back();
  rep (i, n) {
    if (ask(judge, i)) {
      ans[i] = 1;
    }
  }

  printf("! ");
  rep (i, n) {
    printf("%d", ans[i]);
  }
  printf("\n");
  fflush(stdout);

  return 0;
}


Measured memory_bytes: 724
from sys import stdin
from math import pi
from bisect import bisect
from itertools import repeat
def main():
    x1, y1, x2, y2 = map(int, stdin.readline().split())
    sx = 1
    if x1 > x2:
        x1, x2 = -x1, -x2
        sx = -1
    sy = 1
    if y1 > y2:
        y1, y2 = -y1, -y2
        sy = -1
    n = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * n))
    a = []
    for i in xrange(n):
        x, y = dat[i*2:i*2+2]
        x *= sx
        y *= sy
        if x1 <= x <= x2 and y1 <= y <= y2:
            a.append((x, y))
    a.sort()
    c = pi * 10 - 20
    b = [-10 ** 9] + [10 ** 9] * 200010
    m = 1
    for x, y in a:
        p = bisect(b, y, lo=0, hi=m)
        b[p] = y
        if p == m:
            m += 1
    d = pi * 5 - 20
    if m <= min(x2 - x1 + 1, y2 - y1 + 1):
        c = d
    print "%.12f" % ((x2 - x1 + y2 - y1) * 100 + (m - 2) * d + c)
main()


Measured memory_bytes: 44668
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int>G[MAX];
int color[MAX];

void dfs(int r,int c){
  stack<int> S;
  S.push(r); 
  color[r]=c;
  while(!S.empty()){
    int u=S.top();
    S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v);
      }
    }
  }
}
int main(){
  int s,t,m,q;
  cin>>n>>m;


for(int i=0;i<m;i++){
  cin>>s>>t;
  G[s].push_back(t);
  G[t].push_back(s);
 }

int id=1;
for(int i=0;i<n;i++){
  color[i]=NIL;
 }

for(int u=0;u<n;u++){
  if(color[u]==NIL)
    dfs(u,id++);
 }

cin>>q;

for(int i=0;i<q;i++){
  cin>>s>>t;
  if(color[s]==color[t]){
    cout<<"yes"<<endl;
  }
  else{
    cout<<"no"<<endl;
  }
 }
return 0;
}



Measured memory_bytes: 8924
#include <iostream>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <algorithm>

void b(std::istream& in)
{
    std::string S, T;
    in >> S;
    in >> T;

    size_t counter = 0;
    for (size_t i = 0; i < S.size(); ++i)
    {
        if (S.at(i) != T.at(i))
        {
            ++counter;
        }
    }

    std::cout << counter;
}

int main(int, char* [])
{
    b(std::cin);
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> V;
    for(int i = 1; i <= min(A, B); i++)
    {
        if(A % i == 0 && B % i == 0)
            V.push_back(i);
    }
    int n = V.size();
    cout << V[n - K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n,a[maxn],mid,L,R,Ans,N;
bool b[maxn];
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-f;ch=getchar();}
	while (ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
inline bool check(int x){
	int mina=1<<30,minb=1<<30;
	for (int i=1;i<N;i++)
	  if (a[i]<x) b[i]=0;
	  else b[i]=1;
	for (int i=1;i<N-1;i++)
	  if (b[i]==b[i+1]){
	  	if (b[i]) mina=min(mina,min(abs(n-i),abs(n-i-1)));
	  	else minb=min(minb,min(abs(n-i),abs(n-i-1)));
	  }
	if (mina==1<<30&&minb==1<<30) return b[1];
	return mina<minb;
}
int main(){
	n=read();N=n<<1;
	for (int i=1;i<N;i++) a[i]=read();
	L=-1,R=1e8;
	while(R-L>1){
		int mid=L+R>>1;	
		if(check(mid)) L=mid;
		else R=mid;
	}	
	printf("%d",L);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long int lli;
const lli mod1 = 1e9 +7, mod2 = 1e9+21;
const lli base1 = 1007, base2 = 1021;

lli power(lli n, lli p, lli mod){
	lli ret=1;
	for(int i=62; i>=0; i--){
		ret = (ret*ret)%mod;
		if((1LL<<i & p) != 0) ret = (ret*n)%mod;
	}
	return ret;
}

int main(){
	int n,m;
	string s;
	cin >> n >> m >> s;
	
	vector<lli> h1(n+1, 0), h2(n+1, 0);
	for(int i=0; i<n; i++){
		h1[i+1] = (h1[i]*base1 + s[i]-'a'+1)%mod1;
		h2[i+1] = (h2[i]*base2 + s[i]-'a'+1)%mod2;
	}
	int l=0, r=1;
	set<lli> sset1, sset2;
	int ans = 0;
	for(int i=0; i<m; i++){
		string q;
		cin >> q;
		if(q=="L++") l++;
		if(q=="L--") l--;
		if(q=="R++") r++;
		if(q=="R--") r--;
		lli hash1 = (h1[r] -(h1[l]*power(base1, r-l, mod1))%mod1 +mod1)%mod1;
		lli hash2 = (h2[r] -(h2[l]*power(base2, r-l, mod2))%mod2 +mod2)%mod2;
		if(sset1.find(hash1)==sset1.end() || sset2.find(hash2)==sset2.end()){
			ans++;
		}
		sset1.insert(hash1);
		sset2.insert(hash2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35892
n=int(input())

if n>0 and n<1001:
    x=1000-n
if n>1000 and n<2001:
    x=2000-n
if n>2000 and n<3001:
    x=3000-n
if n>3000 and n<4001:
    x=4000-n
if n>4000 and n<5001:
    x=5000-n
if n>5000 and n<6001:
    x=6000-n
if n>6000 and n<7001:
    x=7000-n
if n>7000 and n<8001:
    x=8000-n
if n>8000 and n<9001:
    x=9000-n
if n>9000 and n<10001:
    x=10000-n

print(x)

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

const int MAX_N = 100;

int main(){
	int n,a[MAX_N];
	cin>>n;

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

	sort(a,a+n);

	cout<< abs(a[0]-a[n-1]) <<endl;

}


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

char x,y;

int main(){
    cin >> x >> y;
    if((int)x > (int)y){
        cout << '>' << endl;
    }else if((int)x < (int)y){
        cout << '<' << endl;
    }else{
        cout << '=' << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int k,a,b;
 cin>>k;
 cin>>a>>b;
 int A,B;
 A=a/k;
 B=b/k;
  if(a%k==0 ||b%k==0){
    cout<<"OK"<<endl;
  }
 else if(A<B){
 cout<<"OK"<<endl;
 }
 else{
   cout<<"NG"<<endl;
 }
  
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#include<cassert>
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MRE assert(0)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int>PP;
int a[106];

void dispa(int n) {
	rep(i, n) {
		if (i)cout << ' '; cout << a[i];
	}cout << endl;
}

signed main() {
	int n, m; cin >> n >> m;
	int co = 0;
	rep(i, m) {
		cin >> a[i];
		if (a[i] & 1)co++;
	}
	if (co >= 3)puts("Impossible");
	else if (co <=2) {
		if (co==1) {
			int pos;
			rep(i, m)if (a[i] & 1)pos = i;
			swap(a[pos], a[0]);
		}
		else if (co == 2) {
			int pos1 = -1, pos2 = -1;
			rep(i, m) {
				if (pos1==-1&&(a[i] & 1)) {
					pos1 = i;
				}
				else if (a[i] & 1) {
					pos2 = i;
				}
			}
			swap(a[pos1], a[0]);

			swap(a[pos2], a[m - 1]);
		}

		dispa(m);
		if (m == 1) {
			if (a[0] > 1) {
				m++; a[0]--; a[1]++;
			}
		}
		else {
			a[0]++;
			a[m - 1]--;
			if (!a[m - 1])m--;
		}
		cout << m << endl;
		dispa(m);
	}
	else MRE;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <deque>
using namespace std;

const int MAX_K = 100000;
vector< pair<int, int> > V[MAX_K];
bool reached[MAX_K];

void make_graph(unsigned int k) {
  //cout << "make graph" << endl;
  for (unsigned int i = 1; i < k; i++) {
    V[i].push_back(make_pair((i+1) % k, 1));
    if (i*10 %k != i) {
      V[i].push_back(make_pair(i*10 % k, 0));
    }
  }
  // for (unsigned int i = 0; i < k; i++) {
  //   for (auto itr = V[i].begin(); itr != V[i].end(); ++itr) {
  //     cout << i << "->" << itr->first << ": " << itr->second << ' ';
  //   }
  //   cout << endl;
  // }
}

int bfs (unsigned int k) {

  pair<int, int> node = make_pair(1, 1);
  deque<pair<int, int>> queue; // first: node, second: cumulative cost
  fill(reached, reached+k, false);

  while (node.first > 0) {
    //cout << node.first << ": " << node.second << endl;
    reached[node.first] = true;

    for (auto i = V[node.first].begin(); i != V[node.first].end(); ++i) {
      pair<int, int> next_node = *i;
      if (!reached[next_node.first]) {

	  if (next_node.second == 0) {
	    queue.push_front(make_pair(next_node.first, node.second));
	  }
	  else if (next_node.second == 1) {
	    queue.push_back(make_pair(next_node.first, node.second + 1));
	  }

      }
    }
    // for (auto itr = queue.begin(); itr != queue.end(); ++itr) {
    //   cout << itr->first << ": " << itr->second << ' ';
    // }
    //cout << endl;
    //cout << endl;
    node = queue.front();
    queue.pop_front();
  }
  return node.second;
}

int main() {
  unsigned int k;
  cin >> k;
  make_graph(k);
  cout << bfs(k) << endl;
}

Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n ; i++)
#define rep(i,n) REP(i,0,n)
vector<vector<string> > input;
int g[102][102];
class State{
public:
  int p;
  int cost;
  State(int p, int cost):p(p), cost(cost){

  }
  bool operator < (const State &o) const{
    return cost > o.cost;
  }
};
typedef priority_queue<State> PQ;


int n;

void makeGraph(){
  rep(i,102)rep(j,102)g[i][j] = -1;
  rep(i, (int)input.size()){
    if(input[i][0] == "goto"){
      g[i][i+1] = 1;
      rep(j, (int)input.size()){
	if(input[j][0] == input[i][1]){
	  g[i][j] = 0;
	}
      }
    }
    else{
      g[i][i+1] = 0;
    }
  }

}
bool visited[102];
void dijkstra(){
  memset(visited, 0, sizeof(visited));
  PQ pq;
  pq.push(State(0,0));
  while(!pq.empty()){
    State cur = pq.top();pq.pop();
    if(visited[cur.p])continue;
    if(cur.p == n){
	cout << cur.cost << endl;
	return;
    }
    visited[cur.p] = true;
    for(int i = 0 ; i < n+1; i++){
      if(g[cur.p][i] == -1)continue;
      pq.push(State(i, cur.cost + g[cur.p][i]));
    }
  }
}
void solve(){
  makeGraph();
  dijkstra();
}
void split(string s){
  vector<string> v;
  stringstream ss;
  ss << s;
  string _s;
  while(ss >> _s){
    if(_s != "goto"){
      _s = _s.substr(0,_s.size()-1);
    }
    v.push_back(_s);
  }
  input.push_back(v);
  
}

int main(){

  cin >> n;
  string line;
  getline(cin, line);
  rep(i,n){
    getline(cin, line);
    split(line);
  }
  solve();
  return 0;
}

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

int main(){
int a,b,x,y,g;
cin>>a>>b;
x=a/b;
y=a%b;
g=y*1000000/b;
cout<<x<<" "<<y<<" "<<x<<"."<<g<<endl;
return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
int mp[MAXN],val[MAXN];
bool vis[MAXN];
struct edge
{
	int next,to,v;
}e[MAXN*10];
struct node
{
	int x,v;
	bool operator <(const node& a)const{
		return v>a.v;
	};
};
int cnt=0,n;
void add(int x,int y,int v)
{
	cnt++;
	e[cnt].v=v;
	e[cnt].to=y;
	e[cnt].next=mp[x];
	mp[x]=cnt;
}
priority_queue<node> q;
void dis()
{
	node k;
	k.v=0;k.x=n+1;
	q.push(k);
	while(!q.empty()){
		k=q.top();
		q.pop();
		if(vis[k.x]) continue;
		vis[k.x]=1;
		val[k.x]=k.v;
		for(int i=mp[k.x];i;i=e[i].next)
		if(!vis[e[i].to]){
			node p;
			p.x=e[i].to;
			p.v=k.v+e[i].v;
			q.push(p);
		}
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	for(j=0;j<=9;j++)
	add(i,(i*10+j)%n,j);
	for(i=1;i<=9;i++) add(n+1,i,i);
	dis();
    printf("%d\n",val[0]);
    return 0;
 } 

Measured memory_bytes: 21104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int datasets = in.nextInt();
		in.nextLine();
		for(int i = 0; i<datasets; i++) {
			String a = in.nextLine();
			String b = in.nextLine();
			System.out.println(LCS(a, b));
		}
	}
	
	public static int LCS(String a, String b) {
		int m = a.length();
		int n = b.length();
		int[][] subprobs = new int[m+1][n+1];
		
		for(int i = 0; i <= m; i++) {
			subprobs[i][0] = 0;
		}
		
		for(int i = 0; i<=n; i++) {
			subprobs[0][i] = 0;
		}
		
		for(int i = 1; i<=m; i++) {
			for(int j = 1; j<=n; j++) {
				if(a.charAt(i-1) != b.charAt(j-1)) {
					subprobs[i][j] = Math.max(subprobs[i-1][j], subprobs[i][j-1]);
				}
				else {
					subprobs[i][j] = 1 + subprobs[i-1][j-1];
				}
			}
		}
		
		return subprobs[m][n];
	}

}



Measured memory_bytes: 64748
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <thread>///////////////////

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<long long int> vll;
vector<long long int> w;
//vector<vector<int>> vec(50, vector<int>(4, 0));

int N, Y;
int mode = 0;

//tuple<int, int, int> calc(int A, int B, int C) {}



int main() {
	int N, K,last;
	cin >> K >> N;
	//vector<vector<int>> vec(N, vector<int>(2, 0));
	v.resize(N);
	w.resize(N);
	rep(i, 0, N) {
		cin >> v[i];
		if (i == 0)w[i] = v[i];
		else w[i] = v[i] - v[i - 1];
	}
	w[0] += K - v[N - 1];


	int max = *max_element(w.begin(), w.end());
	int ans = K - max;

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    while(cin >> n >> k and n and k) {
        vector<int> a(n + 1);
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int ans = lim<int>::min();
        int s = 0;
        for(int i = 1; i <= n; i++) {
            s += a[i];
            if(i >= k) {
                s -= a[i - k];
                ans = max(ans, s);
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

struct Unionfind {
  // tree number
  vector<int> par;
  // constructor
  Unionfind(int n = 1) : par(n, -1) {}
  // search root
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return 0;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

struct edge {
  int x, y;
  long long cos;
  bool operator<(const edge &r) const {
    if (cos != r.cos) return cos > r.cos;
    if (x != r.x) return x > r.x;
    return y > r.y;
  }
};

long long n;
vector<edge> edges;
vector<long long> res, memo, sum;
vector<set<int>> g;
Unionfind uf;

void solve();

int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    edges.push_back({--x, --y, c});
  }
  solve();
  for (auto p : res) cout << p << endl;
  return 0;
}

void solve() {
  uf = Unionfind(n);
  res.assign(n, 0);
  sum.assign(n, 0);
  g.resize(n);
  for (int i = 0; i < n; ++i) g[i].insert(i);
  sort(edges.begin(), edges.end());
  for (auto e : edges) {
    long long x = uf.root(e.x), y = uf.root(e.y), c = e.cos, sx, sy;
    sx = uf.size(x);
    sy = uf.size(y);
    if (sx < sy) {
      swap(x, y);
      swap(sx, sy);
    }
    sum[x] += sy * c;
    for (auto p : g[y]) {
      res[p] += sx * c - sum[x] + sum[y];
      g[x].insert(p);
    }
    uf.uni(x, y);
  }
  for (int i = 0; i < n; ++i) res[i] += sum[uf.root(i)];
}

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

int main()
{
    int n,k,q,i;
    cin >> n >> k >> q;
    vector<int> p(n,0);
    int a;
    for(i = 0;i < q;++i){
        cin >> a;
        ++p.at(a-1);
    }
    for(i = 0;i < n;++i){
        if((k-q+p.at(i)) > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
import copy


def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x[1]:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


n = int(input())
data = []
for _ in range(n):
    mark, num = map(str, input().split())
    data.append([mark, int(num)])
data1 = copy.deepcopy(data)

quicksort(data, 0, n-1)

for i in range(n-1):
    if data[i][1] == data[i+1][1]:
        if data1.index(data[i]) > data1.index(data[i+1]):
            print("Not stable")
            break
else:
    print("Stable")

for d in data:
    print(' '.join(str(dd) for dd in d))


Measured memory_bytes: 39512
input = []
while (n = gets.to_i) != 0 do
  input = gets.split.map(&:to_i)
end

puts input*" "
for i in 1..input.size - 1 do
  v = input[i]
  j = i - 1
  while j >= 0 && input[j] > v do
    input[j+1] = input[j]
    j -= 1
    input[j+1] = v
  end
  puts input*" "
end


Measured memory_bytes: 6884
#include <bits/stdc++.h>
//#define int long long int
#define MOD 1000000007
#define MAX INT_MAX
using namespace std;

int add(int a, int b) {
    int z = (a%MOD + b%MOD) % MOD;
    return z;
}

int mul(int a, int b) {
    int z = (a%MOD * b%MOD) % MOD;
    return z;
}

int myXOR(int x, int y) {
     return (x | y) & (~x | ~y);
}

void solve() {
    int n;
    cin >> n;
    cout << 3*n*n << '\n';
    return ;
}              

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  long ans=0,flag;
  char s[310][310];
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%s",s[i]);
  for(int k=0;k<n;k++){
    flag=1;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
        if(s[(i+k)%n][j]!=s[(j+k)%n][i]){
          flag=0;
          break;
        }
    ans+=(long)flag*n;
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 924
# ncrかなと思うが実験すると1 3 6 10 15 21みたいなのが出てくる
# あらかじめN個作っとくんだけどこれ間に合うん？
# 無理ですね はい  解説

# 愚直にみればそれぞれ選ぶか選ばないかで2通りがn回続く
# a,bの2数も含むとすると、すなわち、2^(n) - 1（かならず1本は選ぶので）。これは繰り返し二乗法で解く。
# ここからa,bを考えたものを引く。具体的にはnCr(n, a) mod p とnCr(n, b) mod pを引く。
# nCr mod pで間に合わんやんけと思って諦めたけどよくよく読んだら条件はa = min(n, 2*10^5)なので間に合うやんけ
# nCrの式変形で分母と分子をそれぞれ作ってやるっていう愚直なやつでもいけるんじゃねこれ

n, a, b = map(int, input().split())
MOD = 10**9 + 7


# 繰り返し二乗法
def repMod(a, n, p):
    if n == 1:
        return a % p
    if n % 2 == 1:
        return a * repMod(a, n - 1, p) % p
    ret = repMod(a, n // 2, p) % p
    return (ret * ret) % p


all_comb = repMod(2, n, MOD)
# nCr = n!/(r!(n-r)!) ゆえ ((n-r+1) * (n-r+2) * .. * n)/(1*2*3*..*r)
# これがr = min(n, 2*10^5)なので愚直にやっても間に合う


def nCrMod(n, r, p):
    ret = 1
    # 分子
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret %= p
    # 分母
    for i in range(2, r + 1):
        # ret //= i なんかこれがおかしい（なんでだろうね）
        ret *= repMod(i, p - 2, p)  # なぜかここでやらないと駄目だった
        ret %= p
    # ret = repMod(ret, p - 2, p) # なぜかここでやると駄目だった
    return ret % p


print((all_comb - nCrMod(n, a, MOD) - nCrMod(n, b, MOD) - 1) % MOD)


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

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

    tiii xyh[n];
    int base = -1;
    rep(i, 0, n) 
    {
        int x, y, h;
        cin >> x >> y >> h;
        xyh[i] = make_tuple(x, y, h);
        if (h > 0) base = i;
    }

    rep(cx, 0, 101)
    rep(cy, 0, 101)
    {
        int height = -1;
        int x, y, h;

        tie(x, y, h) = xyh[base];
        height = h + abs(x - cx) + abs(y - cy);

        bool ok = true;
        rep(i, 0, n)
        {
            tie(x, y, h) = xyh[i];
            ok &= h == max(0, height - abs(x - cx) - abs(y - cy));
        }
        if (ok)
        {
            cout << cx << ' ' << cy << ' ' << height << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll ans=10*b+c;
  if(ans%4==0) co("YES")
    else co("NO")
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define REP(i,b,n) for(int (i)=b; (i)<(int)(n); ++(i))
#define rep(i,n) REP(i,0,n)
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(a) (a).begin(),(a).end()
#define print(var) cout<<#var":"<<(var)<<endl;
#define printkv(key,var) cout<<#key":"<<(var)<<endl;
#define updatemax(dst,src) dst=max(dst,src);
#define updatemin(dst,src) dst=min(dst,src);

typedef long long ll;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
  if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}


ll N;
ll M;

int main() {
  while (cin >> N >> M) {
    ll ans = 0;
    ll avail = min(N*2, M);
    ans = avail / 2;
    M -= ans * 2;
    ans += M / 4;
    cout << ans << endl;
  }
}


Measured memory_bytes: 888