akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

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

const int MAXN = 1050;

int n;
vector <int> g[MAXN];
int need[MAXN];
int dp[MAXN];
int dp2[5 * MAXN];

int calc(int v) {
  if (dp[v] != -1) {
    return dp[v];
  }

  int totalSum = 0;
  for (int to : g[v]) {
    totalSum += calc(to) + need[to];
  }

  for (int i = 0; i <= need[v]; i++) {
    dp2[i] = -1;
  }
  dp2[0] = 0;

  int cnt = 0;
  for (int to : g[v]) {
    int a = dp[to], b = need[to];
    for (int i = need[v]; i >= 0; i--) {
      if ((i - a >= 0 && dp2[i - a] == cnt) || (i - b >= 0 && dp2[i - b] == cnt)) {
        dp2[i] = cnt + 1;
      }
    }
    cnt++;
  }
  int mx = -1;
  for (int i = 0; i <= need[v]; i++) {
    if (dp2[i] == cnt) {
      mx = i;
    }
  }
  if (mx == -1) {
    puts("IMPOSSIBLE");
    exit(0);
  }

  dp[v] = totalSum - mx;
  return dp[v];
}

int main() { 

  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    g[p].push_back(i);
  }

  for (int i = 0; i < n; i++) {
    scanf("%d", &need[i]);
  }

  memset(dp, -1, sizeof(dp));
  calc(0);

  puts("POSSIBLE");

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int 
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LL n;cin>>n;
      LL x=n/1000;
      if(n%1000!=0) x++;
      x*=1000;
      cout<<x-n;
    }
    return 0;
}

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

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

// namespace utils
namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    rep (i, mat.size()) {
      rep (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    rep (i, v.size()) cout << v[i] << ' ';
    cout << endl;
  }
// end namespace utils
}


string int2mcxi(int n) {
  string res = "";

  vector<int> base = {1000, 100, 10, 1};
  vector<string> sur = {"m", "c", "x", "i"};

  rep (i, 4) {
    int k = n / base[i];

    if (k > 0) {
    res += k == 1 ? sur[i] : to_string(k) + sur[i];
    }

    n -= (n / base[i]) * base[i];
  }

  return res;
}

int mcxi2int(string mcxi) {
  int res = 0;
  string prfx;

  rep (k, mcxi.size()) {
    if (mcxi[k] == 'm') {
      res += prfx == "" ? 1000 : 1000 * stoi(prfx);
      prfx = "";
    }
    else if (mcxi[k] == 'c') {
      res += prfx == "" ? 100 : 100 * stoi(prfx);
      prfx = "";
    }
    else if (mcxi[k] == 'x') {
      res += prfx == "" ? 10 : 10 * stoi(prfx);
      prfx = "";
    }
    else if (mcxi[k] == 'i') {
      res += prfx == "" ? 1 : 1 * stoi(prfx);
      prfx = "";
    }
    else {
      prfx += mcxi[k];
    }
  }
  return res;
}


int main() {

  int n;
  cin >> n;

  rep (_, n) {
    string ans_mcxi;
    string mcxi;

    int ans_int = 0;
    cin >> mcxi;
    ans_int += mcxi2int(mcxi);

    cin >> mcxi;
    ans_int += mcxi2int(mcxi);

    ans_mcxi = int2mcxi(ans_int);
    cout << ans_mcxi << endl;
  }
}

Measured memory_bytes: 3124
#include<stdio.h>
#include<vector>
using namespace std;

#define NMAX 200005

vector<int> graph1[NMAX], graph2[NMAX];
int n, k, l, num_groups;
int f[NMAX], viz[NMAX], viz2[NMAX], answer[NMAX];
int pula[NMAX], nrp;

inline void dfs1(int node){
    if(viz[node])
        return ;
    viz[node] = num_groups;
    int lim = graph1[node].size();
    for(int i = 0; i < lim; i++)
        dfs1(graph1[node][i]);
}

inline void dfs2(int node){
    if(viz2[node])
        return ;
    viz2[node] = 1;
    f[viz[node]]++;
    pula[++nrp] = node;
    int lim = graph2[node].size();
    for(int i = 0; i < lim; i++)
        dfs2(graph2[node][i]);
}

inline void dfs3(int node){
    if(viz2[node] == 2)
        return ;
    viz2[node] = 2;
    answer[node] = f[viz[node]];
    int lim = graph2[node].size();
    for(int i = 0; i < lim; i++)
        dfs3(graph2[node][i]);
}

inline void dfs_clear(int node){
    if(!viz2[node])
        return ;
    f[viz[node]]--;
    viz2[node] = 0;
    int lim = graph2[node].size();
    for(int i = 0; i < lim; i++)
        dfs_clear(graph2[node][i]);
}


int main () {
    int a, b;
    
    scanf("%d%d%d",&n,&k,&l);
    for(int i = 1; i <= k; i++){
        scanf("%d%d",&a,&b);
        graph1[a].push_back(b);
        graph1[b].push_back(a);
    }
    
    for(int i = 1; i <= n; i++)
        if(!viz[i]){
            ++num_groups;
            dfs1(i);
        }
    //for(int i = 1; i <= n; i++)
     //   printf("%d ", viz[i]);
    //printf("\n");
        
    for(int i = 1; i <= l; i++){
        scanf("%d%d",&a,&b);
        graph2[a].push_back(b);
        graph2[b].push_back(a);
    }
    
    for(int i = 1; i <= n; i++)
        if(!viz2[i]){
            nrp = 0;
            dfs2(i);
            for(int j = 1; j <= nrp; j++){
                answer[pula[j]] = f[viz[pula[j]]];
            }
            for(int j = 1; j <= nrp; j++)
                f[viz[pula[j]]] = 0;
        }
        
    for(int i = 1; i <= n; i++)
        printf("%d ", answer[i]);
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 19200
$nodes = []

def insert(k)
  $nodes.push(k)
  heapIncreaseKey($nodes.length)
end

def heapIncreaseKey(idx)
  parent = idx / 2
  if parent.positive? && $nodes[parent - 1] < $nodes[idx - 1]
    $nodes[parent - 1], $nodes[idx - 1] = $nodes[idx - 1], $nodes[parent - 1]
    heapIncreaseKey(parent)
  end
end

def maxHeapify(i)
  left = i * 2
  right = i * 2 + 1
  max = i
  max = left if left <= $nodes.length && $nodes[max - 1] < $nodes[left - 1]
  max = right if right <= $nodes.length && $nodes[max - 1] < $nodes[right - 1]

  if max != i
    $nodes[i - 1], $nodes[max - 1] = $nodes[max - 1], $nodes[i - 1]
    maxHeapify(max)
  end
end

def extractMax()
  max = $nodes[0]
  $nodes[0], $nodes[-1] = $nodes[-1], $nodes[0]
  $nodes.pop
  maxHeapify(1)
  return max
end

def main
  while !(ins = gets.split)[0].eql?('end')
    if ins[0] == 'insert'
      insert(ins[1].to_i)
    else
      puts extractMax()
    end
  end
end

main



Measured memory_bytes: 14776
n = int(input())
count = 0
ans = []
for i in range(n):
  s = sorted(list(input()))
  ans.append(s)
ans.sort()
x = 0
for i in range(n-1):
  if ans[i] == ans[i+1]:
    x += 1
  else:
    count += x*(x+1)//2
    x = 0
count += x*(x+1)//2
print(count)

Measured memory_bytes: 24652
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const ll INF=1e18;

int main(){
    int n,a;cin>>n>>a;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    ll dp[n+1][n+1][50*n+1];
    for(int i=0;i<=n;i++){
        for(int k=0;k<=n;k++){
            for(int s=0;s<=50*n;s++){
                dp[i][k][s]=0;
            }
        }
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int k=0;k<=n;k++){
            for(int s=0;s<=50*n;s++){
                dp[i+1][k][s]=dp[i][k][s];
                if(k>0&&s>=x[i]) dp[i+1][k][s]+=dp[i][k-1][s-x[i]];
            }
        }
    }
    ll sum=0;
  for(int k=1;k<=n;k++){
    sum+=dp[n][k][k*a];
  }
    cout<<sum<<endl;
    return 0;
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

vector<int> ans;
void solve(int n, int p, int a, int b){
	if(n==1){
		ans.push_back(p|a);
		ans.push_back(p|b);
		return;
	}
	n--;

	int pa = a&(1<<n);
	int pb = b&(1<<n);
	int qa = a&((1<<n)-1);
	int qb = b&((1<<n)-1);

	if(pa==pb){
		solve(n, p|pa, qa, qb);
		ans.pop_back();
		int rb = ans.back();
		solve(n, p|(pa^(1<<n)), rb&((1<<n)-1), qb);
		ans.push_back(p|b);
	} else {
		solve(n, p|pa, qa, qa^1);
		solve(n, p|pb, qa^1, qb);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n, a, b;
	cin >> n >> a >> b;

	int s=0;
	for(int k=0; k<n; k++){
		s+=(a>>k&1)^(b>>k&1);
	}
	if(s%2==0){
		cout << "NO" << endl;
		return 0;
	}

	solve(n, 0, a, b);

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


Measured memory_bytes: 3892
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();

		ArrayList<Integer> sList = new ArrayList<Integer>();
		ArrayList<Integer> hList = new ArrayList<Integer>();
		ArrayList<Integer> cList = new ArrayList<Integer>();
		ArrayList<Integer> dList = new ArrayList<Integer>();

		for(int i = 0;i < count;i++ ) {

			String mark = sc.next();
			int num = sc.nextInt();

			if(mark.equals("S")) {
				sList.add(num);
			} else if(mark.equals("H")) {
				hList.add(num);
			} else if(mark.equals("C")) {
				cList.add(num);
			} else if(mark.equals("D")) {
				dList.add(num);
			}
		}

		for(int i = 0;i < sList.size() - 1; i++) {
			for(int j = 0;j < sList.size() - 1; j++) {
				if(sList.get(j) > sList.get(j + 1)) {
					int x = sList.get(j);
					sList.set(j, sList.get(j + 1));
					sList.set(j +1, x);
				}
			}

		}
		for(int i = 0;i < hList.size() - 1; i++) {
			for(int j = 0;j < hList.size() - 1; j++) {
				if(hList.get(j) > hList.get(j + 1)) {
					int x = hList.get(j);
					hList.set(j, hList.get(j + 1));
					hList.set(j +1, x);
				}
			}

		}
		for(int i = 0;i < cList.size() - 1; i++) {
			for(int j = 0;j < cList.size() - 1; j++) {
				if(cList.get(j) > cList.get(j + 1)) {
					int x = cList.get(j);
					cList.set(j, cList.get(j + 1));
					cList.set(j +1, x);
				}
			}

		}
		for(int i = 0;i < dList.size() - 1; i++) {
			for(int j = 0;j < dList.size() - 1; j++) {
				if(dList.get(j) > dList.get(j + 1)) {
					int x = dList.get(j);
					dList.set(j, dList.get(j + 1));
					dList.set(j +1, x);
				}
			}

		}


		int numCount;
		for(int i = 1;i <= 13; i++) {
			numCount = 0;
			for(int j = 0;j < sList.size(); j++) {
				if(sList.get(j) == i) {
					numCount++;
				}
			}
			if(numCount == 0){
				System.out.println("S " + i);
			}


		}
		for(int i = 1;i <= 13; i++) {
			numCount = 0;
			for(int j = 0;j < hList.size(); j++) {
				if(hList.get(j) == i) {
					numCount++;
				}
			}
			if(numCount == 0){
				System.out.println("H " + i);
			}


		}
		for(int i = 1;i <= 13; i++) {
			numCount = 0;
			for(int j = 0;j < cList.size(); j++) {
				if(cList.get(j) == i) {
					numCount++;
				}
			}
			if(numCount == 0){
				System.out.println("C " + i);
			}
		}
		for(int i = 1;i <= 13; i++) {
			numCount = 0;
			for(int j = 0;j < dList.size(); j++) {
				if(dList.get(j) == i) {
					numCount++;
				}
			}
			if(numCount == 0){
				System.out.println("D " + i);
			}
		}


	}

}

Measured memory_bytes: 26136
n = gets.chomp

if n.to_i < 9
  puts n
else
  n = n.chars.map(&:to_i)
  first = n.first.to_i
  d = n.size

  max = [first, "9" * (d - 1)].join
  puts n.join < max ? 9 * (d - 1) + (first - 1) : n.inject(:+)
end


Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

string s;

int main(){
	cin>>s;
	if (s.length()==6){
		if (s[2]==s[3]&&s[4]==s[5]) {
			cout<<"Yes"<<endl;
			return 0;
		}
		
	}
	cout<<"No"<<endl;
	return 0; 
} 

Measured memory_bytes: 3604
#include <stdio.h>
#define MAX 300000
int main(){
    int N;
    char S[MAX+1];
    int anwx=0;
    int anwy=0;
    int ANW=0;
    scanf("%d",&N);
    scanf("%s",S);
    for(int i=1;i<N;i++) if(S[i]!='W') anwy++;
    for(int i=0;i<N;i++){
        if(i!=0) {
        if(S[i-1]!='E') anwx++;
        if(S[i]!='W') anwy--;
        }
        if(i==0) ANW=anwx+anwy;
        if(ANW>anwx+anwy) ANW=anwx+anwy;
    }
    printf("%d",ANW);
}

Measured memory_bytes: 512
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  d1=x-ls[i1-1]
  d2=ls[i1]-x
  d3=x-lg[i2-1]
  d4=lg[i2]-x
  d5=abs(ls[i1-1]-lg[i2-1])
  d6=abs(ls[i1]-lg[i2-1])
  d7=abs(ls[i1-1]-lg[i2])
  d8=abs(ls[i1]-lg[i2])
  ans1=d1+d5
  ans2=d1+d7
  ans3=d2+d6
  ans4=d2+d8
  ans5=d3+d5
  ans6=d3+d6
  ans7=d4+d7
  ans8=d4+d8
  print(min(ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8))
  
  

Measured memory_bytes: 12052
#include<bits/stdc++.h>
using namespace std;
int h,w,k,col[10],row[10],cnt,ans;
string c[10];
int main(){
  cin>>h>>w>>k;
  for(int i=0;i<h;i++) cin>>c[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(c[i][j]=='#'){
        row[i]++;
        col[j]++;
        cnt++;
      }
    }
  }
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      int x=0;
      for(int k=0;k<h;k++){
        if(i&(1<<k)) x+=row[k];
      }
      for(int l=0;l<w;l++){
        if(j&(1<<l)) x+=col[l];
      }
      for(int k=0;k<h;k++){
        for(int l=0;l<w;l++){
          if(i&(1<<k) && j&(1<<l) && c[k][l]=='#') x--;
        }
      }
      if(cnt-x==k) ans++;
    }
  }
  cout<<ans;
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll mx = -1;
  REP(i, n) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }

  ll cnt = 0;
  while (mx > 0) {
    cnt++;
    mx /= 2;
  }

  vector<map<ll, ll>> mp(1000);

  REP(j, n) {
    ll tmp = 0;
    REP(i, cnt) {
      ll b = a[j] % 2;
      mp[i][b]++;
      a[j] /= 2;
      tmp++;
    }
  }

  ll ans = 0;
  ll next = 0;
  ll i = 0;
  while (true) {
    ll c = mp[i][0] * mp[i][1];

    ans += mod_pow(2, i, MOD) * ((next + c) % 2);

    ans %= MOD;
    next = (next + c) / 2;
    if (next == 0) break;
    i++;
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;

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

    int ans=0;
    int n;
    string s;
    cin >> n >>  s;
    for(int i = 0;i <= n-3;++i){
        if(s.at(i) == 'A'&&s.at(i+1) == 'B'&&s.at(i+2) == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;

void PUNKS_NOT_DEAD() {
    int n, m;
    cin >> n >> m;
    cout << (m == n ? "Yes" : "No");
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0);
    PUNKS_NOT_DEAD();
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int d,t,s;
		String ans;
		String str;
		String[] sa;
		str = bf.readLine();
		sa = str.split(" ");
		d = Integer.parseInt(sa[0]);
		t = Integer.parseInt(sa[1]);
		s = Integer.parseInt(sa[2]);
		if(d <= t*s) {
			ans = "Yes";
		} else {
			ans = "No";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 32640
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int N = fs.nextInt();
		int M = fs.nextInt();
		int A[] = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = fs.nextInt();
		}

		int total = Arrays.stream(A).sum();
		double x =  total * (1.0 / (4.0 * M)) ;

		int count = 0;
		Arrays.sort(A);
		for(int i = 0; i < N; i++) {
			if(A[i] < x) {
				count++;
				if(count > N - M) {
					System.out.println("No");
					break;
				}
			}
		}
		if(count <= N - M)
			System.out.println("Yes");

	}

}


Measured memory_bytes: 27988
#include<stdio.h>
int main()
{
    int k,s,i,j,count = 0;
    scanf("%d %d",&k,&s);
    for(i = 0; i<= k ; i++){
        for(j = 0 ;j<=k ;j++){
            if(s - i - j>=0 && s - i -j<=k)
             count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
s = input()
st1=[]
st2=[]
st3=[]
n=len(s)
lv = 0
for i in range(n):
	c=s[i]
	if c=='\\':
		lv-=1
		st1.append(i)
	elif c=='/':
		lv+=1
		if len(st1) > 0:
			a = i - st1.pop()
			t=0	
			while len(st2)>0 and st2[-1]<lv:
				st2.pop()
				t+=st3.pop()
			st3.append(a+t)		
			st2.append(lv)
		elif len(st2) > 0:
				st2.pop()
				st2.append(lv)
				
st=''
total=0
n = len(st3)
st+=str(n)
for i in range(n):
	st+=' '+str(st3[i])
	total+=(st3[i])
print(total)
print(st)



Measured memory_bytes: 6120
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){
    char c;
    while(1){
        scanf("%c",&c);
        if(c=='\n')break;
        if(islower(c)) printf("%c",toupper(c));
        else if(isupper(c)) printf("%c",tolower(c));
        else printf("%c",c);
    }
    printf("\n");
    return(0);
}



Measured memory_bytes: 2044
#include<iostream>
#include<string>
using namespace std;
int main () {
  string w;
  char l[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
		'o','p','q','r','s','t','u','v','w','x','y','z'};
  cin >> w;
  int lng = w.length();
  int i,j;
  bool pass;
  for(j=0;j<26;++j){
    pass = true;;
    for(i=0;i<lng;++i){
      if(w[i]==l[j]){
	pass=!pass;
      }
    }
    if(!pass){
      break;
    }
  }
  cout << (pass?"Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define  ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define vii vector<pair<int,int> >
#define pb push_back
#define inf 1000000007
#define f(i,a,b) for(i=a;i<b;i++)

using namespace std;
bool cmp(string &a,string &b)
{
	if(a.size()==b.size())return a<b;
	return a.size()<b.size();
}

int main()
{ 
 string s;
 cin>>s;
 ll n,sm=0,i;
 n=s.size();
 
 f(i,0,n)
 {
     sm+=(s[i]-'0');
 }
 if(sm%9==0)cout<<"Yes";
 else cout<<"No";
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n,m,q;
    cin >> n >> m >> q;
    std::vector<std::vector<int>> ma(501,std::vector<int>(501,0));
    std::vector<std::vector<int>> su(501,std::vector<int>(501,0));
    
    for(int i = 0; i < m; i++){
        int l,r;
        cin >> l >> r;
        ma[l][r]++;
    }
    for(int i = 1; i < 501; i++){
        for(int j = 1; j < 501; j++){
            su[i][j] = ma[i][j] + su[i][j - 1];
        }
    }
    for(int i = 1; i < 501; i++){
        for(int j = 1; j < 501; j++){
            su[i][j] += su[i - 1][j];
        }
    }
    for(int i = 0; i < q; i++){
        int x,y;
        cin >> x >> y;
        cout << su[y][y] - su[x - 1][y] - su[y][x - 1] + su[x - 1][x - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4864
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

long long a,b,x;

int main()
{
	//fuckfuck
	cin>>a>>b>>x;
	long long ans=(b/x)-(a%x?a/x:a/x-1);
	printf("%lld\n",ans);
}

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

using namespace std;

const int MOD=1000000007;
typedef long long ll;
ll n,mi,ma,h[100001];

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}

ll pot(ll n,ll k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

ll divide(ll a,ll b)
{
	return mult(a,pot(b,MOD-2));
}

ll sub(ll a,ll b)
{
	return (a-b+MOD)%MOD;
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>h[i];
	}
	mi=2;
	ma=2;
	for (int i=n-1;i>=0;--i)
	{
		ll mip=(mi+h[i]-1)/h[i],map=ma/h[i];
		if (mip*h[i]>ma || map*h[i]<mi)
		{
			cout<<-1<<endl;
			return 0;
		}
		mi=mip*h[i];
		ma=map*h[i]+h[i]-1;
		if (!i) cout<<mi<<' '<<ma<<endl;
	}
}



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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=3030,mod=1e9+7;
string s;
ll dp[N][N],pref[N][N];
int n;

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>s;
	for(int i=1;i<=n;++i)pref[1][i]=1;
	dp[1][1]=1;
	for(int len=2;len<=n;++len){
		for(int newlast=1;newlast<=len;++newlast){
			int l,r;
			if(s[len-2]=='<'){
				l=0;r=newlast-1;
			}
			else{
				l=newlast-1;r=n;
			}
			dp[len][newlast]=(mod+pref[len-1][r]-pref[len-1][l])%mod;
		}
		for(int i=1;i<=n;++i)pref[len][i]=(dp[len][i]+pref[len][i-1])%mod;
	}
	cout<<pref[n][n]<<endl;
}


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

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        double n = Double.parseDouble(br.readLine());
        double count = 0;
        
        for(int i = 1; i <= n; i++){
            if(i % 2 != 0){
                count++;
            }
        }
         
        out.println(count / n);
        out.close();
        
    }
}

Measured memory_bytes: 33152
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
#include<map>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int h, w;
	bool white = true;
	cin >> h >> w;
	char a[101][101];
	for (int i = 0; i < h; i++) {
		white = true;
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
			if (a[i][j] == '#') white = false;
		}
		if (white == true)
			for (int j = 0; j < w; j++) a[i][j] = 'n';
	}


	for (int i = 0; i < w; i++) {
		white = true;
		for (int j = 0; j < h; j++)
		{
			
			if (a[j][i] == '#') white = false;
		}
		if (white == true)
			for (int j = 0; j < h; j++) a[j][i] = 'n';
	}

	for (int i = 0; i < h; i++) {
		white = true;
		for (int j = 0; j < w; j++)
		{
			if (a[i][j] == '#') white = false;
			if (a[i][j] != 'n') cout << a[i][j];
		}
		if(white==false) cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
fun c110(args: Array<String>) {
    var mapA = mutableMapOf<Char, Int>()
    args[0].forEach {
        if (!mapA.containsKey(it)) {
            mapA.put(it, 0)
        }
        mapA.put(it, mapA.get(it)!! + 1)
    }

    var mapB = mutableMapOf<Char, Int>()
    args[1].forEach {
        if (!mapB.containsKey(it)) {
            mapB.put(it, 0)
        }
        mapB.put(it, mapB.get(it)!! + 1)
    }

    println(if (mapA.values.sorted() == mapB.values.sorted()) "Yes" else "No")
}

fun main(args: Array<String>) {
    c110(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("transposition-115.txt","r",stdin)
#define OUT freopen("dichromatic.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define SZ(v) ((int)v.size())
#define sq(x)  ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

#define maxn 1000005
#define mod 1000000007LL

using namespace std ;

int yes[maxn] , h[maxn] , player[maxn] ;
int ans[maxn] ;

int main()
{
    int n ;
    scanf("%d",&n) ;

    printf("%d\n", n*180 - 360 ) ;

    return 0 ;
}


Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	long long n;
	cin >> n;
	long long r = sqrt(n);
	cout << r*r;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int main(){
    string s,t,c,u;
    cin >> s >> t;
    c=s;
    u=s;
    int v=t.length()-1;
    for(int i=s.length()-1;i>=0;i--){
        if(s[i]!=t[v]&&s[i]=='?'){
            s[i]=t[v];
        }
        else if(s[i]!=t[v]&&s[i]!='?'){
            v=t.length()-1;
        }
        if(s[i]==t[v]) v--;
        if(v<0) v=t.length()-1;
    }
    v=0;
    for(int i=0;i<u.length();i++){
        if(u[i]!=t[v]&&u[i]=='?'){
            u[i]=t[v];
        }
        else if(u[i]!=t[v]&&u[i]!='?'){
            v=0;
        }
        if(u[i]==t[v]) v++;
        if(v>=t.length()) v=0;
    }
    int a=0,b=0;
    int temp;
    if(s.rfind(t)!=string::npos||u.rfind(t)!=string::npos){
        if(u.rfind(t)!=string::npos) a=u.rfind(t);
        if(s.rfind(t)!=string::npos) b=s.rfind(t);
        if(s.rfind(t)!=string::npos||u.rfind(t)!=string::npos)
        temp=max(a,b);
        for(int i=0;i<s.length();i++){
            if(temp==i){
                cout << t;
                i+=t.length()-1;
            }
        else if(c[i]=='?') cout << "a";
        else cout << c[i];
        }
        cout << "\n";
    }
    else cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<long long> lucas(100, -1);
	lucas[0] = 2;
	lucas[1] = 1;

	for (int i = 2; i <= n; i++) {
		lucas[i] = lucas[i - 1] + lucas[i - 2];
	}

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

bool reversecompare(int a, int b)
{
  return a > b;
}

int mat[55][55];

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

  int H, W;
  int left, right, up, down, dummy;
  char x;
  cin >> H >> W;
  int counter = 0;

  for (int i = 1; i <= H; i++) 
    for (int j = 1; j <= W; j++) {
      cin >> x;
      if (x == '.')
        mat[i][j] = 0;
      else {
        mat[i][j] = -1;
        counter++;
      }
    }

  mat[1][1] = 1;

  for (int k = 0; k < (H*W); k++) {
    for (int i = 1; i <= H; i++)
      for (int j = 1; j <= W; j++) {
        dummy = mat[i][j];
        left = mat[i][j-1];
        if (left<1) left = 3000;
        right = mat[i][j+1];
        if (right<1) right = 3000;
        up = mat[i-1][j];
        if (up<1) up = 3000;
        down = mat[i+1][j];
        if (down<1) down = 3000;
        if (dummy == 0) mat[i][j] = 3001;
        mat[i][j] = min(mat[i][j], min(up+1, min(down+1, min(left+1, right+1))));
        if (mat[i][j] == 3001) 
          mat[i][j] = 0;
      }
  }
  dummy = (H*W)-mat[H][W]-counter;
  if (mat[H][W] > 0) cout << dummy << endl;
  else cout << -1 << endl;
  // for (int i = 1; i <= H; i++) {
  //   for (int j = 1; j <= W; j++)
  //     cout << mat[i][j];
  //   cout << endl;
  // }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	
	public static void main(String []args){
		long n=sc.nextInt();
		long curMax=0,temp,totalHeight=0;
		for(int i=0;i<n;i++){
			temp=sc.nextInt();
			if(curMax<temp)
				curMax=temp;
			totalHeight+=(curMax-temp);
		}
		System.out.println(totalHeight);
	}
}

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

#define T 1
#define F 0

int solve(int,int,int,int *);

int main(){

  int i,j=0,n,*N,q,*Q;

  scanf("%d",&n);
  N=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&N[i]);
  scanf("%d",&q);
  Q=(int *)malloc(sizeof(int)*q);
  for(i=0;i<q;i++) scanf("%d",&Q[i]);


  for(i=0;i<q;i++){

  if(solve(j,Q[i],n,N)==T)printf("yes\n");
  else printf("no\n");

  }


  free(N);
  free(Q);

  return 0;
}
int solve(int i,int m,int n,int *A){

  int res;

  if(m==0) return T;
  else if(i>=n) return F;
  res=solve(i+1,m,n,A) || solve(i+1,m-A[i],n,A);
  return res;

}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	ll ans=0;
	repi(i,1,n+1){
		if(i%3!=0&&i%5!=0){
			ans+=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

namespace relay2_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a = x[1] - x[2];
            if (x[0] <= x[1]) Console.WriteLine(1);
            else if (a <= 0) Console.WriteLine(-1);
            else
            {
                Console.WriteLine((x[0] - x[1] + a - 1) / a * 2 + 1);
            }
        }
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------

void work(){
    int k,a,b;
     scanf("%d%d%d",&k,&a,&b);
     int ok=0;
     for(int i=a;i<=b;i++){
        if(i%k==0) ok=1;
     }
     if(ok) printf("OK\n");
     else printf("NG\n");
}

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








Measured memory_bytes: 3692
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 

 
int main(void){
    int d,t,s;
    cin>>d>>t>>s;
    if(d<=t*s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }

  deque<int> b;
  for(int i=0;i<N;i+=2){
    b.push_back(a.at(i));
  }
  for(int i=1;i<N;i+=2){
    b.push_front(a.at(i));
  }
  if(N%2==1){
    reverse(b.begin(),b.end());
  }
  for(int i=0;i<N;i++){
    cout<<b.at(i)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 3840
N, M, K = map(int, input().split())

MOD = 10**9 + 7
R = 1
for i in range(K - 2):
    R = (R * (N * M - 2 - i) * pow(i + 1, MOD - 2, MOD)) % MOD

ans = 0
for i in range(1, N + 1):
    for j in range(1, M + 1):
        u = (N - i + 1)
        d = i
        l = j
        r = (M - j + 1)
        D = 0
        D += u * l * (u + l - 2) // 2
        D += u * r * (u + r - 2) // 2
        D += d * l * (d + l - 2) // 2
        D += d * r * (d + r - 2) // 2
        D -= u * (u - 1) // 2
        D -= d * (d - 1) // 2
        D -= l * (l - 1) // 2
        D -= r * (r - 1) // 2
        ans += D

ans = (ans * R * pow(2, MOD - 2, MOD)) % MOD
print(ans)


Measured memory_bytes: 41948
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    F = [[int(i) for i in input().split()] for _ in range(N)]
    left, right = 0, 10 ** 20
    while right - left > 1:
        mid = (left + right) // 2
        west = 0
        for w, d in F: 
            if w <= mid: west += (mid - w) // d + 1
        if west >= K: right = mid
        else: left = mid
        #print(mid, west)
    ans = 10 ** 20
    for w, d in F:
        if w <= left: ans = min(ans, w + ((left - w)//d + 1) * d)
        else: ans = min(ans, w)
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 58384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		// 文字列の入力
int x = sc.nextInt();
      int count = 0;
      for(int i = 0; i <= a; i++) {
      	for(int j = 0; j <= b; j++){
        	for(int k = 0; k <= c; k++){
            	if ((i * 500 + j * 100 + k * 50) == x){ count++;}
            }
        }
      }
  // 出力
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[N];
    int[] b = new int[N];
    int[] c = new int[M];
    int[] d = new int[M];

    for (int i=0; i<N; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    for (int i=0; i<M; i++) {
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();      
    }
    for (int i=0; i<N; i++) {
      int min = 400000000;
      for (int j=0; j<M; j++) {
        min = Math.min(min,manha(a[i],c[j],b[i],d[j]));
      }
      for (int j=0; j<M; j++) {
        if (min == manha(a[i],c[j],b[i],d[j])) {
          System.out.println(j+1);
          break;
        }
      }
    }
  }
  
  public static int manha(int a,int c,int b,int d) {
    return Math.abs(a - c) + Math.abs(b - d);
  }
}


Measured memory_bytes: 23764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String s = in.next();
            int n = s.length();
            int[] digits = new int[n];
            for (int i = 0; i < n; i++) {
                digits[i] = s.charAt(i) - '0';
            }

            int p = 2019;
            int[] freq = new int[p];
            freq[0] = 1;
            long answer = 0;
            int curr = 0;
            int pow10 = 1;
            for (int j = n - 1; j >= 0; j--, pow10 *= 10, pow10 %= p) {
                curr += pow10 * digits[j];
                curr %= p;
                answer += freq[curr];
                freq[curr]++;
            }
            out.println(answer);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

    }
}



Measured memory_bytes: 36772
/*
	??°??????????´???°?????°??????
*/

#include <stdio.h>
#include <math.h>

/*---?´???°??????(x????´???°??§????????°1)---*/
int prime(int x)
{
	int i, j = 1;

	for (i = 2; i <= sqrt(x); i++)		//2??????x?????????????????§??????
		if (x%i == 0) j = 0;			//x????´???°??§???????????°j???0

	return j;
}

int main(void)
{
	int N, a, i, p = 0;

	scanf("%d", &N);			//??°??????????´???°N???????????????

	for (i = 0; i < N; i++) {
		scanf("%d", &a);
		if (prime(a)) p++;		//?´???°??????
	}

	printf("%d\n", p);			//?´???°?????°p???????????????

	return 0;
}

Measured memory_bytes: 596
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    R(n);
    VI cnt(n);
    FOR(i,1,n-1){
        int x;
        R(x);
        cnt[x-1]++;
    }
    W(cnt);
    return 0;
}


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

void chmax (int &x, int a) {
    x = max(x, a);
}

int h, w;
char s[2004][2004];
set < int > ver_bor[2004], hor_bor[2004];  // vertical borders, horizontal borders

signed main () {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> s[i][j];
            if (s[i][j] == '#')
                hor_bor[i].insert(j);
        }
    }
    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            if (s[j][i] == '#')
                ver_bor[i].insert(j);
        }
    }
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '.') {
                auto hor_it = hor_bor[i].lower_bound(j);
                auto ver_it = ver_bor[j].lower_bound(i);
                int l_hor = -1, r_hor = w, l_ver = -1, r_ver = h;
                if (hor_it != hor_bor[i].begin())
                    l_hor = *prev(hor_it);
                if (hor_it != hor_bor[i].end())
                    r_hor = *hor_it;
                if (ver_it != ver_bor[j].begin())
                    l_ver = *prev(ver_it);
                if (ver_it != ver_bor[j].end())
                    r_ver = *ver_it;
                chmax(ans, (r_hor - l_hor - 1) + (r_ver - l_ver - 1) - 1);
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 379392