akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

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

long long int m[1001][1001];

bool used[1001][1001];

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

int main(){
	
	while(true){
		int R;
		cin >> R;
		if(R == 0){
			break;
		}
		
		long long int a[2] = {};
		
		long long int num[2][100001];
		
		for(int i = 0; i < 2; i++){
			for(int j = 0; j <= 100000; j++){
				num[i][j] = 1000000000LL;
			}
		}
		
		for(int i = 0; i < 2; i++){
			int W, H, X, Y;
			cin >> W >> H >> X >> Y;
			X--;
			Y--;
			for(int j = 0; j < H; j++){
				for(int k = 0; k < W; k++){
					cin >> m[j][k];
					used[j][k] = false;
				}
			}
			priority_queue<P1, vector<P1>, greater<P1> > pque;
			P1 p;
			p.first = 1;
			p.second.first = Y;
			p.second.second = X;
			pque.push(p);
			used[Y][X] = true;
			
			for(int j = 0; j <= R; j++){
				num[i][j] = a[i];
				if(pque.empty()){
					break;
				}
				P1 p1 = pque.top();
				pque.pop();
				//cout << p1.first << " ";
				//cout << p1.second.second << " " << p1.second.first << endl;
				a[i] = max(a[i], p1.first);
				for(int j = 0; j < 4; j++){
					P1 pp;
					pp.second.first = p1.second.first + dy[j];
					pp.second.second = p1.second.second + dx[j];
					if(pp.second.second >= 0 && pp.second.first >= 0 && pp.second.second < W && pp.second.first < H && !used[pp.second.first][pp.second.second]){
						pp.first = m[pp.second.first][pp.second.second];
						pque.push(pp);
						used[pp.second.first][pp.second.second] = true;
					}
				}
			}
		}
		
		long long int ans = 1000000000LL;
		
		for(int j = 0; j <= R; j++){
			ans = min(ans, num[0][j] + num[1][R - j]);
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>a;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		a.push_back(now);
	}
	sort(a.begin(),a.end());
	ll l=a[a.size()/2-1];
	ll r=a[a.size()/2];
	cout << max(ll(0),r-l);
	// your code goes here
	return 0;
}

Measured memory_bytes: 1400
n = int(input()) - 1

j = 0

ans = 0

for i in range(1, n):
    
    j = i
    
    while True:
        j += 1
        if i * j > n:
            break
        ans += 1

k = 1

er = 0

while True:
    if k ** 2 > n:
        break
    er += 1
    k += 1

print((ans * 2) + er)

Measured memory_bytes: 9104
mod=10**9+7
n=int(input())
T=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
Tres=[0]*n
Ares=[0]*n
Tres[0]=[0,T[0]]
Ares[-1]=[0,A[-1]]
for i in range(1,n):
  if T[i]>T[i-1]:
    Tres[i]=[0,T[i]]
  else:
    Tres[i]=[1,T[i]]
  if A[-i-1]>A[-i]:
    Ares[-i-1]=[0,A[-i-1]]
  else:
    Ares[-i-1]=[1,A[-i-1]]
ans=1
for i in range(n):
  ta,tb=Tres[i]
  aa,ab=Ares[i]  
  if ta==1 and aa==1:
    ans=ans*min(tb,ab)%mod
  elif ta==0 and aa==1 and tb>ab:
    ans=0
  elif ta==1 and aa==0 and tb<ab:
    ans=0
  elif ta==0 and aa==0 and tb!=ab:
    ans=0
print(ans%mod)


Measured memory_bytes: 31472
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;

  if (a > b) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 1 && a != b) {
    cout << 0 << endl;
    return 0;
  }

  long long maxi, mini;
  maxi = a + b * (n - 1);
  mini = a * (n - 1) + b;
  cout << maxi - mini + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 200000 * 2 + 20;
char str[maxn];
int num[maxn];
void work() {
    scanf("%s", str + 1);
    int lenstr = strlen(str + 1);
    LL ans = 1LL * lenstr * (lenstr - 1) / 2 + 1;
    for (int i = 1; i <= lenstr; ++i) {
        num[str[i]]++;
    }
    for (int i = 'a'; i <= 'z'; ++i) {
        ans -= 1LL * num[i] * (num[i] - 1) / 2;
    }
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,x;

int main(){
	cin>>n>>x;
	if(n>=10) cout<<x<<endl;
	else cout<<x+100*(10-n)<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	strLst := strings.Split(s,"")
	for i := 0; i<12; i++ {
		fmt.Print(strLst[i])
		if i==3 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    int N, L; cin>>N >>L;
    int sum = (L + (L+N-1)) * N / 2;
    if(L+N-1<0){
        sum -= (L+N-1);
    }else if(L>0){
        sum -= L;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
# 根付き木の原点を任意に定める

n = gets.to_i
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
# 無向グラフなので両始点のグラフに入れる
edges.each do |f, t|
  graph[f] << [f, t]
  graph[t] << [t, f]
end

ans = Array.new(n + 1) { Hash.new(0) }
queue = [[1, 1, 0]]
biggest = 0
until queue.empty?
  from, to, num = queue.shift
  used_nums = [num]
  graph[to].each do |f, t|
    # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
    next if t == from
    used_nums.pop if used_nums.last == 0
    if used_nums.include?(1)
      if used_nums.first > used_nums.size
        next_num = used_nums.size
      else
        next_num = used_nums.size + 1
      end
    else
      next_num = 1
    end
    used_nums << next_num
    ans[f][t] = next_num
    queue << [f, t, next_num]
    biggest = next_num if biggest < next_num
  end
end

puts biggest
edges.each { |f, t| puts ans[f][t] }


Measured memory_bytes: 65916
a;long d[2<<17],*p,m=1e9+7;f(){*p+=p[1];d-p--&&f();*p=(*p-p++[a+1])%m;}main(){scanf("%*d%d",&a);p=d+a;for(*p=1;~scanf("%d",&a);)f();printf("%ld",*d);}

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

typedef struct Node
{
    int parent, left, right;
} Node;

class BinTree
{
private:
    Node *nodes;
    int num;

public:
    BinTree(int n)
    {
        num = n;
        nodes = (Node *)calloc(n, sizeof(Node));

        for (int i = 0; i < n; i++)
            nodes[i].parent = -1;
    };

    void setNode(int n, int left, int right)
    {
        nodes[n].left = left;
        setParent(left, n);
        nodes[n].right = right;
        setParent(right, n);
    };

    void setParent(int n, int parent)
    {
        nodes[n].parent = parent;
    };

    int getParent(int n)
    {
        return nodes[n].parent;
    };

    int getSibling(int n)
    {
        int parent = getParent(n);
        if (parent == -1)
            return -1;
        if (nodes[parent].right == n)
            return nodes[parent].left;
        return nodes[parent].right;
    };

    int getDegree(int n)
    {
        return (nodes[n].right != -1) + (nodes[n].left != -1);
    };

    int getDepth(int n)
    {
        int depth = 0;
        while (nodes[n].parent != -1)
        {
            depth++;
            n = nodes[n].parent;
        }
        return depth;
    };

    int getHeight(int n)
    {
        if (n == -1)
            return 0;
        return max(getHeight(nodes[n].right) + (nodes[n].right != -1), getHeight(nodes[n].left) + (nodes[n].left != -1));
    };

    int getType(int n)
    {
        if (nodes[n].parent == -1)
            return 0;
        if (nodes[n].right != -1 || nodes[n].left != -1)
            return 1;
        return 2;
    };

    void printType(int n)
    {
        switch (getType(n))
        {
        case 0:
            printf("root");
            break;
        case 1:
            printf("internal node");
            break;
        case 2:
            printf("leaf");
            break;
        }
    };

    void printInfo(int n)
    {
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", n, getParent(n), getSibling(n), getDegree(n), getDepth(n), getHeight(n));
        printType(n);
        printf("\n");
    };

    void printAll()
    {
        for (int i = 0; i < num; i++)
            printInfo(i);
    };
};

int main()
{
    int n;
    cin >> n;
    BinTree bt(n);
    int id, left, right;
    for (int i = 0; i < n; i++)
    {
        cin >> id >> left >> right;
        bt.setNode(id, left, right);
    }

    bt.printAll();
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n;
  int x =0,y=0;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  rep(i,n){
    if(v[i]>c[i]){
      x += v[i];
      y += c[i];
    }
  }
  cout << x-y << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

struct moji{
	int a;
	char name[11];
};

int str(char s[],char t[]){
	int i=0,gs=0,gt=0;
	while(s[gs]!=0)gs++;
	while(s[gt]!=0)gt++;
	if(gs!=gt)return 0;
	while(s[i]==t[i])i++;
	if(i!=gs)return 0;
	return 1;
}

int main(){
	int n,m,i,j,count=0,ans=0;
	char s[100][11],t[100][11];
	struct moji a[100];
for(i=0;i<100;i++)a[i].a=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%s",s[i]);
	scanf("%d",&m);
	for(i=0;i<m;i++)scanf("%s",t[i]);
	for(i=0;i<n;i++){
		for(j=0;j<count;j++){
			if(strcmp(s[i],a[j].name)==0){
				a[j].a++;
				break;
			}
		}
		if(j==count){
			a[count].a=1;
			strcpy(a[count].name,s[i]);
			count++;
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<count;j++){
			if(strcmp(t[i],a[j].name)==0)a[j].a--;
//			if(str(t[i],a[j].name)==1)puts("OK");
		}
	}
	for(i=0;i<count;i++)ans=max(ans,a[i].a);
//	for(i=0;i<count;i++)printf("%s,%d\n",a[i].name,a[i].a);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      p: [usize; n],
    }

    let mut ans = 0;
    for i in 1..n-1 {
        let mut temp = vec![p[i-1], p[i], p[i+1]];
        temp.sort();
        temp.dedup();
        if temp.len() >= 2 {
            if temp[1] == p[i] {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
L = list(map(int,input().split()))

if N<3:
    print(0)
    exit()

L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]==L[j]: continue
        for k in range(j+1,N):
            if L[i]==L[k] or L[j]==L[k]: continue
            if L[i]+L[j] > L[k]:
                ans += 1
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<deque>

using namespace std;

#define INF 1 << 29
#define LL long long int

struct Edge{
    int a;
    int b;
    Edge(int i,int j):a(i),b(j){

    }
};

deque<int> deq;
vector<vector<Edge>> edge(100001);
vector<int> node(100001,0);
vector<int> cost(100001,-1);
int n,m;

bool visit(int j){
    //cout << j << " ";
    if(node[j] == 1){
        return false;
    }else if(node[j] == 0){
        node[j] = 1;
        for(int i = 0; i < edge[j].size(); i++){
            //cout << edge[j][i].a << endl;
            bool check = visit(edge[j][i].a);
            if(!check){
                return false;
            }
        }
        node[j] = 2;
        deq.push_front(j);
        return true;
    }
    return true;
}

bool dfs(int j){
    for(int i = 0; i < edge[j].size(); i++){
        if(cost[edge[j][i].a] < 0){
            cost[edge[j][i].a] = cost[j] + edge[j][i].b;
            bool check = dfs(edge[j][i].a);
            if(!check) return false;
        }else{
            if(cost[edge[j][i].a] == cost[j] + edge[j][i].b){
            }else{
                return false;
            }
        }
    }
    return true;
}

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

    cin >> n >> m;

    for(int i = 0; i < m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        edge[a].push_back(Edge(b,c));
    }

    bool circle = true;;

    for(int i = 0; i < n && circle; i++){
        if(node[i+1] == 0){
            circle = visit(i+1);
        }
    }

    if(!circle){
        cout << "No" << endl;
        return 0;
    }

    bool result = true;

    for(int i = 0; i < n && result; i++){
        int t = deq[i];
        if(cost[t] == -1){
            cost[t] = 0;
            result = dfs(t);
        }
    }

    if(result){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

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

    vector<int> d(n);
    for(int i = 0;i < n; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    int cnt = 1;
    for(int i = 0; i < n - 1; i++){
        if(d[i] < d[i + 1]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    u64 N;
    cin >> N;

    u64 num = (u64)sqrt(N);
    u64 ret = N - 1;
    for (int i = 2; i <= num; ++i)
    {
        if (!(N % i))
        {
            ret = MIN(ret, (i - 1) + (N / i - 1));
        }
    }

    cout << ret << "\n";
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  LL sum = 0, cnt = 0;
  vector<LL> a(n);
  bool flag = false;
  for (int i = 0; i < n; i ++) {
    cin >> a[i];
    if (a[i] < 0) {
      a[i] *= -1;
      cnt ++;
    }
    sum += a[i];
    if (a[i] == 0) flag = true;
  }
  if (flag) {
    cout << sum << endl;
    return 0;
  }

  if (cnt % 2 != 0) {
    sort(a.begin(), a.end());
    sum -= a[0] * 2;
  }

  cout << sum << endl;
}

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

void search(vector<string> &s, vector<vector<int>> &g, queue<vector<int>> &q, queue<vector<int>> &qnext, int gid)
{
    vector<int> z = q.front(); q.pop();
    bool flag = false;
    int x = z[0], y = z[1];
    if (g[x][y] < 0)
    {
        g[x][y] = gid;
    }
    else if (g[x][y] < gid)
    {
        if (q.size() > 0)
            search(s, g, q, qnext, gid);
        else
            return;
    }
    
    for (int i:{-1,0,1})
    {
        for (int j:{-1,0,1})
        {
            if (i != 0 && j != 0)
                continue;
            if (x+i < 0 || x+i >= s.size() || y+j < 0 || y+j >= s[0].length())
                continue;
            if (s[x+i][y+j] == '.' && g[x+i][y+j] < 0)
            {
                vector<int> tmp(2); tmp[0] = x+i; tmp[1] = y+j;
                q.push(tmp);
                g[x+i][y+j] = gid;
            }
        }
    }
    for (int i:{-2,-1,0,1,2})
    {
        for (int j:{-2,-1,0,1,2})
        {
            if (x+i < 0 || x+i >= s.size() || y+j < 0 || y+j >= s[0].length())
                continue;
            if (s[x+i][y+j] == '.' && g[x+i][y+j] == -1)
            {
                vector<int> tmp(2); tmp[0] = x+i; tmp[1] = y+j;
                qnext.push(tmp);
                g[x+i][y+j] = -2;
            }
        }
    }
    if (q.size() > 0)
        search(s, g, q, qnext, gid);
    else
    {
        if (qnext.size() > 0)
        {
            queue<vector<int>> tmp;
            search(s, g, qnext, tmp, gid + 1);
        }
        else
        {
            return;
        }
    }
}

int main(void)
{
    int h, w; cin >> h >> w;
    vector<int> c(2), d(2);
    vector<string> s(h);
    int c1, c2; cin >> c1 >> c2; c[0] = c1-1; c[1] = c2-1;
    int d1, d2; cin >> d1 >> d2; d[0] = d1-1; d[1] = d2-1;
    for (int i = 0; i < h; i++)
        cin >> s[i];
    vector<vector<int>> g(h, vector<int>(w, -1)); g[c[0]][c[1]] = 0;
    queue<vector<int>> q; q.push(c);
    queue<vector<int>> qnext;
    search(s, g, q, qnext, 0);
    if (g[d[0]][d[1]] == -1)
        cout << -1 << endl;
    else
    {
        cout << g[d[0]][d[1]] - g[c[0]][c[1]] << endl;
    }
}

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

int main(){
    long N;
    cin >> N;
    vector<LL> a,b,c;
    long bm[N];
    fill(bm,bm+N,0);
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        a.push_back(s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        b.push_back(s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        c.push_back(s);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    LL count=0;
    LL sum=0;
    int it;
    for(auto bitr=lower_bound(b.begin(),b.end(),a[0]+1);bitr!=b.end();bitr++){
        auto citr=lower_bound(c.begin(),c.end(),*bitr+1);
        count+=c.end()-citr;
        it=bitr-b.begin();
        bm[it]=c.end()-citr;
    }
    for(int i=N-1;i>=0;i--){
        sum+=bm[i];
        bm[i]=sum;
    }
    for(int i=1;i<N;i++){
        auto bitr=lower_bound(b.begin(),b.end(),a[i]+1);
        it=bitr-b.begin();
        if(it<N) count+=bm[it];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    bool success = true;
    for(int i =0; i < s.size(); i++){
        if(s[i]!=s[s.size()-1-i]){
            success = false;
        }
    }
    for(int i = 0; i < s.size()/2; i++){
        if(s[i]!=s[s.size()/2-1-i]){
            success =false;
        }
    }
    for(int i =0 ; i < s.size()/2; i++){
        if(s[i+s.size()/2+1]!=s[s.size()-1-i]){
            success = false;
        }
    }
    if(success)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
<?php
    $num = explode(" ",trim(fgets(STDIN)));
    $a = $num[0];
    $b = $num[1];
    $d = floor($a/$b);
    $r = $a%$b;
    $avg = ($a / $b);
    $f = round($avg, 5);
    echo $d. " " . $r. " ". $f .PHP_EOL;

Measured memory_bytes: 15408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    vector<ll>a(n),b(n),c(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans=0;
    rep(i,n){
        ll up=lower_bound(all(a),b[i])-a.begin();
        ll down=n-(upper_bound(all(c),b[i])-c.begin());
        ans+=up*down;
    }
    cout<<ans<<endl;
}











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

int main() {
  string S, T;
  cin >> S >> T;
  if (S.size() > T.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if (S.size() < T.size()) {
    cout << "LESS" << endl;
    return 0;
  }

  for (int i = 0; i < S.size(); i++) {
    if (S[i] > T[i]) {
      cout << "GREATER" << endl;
      return 0;
    }
    if (S[i] < T[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin>>s;
    int margin = 0;
    rep(i,s.size())
    {
        char x = s[i];
        while(x == s[i])i++;
        i--;
        margin++;
    }
    cout<<margin-1<<endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void)

{
    int N, a, i, j;
    scanf("%d", &N);
    string s1, s2, s;
    cin>>s1>>s2;
    a = 0;
    j = 0;
    for(i = 0; i < N*2; i++){
        if(i%2 == 0){
            s += s1[a];
            a++;
        }
        else{
            s += s2[j];
            j++;
        }
    }
    cout<<s;
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
import Data.List
import Control.Monad

foo :: Int -> Int -> Int
foo x y = x*y `mod` 2019

hoge :: [Int] -> [Int] -> [Int]
hoge xs ys = do
  x <- xs
  y <- ys
  guard (x<y)
  return $ foo x y

main = do
  sd <- map read . words <$> getLine :: IO [Int]
  let nums = map (`mod` 2019) [head sd..last sd]
  if 0 `elem` nums then print 0
  else print $ foldr min 2019 $ hoge nums nums




Measured memory_bytes: 1276
# Aizu Problem 0268: Konto Type

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
for _ in range(n):
    k = int(input(), 16)
    s = 1 << 31
    p = ""
    if k & s != 0:
        k ^= s
        p = "-"
    a = int(k * 1.0 / (1 << 7))
    print(p + str(a) + str(abs(k * 1.0 / (1 << 7) - a))[1:])

Measured memory_bytes: 8044
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,k] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let ps = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n k ps
  print ans

compute :: Int -> Int -> [Int] -> Int
compute n k ps = sum $ take k $ sort ps

Measured memory_bytes: 4340
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    
    int a = 0;
    for(int i = 1;i <= N;i++){
      int h = scanner.nextInt();
      if(h >= K){
       a++;
     }else{
       continue;
     }
    }
    
   
   System.out.println(a);
    
    
    
    
  }
}

Measured memory_bytes: 47516
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-7
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<int, pair<int, int>> tup;

inline void solve()
{
	int n, m;
	string s, t, u;
	cin >> s >> t;
	cin >> n >> m;
	cin >> u;

	if (s == u)
		n--;
	else
		m--;

	cout << n << ' ' << m;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ull unsigned long long
#define y1 asjdlfaskavslbcjasndscf
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter set< int >::iterator
#define iter1 multiset<int>::iterator
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=300+7;
const int inf=1e18+1e9;
const int mod=998244353;
const ld eps=1e-9;

//const int MAX_MEM=4e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
//    char *res=mem+mpos;
//    mpos+=n;
//    if (mpos>=MAX_MEM){
//        cout<<"BAD"<<endl;
//        exit(0);
//    }
//    return (void*)res;
//}
//
//inline void operator delete(void *) {}

int dp[N][N][N];

main ()
{
    ios;
    string s;
    int k;
    cin>>s>>k;
    k=min(k,(int)s.size());
    int kol=0;
    vector< int >a;
    for (int i=0;i<s.size();++i){
        if (s[i]=='1')++kol;
        else {
            a.pb(kol);
            kol=0;
        }
    }
    if (kol)a.pb(kol);
    a.pb(0);
    dp[0][0][0]=1;
    reverse(all(a));
    int m=a.size();
    for (int i=1;i<a.size();++i){
        for (int j1=0;j1<=k;++j1){
            for (int j2=0;j2<=k;++j2){
                for (int c=0;c<=a[i];++c){
                    if (j1+c>k || j2+c>k)break;
                    dp[i][j1+c][j2+c]+=dp[i-1][j1][j2];
                    dp[i][j1+c][j2+c]%=mod;
                }
                if (dp[i-1][j1][j2]){
                    for (int c=1;c<=j2;++c){
                        dp[i][j1][j2-c]+=dp[i-1][j1][j2];
                        dp[i][j1][j2-c]%=mod;
                    }
                }
            }
        }
    }
    int ans=0;
    for (int j1=0;j1<=k;++j1){
        ans+=dp[m-1][j1][0];
        ans%=mod;
    }
    cout<<ans<<endl;
}

//18 10
//8 1 2 3 4 9 9 5 1 6 6 7 8 6 2 9 10 7
//1 2 3 4 5 6 7 8 9 10


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

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

int main(void) {
  int x;
  cin >> x;
  (x < 1200 ? (cout << "ABC" << endl) : (cout << "ARC" << endl));
  return 0;
}

Measured memory_bytes: 256
S=input()

t=len(S)
for i in range(len(S)//4+1):
    if S[t-7:t]=="dreamer":
        t-=7
    elif S[t-6:t]=="eraser":
        t-=6
    elif S[t-5:t]=="dream" or S[t-5:t]=="erase":
        t-=5
    else:
        break

if t==0: print("YES")
else: print("NO")


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

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

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int A[M],B[N],points[N];
  rep(i,M) { cin >> A[i]; --A[i]; }

  rep(i,N) points[i] = 0;
  rep(i,M){
    rep(j,N) { 
      cin >> B[j]; --B[j]; 
      if( B[j] == A[i] ) ++points[j];
      if( B[j] != A[i] ) ++points[A[i]];
    }
  }
  rep(i,N) cout << points[i] << endl;

  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    string S;
    cin>>S;
    int N=S.size(),X=0,Y=0;

    //X 0101010
    //Y 1010101

    for(int i=0;i<N;++i){
        if(i%2==0){
            if(S[i]=='1')++X;
            if(S[i]=='0')++Y;
        }
        if(i%2==1){
            if(S[i]=='0')++X;
            if(S[i]=='1')++Y;
        }
    }
    cout<<min(X,Y)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  int H, W;
  cin >> H >> W;
  int N;
  cin >> N;
  int a[N];
  vector<int> num;
  FOR(i, 0, N) {
    int in;
    cin >> in;
    FOR(j, 0, in) {
      num.push_back(i + 1);
    }
  }
  int ans[H][W];
  int j = 0;
  FOR(h, 0, H)
  {
    if(h % 2 == 0) {
      FOR(w,0,W) {
        ans[h][w] = num[j];
        j++;
      }
    }
    else
    {
      for (int w = W - 1; w >= 0; w--)
      {
        ans[h][w] = num[j];
        j++;
      }
    }
  }
  FOR(h,0,H) {
    FOR(w,0,W) {
      printf("%d%c", ans[h][w], w == W - 1 ? '\n' : ' ');
    }
  }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==25)
		cout<<"Christmas"<<endl;
	else if(n==24)
		cout<<"Christmas Eve"<<endl;
	else if(n==23)
		cout<<"Christmas Eve Eve"<<endl;
	else
		cout<<"Christmas Eve Eve Eve"<<endl; 
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int main() {
    int n, z, w, a, b;
    cin >> n >> z >> w;
    if (n == 1) {
        cin >> a;
        cout << abs(a - w) << endl;
        return 0;
    }
    REP(i,n-1) {
        cin >> a;
    }
    cin >> b;
    cout << max(abs(b - w), abs(a - b)) << endl;
}


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

void solve(int n, int k)
{
  int res = 1;
  cout << k - 1;
  for (int i = 2; res <= n; ++i)
  {
    cout << " " << res;
    res += i;
  }
  cout << "\n";

  res = 1;
  cout << k - 1;
  for (int i = 1; res <= n; ++i)
  {
    cout << " " << res;
    res += i;
  }
  cout << "\n";

  res = 2;
  int a = res;
  for (int i = 1; res <= n; ++i)
  {
    cout << k - 1 << " " << res;
    for (int j = 0; j < i; ++j)
    {
      res++;
      cout << " " << res;
    }
    res += i + 1;
    for (int j = i + 2; res < n; ++j)
    {
      cout << " " << res;
      res += j;
    }
    cout << "\n";
    res = a + i + 1;
    a = res;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n;
  cin >> n;

  int k = (int)sqrt(n * 2) + 1;
  if (n * 2 != k * (k - 1))
  {
    cout << "No\n";
  }
  else
  {
    cout << "Yes\n"
         << k << "\n";
    solve(n, k);
  }
  return 0;
}


Measured memory_bytes: 1408
# -*- coding: utf-8 -*-

A = list(str(input()))
B = list(str(input()))

if len(A) > len(B):
    print('GREATER')
elif len(A) < len(B):
    print('LESS')
elif A == B:
    print('EQUAL')
else:
    for i in range(len(A)):
        if A[i] > B[i]:
            print('GREATER')
            break
        elif A[i] < B[i]:
            print('LESS')
            break

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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        Queue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            q.offer(a);
        }
        // System.out.println(q);
        for (int i = 0; i < m; i++) {
            int a = q.poll();
            a /= 2;
            q.offer(a);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += q.poll();
        }
        System.out.println(ans);
    }
}

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

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

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

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

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

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

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

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

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


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

int main()
{
    int n, x;
    cin >> n >> x;
    if(x == 1 || x == n * 2 - 1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    int d = 1;
    for(int i = 0; i < n - 2; i++){
        if(d == x - 1) d += 3;
        cout << d << endl;
        d++;
    }
    for(int i = 0; i < 3; i++) cout << x - 1 + i << endl;
    for(int i = 0; i < n - 2; i++){
        if(d == x - 1) d += 3;
        cout << d << endl;
        d++;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>//ソートなどに必要
using namespace std;

int main() 
{
    int n;
    bool answer = false;
    cin >> n;//改行を気にしない、多いときはfor文で。

    for(int i = 0; i <= 25; i++)
    {
      if((n-4*i) % 7 == 0 && n-4*i >= 0) answer = true;
    }

    if(answer) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, K2, digitCount;
    cin >> N >> K;
    digitCount = 1;
    K2 = K;
    while (K2 <= N){
        digitCount += 1;
        K2 *= K;
    }
    cout << digitCount << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

const int MAX_N = 100;
const int MAX_W = 1e5;

bool v[MAX_N][MAX_W];
ll dp[MAX_N][MAX_W];

int N, W;
vector<pair<int, ll>> ks;

ll solve(int n, int w){
	if (n == N)
		return (ll) 0;

	if (v[n][w]) return dp[n][w];

	if (ks[n].first + w > W) { 
		 ll& score = dp[n][w] = solve(n+1, w);
		 v[n][w] = 1;
		 return score;
	}
	else {
		ll& score = dp[n][w] =  max(solve(n+1, w + ks[n].first) + ks[n].second, solve(n+1, w));
		v[n][w] = 1;
		return score;
	}
	
}

int main(){
	cin >> N >> W;

	for(int i = 0;i < N;i++){
		int x;
		ll y;
		cin >> x;
		cin >> y;
		ks.push_back(make_pair(x, y));
	}

	ll sol = solve(0, 0);
	cout << sol << endl;
	return 0;
}


Measured memory_bytes: 84852
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	int N;
	cin >> N;
	map<int, int> m;
	REP(i, N){
		int a;
		cin >> a;
		m[a]++;
	}

	bool ok = true;
	EACH(a, m){
		if(N % 2 == a.first % 2 || a.first >= N){
			ok = false;
		}

		if(N % 2 == 1){
			if(a.second != 2 && !(a.first == 0 && a.second == 1)){
				ok = false;
			}
		}
		else{
			if(a.second != 2){
				ok = false;
			}
		}
	}
	LL MOD = 1e9 + 7;
	LL ret = 1;
	if(ok){
		REP(i, N / 2){
			ret *= 2;
			ret %= MOD;
		}
	}
	else{
		ret = 0;
	}

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 3200
A, B, M = map(int, input().split())
prices_A = list(map(int, input().split()))
prices_B = list(map(int, input().split()))
coupons = [tuple(map(int, input().split())) for _ in range(M)]
possible_purchases = []
for coupon in coupons:
    combination_price = prices_A[coupon[0]-1] + prices_B[coupon[1]-1] - coupon[2]
    possible_purchases.append(combination_price)
possible_purchases.append(min(prices_A)+min(prices_B))
print(min(possible_purchases))

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

int main(){
  int n,m;
  cin >> n >> m;
  int a[55],b[55],c[55],d[55];

  //現在の座標
  for(int i=0;i<n;i++){
      cin >> a[i+1] >> b[i+1];
  }

  //チェックポイントの座標
  for(int i=0;i<m;i++){
      cin >> c[i+1] >> d[i+1];
  }

  //全探索
  for(int i=0;i<n;i++){
    int ans = 1<<30,index = -1;
    for(int j=0;j<m;j++){
      int dis = abs(a[i+1]-c[j+1]) + abs(b[i+1]-d[j+1]);
      if(ans>dis){
          ans = dis;
          index = j+1;
      }
    }
    cout << index << endl;
  }
}


Measured memory_bytes: 256
N, W = list(map(int, input().split()))
W += 1
A = [0] * W
wi, vi = list(map(int, input().split()))
A[wi] = vi

for _ in range(N-1):
    wi, vi = list(map(int, input().split()))
    tmp = [0] * W

    for w in range(W):
        if w-wi < 0:
            tmp[w] = A[w]
        else:
            tmp[w] = max(A[w-wi] + vi, A[w])

    A = tmp

print(max(A))

Measured memory_bytes: 67988
#include <iostream>
#include<math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i =0; i <= (int)(n); i++)

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

    long long ans = 0;
    rep(i, N) {
        if (i % 3 == 0 || i % 5 == 0||(i%3==0&&i%5==0))continue;
        else ans += i;
    }

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

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, T = MAP()
AB = []
for i in range(N):
    a, b = MAP()
    AB.append((a, b))

AB.sort(key=itemgetter(1), reverse=True)
AB.sort(key=itemgetter(0))

TMAX = 6007
dp = list2d(N+1, TMAX, 0)
for i in range(N):
    a, b = AB[i]
    for j in range(TMAX):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j < T:
            dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b)
print(max(dp[N]))


Measured memory_bytes: 181724
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+100;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int a[N][N];
int n,m;
int f[N][N];

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

   cin >> n >> m;
   char ch;
   fr(i,1,n){
      fr(j,1,m){
         cin >> ch;
         a[i][j] = (ch == '.') ? 0 : 1;
      }
   }

   memset(f,0x3f,sizeof f);
   f[1][1] = a[1][1];
   fr(i,1,n){
      fr(j,1,m){
         if(i == 1 && j == 1)continue ;
         f[i][j] = min(f[i-1][j]+(a[i][j]-a[i-1][j] == 1),
               f[i][j-1]+(a[i][j]-a[i][j-1] == 1));
      }
   }
   cout << f[n][m] << endl;
   return 0;
}


Measured memory_bytes: 512
// Author : Nachiket Kanore
// Institute : PICT, Pune

/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */

#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <memory>
#include <random>
#include <cmath>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
 
 
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const int mod = 1e9+7;
const int inf = 1e18;
const int N = 2e5+20;


int32_t main(){
    FAST;
    
    string s;   cin >> s;
    rep(i,0,s.size()-2){
        if(s[i] == 'A' and s[i+1] == 'C')
            return cout << "Yes" , 0;
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2005 + 10;
const int mod = 924844033;

int n, m, tot;
int tag[N], vis[N * 2];
int dp[N], g[N], fac[N], c[N][N], f[N * 2][N][2][2];

inline void Add(int &x, int y) {
	x = (x + y >= mod) ? (x + y - mod) : (x + y);
}

int main() {
	cin >> n >> m;
	c[0][0] = 1;
	for (int i = 1; i < N; ++i) {
		c[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			Add(c[i][j], c[i - 1][j]);
			Add(c[i][j], c[i - 1][j - 1]);
		}
	}
	fac[0] = 1;
	for (int i = 1; i < N; ++i)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	for (int i = 1; i <= n; ++i) {
		if (vis[i]) continue;
		for (int j = i; j <= n; j += m) {
			tag[++tot] = 1;
			vis[j] = 1;
		}
		tag[tot] = 0;
	}
	f[0][0][1][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int a = 0; a < 2; ++a) {
				for (int b = 0; b < 2; ++b) {
					int t = f[i][j][a][b];
					Add(f[i + 1][j][b][0], t);
					if (tag[i + 1])
						Add(f[i + 1][j + 1][b][1], t);
					if (tag[i])
						if (!a) Add(f[i + 1][j + 1][b][0], t);
				}
			}
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < 2; ++j) {
			Add(dp[i], f[n][i][j][0]);
		}
	}
	// cout << n << endl;
	// // for (int i = 0; i <= n; ++i)
	// 	cout << dp[i] << ' ';
	// puts("");
	int ans = fac[n];
	for (int i = n; i >= 1; --i) {
		g[i] = 1LL * dp[i] * fac[n - i] % mod;
		if (i & 1) ans -= g[i];
		else ans += g[i];
		if (ans >= mod) ans -= mod;
		if (ans < 0) ans += mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 81536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll MAX=60;
const ll MOD=1000000007;
ll N;
char S[2][MAX];
ll f(int x,int y){
    if(x==N) return 1ll;
    if(x==0) {
        if(S[0][x]==S[1][x]) return 3ll*f(x+1,0)%MOD;
        return 6ll*f(x+2,1)%MOD;
    }
    if(y==0){
        if(S[0][x]==S[1][x]) return 2ll*f(x+1,0)%MOD;
        return 2ll*f(x+2,1)%MOD;
    }
    if(S[0][x]==S[1][x]) return f(x+1,0);
    return 3ll*f(x+2,1)%MOD;

}
main(){
    scanf("%lld",&N);
    scanf(" %s %s",S[0],S[1]);
    printf("%lld\n",f(0,0));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main
{
 
    public static void main(String[] args)
    {       Scanner stdIn=new Scanner(System.in);
        int a=stdIn.nextInt();
        int b=stdIn.nextInt();
        if(a==b){
            System.out.println("a == b");
        }
        else if(a>b){
            System.out.println("a > b");
        }
        else if(a<b){
            System.out.println("a < b");
        }
 
    }
}

Measured memory_bytes: 26152