akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull A = 9999973, B = 950527;

int H, W;
char T[1005][1005];
ull t[1005][1005];
ull t2[1005][1005];
int h, w;
char U[1005][1005];

int main() {
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; i++) scanf("%s", T[i]);
    scanf("%d %d", &h, &w);
    for(int i = 0; i < h; i++) scanf("%s", U[i]);
    
    ull target = 0;
    for(int i = 0; i < h; i++) {
        ull key = 0;
        for(int j = 0; j < w; j++) {
            key = key * B + U[i][j];
        }
        target = target * A + key;
    }
    
    ull C = 1;
    for(int i = 0; i < w; i++) C *= B;
    
    for(int i = 0; i < H; i++) {
        ull key = 0;
        for(int j = 0; j < W; j++) {
            key = key * B + T[i][j];
            if(j - w >= 0) key -= T[i][j - w] * C;
            t[i][j] = key;
            t2[i][j] = t[i][j];
        }
    }
    
    C = 1;
    for(int i = 0; i < h; i++) C *= A;
    
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(i) t[i][j] += t[i-1][j] * A;
            if(i - h >= 0) t[i][j] -= t2[i-h][j] * C;
            if(t[i][j] == target) {
                if(i - h + 1 >= 0 && j - w + 1 >= 0) {
                    printf("%d %d\n", i - h + 1, j - w + 1);
                }
            }
        }
    }
    return 0;
}


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

const int m=1000000007;

int main(){
  int n;
  cin >> n;
  ll ans=0,sub=0;
  sub=1;
  rep(i,n){sub*=10;sub%=m;}
  ans+=sub;
  sub=1;
  rep(i,n){sub*=9;sub%=m;}
  ans-=2*sub;ans%=m;
  sub=1;
  rep(i,n){sub*=8;sub%=m;}
  ans+=sub;ans%=m;
  if(ans<0) ans+=m;
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace std;
typedef pair<double,double> Point;

void Koch(int n,Point p1,Point p2){
  if (n==0){
    cout<<p1.first<<" "<<p1.second<<endl;
  }else{
    double tri_len = sqrt(pow((p2.first-p1.first)/3.0,2)+pow((p2.second-p1.second)/3.0,2));
    double angle=atan2(p2.second-p1.second,p2.first-p1.first);
    Point pp1(p1.first+(p2.first-p1.first)/3.0,p1.second+(p2.second-p1.second)/3.0);
    Point pp2(pp1.first+tri_len*cos(angle+M_PI/3.0),pp1.second+tri_len*sin(angle+M_PI/3.0));
    Point pp3(p1.first+(p2.first-p1.first)/3.0*2.0,p1.second+(p2.second-p1.second)/3.0*2.0);
    Koch(n-1,p1,pp1);
    Koch(n-1,pp1,pp2);
    Koch(n-1,pp2,pp3);
    Koch(n-1,pp3,p2);
  }
}

int main(){
  int n;
  cin>>n;
  Koch(n,Point(0,0),Point(100,0));
  cout<<100.0<<" "<<0.0<<endl;
  return 0;
}



Measured memory_bytes: 3684
M, D = map(int, input().split())
count = 0

for i in range(22, D+1):
  d1 = i % 10
  d10 = i // 10
  m = d1 * d10
  if (m <= M) and (d1 >= 2):
    count += 1
    #print(m, i)
print(count)

Measured memory_bytes: 38384
#include <stdio.h>

int ord(const void *x, const void *y){
	const int a = *((int *)x);
	const int b = *((int *)y);
	
	if (a>b)
		return 1;
	if (a<b)
		return -1;
	
	return 0;
}

int main(){
	int x;
	scanf("%d", &x);
	long long int vet[x+10];
	
	for(int i=0;i<x;i++){
		scanf("%lli", &vet[i]);
	}
	
	qsort(vet,x,sizeof(vet[0]), ord);
	
	printf("%lli\n", vet[x-1]-vet[0]);
	
	return 0;
}
	


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{
    const int MOD = 1e9+7;
    int n,m;
    cin >> n >> m;
    vector<int> broken(n,false);
    rep(i,m)
    {
        int a; 
        cin >> a;
        broken[a-1] = true;
    }

    vector<int> dp(n+1, 0);
    dp[0] = 1;
    dp[1] = broken[0] ? 0 : 1;

    rep2(i,2,n+1)
    {
        if(broken[i-1])
            dp[i] = 0;
        else
            dp[i] = (dp[i-2] + dp[i-1]) % MOD;
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
li = []
for _ in range(N):
    li.append(int(input()))
li.sort()
kaisu = N-K+1
li2 = []
for i in range(kaisu):
    dist = li[i+K-1] - li[i]
    li2.append(dist)
print(min(li2))

Measured memory_bytes: 11288
n, k = map(int, input().split())
warping = list(map(lambda x: int(x) - 1, input().split()))

is_warped = [ False ] * n
is_warped[0] = True

x = 0
cycle = 0

while not is_warped[warping[x]]:
    x = warping[x]
    is_warped[x] = True

    cycle += 1

    if cycle == k:
        print(x + 1)
        exit(0)

x = warping[x]
cycle += 1

y = 0
cnt = 0

while warping[y] != x:
    y = warping[y]
    cnt += 1

y = warping[y]
cnt += 1

cycle -= cnt

mod = (k - cnt) % (cycle if cycle != 0 else cnt)

while mod:
    y = warping[y]

    mod -= 1

print(y + 1)

Measured memory_bytes: 32396
#include <stdio.h>
#define N 100000
#define inf 2000000
#define WHITE 1
#define BLACK 2 
void dij();

int n,u,e,v,c[100][N],d[N],pi[N],color[N],q[100];
int main(){
  int i,k,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      c[i][j]=inf;}}
  for(i=0;i<n;i++){
    scanf("%d%d",&e,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&c[e][v]);
    }
    
  }
  dij();
  
  for(i=0;i<n;i++)
    printf("%d %d\n",i,d[i]);

  return 0;
}

void dij(){
  int mincost,k,h,i,y;
  for(u=0;u<n;u++){
    d[u]=inf;
    pi[u]=-1;
    color[u]=0;
  }
  d[0]=0;

  while(1){
    mincost=inf;
    
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf){
      break;
    }
    color[u]=BLACK;
    for(k=0;k<n;k++){
      if(color[k]!=BLACK && d[u]+c[u][k]<d[k]){
	pi[k]=u;

       d[k]=d[u]+c[u][k];

      }
      
    }
   
  }
  
    
      
    
  }

Measured memory_bytes: 37496
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b - 1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

int main(){
    ll N; cin >> N;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    int index = -1;
    int ans = 0, cnt = 0;

    rep(i,N-1){
        if(H[i] < H[i+1]){
            ans = max(ans, cnt);
            cnt = 0;
        }else{
            cnt++;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

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

namespace ABC_149b
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            if(input[0] > input[2])
            {
                input[0] -= input[2];
            }
            else if (input[0]+input[1]>input[2])
            {
                input[1] -= input[2] - input[0];
                input[0] = 0;
            }
            else
            {
                input[0] = 0;
                input[1] = 0;
            }

            Console.WriteLine(input[0]+" "+input[1]);
            Console.Read();
        }
    }
}


Measured memory_bytes: 27528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  
  cout<<min(N*A,B)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val N = sc.nextInt()
    var res = N
    for (i <- 0 to N) {
      var cc = 0
      var t = i
      while (t > 0) {
        cc += t % 6
        t /= 6
      }
      t = N - i
      while (t > 0) {
        cc += t % 9
        t /= 9
      }

      if (res > cc) res = cc
    }

    println(res)
  }
}

Measured memory_bytes: 25544
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
#define ll long long int
#define yes cout<<"YES"<<endl
#define NO cout<<"NO"<<endl

#define p(a) cout<<a<<endl

int main()
{
    int n;
    cin>>n;
    if(n<=111)
        cout<<111;
    else if(n<=222)
        cout<<222;
    else if(n<=333)
        cout<<333;
    else if(n<=444)
        cout<<444;
    else if(n<=555)
        cout<<555;
    else if(n<=666)
        cout<<666;
    else if(n<=777)
        cout<<777;
    else if(n<=888)
        cout<<888;
    else if(n<=999)
        cout<<999;
    return 0;
}


Measured memory_bytes: 888
#AGC029-A Irreversible operation
"""
問題：
一直線上にオセロがある
一回の操作で[黒白]を裏返す時[白黒]、最大何回の操作が行えるか
解法：
まずいちばん最初のBが出てくるところまでは無視できる
そこから、Bの数*Wの数が答え
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
flag = 0
black = 0
white = 0
ans = 0
for i in s:
    if flag:
        if i == "B":
            black += 1
        else:
            ans += black
    else:
        if i == "B":
            flag = 1
            black += 1
print(ans)

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

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

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

const int MAX = 1e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, M;
vector<int> G[MAX];

vector<int> bfs(int n) {
    queue<int> q;
    q.push(n);
    vector<int> vis(N, INF);
    vis[n] = -1;
    while (!q.empty()) {
        int now = q.front(); q.pop();
        for (int i : G[now]) {
            if (vis[i] == INF) {
                vis[i] = now;
                q.push(i);
            }
            if (i == n) {
                vector<int> res;
                int j = now;
                while (j != -1) {
                    res.push_back(j);
                    j = vis[j];
                }
                return res;
            }
        }
    }
    vector<int> v(N + 1);
    return v;
}

int main(){
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    vector<int> ans(N + 1);

    rep(i, N) {
        vector<int> res = bfs(i);
        if (res.size() < ans.size()) {
            ans = res;
        }
    }

    if (ans.size() == N + 1) {
        cout << "-1" << endl;
        return 0;
    }

    cout << ans.size() << endl;
    for (auto i : ans) {
        cout << i + 1 << endl;
    }
}

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c) cout << 1 << endl;
  else if((a == b && a != c&& b != c) || (a == c && a != b&& b != c) || (b == c && b != a && c != a)) cout << 2 << endl;
  else if(a != b && a != c && b != c) cout << 3 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* Alohomora */
            #include<bits/stdc++.h>
            #define ll         long long
            #define fl(i,n)    for(i=0;i<n;i++)
            #define fld(i,a,b) for(i=a;i>b;i--)
            #define fli(i,a,n) for(i=a;i<n;i++)
            #define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
            #define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
            #define pb         push_back
            #define mp         make_pair
            #define mod        1000000007 
            #define all(x) 	   x.begin(),x.end()	
            #define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
            #define bada 1000000000000000005
            using namespace std;
            ll fac(ll n){ if(n==0){return 1;}return (n*fac(n-1))%mod;}
            ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
            ll inverse(ll a){return power(a,mod-2);}
            ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
            ll a[2000000];
            void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){a[i]=i;for(j=i*i;j<1000001;j+=i){a[j]=i;}}}}
            vector<ll>v1;
            bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
            { 
                return (a.second < b.second);
            } 
            void comp()
            {
            	 ll i,j,k,n,m,q;
            	 cin>>n>>m>>k;
            	 ll temp=max(n,m);
            	 ll ans=k/temp;
            	 if(k%temp)
            	 ans++;
            	 cout<<ans<<endl;
            } 
            int main()
            {
            	speedup;
            	ll i=0,t;
            	ll n;
            	//cin>>t;
            	t=1;
            	while(t--)
            	{
            	 comp();
            	}
            }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,z,w; cin >> n >> z >> w;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1) cout << abs(w-a[0]) << endl;
    else cout << max(abs(w-a[n-1]),abs(a[n-1]-a[n-2])) << endl;
}



Measured memory_bytes: 256
def sort_two_nums_tuple(x,y):
    return max(x,y),min(x,y)

def calculate_gcd(x,y):
    remain = float('inf')
    while remain != 0:
        remain = x % y
        x = y
        y = remain
    return x

input_x,input_y = map(int,input().split())
x,y = sort_two_nums_tuple(input_x,input_y)
ans = calculate_gcd(x,y)
print(ans)


Measured memory_bytes: 5608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	private	static	BufferedReader	br = null;

	static class Table extends ArrayList<Integer> {}

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int		num = 0;
		int		max = 0;
		int		siz = 0;
		Table	inp = new Table();
		int[]	tbl = null;

		while((num = parseNum()) != 0) {
			max = Math.max(max, num);
			inp.add(num);
		}

		tbl = new int[max];
		for (int i = 1; i < max; i++) {
			tbl[i] = (i*i);
		}

		siz = inp.size();
		for (int i = 0; i < siz; i++) {
			solve(inp.get(i), tbl);
		}
	}

	private static void solve(int num, int[] tbl) {
		int		tmp = 0;
		int		siz = 0;
		int		lim = (num-1)/2;
		Table	sub = new Table();
		int[]	cnt = new int[lim+1];

		for (int i = 1; i < num; i++) {
			tmp = tbl[i]%num;
			if (!sub.contains(tmp)) {
				sub.add(tmp);
			}
		}

		siz = sub.size();
		for (int i = 0; i < siz; i++) {
			for (int j = 0; j < siz; j++) {
				if (i!=j) {
					tmp = sub.get(j)-sub.get(i);
					if (tmp < 0) tmp = tmp+num;
					if (tmp > lim) tmp = num-tmp;
					cnt[tmp]++;
				}
			}
		}

		for (int i = 1; i <= lim; i++) {
			System.out.println(cnt[i]);
		}
	}

	private static int parseNum() {
		int		param = 0;
		String	strin = null;

		if ((strin = parseStdin()) != null) {
			param = Integer.parseInt(strin);
		}
 
		return param;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 27580
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"

void solve(){

int n;
cin>>n;

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

long long ma = a[0];
long long cnt = 0;
for(int i  =  1;i<n;i++){
    if(a[i]<ma){
        cnt += ma-a[i];
    }
    else ma = a[i];
}

cout<<cnt<<endl;

}
 
 
int main()
{

solve();
 
return 0;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	ll a;
	ld b;
	cin>>a>>b;
	cout<<(ll)(a*b)<<endl;
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9 + 7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N;
ll X[101010];
ll Fa[101010];
ll i, j, ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &X[i]);
    }

    Fa[0] = 1;
    fornum(i,0,N){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
    }

    j = 0;
    fornum(i,1,N){
        j += moddiv(Fa[N - 1], Fa[i]) * Fa[i - 1];
        j %= MOD;
        ans = (ans + j * (X[i] - X[i - 1])) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) { cin >> a[i]; }
    sort(a.begin(), a.end());
    pair<int, int> ans;
    ans.first = a[n - 1];
    a.erase(a.begin() + n - 1);
    double tar = (double)ans.first / 2;
    int m = 1e9 + 7;
    for (int i = 0; i < n - 1; ++i) {
        if(abs(tar - a[i]) < m){
            ans.second = a[i];
            m = abs(tar - a[i]);
        }
    }
    cout << ans.first << ' ' << ans.second << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
    static void solve(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;
        while(a<=b) if((a++%c)==0) count++; 
        System.out.println(count);
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }
}

Measured memory_bytes: 35704
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

ll BASE_NUM = 1000000007;


int main()
{
    // 整数の入力
    ll N,K,S;
    cin >> N >> K >> S;
    ll dummy;
    if (S == 1000000000){
        dummy = 1;
    }else{
        dummy = 1000000000;
    }

    for(int i = 0;i < N;i++){
        if (i != 0){
            cout << " ";
        }
        if(i < K){
            cout << S;
        }else{
            cout << dummy;
        }
    }
    cout << endl;

   return 0;
}

Measured memory_bytes: 1280
import math

inp_1 = input().split()
n = int(inp_1[0])
d = int(inp_1[1])

input_matrix = []
for i in range(n):
    input_matrix.append([int(s) for s in input().split()])

def kyori(x_list,y_list):
    dim = len(x_list)
    kyori_nibeki = 0
    for i in range(dim):
        kyori_nibeki = kyori_nibeki + (x_list[i] - y_list[i])**2
    return math.sqrt(kyori_nibeki)


count = 0
for i in range(n):
    for j in range(n):
        if j > i:
            kyori_compare = kyori(input_matrix[i],input_matrix[j])
            if kyori_compare ==  math.floor(kyori_compare):
                count = count + 1

print(count)






Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define       M                        1000000007
#define       ll                       long long
#define	      FIO		                   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define        ifor(st,lim)             for(int i=st;i<lim;i++)
#define       jfor(stt,llim)           for(int j=stt;j<llim;j++)
#define       eifor(st,lim)            for(int i=st;i<=lim;i++)
#define       ejfor(stt,llim)          for(int j=stt;j<=llim;j++)
#define       blank		                 cout<<'\n';

void solve()
{
    int n,x,t; cin>>n>>x>>t;
    int p = n/x;
    if(n%x == 0) cout<<t*p;
    else cout<<(p+1)*t; 
}

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


Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int t = sc.nextInt();
            while (t-- > 0) {
            int n = sc.nextInt(), k = sc.nextInt();
            int[] x = new int[n];
            for (int i = 0; i < n; ++i) x[i] = sc.nextInt();
            ArrayList<Integer> l = new ArrayList<Integer>();
            int sum = 0;
            for (int i = 0; i < n-1; ++i) {
                l.add(x[i+1]-x[i]);
                sum += x[i+1]-x[i];
            }
            Collections.sort(l, (i1, i2)->i2-i1);
            if (k >= n) { sum = 0; }
            else {
                for (int i = 0; i < k-1; ++i) {
                    sum -= l.get(i);
                }
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 103524
n, m = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(n)]
checkpoints = [list(map(int, input().split())) for _ in range(m)]
for a, b in students:
    dist = 4 * 10 ** 8
    ans = 0
    for j in range(m):
        c, d = checkpoints[j]
        tmp = abs(a - c) + abs(b - d)
        if dist > tmp:
            dist = tmp
            ans = j + 1
    print(ans)


Measured memory_bytes: 3316
S=str(input())
point = 0
N=len(S)
if N%2==0:
  A=[0,1]*(N//2)
else:
  A=[0,1]*(N//2)+[0]

T=[]
for i in range(N):
  if S[i]=='g':
    T +=[0]
  else:
    T +=[1]

count=0
for i in range(N):
  count +=A[i]-T[i]
print(count)

Measured memory_bytes: 4724
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int>
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size()
	#define PI 3.14159265358979323846

	const int N =2e5+5;

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

      int maxi;
      
    void solve(){
        int k,x;
        cin>>k>>x;
        
        vi v;
        
        int cnt=k;
        for(int i=x; ;i--){
              if(cnt==0)
             break;
             
            v.pb(i);
            cnt--;
          
        }
        
        cnt=k-1;
        for(int i=x+1; ;i++ ){
             if(cnt==0)
              break;
              
            v.pb(i);
            cnt--;
           
        }
        
        sort(all(v));
        
        rep(i,0,sz(v))
          cout<<v[i]<<" ";           
        
     }
       
       
	int32_t main() {

	  cool;
	  int t=1;
     // cin>>t;


	  while (t--)
		 solve();

	  return 0;
	}


Measured memory_bytes: 256
n = int(input())
li = [0]*n
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1==d2:
        li[i] = 1
lii = [0]*n
lii[0]=li[0]
for i in range(n-1):
    if li[i+1]==1:
        lii[i+1]=lii[i]+li[i+1]
    else:
        lii[i+1]=0

if max(lii)>=3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9216
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strconv"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n := ScanInt64()
	a := ScanInt64Slice(n)
	//sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	a = quicksort(a)

	found := false

	for i := int64(1); i < n; i++ {
		if a[i] == a[i-1] {
			found = true
			break
		}
	}

	if found {
		P("NO")
	} else {
		P("YES")
	}

	close(O)
	oWg.Wait()
}

func quicksort(a []int) []int {
	if len(a) < 2 {
		return a
	}

	left, right := 0, len(a)-1

	pivot := rand.Int() % len(a)

	a[pivot], a[right] = a[right], a[pivot]

	for i, _ := range a {
		if a[i] < a[right] {
			a[left], a[i] = a[i], a[left]
			left++
		}
	}

	a[left], a[right] = a[right], a[left]

	quicksort(a[:left])
	quicksort(a[left+1:])

	return a
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int {
	length := int(n)
	arr := make([]int, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var seq = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var avg = Math.Ceiling(seq.Average());

            var ans = int.MaxValue;

            for (var i = 1; i <= avg; ++i) {
                var sumVal = seq.Select(s => (s-i) * (s-i)).Sum();
                // Console.WriteLine($"{i}: {sumVal}");
                ans = Math.Min(ans, sumVal);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28328
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/dsu>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n, m;
	cin >> n >> m;

	atcoder::dsu d(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		d.merge(a - 1, b - 1);
	}

	unordered_set<int> s;
	rep(i, n)s.insert(d.leader(i));

	cout << s.size() - 1 << endl;



	return 0;
}


Measured memory_bytes: 6984
#include <iostream>
using namespace std;
int main(){
     long long a,b;
     cin>>a>>b;
     if(a<b){
     for(int i=1;i<=b;i++){
     	cout<<a;
	}
	
    }
    else{
    	for(int i=1;i<=a;i++){
    		cout<<b;
	    }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int sz;
    sz = s.size();
    int st;
    st = s[0]-'0';
    int cnt=0;
    for(int i=0; i<sz; i++){
        if(st==0){
            if(i%2==0){
                if(s[i]!='0') cnt++;
            }else{
                if(s[i]!='1') cnt++;
            }
        }else{
            //st=1
            if(i%2==0){
                if(s[i]!='1') cnt++;
            }else{
                if(s[i]!='0') cnt++;
            }
        }
    }
    cout << cnt << endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    ll ans=a+b+c-max(max(a,b),c);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

class Main {

  public static void main(String[] args) {
    final FastScanner sc = new FastScanner();
    final PrintWriter writer = new PrintWriter(System.out);
    int length = sc.nextInt();
    char[] s = sc.next().toCharArray();
    char[] t = sc.next().toCharArray();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < length; i++) {
      sb.append(s[i]).append(t[i]);
    }
    writer.println(sb.toString());
    writer.flush();
    writer.close();
  }

  // FastScanner --
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte())
        return buffer[ptr++];
      else
        return -1;
    }

    private boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr]))
        ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext())
        throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext())
        throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
        throw new NumberFormatException();
      return (int) nl;
    }

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

Measured memory_bytes: 23252
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  //invs.length=n+1,invs[0]=invs[1]=1;
  //for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[n-r]);}
function mput(n){return (n%mod+mod)%mod;}


var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var n = next();
  var ans = pow(10,n);
  ans -= pow(9,n);
  ans -= pow(9,n);
  ans += pow(8,n);
  return mput(ans);
}

Measured memory_bytes: 29756
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong a, b, c, k;

int main(){
    cin >> a >> b >> c >> k;
    if(k % 2 == 0){
        cout << a - b;
    }else{
        cout << b - a;
    }
    return 0;
}


Measured memory_bytes: 256
while gets
  a = $_.split.map(&:to_i)
  #a = $_.split(" ").map{|val| val.to_i}

  a.sort!.reverse!
  puts a.join(" ")

  #for i in 0...a.size
  #  print " " if i != 0
  #  print a[i]
  #end
  #puts
end

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

#define int long long
#define INF (1LL<<60)
int N, X;
int A[2000], B[2000];

void rsucc(int &r, deque<int> &q) {
    while(!q.empty() && B[q.back()] >= B[r]) q.pop_back();
    q.push_back(r++);
}
void lsucc(int &l, deque<int> &q) { if(q.front() == l++) q.pop_front(); }

int slide_min(int w) {
  vector<int> ret;
  deque<int> q;
  int l = 0, r = 0;

  int s = B[0] * w;
  while(r < w) rsucc(r, q);
  while(r < N) {
    rsucc(r,q); lsucc(l, q);
    s += B[q.front()];
  }
  return s;
}
int f(int b) {
  return X*(b-1) + slide_min(b);
}

signed main() {
  cin >> N >> X;
  for (int i=0; i<N; i++) cin >> A[i];
  int mi = min_element(A, A+N) - A;
  for (int i=0; i<N; i++) B[i] = A[(mi+i)%N];

  int m = INF;
  for (int i=1; i<=N; i++) m = min(m, f(i));
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int res;
int k, n, m;
int main(){
    cin >> n >> m;
    for(int i = 0;i < n;i++){
    	cout << "lst " << i << endl;
    	cin >> k;
    	res += k * (k-1);
    	for(int j = 0;j < k;j++)cin >> m;
    }
    cout << "ans " << res <<  endl; // ????????´????????????????????\
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    // {
    	int n;
    	cin>>n;
    	vector< pair <int,int> > arr;
    	for(int i=0;i<n;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		arr.push_back({a,b});
    	}
    	int count=0;
    	for(int i=0;i<n;i++)
    	{
    		if(arr[i].first==arr[i].second)
    			{
    				count++;
    				if(count==3)
    					break;
    			}
    		else
    			count=0;
    	}
    	if(count==3)
    		cout<<"Yes"<<endl;
    	else
    		cout<<"No"<<endl;
}

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

int main() {
  int N, A, B, ret = 0;
  cin >> N >> A >> B;
  for (int i = 1; i <= N; i++) {
    int tmp = i, s = 0;
    while (tmp) {
      s += tmp % 10;
      tmp /= 10;
    }
    if (A <= s && s <= B) ret += i;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
res = 0
K,A,B = gets.split(" ").map { |e| e.to_i }
if (B-A)/2.0 > 1
  if K < A-1
    puts K+1
  else
    res = A
    res += (K-A+1)/2*(B-A)+(K-A+1)%2
    puts res
  end
else
  puts K+1
end

Measured memory_bytes: 1788
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N, M;
  cin >> N >> M;
  vi A(N);
  cin >> A;
  sort(all(A));
  vi S = A;
  psum(S);

  if (M == N * N) {
    int ans = 0;
    rep(i, 0, N) { ans += A[i] * N + S[N - 1]; }
    cout << ans << endl;
    return 0;
  }
  if (M == 1) {
    cout << A[N - 1] * 2 << endl;
    return 0;
  }

  dump(A);

  auto cnt = [&](int k) -> pii {
    int c = 0;
    int s = 0;
    rep(i, 0, N) {
      int l = k - A[i];
      int j = lower_bound(all(A), l) - begin(A);
      int tmp = S[N - 1];
      if (j) tmp -= S[j - 1];
      s += tmp + A[i] * (N - j);
      c += N - j;
    }
    return {c, s};
  };

  int ok = A[N - 1] * 2 + 1;
  int ng = A[0] * 2;
  int ans = 0;
  while (abs(ok - ng) > 1) {
    int k = (ok + ng) / 2;
    auto x = cnt(k);
    if (x.first <= M) {
      ok = k;
      ans = x.second;
    } else {
      ng = k;
    }
  }
  dump(ok, ng, ans);

  int r = M - cnt(ok).first;
  ans += r * (ok - 1);

  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int cnt;
	int a,b,c;
	a = b = c = cnt = 0;
	while(true){
		int A[5];
		for(int i = 0; i < 3; i++){
			int tmp;
			scanf("%d",&tmp);
			A[i] = tmp;
		}
		sort(A,A+3);
		if(A[2] >= A[1] + A[0])break;
		cnt++;
		if(A[0]*A[0] + A[1]*A[1] == A[2]*A[2])a++;
		else if(A[0]*A[0] + A[1]*A[1] > A[2]*A[2])b++;
		else if(A[0]*A[0] + A[1]*A[1] < A[2]*A[2])c++;
	}
	printf("%d %d %d %d\n",cnt,a,b,c);
	return 0;
}

Measured memory_bytes: 1044
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = Pattern.compile(" ").splitAsStream(stdin.nextLine()).mapToInt(Integer::parseInt).toArray();

        Arrays.sort(a);

        List<List<Integer>> history = new ArrayList<>();
        int lo = a[0];
        int hi = a[n - 1];
        for (int i = 1; i < n - 1; i++) {
            if (a[i] > 0) {
                history.add(Arrays.asList(lo, a[i]));
                lo = lo - a[i];
            } else {
                history.add(Arrays.asList(hi, a[i]));
                hi = hi - a[i];
            }
        }
        history.add(Arrays.asList(hi, lo));

        PrintWriter out = new PrintWriter(System.out, false);
        out.println(hi - lo);
        for (List<Integer> row : history) {
            out.printf("%d %d%n", row.get(0), row.get(1));
        }
        out.flush();
    }

}

Measured memory_bytes: 113264
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    while(N){
        vector<ll> V(N);
        rep(i,0,N)cin >> V[i];
        ll maxi = 0;
        rep(i,0,N)rep(j,i+1,N){
            if(V[i] + V[j] <= M)maxi = max(maxi, V[i] + V[j]);
        }
        if(maxi == 0)cout << "NONE" << endl;
        else cout << maxi << endl;
        cin >> N >> M;
    }
}


Measured memory_bytes: 3084
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9

def resolve():
    n = int(input())
    a = [0]
    a.extend(list(map(int,input().split())))
    dp = [[0,0] for _ in range(n+1)]
    dp[0][1]=-INF
    for i in range(1,n+1):
        dp[i][0] = max(dp[i-1][0]+a[i],dp[i-1][1]-a[i])
        dp[i][1] = max(dp[i-1][0]-a[i],dp[i-1][1]+a[i])
    print(dp[n][0])

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 26060
#include <iostream>
#include <complex>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>

using namespace std;

int res[200000];

int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        int idx = (N - 1) / 2 + (i < N / 2);
        res[A[i].second] = A[idx].first;
    }
    for (int i = 0; i < N; i++) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 4480
use proconio::input;

fn main() {
    input! {
        n: usize,
        h: i64,
        w: i64,
        ab: [(i64, i64); n],
    }

    let ans = ab.iter().filter(|(a, b)| h <= *a && w <= *b).count();

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


Measured memory_bytes: 2224
use proconio::input;
fn main() {
    input!(n: usize, ab: [(u32, u32); n]);
    let mut a = ab.iter().map(|&(x, _)| 2 * x).collect::<Vec<u32>>();
    let mut b = ab.iter().map(|&(_, y)| 2 * y).collect::<Vec<u32>>();
    a.sort();
    b.sort();
    println!(
        "{}",
        if n % 2 == 0 {
            (b[n / 2 - 1] + b[n / 2]) / 2 - (a[n / 2 - 1] + a[n / 2]) / 2 + 1
        } else {
            (b[n / 2] - a[n / 2]) / 2 + 1
        }
    );
}


Measured memory_bytes: 9524