akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<pair<int, int> > XL(N, pair<int, int>());
  REP(i, N){
    int x, l; cin >> x >> l;
    XL[i] = {x+l, max(0, x-l)};
  }
  sort(XL.begin(), XL.end());
  int ans = 0, X = 0;
  REP(i, N){
    if(XL[i].second >= X){
      ans++;
      X = XL[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
  var s string
  fmt.Scan(&s)
  list := []string{
    "dream",
    "dreamer",
    "erase",
    "eraser",
  }
  for len(s) > 0 {
    flag := false
    for _, w := range list {
      if len(s) >= len(w) && s[len(s)-len(w):] == w {
        s = s[:len(s)-len(w)]
        flag = true
        break
      }
    }
    if !flag {
      fmt.Println("NO")
      return
    }
  }
  fmt.Println("YES")
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */

int main()
{
    fio;
    int t,n,i;
    cin >> n;
    int x = n% 10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
        cout << "hon" <<endl;
    else if(x == 0 || x == 1 || x== 6 || x == 8)
        cout << "pon"<<endl;
    else   
        cout << "bon"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

int main()
{
  int n, m;
  cin>>n>>m;
  vecint p(n);
  REP(i,n) cin>>p[i];
  UnionFind uf(n+1);
  REP(i,m) {
    int x,y;
    cin>>x>>y;
    uf.merge(x,y);
  }
  map<int, set<int>> ms;
  FOR(i,1,n+1) {
    ms[uf.root(i)].insert(p[i-1]);
  }
  int cnt = 0;
  FOR(i,1,n+1) {
    if (ms[uf.root(i)].count(i)) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 15104
#include<stdio.h>
#include<string.h>
#define N 100

void BubbleSort(char (*)[3],int);
void SelectionSort(char (*)[3],int);

int main(){
  int i,j,n,temp,cnt=0,minj;
  char A[N][3],B[N][3],S[N][3];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",A[i]);
    strcpy(B[i],A[i]);
    strcpy(S[i],A[i]);
  }
  BubbleSort(B,n);
  SelectionSort(S,n);

  int check=0;
  for(i=0;i<n;i++){
    if(strcmp(B[i],S[i])!=0)check=1;
  }
  if(check==0) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}
void BubbleSort(char A[N][3],int n){
  int i,j;
  char temp[3];
      for(i=0;i<n;i++){
	for(j=n-1;j>i;j--){
	  if(A[j][1]<A[j-1][1]){
	  strcpy(temp,A[j]);
	  strcpy(A[j],A[j-1]);
	  strcpy(A[j-1],temp);
	  }
	}
      }
      for(i=0;i<n-1;i++){
	printf("%s ",A[i]);
      }
     printf("%s\n",A[n-1]);
     printf("Stable\n");
}
void SelectionSort(char A[N][3],int n){
  int i,j,minj;
  char temp[3];
    for(i=0;i<n;i++){
      minj=i;
      for(j=i;j<n;j++){
	if(A[j][1]<A[minj][1])minj=j;
      }
      strcpy(temp,A[i]);
      strcpy(A[i],A[minj]);
      strcpy(A[minj],temp);
    }
  for(i=0;i<n-1;i++){
  printf("%s ",A[i]);
  }
  printf("%s\n",A[n-1]);
}




Measured memory_bytes: 2048
#include<stdio.h>
int main(){
	
	int i,j,k,count=0,A,B,C,X;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&X);
	
	for(i=0;i<=A;i++){
		
	
	for(j=0;j<=B;j++){
		
	
	for(k=0;k<=C;k++){
		
		if(X==500*i+100*j+50*k){
			count++;
	}
	}
	}
	}
	
	printf("\n%d\n\n",count);
	
	
	return 0;
}

Measured memory_bytes: 128
from heapq import *
N, M = map(int, input().split())
A = [-int(x) for x in input().split()]
heapify(A)
for x in range(M):
    tmp = int(heappop(A)/2)
    heappush(A,tmp)
res = 0
for x in A:
    res -= x
print(res)


Measured memory_bytes: 14188
n = int(input())
h = list(map(int, input().split(" ")))
a = 'Yes'
m = 0
for i in range(1, len(h)):
    m = max(h[i], m)
    if h[i] < h[i-1] and m - h[i] > 1:
        a = 'No'
        break
print(a)


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//begineer contest 139
//b

int main()
{
	int a,b;

	cin>>a>>b;

	if(b==1)
	{
		cout<<0<<endl;
		return 0;
	}


	int ans = 0;
	int curr = 0;

	while(true)
	{
		curr+=a;
		if(curr<b)
			curr--;
		else
		{
			ans++;
			break;
		}
		ans++;
	}
	cout<<ans<<endl;
}


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

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

 for(int i=0; i<Q; i++){
  int c, a, n;
  cin >> c >> a >> n;

  //????¬????

  int can = min(min(c,a),n);
  c -= can;
  a -= can;

  int cca = min(c/2,a);
  c -= cca*2;

  int ccc = c/3;

  cout << can+cca+ccc << endl;
 }

 return 0;
}

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

int main() {
	int x,y,n;
	while(1){
		cin >> x >> y;
		if(x == 0 && y == 0){
			break;
		}
		if(x > y){
			n = x;
			x = y;
			y = n;
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <climits>
#include <queue>

using namespace std;

class DisjointSet {
public:
    vector<int> p, rank;

    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            p[i] = i;
            rank[i] = 0;
        }
    }

    int findSet(int x) {
        while (x != p[x]) {
            x = p[x];
        }

        return p[x];
    }

    void link(int x, int y) {
        if (rank[x] < rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    DisjointSet disjointSet = DisjointSet(n);

    for (int i = 0; i < q; ++i) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            disjointSet.unite(x, y);
        } else {
            cout << disjointSet.same(x, y) << endl;
        }
    }
}


Measured memory_bytes: 3176
<?php
	fscanf(STDIN,"%d%d%d%d",$n,$m,$x,$y);
	$a=explode(" ",fgets(STDIN));
	$b=explode(" ",fgets(STDIN));
	for($i=0;$i<$n;$i++)$x=$x<+$a[$i]?$a[$i]:$x;
	for($i=0;$i<$m;$i++)$y=$y<+$b[$i]?$y:$b[$i];
	echo $x<$y?"No War":War;

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

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


int n;
n=N/2;

int i=0;


if(N%2==1){cout<<"No";}
else{
int b=1;
for(int i;i<n;i++){
if(s.at(i)!=s.at(i+n)){
b=0;
}
}
if(b==1){cout<<"Yes";}
else {cout<<"No";}




}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int w, h, x, y, r;
	cin>>w>>h>>x>>y>>r;
	if(0<=x-r&&x+r<=w&&0<=y-r&&y+r<=h) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000


int main() {

	LL n, i, b,c, q, num;
	map<LL, LL> mp;
	LL sum = 0;
	cin>>n;
	for(i = 0 ; i < n; i++) {
		cin>>num;
		sum += num;
		mp[num] = mp[num] + 1;
	}

	cin>>q;
	while(q--) {

		cin>>b>>c;

		if(mp[b] == 0) {
			cout<<sum<<endl;
		}
		else {
		 	sum = sum - b*mp[b] + c*mp[b];
		
			mp[c] += mp[b];
			mp[b] = 0;
			cout<<sum<<endl;
		}
	}

	return 0;
}

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

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

int dist[100][100];

int main() {
	int n;
	cin >> n;
	
	fill(dist[0], dist[100], INF);
	REP(i, n) dist[i][i] = 0;
	REP(i, n) {
		int r, k;
		scanf("%d %d", &r, &k);
		r--;
		REP(j, k) {
			int t;
			scanf("%d", &t);
			t--;
			dist[r][t] = 1;
		}
	}
	
	REP(k, n) REP(i, n) REP(j, n)
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	
	int p;
	cin >> p;
	REP(i, p) {
		int s, d, v;
		scanf("%d %d %d", &s, &d, &v);
		s--; d--;
		if (dist[s][d] == INF || dist[s][d] >= v) puts("NA");
		else printf("%d\n", dist[s][d] + 1);
	}
	return 0;
}

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

int main(){
	string s,t;
	int a,b;
	string u;
	cin >> s >> t >> a >> b >> u;
	
	if(s == u){
		cout << a-1 << " " << b << endl;
	}else{
		cout << a << " " << b-1 << endl;
	}
	
	
    return 0;
}



Measured memory_bytes: 384
n = int(input())
st = list(map(int,input().split()))
st.sort(reverse = True)
count = 0

for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if (st[i] != st[j] != st[k]) and (st[i] < st[j] + st[k]):
        count += 1
        
print(count)


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

int dp[100009]; vector<int>vec;

int main() {
	int u1 = 1; for (int i = 0; i < 10; i++) { vec.push_back(u1); u1 *= 6; }
	int u2 = 1; for (int i = 0; i < 8; i++) { vec.push_back(u2); u2 *= 9; }

	for (int i = 0; i <= 100000; i++) dp[i] = 10000;
	dp[0] = 0;
	for (int i = 0; i <= 100000; i++) {
		for (int j : vec) {
			if (i + j <= 100000) dp[i + j] = min(dp[i + j], dp[i] + 1);
		}
	}
	int n; cin >> n;
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  int H,W,D;
  cin>>H>>W>>D;
  int a[H+1][W+1];
  map<int,pair<int,int>>mp;
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin>>a[i][j];
      mp[a[i][j]]=make_pair(i,j);
    }
  }
  int S[H*W+1];
  for(int i=1; i<=H*W; i++){
      S[i+D]=S[i]+(abs(mp[i+D].first-mp[i].first)+abs(mp[i+D].second-mp[i].second));
  }
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    int a,b;
    cin>>a>>b;
    cout<<S[b]-S[a]<<endl;
  }
}
  
  

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define endl "\n"
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define com(a, b) a ## b
#define scv(a, b, c) #a#b#c
#define db(x) cerr << "[" << #x << ": " << (x) << "] " << endl;
#define run cerr << 1 << endl; 
template<class T> void printvec(vector<T>& x, int a, int b) {foru (i, a, b) cout << x[i] << " "; cout << endl;}

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const ld PI = acos((ld) -1);
const ld EPS = 1e-6;
const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;
const int BASE = 10000;

ll Pow(ll a, int n) {
    if (!n) {
        return 1LL;
    }
    ll t = Pow(a, n / 2);
    t = t * t % MOD;
    if (n & 1) {
        t = t * a % MOD;
    }
    return t;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vll res(k + 1);
    ll ans = 0;
    for (int i = k; i; i--) {
        int t = k / i;
        ll tmp = Pow(t, n);
        // cout << t << " ";
        for (int j = i + i; j <= k; j += i) {
            tmp = (tmp + MOD - res[j]) % MOD;
        }
        ans = (ans + tmp * i) % MOD;
        res[i] = tmp; 
        // cout << tmp << " " << ans << endl;
    }
    cout << ans;
}

int main() {
    #ifdef DEBUG
        com(fre, open) (scv(solve, ., inp), "r", stdin);
        com(fre, open) (scv(solve, ., out), "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
} 

Measured memory_bytes: 3972
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            out.println(x + x * x + x * x * x);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }

}

Measured memory_bytes: 33912
#include <stdio.h>

int max (int a, int b) {
	return (a>b)?a:b;
}

int main () {
	int A, B, C;
	scanf ("%d %d %d", &A, &B, &C);
	int m = max(max (A,B),C);
	int sum = A+B+C;
	printf ("%d\n",((sum-m)%2)?((3*m+3-sum)/2):((3*m-sum)/2));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

ll N, M, V, P;
vector<ll> A;

bool isok(ll mididx){
  if(mididx <= P-1) return true;
  // 当該問題の最高スコア
  ll maxi = A[mididx]+M; if(maxi < A[P-1]) return false; //到達できないので
  ll V_ = V;// M人が残りV_ 問に投票
  V_--;// 自分には投票するので
  V_ -= (P-1); // 超上位には投票しておけばいいので
  V_ -= (N-mididx-1); // 下位のものにも投票してよいので
  if(V_<=0) return true; // 投票先残ってないならええやろ

  // V_問を残りM_回の投票
  ll counter = 0;
  // 投票先はA[P-1]からA[mididx-1]まで
  for(ll i=P-1; i<mididx; i++){
    counter += min(M, maxi-A[i]);
  }

  if(counter >= M*V_) return true;
  else return false;
}

ll binsch(){
  ll ngidx = N;
  ll okidx = P-1;
  while(abs(okidx-ngidx)>1){
    ll mididx = (okidx+ngidx)/2;
    if(isok(mididx)) okidx = mididx;
    else ngidx = mididx;
  }
  return okidx;
}

int main(){
  cin >> N >> M >> V >> P;
  A.resize(N); rep(i,N) cin >> A[i];
  sort(rall(A));
  cout << binsch()+1 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

ll dp[55][55][2600];

int main(void)
{
    int N,A;
    cin >> N >> A;
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    SORT(x);

    // vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(N+1, vector<ll>(N*x.back()+1)));

    dp[0][0][0] = 1;
    REP(k, N){
       REP(s, k+1){
            REP(t, N*A+1){
                if(dp[k][s][t]){
                    dp[k+1][s+1][t+x[k]] += dp[k][s][t];
                    dp[k+1][s][t] += dp[k][s][t];
                }
            }
       } 
    }

    ll ans = 0;
    Rep(k, N, N+1){
       Rep(s, 1, k+1){
           ans += dp[k][s][A*s];
       } 
    }
    pr(ans);
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int dp[45][405][405];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    rep(i, n + 1){
        rep(j, 405){
            rep(k, 405){
                dp[i][j][k] = IINF;
            }
        }
    }
    dp[0][0][0] = 0;
    REP(i, 1, n + 1){
        rep(j, 405){
            rep(k, 405){
                if(j >= a[i - 1] && k >= b[i - 1]){
                    dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - a[i - 1]][k - b[i - 1]] + c[i - 1]);
                }else{
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }
    int ans = IINF;
    int l = ma, m = mb;
    while(l < 405 && m < 405){
        ans = min(ans, dp[n][l][m]);
        l += ma;
        m += mb;
    }
    if(ans < IINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b;cin>>a>>b;
  if(a==1)a=14;
  if(b==1)b=14;
  if(a==b){
    cout<<"Draw"<<endl;
  }else if(a<b){
    cout<<"Bob"<<endl;
  }else{
    cout<<"Alice"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main() {
  vector<int> a(5);
  rep(i, 5) cin >> a[i];
  int k;
  cin >> k;
  if (a[4] - a[0] > k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]

cnt = 0

for i in range(n):
    value = c
    for j in range(m):
        value += a[i][j]*b[j]
    if value>0:
        cnt += 1

print(cnt)

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

void Main(){
    int n , k;
    cin >> n;
    cin >> k;
    int h[n];
    int ans = 0;
    rep(i,n){
        cin >> h[i];
        if(h[i] >= k) ans ++;
    }
    cout << ans << endl;
}
    
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    Main();
    return 0;
}

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

using namespace std;

#define LCM(a,b)                (a / __gcd(a,b) ) *b
#define GCD(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define LL                      long long
#define ULL                     unsigned long long
#define pb                      push_back
#define tcase                   cout<<"Case "<<C++<<": ";
#define all(a)                  a.begin(),a.end()
#define Unique(a)               sort(all(a)),a.erase(unique(all(a)),a.end
#define ABS(x)                  ((x)<0?-(x):(x))
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(a,min(b,min(c,d)))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(a,max(b,max(c,d)))
#define PI                      acos(-1.0)
#define ff                      first
#define ss                      second
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define FastRead                ios_base::sync_with_stdio(0);cin.tie(NULL);
#define FOR(x, l, r)            for (int x = l; x<=r; ++x)
#define REP(x,r)                for (int x = 0; x <r; ++x)
#define NN                      cout<<"\n";
#define NNN                     cout<<"\n------------------------------\n";

//***********************************************************************//
//                      SHAHED AHMED, CSE'15, IUT                        //
//***********************************************************************//



int main()
{
    string s;
    LL n;

    cin>>s;

    cin>>n;

    vector<LL> v;

    LL cnt=1;

    for(int i=1;i<s.size();i++)
    {
        if(s[i]!=s[i-1])
        {
            v.pb(cnt);
            cnt=1;
        }
        else cnt++;

    }

    v.pb(cnt);

    if(v.size()==1)
    {
        LL tot = v[0]*n;

        cout<<tot/2;
    }
    else
    {
        if(s.front()==s.back())
        {

            LL ans=0;

            ans+= v[0]/2;

            for(int i=1;i<v.size()-1;i++)
            {
                ans+=(v[i]/2)*n;
            }

            ans+=(v[v.size()-1]/2);

            ans+= ((v[v.size()-1] + v[0])/2)*(n-1);
            cout<<ans;
        }
        else
        {
            LL ans=0;
            for(auto u:v)
            {
                ans+=(u/2)*n;
            }
            cout<<ans;
        }

    }






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = 1e9 + 7;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	ll n, ans1 = 1, ans2  = 1, ans3 = 1;
	cin >> n;
	for(int i = 1; i <= n; i++) ans1 = (ans1*10)%mod;
	for(int i = 1; i <= n; i++) ans2 = (ans2*9)%mod;
	for(int i = 1; i <= n; i++) ans3 = (ans3*8)%mod;
	ans2 = (2*ans2 - ans3 + mod)%mod;
	cout << (ans1 - ans2 + mod)%mod;
}

Measured memory_bytes: 3640
'use strict';

const main = input => {
  input = input.split('\n');
  const n = Number(input[0]);
  const S = input[1].split(' ').map(Number);
  const T = input[3].split(' ').map(Number);
  console.log(
    T.reduce((acc, num) => (linerSearch(S, n, num) > -1 ? acc + 1 : acc), 0)
  );
};

function linerSearch(arr, len, key) {
  let i = 0;
  arr[len] = key;
  while (arr[i] !== key) {
    i += 1;
  }
  return i === len ? -1 : i;
}

// function linerSearch(arr, len, key) {
//   for (let i = 0; i < len; ++i) {
//     if (arr[i] === key) {
//       return i;
//     }
//   }
//   return -1;
// }

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

def swap(A, B):
    temp = A
    A = B
    B = temp
    return A, B
    
def main():
    X, Y, Z = map(int, input().rstrip().split())
    A = X
    B = Y
    C = Z
    A, B = swap(A, B)
    A, C = swap(A, C)
    print(" ".join(map(str, [A, B, C])))
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; 
  cin >> N;
  vector<long long> p(3*N);
  for(int i = 0; i < 3*N; i++){
    cin >> p[i];
  }
  sort(p.begin(),p.end());
  long long  ans = 0;
  for(int i = N; i < 3*N; i+= 2){
    ans+= p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
<?php
    $cnt = str_replace(array("\r" , "\r\n" , "\n") , "" , fgets(STDIN));
    $list = explode(" " , str_replace(array("\r" , "\r\n" , "\n") , "" , fgets(STDIN)));
    $res = 1;
    
    for ($i = 0; $i < intval($cnt); $i++) {
        if (intval($list[$i]) == 0) {
            $res = 0;
            break;
        }
        $res = $res * $list[$i];
    }
    
    if ($res > pow(10 , 18)) {
        echo(-1);
    } else {
        echo($res);
    }
  
 ?>

Measured memory_bytes: 25556
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll N;
ll M;
ll s;
ll c;
ll ans[4];
bool jud = true;

void solve() {
	cin >> N >> M;
	rep(i, 4) ans[i] = -1;
	rep(i, M) {
		cin >> s >> c;
		if (ans[s] != -1 && ans[s] != c) {
			jud = false;
		}
		ans[s] = c;
	}
	if (!jud) {
		cout << -1 << endl;
		return;
	}
	if (ans[1] == 0 && N != 1) {
		cout << -1 << endl;
		return;
	}
	if (N == 1) {
		if (ans[1] == -1) ans[1] = 0;
		cout << ans[1] << endl;
		return;
	}
	if (ans[1] == -1) ans[1] = 1;
	if (ans[2] == -1) ans[2] = 0;
	if (ans[3] == -1) ans[3] = 0;
	rep(i, N) cout << ans[i + 1];
	cout << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 256
N,C = map(int,input().split())

data = [[0]*(10**5+1) for i in range(C)]

for i in range(N):
    s,t,c = map(int,input().split())
    c -= 1
    for i in range(s,t+1):
        data[c][i] = 1

ans = 0

for i in range(1,10**5+1):
    count = 0
    for j in range(C):
        count += data[j][i]
    ans = max(ans,count) 

print(ans)

Measured memory_bytes: 69976
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

const ll inf=(1LL<<40);
int N,t[110],v[110]; ld dp[20010][110]; ll mxv[20010];

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

    int i,j;
    for (i=1; i<=N; i++)
        cin >> t[i];

    for (i=1; i<=N; i++)
        cin >> v[i];

    int s=0;
    for (i=1; i<=N; i++){
        for (j=s; j<s+t[i]; j++)
            mxv[j]=v[i];

        s+=t[i];
    }


    for (i=1; i<=102; i++)
        dp[s][i]=-inf;

    for (i=s-1; i>=0; i--){
        for (j=0; j<=102; j++){
            dp[i][j]=-inf;
            if (j>mxv[i]) continue;

            dp[i][j]=max(dp[i][j],j+dp[i+1][j]);
            if (j>0) dp[i][j]=max(dp[i][j],j-1+0.5+dp[i+1][j-1]);
            if (j<mxv[i]) dp[i][j]=max(dp[i][j],j+0.25+dp[i+1][j]);
            if (j<mxv[i]) dp[i][j]=max(dp[i][j],j+0.5+dp[i+1][j+1]);
        }
    }

    cout << fixed << setprecision(10) << dp[0][0] << "\n";
	return 0;
}


Measured memory_bytes: 34816
<?php

$in = trim(fgets(STDIN));
$words = preg_split("/[\s,\. ]+/", $in);

$cnt = count($words);
for ($i=0; $i < $cnt; $i++) {
    $num = strlen($words[$i]);
    if ($num < 3 or 6 < $num) {
        unset($words[$i]);
    }
}
array_values($words);
echo implode(" ", $words) . "\n";

Measured memory_bytes: 15368
use std::io;
use std::cmp;


fn main() {
    let (x, y) = {
        let i = read::<isize>();
        (i[0], i[1])
    };

    let mut ans = 10_000_000_000_000;

    for s in 0..2 { for t in 0..2 {
        let mut cnt = 0;
        let mut _x = x;
        let mut _y = y;
        if s > 0 { _x = -x; cnt += 1; }
        if t > 0 { _y = -y; cnt += 1; }
        if _x <= _y {
            cnt += _y - _x;
        } else { continue; }

        ans = cmp::min(ans, cnt);
    }}

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


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

class P {
	public:
		int x;
		int y;
		P(int x, int y) :x(x),y(y) {}
};

char map[20][20];

int bfs(int W, int H) {
	queue<P> q;
	bool ch[H][W];
	for (int i=0; i<H; i++)
	for (int j=0; j<W; j++)
		ch[i][j] = false;
	for (int i=0; i<H; i++)
	for (int j=0; j<W; j++)
		if (map[i][j] == '@') {
			q.push(P(j,i));
			ch[i][j] = true;
			break;
		}
	while(!q.empty()) {
		P c = q.front();
		q.pop();
		if (c.x+1<W && (!ch[c.y][c.x+1]) && map[c.y][c.x+1]=='.')
		{ q.push(P(c.x+1, c.y)); ch[c.y][c.x+1]=true; }
		if (c.y+1<H && (!ch[c.y+1][c.x]) && map[c.y+1][c.x]=='.')
		{ q.push(P(c.x, c.y+1)); ch[c.y+1][c.x]=true; }
		if (c.x-1>=0 && (!ch[c.y][c.x-1]) && map[c.y][c.x-1]=='.')
		{ q.push(P(c.x-1, c.y)); ch[c.y][c.x-1]=true; }
		if (c.y-1>=0 && (!ch[c.y-1][c.x]) && map[c.y-1][c.x]=='.')
		{ q.push(P(c.x, c.y-1)); ch[c.y-1][c.x]=true; }
	}
	int cnt = 0;
	for (int i=0; i<H; i++)
	for (int j=0; j<W; j++)
		if (ch[i][j]) cnt++;
	return cnt;
}

int main() {
	int n, m;
	while (cin >> n >> m, (n||m)) {
		for (int i=0; i<m; i++)
		for (int j=0; j<n; j++)
			cin >> map[i][j];
		int res = bfs(n, m);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int q = sc.nextInt();
		TreeSet<Long> shrines = new TreeSet<>();
		shrines.add(Long.MAX_VALUE / 10);
		shrines.add(Long.MIN_VALUE / 10);
		for (int i = 0; i < a; i++) {
		    shrines.add(sc.nextLong());
		}
		TreeSet<Long> temples = new TreeSet<>();
		temples.add(Long.MAX_VALUE / 10);
		temples.add(Long.MIN_VALUE / 10);
		for (int i = 0; i < b; i++) {
		    temples.add(sc.nextLong());
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    long min = Long.MAX_VALUE;
		    long x = sc.nextLong();
		    long befS = shrines.floor(x);
		    min = Math.min(min, Math.abs(befS - temples.floor(befS)) + Math.abs(x - befS));
		    min = Math.min(min, Math.abs(befS - temples.ceiling(befS)) + Math.abs(x - befS));
		    long afS = shrines.ceiling(x);
		    min = Math.min(min, Math.abs(afS - temples.floor(afS)) + Math.abs(x - afS));
		    min = Math.min(min, Math.abs(afS - temples.ceiling(afS)) + Math.abs(x - afS));
		    long befT = temples.floor(x);
		    min = Math.min(min, Math.abs(befT - shrines.floor(befT)) + Math.abs(x - befT));
		    min = Math.min(min, Math.abs(befT - shrines.ceiling(befT)) + Math.abs(x - befT));
		    long afT = temples.ceiling(x);
		    min = Math.min(min, Math.abs(afT - shrines.floor(afT)) + Math.abs(x - afT));
		    min = Math.min(min, Math.abs(afT - shrines.ceiling(afT)) + Math.abs(x - afT));
		    sb.append(min).append("\n");
		}
	    System.out.print(sb);
   }
}




Measured memory_bytes: 111456
#include <bits/stdc++.h>
using namespace std;
long long int h,n;
long long int f[2000005];
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	f[0]=0;	
	for(int i=1;i<=2000000;i++){
		f[i]=0x7ffffffffffffff;
	}
	cin>>h>>n;
	long long int a[n+1],b[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	for(int j=1;j<=n;j++){
		for(int i=a[j];i<=20000;i++){
			f[i]=min(f[i-a[j]]+b[j],f[i]);
		}
	}
	long long int minv=0x7ffffffffffffff;
	for(int i=h;i<=20000;i++){
		if(f[i]<minv){
			minv=f[i];
		}
	}
	cout<<minv;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int N = S.size();
    cout << S[0] << N - 2 << S[N - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b)>(c+d)){
  cout << "Left";
  }
  else if((a+b)==(c+d)){
  cout << "Balanced";
  }
  else{
  cout << "Right";
  }
}

Measured memory_bytes: 256
#include<stdio.h>

void insertionSort(int A[],int N){
  int i,v,j,r;
  for(r=0;r<N;r++){
      if(r==N-1){
	printf("%d\n",A[r]);
      }
      else{
	printf("%d ",A[r]);
      }
    }
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(r=0;r<N;r++){
      if(r==N-1){
	printf("%d\n",A[r]);
      }
      else{
	printf("%d ",A[r]);
      }
    }
  }
}
  

int main(void){
  int i,n;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  insertionSort(a,n);
  return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int ans = 0;
	rep(i, 0, 3001){
		if(r*i > n) break;
		rep(j, 0, 3001){
			int t = r*i + g*j;
			if(t > n) break;
			if((n-t)%b == 0){
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
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[] L = new int[n];
        for(int i=0;i<n;i++){
            L[i] = sc.nextInt();
        }
        Arrays.sort(L);
//        for(int i=0;i<L.length;i++){
//            System.out.print(" "+L[i]);
//        }
        int count = 0;
        for(int i=0;i<n-2;i++){
           for(int j=i+1;j<n-1;j++){
               if(L[i]==L[j]){
                   continue;
               }
               for(int k=j+1;k<n;k++){
                   if(L[j]==L[k]){
                       continue;
                   }
                   if(checkTriangle(L[i],L[j],L[k])){
                       count++;
                   }
               }
           }
        }
        System.out.println(count);
    }
    static boolean checkTriangle(int a,int b,int c){
        return Math.abs(b-a) < c && c < a+b;
    }
}

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

class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int c = int.Parse(input[2]);
        // 文字列の入力
        //string s = Console.ReadLine();
        int sum = 0;
		//出力
        for(int i = a; i < (c + 0.5); i+= a)
        {
            sum += b;
        }
		Console.WriteLine(sum);
        //var list = new List<int>();
		
	}
}

Measured memory_bytes: 11092
#include <stdio.h>

int main()
{
	int i, N, a[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int j, k, num[3] = {}, count[3] = {};
	for (i = 1, k = 0; i <= N; i++) {
		for (j = 0; j < k; j++) if (a[i] == num[j]) break;
		if (j == k) {
			if (k == 2) break;
			else {
				num[k] = a[i];
				count[k++] = 1;
			}
		} else count[j]++;
	}
	
	if (i <= N) printf("No\n");
	else if (k == 1) {
		if (num[0] == N - 1 || num[0] <= N / 2) printf("Yes\n");
		else printf("No\n");
	} else if (num[0] < num[1] - 1 || num[0] > num[1] + 1) printf("No\n");
	else {
		if (num[0] > num[1]) {
			num[0]--;
			num[1]++;
			count[0] += count[1];
			count[1] = count[0] - count[1];
			count[0] -= count[1];
		}
		if (count[0] > num[0] || count[1] < (num[1] - count[0]) * 2) printf("No\n");
		else printf("Yes\n");
	}
	fflush(stdout);
	return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> in(n);
    for(int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        g[x - 1].push_back(y - 1);
        in[y - 1]++;
    }

    vector<int> ord;
    vector<bool> vis(n);
    for(int i = 0; i < n; ++i) {
        if(in[i] != 0) continue;
        function<void(int)> dfs = [&] (int v) {
            vis[v] = true;
            for(auto to : g[v]) {
                if(vis[to]) continue;
                dfs(to);
            }
            ord.push_back(v);
        };
        dfs(i);
    }
    reverse(begin(ord), end(ord));

    vector<int> dp(n);
    for(int i = 0; i < n; ++i) {
        const int v = ord[i];
        for(auto to : g[v]) {
            dp[to] = max(dp[to], dp[v] + 1);
        }
    }

    cout << *max_element(begin(dp), end(dp)) << endl;
}


Measured memory_bytes: 11768
#include<stdio.h>

int main(void){

    //A:解毒剤入りのおいしくないクッキー
    //B:解毒剤入りの美味しいクッキー
    //C:毒入りの美味しいクッキー
    int A,B,C,result;
    
    scanf("%d %d %d",&A,&B,&C);

    if(A + B + 1 >= C){
        result = B + C;
    }else{
        result = A + 2 * B + 1;
    }

    printf("%d",result);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);
    	int a=sc.nextInt();
    	int b=sc.nextInt();

    	int diff=b-a-1;

    	int highta=diff*(diff+1)/2;

    	int x=highta-a;

    	System.out.println(x);
    }
}



Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const int N=10005;
char s[N];
int main()
{
	int anum=0,cnum=0,cnt=0,sum=0;
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(s[1]!='A') printf("WA");
	else
	{
		//cout<<s<<endl;
		for(int i=1;i<=len;i++)
		{
			if(s[i]=='A') anum++;
			if(s[i]=='C')
			{
				cnum++;
				if(i>=3&&i<len) cnt++;
			}
			if(s[i]>='A'&&s[i]<='Z') ++sum;
		}
		if(anum==1&&cnum==1&&cnt==1&&sum==2) printf("AC");
		else printf("WA");
	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] ary = new int[3];
		int res;
		
		for(int i=0; i<ary.length; i++) {
			ary[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(ary);
		
		res = Math.abs(ary[0] - ary[1]);
		res += Math.abs(ary[1] - ary[2]);
		
		System.out.println(res);
	}

}

Measured memory_bytes: 21716