akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n,q = map(int, input().split())
stx = [tuple(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

#これはセグ木 * bisect
import bisect
inf = 10**9 + 100

def init(n,init_num=0):
    num = len(str(bin(n-1))) + 1
    seg = [init_num] * (2**num)
    seg[0] = 2**(num-1)
    return(seg)

def update(head, tail, x):
    # print('{} {} {}'.format(head, tail, x))
    head += seg[0]
    tail += seg[0]
    points = []
    while(head <= tail):
        if(head == tail):
            points.append(head)
            break

        if(head % 2 ==1):
            points.append(head)
            head += 1
        head = head//2

        if(tail % 2 == 0):
            points.append(tail)
            tail -= 1
        tail = (tail-1)//2

    for point in points:
        seg[point] = min(seg[point], x)

def execute(p):
    p += seg[0]
    tmp = seg[p]
    while(p > 0):
        p = p//2
        tmp = min(tmp, sep[p])
    return(tmp)

def execute_all():
    for i in range(2,len(seg)):
        seg[i] = min(seg[i], seg[i//2])


seg = init(q, init_num = inf)

for i in range(n):
    left = bisect.bisect_left(d, stx[i][0] -stx[i][2])
    right = bisect.bisect_right(d, stx[i][1] - stx[i][2] -1) -1
    update(left, right, stx[i][2])
    # print('{} {} {}'.format(left, right, stx[i][2]))

execute_all()

for i in seg[seg[0]: seg[0] + q]:
    if(i == inf):
        print(-1)
    else:
        print(i)

Measured memory_bytes: 119648
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner a = new Scanner(System.in);
		int h =1;
		int w = 1;
		
		
		while(h > 0 && w > 0){
			h = a.nextInt();
			w = a.nextInt();
			for(int i = 0;i < h;i++){
				int count = 0;
				for(int j = 0;j < w;j++){
					if((i % 2) == 0){
						System.out.print("#");
						count++;
						if(count == (w))
							break;
						System.out.print(".");
						count++;
						if(count == (w))
							break;
					}else{
						System.out.print(".");
						count++;
						if(count == (w))
							break;
						System.out.print("#");
						count++;
						if(count == (w))
							break;
					}
				}
				if(h != 0 && w != 0)
					System.out.println();
			}
			if(h != 0 && w != 0)
				System.out.println();
		}
	}

}

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

using namespace std;

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

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

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

bool b1, b2, b3;

int main(){
	bool f = 0;
	cin >> b1 >> b2 >> b3;
	if (b3){
		if (!b1&&!b2)f = 1;
	}
	else{
		if (b1&&b2)f = 1;
	}
	if (f)cout << "Open" << endl;
	else cout << "Close" << endl;
}

Measured memory_bytes: 1156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class AOddsOfOddness {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        int k = (N+1) / 2;
        out<<fixed<<setprecision(10)<<1.0*k/N<<'\n';
    }
};


int main() {
	AOddsOfOddness solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <cmath>

double abs(double a);


int main()
{
    int n;

    std::cin >> n;

    double x[n];
    double y[n];

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

    for (int i = 0;i < n; i++) {
        std::cin >> y[i];
    }
    double p1 = 0,p2 = 0,p3 = 0,p8 = 0;

    //p=1
    for (int i = 0; i < n; i++) {
        p1 += abs(x[i] - y[i]);
    }

    //p=2
    for (int i = 0; i < n ; i++) {
        p2 += (x[i] - y[i]) * (x[i] - y[i]);
        if (i == n - 1) {
            p2 = sqrt(p2);
        }
    }

    //p=3
    for (int i = 0; i < n; i++) {
        p3 += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
        if (i == n - 1) {
            p3 = std::pow(p3, 1.0/3.0);
        }
    }

    //p=8
    for (int i = 0; i < n; i++) {
        if (p8 <= abs(x[i] -y[i])) {
            p8 = abs(x[i] - y[i]);
        }
    }

    std::printf("%lf\n%lf\n%lf\n%lf\n",p1,p2,p3,p8);

}

double abs(double a)
{
    if (a < 0) {
        return -a;
    } else {
        return a;
    }
}

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

int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;


void solve(){

	int n,m; cin>>n>>m;
	int s = 0;
	for(int i=0; i<m; i++){
		 int x; cin>>x;
		 s +=  x;
	}
	if(n - s  < 0) cout<<-1;
	else cout<<n-s;

}





int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	
	int t =1; 
	//cin>>t;



	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}

	return 0;

}




Measured memory_bytes: 3656
#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int array[n];
	int i,j;
	for (i=0;i<n;i++)
	{
		scanf("%d",&array[i]);
	}
	for (i=0;i<n-1;i++)
	{
		for (j=0;j<n-i-1;j++)
		{
			if (array[j]>array[j+1])
			{
				int temp = array[j];
				array[j] = array[j+1];
				array[j+1] = temp;
			}
		}
	}
	int count=1;
	for (i=1;i<n;i++)
	{
		if (array[i]!=array[i-1])
			count++;
	}
	printf("%d",count);
	return 0;
	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, sum = 0; cin >> n;
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        sum += x;
    }cout << sum  - n;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <set>

#define REP(i, n) for (int i=0;i<(n);i++)
#define FOR(i, a, b) for (int i=(a);i<(b);i++)

using namespace std;

int N;
long long int x;
long long int a[101];

int main()
{
    scanf("%d %lld", &N, &x);
    REP(i, N)
        scanf("%lld", &a[i]);
    sort(a, a+N);
    int ans = 0;
    REP(i, N-1) {
        if (x >= a[i]) {
            x -= a[i];
            ans++;
        } else
            break;
    }
    if (x==a[N-1])
        ans++;
    cout << ans << endl;
    return 0;
}


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

int main() {
	// your code goes here
	ll int n;
	cin>>n;
	vector<ll int> h(n+1),dp(n+1,0);
	ll int i,j;
	for(i=1;i<=n;i++)
	cin>>h[i];
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(i=3;i<=n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n]<<"\n";
	return 0;
}


Measured memory_bytes: 1792
from sys import stdin

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

w = S()

for i in range(len(w)):
    if w.count(w[i]) % 2 == 1:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int k;
    string s;
    cin >> k >> s;
    for(int i = 0; i < k; i++){
        if(s.size() == i) break;
        cout << s[i];
    }
    if(k < s.size()) cout << "...";
    cout << endl;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
struct plane
{
	int x;int y;int dir;	
}pl[N];
vector<plane> xx[N],yy[N],zz[N*2],ff[N*2];
int cntx,cnty,cntz,cntf;
bool cmp1(plane a,plane b)
{
	if (a.x>b.x) return 0;
	if (a.x<b.x) return 1;
	return a.y<b.y;
}
signed main()
{
	int n;
	cin>>n;
	int ans=inf;
	for (int i=1;i<=n;i++)
	{
		cin>>pl[i].x>>pl[i].y;
		string s;cin>>s;
		if (s=="U") pl[i].dir=1;
		if (s=="R") pl[i].dir=2;
		if (s=="D") pl[i].dir=3;
		if (s=="L") pl[i].dir=4;
	}
	sort(pl+1,pl+n+1,cmp1);
	for (int i=1;i<=n;i++)
	{
		xx[pl[i].x].push_back(pl[i]);
		yy[pl[i].y].push_back(pl[i]);
		ff[pl[i].x+pl[i].y].push_back(pl[i]);
		zz[pl[i].x-pl[i].y+N-5].push_back(pl[i]);
	}
	for (int i=0;i<N;i++)
	{
		if (xx[i].size()>=2)
		{
			int tmpans=0x3f3f3f3f;
			int tmpy=-1;
			for (int j=0;j<xx[i].size();j++)
			{
				if (xx[i][j].dir==1) tmpy=xx[i][j].y;
				if (xx[i][j].dir==3 && tmpy!=-1) tmpans=min(tmpans,xx[i][j].y-tmpy); 
			}
			ans=min(ans,5*tmpans);
		}
	}
	for (int i=0;i<N;i++)
	{
		if (yy[i].size()>=2)
		{
			int tmpans=0x3f3f3f3f;
			int tmpx=-1;
			for (int j=0;j<yy[i].size();j++)
			{
				if (yy[i][j].dir==2) tmpx=yy[i][j].x;
				if (yy[i][j].dir==4 && tmpx!=-1) tmpans=min(tmpans,yy[i][j].x-tmpx); 
			}
			ans=min(ans,5*tmpans);
		}
	}
	for (int i=0;i<2*N;i++)
	{
		if (ff[i].size()>=2)
		{
			int tmpans=inf;
			int tmpd=-1;
			int tmpr=-1;
			for (int j=0;j<ff[i].size();j++)
			{
				if (ff[i][j].dir==2) tmpr=ff[i][j].x;
				if (ff[i][j].dir==3) tmpd=ff[i][j].x;
				if (ff[i][j].dir==1 && tmpr!=-1) tmpans=min(tmpans,ff[i][j].x-tmpr); 
				if (ff[i][j].dir==4 && tmpd!=-1) tmpans=min(tmpans,ff[i][j].x-tmpd); 
			}
			ans=min(ans,10*tmpans);
		}
	}
	for (int i=0;i<2*N;i++)
	{
		if (zz[i].size()>=2)
		{
			int tmpans=inf;
			int tmpu=-1;
			int tmpr=-1;
			for (int j=0;j<zz[i].size();j++)
			{
				if (zz[i][j].dir==2) tmpr=zz[i][j].x;
				if (zz[i][j].dir==1) tmpu=zz[i][j].x;
				if (zz[i][j].dir==3 && tmpr!=-1) tmpans=min(tmpans,zz[i][j].x-tmpr); 
				if (zz[i][j].dir==4 && tmpu!=-1) tmpans=min(tmpans,zz[i][j].x-tmpu); 
			}
			ans=min(ans,10*tmpans);
		}
	}
	if (ans==inf) cout<<"SAFE"<<endl;else cout<<ans<<endl;
}

Measured memory_bytes: 65232
import 'dart:io';
import 'dart:math';

main(List<String> args) {
  List S = stdin.readLineSync().split('').map((x) => int.parse(x)).toList();
  int N = S.length;
  var mods = Map();
  int s = 0;
  mods[0] = 1;
  var D = []..length = N;
  D[0] = 1;
  for (var i = 1; i < N; i++) {
    D[i] = D[i - 1] * 10 % 2019;
  }

  for (var i = N - 1; i >= 0; i--) {
    s += D[N - 1 - i] * S[i];
    s %= 2019;
    if (mods.containsKey(s))
      mods[s] += 1;
    else
      mods[s] = 1;
  }
  int ans = 0;
  mods.forEach((k, v) => ans += (v * (v - 1)) ~/ 2);
  //print(mods);
  print(ans);
}


Measured memory_bytes: 17896
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N=1e6+5;
const int mod=1e9+7;
int n,dp[N],f[N];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    dp[1]=n;
    dp[2]=(n*n)%mod;
    f[1]=dp[1];
    f[2]=(dp[1]+dp[2])%mod;
    for(int i=3;i<=n;i++)
    {
        dp[i]=(dp[i-1]+(n-1)*(n-1)+f[i-3]+(n-i+2))%mod;
        f[i]=(f[i-1]+dp[i])%mod;
    }
    cout<<dp[n];
}


Measured memory_bytes: 15872
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))

    for i in range(m // n, 0, -1):
        rem = m - i * n
        if rem % i == 0:
            print(i)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

  static class APassword {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      long n = in.readInt();
      out.printLine(n * n * n);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void close() {
      writer.close();
    }

    public void printLine(long i) {
      writer.println(i);
    }
  }

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

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

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

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

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

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

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


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

using P = pair<long long, long long>;
long long n;
vector<P> v;

long long solve();

int main() {
  cin >> n;
  v.resize(n);
  for (auto &p : v) {
    cin >> p.first >> p.second;
    if (p.first < p.second) swap(p.first, p.second);
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, now = 0, l = 0, r = 0;
  {  // search  default answer
    sort(v.begin(), v.end());
    res = v[n - 1].first - v[0].first;
    for (auto &p : v) swap(p.first, p.second);
    sort(v.begin(), v.end());
    res *= v[n - 1].first - v[0].first;
  }
  {
    int id = 0;
    for (int i = 0; i < n; ++i)
      if (v[id].second < v[i].second) id = i;
    if (!id) return res;
    swap(v[id].first, v[id].second);
    swap(v[1], v[id]);
    now = v[1].first - v[0].first;
    l = v[0].second;
    r = v[1].second;
    if (l > r) swap(l, r);
    for (int i = 2; i < n; ++i)
      if (v[i].first > r)
        r = v[i].first;
      else if (v[i].second < l)
        l = v[i].second;
    vector<P> tmp;
    for (int i = 2; i < n; ++i)
      if (v[i].first < l && r < v[i].second) tmp.push_back(v[i]);
    v = tmp;
  }
  for (auto p : v) {
    res = min(res, now * (r - p.first));
    r = max(r, p.second);
  }
  res = min(res, now * (r - l));
  return res;
}

Measured memory_bytes: 6400
import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

no_route = 15001

# (v-1) th vertex is excluded
dp = [[no_route] * (V - 1) for i in range(1 << (V - 1))]

adj = [[] for i in range(V)]

for line in file_input:
    s, t, d = map(int, line.split())
    if s == V - 1:
        # Record the distance from the (v-1) th vertex to the adjacent vertex
        dp[1 << t][t] = d
    else: 
        # Store distance from source, not target
        adj[t].append((s, d))

# DP
for b in range(1, 1 << (V - 1)):
    for i in range(V - 1):
        b_i = 1 << i
        if b & b_i:
            pre_bit = b ^ b_i
            dp_pre = dp[pre_bit]
            for s, d in adj[i]:
                pre_rec = dp_pre[s]
                if pre_rec != no_route:
                    dp[b][i] = min(dp[b][i], pre_rec + d)

ans = no_route

# A state where all vertices other than (v-1) have been visited.
dp_comp = dp[(1 << (V - 1)) - 1]

for s, d in adj[V - 1]:
    comp_rec = dp_comp[s]
    if comp_rec != no_route:
        ans = min(ans, comp_rec + d)

if ans == no_route:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 14308
#include<cstdio>

int main(void){
	int n,i,j,k,m=0;
	int a[10000],b[10000];
	int x[5]={0},y[5]={0};
	while(true){
		scanf("%d",&n);
		if(n==0)break;
		
		for(i=0;i<n;i++){
			scanf("%d%d",&a[i],&b[i]);
			if(a[i]>b[i]){
				x[m]=x[m]+a[i]+b[i];
			}else if(a[i]<b[i]){
				y[m]+=a[i]+b[i];
			}else{
				x[m]+=a[i];
				y[m]+=b[i];
			}
		}
		
		
		m++;
	}
	
	for(i=0;i<m;i++){
		printf("%d %d\n",x[i],y[i]);
	}
		
	return 0;
}					
					
					
				

Measured memory_bytes: 2776
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 100000000000000000000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define nl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll c2(ll n){
	return (n*(n-1))/2;
}
ll solveneg(vector<ll>vec,ll neg,ll pos,ll k){
	ll n,i,z,j;
	n=vec.size();
	vector<ll>negs(vec.begin(),vec.begin()+neg);
	vector<ll>poss(vec.begin()+n-pos,vec.end());
	
	ll lo=negs[0]*poss.back();
	ll hi=poss[0]*negs.back();
	
	reverse(negs.begin(), negs.end());
	reverse(poss.begin(), poss.end());
	while(lo<=hi){
		ll mid=(lo+hi)/2;
		ll c=0;
		for(i=0,j=0;i<negs.size();i++){
			for(;j<poss.size() && negs[i]*poss[j]<=mid;j++);
			c+=j;
		}
		if(c<k){
			lo=mid+1;
		}else{
			hi=mid-1;
		}
	}
	return lo;
}
ll solvepos(vector<ll>vec,ll neg,ll pos,ll k){
	ll n,i,j;
	n=vec.size();
	vector<ll>negs(vec.begin(),vec.begin()+neg);
	vector<ll>poss(vec.begin()+n-pos,vec.end());
	reverse(negs.begin(), negs.end());
	ll lo=INT_MAX;
	ll hi=INT_MIN;
	if(negs.size()>=2){
		lo=min(lo,negs[0]*negs[1]);
		hi=max(hi,negs[neg-1]*negs[neg-2]);
	}
	if(poss.size()>=2){
		lo=min(lo,poss[0]*poss[1]);
		hi=max(hi,poss[pos-1]*poss[pos-2]);
	}
	while(lo<=hi){
		ll mid=(lo+hi)/2;
		ll c=0;
		for(i=pos-1,j=0;i>=0;i--){
			for(;j<i&&poss[i]*poss[j]<=mid;j++);
			c+=min(i,j);
		}
		for(i=neg-1,j=0;i>=0;i--){
			for(;j<i&&negs[i]*negs[j]<=mid;j++);
			c+=min(i,j);
		}
		if(c<k){
			lo=mid+1;
		}else{
			hi=mid-1;
		}
	}
	return lo;
}
void solve(){
	ll n,i,k,pos=0,neg=0,z=0;
	in2(n,k);
	vll vec(n);
	nfl(i,n){
		in(vec[i]);
		if(vec[i]==0)
			z++;
		if(vec[i]>0)
			pos++;
		if(vec[i]<0)
			neg++;
	}
	sort(vec.begin(), vec.end());
	ll negp=pos*neg;
	ll zerp=c2(z)+z*(n-z);
	ll posp=c2(pos)+c2(neg);
	ll ans;
	if(k<=negp){
		ans=solveneg(vec,neg,pos,k);
	}else if(k<=zerp+negp){
		ans=0;
	}else{
		ans=solvepos(vec,neg,pos,k-zerp-negp);
	}
	cout<<ans<<nl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


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

using namespace std;

int main()
{

    long long int n=0,i,c=0;
    cin>>n;
    long long int ar[n];
    for(i=0; i<n; i++)
    {
        cin>>ar[i];
    }
    

    for(i=0; i<n-1; i++)
    {
        if(ar[i]>ar[i+1])
        {
            c+=abs(ar[i]-ar[i+1]);
            ar[i+1]=ar[i];
        }
        
    }
    
   cout<<c;
    
    
    return 0;
}


Measured memory_bytes: 5116
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

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

const int MOD = 1e9 + 7;
const int maxn = 123456;
const double EPS = 1e-8;

int a[maxn], b[maxn], c[maxn];
vector<pii>va, vb;
bool cmp(pii &x, pii &y){
	if(x.first != y.first)return x.first > y.first;
	return x.second < y.second;
}
class C {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;
		va.clear();vb.clear();
		memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c));
		for (int i = 1; i <= n; ++i) {
			in >> a[i];
		}
		int i, j;
		for (i = 1; i <= n; i += 2) {
			b[a[i]]++;
		}
		for (i = 2; i <= n; i += 2) {
			c[a[i]]++;
		}
		for (i = 1; i < maxn; ++i) {
			va.push_back({b[i], i});
			vb.push_back({c[i], i});
		}
		sort(va.begin(), va.end(), cmp);
		sort(vb.begin(), vb.end(), cmp);
		int res;
		int na, nb;
		na = n/2 + (n % 2 == 1 ? 1 : 0);
		nb = n/2;
//		cerr << va[0].first << " " << vb[0].first << endl;
		if(va[0].second == vb[0].second){
			res = min(na - va[0].first + nb - vb[1].first, na - va[1].first + nb - vb[0].first);
		} else res = na - va[0].first + nb - vb[0].first;
//		cerr << res << endl;
		out << res;
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 3820
package main

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

const (
	bufsiz = 1024 * 1024
)

func main() {
	writer := newWriter(os.Stdout)
	defer writer.Flush()

	sc := newScanner(os.Stdin)
	a := sc.scanInt()
	b := sc.scanInt()

	if b%a == 0 {
		writer.println(a + b)
	} else {
		writer.println(b - a)
	}
}

func print(okng string) {
	fmt.Println(okng)
	os.Exit(0)
}

type scanner struct {
	*bufio.Scanner
}

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) scanStr() string {
	s.Buffer(make([]byte, bufsiz), bufsiz)
	if !s.Scan() {
		panic("scan failed")
	}
	return s.Text()
}

func (s *scanner) scanInt() int {
	if !s.Scan() {
		panic("scan failed")
	}
	i, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type writer struct {
	*bufio.Writer
}

func newWriter(wr io.Writer) *writer {
	w := bufio.NewWriter(wr)
	return &writer{w}
}

func (w *writer) printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(w, f, args...)
}

func (w *writer) println(args ...interface{}) (int, error) {
	return fmt.Fprintln(w, args...)
}


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

typedef struct __card {
	int number;
	char suit;
} card_t;

void bubble_sort( card_t * p, int size );
void selection_sort( card_t * p, int size );
void print_array( card_t * p, int size );
bool is_stable( card_t * b, card_t * s, int size );

int main() {
	int num;
	char str[2];
	card_t b_card[36];
	card_t s_card[36];
	cin >> num;

	for ( int i = 0 ; i < num ; i++ ) {
		cin >> b_card[i].suit >> b_card[i].number;
		s_card[i] = b_card[i];
	}

	bubble_sort( b_card, num );
	selection_sort( s_card, num );

	print_array( b_card, num );
	cout << "Stable" << endl;
	print_array( s_card, num );
	if ( is_stable( b_card, s_card, num ) ) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	//cout << &b_card << ":" << &s_card << endl; 

	return 0;
}

void bubble_sort( card_t * p, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		for ( int j = size-1 ; j >= i+1 ; j-- ) {
			if ( p[j-1].number > p[j].number ) {
				card_t tmp;
				tmp = p[j-1];
				p[j-1] = p[j];
				p[j] = tmp;
			}
		}
	}	
}

void selection_sort( card_t * p, int size ) {
	int minj = 0;
	int i = 0, j = 0;
	for ( i = 0 ; i < size ; i++ ) {
		minj = i;
		for ( j = i ; j < size ; j++ ) {
			if ( p[minj].number > p[j].number ) {
				minj = j;
			}
		}
		card_t tmp;
		tmp = p[i];
		p[i] = p[minj];
		p[minj] = tmp;
	}
}

void print_array( card_t * p, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		if ( i == size-1 ) {
			cout << p[i].suit << p[i].number << endl;
		} else {
			cout << p[i].suit << p[i].number  << " "; 
		}
	}
}

bool is_stable( card_t * b, card_t * s, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		if ( b[i].suit != s[i].suit ) {
			return false;
		}
	}
	return true;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
    int N,D;
    cin >> N >> D;
    int a = 2*D + 1;

    cout << ceil(N/float(a)) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    deque<ll> q;
    rep(i,0,n){
        if(i%2) q.push_front(a[i]);
        else q.push_back(a[i]);
    }
    if(n%2) rev(q);
    rep(i,0,n){
        if(i==n-1) cout<<q[i]<<"\n";
        else cout<<q[i]<<" ";
    }
}

Measured memory_bytes: 5376
n, m, k = map(int, input().split())

MOD = 998244353

fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % MOD

inv[n] = pow(fac[n], MOD-2, MOD)
for j in range(n - 1, -1, -1):
    inv[j] = inv[j + 1] * (j + 1) % MOD

def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % MOD

ans = 0
for i in range(k + 1):
  ans += (m * pow(m - 1, n - i - 1, MOD) * comb(n - 1, i)) % MOD
print(ans % MOD)


Measured memory_bytes: 24712
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<cmath>
#define pub push_back
using namespace std;
int main(void){
    int n,m,a,b,c;
    string ans="Yes";
    cin>>a>>b>>c;
    if(a>c||c>b){ans="No";}
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int x,y,w,h,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if(x+r>w||x-r<0||y+r>h||y-r<0){
printf("No\n");
}else{
printf("Yes\n");
}
return 0;
}

Measured memory_bytes: 584
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 12)
#define INF (1 << 29)

int mem[MAXN];
int c[MAXN];
int u[MAXN];
int n, m;

int solve(int mask) {
	if (mask == 0) {
		return 0;
	}
	int & ret = mem[mask];
	if (ret >= 0) {
		return ret;
	}
	ret = INF;
	for (int i = 0; i < m; i++) {
		int next = mask & (~u[i]);
		if (next == mask) {
			continue;
		}
		int nextcost = c[i] + solve(next);
		if (nextcost < ret) {
			ret = nextcost;
		}
	}
	return ret;
}

int main() {
	memset(mem, -1, sizeof(mem));
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> c[i];
		cin >> t;
		for (int j = 0; j < t; j++) {
			int tt;
			cin >> tt;
			tt--;
			u[i] |= (1 << tt);
		}
	}
	int ret = solve((1 << n) - 1);
	if (ret < INF) {
		cout << ret << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3184
using System;
using System.Collections;

namespace gotojail
{
    class Program
    {
        static void Main(string[] args)
        {
            //結果格納ハッシュテーブル
            Hashtable hsResult = new Hashtable();

            //1行目をとる
            var times = int.Parse(Console.ReadLine());
            for (var i = 0; i < times; i++)
            {
                // for文ぐるぐるで標準入力ピコピコして配列に入れ込んでいる
                string input = Console.ReadLine();

                //各行の結果の配列をハッシュテーブルに格納する
                hsResult.Add(i, input);
            }

            //3階連続でぞろ目か判定する
            if (BolChk3TimesZorome(hsResult, times))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        public static Boolean BolChk3TimesZorome(Hashtable phsInput, int pintTimes) {

            string strResultTF = "";

            //ハッシュテーブルを展開する
            for (var i = 0; i < pintTimes; i++)
            {
                string strResInhs = phsInput[i].ToString();
                string[] strRes = strResInhs.Split(" ");

                if (strRes[0].ToString() == strRes[1].ToString())
                {
                    strResultTF += "t";
                }
                else
                {
                    strResultTF += "f";
                }

            }
            //「ttt」の文字列を検索する
            return strResultTF.Contains("ttt");

        }
    }
}


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

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;
  if(n > 1 && m > 1) ans = n*(n-1)/2 + m*(m-1)/2;
  if (1 >= n > 0) ans = m*(m-1)/2;
  if (1 >= m > 0) ans = n*(n-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 100005
#define maxm 10000005
#define inf 0x7fffffff
#define ll long long

using namespace std;
int N,M,A[maxm],tp[maxm];
bool B[maxm];

inline int read(){
	int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}

inline bool check(int x){
	for(int i=1;i<=M;i++) B[i]=(A[i]>=x);
	for(int len=1;len<N;len++){
		if(B[N-len]==B[N-len+1]) return B[N-len];
		if(B[N+len-1]==B[N+len]) return B[N+len];
	}
	return B[1];
}

int main(){
	//freopen("triangle.in","r",stdin);
	//freopen("triangle.out","w",stdout);
	N=read(),M=(N<<1)-1;
	for(int i=1;i<=M;i++) A[i]=read();
	memcpy(tp,A,sizeof(A));
	sort(tp+1,tp+1+M);
	int l=1,r=M,ans=-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(tp[mid])) ans=tp[mid],l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 43392
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,ans=0,cnt=1;
    cin>>n;
    while(n!=1)
    {
        n/=2;
        ++cnt;
    }
    for(int i=1;i<=cnt;i++)
    {
        ans+=pow(2,i-1);
    }

    cout<<ans<<endl;

    return  0;
}




Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


void MAIN() {
    LL A, B, C;
    scanf("%lld%lld%lld", &A, &B, &C);
    LL ans = 0;

    LL g = min(B, C);
    ans += g * 2;
    B -= g;
    C -= g;

    g = min(A, C);
    ans += g;
    C -= g;

    ans += B;
    if (C) ans += 1;
    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
inf = float('inf')

n, *goal = map(int, input().split())
l = [int(input()) for _ in range(n)]

ans = inf
for q in range(4 ** n):
    cost = -30
    t = [0] * 3
    for j in range(n):
        idx = (q // (4 ** j)) % 4
        if idx == 3: continue
        t[idx] += l[j]
        cost += 10

    if any(tt == 0 for tt in t):
        continue

    for idx in range(3):
        cost += abs(t[idx] - goal[idx])

    ans = min(ans, cost)

print(ans)


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

int main(){
	int a[12];
	a[1]=1;	a[2]=3;	a[3]=1;	a[4]=2;	a[5]=1;	a[6]=2;
	a[7]=1;	a[8]=1;	a[9]=2;	a[10]=1; a[11]=2; a[12]=1;	
	
	int x, y;
	cin >> x >> y;
	
	if(a[x]==a[y])	cout << "Yes" << endl;
	else		cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

int main() {
    int n; cin >> n;
    int t; cin >> t;
    int ans = 1000000;
    rep (i, n) {
        int c, x; cin >> c >> x;
        if (x <= t) {
            ans = min(ans, c);
        }
    }
    if (ans == 1000000) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

ll gcd(ll a, ll b) {
  return (!a || !b) ? 0 : ((a % b == 0) ? b : gcd(b, a % b));
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
  }

  vector<ll> f(n);
  ll res = v[0];
  for (ll i = 1; i < n; i++) {
    res = gcd(v[i - 1], res);
    f[i] = res;
  }

  vector<ll> b(n);
  res = v[n - 1];
  for (ll i = n - 1; i > 0; i--) {
    res = gcd(v[i], res);
    b[i - 1] = res;
  }

  ll ans = 1;
  for (ll i = 0; i < n; i++) {
    if (f[i] == 0 || b[i] == 0)
      ans = max(ans, max(f[i], b[i]));
    else
      ans = max(ans, gcd(f[i], b[i]));
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
ary = []
while true
  i = STDIN.gets.split.map do |num| num.to_i end
  break if i[0] == 0 && i[1] == 0
  ary.push i
end

ary.each do |r|
  r[0].times do
    r[1].times do print '#' end
    puts
  end
  puts
end

Measured memory_bytes: 6104
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define mkp make_pair
#define no {cout << "-1\n"; return;}

void solve() {
    int n, a, b; 
    cin >> n >> a >> b;
    int lst, ans = 0;
    cin >> lst;
    loop(i, n - 1) {
        int x; cin >> x;
        ans += min(b, (x - lst) * a);
        lst = x;
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3580
package main

import (
	"fmt"
  	"strings"
)

func main() {
	var s1,s2,s3 string
	fmt.Scan(&s1,&s2,&s3)
	
	fmt.Print(strings.ToUpper(string(s1[0])))
	fmt.Print(strings.ToUpper(string(s2[0])))
	fmt.Print(strings.ToUpper(string(s3[0])))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> X(N);
  rep(i, N) {
    cin >> X[i];
  }

  map<int, int> m;
  vector<ll> cnt(M), cnt_pair(M);
  rep(i, N) {
    cnt[X[i] % M]++;
    m[X[i]]++;
    if (m[X[i]] % 2 == 0)
      cnt_pair[X[i] % M]++;
  }
  // debug(cnt);
  // debug(cnt_pair);

  ll ans = 0;
  repp(i, 1, (M - 1) / 2) {
    int l = i, s = M - i;
    if (cnt[l] < cnt[s])
      swap(l, s);
    ans += cnt[s];
    ans += min(cnt_pair[l], (cnt[l] - cnt[s]) / 2);
  }

  ans += cnt[0] / 2;
  if (M % 2 == 0)
    ans += cnt[M / 2] / 2;
  cout << ans << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int a,b; cin >> a >> b;
    if(b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
}

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

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

typedef long long ll;

int main(void){
  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> work(n);

  int a, b;
  REP(i, n){
    cin >> a >> b;
    work[i] = make_pair(a, b);
  }

  sort(work.begin(), work.end());

  priority_queue<int> queue;

  int start = 0;
  ll ans = 0;
  for(int i = 1; i <= m; i++){
    for(int j = start; j < n; j++){
      if(work[j].first <= i){
        queue.push(work[j].second);
      }else{
        start = j;
        break;
      }
      if(j == n-1) start = n;
    }

    if(!queue.empty()){
      ans += queue.top();
      queue.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1660
N, M, X = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]

flg = False
ans = 10**9
for i in range(2**N):
    bits = bin(i)[2:].zfill(N)
    ok = True
    xs = [0] * M
    tmp = 0
    for i, b in enumerate(bits):
        if b == '0': continue

        for j in range(M):
            xs[j] += L[i][j+1]

        tmp += L[i][0]

    for x in xs:
        if x < X:
            ok = False
            break

    if ok:
        flg = True
        ans = min(tmp, ans)

ans = ans if flg else -1
print(ans)

Measured memory_bytes: 9164
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0]);
  var output = 0;
  for(var i = 1; i <= N; i++){
    var tmp = input[i].split(" ");
    if(tmp[1] == "JPY"){
       output += parseInt(tmp[0]);
    }else{
       output += parseFloat(tmp[0]) * 380000;
       }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7372
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
#2019-02-11

#DP

L = int(input())

DP = [0 for i in range(5)]

def cost(a):
    if a:
        return [a, a%2, (a+1)%2, a%2, a]
    else:
        return [0, 2, 1, 2, 0]

def list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

for i in range(L):
    a = int(input())
    cos = cost(a)
    DP[4] = min(DP[:5]) + cos[4]
    DP[3] = min(DP[:4]) + cos[3]
    DP[2] = min(DP[:3]) + cos[2]
    DP[1] = min(DP[:2]) + cos[1]
    DP[0] = min(DP[:1]) + cos[0]



print(min(DP))

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n;

int main(void){
	cin>>n;

	map<int, int> res;
	for (int i = 1; i <= n; i++) {
		int tmp = i;
		int div = 2;
		while (tmp > 1) {
			if (tmp % div == 0) {
				++res[div];
				tmp /= div;
			} else {
				div++;
			}
		}
	}
	
	ll ans = 1;
	for (auto ite = res.begin(); ite != res.end(); ++ite) {
		ans *= (ite->second + 1);
		ans %= MOD;
	}

	cout<< ans <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  string o,e;
  cin >> o >> e;
  REP(i, o.size() - 1) { cout << o[i] << e[i]; }
  if(o.size()==e.size())
    cout << o[o.size()-1] << e[e.size()-1] << endl;
  else
    cout << o[o.size()-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int a, b;

signed main() {
    cin >> a >> b;
    if (a>=13) cout << b;
    else if (a>=6) cout << b/2;
    else cout << 0;
    cout << endl;
}


Measured memory_bytes: 256