akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll mi = 1e9, sum = 0;
	vector<ll> a(n);
	int cnt = 0;
	bool zero = false;
	rep(i,n){
		cin >> a[i];
		if(a[i] < 0){
			++cnt;
			chmin(mi, -a[i]);
			sum -= a[i];
		}
		else if(a[i] == 0) zero = true;
		else{
			chmin(mi, a[i]);
			sum += a[i];
		}
	}
	ll ans = sum;
	if(!zero && (cnt%2 == 1)) ans -= 2 * mi;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3992
n=int(input())
L=list(map(int,input().split()))
L.sort()
count=0
for i in range(n-2):
  for j in range(i+1,n-1):
    x=j+1
    y=n-1
    while y!=x+1 and y!=x:
      if L[i]+L[j]>L[(x+y)//2]:
        x=(x+y)//2
      else:
        y=(x+y)//2
    p=y if L[i]+L[j]>L[y] else x
    if L[i]+L[j]<=L[p]:
      count+=0
    else:
      count+=p-j
print(count)

Measured memory_bytes: 43612
#include <iostream>

using namespace std;

int main(){
    int bc = 0;
    int A, B;
    float T;
    cin >> A >> B >> T;
        int count = A;
    while (T + 0.5 > count){
        count += A;
        bc += B;
    }
    cout << bc;
    return 0;
}

Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

MOD = 10**9+7

H,W = map(int, input().split())
M = np.array([list(input().rstrip("\n")) for _ in range(H)]) == "."

D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * M[i]
    D[-i-1] = (D[-i] + 1) * M[-i-1]

for i in range(W):
    L[:,i] = (L[:,i-1] + 1) * M[:,i]
    R[:,-i-1] = (R[:,-i] + 1) * M[:,-i-1]

print(np.max(U+D+L+R)-3)

Measured memory_bytes: 219504
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7;//998244353 ;

ll a,w,t,r;

int main(){
  int n;
  cin >> n;
  string s[n];
  rep(i,n){
    cin >> s[i];
    if(s[i][0]=='A')a++;
    if(s[i][0]=='W')w++;
    if(s[i][0]=='T')t++;
    if(s[i][0]=='R')r++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << w << endl;
  cout << "TLE x " << t << endl;
  cout << "RE x " << r << endl;
return 0;}

Measured memory_bytes: 6744
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    int x = 1;
    int cnt = 1;
    while (1) {
        cin >> x;
        if (x == 0) break;
        cout << "Case " << cnt << ": " << x << '\n';
        cnt++;
    }

}



Measured memory_bytes: 3084
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a)
{
    for(LL i=2; i*i<=a; i++)
    {
        if(a%i==0)
            return false;
    }
    return true;
}
bool isVowel(char ch)
{
    ch=toupper(ch);
    if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E')
        return true;
    return false;
}
int toInt(string s)
{
    int sm;
    stringstream ss(s);
    ss>>sm;
    return sm;
}
template<typename T>inline T gcd(T a,T b)
{
    if(a<0)
        return gcd(-a,b);
    if(b<0)
        return gcd(a,-b);
    return (b==0)?a:gcd(b,a%b);
}
template<typename T>inline T lcm(T a,T b)
{
    if(a<0)
        return lcm(-a,b);
    if(b<0)
        return lcm(a,-b);
    return a*(b/gcd(a,b));
}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n>>m>>c)
    {
        vi a,b[n];
        rep(i,m)
        {
            vp(a,x);
        }
        rep(j,n)
        {
            rep(i,m)
            {
                cin>>x;
                b[j].pb(x);
            }
        }
        s=0;
        rep(i,n)
        {
            x=c;
            rep(j,m)
            {
                y=b[i][j]*a[j];
                x+=y;
            }
            if(x>0) s++;
        }
        cout<<s<<en;
}
}



Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(int(T) for T in input().split())
B = sorted(int(T) for T in input().split())
C = sorted(int(T) for T in input().split())
Count = 0
for TB in B:
    SmallA = bisect.bisect_left(A,TB)
    BigC   = N-bisect.bisect_right(C,TB)
    Count += SmallA*BigC
print(Count)

Measured memory_bytes: 29560
int main(){
    int h,w,a;
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0){
            break;
        }else{
            a=0;
            for(;h>0;h--){
                for(int i=0;i<w;i++){
                    if((a+i)%2==0){
                        putchar('#');
                    }else{
                        putchar('.');
                    }
                }
                a++;
                printf("\n");
            }
            printf("\n");
        }
    }
}



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

public class Main{

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

	private Scanner scan;

	public void mainrun() {
		scan = new Scanner(System.in);

		int n = 0;

		while((n = scan.nextInt()) != 0) {
			int[] h = new int[5];

			h[0] = n;
			for(int i = 1;i < h.length;i++) {
				h[i] = scan.nextInt();
			}

			boolean[] f = new boolean[3];
			Arrays.fill(f,false);

			for(int num : h) {
				f[num-1] = true;
			}

			int[] ans = new int [3];

			if(f[0] && f[1] && f[2] ||
				f[0] && !f[1] && !f[2] ||
				!f[0] && f[1] && !f[2] ||
				!f[0] && !f[1] && f[2]
			) {
				Arrays.fill(ans, 3);
			}else if(f[0] && f[1] && !f[2] ) {
				ans[0] = 1;
				ans[1] = 2;
			}else if(!f[0] && f[1] && f[2] ) {
				ans[1] = 1;
				ans[2] = 2;
			}else if(f[0] && !f[1] && f[2] ) {
				ans[2] = 1;
				ans[0] = 2;
			}

			for(int num : h) {
				System.out.println(ans[num-1]);
			}
		}
	}

}


Measured memory_bytes: 28712
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
A = list(map(int,input().split()))
a1 = sum(A)%p
B = [A[i]**2 for i in range(N)]
a2 = 0
for i in range(N):
    a2 = (a2+B[i])%p
ans = (((a1*a1)%p-a2)%p * pow(2,p-2))%p
print(ans)

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

n = int(input())

abc = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, abc):
    da, db, dc = 0, 0, 0
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(dc, da) + b
        nc = max(da, db) + c
        da, db, dc = na, nb, nc

    return max(da, db, dc)

print(happy(n, abc))


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

int main() {
  struct Line{
    double x1, y1, x2, y2;
  };

  Line l1, l2;
  int n;

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> l1.x1 >> l1.y1 >> l1.x2 >> l1.y2 >> l2.x1 >> l2.y1 >> l2.x2 >> l2.y2;
    if((l1.y2-l1.y1)/(l1.x2-l1.x1) == (l2.y2-l2.y1)/(l2.x2-l2.x1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
var
  i:longint;
  s,c:ansistring;
  t:char;
begin
  readln(s);
  c:=s;
  for i:=1 to length(c) div 2 do
   begin
     t:=c[i];
     c[i]:=c[length(c)-i+1];
     c[length(c)-i+1]:=t;
   end;
  for i:=1 to length(c) do
   begin
     if c[i]='b' then begin c[i]:='d';continue; end;
     if c[i]='d' then begin c[i]:='b';continue; end;
     if c[i]='p' then begin c[i]:='q';continue; end;
     if c[i]='q' then begin c[i]:='p';continue; end;
   end;
  if s=c then writeln('Yes')
         else writeln('No');
end.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  vector<int>s(5);
  vector<int>c(5);
  cin >> N >>M;
  for(int i=0; i<M;i++){
  cin >>s.at(i) >>c.at(i);
  }
  int error =0; //error=１なら数字が書けないとしよう

  for(int i=0; i<M;i++){
    if(s.at(i)==1&&c.at(i)==0 && N!=1){error=1;}
  		for(int j=0; j<i;j++){
    		if(s.at(i)==s.at(j) &&c.at(i)!=c.at(j)){error=1;}   	
    	}
  }
   vector<int>ans(5);
  if(N!=1){ans.at(0)=1;}
  
    if(error==0){
      for(int i=0; i<M;i++){
        ans.at(s.at(i)-1)=c.at(i);
        
      }
    
 	  for(int i=0; i<N;i++){
       cout <<ans.at(i); 
      }
    }
  	else{cout <<-1;}
  cout << endl;
}

Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("in.txt",  "r",  stdin);
        freopen("out.txt", "w", stdout);
    #endif
//*/

        

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

    if(a >= 1 && b <= 9 && a <= 9 && b >= 1)
    {
        cout<<a*b;
    }    
    else
    {
        cout<<-1;
    }












    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,r[300010] = {},l[300010] = {},mi = INF;
	string s;
	cin >> n >> s;
	for(int i = 0;i < n;i++){
		if(s[i] == 'E') r[i + 1]++;
		else l[i + 1]++;
		r[i + 1] += r[i];
		l[i + 1] += l[i];
	}
	for(int i = 0;i < n;i++){
		chmin(mi,l[i] + r[n] - r[i + 1]);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 5508
#include<iostream>

using namespace std;

int main()
{
  int X,Y,Z,box;
  cin >> X >> Y >> Z;
  box = X;
  X = Y;
  Y = box;
  box = X;
  X = Z;
  Z = box;
  cout << X  << " "<< Y << " "<< Z << endl;
  return 0;
}


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

int main(){
    // input
    int N;
    cin >> N;
    vector<int> d(N);
    for( int i=0; i<N; i++ ){
        cin >> d[i];
    }

    // calc
    long long ans = 0;
    for(int i=0; i<N; i++ ){
        for( int j=i+1; j<N; j++ ){
            ans += d[i]*d[j];
        }
    }

    // output
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    string s; cin >> s;
    int len = s.size(), zero = 0;
    for (int i = 0; i < len; i++) if (s[i] == '0') zero++;
    cout << 2 * min(zero, len - zero) << endl;
    return 0;
}

Measured memory_bytes: 512
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

fn main() {
    input! {
        n: usize,
        a_s: [usize; n],
    }
    let mut v = a_s.iter().map(|x| *x - 1).enumerate().collect::<Vec<_>>();
    v.sort_by(|l, r| l.1.cmp(&r.1));
    println!(
        "{}",
        v.iter()
            .map(|x| (x.0 + 1).to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 13052
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    vl xs(5);  ll ter = 10;
    REP(i, 5){
        ll x; cin >> x;
        if(x % 10 != 0) ter = min(ter, x%10);
        xs[i] = ( (x+9) / 10) * 10;
    }
   
    ll ans = ter;
    REP(i, 5) ans += xs[i];
    cout << ans - 10 << endstr;
    return 0;
}


Measured memory_bytes: 256
x,k,d=map(int,input().split())
x=abs(x)
mx=k*d
ans=0
if(mx<=x):
    ans=x-mx
else:
    k-=x//d
    if(k%2==0):
        ans=x%d
    else:
        ans=d-(x%d)
print(ans)

Measured memory_bytes: 9128
#include <stdio.h>
#include<string.h>
int main()
{
int flag=0,i,str1=0,str2=0;
char a[1000],b[1000],c;
gets(a);
gets(b);
flag=0;
for(i=0;i<strlen(a)+strlen(b);i++)
{
    if(flag==0)
    {
          printf("%c",a[str1++]);
          flag=1;
    }else{
        printf("%c",b[str2++]);
        flag=0;
    }
}


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;

int main(){
	int n, i, ans=0;
	cin>>n;
	int l, r;
	for(i=0; i<n; i++){
		cin>>l>>r;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

signed main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>>p;
    priority_queue<ll>pq;
    ll ans=0;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        p.emplace_back(a,b);
    }
    sort(p.begin(),p.end());
    p.push_back(make_pair(-1,0));
    int i=0;
    for(int t=0;t<=m;++t){
        while(p[i].first==t){
            pq.push(p[i].second);
            ++i;
        }
        if(pq.empty())continue;
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3568
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#include <ctime>
#include <numeric>
using namespace std;

#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(unique(all(x)) - (x).begin())
#define ld long double
#define int long long

void SOLVE1() {
	int n, x, y;
	cin >> n >> x >> y;
	vector <int> ans(n);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int dist = j - i;
			dist = min(dist, abs(i - x) + 1 + abs(y - j));
			ans[dist]++;
		}
	}
	for (int i = 1; i < n; i++) cout << ans[i] << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	int Q = 1;
	//cin >> Q;
	while (Q--) {
		SOLVE1();
	}

	return 0;
}

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

using namespace std;

using ll = long long;

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

const ll MOD = 998244353LL;

const int MAX = 210000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll f(size_t m, size_t n) {
    ll ret = (m * modpow(m-1, n - 1, MOD)) % MOD;
    return ret;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll combinations2(size_t n, size_t k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r = r % MOD;
        r = r * modinv(d, MOD);
        r = r % MOD;
    }
    if (r > MOD / 2) {
        r -= MOD;
    }
    return r;
}

void solve() {
    size_t n, m, k;
    cin >> n >> m >> k;
    ll ret = 0;
    REP(i, k+1) {
        ret += f(m, n - i) * COM(n - 1, i);
        ret = ret % MOD;
    }
    if (ret < 0) {
        ret += MOD;
    }
    cout << ret << endl;
}

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

    COMinit();

    solve();

    return 0;
}

Measured memory_bytes: 8576
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	for(ll i = m/n; i >= 1; --i){
		ll r = m - i * n;
		if(r < 0) continue;
		if(r%i == 0){
			cout << i << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

static const int mod = 1e9+7;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> grid(H, vector<int> (W));
  char ch;
  rep(i, 0, H) {
    rep(j, 0, W) {
      cin >> ch;
      if (ch == '.') {
        grid[i][j] = 1;
      } else {
        grid[i][j] = 0;
      }
    }
  }

  vector<vector<int>> dp(H, vector<int> (W, 0));
  dp[0][0] = 1;

  rep(h, 0, H) {
    rep(w, 0, W) {
      if (grid[h][w] == 0) continue; // 壁
      // left
      if (w > 0) {
        if (grid[h][w-1] == 1) {
          dp[h][w] += dp[h][w-1];
          dp[h][w] %= mod;
        }
      }

      // up
      if (h > 0) {
        if (grid[h-1][w] == 1) {
          dp[h][w] += dp[h-1][w];
          dp[h][w] %= mod;
        }
      }
    }
  }

  cout << dp[H-1][W-1] << endl;
};


Measured memory_bytes: 8192
n = int(input())
list_a=list(map(int, input().split()))  #リスト入力
list_a.sort(reverse=True)
# list_a = sort(list_a)
result = 1
if list_a[-1] == 0 :
    print(0)
else:
    for i in list_a:
        result = result * i
        if result > 1000000000000000000:
            print(-1)
            break

    if result <= 1000000000000000000:
        print(result)


Measured memory_bytes: 21780
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;



int main()
{
  int m, n, a[2222], b[2222], f[2222][2222] = {0};
  cin >> m >> n;
  for (int i = 1; i <= m; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];

  for (int i = 0; i <= max(m, n); i++)
    f[i][0] = f[0][i] = 1;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
    {
      f[i][j] = (f[i - 1][j] + f[i][j - 1]) % BASE;
      if (a[i] != b[j])
        f[i][j] = (f[i][j] - f[i - 1][j - 1] + BASE) % BASE;
    }

  cout << f[m][n] << endl;
} 

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

int main() {
	int n, temp, Max = 0;
	cin >> n;
	vector<vector<int>> nums(n, vector<int>(3));
	vector<vector<int>> dp(n, vector<int>(3));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> temp;
			nums[i][j] = temp;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			if (i == 0) {
				dp[i][j] = nums[i][j];
			} else {
				Max = 0;
				for (int k = 0; k < 3; ++k) {
					if (k == j) {
						continue;
					} else {
						Max = max(nums[i][j] + dp[i - 1][k], Max);
						dp[i][j] = Max;
					}
				}
			}
		}
	}
	cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;
	// cout << dp[n - 1][0] << " " << dp[n - 1][1] << " " << dp[n - 1][2];
//	for (int i = 0; i < n; ++i) {
//		for (int j = 0; j < 3; ++j) {
//			cout << dp[i][j] << " ";
//		}
//		cout << endl;
//	}
	return 0;
}


Measured memory_bytes: 13692
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int a,b,c,d,k;
    cin >> a >> b >> c >> d >> k;
    int sa;
    if(a == c) {
        sa = d-b;
    } else {
        if(b != 0) {
            b = 60 - b;
            a++;
        }
        sa = (c-a)*60+b+d;
    }
    if(sa == k) cout << 0 << endl;
    else {
        cout << sa-k << endl;
    }
}


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

typedef long long int ll;

ll n;
ll arr[100005][3];

ll dp[100005][3];

ll solve(ll i,ll c){
	
	if(i>=n)return 0;
	
	if(dp[i][c]==-1){
		
		if(c==0){
		//	cout<<i<<" "<<dp[i][c]<<endl;
			dp[i][c] = max(solve(i+1,1),solve(i+1,2));
		//	cout<<i<<" "<<dp[i][c]<<endl;
		}
		else{
			if(c==1){
			dp[i][c] = max(solve(i+1,0),solve(i+1,2));
			}
			else{
				dp[i][c] = max(solve(i+1,0),solve(i+1,1));
			}
		}
		dp[i][c]+=arr[i][c];
		
	
//	cout<<dp[i][c]<<endl;
   }
	return dp[i][c];
	
}

int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(ll i=0;i<n;i++){
		
		cin>>arr[i][0];
		cin>>arr[i][1];
		cin>>arr[i][2];
		
	}
	cout<<max(solve(0,0),max(solve(0,1),solve(0,2)))<<endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

ll attack(ll h){
    if(h==1) return 1;
    else return (2*attack(h/2) + 1);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll h; cin>>h;
    cout<<attack(h)<<"\n";
    return 0;
}

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

int prime[100];
bool is_prime[101];
int p=0;

void sieve(int n){
    for (int i=0;i<101;i++){
        is_prime[i]=true;
    }
    is_prime[0]=false;
    is_prime[1]=false;
    for (int i=2;i<=n;i++){
        if (is_prime[i]){
            prime[p++]=i;
            for (int j=2*i;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    sieve(N);
    map<int,int> factor;
    rep(i,p){
        int x=prime[i],y=N;
        while (y>0){
            factor[x]+=y/x;
            y/=x;
        }
    }
    int a=0,b=0,c=0,d=0,e=0;
    for (auto x:factor){
        int y=x.second;
        if (y>=74){
            a++;
        }
        else if (y>=24){
            b++;
        }
        else if (y>=14){
            c++;
        }
        else if (y>=4){
            d++;
        }
        else if (y>=2){
            e++;
        }
    }
    int f=a+b+c+d;
    int g=f+e;
    int ans=a+(a+b)*(g-1)+(a+b+c)*(f-1)+f*(f-1)*(e+f-2)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def main():
    n, k = ns()

    if n > k:
        print(0)
        exit(0)

    # 使い方
    facts, invs = prepare(n + k, MOD)

    tmp = facts[k] * invs[n] * invs[k - n] % MOD
    print(tmp)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7432
n,k=list(map(int, input().split()))
a=list(map(int, input().split()))
b=[0]*(n+1)
for i in range (n):
    b[i+1]=a[i]
ctr=[-1]*(n+1)
ctr[1]=0
x=1
c=0
s=0
while c==0:
    y=b[x]
    s+=1
    if ctr[y]==-1 and y!=1:
        ctr[y]=s
        x=y
    else:
        ll=s-ctr[y]
        c+=1
        f=ctr[y]

if k<f:
    ans=ctr.index(k)
else:
    zz=(k-f)%ll
    ans=ctr.index(zz+f)
print(ans)



Measured memory_bytes: 32380
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(read().split(),np.int64)

INF = 10**18

# 左端ごとに、個数 -> 大きさ
size = np.full((N,N),INF,np.int64)
for n in range(N):
    size[n,:N-n] = A[n:].cumsum()

dpl = np.zeros((N,N),np.int64)
dpr = np.zeros((N,N),np.int64)

for n in range(1,N):
    x = np.min(dpl[:N-n,:n] + dpr[n:N,:n][:,::-1],axis=1)
    x += size[:N-n,n]
    dpl[:N-n,n] = x
    dpr[n:N,n] = x

answer = dpl[0,-1]
print(answer)

Measured memory_bytes: 16660
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int isPrime(int X){
    int rootX = pow(X, 0.5);
    REP(i, 2, rootX+1){
        if(X%i != 0){
            if(i == rootX+1){
                return true;
            }
        }else{
            return false;
        }
    }
}

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

    while(!isPrime(X)){
        X++;
    }
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b,c,i;
    int	s[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		scanf("%d",&b);
		scanf("%d",&c);
		if(a*a+b*b==c*c || b*b+c*c==a*a || a*a+c*c==b*b){
			s[i]=1;
		}
		else{
			s[i]=0;
	}
	}
	for(i=0;i<n;i++){
		if(s[i]==1){
			printf("YES\n");
	}
	    if(s[i]==0){
			printf("NO\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2108
//============================================================================
// Name        : template.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

//WA
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a; cin >> a;
	long double b; cin >> b;
	ll bee = (b * 100) + .5;
	ll ans = (a * bee) / 100;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

struct mint {
	ll x;
	mint(ll x = 0) :x(x% mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n = 1) :n(n), f(n + 1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x) { return f[x] == x; }
	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) return {};
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	Sieve sieve(k);
	vector<mint> d(k + 1);
	for (int i = 1; i <= k; ++i) {
		d[i] = mint(k / i).pow(n);
	}
	for (int p : sieve.primes) {
		for (int i = p; i <= k; i += p) {
			d[i / p] -= d[i];
		}
	}
	mint ans = 0;
	for (int i = 1; i <= k; ++i) ans += mint(i) * d[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4488
use std::io::{stdin, BufRead, BufReader};
fn main(){
  let input = BufReader::new(stdin());
  for input in input.lines(){
    let n: u32 = input.unwrap().trim().parse::<u32>().unwrap();
    let mut res=0;
    for i in 0..10{
        for j in 0..10{
            for k in 0..10{
                for l in 0..10{
                    if (i+j+k+l)==n{
                        res=res+1;
                    }
                }
            }
        }
    }
    println!("{}",res);
  }
}
    

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
 
pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  int ans = 0;
  for(const auto&  c : s)
  {
    if (c == '+') ans++;
    if (c == '-') ans--;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

#define rep(i, n) for(int i=0; i<n; i++)

const int mod=1e9+7;
inline int add(int x,int y)
{
  x+=y;
  if (x>=mod)
    return x-mod;
  return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if (x<0)
    return x+mod;
  return x;
}
inline int mul(int x,int y)
{
  return (x*1ll*y)%mod;
}
inline int power(int x,int y)
{
  int ans=1;
  while(y)
    {
      if (y&1) ans=mul(ans,x);
      x=mul(x,x);
      y>>=1;
    }
  return ans;
}
inline int inv(int x)
{
  return power(x,mod-2);
}
inline int gcd(int x, int y)
{
  return(y!=0)?gcd(y, x%y):x;
}
inline ll nPr(int n, int r)
{
  ll i,result=1;
  rep(i,r)
    {
      result*=(ll)(n-i);
    }
  return result;
}
inline ll nCr(int n,int r)
{
  ll i,result=1;
  rep(i,min(r,n-r))
    {
      result*=(ll)(n-i);
      result/=(ll)(i+1);
    }
  return result;
}
bool prime(int n)
{
  for (int i=2; i<n/2; i++)
    {
      if(n%i==0)
	return false;
    }
  return true;
}

/*------------CODE-----------*/

int main()
{
  IOS;
  int a, b, k;
  cin >> k;
  cin >> a >> b;
  for (int i=min(a, b); i<=max(a, b); i++)
    {
      if (i%k==0)
	{
	  cout << "OK" << endl;
	  return 0;
	}
    }
  
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

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

  if(N <= 9){
    cout << N << endl;
  }
  else if (N <= 99){
    cout << 9 << endl;
  }
  else if (N <= 999){
    cout << 9 + N - 99 << endl;
  }
  else if (N <= 9999){
    cout << 909 << endl;
  }
  else if (N <= 99999){
    cout << 909 + (N - 9999) << endl;
  }
  else if (N == 100000){
    cout << 90909 << endl;
  }
  else cout << "error" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <math.h>
using namespace std;

int distance(int x1,int x2,int y1,int y2) {
	int x = (int)abs(x1 - x2);
	int y = (int)abs(y1 - y2);
	return (x + y);
}

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

	vector<vector<int>> student(2, vector<int>(N));
	vector<vector<int>> checkpoint(2, vector<int>(M));

	for (int i = 0; i < N; i++) {
		cin >> student[0][i] >> student[1][i];
		//cout << student[0][i] << student[1][i] << endl;
	}

	for (int i = 0; i < M; i++) {
		cin >> checkpoint[0][i] >> checkpoint[1][i];
		//cout << checkpoint[0][i] << checkpoint[1][i] << endl;
	}

	for (int i = 0; i < N; i++) {
		int mannhattan = distance(student[0][i], checkpoint[0][0], student[1][i], checkpoint[1][0]);
		int position = 0;
		for (int j = 1; j < M; j++) {
			int tmp = distance(student[0][i], checkpoint[0][j], student[1][i], checkpoint[1][j]);
			if (tmp < mannhattan) {
				mannhattan = tmp;
				position = j;
			}
		}
		cout << (position + 1) << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <climits>
#include <iostream>

using namespace std;
using ll = int64_t;

ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main() {
  ll n;
  cin >> n;
  n <<= 1;
  ll ans = n - 1;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll rem = n / i;
    ll x, y;
    ll g = extgcd(i, rem, x, y);
    if (g != 1)
      continue;
    ll t = x / rem;
    x %= rem;
    y += t * i;
    ans = min(ans, min(abs(x) * i, abs(y) * rem));
    if (x > 0)
      x -= rem, y += t;
    else
      x += rem, y -= t;
    ans = min(ans, min(abs(x) * i, abs(y) * rem));
  }
  cout << ans;
}

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

int main(void)
{
    string S;
    cin >> S;

    int ans = INF;
    REP(i, 26){
        char c = 'a'+i;
        string s = S;

        bool ff = true;
        for (int k = 0; k < S.size(); k++){
            if(S[k] == c){
                ff = false;
                break;
            }
        }
        if(ff) continue;

        for (int k = 0; k < S.size(); k++)
        {
            //check
            bool f = true;
            REP(j, s.size()-1){
                if(s[j] != s[j+1]){
                    f = false;
                    break;
                }
            }
            if(f){
                ans = min(ans, k);
            }

            string tmp_s;
            REP(j, s.size()-1){
                if(s[j] == c || s[j+1] == c) tmp_s.pb(c);
                else tmp_s.pb(s[j]);
            }
            s = tmp_s;
        }
    }

    pr(ans);
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long n = Long.parseLong(in.next());
            long a = (long) Math.sqrt(n);
            while (n % a != 0) {
                --a;
            }

            long b = n / a;
            long ans = a - 1 + b - 1;
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int a[56],n;
int main(){
	scanf("%d",&n);
	int k=0;
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		if(abs(a[i])>=abs(a[k]))k=i;
	}
	printf("%d\n",n*2);
	for(int i=1;i<=n;++i){
		printf("%d %d\n",k,i);
	}
	if(a[k]>=0){
		printf("%d 1\n",k);
		for(int i=2;i<=n;++i){
			printf("%d %d\n",i-1,i);
		}
	}else{
		printf("%d %d\n",k,n);
		for(int i=n-1;i;--i){
			printf("%d %d\n",i+1,i);
		}
	}
	return 0;
}

Measured memory_bytes: 256