akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define  lowbit(x) (x&(-x))
#define  ll long long
#define  ull unsigned long long
#define  max(a,b) (a>b?a:b)
#define  min(a,b) (a>b?b:a)
#define  PI acos(-1.0)
#define  fir first
#define  sec second
#define  SZ(x) (x.size())
#define  inf 0x3f3f3f3f
#define  PB push_back
#define  MP make_pair
#define  all(x) (x).begin(),(x).end()
#define  PII pair<int,int>
#define  E 2.7182818284590452353602874713527
using namespace std;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
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;}
//const ll mod = 10000019;
//const ll phi_mod_prime=mod-1;
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
ll phi(ll n){ ll rea=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ rea=rea-rea/i;while(n%i==0) n/=i;}}if(n>1) rea=rea-rea/n;return rea;}
//a^(b%modhi(mod)+phi(mod))%mod;
void exgcd(int a,int b,int &x,int &y,int &d){if(!b){x=1;y=0;d=a;}else exgcd(b,a%b,y,x,d),y-=a/b*x;}
inline int inv(int a,int mod){int x,y,d;exgcd(a,mod,x,y,d);x=(x%mod+mod)%mod;return x;}
/********************************Head----Template**********************************************/

int MOD = 1000000007;
vector<int> X;
vector<int> Y;
vector<int> DX;
vector<int> DY;
int N;
double solve(double a) {

	double mxx = -1e18;
	double mnx = 1e18;
	double mxy = -1e18;
	double mny = 1e18;
	for (int i = 0; i < N; i++) {
		double x = X[i] + a * DX[i];
		double y = Y[i] + a * DY[i];
		mxx = max(mxx, x);
		mnx = min(mnx, x);
		mxy = max(mxy, y);
		mny = min(mny, y);
	}
	return (mxx - mnx) * (mxy - mny);
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	X.resize(N);
	Y.resize(N);
	DX.resize(N, 0);
	DY.resize(N, 0);
	char dd;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> dd;
		if (dd == 'U')  DY[i] = 1;
		else if (dd == 'D')  DY[i] = -1;
		else if (dd == 'R') DX[i] = 1;
		else if (dd == 'L') DX[i] = -1;
	}
	double res = 1e18;
	double u = 1e9;
	double d = 0;
	for (int t = 0; t < 200; t++) {
		double uu = (u * 2 + d) / 3;
		double dd = (u + d * 2) / 3;
		double uv = solve(uu);
		double dv = solve(dd);
		res = min(res, uv);
		res = min(res, dv);
		if (dv < uv)  u = uu;
		else d = dd;

	}
	printf("%.11f\n",res);
	return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define F first
#define S second
using namespace std;

int Q = 1e7, h1, h2, cut = 20;
int n, s, D, l, r, up, mx, cnt, mxx, xx, a[30], b[400][30], la[400], u[400], ans[400], o[400];
pair<int, int> c[400][30];
bool v[400][30];

int f(int p, int q1, int q2) {
	int sz = q2 - q1 + 1;
	return p * sz * (sz + 1) / 2;
}

int main()
{
	int i, j, k, t, x, t1, t2;
	srand(time(NULL));
	cin >> D;
	for (i = 0; i < 26; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 1; i <= D; i++) {
		mxx = -2e9;
		for (j = 0; j < 26; j++) {
			scanf ("%d", &b[i][j]);
		}
		for (j = 0; j < 26; j++) {
			cnt = b[i][j];
			for (k = 0; k < 26; k++) {
				if (k == j) continue;
				cnt -= (i - o[k]) * a[k];
			}
			if (cnt > mxx) {
				xx = j;
				mxx = cnt;
			}
		}
		o[xx] = i;
		ans[i] = u[i] = xx;
	}
//	for (i = 1; i <= D; i++) {
//		ans[i] = u[i] = 1;
//	}
//	for(i = 1; i <= D; i++) {
//		printf("%d\n", ans[i] + 1);
//	}

	for (i = 1; i <= D; i++){
//		scanf ("%d", &t);
		t = u[i];
		s += b[i][t];
		la[t] = i;

		for (j = 0; j < 26; j++) {
			s -= a[j] * (i - la[j]);
		}
		v[i][t] = 1;
	}
//	cout << s << endl;
//	cin >> Q;
	for (i =0; i < 26; i++) {
		v[0][i] = 1;
		v[D + 1][i] = 1;
	}
	mx = s;
	while (Q--) {
//		scanf ("%d %d", &t1, &t2);
		t1 = rand() % D + 1;
		t2 = rand() % 26;
		if (u[t1] == t2) t2 = (t2 + 1) % 26;
		x = u[t1];
		s -= b[t1][x];
		v[t1][x] = 0;
		v[t1][t2] = 1;
		u[t1] = t2;
		s += b[t1][t2];
		for (l = t1 - 1; l >= 0; l--) if (v[l][x]) break;
		for (r = t1 + 1; r <= D + 1; r++) if (v[r][x]) break;
		s += f(a[x], l + 1, t1 - 1);
		s += f(a[x], t1 + 1, r - 1);
		s -= f(a[x], l + 1, r - 1);
		for (l = t1 - 1; l >= 0; l--) if (v[l][t2]) break;
		for (r = t1 + 1; r <= D +1; r++) if (v[r][t2]) break;
		s += f(a[t2], l + 1, r - 1);
		s -= f(a[t2], l + 1, t1 - 1);
		s -= f(a[t2], t1 + 1, r - 1);
		if (s > mx) {
			up = 0;
			for (i = 1; i <= D; i++) {
				ans[i] = u[i];
			}
			mx = s;
		} else up++;
		if (up == cut) {
			up = 0;
			memset(v, 0, sizeof(v));
			for (i =0; i < 26; i++) {
				v[0][i] = 1;
				v[D + 1][i] = 1;
			}
			for (i = 1; i <= D; i++) {
				u[i] = ans[i];
				v[i][ans[i]] = 1;
			}
			s = mx;
		}
	}
	for (i = 1; i <= D; i++) {
		printf("%d\n", ans[i] + 1);
	}
    return 0;
}


Measured memory_bytes: 3828
#include <string>
#include <iostream>
using namespace  std;
 
int main()
{
   string st1 , st2;
  int count = 0; 
  cin>>st1 >> st2;
  for(int i = 0; i < 3 ; i++)
  {
      if(st1[i] == st2[i]) count++;
  } 
  printf("%d",count);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1e9
#define N 100005
using namespace std;

int main(){
  int n;
  while(cin>>n&&n){
    int hp[100],m,mp[100],tg[100],dm[100];
    string s;
    for(int i=0;i<n;i++)cin>>hp[i];
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>s>>mp[i]>>s>>dm[i];
      tg[i]=s[0]=='A';
    }

    int dp[2][N];

    for(int i=0;i<N;i++)dp[0][i]=dp[1][i]=inf;
    dp[0][0]=dp[1][0]=0;
    for(int i=0;i<m;i++){
      for(int j=0;j<N;j++){
	dp[tg[i]][min(N-1,j+dm[i])]=min(
        dp[tg[i]][min(N-1,j+dm[i])],dp[tg[i]][j]+mp[i]);
      }
    }

    for(int i=N-1;i>0;i--){
      dp[0][i-1]=min(dp[0][i-1],dp[0][i]);
      dp[1][i-1]=min(dp[1][i-1],dp[1][i]);
    }

    int mn=inf;
    for(int i=0;i<=100000;i++){
      bool f=false;
      int s=dp[1][i];
      for(int j=0;j<n;j++)
	s+=dp[0][max(0,hp[j]-i)],f|=s>=inf;
      if(!f)mn=min(mn,s);
    }
    cout<<mn<<endl;
  }

  return 0;
}

Measured memory_bytes: 3856
#include<stdio.h>

int main(void) {
	int number[3], i, j, a;
	for (i = 0; i < 3; i++)
		scanf("%d", &number[i]);
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 2; j++) {
			if (number[j] > number[j + 1]){
				a = number[j];
				number[j] = number[j + 1];
				number[j + 1] = a;
			}
		}
	}
	printf("%d %d %d\n", number[0],number[1],number[2]);
	return 0;
}


Measured memory_bytes: 2736
N, M = map(int, input().split())
K = [0] * (N + 1)
for i in range(M):
    l, r = map(int, input().split())
    K[l - 1] += 1
    K[r] -= 1

for i in range(1, N + 1):
    K[i] += K[i - 1]
print([i == M for i in K].count(True))


Measured memory_bytes: 51160
N = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                continue
            if L[i] + L[j] > L[k]:
                ans += 1
print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void findAns()
{
    int n;
    cin >> n;
    float d;
    cin >> d;

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int src, des;
        cin >> src >> des;

        double value = sqrt(pow(src, 2) + pow(des, 2));
        if (value <= d)
        {
            //cout << value << "\n";
            ans++;
        }
    }
    cout << ans << "\n";

}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("new.txt", "w", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while (t--) findAns();

}

Measured memory_bytes: 3740
import bisect
import random

def test(L):
    lst = []
    N = len(L)
    for a in range(N):
        for b in range(a):
            for c in range(b):
                if L[a] < L[b] + L[c]:
                    lst.append((c, b, a))
    return lst

def test_len(L):
    return len(test(L))

def test2(L):
    return len(set((l[0], l[2]) for l in test(L)))

N = int(input())
L = sorted(map(int, input().split()))
# L = [1, 1, 1000]
# L = [218, 233, 389, 645, 704, 728, 786]
# N = 10
# L = sorted([random.randint(0, 1000) for _ in range(N)])
# L = [150, 190, 192, 281, 294, 374, 501, 686, 769, 954]
# print(L)
# N = len(L)
S = 0
for a in range(2, N):
    c = bisect.bisect_left(L, (L[a] + 2) // 2)
    while c >= 0:
        if L[a] < L[c] * 2:
            c -= 1
        else:
            break
    b = c + 1
    assert L[a] < L[b] * 2
    if b == 0:
        # print("b0", b, a, (a - 1) * (a) // 2)
        S += (a - 1) * (a) // 2
        continue
    if c >= a - 1:
        continue
    assert L[a] < L[b] + L[b]
    assert L[a] >= L[c] + L[c], (a, c)
    S += (a - b) * (a - b - 1) // 2
    while c >= 0:
        while L[a] >= L[b] + L[c]:
            b += 1
        assert L[a] < L[b] + L[c]
        assert L[a] >= L[b - 1] + L[c]
        # print(c, b, a)
        S += a - b
        c -= 1
print(S)
# print(test_len(L))

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

int main()
{
	int n;
	int p[105];
	int m;
	
	while(~scanf("%d",&n)){
		int sum=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&p[i]);
			sum+=p[i];
		}
			
		scanf("%d",&m);
		int x,y;
		for(int i=1;i<=m;i++){
			scanf("%d%d",&x,&y);
			sum=sum-p[x]+y;
			printf("%d\n",sum);
			sum=sum+p[x]-y;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
struct dice{
	int top;
	int front;
	int right;
	int left;
	int back;
	int bottom;
	int n;
	void spin(char x){
		if(x=='E'){
			n=top;
			top=left;
			left=bottom;
			bottom=right;
			right=n;
		}
		if(x=='W'){
			for(int i=0;i<3;i++){
				spin('E');
			}
		}
		if(x=='S'){
			n=top;
			top=back;
			back=bottom;
			bottom=front;
			front=n;
		}
		if(x=='N'){
			for(int i=0;i<3;i++){
				spin('S');
			}
		}
		if(x=='R'){
			n=front;
			front=left;
			left=back;
			back=right;
			right=n;
		}
	}
};

int main() {
	int a[6];
	int X[25],Y[25];
	int ans;
	int q;
	for(int i=0;i<6;i++){
		cin>>a[i];
	}
	dice d;
	d.top=a[0];
	d.front=a[1];
	d.right=a[2];
	d.left=a[3];
	d.back=a[4];
	d.bottom=a[5];
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>X[i]>>Y[i];
		for(int j=0;j<4;j++){
			d.spin('R');
			if(d.front==Y[i]) break;
			if(j==3){
				for(int k=0;k<4;k++){
					d.spin('S');
					if(d.front==Y[i]) break;
				}
			}
		}
		for(int j=0;j<4;j++){
			d.spin('E');
			if(d.top==X[i]){
				cout<<d.right<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3056
#include <cstdio>

using namespace std;

int main()
{
  int i, j;

  for (i = 1; i <= 9; i++) {
    for (j = 1; j <= 9; j++) {
      printf("%dx%d=%d\n", i, j, i*j);
    }
  }

  return 0;
}

Measured memory_bytes: 924
import java.util.*;

public class Main {
	static int[][] DIR = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	public static final int Y = 1024;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][];
		int num_w = 0;
		int num_b = 0;

		HashSet<Integer> black = new HashSet<>();

		for (int i = 0; i < H; i++) {
			String s = sc.next();
			char[] cs = s.toCharArray();
			A[i] = cs;
			for (int j = 0; j < cs.length; j++) {
				if (cs[j] == '.') {
					num_w ++;
				}
				else {
					black.add(i * Y + j);
					num_b++;
				}
			}
		}
		int turn = 0;
		while (num_w > 0) {
			turn++;

			HashSet<Integer> black2 = new HashSet<>();
			for (int pair : black) {
				int _y = pair / Y;
				int _x = pair % Y;
				for (int d = 0; d < DIR.length; d++) {
					int x = _x + DIR[d][0];
					int y = _y + DIR[d][1];

					if (0 <= y && y < A.length && 0 <= x && x < A[y].length && A[y][x] == '.') {
						A[y][x] = '#';
						black2.add(y * Y + x);
						num_w--;
					}
				}
			}
			black = black2;
		}
		System.out.println(turn);
	}
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string s; cin >> s;
    REP(i,s.size()){
        cout << (s[i]==','?' ':s[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int N,M,Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int ans=0;

void dfs(vector<int> &A,int now){
  if(now==N){
    int tmp=0;
    for(int i=0;i<Q;i++){
      if(A.at(b.at(i)-1)-A.at(a.at(i)-1)==c.at(i))  tmp+=d.at(i);
    }
    chmax(ans,tmp);
    return;
  }
  for(int i=A.at(now-1);i<=M;i++){
    A.at(now)=i;
    dfs(A,now+1);
  }
}
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for(int i=0;i<Q;i++)  cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

  vector<int> A(N,1);
  dfs(A,1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3660
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int main(){
	long int NNN , MMM;
	cin >> NNN >> MMM;
	//周囲に何ます有るか考える、奇数なら表のまま、偶数なら裏返って終わると思う。
	/*
	M=1,N=1、1
	M=2,N=1,0
	M=2,N=2,0
	M=1,N=2,0
	以下、大きい方をMとする
	N=1の時、両端以外は周囲に2マス両端は1マスなので、両端以外が表を向く→M-2が答え
	N=2の時、両端は3マスそれ以外は5マスなので、全部のマスが表を向く→0
	N>2の時、淵は3,5マスなので表、中身は8マスなので裏を向く
	*/
	if(NNN>MMM){
		swap(NNN,MMM);
	}
	if(NNN==1){
		if(MMM==1){
			cout << 1 << endl;
		}
		else{
			cout << MMM-2 << endl;
		}
		return 0;
	}
	if(NNN==2 || MMM ==2){
		cout << 0 << endl;
		return 0;
	}
	long int ans = (MMM-2)*(NNN-2);
	cout << ans <<endl;


	return 0;
}


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int INF = 1e9;
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
void solve()
{
    string s;
    cin >> s;
    map<char, deque<int>> mp;
    int cta = 0;
    int x = s.length();
    for (auto i : s)
        mp[i].push_back(++cta);
    int res = INF;
    for (auto i : mp)
    {
        int tmp = 0;
        int len = i.second.size();
        for (int j = 0; j <= len; ++j)
        {
            if (j == 0)
                tmp = max(tmp, i.second[j] - 1);
            else if (j == len)
                tmp = max(tmp, abs(x - i.second[j - 1]));
            else
                tmp = max(tmp, abs(i.second[j] - i.second[j - 1]) - 1);
        }
        res = min(res, tmp);
    }
    cout << res << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define mp make_pair
int main()
{
	std::ios::sync_with_stdio(false);
	int n,a[105];
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	cout<<a[n]-a[1]<<endl;
	return 0;
}


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

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; ++i){
        for (int j = 0; j < d; ++j){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i){
        for (int j = i+1; j < n; ++j){
            int norm = 0;
            for (int k = 0; k < d; ++k){
                int diff = abs(x[i][k] - x[j][k]);
                norm += diff * diff;
            }
            bool flag = false;
            for (int k = 0; k <= norm; ++k){
                if (k * k == norm){
                    flag = true;
                }
            }
            if (flag) ++ans;
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
#include <vector>

const double kEpsilon = 1e-10;

inline bool equals(double a, double b)
{
    return fabs(a - b) < kEpsilon;
}

class Point
{
  public:
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y)
    {
    }

    Point operator+(const Point &p)
    {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point &p)
    {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(const double k)
    {
        return Point(x * k, y * k);
    }

    double SquaredNorm()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(this->SquaredNorm());
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator==(const Point &p) const
    {
        return fabs(x - p.x) < kEpsilon && fabs(y - p.y) < kEpsilon;
    }

    double dot(const Point &p) const
    {
        return x * p.x + y * p.y;
    }
    double cross(const Point &p) const
    {
        return x * p.y - y * p.x;
    }
};

double dot(const Point &p1, const Point &p2)
{
    return p1.x * p2.x + p1.y * p2.y;
}
double cross(const Point &p1, const Point &p2)
{
    return p1.x * p2.y - p1.y * p2.x;
}

using Vector = Point;

int main()
{
    Point p0, p1, p2;
    int q;

    std::cin >> p0.x >> p0.y >> p1.x >> p1.y;
    std::cin >> q;

    Vector a, b;
    a = p1 - p0;

    auto println = [](auto s) { std::cout << s << std::endl; };

    for (size_t i = 0; i < q; ++i)
    {
        std::cin >> p2.x >> p2.y;
        b = p2 - p0;

        auto cross_z = a.cross(b);

        if (cross_z > 0.0)
            println("COUNTER_CLOCKWISE");
        else if (cross_z < 0.0)
            println("CLOCKWISE");
        else
        {
            auto dot_prod = a.dot(b);
            if (dot_prod < 0.0)
                println("ONLINE_BACK");
            else if (b.abs() > a.abs())
                println("ONLINE_FRONT");
            else
            {
                println("ON_SEGMENT");
            }
        }
    }
}



Measured memory_bytes: 3236
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	dd := map[int]int{}
	for i := 0; i < n; i++ {
		d := getNextInt(scanner)
		dd[d] = dd[d] + 1
	}
	m := getNextInt(scanner)
	tt := map[int]int{}
	for i := 0; i < m; i++ {
		t := getNextInt(scanner)
		tt[t] = tt[t] + 1
	}
	for t, c := range tt {
		if dd[t] < c {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")

}


Measured memory_bytes: 19840
#include<stdlib.h>
/*int int_cmp(const int *a, const int *b){
  if (*a < *b)
    return (-1);
  else if (*a > *b)
    return (1);
  return (0);} */
p(int*a,int*b){return*a-*b;}
int main () {
int f[1001];
int F[1001];
int N,i,V,d,count;
N=1001;
f[0]=2;
f[1]=3;
for(i=2;i<1001;i++){f[i]=f[i-1]+f[i-2];f[i]=f[i]%N;}
for(;~scanf("%d%d",&V,&d);){
  count = 1;
  for(i=0;i<V;i++)F[i]=f[i];
  qsort(F,V,4,p);
  for(i=1;i<V;i++)
    if( F[ i] - F[ i - 1] > d - 1)
      count++;
  printf( "%d\n" , count);
 }
 return 0;
}

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

#define repeat(i, x) for (int64_t i = 0; (i) < (int64_t)(x); (i)++)

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

    int n;
    cin >> n;

    int k = 2;
    while (k * (k - 1) < 2 * n) k++;

    if (k * (k - 1) != 2 * n) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    cout << k << endl;
    vector<set<int>> sets(k);

    int start = 1;
    repeat (i, k) {
        int size = sets[i].size();
        repeat (j, k - 1 - size) {
            sets[i].insert(start);
            sets[i + j + 1].insert(start);
            start++;
        }
    }

    repeat (i, k) {
        cout << sets[i].size();
        for (int num : sets[i]) {
            cout << " " << num;
        }
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db long double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
const int mxn=3002;
int n;
int a[mxn];
int dp[mxn][mxn][2];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=n;i>=1;i--)
    for (int j=i;j<=n;j++)
    {
        if (i==j) dp[i][j][0]=a[i],dp[i][j][1]=0;
        if (dp[i][j-1][1]+a[j]<dp[i+1][j][1]+a[i]) dp[i][j][0]=dp[i+1][j][1]+a[i],dp[i][j][1]=dp[i+1][j][0];
            else dp[i][j][0]=dp[i][j-1][1]+a[j],dp[i][j][1]=dp[i][j-1][0];
    }
    cout<<dp[1][n][0]-dp[1][n][1];
    return 0;
}

Measured memory_bytes: 85432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = cin.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int r : a)
			map.put(r / 400, 1 + map.getOrDefault(r / 400, 0));
		int min = map.entrySet().stream().mapToInt(entry -> entry.getKey() >= 8 ? 0 : 1).sum();
		min = Math.max(min, 1);
		int max = map.entrySet().stream().mapToInt(entry -> entry.getKey() >= 8 ? entry.getValue() : 1).sum();
		cout.println(min + " " + max);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll X=in();
	ll A=X/500LL;
	X%=500LL;
	ll B=X/5LL;
	out(1000LL*A+5LL*B);
	return 0;
}


Measured memory_bytes: 256
/*
 *
 *	File Name: 
 *	Author: r3gz3n
 *	Description: 
 *	Difficulty: 
 *
 */

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define sz size()


template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}

using namespace std;
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;

const int MOD = 1e9 + 7;

int main(int argc, char* argv[])
{
	if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
	if(argc == 3) freopen(argv[2], "w", stdout);
	int a, b, c;
	while(cin >> a >> b >> c)
	{
		if(a + b == c or b + c == a or a + c == b) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


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

const int INF = 1e9;
int N,M,b,c;
int d[1000],a[1000];
int dp[(1<<12)-1];

int main(void){
    cin >> N >> M;
    fill(dp,dp+(1<<N),INF);
    for(int i=1;i<=M;i++){
        cin >> a[i] >> b;
        //cout << a[i] << endl;
        rep(j,b){
            cin >> c;
            d[i] += 1<<(c-1); 
        }
    }
    dp[0] = 0;
    
    for(int i=1;i<=M;i++){
        for(int j=0;j<(1<<N);j++){
            dp[j|d[i]] = min(dp[j|d[i]], dp[j] + a[i]);
        }
        //for(int j=0;j<(1<<N);j++)cout << dp[j] << endl;
    }
    
    //for(int j=0;j<(1<<N);j++)cout << dp[j] << endl;
    if(dp[(1<<N)-1]!=INF)cout << dp[(1<<N)-1] << endl;
    else cout << -1 <<endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[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 $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, 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 solve() {
    input!(
        r: usize,
    );

    println!("{}", r*r);
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    char o[51];
    char e[51];

    scanf("%s %s", o, e);
    int l = strlen(o);

    for (int i = 0; i < l; i++) {
        printf("%c", o[i]);
        if (i != l - 1 || strlen(e) == l) {
            printf("%c", e[i]);
        }

    }

    return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;

	s[3] = '8';
	cout << s << endl;
	
	#ifdef LOCAL_DEFINE
		cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}



Measured memory_bytes: 256
<?php
$N = intval(trim(fgets(STDIN)));
$arrFood = explode(' ', fgets(STDIN));
$arrPoint = explode(' ', fgets(STDIN));
$arrBonus = explode(' ', fgets(STDIN));

$bonusSum = 0;
for($i = 0; $i < $N - 1; $i++) {
    if($arrFood[$i+1] - $arrFood[$i] == 1) {
        $bonusSum += $arrBonus[$arrFood[$i] - 1];
    }
}

$basicSum = array_sum($arrPoint);

echo $basicSum + $bonusSum;
?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
#define INF 20000000
#define INF2 2000000000000000000
 
using namespace std;

int main()
{
    IOS;
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] == '?')
            cout << 'D';
        else
            cout << s[i];
    }
}



Measured memory_bytes: 3776
S = gets.chomp
K = gets.to_i

ans = S.scan(/(.)\1/).size
if K != 1
  n = (S[/^(.)\1*/]||[]).size
  if S.size == n
    ans = n * K / 2
  else
    ans += S.chars.rotate(n).join.scan(/(.)\1/).size * (K-1)
  end
end
puts ans

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

int T[222];
double V[222];
double M[44444];

int main(){
  int N; cin>>N;
  rep(i,44444) M[i]=101;
  rep(i,N) cin>>T[i];
  rep(i,N) cin>>V[i];
  int sum=0;
  rep(i,N){
    T[i]*=2;
    for(int j=sum;j<=sum+T[i];j++){
      M[j]=min(M[j],V[i]);
    }
    sum+=T[i];
  }
  M[0]=M[sum]=0;
  rep(i,N){
    rep(j,sum) M[j+1]=min(M[j+1],M[j]+0.5);
    for(int j=sum-1;j>=0;j--) M[j]=min(M[j],M[j+1]+0.5);
  }
  double ans=0;
  rep(i,sum) ans+=(M[i]+M[i+1]);
  cout<<setprecision(15);
  cout<<ans/4<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <list>

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){};
    Edge(int u, int v, long long w): from(u), to(v), cost(w){};
    ~Edge(){};
};

// Dijkstra's Algorithm
void Dijkstra(std::vector<Edge> &edge, int N, int start, std::vector<long long> &distance)
{
    typedef std::pair<long long, int> P;
    const long long infty = 1e+18;

    // initialize
    distance.clear();
    for(int i=0; i<N; i++) distance.push_back(infty);
    distance[start] = 0;
    std::priority_queue<P, std::vector<P>, std::greater<P> > q;
    q.push(P(0, start));

    std::vector<std::list<P> > edge_list(N);
    for(auto &&itr = edge.begin(); itr != edge.end(); itr++){
        edge_list[itr->from].push_back(P(itr->cost, itr->to));
    }

    // update
    while(!q.empty()){
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if(distance[u] < d) continue; // not updated

        for(auto &&itr = edge_list[u].begin(); itr != edge_list[u].end(); itr++){
            int v = itr->second;
            long long w = itr->first;
            if(distance[u] + w < distance[v]){
                distance[v] = distance[u] + w;
                q.push(P(distance[v], v));
            }
        }
    }
}

int main()
{
    int H, W;
    std::cin >> H >> W;
    std::vector<std::vector<int> > c(10, std::vector<int>(10));
    std::vector<std::vector<int> > A(H, std::vector<int>(W));
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++) scanf(" %d", &c[i][j]);
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            scanf(" %d", &A[i][j]);
            if(A[i][j] == -1) A[i][j] = 1;
        }
    }

    std::vector<Edge> edge;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(i != j) edge.push_back(Edge(j, i, c[i][j]));
        }
    }
    std::vector<long long> distance;
    Dijkstra(edge, 10, 1, distance);

    long long ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++) ans += distance[A[i][j]];
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 512
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!(
                    "[{}:{}] {} = {:#?}",
                    file!(),
                    line!(),
                    stringify!($val),
                    &tmp
                );
                tmp
            }
        }
    };
}

fn main() {
    input! {
        n: usize,
        a_v: [u64; n],
    }

    let mut odd = 0u64;
    for a in a_v {
        if a % 2 != 0 {
            odd += 1;
        }
    }

    let answer = if odd % 2 == 0 { "YES" } else { "NO" };

    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll N,M; cin >> N >> M;
    vector<pair<ll,ll>> AB(N);
    rep(n,0,N)
        cin >> AB[n].first >> AB[n].second;

    sort(ALL(AB));

    ll cur = 0;  ll ans = 0;
    for(int i=0;i<N;i++){
        if(cur+AB[i].second < M) ans += AB[i].first * AB[i].second;
        else{
            ans += AB[i].first * (M-cur);
            break;
        }
        cur += AB[i].second;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
//???1:AC?????????
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int* BIT;
int* table;
ll* weight;
int* hanten_num;
ll* mult;

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

void func(){

	for(int i = 1; i <= N; i++){
		BIT[i] = 0;
	}

	for(int i = 1; i <= N; i++){
		table[i] = i;
	}

	weight[N] = 0;
	weight[N-1] = 1;
	for(int digit = N-2; digit >= 1; digit--){
		weight[digit] = mult[N-(digit)];
	}

	int R;
	scanf("%d",&R);

	int left,right;
	for(int loop = 0; loop < R; loop++){
		scanf("%d %d",&left,&right);
		swap(table[left],table[right]);
	}

	for(int digit = N; digit >= 1; digit--){
		hanten_num[digit] = getSum(table[digit]);
		add(table[digit],1);
	}

	ll ans = 0;

	for(int digit = 1; digit <= N-1; digit++){
		ans += (weight[digit]*(ll)hanten_num[digit])%MOD;
		ans %= MOD;
	}

	printf("%lld\n",ans%MOD);
}



int main(){

	BIT = new int[100001];
	table = new int[100001];
	weight = new ll[100001];
	hanten_num = new int[100001];
	mult = new ll[100001];

	mult[1] = 1;

	for(int i = 2; i <= 100000; i++){
		mult[i] = mult[i-1]*i;
		mult[i] %= MOD;
	}

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

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

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

    int n;
    ll k;
    cin >> n >> k;

    map<int, ll> bigArray;
    REP(i, n) {
        int a;
        ll b;
        cin >> a >> b;
        bigArray[a] += b;
    }

    int res = 0;
    for (auto i : bigArray) {
        k -= i.second;
        if (k <= 0) {
            res = i.first;
            break ;
            }
    }

    cout << res << '\n';
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String s = sc.next();
		String t = sc.next();

		int max = 0;
		for (int i = 1; i <= N; i++) {
			if (s.substring(N - i, N).equals(t.substring(0, i))) {
				max = Math.max(i, max);
			}
		}
		System.out.println((s + t.substring(max, N)).length());
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 8276
def gcd(x,y):
    if x<y:x,y =y,x
    if y==0: return x
    return gcd(y,x%y)
N = int(input())
A = list(map(int,input().split()))
L = [0]
R = [0]
for i in range(N):
    L.append(gcd(L[i],A[i]))
    R.append(gcd(R[i],A[N-i-1]))
R.reverse()
print(max([gcd(L[i],R[i+1])for i in range(N)]))

Measured memory_bytes: 14180
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    ans = 0
    if op == "+":
        ans = a + b
    elif op == "-":
        ans = a - b
    elif op == "*":
        ans = a * b
    elif op == "/":
        ans = a // b
    else:
        break
    
    print(ans)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	sort(begin(A), end(A));
	int first_lt0 = 0;
	while(first_lt0+1 < N && A[first_lt0+1] < 0) first_lt0++;
	cat ans = (first_lt0 != N-1) ? -A[first_lt0] : A[first_lt0];
	for(int i = first_lt0+1; i < N; i++) ans += A[i];
	for(int i = 0; i < first_lt0; i++) ans -= A[i];
	cout << ans << "\n";
	cat cur = A[first_lt0];
	for(int i = first_lt0+1; i <= N-2; i++) {
		cout << cur << " " << A[i] << "\n";
		cur -= A[i];
	}
	if(first_lt0 < N-1) {
		cout << A[N-1] << " " << cur << "\n";
		cur = A[N-1]-cur;
	}
	for(int i = 0; i < first_lt0; i++) {
		cout << cur << " " << A[i] << "\n";
		cur -= A[i];
	}
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2304
from collections import deque
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    e[a].append(b)
    e[b].append(a)

l = deque([1])
s = set([1])
while True:
    check = True
    for nex in e[l[-1]]:
        if nex in s:
            continue
        l.append(nex)
        s.add(nex)
        check = False
        break
    if check:
        break
while True:
    check = True
    for nex in e[l[0]]:
        if nex in s:
            continue
        l.appendleft(nex)
        s.add(nex)
        check = False
        break
    if check:
        print(len(l))
        print(*l)
        exit()

Measured memory_bytes: 32484
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i+=2)
    {
        if (num % i == 0){
            return false;
        }
    }

    return true;
}

int main() {
    int X; cin >> X;
    while(true){
        if (isPrime(X)){
            break;
        }else{
            X += 1;
        }
    }
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256