akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public char[][] tile;
    public int[][] movedTile;

    public static void main(String[] args) throws IOException {
        BufferedReader bReader =
                new BufferedReader(new InputStreamReader(System.in));
        String inputedStr;

        while (!"0 0".equals(inputedStr = bReader.readLine())) {
            boolean loopFlag = true;
            String[] editedstr = inputedStr.split(" ");
            int X = Integer.parseInt(editedstr[0]);
            int Y = Integer.parseInt(editedstr[1]);
            char[][] tile = new char[X][Y];
            int[][] movedTile = new int[X][Y];
            int xcurrentloc = 0;
            int ycurrentloc = 0;
            for (int i = 0; i < X; i++) {
                tile[i] = bReader.readLine().toCharArray();
            }
            while (movedTile[xcurrentloc][ycurrentloc] != 1) {
                if (tile[xcurrentloc][ycurrentloc] == '>') {
                    movedTile[xcurrentloc][ycurrentloc++] = 1;
                } else if (tile[xcurrentloc][ycurrentloc] == '<') {
                    movedTile[xcurrentloc][ycurrentloc--] = 1;
                } else if (tile[xcurrentloc][ycurrentloc] == 'v') {
                    movedTile[xcurrentloc++][ycurrentloc] = 1;
                } else if (tile[xcurrentloc][ycurrentloc] == '^') {
                    movedTile[xcurrentloc--][ycurrentloc] = 1;
                } else if (tile[xcurrentloc][ycurrentloc] == '.') {
                    loopFlag = false;
                    break;
                } else {
                }
            }
            if (loopFlag) {
                System.out.println("LOOP");
                loopFlag = true;
            } else {
                System.out.println(ycurrentloc + " " + xcurrentloc);
            }
        }
    }
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n;
string s, t;

vector<pair<int, int>> get_lines(string s) {
  vector<pair<int, int>> ans;
  ans.push_back(s[0] == '0' ? make_pair(0, 0) : make_pair(1, 0));
  for (int i = 1; i < n; ++i)
    if (s[i] != s[i - 1])
      ans.push_back({ans.back().first ^ 1, i});
  ans.push_back({ans.back().first ^ 1, n});
  return ans;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s >> t;
  vector<pair<int, int>> a = get_lines(s);
  vector<pair<int, int>> b = get_lines(t);
  reverse(b.begin(), b.end());
  for (int i = 0; i < 5005; ++i)
    b.push_back({b.back().first ^ 1, 0});
  reverse(b.begin(), b.end());
  for (int i = 0; i < 5005; ++i)
    b.push_back({b.back().first ^ 1, n});
  int ans = 2e9;
  for (int i = 0; i < b.size(); ++i) {
    if (b[i].first == a[0].first) {
      int x = 0, y = i;
      int cur = 0;
      while (y >= 0) {
        int u = 0, v = b[y].second;
        cur += v - u;
        --y;
      }
      x = 1, y = i + 1;
      while (y < b.size()) {
        int u = (x < a.size() ? a[x].second : n);
        int v = b[y].second;
        cur += abs(v - u);
        ++x;
        ++y;
      }
      ans = min(ans, cur);
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 768
N, W = map(int, input().split())
item = [tuple(map(int, input().split())) for _ in range(N)]

w1 = item[0][0]
V = [[] for _ in range(4)]
for w, v in item:
    V[w - w1].append(v)
for i in range(4):
    V[i].sort(reverse=True)

cnt = [0] * 4
for i in range(4):
    cnt[i] = len(V[i])

ans = 0
for i in range(cnt[0] + 1):
    S0 = sum(V[0][:i])
    W0 = i * w1
    for j in range(cnt[1] + 1):
        S1 = sum(V[1][:j])
        W1 = j * (w1 + 1)
        for k in range(cnt[2] + 1):
            S2 = sum(V[2][:k])
            W2 = k * (w1 + 2)
            for l in range(cnt[3] + 1):
                S3 = sum(V[3][:l])
                W3 = l * (w1 + 3)
                if W0 + W1 + W2 + W3 <= W:
                    ans = max(ans, S0 + S1 + S2 + S3)

print(ans)


Measured memory_bytes: 46300
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let _n = get!(usize);
    let v = get!([usize]);
    let mut ans = 0;
    for i in v.iter() {
        ans += i.trailing_zeros();
    }
    println!("{}", ans);
}


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


def main():
    N = int(input())
    S = input().strip()
    if len(S) % 2 != 0:
        print("No")
        return
    if S[:len(S)//2] == S[len(S)//2:]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod=1e9+7;

ll dp[100][4][4][4];

int main(){
  int n;
  cin >> n;
  dp[0][3][3][3]=1;
  rep(i,n){
    rep(j,4){
      rep(k,4){
        rep(l,4){
          rep(m,4){
            if(k==0&&l==1&&m==2 || k==1&&l==0&&m==2 || k==0&&l==2&&m==1 ||j==0&&l==1&&m==2|| j==0&&k==1&&m==2)
              continue;
            dp[i+1][k][l][m]+=dp[i][j][k][l];
            dp[i+1][k][l][m]%=mod;
          }
        }
      }
    }
  }
  ll sum=0;
  rep(i,4){
    rep(j,4){
      rep(k,4){
        sum+=dp[n][i][j][k];
        sum%=mod;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

class Mint
{
private:
    ll x;
public:
    Mint(ll x = 0) :x((x% mod + mod) % mod) {}
    ll Get() const { return x; }
    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 { return Mint(*this) += a; }
    Mint operator-(const Mint a) const { return Mint(*this) -= a; }
    Mint operator*(const Mint a) const { return Mint(*this) *= 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 { return Mint(*this) /= a; }
};
inline ostream& operator<<(ostream& os, const Mint& a) { return os << a.Get(); }

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	vector<Mint> s(n);
	s[0] = a[0];
	for (int i = 1; i < n; i++) {
		s[i] = s[i - 1] + a[i];
	}

    Mint ans = Mint();
	for (ll i = 0; i < n - 1; i++) {
        ans += Mint(a[i]) * (s[n - 1] - s[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6408
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    cin>>n;
    vector<ll> v(n);  // index -> value
    vector<PLL> s(n); // {value, index}
    vector<ll> u(n);  // index -> strength
    vector<ll> p(n);  // stlength -> value

    rep(i,0,n){
        cin>>v[i];
        s[i] = PLL(v[i],i );
    }
    sort(begin(s),end(s));
    rep(i,0,n){ // strength
        u[ s[i].second ]=i;
        p[i] = s[i].first;
    }
    // rep(i,0,n){
    //     cout<<i<<" "<<u[i]<<endl;
    // }

    // n=6
    // 0 1 2 3(=n/2) 4 5

    rep(i,0,n){
        ll t, strength = u[i];
        if (strength == n/2) {
            t = p[n/2-1];
        } else if(strength > n/2){
            t = p[n/2-1];
        } else if(strength < n/2) {
            t = p[n/2];
        }
        // cout<<"stlength="<<strength<<endl;
        cout<<t<<endl;
    }

    return 0;
}


Measured memory_bytes: 9984
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

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

    sort(s.begin(),s.end());
    int sum = 0;
    rep(i,n) sum += s[i];

    if(sum % 10 != 0){cout << sum << endl; return 0; }
    rep(i,n){
        if((sum - s[i]) % 10 != 0){
            cout << sum - s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
//package unk;

import java.util.Scanner;

/**
 * @author sguar <shugangcao@gmail.com>
 * welcome to kuaishou
 * Created on 2020-01-10
 */
public class Main {

    private int a1 = 1;
    private int a2 = 1_000_000_000;
    public void run() {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int k = cin.nextInt();
        int S = cin.nextInt();
        int unUsed = a2;
        if (S == a2) {
            unUsed = a1;
        }
        for (int i = 1; i <= k; i++) {
            System.out.print(S);
            if (i < k) System.out.print(" ");
        }
        if (k < n) {
            for (int i = k + 1; i <= n; i++) {
                System.out.print(" " + unUsed);
            }
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 42556
<?php

function fget_array($dlmt = null) {
    $input = trim(fgets(STDIN));
    return $dlmt ? explode($dlmt, $input) : str_split($input);
}

list($n, $k) = fget_array(' ');
$h = fget_array(' ');
$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    if ($h[$i] >= $k) $cnt++;
}
echo $cnt;
?>


Measured memory_bytes: 12792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

//
int main(void) {
    int N,M;
    cin >> N >> M;
    vector<int> a(N),b(N);
    rep(i,N) cin >> a.at(i) >> b.at(i);
    vector<int> indices(a.size());
    iota(all(indices), 0);
    sort(all(indices),
        [&a](int i1, int i2) { return a[i1] < a[i2]; });
    ll ans=0;
    int cnt=0;
    int tmp=0;
    while(cnt<M){
        while(cnt<M&&b.at(indices.at(tmp))>0){
            ans += a.at(indices.at(tmp));
            b.at(indices.at(tmp))--;
            cnt++;
        }
        tmp++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        H: usize,
        W: usize,
        A: [chars; H],
    }
    let mut hh = vec![];
    let mut ww = vec![];
    for h in 0..H{
        for w in 0..W{
            if A[h][w]=='#'{
                hh.push(h);
            }
        }
    }
    for w in 0..W{
        for h in 0..H{
            if A[h][w]=='#'{
                ww.push(w);
            }
        }
    }
    for h in 0..H{
        for w in 0..W{
            if hh.contains(&h) && ww.contains(&w){
                print!("{}",A[h][w]);
            }
        }
        if hh.contains(&h){
            println!("{}","");
        }
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>

#define ll long long int
#define llu unsigned long long int
#define N 3001
using namespace std;
vector<vector<int>> dp(N,vector<int>(N,-1));
int main(){
string s,t;
cin>>s>>t;
if(s[0]==t[0]){
	dp[0][0]=1;
}else dp[0][0]=0;

for(int i=0;i<s.size();i++){
	for(int j=0;j<t.size();j++){
		if(i==0&&j!=0){
				if(s[i]==t[j]){
					dp[i][j]=1;
				}else dp[i][j]=dp[i][j-1];
		}
		if(i!=0&&j==0){
				if(s[i]==t[j]){
					dp[i][j]=1;
				}else dp[i][j]=dp[i-1][j];
		}
		if(dp[i][j]==-1){
			if(s[i]==t[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
}
}
int x=dp[s.size()-1][t.size()-1];
// for(int i=0;i<s.size();i++){
// 	cout<<s[i]<<" ";
// 	for(int j=0;j<t.size();j++)
// 	cout<<dp[i][j]<<" ";
char a[x+1];
a[x]='\0';
for(int i=s.size()-1,j=t.size()-1;x>0;){
	if(i!=0&&dp[i][j]==dp[i-1][j]){
		--i;
	}else if(j!=0&&dp[i][j]==dp[i][j-1]){
		--j;
	}else{
		a[x-1]=s[i];
		--x;
		--i;--j;
	}
	}
	
	cout<<a;

return 0;
}


Measured memory_bytes: 35584
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var ks = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long res = 0;
        for (int x = 0; x <= ks[0]; x++)
        {
            for (int y = 0; y <= ks[0]; y++)
            {
                var z = ks[1] - x - y;
                if (0 <= z && z <= ks[0]) res++;
            }
        }
        Console.WriteLine(res);
    }
}


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

int main() {
  //入力
  int n;
  cin >>n;
  vector<int>flower(n);
  for(int i=0;i<n;i++)
  {
    cin >>flower[i];
  }

  //処理
  int ans=flower[0];
  for(int i=0;i<n-1;i++)
  {
    if(flower[i+1]-flower[i]>0)
    {
      ans+=flower[i+1]-flower[i];
    }
  }

  //出力
  cout << ans << endl;
}


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


int main() {
	
  int a,b,c ;
  cin >> a >> b >> c ;
  
  if ( a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 ) cout << "Possible" ;
  else cout << "Impossible" ;

}

Measured memory_bytes: 256
N = int(input())
M,A,R,C,H = 0,0,0,0,0
for i in range(N):
    S = input()
    if S[0] == "M":
        M += 1
    elif S[0] == "A":
        A += 1
    elif S[0] == "R":
        R += 1
    elif S[0] == "C":
        C += 1
    elif S[0] == "H":
        H += 1
ans = 0
MARCH = [M,A,R,C,H]
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += MARCH[i]*MARCH[j]*MARCH[k]
print(ans)

Measured memory_bytes: 9140
#include <iostream>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC110();
}

void ABC110(){
    int a,b,c,max;
    cin>>a>>b>>c;
    max=a;
    if(b>=max)max=b;
    if(c>=max)max=c;
    if(a==max)cout<<a*10+b+c<<endl;
    else if(b==max)cout<<b*10+a+c<<endl;
    else if(c==max)cout<<c*10+a+b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
using namespace std;
const int N=1005,mod=1e9+7;
int n,m,a,b,c,d; ll K; char s[N][N];
int ksm(int x,ll y){
	int s=1;
	for (;y;y>>=1,x=(ll)x*x%mod) if (y&1) s=(ll)s*x%mod;
	return s;
}
void upd(int &x,int y){x+=y; x-=x>=mod?mod:0;}
struct matrix{
	int a[2][2],n,m;
	matrix(int n,int m):n(n),m(m){memset(a,0,sizeof(a));}
	matrix operator * (matrix y){
		matrix x=*this,z(x.n,y.m);
		rep (i,0,z.n-1)
			rep (j,0,z.m-1)
				rep (k,0,x.m-1)
					upd(z.a[i][j],(ll)x.a[i][k]*y.a[k][j]%mod);
		return z;
	}
	matrix operator ^ (ll p){
		matrix x=*this,y(n,m);
		rep (i,0,n-1) y.a[i][i]=1;
		for (;p;p>>=1,x=x*x) if (p&1) y=y*x;
		return y;
	}
};
void solve(int a,int b,int c){
	matrix t(2,2); t.a[0][0]=a,t.a[0][1]=mod-b,t.a[1][1]=c;
	matrix f(2,1); f.a[0][0]=f.a[1][0]=1;
	f=(t^K)*f;
	printf("%d\n",f.a[0][0]);
}
int main(){
	scanf("%d%d%lld",&n,&m,&K);
	if (!K) return puts("1"),0; K--;
	rep (i,1,n){
		scanf("%s",s[i]+1),c+=s[i][1]=='#'&&s[i][m]=='#';
		rep (j,1,m) a+=s[i][j]=='#';
	}
	rep (j,1,m) d+=s[1][j]=='#'&&s[n][j]=='#';
	if (c&&d) return puts("1"),0;
	if (!c&&!d) return printf("%d\n",ksm(a,K)),0;
	if (c) rep (i,1,n) rep (j,1,m-1) b+=s[i][j]=='#'&&s[i][j+1]=='#';
	if (d) rep (j,1,m) rep (i,1,n-1) b+=s[i][j]=='#'&&s[i+1][j]=='#';
	solve(a,b,c|d);
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int b[] = new int[N];
		int c[] = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		int dp[][] = new int[N][3];
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		for(int i = 1; i < N; i++) {
			dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + a[i];
			dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + b[i];
			dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + c[i];
		}
		System.out.println(Math.max(dp[N - 1][0], Math.max(dp[N - 1][1], dp[N - 1][2])));
	}
}


Measured memory_bytes: 95396
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 2e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e5+100;
const int mod = 1e9+7;
ll dp[upperlimit];
int val[upperlimit];
int wt[upperlimit];
int main() {
	int n,w;
	sd(n);sd(w);
	for(int i = 1; i <= n; i++){
		sd(wt[i]);sd(val[i]);
	}
	dp[0]=0;
	for(int i = 1; i < upperlimit; i++) dp[i]=INFLL;
	for(int i = n; i > 0; i--){
		for(int j = upperlimit-1; j >= val[i]; j--){
			dp[j]=min(dp[j],dp[j-val[i]]+wt[i]);
		}
	}
	for(int i = upperlimit-1; i >= 0; i--){
		if(dp[i]<=w){
			pd(i);break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
	int a;in_t(){cin>>a;}
	operator int() {return a;}
};
class ld_t{public:
	long double a;ld_t(){cin>>a;}
	operator long double() {return a;}
};
vector<int>make;//あるべき場所
vector<vector<int>>kati;
int solve(int now){
	vector<int>ans;
	for(int i=0;i<kati[now].size();i++){
		ans.pub(solve(kati[now][i]));
	}
	sort(ans.rbegin(),ans.rend());
	int ret=0;
	for(int i=0;i<ans.size();i++){maxeq(ret,ans[i]+i+1);}
	return ret;
}
int main(void){
	in_t n;
	int i,j;
	make.res(n);
	kati.res(n);
	for(i=1;i<n;i++){
		int a;cin>>a;a--;
		make[i]=a;
		kati[a].pub(i);
	}
	cout<<solve(0)<<endl;
	return 0;
}

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

int main(){
    char c;
    cin >> c;
    string abc = "abcdefghijklmnopqrstuvwxyz";
    for (int i=0;i<26;i++){
        if (abc.at(i)==c){
            cout << abc.at(i+1) << endl;
        }
    }

}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var l = s.length;
  var ans = l;
  for(var i = 0; i < 26; i++){
    var mx = 0;
    var n = 0;
    for(var j = 0; j < l; j++){
      if(s[j].charCodeAt()-97 === i){
        if(n > mx)mx = n;
        n = 0;
      }else n++;
    }
    if(n > mx)mx = n;
    if(mx < ans)ans = mx;
  }
  return ans;
}

Measured memory_bytes: 7624
K = int(input())
al = []

def sums(i):
    s = 0
    old = i
    while i>0:
        s += i%10
        i = i//10
    return (s,old)

for i in range(1,1000):
    al.append(sums(i))
for j in range(4,16):
    for k in range(100,1000):
        al.append(sums(k*(10**(j-3))+10**(j-3)-1))
anslist = []
al.reverse()
maxs,maxi = sums(10**15)
for j in al:
    if maxs*j[1] <= maxi*j[0]:
        anslist.append(j[1])
        maxs = j[0]
        maxi = j[1]
anslist.reverse()

for i in range(K):
    print(anslist[i])

Measured memory_bytes: 4288
from collections import deque
N = int(input())
v = list(map(int, input().split()))

v = sorted(v)
v = deque(v)


for i in range(N - 1):
    cal = 0
    cal += v.popleft()
    cal += v.popleft()
    cal = cal / 2
    v.appendleft(cal)

print(v.pop())


Measured memory_bytes: 3316
import java.util.Scanner;

class Pair<F, S>{
	F first;
	S second;
	public Pair(F f, S s) {
		first = f;
		second = s;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 66192
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n,d;cin >> n>>d;
  int out = n/(2*d+1);
  if(n%(2*d+1) !=0) ++out;
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s, t;
    cin >> s >> t;
    int n = s.length();
    vector<int> tableS(26, -1), tableT(26, -1);
    for(int i = 0; i < n; ++i){
        int x = s[i] - 'a', y = t[i] - 'a';
        if(tableS[x] == -1){
            tableS[x] = y;
        }
        else{
            if(tableS[x] != y){
                cout << "No\n";
                return 0;
            }
        }
        if(tableT[y] == -1){
            tableT[y] = x;
        }
        else{
            if(tableT[y] != x){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 916
#define _LIBCPP_DEBUG 0
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int h, w, k;
vector<string> s;
vector<int> st;
vector<vector<int>> ans;

int main(){
    cin >> h >> w >> k;
    s.resize(h);
    st.assign(h, 0);
    ans.assign(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
        cin >> s.at(i);
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') st.at(i)++;
        }
    }

    int num = 0;
    for (int i = 0; i < h; i++) {
        if (st.at(i) == 0) continue;
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') num++;
            ans.at(i).at(j) = num;
        }
        for (int j = 0; j < w; j++) {
            if (s.at(i).at(j) == '#') break;
            ans.at(i).at(j)++;
        }
    }

    for (int i = 0; i < h-1; i++) {
        if (st.at(i+1) == 0) {
            for (int j = 0; j < w; j++) {
                ans.at(i+1).at(j) = ans.at(i).at(j);
            }
        }
    }
    for (int i = h-1; i > 0; i--) {
        if (st.at(i-1) == 0) {
            for (int j= 0; j < w; j++) {
                ans.at(i-1).at(j) = ans.at(i).at(j);
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans.at(i).at(j) << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    vector<P> d(n);
    rep(i,n){
        ll p; cin >> p;
        d.emplace_back(p,i+1);
    }
    sort(all(d));
    reverse(all(d));
    
    multiset<ll> left,right;
    ll ans=0;

    left.insert(0);
    left.insert(0);
    left.insert(-d[0].second);
    right.insert(d[0].second);
    right.insert(n+1);
    right.insert(n+1);

    for(int i=1; i<n; i++){
        ll now=d[i].first;
        ll id=d[i].second;
        ll l1=*left.lower_bound(-id);
        left.erase(left.find(l1));
        ll l2=*left.lower_bound(-id);
        left.insert(l1);
        ll r1=*right.lower_bound(id);
        right.erase(right.find(r1));
        ll r2=*right.lower_bound(id);
        right.insert(r1);
        //cout << l1 << l2 << r1 << r2 << endl;
        l1*=-1;
        l2*=-1;
        ans+=now*((id-l1)*(r2-r1)+(r1-id)*(l1-l2));
        left.insert(-id);
        right.insert(id);
    }

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

Measured memory_bytes: 15624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int main () {
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\n", a * b);
  return 0;
}

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

int main(void){
    int k; cin >> k;
    ll a = 7;
    int ans = 1;
    for(int i = 0; i < k; i++){
        if(a % k == 0) break;
        else{
            // 答えがあるなら、k回以内にどこかで k で割ったあまり 0 になる(どうして)
            a = 10 * a + 7;
            a %= k;
            ans++;
        }
    }
    // 桁数やばいことになる。どうしよう。

    if(ans != k+1) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll cube = a * b * c;
    ll ans = min({cube - a * b * (c / 2) * 2, cube - b * c * (a / 2) * 2, cube - a * c * (b / 2)* 2});
    cout << ans << endl;
}

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

int main(){
	int r,c,sum,all;
	cin >> r >> c;

	int t[r][c];

	for(int i=0;i<r;i++){
		sum = 0;
		for(int j=0;j<c;j++){
			cin >> t[i][j];
			cout << t[i][j] << " ";
			sum = sum + t[i][j];
		}
		cout << sum << endl;
	}

	all = 0;

	for(int j=0;j<c;j++){
		sum = 0;
		for(int i=0;i<r;i++){
			sum = sum + t[i][j];
		}
		cout << sum << " ";
		all = all + sum;
	}

	cout << all << endl;

}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 S, s;
  cin >> S;

  vi ans(S+1, 0);
  i64 T = 0;
  i64 NUM = 1000000007LL;
  if(S < 3) {
    cout << 0 << endl;
    return 0;
  }
  
  ans[3] = 1;
  REP(4, S+1, s) {
    T += ans[s-3];
    T %= NUM;
    ans[s] = T+1;
    ans[s] %= NUM;
  }
  cout << ans[S] << endl;

  return 0;
}


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

void conv(int n, int i) {
    if(n==0){
        cout << 0;
        return;
    }
    if(n == i) {
        cout << 1;
        return;
    }
    int a;
    if(n % (i * (-2)) != 0) {
        n -= i;
        a = 1;
    } else
        a = 0;
    i *= -2;
    conv(n, i);
    cout << a;
}

int main() {
    int N;
    cin >> N;
    conv(N, 1);
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// LHiC氏.
// https://atcoder.jp/contests/code-festival-2017-qualb/submissions/2148130
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MX = 2010;
const LL MOD = 1e9 + 7;
int a, b;
int cnk[MX * 2][MX * 2];
int dp1[MX][MX];
int cc[MX][MX];

int main(){
    scanf("%d %d", &a, &b);
    rep(i, MX * 2){
        rep(j, MX * 2){
            if(i == j || j == 0) cnk[i][j] = 1;
            else if(j > i)       cnk[i][j] = 0;
            else                 cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % MOD;
        }
    }
    rep(i, MX){
        cc[i][0] = 1;
        repx(j, 1, i + 1) cc[i][j] = (cc[i][j - 1] + cnk[i][j]) % MOD;
    }
    rep(i, a + 1){
        rep(j, b + 1){
            if(i == 0 && j == 0) dp1[i][j] = 1;
            if(i)                dp1[i][j] = dp1[i - 1][j];
            if(j)                dp1[i][j] = (dp1[i][j] + cc[j - 1][min(j - 1, i)]) % MOD;
        }
    }
    LL ans = 0;
    rep(i, a + 1){
        rep(j, b){
            if(a - i >= (b - 1 - j)) ans = (ans + LL(cnk[b - 1][j]) * dp1[a - i - (b - 1 - j)][b - 1 - j]) % MOD;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

int n, x=1, temp=1;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    int b[n];
    for (int i=0; i<n; i++) b[i] = -1;
    b[0] = a[0];
    for (int i=1; i<n; i++) {
        if (a[i] == b[x-1]) temp =0;
        else {b[x] = a[i];
        x++;} temp = 1;
    }
    for (int i=0; i<x-1; i++) cout << b[i] << " ";
    cout << b[x-1] << endl;
} 


Measured memory_bytes: 3896
#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;

namespace tree {
struct union_find {
  vector<int> par, rank, size;
  int compnum;

  union_find(int N) {
    compnum = N;
    par.resize(N), rank.resize(N), size.resize(N);
    for(int i=0; i<N; i++) {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  int root(int x) {
    return par[x] == x ? x : 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, size[y] += size[x];
    } else {
      par[y] = x, size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
    compnum--;
  }

  int operator[](int x) { return root(x); }
  void operator()(int x, int y) { return unite(x, y); }

  bool same(int x, int y) { return root(x) == root(y); }
  int size_of(int x) { return size[root(x)]; }
  int num_of_comps() { return compnum; }
};
}

int main() {

  int N, M; cin >> N >> M;
  vector<vector<int>> user(M);

  tree::union_find uf(N);

  rep(i, N) {
    int K; cin >> K;
    rep(j, K) {
      int l; cin >> l; l --;
      user[l].push_back(i);
    }
  }

  for(auto& e: user) {
    if(e.size()) {
      int fst = e[0];
      REP(i, 1, (int)e.size()) {
        uf(fst, e[i]);
      }
    }
  }

//  cout << uf.num_of_comps() << endl;

  cout << (uf.num_of_comps() == 1 ? "YES" : "NO") << endl;
  
  return 0;
}

Measured memory_bytes: 4608
year = 2019

l, r = map(int, input().split())
d = l // year
l %= year
r -= d * year
if l == 0 or r >= year:
    print(0)
else:
    ans = year
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            res = i * j % year
            ans = min(ans, res)
            if res == ans: param = (i, j)
    print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=1e5+10;
int n,len;
char ss[N],cnt=1;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
//	freopen("Next Letter.in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s",ss+1); read(n);
	len=strlen(ss+1);
	for(int i=1;i<=len && n;i++)
	{
		if(i==len)
		{
			n%=26;
			ss[i]= ss[i]+n>'z' ? ss[i]+n-26 : ss[i]+n;
			break;
		}
		if(ss[i]=='a') continue;
		if(27-(ss[i]-'a'+1)<=n)
		{
			n-=(27-(ss[i]-'a'+1));
			ss[i]='a';
		}
		/*else 
		{
			n%=26;
			ss[len]= ss[len]+n>'z' ? ss[len]+n-26 : ss[len]+n;
			break;
		}*/
	}
	printf("%s\n",ss+1);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 384
'import sys'
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)


Measured memory_bytes: 5600
n = int(input())
S = [input() for _ in range(n)]
m = int(input())
T = [input() for _ in range(m)]
ans = 0
for x in set(S):
    score = 0
    score += sum([s == x for s in S])
    score -= sum([t == x for t in T])
    ans = max(ans, score)
print(ans)

Measured memory_bytes: 3064
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll N, M;
	cin >> N >> M;
	pair<ll, ll> AB[N];
	rep(i, N){
		ll a, b;
		cin >> a >> b;
		AB[i] = make_pair(a, b);
	}
	sort(AB, AB+N);
	
	ll ans=0, it=0, cnt=0;
	rep(i, M){
		ans += AB[it].fs;
		cnt++;
		if (cnt==AB[it].sc){
			it++;
			cnt=0;
		}
	}
	cout << ans << endl;

}








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

int main(){
  ll n;
  cin >> n;
  map<ll,ll> mp;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    mp[a[i]]++;
  }
  ll sum=0;
  for(int i=1; i<=n; i++){
    sum +=  mp[i]*(mp[i] - 1)/2;
  }
  rep(i,n){
    ll v = mp[a[i]];
    ll ans = sum - v*(v-1)/2 + (v-1)*(v-2)/2;
    cout << ans << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N;
ll D[13];

bool dfs(vector<ll> &v,ll d,ll s){
    if(d == 13) return true;
    if(D[d] == 0) return dfs(v, d+1, s);
    if(D[d] == 2){
        if(d*2 < s || 24-d*2 < s) return false;
        for(auto &e : v){
            if(abs(e-d)<s || 24 - abs(e-d)<s) return false;
            if(abs(e-(24-d))<s || 24 - abs(e-(24-d))<s) return false;
        }
        v.push_back(d);
        v.push_back(24-d);
        bool f = dfs(v,d+1,s);
        v.pop_back();
        v.pop_back();
        return f;
    }
    bool b;
    b = true;
    for(auto &e : v){
        if(abs(e-d)<s || 24 - abs(e-d)<s) b = false;
    }
    if(b){
        v.push_back(d);
        bool f = dfs(v,d+1,s);
        v.pop_back();
        if(f) return true;
    }
    b = true;
    for(auto &e : v){
        if(abs(e-(24-d))<s || 24 - abs(e-(24-d))<s) return false;
    }
    if(b && d != 12){
        v.push_back(24-d);
        bool f = dfs(v,d+1,s);
        v.pop_back();
        if(f) return true;
    }
    return false;
}

bool check(ll s){
    vector<ll> v;
    v.push_back(0);
    return dfs(v,1,s);
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        ll d;
        cin >> d;
        D[d]++;
    }
    if(D[0]>0){
        cout << 0 << endl;
        return 0;
    }
    for(int i=1;i<=11;i++){
        if(D[i] > 2){
            cout << 0 << endl;
            return 0;
        }
    }
    if(D[12] > 1){
        cout << 0 << endl;
        return 0;
    }
    ll max_s = 24 / (N+1);
    for(int s = max_s;s > 0;s--){
        if(check(s)){
            cout << s << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
c = 4 * 7
n = int(input())
if n == c:
    print("Yes")
    exit()
m = n % c
i = n
while 0 < i:
    j = i
    while 0 < j:
        j -= 7
        if j == 0:
            print("Yes")
            exit()
    i -= 4
    if i == 0:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int  n = sc.nextInt();
   List<Integer> a = new ArrayList<>();
   for(int i = 0;i < n;i++){
       a.add(sc.nextInt());
   }
   int max = a.get(0);
   int min = a.get(0);
   for(int i = 1; i < n ; i++){
     if(a.get(i) > max){
       max = a.get(i);
     }
     if(a.get(i) < min){
       min = a.get(i);
     }
   }
   System.out.println(max - min);
 }

}


Measured memory_bytes: 21844
s=input()
S=set(s)
ans=float("inf")
for x in S:
  count=0
  t=s
  n=len(set(t))
  while n>1:
    count+=1
    tt=""
    for i in range(len(t)-1):
      if t[i]==x or t[i+1]==x:
        tt+=x
      else:
        tt+=t[i]
    t=tt
    n=len(set(t))
  ans=min(ans,count)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <queue>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())


// 木構造を作る。

int main()
{
	string S;
	cin >> S;
	int a,z;
	REP(i,S.size()){
		if(S[i]=='A'){
			a=i;
			break;
		}
	}
	for (int i = S.size()-1; i >=0 ; --i)
	{
		if(S[i]=='Z'){
			z=i;
			break;
		}
	}
	cout << z-a+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
	int S = 0;
	
	scanf("%d", &S);
	
	int h = S / 3600;
	int m = (S % 3600) / 60;
	int s = (S % 3600) % 60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


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

int main () {
    string line;
    while (cin >> line) {
        int o = 0, x = 0;
        char prev = line[0];
        if (line[0] == 'o') {
            o++;
        } else {
            x++;
        }
        for (int i = 1, size = line.size(); i < size; i++) {
            if (prev == 'x' && line[i] == 'o') {
                o++;
                prev = 'o';
            } else if (prev == 'o' && line[i] == 'x') {
                x++;
                prev = 'x';
            }
        }
        if (o >= x) {
            cout << 'o' << endl;
        } else {
            cout << 'x' << endl;
        }
    }
}

Measured memory_bytes: 1172
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //int answer = 0;
        long answer=0;
        //String answer="Good";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long n = B-A+1;

        if(C==D)
        {
            long a=A/C;
            long b=B/C;
            long x=b-a;
            if (A%C==0) {x++;}
            answer=n-x;
            System.out.println(answer);
            return;
        }

        long a=A/C;
        long b=B/C;
        long p=b-a;
        if (A%C==0){p++;}

        a=A/D;
        b=B/D;
        long q=b-a;
        if (A%D==0){q++;}

        long e=(C*D)/e1.gcd(C,D);
        a=A/e;
        b=B/e;
        long r=b-a;
        if(A%e==0){r++;}

        answer=n-(p+q-r);
        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

class Euclid
{
    public static int gcd(int x,int y)//ユークリッドの互除法を使って2値の最大公約数を求める(int)
    {
        int tmp;
        if(x<y)
        {
            tmp=x;
            x=y;
            y=tmp;
        }
        if(x==0)//(x or y)=0の時は0でない時の値を返す
        {
            return y;
        }else if(y==0)
        {
            return x;
        }else
        {
            while ((tmp = x % y) != 0)
            {
                x = y;
                y = tmp;
            }
            return y;
        }
    }

    public static long gcd(long x,long y)//ユークリッドの互除法を使って2値の最大公約数を求める(long)
    {
        long tmp;
        if(x<y)
        {
            tmp=x;
            x=y;
            y=tmp;
        }
        if(x==0)//(x or y)=0の時は0でない時の値を返す
        {
            return y;
        }else if(y==0)
        {
            return x;
        }else
        {
            while ((tmp = x % y) != 0)
            {
                x = y;
                y = tmp;
            }
            return y;
        }
    }
}

Measured memory_bytes: 21844