akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    vector <int> v2=v;
    sort(all(v2));
    int diff=0;
    for(int i=0;i<n;i++)
        if(v[i]!=v2[i])
            diff++;
    if(diff>2)
        cout<<"NO\n";
    else
        cout<<"YES\n";
    
    
    
    return 0;   
}


 
 


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

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

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

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    
    for(int i=0; i<n; i++){
      String s = sc.next();

      if(s.equals("AC")) ac++;
      else if(s.equals("WA")) wa++;
      else if(s.equals("TLE")) tle++;
      else if(s.equals("RE")) re++;
    }

    System.out.println("AC x " + ac);
    System.out.println("WA x " + wa);
    System.out.println("TLE x " + tle);
    System.out.println("RE x " + re);
  }
}

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

int main() {
	int w, a, b, c;
	scanf("%d %d %d", &w, &a, &b);
	c = b + w;
	w += a;
	
	if (c < a) {
		printf("%d\n", a - c);
	}else {
		if (b > w) {
			printf("%d\n", b - w);
		}else{
			printf("%d\n", 0);
		}
	}
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
struct UnionFind
{
    vector<int> par,num; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N),num(N,1)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        num[ry]+=num[rx];
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.tie(0);
    ll n,k,l;
    cin>>n>>k>>l;
    UnionFind tree(n);
    rep(i,k){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        tree.unite(x,y);
    }
    UnionFind tree2(n);
    rep(i,l){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        tree2.unite(x,y);
    }
    map<P,ll> mp;
    rep(i,n){
        mp[{tree.root(i),tree2.root(i)}]++;
    }
    rep(i,n){
        cout<<mp[{tree.root(i),tree2.root(i)}]<<endl;
    }
 //   cout<<endl;
}


Measured memory_bytes: 15104
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
 
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}
 
func CombMod2(N, k int) int {
  if N & k == k { return 1 }
  return 0
}
 
func Solve() {
  var N int
  NextInt(&N)
  A := make([]int, N)
  for i, s := range NextLine() {
    A[i], _ = strconv.Atoi(string([]rune{s}))
  }
  B := make([]int, N - 1)
  for i := range B {
    B[i] = AbsInt(A[i] - A[i + 1])
  }
  cnt := 0
  for i, b := range B {
    cnt += CombMod2(N - 2, i) * (b % 2)
  }
  if cnt % 2 == 1 {
    Write(1)
    return
  }
  for i, b := range B {
    if b == 1 {
      Write(0)
      return
    }
    B[i] /= 2
  }
  cnt = 0
  for i, b := range B {
    cnt += CombMod2(N - 2, i) * b
  }
  if cnt % 2 == 1 {
    Write(2)
    return
  }
  Write(0)
}
 
func main() {
  Solve()
  Output()
}

Measured memory_bytes: 23424
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean bl = true;
        for (int i=0; i<n; i++) {
            int a = sc.nextInt();
            if (a%2==0) {
                if (!(a%3==0||a%5==0)) {
                    bl = false;
                }
            }
        }
        System.out.println(bl?"APPROVED ":"DENIED");
    }
}

Measured memory_bytes: 23380
#include<stdio.h>
int main(){
	double a,b,c,d,e,f;
	double A,B,C,D,E,F;
	double x,y;
	
	while(scanf("%lf%lf%lf%lf%lf%lf",&a ,&b ,&c ,&d ,&e ,&f )!=EOF){
		A=a*d;
		B=b*d;
		C=c*d;
		D=a*d;
		E=a*e;
		F=a*f;
//		printf(" %lfx + %lfy = %lf\n",A,B,C);
//		printf(" %lfx + %lfy = %lf\n",D,E,F);
		if(B==E){y=0;}
		else{y=(C-F)/(B-E);}
		if(y==-0.000){y=0;}
		x=(c-b*y)/a;
		printf("%1.3lf %1.3lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

/*
 * @author Tanzim Ibn Patowary
 * Created  Apr 25, 2020 3:55:23 AM
 */
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner mScanner = new Scanner(System.in);
		int number = mScanner.nextInt();
		double pi = 2*Math.PI*number;
		System.out.println(pi);
	}

}


Measured memory_bytes: 27152
x = input()
w, h, x, y, r = x.split(' ')
w, h, x, y, r = int(w), int(h), int(x), int(y), int(r)
if (x - r) < 0 or \
   (x + r) > w or \
   (y - r) < 0 or \
   (y + r) > h:
    print('No')
else:
    print('Yes')


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

int main()
{
  string S;
  cin>>S;
  int cnt=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='x'){
		cnt++;
    }
  }
  if(cnt>=8){
    cout<<"NO";
  }
  else{
	cout<<"YES";
  }
}

Measured memory_bytes: 256
n = int(input())
hlist = list(map(int,input().split()))
kijun = hlist[0]
ans = 0
max = hlist[0]

for x in range(0,n):
  if hlist[x] >= max:
    max = hlist[x]
    ans+=1
  #print(hlist[x])
    
print(ans)

Measured memory_bytes: 8784
S,T = input(),input()
N,M = len(S),len(T)
maximum = 0
maxstr = ""
for i in range(0,N-M+1):
    str = S[:i] + T + S[i+M:]

    n = 0
    for j in range(i,i+M):
        if (S[j] != str[j])&(S[j]!="?"):
            n = 1
            # print(S[j],str[j])
            break
    if n==1:continue

    match = 0
    for j in range(N):
        if (S[j] == str[j])|(S[j]=="?"):match += 1
    if maximum<=match:
        maximum = match
        maxstr = str
    # print(str)
# print(maximum)
if maximum == 0:print("UNRESTORABLE")
else:print(maxstr.replace("?","a"))

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


int main(){
    int a,b,k;
    cin>>k>>a>>b;
    int d1=a/k;
    int d2=b/k;
    if(d1<d2){
        puts("OK");
    }
    else if(d1==d2&&a%k==0){
        puts("OK");
    }
    else{
        puts("NG");
    }
}


Measured memory_bytes: 3620
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

ll A[N];

int main(){
	fastio;
	int n; cin>>n;
	For(i,0,n) cin>>A[i];
	sort(A,A+n);
	reverse(A,A+n);
	ll ans=A[0];
	int men = 2;
	int ind=0;
	while(men<n){
		if(!(men&1)) ind++;
		ans += A[ind];
		men++;
	}
	cout << ans << endl;
	return 0;
}



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

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

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  int a;
  set<int> A;
  for (int i{}; i < N; ++i) {
    scanf("%d", &a);
    if (A.find(a) == A.end()) {
      A.insert(a);
    } else {
      A.erase(a);
    }
  }

  printf("%d\n", A.size());
  return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define ms(x, v) memset(x, v, sizeof(x))
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
#define pii pair<int, int>
pii s[N];
int id1[N], id2[N];
bool cmp1(int i, int j)
{
    return s[i].first < s[j].first;
}
bool cmp2(int i, int j)
{
    return s[i].second < s[j].second;
}
int pa[N];
int fpa(int x) {return pa[x] == x ? x : pa[x] = fpa(pa[x]); }

int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    rep(i, n) cin >> s[i].first >> s[i].second;
    rep(i, n) pa[i] = id1[i] = id2[i] = i;
    sort(id1, id1 + n, cmp1);
    sort(id2, id2 + n, cmp2);
    vector<pair<int, pii> > v;
    rep(i, n - 1) v.push_back({s[id1[i + 1]].first - s[id1[i]].first, {id1[i], id1[i + 1]}});
    rep(i, n - 1) v.push_back({s[id2[i + 1]].second - s[id2[i]].second, {id2[i], id2[i + 1]}});
    sort(v.begin(), v.end());
    ll ans = 0;
    for(auto x : v)
    {
        if(fpa(x.second.first) == fpa(x.second.second)) continue;
        ans += x.first;
        pa[fpa(x.second.first)] = fpa(x.second.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6900
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/(__gcd(a,b));
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];

    for (int i = 0; i < n; ++i) {
        d[i]=INFTY;
        color[i]=WHITE;
    }

    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for (int i = 0; i < n; ++i) {
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for (int v = 0; v < n; ++v) {
            if(color[v]!=BLACK && M[u][v] != INFTY){
                if(d[v]>d[u] + M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v]=GRAY;
                }
            }

        }
    }

    for(int i=0; i<n; ++i){
        cout<<i<<" "<< (d[i] == INFTY ? -1 : d[i]) <<endl;
    }
}



int main(){
    cin>>n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            M[i][j]=INFTY;
        }
    }

    int k,c,u,v;
    for (int i = 0; i < n; ++i) {
        cin>>u>>k;
        for (int j = 0; j < k; ++j) {
            cin>>v>>c;
            M[u][v]=c;
        }
    }

    dijkstra();

    return 0;
}


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

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

	int W[110];

	int S1 = 0;
	int S2 = 0;

	for (int i = 0; i < N; i++) {
		cin >> W[i];//重さの代入
		S1 += W[i];
	}


	for (int i = 0; i < N; i++) {
		if (S1 >= S2) {
			S1 -= W[N - 1 - i];
			S2 += W[N - 1 - i];
		}
		if (S1 < S2) {
			if (S2 - S1 > S1 - S2 + 2 * W[N - 1 - i]) {
				cout << S1 - S2 + 2 * W[N - 1 - i] << endl;
				break;
			}
			else {
				cout << S2 - S1 << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	string s;
	cin >> s;
	s = "0" + s;
	ll carry = 0;
	string sub = "";
	for(int i = s.size()-1; i >= 1; i--){
		int num = (s[i] - '0') + carry;
		if(num < 10 - num || (num == 5 && s[i-1] <= '4')){
			carry = 0;
			ans += num;
			//sub = "o" + sub;
		}
		else{
			carry = 1;
			ans += 10 - num;
			//sub = "x" + sub;
		}
	}
	//cout << sub << endl;
	ans += carry;
	cout << ans << endl;
}

Measured memory_bytes: 5348
#include <stdio.h>

int main(){
  int x,y,z;
  scanf("%d %d %d", &x, &y, &z);
  
  int canSit = 0;
  for(int i = 1; i < 100000; i++){
    //n人座るには占領幅(y)と余幅(z)×2必要
    if(x < (y*i + z*(i+1))){
      canSit = i-1;
      break;
    }
  }
  printf("%d",canSit);
}

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

long long a,b,c,d,both,ans;

long long euk(long long A,long long B){//A<B
  if(B%A==0) return A;
  else{
    return euk(B%A,A);
  }
}

long long cul(long long n){
  n=n-(n/c)-(n/d)+(n/both);
  return n;
}
int main(){
  cin>>a>>b>>c>>d;
  
  if(c<d) both=euk(c,d);
  else both=euk(d,c);

  both=c*(d/both);
  ans=cul(b);
  ans-=cul(a-1);

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

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    count = [0] * (N + 1)
    for _ in range(M):
        l, r = map(int, input().split())
        count[l - 1] += 1
        count[r] -= 1
    ans = (1 if count[0] == M else 0)
    for i in range(1, N):
        count[i] += count[i - 1]
        if count[i] == M: ans += 1
    print(ans)

    return 0

if __name__ =="__main__":
    solve()

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int v[n], c[n];
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] - c[i] >= 0) ans += (v[i] - c[i]);
    }

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


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

int main() {
    int n;
    cin >> n;
    int a=0,b=0,c=0,d=0;
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC") a++;
        if(s=="WA")b++;
        if(s=="TLE")c++;
        if(s=="RE")d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl; 
}

Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int to[180001], ne[180001], he[601], kazu[601];
double memo[601];
double dfs(int v) {
	if (memo[v] != -1) return memo[v];
	double ret = 0;
	for (int p = he[v]; p; p = ne[p]) {
		ret += dfs(to[p]);
	}
	return memo[v] = 1 + ret / kazu[v];
}

int to2[180001], ne2[180001], he2[601];
double K[601] = {};
double omomi(int v) {
	if (K[v] != -1) return K[v];
	double ret = 0;
	for (int p = he2[v]; p; p = ne2[p]) {
		ret += omomi(to2[p]) / kazu[to2[p]];
	}
	return K[v] = ret;
}

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


	int N, M;
	cin >> N >> M;
	rep1(i, M) {
		int s, t;
		cin >> s >> t;
		to[i] = t;
		ne[i] = he[s];
		he[s] = i;
		kazu[s]++;
		to2[i] = s;
		ne2[i] = he2[t];
		he2[t] = i;
	}

	rep1(i, N) memo[i] = -1;
	memo[N] = 0;

	double kotae = dfs(1);

	rep1(i, N) K[i] = -1;
	K[1] = 1;

	double saishou = 0;
	rep1(i, N) {
		if (kazu[i] > 1) {
			double saidai = 0;
			double kei = 0;
			for (int p = he[i]; p; p = ne[p]) {
				kei += dfs(to[p]);
				chmax(saidai, dfs(to[p]));
			}
			double are = (kei - saidai) / (kazu[i] - 1) - kei / kazu[i];
			are *= omomi(i);
			chmin(saishou, are);
		}
	}

	cout << setprecision(12) << kotae + saishou << endl;

	Would you please return 0;
}

Measured memory_bytes: 3072
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int m; cin >> m;
	ll digits = 0;
	ll sum = 0;
	rep(i, m)
	{
		ll d, c; cin >> d >> c;
		digits += c;
		sum += d * c;
	}
	cout << digits - 1 + (sum + 8) / 9 - 1 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,a[N],b[N],c[N];
ll ans=0;
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (register int i=1;i<=n;++i) scanf("%d",&b[i]);
	for (register int i=1;i<=n;++i) scanf("%d",&c[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for (register int i=1;i<=n;++i) {
		int t1=lower_bound(a+1,a+n+1,b[i])-a-1;
		int t2=n-(upper_bound(c+1,c+n+1,b[i])-c)+1;
		ans+=1ll*t1*t2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
int a[1000];

int main() {
    string number;
    cin >> number;
    int sum = 0;
    rep(0,number.length()) sum += number[i] - '0';
    if (sum % 9 == 0) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3720
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))

ans = max(bisect.bisect_right(B,k),bisect.bisect_right(A,k))

for i in range(len(a)):
    r = (k-A[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
    #print(i+1,r,i+1+bisect.bisect_right(B,r))
    
for i in range(len(b)):
    r = (k-B[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(A,r))
    #print(i+1,r,i+1+bisect.bisect_right(A,r))
    
print(ans)

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

int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  vector<int> hoge = {0,1};
  char tmp = s.at(0);
  for (int i=1; i<n; i++) {
    if (s.at(i) == tmp) hoge.back()++;
    else {
      tmp = s.at(i);
      hoge.push_back(hoge.back()+1);
    }
  }
  if (s.at(0) == '0') hoge.insert(hoge.begin(), 0);
  if (s.back() == '0') hoge.push_back(hoge.back());

  int ans = 0;
  if (hoge.size() > 2*k+1) {
    for (int i=0; i<hoge.size()-(2*k+1); i+=2) ans = max(ans, hoge.at(i+2*k+1) - hoge.at(i));
  }
  else ans = hoge.back();
  cout << ans << endl;
}

Measured memory_bytes: 1020
/* Bismillahir Rahmanir Rahim */
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<string>
#define   mod          1000000007
#define   lp(i,n)      for(int i=1;i<=n;i++)
#define   lpp(i,a,b)    for(int i=a,i<=b;i++)
#define   stlp(i,n)    for(int i=0;i<n;i++)
#define   ll           long long int
#define   ull          unsigned long long int
#define   tst          int t;cin>>t;while(t--)
#define   pb           push_back
#define   vi           vector<int>v
#define   vs           vector<string>v
#define   rslt(x)      cout<<x<<endl;
#define   mp(x,y)      make_pair(x,y)
#define   yes          rslt("yes")
#define   YES          rslt ("YES")
#define   Yes          rslt ("Yes")
#define   NO           rslt("NO")
#define   srt(v)       sort(v.begin(),v.end())
#define   gcd(a,b)     __gcd(a,b)
#define   lcm(a,b)     (a*gcd(a,b))/b
#define   max          1000007
#define   ar          int s[200000]

using namespace std;
int main()
{

    string s;
    cin>>s;
    ll sum = 0;
    for(auto it:s)
        sum+=(it-'0');
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);

  for(int i=0;i<n;i++) {
    int temp;
    cin >> temp;
    a.at(i)=temp-1;
  }
  for(int i=0;i<n;i++) {
    cin >> b.at(i);
  }
  for(int i=0;i<n-1;i++) {
    cin >> c.at(i);
  }
  int ans=b.at(a.at(0));
  for(int i=1;i<n;i++) {
    ans+=b.at(a.at(i));
    if(a.at(i)-a.at(i-1)==1) {
      ans+=c.at(a.at(i-1));
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

int main(){
	int n;
	
	while(cin >> n,n){
		int mp[11][11];
		
		REP(i,n)REP(j,5)cin >> mp[i][j];
		int ans = 0;
		while(1){
			bool flag = false;
			REP(i,n){
				REP(j,5){
					int cou = 0;
					int now = 0;
					for(int k = j;k < 5;k++){
						if(mp[i][k] == -1)break;
						if(k == j){
							now = mp[i][k];
							cou = 1;
						}
						else{
							if(mp[i][k] == now)cou++;
							else break;
						}
					}
					if(cou >= 3){
						flag = true;
						for(int k = 0;k < cou;k++){
							ans += mp[i][j+k];
							mp[i][j+k] = -1;
						}
					}
				}
			}
			
			REP(q,n){
				for(int i = n-1;i > 0;i--){
					REP(j,5){
						if(mp[i][j] == -1){
							mp[i][j] = mp[i-1][j];
							mp[i-1][j] = -1;
						}
					}
				}
			}			
			if(!flag)break;
		}
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    
    int odd=0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        if(a%2){
            odd++;
        }
    }
    
    if(odd%2){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const ll INF = 1LL << 60;

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    vector<vector<ll>> dp(n+1, vector<ll>(h+1, INF));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= h; j++){
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            int col = min(j+a[i-1], h);
            dp[i][col] = min(dp[i][col], dp[i][j] + b[i-1]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 81560
#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 20001
int main(void)
{
	double a;
	int c1, c2, c3, s, cou = 0;
	while (scanf_s("%d %d %d", &c1, &c2, &c3) != EOF) {
		s = 20 - (c1 + c2);
		if (s > 10) printf("YES\n");
		else if (s < 1) printf("NO\n");
		else {
			if (s >= c1) ++cou;
			if (s >= c2) ++cou;
			if (s >= c3) ++cou;
			a = (double)(s - cou) / (10 - 3);
			if(a >= 0.5) printf("YES\n");
			else  printf("NO\n");
			cou = 0;
		}
	}
}

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

#define mp make_pair
#define mx 105

int main(){
//	freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int n;
	cin>>n;

	int arr[n];
	int dp[n];
	
	for(int i=0;  i<n; i++){
		cin>>arr[i];
		if(i!=0)
			dp[i]=INT_MAX;
	}

	dp[0]=0;

	for(int i=0;i<n; i++){
		for(int j = 1; j<3; j++){
			if(i+j<n){
				dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i+j]-arr[i]));
			}
		}
	}

	cout<<dp[n-1]<<endl;
	return 0;

}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll a,b;
  cin>>a>>b;
  b=b/1000;
  b=b-a;

  ll yuki=0,hide=0;

  ll res=-1,resd=-1,resf=-1;

  while(yuki+hide<=a){
    while(yuki+hide<=a){
      if(b==yuki*9+hide*4){
        res=yuki;
        resd=hide;
        resf=a-res-resd;
      }
      //cout<<yuki<<" "<<hide<<endl;
      hide++;
    }
    hide=0;
    yuki++;
  }
  cout<<res<<" "<<resd<<" "<<resf<<" "<<endl;

}


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

int main() {
    int n; scanf("%d", &n);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
    int sum = 0;
    for (int i = 0; i < n; ++i) sum ^= a[i];
    a.push_back(sum);
    sum = 0;
    for (int i = 0; i < n; ++i) sum ^= b[i];
    b.push_back(sum);
    if (multiset<int>(a.begin(), a.end()) != multiset<int>(b.begin(), b.end())) {
        puts("-1");
        return 0;
    }

    if (a == b) {
        puts("0");
        return 0;
    }

    vector<int> v;
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        if (a[i] != b[i] || i == n) {
            v.push_back(a[i]);
            v.push_back(b[i]);
            ans += i < n;
        }
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());

    vector<int> uf(v.size());
    iota(uf.begin(), uf.end(), 0);

    function<int(int)> Find = [&](int x) {
        if (x == uf[x]) return x;
        return uf[x] = Find(uf[x]);
    };

    auto Merge = [&](int x, int y) {
        uf[Find(x)] = Find(y);
    };

    for (int i = 0; i <= n; ++i) {
        if (a[i] != b[i] || i == n) {
            int x = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
            int y = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
            Merge(x, y);
        }
    }
    for (int i = 0; i < v.size(); ++i) ans += Find(i) == i;
    printf("%d\n", ans - 1);
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> c(n);
  rep(i, n) cin >> c[i];
  vector<mint> dp(n+1);
  dp[0] = 1;
  vector<int> prev(200010, -1);
  rep(i, n) {
    dp[i+1] = dp[i];
    if(prev[c[i]] != -1 && prev[c[i]] != i) dp[i+1] += dp[prev[c[i]]];
    prev[c[i]] = i+1;
  }
  cout << dp[n].x << endl;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
	long long int i,j,k,l,n,q,count2=0,sum=0;
	char d;
	cin >> n >> k;
	vector<lli>in(n);
	for(i=0;i<n;i++){
		cin >> in[i];
	}
	sort(in.begin(),in.end());
	for(i=0;i<k;i++)sum=sum+in[i];
	cout << sum << '\n';
	
	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{  
    ll n,w;
    cin>>n>>w;
    vector<ll> sums(n);
    vector<ll> values(n);
    unordered_map<ll,ll> um;
    ll totsum = 0;
    for(int i = 0 ; i <  n ; i++)
    {
        cin>>sums[i];
        
        cin>>values[i];
        um[values[i]]++;
        totsum += values[i];
    }
    vector<ll> dp(totsum+1, INT_MAX);
    dp[0] = 0;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = totsum - values[i] ; j>=0 ; j-- )
        {   
           
          dp[j+values[i]] = min(dp[j+values[i]] , dp[j]+sums[i]);
               
        }
    }
    for(int j = totsum ; j>= 0 ;j--)
    {
        if(dp[j] <= w)
        {
           cout<<j<<endl;
            break;
        }
    }
    return 0;
        
}



Measured memory_bytes: 1152
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        int top1 = 0;
        int idx1 = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            if (top1 < A[i]) {
                top1 = A[i];
                idx1 = i;
            }
        }

        int top2 = 0;
        for (int i = 0; i < N; i++) {
            if (i != idx1  && top2 < A[i]) {
                top2 = A[i];
            }
        }

        long max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            if (A[i] == top1) {
                System.out.println(top2);
            } else {
                System.out.println(top1);
            }
        }

        return;
    }

}

Measured memory_bytes: 105820
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int MAXN=4e5+7;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const double pi=acos(-1.0);

struct Complex
{
    double x,y;
    Complex(double _x=0.0,double _y=0.0) :x(_x),y(_y) {}
    Complex operator - (const Complex &b) const {return Complex(x-b.x,y-b.y);}
    Complex operator + (const Complex &b) const {return Complex(x+b.x,y+b.y);}
    Complex operator * (const Complex &b) const {return Complex(x*b.x-y*b.y,x*b.y+y*b.x);}
};
/*
进行FFT和IFFT前的反转变换
位置i和(i的二进制反转后位置)互换
len必须为2的幂
*/
void change(Complex *y,int len)
{
    for(int i=1,j=len/2;i<len-1;i++)
    {
        if(i<j) swap(y[i],y[j]);
        //交换互为小标反转的元素,i<j保证交换依次
        //i做正常+1,j反转类型的+1,始终保持i和j是反转的
        int k=len/2;
        while(j>=k)
        {
            j-=k;
            k/=2;
        }
        if(j<k) j+=k;
    }
}
//做FFT  on==1时DFT on==-1时IDFT
void fft(Complex *y,int len,int on)
{
    change(y,len);
    for(int h=2;h<=len;h<<=1)
    {
        Complex wn(cos(-on*2*pi/h),sin(-on*2*pi/h));
        for(int j=0;j<len;j+=h)
        {
            Complex w(1,0);
            for(int k=j;k<j+h/2;k++)
            {
                Complex u=y[k];
                Complex t=w*y[k+h/2];
                y[k]=u+t;
                y[k+h/2]=u-t;
                w=w*wn;
            }
        }
    }
    if(on==-1)
        for(int i=0;i<len;++i)
            y[i].x/=len;
}

Complex x1[MAXN],x2[MAXN];
ll ans[MAXN];
int a[MAXN],cnt[MAXN];

int main()
{
    int n;
    ll m;
    scanf("%d%lld",&n,&m);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    int len=1;
    while(len<2e5) len<<=1;
    for(int i=0;i<len;++i)
        x1[i]=Complex(cnt[i],0);
    fft(x1,len,1);
    for(int i=0;i<len;++i)
        x1[i]=x1[i]*x1[i];
    fft(x1,len,-1);
    for(int i=0;i<len;++i)
        ans[i]=(ll)(x1[i].x+0.5);
    ll cntt=0;
    ll res=0;
    for(int i=len-1;i>=0;--i)
    {
        if(cntt+ans[i]>m)
        {
            res+=(m-cntt)*i;
            break;
        }
        else
        {
            cntt+=ans[i];
            res+=i*ans[i];
        }
    }
    printf("%lld\n",res);
    return 0;
}



Measured memory_bytes: 17792
N = int(input())
S = input()

wnums = [0]
enums = [0]
for i in range(0, N-1):
    if S[i] == 'W':
        wnums.append(wnums[i]+1)
    else:
        wnums.append(wnums[i])

j=0
for i in range(N-1, 0, -1):
    if S[i] == 'E':
        enums.append(enums[j]+1)
    else:
        enums.append(enums[j])
    j += 1

enums.reverse()

ans = 10**9
for i in range(N):
    num = wnums[i] + enums[i]
    if ans > num:
        ans = num
print(ans)

Measured memory_bytes: 18080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int N; cin >> N;
  int s = 0; int c = N;
  while (c > 0) {
    s += c % 10;
    c /= 10;
  }
  if (N % s == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max({a * c, a * d, b * c, b * d});
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3556
import java.util.Scanner;

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

        int n = sc.nextInt();
        long[] cnt = new long[5];  // MARCH

        for (int i = 0; i < n; i++) {
            char c = sc.next().charAt(0);
            switch(c) {
                case ('M'): cnt[0]++; break;
                case ('A'): cnt[1]++; break;
                case ('R'): cnt[2]++; break;
                case ('C'): cnt[3]++; break;
                case ('H'): cnt[4]++; break;
            }
        }
        sc.close();

        long ans = 0;
        for (int i = 0; i < 3; i++) {
            if (cnt[i] == 0)
                continue;
            for (int j = i+1; j < 4; j++) {
                if (cnt[j] == 0)
                    continue;
                for (int k = j+1; k < 5; k++) {
                    if (cnt[k] == 0)
                        continue;
                    ans += cnt[i] * cnt[j] * cnt[k];
                }
            }
        }

        System.out.println(ans);
    }
}


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

int main(){
  int n,m,i,j,k,l,ans=0;
  cin >> n >> m;
  vector<int> a(m);
  for(i=0; i<n; i++){
    cin >> k;
    for(j=0; j<k; j++){
      cin >> l;
      a[l-1]++;
    }
  }
  for(i=0; i<m; i++){
    if(a[i]==n){
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define all(v) v.begin(),v.end()
#define vll vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

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

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}


ll dp[200000];
vll v1[200001];
ll n,arr[200000];

ll binsearch(ll a, ll val)
{
    ll low=0;
    ll high=v1[a].size()-1;
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(v1[a][mid]==val)
            return mid;
        else if(v1[a][mid]<val)
            low=mid+1;
        else
            high=mid-1;
    }
    return -1;
}

ll func(ll start, ll end)
{
    if(start+1>=end)
        return 0;
    else
    {
        if(dp[start]!=-1)
            return dp[start];
        else
        {
            ll ans=0;
            ll currindex=binsearch(arr[start],start);
            ans=func(start+1,end)%mod;
            if(currindex+1==v1[arr[start]].size())
            {
                dp[start]=ans;
                return dp[start];
            }
            else
            {
                if(v1[arr[start]][currindex+1]!=v1[arr[start]][currindex]+1)
                {
                    ans=(ans+1+func(v1[arr[start]][currindex+1],end))%mod;
                }
                dp[start]=ans;
                return dp[start];
            }
        }
    }
}
signed main() 
{
    fast_cin();
    memset(dp,-1,sizeof(dp));
    cin>>n;
    For(i,0,n)
    {
        cin>>arr[i];
        v1[arr[i]].pb(i);
    }
    cout<<(1+func(0,n))%mod;
    return 0;    
}

Measured memory_bytes: 23680
import bisect
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0] + list(accumulate(A))
b = list(accumulate(B))
ans = 0
for i in range(N + 1):
    if (t := K - a[i]) >= 0:
        e = bisect.bisect_right(b, t)
        ans = max(ans, i + e)
print(ans)

Measured memory_bytes: 49288
input = raw_input


def answer():
    n, m, v, p = map(int, input().split(" "))
    nums = sorted(map(int, input().split(" ")), reverse=True)

    num_last = nums[p-1]

    nokori_sum = sum(nums[p-1:n])

    out = p
    count = 0
    if v > p:
        cumsum = {}
        cur = 0
        
        cur = 0
        for i in range(p-1, n):
            x = nums[i]
            cur += x
            cumsum[i] = cur

        for i in range(p, n):
            x = nums[i]
            if x + m < num_last:
                break

            #nokori_yoyuu = ( (x + m) * (n-p+1- 1) ) - (nokori_sum-x)
            #nokori_yoyuu = 0
            #for j in range(p-1, n):
            #    if j == i:
            #        continue
            #    x2 = nums[j]
            #    cur_yoyuu = max(0, min(x+m-x2, m))
            #    nokori_yoyuu += cur_yoyuu

            area1 = (x+m) * (i-p+1) - cumsum[i-1]
            #print("n", n, "i", i, "m", m)
            area2 = (n - i - 1) * m
            #print(area1, area2, nokori_yoyuu)

            nokori_yoyuu = area1 + area2

            cost = (v-p) * m
            if cost > nokori_yoyuu:
                break

            count += 1

        out += count

    else:
        for x in nums[p:]:
            if x + m < num_last:
                break
            count += 1
        out += count

    print(out)

answer()

Measured memory_bytes: 55332
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, f[2009], mod=1e9+7, inv[2009];
ll ans;
int ncr(int n, int r)
{
    if(n<r)
        return 0 ;
    return 1LL*f[n] * (1LL*inv[r]*inv[n-r]%mod) %mod;
}
int main()
{
    IO
    cin>>n;
    inv[0]=inv[1]=1;
    f[0]=f[1]=1;
    for(int i=2; i<=n; i++)
    {
        inv[i]=mod- 1LL*mod/i*inv[mod%i]%mod;
        f[i]=1LL*i*f[i-1]%mod;
    }
    for(int i=2; i<=n; i++)
        inv[i]=1LL*inv[i-1]*inv[i]%mod;
    for(int i=1; 3*i<=n; i++)
    {
        int rem=n-3*i;
        ans+=ncr(i-1+rem,rem);
        ans%=mod;
    }
    cout<<ans;
}


Measured memory_bytes: 3660
N,M=map(x->parse(Int,x),split(readline()))
D=Dict{Int,Int}()
D[0]=1
ans=0
now=0
for a=map(x->parse(Int,x),split(readline()))
	now=(now+a)%M
	ans+=get(D,now,0)
	D[now]=get(D,now,0)+1
end
println(ans)


Measured memory_bytes: 167696