akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n;
    cin>>n;
    vi a(n);
    ll ans=0;
    rep(i,n)cin>>a[i];
    rep(i,n){
        int t=0;
        t=a[i]/2;
        a[i]-=t*2;
        ans+=t;
        if(a[i]==1&&i+1<n&&a[i+1]>0){
            ans++;
            a[i+1]--;
        }
    }
    fin(ans);
    

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;

int n;
int a[100002];

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	sort(a, a + n);
	cout << a[n/2]-a[n/2-1];


	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
class Program{
  static void Main(){
    int[] card =
      Console.ReadLine().Split(' ').Select(a => int.Parse(a))
      .Concat(Console.ReadLine().Split(' ').Select(a => int.Parse(a)))
      .Concat(Console.ReadLine().Split(' ').Select(a => int.Parse(a)))
      .ToArray();
    Console.ReadLine();
    string input;
    while((input = Console.ReadLine())!=null){
      int b = int.Parse(input);
      var idx = Array.IndexOf(card, b);
      if(idx >= 0) card[idx] = 0;
    }
    if(card[0]+card[1]+card[2]==0
       || card[3]+card[4]+card[5]==0
       || card[6]+card[7]+card[8]==0
       || card[0]+card[3]+card[6]==0
       || card[1]+card[4]+card[7]==0
       || card[2]+card[5]+card[8]==0
       || card[0]+card[4]+card[8]==0
       || card[2]+card[4]+card[6]==0)
       Console.WriteLine("Yes");
    else
       Console.WriteLine("No");
  }
}

Measured memory_bytes: 13280
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t = input()
n = len(t)
ans = []
for i in range(n):
    if t[i] == '?':
        ans.append('D')
    else:
        ans.append(t[i])
print(''.join(ans))

Measured memory_bytes: 82320
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int X, A;
	int ans;
	cin >> X >> A;
	if (X < A) ans = 0;
	else ans = 10;
	cout << ans << endl;

	return 0;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int maxv = min(a, b);
  if(b > a) swap(a, b);
  int minv = max(a + b - n, 0);
  cout << maxv << " "<< minv << endl;
}

Measured memory_bytes: 256
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

	/**
	 * SortedMap
	 */
	public static void main(String[] args) {
		List<Point> list = new ArrayList<Point>();
		Map<Integer, SortedMap<Integer, Integer>> map = new HashMap<>();
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		for (int i = 0; i < M; i++) {
			int P = sc.nextInt();
			int Y = sc.nextInt();
			list.add(new Point(P, Y));
			SortedMap<Integer, Integer> treeMap;
			if (map.containsKey(P)) {
				treeMap = map.get(P);
			} else {
				treeMap = new TreeMap<Integer, Integer>();
			}
			treeMap.put(Y, 0);
			map.put(P, treeMap);
		}
		for (Entry<Integer, SortedMap<Integer, Integer>> item : map.entrySet()) {
			int index = 0;
			Iterator<Entry<Integer, Integer>> iterator = item.getValue().entrySet().iterator();
			while (iterator.hasNext()) {
				iterator.next().setValue(++index);
			}
		}
		for (Point point : list) {
			int p = point.x;
			System.out.println(String.format("%06d%06d", p, map.get(p).get(point.y)));
		}
	}
}


Measured memory_bytes: 176668
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;

 
int main(){

    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    rep(i, q){
        int ty;
        cin >> ty;
        if(ty == 1){
            swap(s,t);
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f==1){
                t += c;
            }else{
                s += c;
            }
        }
    }
    reverse(t.begin(), t.end());
    t+=s;
    cout << t << endl;
   
/*    string s;
   cin >> s;
   int q;
   cin >> q;
    int query;
   rep(i,q){
       cin >> query;
       if(query ==1){
           reverse(s.begin(), s.end());
       }
       else {
           int f;
           cin >> f;
           string c;
           cin >> c;
           if(f == 1){
               s.insert(0, c);
           }
           else {
               s.insert(s.size(), c);
           }
       }
   }
   cout << s;*/
   

 
    return 0;
}

Measured memory_bytes: 1128
import itertools
def solve():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    per = list(itertools.permutations(tuple(range(1,N+1))))
    
    i = 0
    a = 0
    b = 0
    for p in per:
        if p == P:
            a = i
        if p == Q:
            b = i
        i += 1
    
    print(abs(a-b))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 44784
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
while(x != NIL){
  y = x;
  if(z->key < x->key){
    x = x->l;
  }
  else{
    x = x->r;
  }
}
/*最下層*/
z->p = y;
if(y == NIL){
  root = z;
}
else{
  if(z->key < y->key){
    y->l = z;
  }
  else {
    y->r = z;
  }
}
}

void inorder(Node u){
if(u==NIL){
  return;
}
inorder(u->l);
printf(" %d",u->key );
inorder(u->r);
}

void preorder(Node u){
if(u==NIL){
  return;
}
printf(" %d", u->key);
preorder(u->l);
preorder(u->r);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25128
#pragma GCC optimize("O3,inline,unroll-loops")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    string a, b;
    int i, o;

    cin >> a >> b;
    for(i = o = 0; i < a.size(); i ++)
        o += a[i] != b[i];
    cout << o << endl;

    return 0;
}


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

const int N = 100005;

int n;
long long ans = 0;
string s;
map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(false);
  	cin.tie(nullptr);
  	cin >> n;
  	while (n--)
    {
        cin >> s;
     	sort(s.begin(), s.end());
      	ans += (ma[s]++);
    }
  	cout << ans;
}

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

int main() {

	char s[100001];
	scanf("%s", s);
	int n = strlen(s);
	vector<char> v1(n);
	vector<char> v2(n);
	v1[0] = '0';
	v2[0] = '1';
	for(int i = 1; i < n; i++) {
		if(v1[i -  1] == '0') {
			v1[i] = '1';
		}else {
			v1[i] = '0';
		}
		if(v2[i - 1] == '0') {
			v2[i] = '1';
		}else {
			v2[i] = '0';
		}
	}
	int x = 0;
	int y = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] != v1[i]) {
			x++;
		}
		if(s[i] != v2[i]) {
			y++;
		}
	}
	printf("%d\n", min(x, y));
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<stdlib.h>

int main(void){
    int N,T,A;
    scanf("%d",&N);
    scanf("%d%d", &T, &A);
    int H[N];
    for(int i=0; i<N; i++){
        scanf("%d",&H[i]);
    }

    int base = abs(1000*T-6*H[0]), judge, ans = 0;
    for(int i=0; i<N; i++){
        judge = abs(1000*(A-T)+6*H[i]);
        if(base>judge){
            base = judge;
            ans=i;
        }
    }

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


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

typedef long long LL;
const int maxn = 1e5 + 10;
int n;
pair<int, int> p[maxn];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		scanf("%d", &p[i].first);
		p[i].second = i;
	}
	sort(p + 1, p + 1 + n);
	int ans = 0;
	for(int i = 1; i <= n; i++) if(abs(p[i].second - i) % 2) ans++;
	return 0*printf("%d\n", ans/2);
}

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

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

    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    int ans = 1;
    
    for(int i = 0; i < n - 1; i++){
        if(s[i]==s[i+1]) continue;
        else ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<ll>b(n);
	vector<ll>c(n);
	rep(i, n) {
		b[i] = i - a[i];
		c[i] = i + a[i];
	}
	sort(b.begin(), b.end());
	ll h(0);
	rep(i, n) {
		ll k;
		k = upper_bound(b.begin(), b.end(), c[i]) - lower_bound(b.begin(), b.end(), c[i]);
		h += k;
	}
	cout << h;

	return 0;
}

Measured memory_bytes: 8008
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

int main()
{
	int a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f
		, a || b || c || d || e || f)
	{
		int x, y, z;
		x = a + d;
		y = b + e;
		z = c + f;

		int ans = 0;
		for (int i = 0; i <= min(2, min(x, min(y, z))); ++i)
			ans = max(ans, i + (x-i)/3 + (y-i)/3 + (z-i)/3);
//			 + min((x-i)%3, min((y-i)%3, (z-i)%3)));

		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  char C;
  cin >> C;
  
  if ( C == 'a') {
    C = 'b';
  }
  else if ( C == 'b') {
    C = 'c';
  }
  else if ( C == 'c') {
    C = 'd';
  }
  else if ( C == 'd') {
    C = 'e';
  }
  else if( C == 'e') {
    C = 'f';
  }
  else if ( C == 'f') {
    C = 'g';
  }
  else if ( C == 'g') {
    C = 'h';
  }
  else if ( C == 'h') {
    C = 'i';
  }
  else if ( C == 'i') {
    C = 'j';
  }
  else if ( C == 'j') {
    C = 'k';
  }
  else if ( C == 'k') {
    C = 'l';
  }
  else if ( C == 'l') {
    C = 'm';
  }
  else if ( C == 'm') {
    C = 'n';
  }
  else if ( C == 'n') {
    C = 'o';
  }
  else if ( C == 'o') {
    C = 'p';
  }
  else if ( C == 'p') {
    C = 'q';
  }
  else if ( C == 'q') {
    C = 'r';
  }
  else if ( C == 'r') {
    C = 's';
  }
  else if ( C == 's') {
    C = 't';
  }
  else if ( C == 't') {
    C = 'u';
  }
  else if ( C == 'u') {
    C = 'v';
  }
  else if ( C == 'v') {
    C = 'w';
  }
  else if ( C == 'w') {
    C = 'x';
  }
  else if ( C == 'x') {
    C = 'y';
  }
  else if ( C == 'y') {
    C = 'z';
  }
 
  cout << C << endl;
  
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi h(n);
	rep(i, n) cin >> h[i];

	vi ok(n, true);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--, b--;

		if (h[a] <= h[b]) ok[a] = false;
		if (h[b] <= h[a]) ok[b] = false;
	}

	int ans = 0;
	rep(i, n) {
		if (ok[i]) ans++;
	}
	cout << ans << endl;
}

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

int main(void) {
    i64 q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    if (q * 2 < h) h = q * 2;
    if (h * 2 < s) s = h * 2;
    if (s * 2 < d) d = s * 2;
    cout << n / 2 * d + n % 2 * s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,k,ans=0,as=0,bs=0,bp=0;
    cin>>n>>m>>k;
    vector<long long> a(n),b(m);
    
    for(auto i=0;i<n;i++){
        cin>>a[i];
        as += a[i];
    }
    
    for(auto i=0;i<m;i++){
        cin>>b[i];
    }
    
    for(auto i=n;i>=0;i--){
        if(i < n){
            as -= a[i];
        }
        if(as <= k ){
            while(bp<m && bs + as + b[bp] <= k){
                bs += b[bp];                   
                bp++;
            }
            ans =max(ans,i+bp);
        }
    }
    
    cout<<ans;
    
    return 0;
}

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

int main () {
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if (a<0 && b>=0){
    if (c<0 && d>=0){
      cout << max(a*c,b*d) << endl;
    }
    else if (d<0){
      cout << a*c << endl;
    }
    else {
      cout << b*d << endl;
    }
  }
  else if (b<0){
    if (c<0 && d>=0){
      cout << a*c << endl;
    }
    else if (d<0){
      cout << a*c << endl;
    }
    else {
      cout << b*c << endl;
    }
  }
  else {
    if (c<0 && d>=0){
      cout << b*d << endl;
    }
    else if (d<0){
      cout << a*d << endl;
    }
    else {
      cout << b*d << endl;
    }
  }
}
      
  

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    ps = ""
    for i in P:
        ps = ps + str(i)
    qs = ""
    for i in Q:
        qs = qs + str(i)
    import itertools
    A = [i+1 for i in range(N)]
    i = 0
    p = q = 0
    for a in itertools.permutations(A):
        s = ""
        for j in a:
            s = s + str(j)
        if ps == s:
            p = i
        if qs == s:
            q = i
        i += 1
    print(abs(p-q))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    a=bisect.bisect_left(A,b)
    c=bisect.bisect_right(C,b)
    ans += a *(N-c)
print(ans)

Measured memory_bytes: 23360
import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Integer count = 0;
		Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String word = s.next().toLowerCase();
		while(s.hasNext()){
			String input = s.next().toLowerCase();
			if(input.equals("END_OF_TEXT")){
				break;
			}
			String[] word_list = input.split(" ");
			for(int i = 0; i < word_list.length; i++){
				if(word.equals(word_list[i])){
					count++;
				}
			}
		}
		s.close();
		System.out.println(count);

	}

}

Measured memory_bytes: 19756
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    s = input()
    if s == "a" or s == "i" or s == "u" or s == "e" or s == "o":
        print("vowel")
    else:
        print("consonant")


Measured memory_bytes: 3828
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  1e5 + 10;  
#define FI first
#define SE second
typedef pair<int, int>pii;
int num[N];
ll tmp[N], n;
bool judge(int cnt, int a, int b)
{
	int d = a - b;
	int lcnt = cnt;
	for (int i = 0; i < n; i++)
	{
		tmp[i] = num[i];
		tmp[i] -= (ll)cnt*b;
		if (tmp[i] <= 0)
			continue;
		int ct = tmp[i] / d + (tmp[i]%d?1:0);
		if (ct > lcnt)
			return false;
		lcnt -= ct;
	}
	return true;
}	
int main()  
{  
  // freopen("in.txt","r",stdin);
   int  a, b;
   while (~scanf("%d%d%d", &n, &a, &b))
   {
   
   	for (int i = 0; i < n; i++)
   	{
   		scanf("%d", num + i);
   	}
   //	sort(num, num + n, greater<int>());
   	int l = 0, r = 1e9 + 10;
   	while (l < r)
   	{
   		int mid = l + ((r - l)>>1);
   		if (judge(mid, a, b))
   			r = mid;
   		else
   			l = mid + 1;
   	}
   	printf("%d\n", l);
   }
   
   return 0;  
}  

Measured memory_bytes: 1408
#include<stdio.h>
main(){
  double a,b,c,d,e,f,x,y;
  int xx,yy;
  while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
  x=(c*e-f*b)/(a*e-d*b);
  y=(a*f-d*c)/(a*e-d*b);
  xx=x*10000;
  yy=y*10000;
  xx=xx%10;
  yy=yy%10;
  if(xx>=5){
    x=x+0.001;
  }
  if(yy>=5){
    y=y+0.001;
  }
  printf("%.3f %.3f\n",x+0,y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
// I LOVE IT :D
//#define int long long
using namespace std;
inline int in() {int32_t x ; scanf("%d",&x) ; return x ; }
inline string getStr() {char ch[1000000] ; scanf("%s",ch) ; return ch ;}
const int MAX_N = 500005;
const int MAX_LG = 22;

pair<int , int> x[MAX_N] ; int y[MAX_N];
int st[MAX_LG][MAX_N];
int ptr[4*MAX_N];
void build(int d , int b , int e )
{
    if (b == e) {
        st[d][b] = x[b].second;
        return;
    }
    int m = (b + e) >> 1;
    build(d + 1, b, m);
    build(d + 1, m + 1, e);
    int l = b, r = m + 1;
    for (int pt = b; pt <= e; ++pt) // p = point ha
        if (l != m + 1 && (r == e + 1 || y[st[d + 1][l]] < y[st[d + 1][r]]))
            st[d][pt] = st[d + 1][l++];
        else
            st[d][pt] = st[d + 1][r++];
}
int j;
int result[105];
int L = 0;
inline void query(int dep , int l , int r , int x1 , int y1 , int x2 , int y2 , int p = 0)
{
    if (x[r].first < x1 || x[l].first > x2)
        return ;
    if (y[st[dep][l]] > y2 || y[st[dep][r]] < y1)
        return ;
    if (x[l].first >= x1 && x[r].first <= x2)
    {
        
        if (ptr[p] < l)
            ptr[p] = l;
        while (ptr[p] <= r && (y[st[dep][ptr[p]]] < y1) )
            ptr[p] ++;
        for (int j = ptr[p] ; j <= r ; j ++)
        {
            if (!(y[st[dep][j]] >= y1 && y[st[dep][j]] <= y2))break;
            L ++;
            result[L] = st[dep][j];
        }
        return ;
    }
    int mid = (l + r) >> 1;
    query(dep + 1 , l  , mid , x1 , y1 , x2 , y2 , 2*p + 1);
    query(dep + 1 , mid + 1 , r , x1 , y1 , x2 , y2 , 2*p + 2);
    return ;
}
const int MAX_Q = 20000;
pair< pair<pair<int , int > , pair<int , int > > , int    > * quer = new pair <pair <pair<int , int> , pair<int , int > > ,int >[MAX_Q];
vector< vector<int> > res(MAX_Q);
int32_t main()
{
    int n = in();
    for (int i = 0 ; i < n ; i ++)
    {
        x[i] = {in() , i};
        y[i] = in();
    }
    sort(x , x + n);
    build(0 , 0 , n - 1);
    int q = in();
    int x1 , x2 , y1 , y2;
    
    for (int i = 0 ; i < q ; i ++)
    {
        x1 = in() , x2 = in() , y1 = in() , y2 = in();
        quer[i] = {{{y1 , y2} , {x1 , x2}},i};
    }
    sort(quer ,quer + q);
    for (int j = 0 ; j < q ; j ++)
    {
        int ind = quer[j].second;
        pair<int , int >xc = quer[j].first.second;
        pair<int , int >yc = quer[j].first.first;
        L = -1;
        query(0 , 0 , n - 1 , xc.first , yc.first , xc.second , yc.second);
        for (int j = 0 ; j <= L ; j ++)
        {
            res[ind].push_back(result[j]);
        }
        sort(res[ind].begin(),res[ind].end());
    }
    for (int j = 0 ; j < q ; j ++)
    {
        for (int i = 0 ; i < res[j].size() ; i ++)
            printf("%d\n",res[j][i]);
        printf("\n");
    }
}

Measured memory_bytes: 59328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }

signed main(void){
    int n,m; cin>>n>>m;
    vector <int> to(n);
    vector <vector<int>> graph(n,vector <int>());
    vector <vector<int>> ot(n,vector <int>());
    rep(i,n+m-1){
        int a,b; cin>>a>>b;
        a--; b--;
        to[b]++;
        graph[a].push_back(b);
        ot[b].push_back(a);
    }
    priority_queue <int> que;
   
    vector <int> topo(n);
    int x = 0;
    vector <int> deg(n);
    int top;
    rep(i,n) {deg[i] = to[i]; if(to[i]==0) top = i;}
    que.push(top);
    while(!que.empty()){
        int v = que.top(); que.pop();
        topo[x++] = v;
        for(int i=0;i<graph[v].size();i++){
            int nv = graph[v][i];
            deg[nv]--;
            if(deg[nv]==0) que.push(nv);
        }
    }
    
    /*for(int i=0;i<n;i++){
        cout<<topo[i]+1<<endl;
    }*/
    vector <int> oya(n,0);
    
    rep(i,n){
        
        int now = topo[i];
        rep(j,graph[now].size()){
            oya[graph[now][j]] = now+1;
        }
    }
    rep(i,n) cout<<oya[i]<<endl;
}


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

int main(){
  int sx,sy,tx,ty,dx,dy;
  cin >> sx >> sy >> tx >> ty;
  dx = tx - sx;
  dy = ty - sy;
  for(int i = 0; i < dy; i++){
    cout << 'U';
  }
  for(int i = 0; i < dx; i++){
    cout << 'R';
  }
  for(int i = 0; i < dy; i++){
    cout << 'D';
  }
  for(int i = 0; i < dx; i++){
    cout << 'L';
  }
  cout << 'L';
  for(int i = 0; i < dy+1; i++){
    cout << 'U';
  }
  for(int i = 0; i < dx+1; i++){
    cout << 'R';
  }
  cout << 'D';
  cout << 'R';
  for(int i = 0; i < dy+1; i++){
    cout << 'D';
  }
  for(int i = 0; i < dx+1; i++){
    cout << 'L';
  }
  cout << 'U';
  cout << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std; 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll n;
  cin>>n;
  ll a[n];
  ll v[n+1]={0};
  for(ll i=0;i<n-1;i++)
  {
       cin>>a[i];
       v[a[i]]++;
  }
  for(ll i=1;i<=n;i++)
  {
      cout<<v[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6780
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;



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

	long long n, i, j, k, w, s, v, ans, x, MAXW = 20010;
	cin >> n;
	vector<tuple<long long, long long, long long>> plist(n);
	for (i = 0; i < n; i++) {
		cin >> w >> s >> v;
		plist[i] = { s + w, w, v };
	}
	sort(plist.begin(), plist.end());

	vector<long long> dp(MAXW, 0);
	for (i = 0; i < n; i++) {
		tie(s, w, v) = plist[i];

		for (j = s; j >= 0; j--) {
			if (j + w <= s) dp[j + w] = max(dp[j + w], dp[j] + v);
		}
	}

	ans = *max_element(dp.begin(), dp.end());
	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a)*b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(l.second - l.first, p - l.first) / norm(l.second - l.first);
	return l.first + t * (l.second - l.first);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a; c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c) ) return -2;
	return 0;
}

bool intersectSP(const line &s, const xy_t &p){
	return abs(s.first - p) + abs(s.second - p) - abs(s.second - s.first) < EPS;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}


double distanceSP(const line &s, const xy_t p){
	xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

double distanceSS(const line &s, const line &t){
	if(intersectSS(s, t)) return 0.0;
	return min(min(distanceSP(s, t.first), distanceSP(s, t.second)),
		min(distanceSP(t, s.first), distanceSP(t, s.second)));
}

xy_t crosspoint(const line &l, const line &m){
	double a = cross(l.second - l.first, m.second - m.first);
	double b = cross(l.second - l.first, l.second - m.first);
	if(abs(a) < EPS && abs(b) < EPS) return m.first;
	if(abs(a) < EPS) assert(false);
	return m.first + b / a * (m.second - m.first);
}

int main(){
	int dp[20][1000];
	int n;
	while(cin >> n && n){
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for(int i = 1; i <= 17; i++){
			for(int j = 0; j <= n; j++){
				dp[i][j] = dp[i-1][j];
				if(j >= i * i){
					dp[i][j] += dp[i][j-i*i];
				}
			}
		}
		cout << dp[17][n] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int n, k; cin >> n >> k;
		int p[n+1];
		FOR1(i, n) cin >> p[i];
		sort(p+1, p+n+1);
		int cst = 0;
		FOR1(i, k){
			cst += p[i];
		}
		cout << cst;
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3632
def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def remove_Edge(N,Ef,Eb,start,goal):
    v = connect_dfs(N,Ef,start) & connect_dfs(N,Eb,goal)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            Ef[j].pop(i)

def Bellman_Ford(N,E,start,INFTY=10**18):
    def update(dist,N,E,start):
        done = [False]*N
        done[start] = True
        q = [start]
        d = dist[:]
        while q:
            i = q.pop()
            di = d[i]
            for j,c in E[i].items():
                d[j] = min(d[j],d[i]+c)
                if not done[j]:
                    q.append(j)
                    done[j] = True
        return d
    #
    d = [INFTY]*N
    d[start] = 0
    for _ in range(N-1):
        d = update(d,N,E,start)
    if d!=update(d,N,E,start): return None
    else: return d

N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
INFTY = 10**18
for a,b,c in ABC:
    Ef[a-1][b-1] = min(P-c,Ef[a-1].get(b-1,INFTY))
    Eb[b-1][a-1] = min(P-c,Eb[b-1].get(a-1,INFTY))
    
remove_Edge(N,Ef,Eb,0,N-1)
d = Bellman_Ford(N,Ef,0)

if d==None:ans=-1
else:ans = max(0,-d[-1])
print(ans)

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

typedef long long ll;

ll gcd(ll a, ll b) {
    if(b==0) {
        return a;
    }
    else {
        return gcd(b, a%b); 
    }
}

ll lcm(ll a, ll b) {
    return (a*b)/gcd(a,b);
}

ll F(ll A, ll X) {
    return A/X;
}

ll F(ll L, ll R, ll X) {
    return ( F(R, X) - F(L-1, X) );
}

int main() 
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans;
    ans = (B-A+1) - F(A, B, C) - F(A, B, D) + F(A, B, lcm(C,D));
    cout << ans << 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++)
using ll = long long;
using P = pair<int, int>;


int main(){
    int n, m; cin >> n >> m;
    vector<P> p(m);
    rep(i,m) cin >> p[i].first >> p[i].second;
    rep(i,1000){
        string s = to_string(i);
        if(s.size() != n) continue;
        bool isOK = true;
        rep(i,m){
            if(s[p[i].first-1]-'0' != p[i].second) isOK = false;
        }
        if(isOK){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val K = nextInt()
    var ans = 0L
    for (a in 1 .. K)
    for (b in 1 .. K)
    for (c in 1 .. K)
        ans += gcd(a, gcd(b, c))
    return println(ans)
}
tailrec fun gcd(a: Int, b: Int): Int = if (a % b == 0) b else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset


Measured memory_bytes: 34476
$cnt=0

def solve(adj,n,m)
	perm(0,1,0,adj,n,m)
	puts $cnt
end

def perm(i,u,c,adj,n,m)
	if i<n-1
		for x in 0..n-1
			if ((u>>x)&1)==0
				nu=u+(1<<x)
				if adj[c][x]==1
					perm(i+1,nu,x,adj,n,m)
				end
			end
		end
	else
		$cnt+=1
	end
end

if __FILE__==$0
	
	rl_i=lambda{|str,dl|str.strip.split(dl).map(&:to_i)}
	
	dl=" "
	num=rl_i[gets,dl]
	adj=Array.new(num[0]){Array.new(num[1]){0}}
	num[1].times do |i|
		v=rl_i[gets,dl]
		adj[v[0]-1][v[1]-1]=1
		adj[v[1]-1][v[0]-1]=1
	end
	solve(adj,num[0],num[1])
end

Measured memory_bytes: 1788
N = int(input())
As = list(map(int,input().split()))

nums = {}
for a in As:
    if a in nums.keys():
        nums[a] += 1
    else:
        nums[a] = 1

hens = []
for n in nums.items():
    if n[1] >= 4:
        hens.append(n[0])
    if n[1] >= 2:
        hens.append(n[0])

if len(hens) < 2:
    print(0)
    exit()

hens.sort(reverse=True)
print(hens[0] * hens[1])

Measured memory_bytes: 17960
n = int(input())
s = input()

ans = ["SS", "SW", "WS", "WW"]

for i in range(4):
    for j in range(1, n):
        if s[j] == "o" and ans[i][j] == "S":
            ans[i] += ans[i][j-1]
        elif s[j] == "o" and ans[i][j] == "W":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        elif s[j] == "x" and ans[i][j] == "S":
            ans[i] += "W" if ans[i][j-1] == "S" else "S"
        else:
            ans[i] += ans[i][j - 1]

    if ans[i][0] == ans[i][n]:
        if ans[i][n-1] == ans[i][1] and ((s[0] == "o" and ans[i][0] == "S") or (s[0] == "x" and ans[i][0] == "W")):
            print(ans[i][:-1])
            break
        if ans[i][n-1] != ans[i][1] and ((s[0] == "o" and ans[i][0] == "W") or (s[0] == "x" and ans[i][0] == "S")):
            print(ans[i][:-1])
            break
else:
    print(-1)

Measured memory_bytes: 3884
n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
   t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

ans = [0] * (q)
for i in range(q):
   l, r = map(int, input().split())
   ans[i] = t[r-1] - t[l-1]

[print(x) for x in ans]


Measured memory_bytes: 12728
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

T = input()
for x in T:
	if x == "?":
		print("D", end = "")
	else:
		print(x, end = "")
print()

Measured memory_bytes: 10132
s =input()
n = len(s)
a = [0]*(n+1)
res = 0
hidari = [0] *(n+1)
for i in range(1,n+1):
    if s[i-1] == '<':
        res +=1
    else:res = 0
    hidari[i] = res
hidari[-1] = res
res = 0
migi = [0] *(n+1)
for i in range(n-1,-1,-1):
    if s[i] == '>':
        res+=1
    else:res = 0
    migi[i] = res
migi[0] = res
ans = 0
for i in range(n+1):
    ans += max(migi[i],hidari[i])
print(ans)

Measured memory_bytes: 31132
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long X = Math.Abs(A[2]-A[0]);
		long Y = Math.Abs(A[3]-A[1]);
		
		if(X > Y){ var t = X; X = Y; Y = t;}
		if(X==0){
			Console.WriteLine(0);
			return;
		}
		
		long g = gcd(X,Y);
		long xg = X/g;
		long yg = Y/g;
//Console.WriteLine("{0} {1}",X,Y);
		long ans = xg+yg-1;
		ans *= g;
		Console.WriteLine(ans);
		
	}
	
	long gcd(long a,long b){ return a==0 ? b : gcd(b%a,a);}
	
	int[] A;
	public Sol(){
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 2648
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n, m, k] <- getIntList
  as <- getIntList
  bs <- getIntList
  print $ solve n m k as bs

solve :: Int -> Int -> Int -> [Int] -> [Int] -> Int
solve n m k as bs = (go `on` f) as bs
  where
    f = V.fromList . scanl (+) 0
    go av bv = maximum [ i + j | i <- [0..n], let k' = k - av V.! i, k' >= 0, let j = fst (bisearch ((<= k') . (bv V.!)) (0, m+1))]              

-- input

getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

Measured memory_bytes: 16116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
int max=-1;
cin>>n;
vector<int> p(n);
    for(int i=0;i<n;++i){
    cin>>p[i];
    if(p[max]<=p[i]){
        max=i;
    }
    }
    p[max]/=2;
    int sum=0;
    for(int i=0;i<n;++i){
        sum+=p[i];
    }
    cout<<sum<<endl;




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double llf;
#define ft first
#define sd second
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(b-a&1)puts("Borys");
	else puts("Alice");
}

Measured memory_bytes: 764
n,m,k = gets.split.map &:to_i
as = gets.split.map &:to_i
bs = gets.split.map &:to_i

remain = k

ind = 0

as.each.with_index(1) {|a, i|
	if remain >= a then
		remain -= a
		ind = i
	else
		break
	end
}

b_ind = 0

bs.each.with_index(1) { |b, i|
	if remain >= b then
		remain -= b
		b_ind = i
	else
		break
	end
}

sum = ind + b_ind

(ind - 1).downto(0){ |i|
	remain += as[i]
	(b_ind...bs.size).each{ |j|
		if remain >= bs[j] then
			remain -= bs[j]
			b_ind += 1
		else
			break
		end
	}
	
	if i + b_ind > sum then
		sum = i + b_ind
	end
}

puts sum


Measured memory_bytes: 48748
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

int main() {
IOS;
    ll n,k,i,ans=0,x;
  cin>>n;
  ll b=1;
  while(b*2<=n)b*=2;
  cout<<2*b-1<<endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll A,B;
    cin >> A >> B;
    if(A <= 9 && B <= 9){
        cout << A * B << endl;
    } else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 1050;

int x, y, z, k;
long long xy;
long long a[MAXN], b[MAXN], c[MAXN];
map < long long, int > mp;
priority_queue <long long> q;

long long getSum(long long need) {
  auto it = mp.lower_bound(-need); 
  if (it != mp.begin() && (it == mp.end() || it->first > -need)) {
    it--;
  }
  if (it->first > -need) {
    return 0;
  }
  return it->second;
}

long long getCnt(long long x) {
  long long cnt = 0;
  for (int i = 0; i < z; i++) {
    long long cur = c[i];
    if (cur >= x) {
      cnt += xy;
      continue;
    }
    long long need = x - cur;
    cnt += getSum(need);
  }
  return cnt;
}

int main() { 

  cin >> x >> y >> z >> k;
  for (int i = 0; i < x; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < y; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 0; i < z; i++) {
    scanf("%lld", &c[i]);
  }
  xy = x * y;

  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      mp[-(a[i] + b[j])]++;
    }
  }
  long long sum = 0;
  auto it = mp.begin();
  while (it != mp.end()) {
    sum += it->second;
    it->second = sum;
    it++;
  }

  long long l = 1, r = 30ll * 1e9;
  while (l < r) {
    long long mid = (l + r + 1) / 2;
    // cerr << "mid " << mid << " " << getCnt(mid) << endl;
    if (getCnt(mid) >= k) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }


  // cerr << "L " << l << endl;

  sort(c, c + z);
  for (int i = 0; i < z; i++) {
    long long prev = 0;
    for (auto x : mp) {
      long long cur = -x.first;
      if (cur + c[i] <= l) {
        break;
      }
      for (int j = 0; j < x.second - prev; j++) {
        q.push(cur + c[i]);
        if (sz(q) > k) {
          q.pop();
        }
      }
      prev = x.second;
    }
  }

  vector <long long> ans;
  while (!q.empty()) {
    ans.push_back(q.top());
    q.pop();
  }
  while (sz(ans) < k) {
    ans.push_back(l);
  }

  sort(all(ans));
  reverse(all(ans));
  for (int i = 0; i < sz(ans); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 62848
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
int n, m, k;

int main() {
    scanf("%d %d %d", &n, &m, &k);
    vector<int> a(n + 1, 0), b(m + 1, 0);
    vector<long long> sumA(n + 1, 0), sumB(m + 1, 0);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sumA[i] = sumA[i - 1] + a[i];
    }
    for (int i = 1; i <= m; ++i) {
        scanf("%d", &b[i]);
        sumB[i] = sumB[i - 1] + b[i];
    }

    int max_ans = 0;
    int j = m;
    for (int i = 0; i <= n; ++i) {
        if (sumA[i] > k) {
            break;
        }
        int p = upper_bound(sumB.begin(), sumB.end(), k - sumA[i]) - sumB.begin();
        /*printf("%d\n", p);

        while (sumB[j] > k - sumA[i]) {
            j--;
        }*/
//        max_ans = max(max_ans, i + j);
        max_ans = max(max_ans, i + (p - 1));
    }

    printf("%d\n", max_ans);
    return 0;
}


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

int main() {
  int ans = 0;
  int c;
  for(int i = 0; i < 3; ++i) {
    cin >> c;
    ans = 10 * ans + c;
  }
  if(ans % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,k = gets.chomp.split.map(&:to_i)

count = 0
if k==0
  count = n*n
else
  (k+1..n).each do |b|
    rem = n%b
    if rem >= k
      count += (b-k)*(n/b) + rem + 1 - k
    else
      count += (b-k)*(n/b)
    end
  end
end
printf("%d\n",count)

Measured memory_bytes: 1788
n = gets.to_i
data = n.times.map{ gets.strip.split.map(&:to_i)}

def is_reachable(current, next_data)
    tc, xc, yc = current
    tn, xn, yn = next_data
    dist = (xc - xn).abs + (yc - yn).abs
    return false if dist > tn - tc
    (dist-(tn - tc)).even?
end

current = [0, 0, 0]
data.each do |d|
    unless is_reachable(current,d)
        puts 'No'
        exit 0
    end
    current = d
end

puts 'Yes'


Measured memory_bytes: 9468