akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int H,W; cin >> H >> W;
    int a[H][W]; REP(i,H)REP(j,W) cin >> a[i][j];
    VVI ans;
    REP(i,H){
        if(i%2 == 0){
            REP(j,W-1){
                if(a[i][j]%2){
                    a[i][j]--;
                    a[i][j+1]++;
                    VI push{i+1,j+1,i+1,j+2};
                    ans.push_back(push);
                }
            }
            if(a[i][W-1]%2 && i<H-1){
                a[i][W-1]--;
                a[i+1][W-1]++;
                VI push{i+1,W,i+2,W};
                ans.push_back(push);
            }
        }
        else{
            RFOR(j,W,1){
                if(a[i][j]%2){
                    a[i][j]--;
                    a[i][j-1]++;
                    VI push{i+1,j+1,i+1,j};
                    ans.push_back(push);
                }
            }
            if(a[i][0]%2 && i<H-1){
                a[i][0]--;
                a[i+1][0]++;
                VI push{i+1,1,i+2,1};
                ans.push_back(push);
            }
        }
    }

    cout << ans.size() << en;
    REP(i,ans.size()){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << en;
    }
    return 0;
}

Measured memory_bytes: 10032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var w = int.Parse(Console.ReadLine());
            for (int i = 0; i < s.Length; i++)
            {
                if (i % w == 0)
                {
                    Console.Write(s[i]);
                }
            }
            Console.WriteLine();
        }
    }
}

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

using namespace std;

int N, M, x, y, INF, a[509][509], v[509];

void print (bool ans)
{
    if (ans == 0)
    {
        printf ("No\n");
        exit (0);
    }
    printf ("Yes\n");
    for (int i=1; i<=N; i++, printf ("\n"))
        for (int j=1; j<=M; j++)
            printf ("%d ", a[i][j]);
}

void calc (int d, int N)
{
    int r = (N + 1) % d;
    for (int i=1; i<=N; i++)
        if (i % d != r)
            v[i] = (INF - 1) / (d - 1);
        else
            v[i] = -INF;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &N, &M, &x, &y), INF = 1e9;
if (N % x != 0)
{
    calc (x, N);
    for (int i=1; i<=N; i++)
        for (int j=1; j<=M; j++)
            a[i][j] = v[i];
    print (1);
}
else
if (M % y != 0)
{
    calc (y, M);
    for (int i=1; i<=N; i++)
        for (int j=1; j<=M; j++)
            a[i][j] = v[j];
    print (1);
}
else print (0);
return 0;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

vector<long long> parent, length;

int find(int n)
{
	if(parent[n] == n)
	{
		return n;
	}
	return parent[n] = find(parent[n]);
}

void add(int a, int b)
{
	int x = find(a);
	int y = find(b);
	if(x == y)
	{
		return;
	}
	parent[x] = y;
	length[y] += length[x];
}


void solve() {
    
    rd2(ll, n, m);
    
    parent.resize(n + 1);
	length.resize(n + 1);
	
    for(int i = 0; i <= n; i++) {
		parent[i] = i;
		length[i] = 1;
	}
    
    for(int i = 0; i < m; i++) {
        rd2(ll, a, b);
        add(a, b);
    }
    
    map<ll, ll> M;
    for(int i = 1; i <= n; i++) {
        M[find(i)]++;
    }
    
    // for(auto x: M)
    //     cout << x.F << " " << x.S << endl;
    
    ll dvd = M.size();
    
    ll mxm = LLONG_MIN;
    for(auto x: M) {
        mxm = max(mxm, x.second);
    }
    
    cout << mxm;
}


int main() {
	
	fastio;
	
	ll t = 1;
    while(t--) {
        solve();
    }


	return 0;
}


Measured memory_bytes: 18660
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(inti = n; i >= 0; i--)


int main() {
	LL a, b, c;
	LL ans = 0;
	cin >> a >> b >> c;
	if (b > c) {
		ans = b + c;
	}
	else {
		ans += b * 2;
		c -= b;
		if (a >= c) {
			ans += c;
		}
		else {
			ans += a + 1;
		}
	}
	cout << ans;
}



Measured memory_bytes: 256
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();

    if(b % a == 0) {
      System.out.println(a + b);
    } else {
      System.out.println(b - a);
    }
  }
}

Measured memory_bytes: 21844
//package com.karancp;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStream;


 class Main {
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader z = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver =new task();
        solver.solve(z,out);
        out.close();
    }

    static class task
    {

        static long gcd(long a,long b)
        {
            if(b==0)return a;
            else return gcd(b,a%b);
        }
        static long lcm(long a,long b)
        {
            long pp=a*b;
            long bb=gcd(a,b);
            long res =pp/bb;
            return res;
        }
        static int max(int a,int b)
        {
            return Math.max(a,b);
        }
        static int min(int a,int b)
        {
            return Math.min(a,b);
        }





        public static void solve(InputReader z, PrintWriter out) {
            int n=z.nextInt();
            int k=z.nextInt();
            int j;
            int ar[]=new int[n];
            int dp[]=new int[n+1];
            int i;
            for(i=0;i<n;i++)ar[i]=z.nextInt();
            Arrays.fill(dp,Integer.MAX_VALUE);

            dp[1]=0;
            dp[2]=Math.abs(ar[0]-ar[1]);

            for(i=3;i<=n;i++)
            {
                for(j=1;j<=k;j++)
                {
                    if(i-j>0){
                    int a=Math.abs(ar[i-1]-ar[i-j-1]);
                    dp[i]=min(dp[i],dp[i-j]+a);
                    }
                }
            }
            out.print(dp[n]);


        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

    }



}

Measured memory_bytes: 33448
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int len=s.length();
	if(s[0]==s[len-1]){
		cout<<(len%2==0 ? "First":"Second");
	}
	else{
		cout<<(len%2==1 ? "First":"Second");
	}
	cout<<endl;
	return 0;
}

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

using namespace std;
#define int long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;

int N;
ppi px[100100];
ppi py[100100];
vector<pip> edge;

struct UF {
    const static int size = 100100;
    int par[size];
    int rank[size];

    UF(int n) {
        rep(i, n) {
            par[i] = i;
            rank[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

signed main() {
    cin >> N;
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        px[i] = ppi(pii(x, y), i);
        py[i] = ppi(pii(y, x), i);
    }
    sort(px, px + N);
    sort(py, py + N);
    rep(i, N - 1) {
        int x0 = px[i].first.first;
        int x1 = px[i + 1].first.first;
        int cost = x1 - x0;
        int i0 = px[i].second;
        int i1 = px[i + 1].second;
        edge.push_back(pip(cost, pii(i0, i1)));
    }
    rep(i, N - 1) {
        int y0 = py[i].first.first;
        int y1 = py[i + 1].first.first;
        int cost = y1 - y0;
        int i0 = py[i].second;
        int i1 = py[i + 1].second;
        edge.push_back(pip(cost, pii(i0, i1)));
    }
    sort(edge.begin(), edge.end());

    UF uf(N + 10);
    int ans = 0;
    rep(i, edge.size()) {
        pii p = edge[i].second;
        if (!uf.same(p.first, p.second)) {
            ans += edge[i].first;
            uf.unite(p.first, p.second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13296
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

void probB() {
	int N; cin >> N;
	vi  results(4);
	string s;
	for (int i = 0; i < N; i++) {
		cin >> s;
		if (s == "AC") results[0]++;
		else if (s == "WA") results[1]++;
		else if (s == "TLE") results[2]++;
		else results[3]++;

	}

	cout << "AC" << " x " << results[0] << endl;
	cout << "WA" << " x " << results[1] << endl;
	cout << "TLE" << " x " << results[2] << endl;
	cout << "RE" << " x " << results[3] << endl;
	return;
}

void probA() {
	int N; cin >> N;
	if (N % 1000 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1000 - (N % 1000) << endl;
	}
}
int main() {
	probA();
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

int factrial(int n)
{
    if(n==1) return 1;
    int m = factrial(n-1);
    return n*m;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int> > loc(N,vector<int>(2,0));
    vector<vector<double> > dist(N,vector<double>(N,0));

    for (int i=0; i<N; ++i)
    {   
        int x,y;
        cin >> x >> y;
        loc[i][0] = x;
        loc[i][1] = y;
    }

    for (int i=0; i<N; ++i)
    {
        for (int j=i+1; j<N; ++j)
        {
            dist[i][j] = dist[j][i] = sqrt(pow(loc[i][0]-loc[j][0],2) + pow(loc[i][1]-loc[j][1],2));
            // cout << i << " " << j << " " << dist[i][j] << endl;
        }
    }

    vector<int> v;
    for(int i=0; i<N; ++i)
    {
        v.push_back(i);
    }
    double sum = 0.0;
    int count = 0.0;
    int div = factrial(N);
    do {
        for (int i = 0; i < v.size(); ++i)
        {
            if(i>0)
            {
                int from = v[i-1];
                int to = v[i];
                sum += dist[from][to];
                // double tmp = dist[from][to]/div;
                // sum += tmp; 
                // cout << dist[from][to] << " "; 
                // cout << from << to << endl;
                // cout << v[i] << " " << v[i+1] << " ";

            }
            // cout << v[i] << " ";
        }
        ++count;
        // cout << endl;    
    } while (next_permutation(v.begin(), v.end()));

    // cout << sum << endl;
    // cout << double(sum) << endl;
    cout << setprecision(10) << sum/div<< endl;
    // cout << count << endl;
    // cout << count << endl;
    // cout << N << endl;
    return 0;
}

Measured memory_bytes: 256
x=int(input())
if x>=400 and x<=599:
    print(8)
elif x>=600 and x<=799:
    print(7)
elif x>=800 and x<=999:
    print(6)
elif x>=1000 and x<=1199:
    print(5)
elif x>=1200 and x<=1399:
    print(4)
elif x>=1400 and x<=1599:
    print(3)
elif x>=1600 and x<=1799:
    print(2)
else:
    print(1)
    

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

int main(){
    int n,k=0;
    cin>>n;
    string str[n+1];
    string str2[n+1];
    map<string,int> mp;
    int j=0;
    for(int i=1;i<=n;i++){
        cin>>str[i];
        mp[str[i]]++;
    }
    int maxv=0;
    
    for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
        maxv=max(maxv,it->second);
    }
    
    for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
        if(it->second==maxv)
          cout<<it->first<<endl;
    }
    
    return 0;
}

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

int main(void){
    int N;
    cin>>N;
    
    vector<long long> a(3*N+1);
    for(int i=0;i<3*N;i++) cin>>a[i+1];
    
    sort(a.begin(),a.end());
    
    long long sum=0;
    for(int i=3*N-1;i>N;i-=2){
        sum+=a[i];
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912

const long double PI = acos(-1);
const ll DEP = 1LL << 50;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int N,p; string s;
vector<pair<pair<string,int>,int>> P;
int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> s >> p;
		P.push_back(make_pair(make_pair(s,-p),i+1));
	}
	sort(P.begin(),P.end());
	for(int i = 0; i < N; i++){
		cout << P[i].second << endl;
	}
	return 0;
}




Measured memory_bytes: 256
n = int(input())
pairsum = n - n % 2 + 1
sol = []
for i in range(1, 1 + n):
    for j in range(i + 1, 1 + n):
        if i + j != pairsum:
            sol.append((i, j))
print(len(sol))
for s in sol:
    print(*s)

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

int main() {

  for(int N, M; cin >> N >> M && (N|M);) {
    vector<vector<tuple<int, int, int>>> G(N);
    rep(_, M) {
      int u, v, d, c; cin >> u >> v >> d >> c;
      u--, v--;
      G[u].emplace_back(v, d, c);
      G[v].emplace_back(u, d, c);
    }

    PQ_G<tuple<int, int, int>> pq;
    pq.emplace(0, 0, 0);

    vector<int> dist(N, inf);

    ll ans = 0;
    while(!pq.empty()) {
      int d, c, p; tie(d, c, p) = pq.top(); pq.pop();
      if(dist[p] <= d) continue;
      dist[p] = d;
      ans += c;
      for(auto const& e: G[p]) {
        int _v, _d, _c; tie(_v, _d, _c) = e;
        if(dist[_v] <= d + _d) continue;
        pq.emplace(d + _d, _c, _v);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

namespace std {
	#define u(x, a, b) for(ll x = a; x < b; x++)
	#define d(x, a, b) for(ll x = a; x > b; x--)
}

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

int main(){
	ll n;
	cin >> n;
	
	ll a[n];
	ll xall = 0;
	u(one, 0, n){cin >> a[one]; xall = (xall^a[one]);}
	
	u(one, 0, n){cout << (xall^a[one]) << ' ';}
}


Measured memory_bytes: 5108
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    link = np.zeros((M, N))

    for i in range(M):
        tmp = list(map(int, input().split()))
        for j in range(1, tmp[0]+1):
            link[i][tmp[j]-1] = 1

    p = np.array(list(map(int, input().split()))).T
    # print(link.shape)
    # print(p.shape)
    ans = 0
    for i in range(2**N):
        switch = np.zeros((N, 1))
        for j in range(N):
            if i&1:
                switch[j][0] = 1
            i >>= 1
        now = np.dot(link, switch) % 2
        ok = True
        for i in range(M):
            if now[i] != p[i]:
                ok = False
                break
        if ok:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 14852
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

ll N,K;
ll A[100010],B[100010];
ll ans;
vector<ll> popin;
ll check(ll idx,ll par){

	ll tmp = par+(1<<idx);
	tmp--;
	ll ret = 0;
	REP(i,0,N){
		if((tmp|A[i])==tmp){
			ret+=B[i];
		}
	}
	return ret;
}
int main() {
	cin>>N>>K;
	REP(i,0,N){
		cin>>A[i]>>B[i];
	}
	ll up=0;
	ll k=K;
	while(k>0){
		if(k%2==1) popin.push_back(up);
		up++;
		k/=2;
	}
	ll opt=0;
	RREP(i,0,popin.size()){
		ans=max(ans,check(popin[i],opt));
		opt |= 1<<popin[i];
	}


	p(max(ans,check(0,K)));
	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            var d = cin.ReadInt;
            var x = a+b;
            var y = c+d;
            if(x==y){
                WriteLine("Balanced");
            }else if(x>y){
                WriteLine("Left");
            }else{
                WriteLine("Right");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator =' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

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

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

int main(){
    double d,t,s;
    cin>>d>>t>>s;
    if(d/s<=t){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int m,d;
    cin>>m>>d;
    int l=0;
    for(int i=1;i<=m;i++){
    	for(int j=1;j<=d;j++){
    		vector<int> v;
    		int t=j;
    		while(t){
    			v.push_back(t%10);
    			t/=10;
    		}
    		if(v.size()==1) continue;
    		if(v[0]>=2 && v[1]>=2 && v[0]*v[1]==i) l++;
    	}
    }
    cout<<l;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
if sum(a)<=k:
    print(0)
    exit()
f.sort(reverse=True)
l=0
r=10**12
x=(r+l)//2
def check(x):
    p=0
    for i in range(n):
        if x//f[i]<a[i]:
            p+=a[i]-x//f[i]
            if p>k:
                return False
    if p>k:
        return False
    else:
        return True
while l+1<r:
    if check(x):
        r=x
        x=(r+l)//2
    else:
        l=x
        x=(r+l)//2
print(r)

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

int main(){
	int N, M; cin >> N >> M;
	vector<int> graph_si(N, 0), graph_ie(N, 0);

	for(int i = 0; i < M; ++i){
		int a, b;
		cin >> a >> b;

		a--; b--;
		if(a == 0) graph_si[b] = 1;
		if(b == N-1) graph_ie[a] = 1;
	}

	for(int i = 1; i < N-1; ++i){
		if(graph_si[i] && graph_ie[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;

	return 0;
}


Measured memory_bytes: 1792
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
    
main()


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

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

  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t C[N];
  for(int i=0;i<N;i++){
    cin >> C[i];
  }
  sort(C, C+N);
  reverse(C, C+N);
  int64_t left = 0, right = C[0]/B+1;
  int64_t mid = (left + right)/2;
  while(right - left > 1){
    mid = (left + right)/2;
    int64_t kai = 0;
    for(int i=0;i<N;i++){
      int AC = (C[i] - B*mid+A-B-1)/(A-B);
      if(AC > 0) kai += AC;
    }
    if(kai > mid) left = mid;
    else right = mid;
  }
  cout << right << endl;
}

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

long long n,h[105],dp[105],tmp,mod=1000*1000*1000+7,pre[105],l,r,omega,dest,prog;
deque<pair<long long,int> > v;

long long fastp(long long base,int exp){
    if(exp==0)return 1;
    
    long long val=fastp(base,exp/2);
    val=(val*val)%mod;
    if(exp%2)val*=base;
    return val%mod;
}


int main(){

	cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];

    dp[n+1]=1;
    pre[0]=1;
    for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]*fastp(2,max(0ll,h[i]-h[i-1]));
        pre[i]%=mod;
    }
    
    for(int i=n;i>0;i--){
        tmp=2*dp[i+1];
        
        v.clear();
        v.push_back({2,n+1});
        for(int j=n;j>=i;j--){
            while(v.size()>0 && v.back().first>=h[j]+1)v.pop_back();
            v.push_back({h[j]+1,j});
        }
        
        while(v.size()>1 && v[1].first<=h[i-1])v.pop_front();
        
        v[0].first=max(v[0].first,h[i-1]+1);
        
        for(int j=0;j<v.size()-1;j++){
            l=v[j].first;
            r=v[j+1].first-1;
            if(l>r)continue;
            dest=v[j].second;
            omega=(pre[dest-1]*fastp(pre[i],mod-2))%mod;
            prog=(fastp(2,h[i]-l)*(2-fastp(fastp(2,r-l),mod-2)))%mod;
            prog+=mod;
            prog%=mod;
            tmp+=((2ll*omega*prog)%mod*dp[dest])%mod;
            tmp%=mod;
        }
        
        dp[i]=tmp%mod;
    }
    
    cout<<(dp[1]%mod+mod)%mod<<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int w, h;
string f[20];
int cnt;

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

void rec(int x, int y) {
  f[y][x] = '#';
  cnt++;

  for (int i=0; i<4; i++) {
    int mx = x + dx[i];
    int my = y + dy[i];

    if (mx < 0 || w <= mx) { continue; }
    if (my < 0 || h <= my) { continue; }
    if (f[my][mx] != '.') { continue; }

    rec(mx, my);
  }
}

int main() {
  while (cin >> w >> h, (w||h)) {
    for (int i=0; i<h; i++) {
      cin >> f[i];
    }

    cnt = 0;
    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        if (f[y][x] == '@') { rec(x, y); }
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3064
N = int(input())
Sdict = {}
for i in range(N):
    S = input()
    if S in Sdict:
        Sdict[S] += 1
    else:
        Sdict[S] = 1


M = max(Sdict.values())
ans = []
for k in Sdict.keys():
    if Sdict[k] == M:
        ans.append(k)

ans.sort()
print('\n'.join(ans))

Measured memory_bytes: 34140
import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]  # 番兵を入れておくと良い
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for qi in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 13972
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long func(long long a,long long b){
    return a/b;
}

int main(){
    long long a,b,c,d; cin >> a >> b >> c >> d;
    long long lcm = LCM(c,d);
    long long ans = b-a+1;
    ans -= (func(b,c)-func(a-1,c));
    ans -= (func(b,d)-func(a-1,d));
    ans += (func(b,lcm)-func(a-1,lcm));
    cout << ans << endl;
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
void File(){
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define ll long long
const int maxn=2e5+10;
int n;
ll a[maxn],sum[maxn];
int main(){
	//File();
	scanf("%d",&n);
	REP(i,1,n)scanf("%lld",&a[i]);
	REP(i,1,n+1)sum[i]=sum[i-1]+abs(a[i]-a[i-1]);
	REP(i,1,n){
		printf("%lld\n",sum[n+1]-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]));
	}
	return 0;
}


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

long gcd(long m, long n)
{
	if ((m == 0) || (n == 0))
		return 0;
	
	while(m != n) {
		if (m > n) m -= n;
		else       n -= m;
	}
	return m;
}

long lcm(long m, long n)
{
	if ((m == 0) || (n == 0))
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m, n)
}

int main()
{
    string S, T;
    map<long, char> ans;

    long N, M;
    cin >> N >> M >> S >> T;
    long L = lcm(N, M);
    //cout << L;

    for(long i = 0; i < N; i++) {
        ans[(L / N) * i] = S[i];
    }
    for(long i = 0; i < M; i++) {
        long idx = (L / M) * i;
        if(ans.find(idx) != ans.end() && ans[idx] != T[i]) {
            cout << -1;
            return 0;
        }
    }

    cout << L;
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve() {
    int r, g;
    cin >> r >> g;
    cout << 2*g-r << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int dx[] = {0, 1, 1, 0, -1, -1};
const int dy[] = {-1, 0, 1, 1, 0, -1};
 
using Point = pair<int, int>;
 
int main() {
  int T;
  cin >> T;
  cin.ignore();  
  while(T--) {
    string s, t, sp;    
    //cin >> s >> t >> sp;
    getline(cin, s);
    getline(cin, t);
    getline(cin, sp);
    if(s.size() != t.size()) {
      cout << "false" << endl;
      continue;
    }
    int x = 0, y = 0;
    set<Point> vis;
    vis.insert(Point(0, 0));
    for(char c : s) {
      int k = c-'a';
      x += dx[k], y += dy[k];
      vis.insert(Point(x, y));
    }
    for(int i = 0; i < 6; i++) {
      for(Point p : vis) {
    set<Point> st;
    int x = p.first, y = p.second;
    st.insert(Point(x, y));
    for(char c : t) {
      int k = c-'a';
      x += dx[(k+i)%6], y += dy[(k+i)%6];
      if(!vis.count(Point(x, y))) {
        break;
      } else {
        st.insert(Point(x, y));
      }
    }
    if(st == vis) {
      cout << "true" << endl;
      goto end;
    }
      }
    }
    cout << "false" << endl;
  end: ;
  }
  return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long
#define pb push_back 
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; 
	
    string s; 
    cin >> s; 
    int n = s.size() ; 
    vector<int> a(n+1) ;
    int cur = 0 ;  
    for(int i = 0 ; i < n  ; ++i) {
        if(s[i] == '<') {
            a[i+1] = max(a[i]+1, a[i+1]) ; 
        }
         
    } 
    for(int i = n; i>= 0 ; --i) {
        if(s[i]=='>') {
            a[i] = max(a[i+1]+1, a[i]) ; 
        }
       
    }
    
    ll sum = 0 ;  
    for(int i = 0 ; i <= n ;++i) {
        //cout << a[i] << " " ;
        sum += a[i] ; 
    }
    cout << sum ; 
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> a(q), cnt(n), ans(n);
    for (int i = 0; i < q; i++)
    {
        cin>>a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    for (int i = 0; i < n; i++)
    {
        ans[i] = k - (q - cnt[i]);
    }
    for (int i = 0; i < n; i++)
    {
        if(ans[i]>0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vc<pi> A;
    rep(i,N){
        int a; cin >> a;
        A.eb(a,i+1);
    }
    sort(all(A));

    if(A[0].fi >= 0){
        cout << N-1 << endl;
        rep(i,N-1){
            cout << i+1 <<" "<< i+2 << endl;;
        }
    }

    else if(A[N-1].fi <= 0){
        cout << N-1 << endl;
        rep(i,N-1){
            cout << N-i << " " << N-i-1 << endl;; 
        }
    }

    else if(abs(A[0].fi) > abs(A[N-1].fi)){
        cout << 2*N-1 << endl;
        rep(i,N){
            cout << A[0].se << " " << i+1 << endl;
        }
        rep(i,N-1){
            cout << N-i << " " << N-i-1 << endl;; 
        }
    }

    else {
        cout << 2*N-1 << endl;
        rep(i,N){
            cout << A[N-1].se << " " << i+1 << endl;
        }
        rep(i,N-1){
            cout << i+1 << " " << i+2 << endl;
        }
    }
}

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

struct Card{
    char a;
    int value;
};

void bubble_sort(Card A[],int n){
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            if(A[j].value>A[j+1].value){
                Card t=A[j];
                A[j]=A[j+1];
                A[j+1]=t;
            }
        }
    }
    return;
}

void selection_sort(Card A[],int n){
    for(int i=0;i<n-1;i++){
        int k=i;
        for(int j=i+1;j<n;j++){
            if(A[k].value>A[j].value)k=j;
        }
        if(k!=i){
            Card t=A[k];
            A[k]=A[i];
            A[i]=t;
        }
    }
    return;
}

int main(){
    Card A[36],B[36];
    int n;
    bool b=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i].a>>A[i].value;
        B[i]=A[i];
    }
    bubble_sort(A,n);
    selection_sort(B,n);
    for(int i=0;i<n;i++){
        if(i==0)cout<<A[i].a<<A[i].value;
        else cout<<' '<<A[i].a<<A[i].value;
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    for(int i=0;i<n;i++){
        if(i==0)cout<<B[i].a<<B[i].value;
        else cout<<' '<<B[i].a<<B[i].value;
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        if(A[i].a!=B[i].a)b=0;
    }
    if(b)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
int main(void)
{
	int i,a[3],fn=0,sn=0;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	for(i=0;i<3;i++){
		if(a[i] == 5) fn++;
		else if(a[i] == 7) sn++;
	}
	if((fn == 2) && (sn == 1)) printf("YES");
	else printf("NO");

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll L = C / __gcd(C, D) * D;
    ll n = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / L - (A - 1) / L);
    cout << (B - A + 1) - n;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

typedef long long ll;

vector<int> parent;
vector<int> cardinality;
vector<int> height;
ll N,M;

void init(int n) {
    parent.assign(n,-1);
    cardinality.assign(n,1);
    height.assign(n,0);
    
    for (int i=0; i<n; i++) {
        parent[i] = i;
    }
}

int find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        return parent[x] = find(parent[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }
    if (height[x] < height[y]) {
        parent[x] = y;
        cardinality[y] += cardinality[x];
    } else {
        parent[y] = x;
        cardinality[x] += cardinality[y];
        if (height[x] == height[y]) {
            ++height[x];
        }
    }
}

int size(int x) {
    x = find(x);
    return cardinality[x];
}

int main() {
    cin >> N >> M;
    
    vector<ll> A(M);
    vector<ll> B(M);
    for (int i=0; i<M; i++) {
        cin >> A[i] >> B[i];
    }

    init(N+1);
    vector<ll> answer(M+1);
    answer[M] = (N * (N-1))/2;
    
    for (int i=M-1; 0<=i; i--) {
        auto a = A[i];
        auto b = B[i];
        
        if (find(a) ==  find(b)) {
            answer[i] = answer[i+1];
        } else {
            auto sizea = size(a);
            auto sizeb = size(b);
            answer[i] = answer[i+1] - sizea * sizeb;
        }
        unite(a,b);
    }

    for (int i=1; i<=M; i++) {
        cout << answer[i] << endl;
    }
}


Measured memory_bytes: 4864
#include <stdio.h>
 
int cal(int z){
	int temp, fin;
	temp=z%1000;
	if(temp>0){
		fin=1000-temp;
	}
	else{
		fin=0;
	}
	return fin;
}
 
int main(){
	double x,y;
	scanf("%lf", &x);
	printf("%d",cal(x));
	return 0;
}

Measured memory_bytes: 1704
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		mathClass keisan;
		Scanner scan = new Scanner(System.in);
		int queueAmount = scan.nextInt();
		int qTime = scan.nextInt();
		int totalTime = 0;
		int amari = 0;
		int[] proNum = new int[queueAmount+1];	//?????°?????????????????????1????????¨??????
		String[] proID = new String[queueAmount+1];

		for(int i=0; i<queueAmount; i++){
			proID[i] = scan.next();
			proNum[i] = scan.nextInt();
		}
		int dataTop = 0;
		int dataBottom = queueAmount-1;
		proNum[queueAmount] = 0;
		
		while(true){
			//?????????????????????????????????????????????
			if(proNum[dataTop] <= qTime){			
				totalTime = totalTime + proNum[dataTop];
				System.out.println(proID[dataTop]+" "+(totalTime) );
				//???????????§?????£??????break
				if(dataTop == dataBottom) break;
				
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
			else{
				proNum[dataTop] -= qTime;
				totalTime += qTime;
				//????????????????°????1???????????????????????§????????£??????0?????????
//				System.out.println("?????? "+proID[dataTop]+" "+proNum[dataTop]);
				dataBottom += 1;
				if(dataBottom > queueAmount){
					dataBottom = 0;
				}
				//???????°???????????????????????????£??\
				proNum[dataBottom] = proNum[dataTop];
				proID[dataBottom] = proID[dataTop];
				dataTop += 1;
				if(dataTop > queueAmount){
					dataTop = 0;
				}
			}
//			System.out.println("totaltime is "+totalTime);
		}




	}
}
class mathClass{

	public mathClass(){

	}

	//?????????????????????
	public int shisokuEnzan(String stringX,String stringY,String op){
		int ret =0;
		int x =Integer.parseInt(stringX);
		int y =Integer.parseInt(stringY);
//		System.out.println(x+" "+op+" "+y+" wo okonau");

		if(op.charAt(0) == '+'){
			ret = x + y;
		}
		if(op.charAt(0) == '-'){
			ret = x - y;
		}
		if(op.charAt(0) == '*'){
			ret = x * y;
		}
		if(op.charAt(0) == '/'){
			ret = x / y;
		}
		return ret;
	}

	//???????????¨?????????
	public void disp(int[] ary){
		for(int i=0;i<ary.length;i++){
			System.out.println(ary[i]);
		}
	}

}

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

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

    deque<int> ans;
    int pos = n;
    while(pos>0){
        for(int i=min(pos,m);i>0;--i){
            if(s[pos-i]=='0'){
                pos -= i;
                ans.push_front(i);
                goto l_next;
            }
        }
        cout << -1 << endl;
        return 0;
        l_next:;
    }

    cout << ans.front();
    ans.pop_front();
    while(!ans.empty()){
        cout << " " << ans.front();
        ans.pop_front();
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 868