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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    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 combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(100005);

mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> C(N);
    rep(i, N) cin >> C[i];
    sort(C.begin(), C.end());

    vector<mint> two(N + 1);
    two[0] = 1;
    rep(i, N) two[i + 1] = two[i] * 2;

    mint ans;
    rep(i, N) {
        int l = i, r = N - 1 - i;
        mint now = two[r];
        if (r != 0) now += two[r - 1] * r;
        now *= two[l];
        now *= C[i];
        ans += now;
    }

    ans *= two[N];
    cout << ans.x << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
 
class Dice3{
public:
    Dice3(){
        number = new int[6];
        checkTable = new int[101];
        for(int i = 0; i < 101; i++) checkTable[i] = -1;
    };
    ~Dice3(){
        delete[] number;
        delete[] checkTable;
    };
 
    void setLabel(int index,int num){
        number[index] = num;
        checkTable[num] = index;
    };
 
    void roll(char dst){
        switch(dst){
        case 'E':
            setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
            break;
        case 'N':
            setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
            break;
        case 'S':
            setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
            break;
        case 'W':
            setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
            break;
        }
    };
 
    bool isValidMember(int inputed[]){
        for(int i = 0; i < 6; i++)
        {
            if(checkTable[inputed[i]] == -1)
                return false;
        }
        return true;
    }
    bool isSameDice(int inputed[]){
        char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
        for(int i = 0; i < 24; i++){
            roll(order[i]);
            for(int j = 0; j < 6; j++){
                if(inputed[j] != number[j])
                    break;
                if(j == 5)
                    return true;
            }
        }
        return false;
    }
 
private:
    void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
 
private:
    int* number;
    int* checkTable;
};
 
int main(){
    Dice3 dice3;
    int tmp,inputed[6];
    for(int i = 0; i < 6; i++){
        scanf("%d",&tmp);
        dice3.setLabel(i,tmp);
    }
    for(int i = 0; i < 6; i++) scanf("%d",&inputed[i]);
 
    if(dice3.isValidMember(inputed) && dice3.isSameDice(inputed))
        printf("Yes\n");
    else{
        printf("No\n");
    }
}


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

using namespace std;

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

	char a,b;

	cin >> a >> b;

	if(a=='H')
	{
		cout << b << '\n';
	}
	else
	{
		if(b=='H')
		{
			cout << 'D' << '\n';
		}
		else
		{
			cout << 'H' << '\n';
		}
	}
	return 0;
}


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

int main(){
    int H,W;
    
    while(1){
    cin >> H >> W;
        if(H == 0 && W == 0)break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if( i % 2 == 0 && j % 2 == 0) cout << "#";
                else if( i % 2 == 1 && j % 2 == 1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int x,y;
    bool operator<(const node&o)const
    {
        return y>o.y;
    }
}a[100005];
int n,k,cot=0;
bool vis[100005];
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
    long long ans=0,res=0,type=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(cot<k)
        {
            if(!vis[a[i].x])
            {
                vis[a[i].x]=true;
                type++;
            }
            else q.push(a[i].y);
            res+=a[i].y;
            cot++;
            ans=max(ans,res+type*type);
        }
        else
        {
            if(q.empty())break;
            if(vis[a[i].x]) continue;
            vis[a[i].x]=true;
            type++;
            res+=a[i].y;
            res-=q.top();q.pop();
            ans=max(ans,res+type*type);
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    vector<int> a(3);
    rep(i, 3) cin >> a.at(i);
    int ans = 0;
    sort(a.begin(), a.end());
    while (a.at(0) != a.at(2)) {
        if (a.at(2) - a.at(0) >= 2) {
            a.at(0) += 2;
        }
        else {
            a.at(0)++;
            a.at(1)++;
        }
        sort(a.begin(), a.end());
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
list($T,$A) = explode(" ",trim(fgets(STDIN)));
$H = explode(" ",trim(fgets(STDIN)));
$pos = 0;
$min = 999999;
foreach($H as $k=>$v) {
  $r=abs($A - ($T - ($v*0.006)));
  if ($r < $min) {
    $pos = $k+1;
    $min = $r;
  }
}
printf("%d\n",$pos);


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n,m; cin >> n >> m;
  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k; cin >> n >> k;
	vl a(n);
	FOR(i,0,n) cin >> a[i];
	
	vl spos(n+1), sneg(n+1);
	FOR(i,0,n) {
		spos[i+1] = spos[i], sneg[i+1] = sneg[i];
		if (a[i] < 0) sneg[i+1] += a[i]; else spos[i+1] += a[i];
	}
	
	ll res = -oo;
	FOR(i,k,n+1) {
		ll sum = spos[i]+sneg[i]-spos[i-k]-sneg[i-k];
		res = max(res, sum + spos[i-k] + spos[n]-spos[i]);
		res = max(res, spos[i-k] + spos[n]-spos[i]);
	}
	cout << res << endl;

}



Measured memory_bytes: 2560
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}

	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int n,m,left,right;
			int index,indexL,indexR, result;
			n = sc.nextInt();
			m = sc.nextInt();
			Map <Integer,Integer> mapL = new TreeMap<Integer,Integer> ();
			Map <Integer,Integer> mapR = new TreeMap<Integer,Integer> ();
            indexL=-1;
            indexR=n+1;
			for(index=0;index<m;index++) {
				left = sc.nextInt();
				right = sc.nextInt();
				if(left>indexL) indexL=left;
				if(right<indexR) indexR=right;
			}
			sc.close();
			result=indexR-indexL+1;
			if(indexL>indexR) result=0;
			// 出力
			System.out.println(result);

	}
}

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

signed main() {
    int a[3];
    
    for ( int i = 0; i < 3; i++ ) {
        cin >> a[i];
    }
    
    sort(a, a+3);
    cout << a[0] + a[1] << endl;
    
    return (0);
}

Measured memory_bytes: 3620
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
a,b,c = LS()
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")
#B

#C
""""
n,T = LI()
ans = 0
t = LI()
for i in range(n-1):
    ans += min(T,t[i+1]-t[i])
ans += T
print(ans)
"""

#D
"""
n,w = LI()
g = LIR(n)
l = [[] for i in range(4)]
for W,v in g:
    l[W-g[0][0]].append(v)
    l[W-g[0][0]].sort(reverse = True)
l0 = len(l[0])
l1 = len(l[1])
l2 = len(l[2])
l3 = len(l[3])
for i in range(l0-1):
    l[0][i+1] += l[0][i]
l[0].insert(0,0)
for i in range(l1-1):
    l[1][i+1] += l[1][i]
l[1].insert(0,0)
for i in range(l2-1):
    l[2][i+1] += l[2][i]
l[2].insert(0,0)
for i in range(l3-1):
    l[3][i+1] += l[3][i]
l[3].insert(0,0)
ans = 0
for i in range(l0+1):
    for j in range(l1+1):
        for k in range(l2+1):
            for m in range(l3+1):
                if i*g[0][0]+j*(g[0][0]+1)+k*(g[0][0]+2)+m*(g[0][0]+3) <= w:
                    ans = max(ans,l[0][i]+l[1][j]+l[2][k]+l[3][m])
print(ans)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<vi> pqvi;
typedef priority_queue<vll> pqvll;
typedef priority_queue<int, vi, greater<int>> pqi_G;
typedef priority_queue<ll, vll, greater<ll>> pqll_G;
typedef priority_queue<vi, vvi, greater<vi>> pqvi_G;
typedef priority_queue<vll, vvll, greater<vll>> pqvll_G;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) cout << n << endl;
  else cout << n * 2 << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a=[list(map(int,input().split())) for i in range(n)]

def solve(bans):
    cnts=[0]*m
    for itm in a:
        for fav in itm:
            if (fav-1) in bans:
                continue
            cnts[fav-1]+=1
            break
    ret = max(cnts)
    max_ss = [i for i, v in enumerate(cnts) if v == ret]
    return ret, max_ss # current ans, most popular sports

ban_s = []
ans=10000
while True:
    ret, max_ss = solve(ban_s)
    if ret==0:
        break
    ans=min(ans,ret)
    ban_s.extend(max_ss)

print(ans)

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

int main(){
  int a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin >> n;
  cout << a[n] << '\n';
}


Measured memory_bytes: 764
n = gets.chomp.to_i

b = []
can = false
n.times do |i|
    b[i] = gets.chomp.to_i
end

nx = 0
time = 0
success = false

n.times do
    next unless nx
    nx = b[nx] - 1
    time += 1
    if nx == 1
        success = true
        break
    end
end

if success
    puts time
else
    puts '-1'
end



Measured memory_bytes: 2628
#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<ll,ll>;

int main() {
    ll H,W,K;
    int ans=0;
    cin>>H>>W>>K;
    vector<string> s(H);
    rep(i,H)cin>>s[i];
    rep(is,1<<H)rep(js,1<<W){
      int cnt=0;
      rep(i,H)rep(j,W){
        if(is>>i&1)continue;
        if(js>>j&1)continue;
        if(s[i][j]=='#')cnt++;
      }
      if(cnt==K)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int i, j, k, ex1, ex2, ex3, ex4, n, a, b;
	int dice[101][7];
	int command;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		for (j = 1; j <= 6; j++){
			scanf("%d", &dice[i][j]);
		}			
	}

	for (i = 1; i <= n; i++){
		for (j = i + 1; j <= n; j++){
			for (k = 0; k < 10000; k++){
				command = rand() % 4;
				if (command == 0){
					ex1 = dice[i][1];
					ex2 = dice[i][2];
					ex3 = dice[i][5];
					ex4 = dice[i][6];
					dice[i][1] = ex3;
					dice[i][2] = ex1;
					dice[i][5] = ex4;
					dice[i][6] = ex2;
				}
				else if (command == 1){
					ex1 = dice[i][1];
					ex2 = dice[i][2];
					ex3 = dice[i][5];
					ex4 = dice[i][6];
					dice[i][1] = ex2;
					dice[i][2] = ex4;
					dice[i][5] = ex1;
					dice[i][6] = ex3;
				}
				else if (command == 2){
					ex1 = dice[i][1];
					ex2 = dice[i][3];
					ex3 = dice[i][4];
					ex4 = dice[i][6];
					dice[i][1] = ex3;
					dice[i][3] = ex1;
					dice[i][4] = ex4;
					dice[i][6] = ex2;
				}
				else if (command == 3){
					ex1 = dice[i][1];
					ex2 = dice[i][3];
					ex3 = dice[i][4];
					ex4 = dice[i][6];
					dice[i][1] = ex2;
					dice[i][3] = ex4;
					dice[i][4] = ex1;
					dice[i][6] = ex3;
				}
				for (a = 1; a <= 6; a++)
					if (dice[i][a] != dice[j][a])
						break;
				if (a == 7){
					printf("No\n"); return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 2112
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int dp[330][330][330];
int pre[330][26];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int K; cin >> K;
    int N = S.size();

    rep(i,N) {
        rep(j,26) {
            if (i) pre[i][j] = pre[i-1][j];
            else pre[i][j] = -1;
        }
        pre[i][S[i]-'a'] = i;
    }

    rep(i,N+1) rep(j,N+1) rep(k,K+1) dp[i][j][k] = -1;
    dp[0][0][0] = N;
    rep(i,N) {
        rep(j,N+1) {
            rep(k,K+1) {
                if (dp[i][j][k]==-1) continue;
                if (dp[i][j][k] > i) chmax(dp[i+1][j][k],dp[i][j][k]);
                int num = dp[i][j][k];
                if (num and pre[num-1][S[i]-'a'] > i) chmax(dp[i+1][j+1][k],pre[num-1][S[i]-'a']);
                if (k < K and num-1 > i) chmax(dp[i+1][j+1][k+1],num-1);
            }
        }
    }
    int ans = 0;
    rep(i,N+1) {
        rep(j,N+1) {
            rep(k,K+1) {
                if (dp[i][j][k]==-1) continue;
                if (dp[i][j][k] > i) chmax(ans,j*2+1);
                else chmax(ans,j*2);
            }
        }
    }

    cout << ans << ln;
}

Measured memory_bytes: 129280
def main():
    q, h, s, d = map(int, input().split())
    target = int(input())
    h = min(2 * q, h)
    s = min(2 * h, s)
    d = min(2 * s, d)
    answer = target // 2 * d + (target % 2) * s
    print(answer)


if __name__ == '__main__':
    main()



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

main()
{
    int n; cin>>n;
    string s; cin>>s;
    int l=0; int r=n-1;
    int ans=0;
    while(true)
    {
        while(l<n and s[l]=='R') l++;
        while(r>=0 and s[r]=='W') r--;
        if(l<r)
        {
            ans++;
            swap(s[l],s[r]);
        }
        else break;
    }
    cout<<ans;
}

Measured memory_bytes: 3680
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var N int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	var n = 1
	var sum int
	var p = false
	for i := 0; i < N; i++ {
		n = a[n-1]
		sum++
		if n == 2 {
			p = true
			break
		}
	}
	if p {
		fmt.Fprintln(wtr, sum)
	} else {
		fmt.Fprintln(wtr, -1)
	}

	_ = wtr.Flush()
}


Measured memory_bytes: 6320
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let m: usize = read!();
    let mut shops = Vec::with_capacity(n);

    for _ in 0..n {
        let a: usize = read!();
        let b: usize = read!();
        shops.push((a, b));
    }

    shops.sort();

    let mut remaining_number = m;
    let mut sum_cost = 0;
    for (cost, limit) in shops {
        if limit <= remaining_number {
            remaining_number -= limit;
            sum_cost += cost * limit;
        } else {
            let amount_buy = remaining_number;
            sum_cost += cost * amount_buy;
            break;
        }
    }

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


Measured memory_bytes: 4148
program main
  implicit none
  integer :: a, b, k, i, j
  read (*, *) a, b, k
  j = 0
  do i = min(a, b), 1, -1
    if (modulo(a, i) + modulo(b, i) == 0) then
      j = j + 1
      if (j == k) then
        write (*, "(i0)") i
        stop
      end if
    end if
  end do
  stop 1
end program main


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, L;
    cin >> N >> L;

    ll s = 0;

    REP(i, N) {
        s += L + i;
    }

    if (L > 0) {
        s -= L;
    }
    else if (L + N - 1 >= 0) {

    }
    else {
        s -= L + N - 1;
    }


    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


Graph G(100100);

int ans = 1;
int N, K;

void dfs(int vertex, int parent, int level_color, int node_color) {
  ans *= node_color;
  ans %= 1000000007;
  int cnt = 0;
  // cout << "level color : " << level_color << endl;
  int next_level_color = max(K - 2, level_color - 1);
  // cout << "next level color : " << next_level_color << endl;
  for (auto next_v : G[vertex]) {
    if (next_v == parent) continue;
    // cout << "next_v: " << next_v << " next_level_color: " << next_level_color << " cnt : " << cnt << endl; 
    dfs(next_v, vertex, next_level_color, next_level_color - cnt);
    cnt++;
  }
}

signed main() {
  cin >> N >> K;

  
  for (int i = 0; i < N-1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0, -1, K, K);
  cout << ans % 1000000007<< endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	int N, A, B; cin >> N >> A >> B;
	if ((B - A - 1) % 2 == 0){
		cout << "Borys" << endl;
	}else{
		cout << "Alice" << endl;
	} // end if 
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  int ans=0;
  int count=1;
  for(int i=1;i<n;i++){
    if(a[i-1]==a[i]){
      count++;
    }
    else{
      ans+=count%2;
      count=1;
    }
  }
  ans+=count%2;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

template<typename T>
vector<T> convert_base(T x, T b) {
  vector<T> res;
  T t = 1, k = llabs(b);
  while(x) {
    res.emplace_back((x * t) % k);
    if(res.back() < 0) res.back() += k;
    x -= res.back() * t;
    x /= k;
    t *= b/k;
  }
  if(res.empty()) res.emplace_back(0);
  reverse(begin(res),end(res));
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  cin >> n;
  auto ans = convert_base<ll> (n, -2);
  for (auto x:ans) {
    cout << x;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
///
// File:  2699.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 23:53:04 2017
//

#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t D;
    double E;
    cin >> D >> E;
    if (D == 0) break;

    double min_diff = 1000.0;
    for (uint32_t x = 0; x <= D; x++) {
      uint32_t y = D - x;
      min_diff = min(min_diff, abs(sqrt(x * x + y * y) - E));
    }

    cout << fixed;
    cout << setprecision(5) << min_diff + 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 3256
#include <cstdint>
#include <cstdio>

using namespace std;

inline int64_t max(int64_t a, int64_t b) {
  return a >= b ? a : b;
}

inline int64_t min(int64_t a, int64_t b) {
  return a <= b ? a : b;
}

int main() {
  int n;
  scanf("%d", &n);

  int64_t r;
  int64_t r_min;
  int64_t d_max = -1000000000;
  scanf("%lld", &r_min);
  for (int i = 1; i < n; ++i) {
    scanf("%lld", &r);
    d_max = max(d_max, r - r_min);
    r_min = min(r_min, r);
  }
  printf("%lld\n", d_max);                                                                                                                                                

  return 0;
}

Measured memory_bytes: 2728
toInt :: (String -> Int)
toInt x = read x ::Int
listConv :: [Int] -> [Char]
listConv [] = ""
listConv (x:[]) = (show x)
listConv (x:xs) = (show x) ++ " " ++ listConv xs

maxXaxis = 1000000
minXaxis = -1000000
main = do
  args <- words <$> getLine
  putStrLn (listConv [e |e <- [minXaxis..maxXaxis], let k = (map(toInt) args) !! 0,
                                       let x = (map(toInt) args) !! 1,
                                       (x - (k -1)) <= e, e <= (x + (k - 1))])


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

	int N, M, Q;
	cin >> N >> M >> Q;
	int sum[N + 2][N + 2];
	rep(i, N + 2) rep(j, N + 2) sum[i][j] = 0;
	rep(i, M) {
		int L, R;
		cin >> L >> R;
		sum[L][R]++;
	}
	//rep(i, N + 1) {
	//	rep(j, N + 1) {
	//		cout << sum[i][j] << " ";
	//	}
	//	cout << endl;
	//}
	//cout << endl;
	rep(i, N + 1) {
		for(int j = i; j < N; j++){
			sum[i][j + 1] += sum[i][j];
		}
	}
	//rep(i, N + 1) {
	//	rep(j, N + 1) {
	//		cout << sum[i][j] << " ";
	//	}
	//	cout << endl;
	//}
	//cout << endl;
	rep(j, N + 1) {
		for (int i = j; i > 0; i--) {
			sum[i - 1][j] += sum[i][j];
		}
	}
	//cout << endl;
	//rep(i, N + 1) {
	//	rep(j, N + 1) {
	//		cout << sum[i][j] << " ";
	//	}
	//	cout << endl;
	//}
	rep(i, Q) {
		int L, R;
		cin >> L >> R;
		cout << sum[L][R] << endl;
	}

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI M_PI

using namespace std;

int main(void){
    int r; cin >> r;
    cout << 3 * r * r << endl;
    
    return 0;
}

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

struct hoge {
    int p;
    int y;
    int id;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<hoge> ds(m);
    vector<hoge*> ps(m);
    for(int i=0; i<m; i++) {
        cin >> ds[i].p >> ds[i].y;
        ps[i] = &ds[i];
    }
    sort(ps.begin(), ps.end(), [](hoge *a, hoge *b){return a->p<b->p || (a->p==b->p && a->y<b->y);});
    int id = 0;
    for(int i=0; i<m; i++) {
        if(i==0 || ps[i]->p!=ps[i-1]->p) id = 0;
        ps[i]->id = ++id;
    }
    for(int i=0; i<m; i++) {
        printf("%06d%06d\n", ds[i].p, ds[i].id);
    }
    
    return 0;
}


Measured memory_bytes: 3456
n, m = gets.to_s.split.map{|i|i.to_i}
ds = Array.new(m){ gets.to_s.split.map{|i|i.to_i} }.sort{|x,y|x[1]<=>y[1]}

ans = 0
front = 1
ds.each do |ab|
  if ab[0] >= front
    ans += 1
    front = ab[1]
  end
end

puts ans

Measured memory_bytes: 11128
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n;
  cin >> n;
  long ans = 0;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0 && n/i-1 > i){
      ans += (n/i)-1;
    }
  }
  if(n==2)ans = 0;
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
AB = []
for i in range(m):
  ab = list(map(int, input().split()))
  AB.append(ab)

sort_ab = sorted(AB, key=lambda x: x[1])
cur_max = 0
cnt = 0
for el in sort_ab:
  if el[0] >= cur_max:
    cnt += 1
    cur_max = el[1]
print(cnt)

Measured memory_bytes: 29840
def main():
    n = int(input())
    adic = dict()
    bdic = dict()

    for i in range(n):
        a, b = map(int, input().split())
        adic[i+1] = a
        bdic[i+1] = b
    
    bdic2 = sorted(bdic.items(),key = lambda x:x[1])
    time = 0

    for dic in bdic2:
        shigoto = dic[0]
        time += adic[shigoto]
        if time > dic[1]:
            print("No")
            exit()
    
    print('Yes')





if __name__ == "__main__":
    main()

Measured memory_bytes: 70372
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int sum = 0;
			int keep = 0;
			int[] d = new int[6];
			d[0] = 1;
			d[1] = 6;
			d[2] = 2;
			d[3] = 3;
			d[4] = 5;
			d[5] = 4;
			
			for(int i=0;i<n;i++){
				String s = sc.next();
				if(s.compareTo("North")==0 || s.compareTo("South")==0){
					for(int j=0;j<3;j++){
						keep = d[0];
						d[0] = d[2];
						d[2] = d[1];
						d[1] = d[4];
						d[4] = keep;
						if(s.compareTo("North")==0)break;
					}
				}else if(s.compareTo("East")==0 || s.compareTo("West")==0){
					for(int j=0;j<3;j++){
						keep = d[0];
						d[0] = d[5];
						d[5] = d[1];
						d[1] = d[3];
						d[3] = keep;
						if(s.compareTo("East")==0)break;
					}
				}else if(s.compareTo("Right")==0 || s.compareTo("Left")==0){
					for(int j=0;j<3;j++){
						keep = d[2];
						d[2] = d[3];
						d[3] = d[4];
						d[4] = d[5];
						d[5] = keep;
						if(s.compareTo("Right")==0)break;
					}
				}
				sum += d[0];
			}
			System.out.println(sum+1);
		}
	}
}

Measured memory_bytes: 25400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var D = c2i(RL());

            var acstr = "AC";
            var wastr = "WA";
            var tlestr = "TLE";
            var restr = "RE";
            int accnt=0,wacnt=0,tlecnt=0,recnt=0;

            for (var i = 0; i < D; i++)
            {
                var str = RL();
                if (str.Equals(acstr)) accnt++;
                if (str.Equals(wastr)) wacnt++;
                if (str.Equals(tlestr)) tlecnt++;
                if (str.Equals(restr)) recnt++;
            }

            var xstr = " x ";
            Console.WriteLine(acstr+xstr+accnt);
            Console.WriteLine(wastr + xstr + wacnt);
            Console.WriteLine(tlestr + xstr + tlecnt);
            Console.WriteLine(restr + xstr + recnt);
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 30712
function Main(args){
    const input = args.trim().split(" ");
    const [A, B, H, M] = input;

    const c = (H / 12 + M / (12*60) - M / 60) * Math.PI * 2;
    const ans = (A**2 + B**2 - 2*A*B*Math.cos(c)) ** 0.5;
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29756
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	return c - '0';
}
int keta(int a) {
	return to_string(a).size();
}
int a[310][310];
int b[100010], c[100010],l[100010],r[100010],s[100010];
signed main() {
	int h, w, d, q;
	cin >> h >> w >> d;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}
	cin >> q;
	rep(i, q) {
		cin >> l[i] >> r[i];
	}
	rep(i, h) {
		rep(j, w) {
			b[a[i][j]] = i;
			c[a[i][j]] = j;
		}
	}
	for (int i = d + 1; i <= h * w; i++) {
		s[i] = s[i - d] + abs(b[i] - b[i - d]) + abs(c[i] - c[i - d]);
	}
	rep(i, q) {
		cout << s[r[i]] - s[l[i]] << endl;
	}
}


Measured memory_bytes: 5632
#include<stdio.h>

int main(){
  int m1,d1,m2,d2;
  scanf("%d %d",&m1,&d1);
  scanf("%d %d",&m2,&d2);
  if(d1>d2){
    printf("%d",1);
  }else {
    printf("%d",0);
  }

return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
#define Maxn 5005
#define LL long long
const int mod = 1e9+7;
int n;
LL h[Maxn],p[Maxn];
char s[Maxn];
map<int,int>M;
bool check(int s)
{
    M.clear();
    for(int i=s;i<=n;i++) 
    {
        int t=(h[i]-(LL)h[i-s]*p[s]%mod+mod)%mod;
        int pre=M[t];
        if(pre) 
        {
            if(i-pre>=s) return true; 
        }
        else M[t]=i;
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    p[0]=1; h[0]=0;
    for(int i=1;i<=n;i++) h[i]=((LL)h[i-1]*29+s[i])%mod,p[i]=(LL)p[i-1]*29%mod;
    int l=0,r=n;
    while(l<r)
    {
        int mid=(l+r+1)>>1;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main() {
  string ss;
  int q;
  cin >> ss >> q;
  deque<char> s(ss.begin(), ss.end());
  bool r = false;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      r = !r;
    } else if (t == 2) {
      int f;
      char c;
      cin >> f >> c;
      if (r) {
        if (f == 1) f = 2;
        else if (f == 2) f = 1;
      }
      if (f == 1) {
        s.push_front(c);
      } else if (f == 2) {
        s.push_back(c);
      }
    }
  }
  if (r) {
    reverse(s.begin(), s.end());
  }
  for (char x : s) {
    cout << x;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <fstream>
#include <cstring>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;

	cout << max(a + b, max(2 * a - 1, 2 * b - 1)) << '\n';

	return 0;
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
[a.append(list(map(int,input().split()))) for _ in range(n)]
res=0
for i in a:
    if sum([i[j]*b[j] for j in range(len(i))])+c>0:
        res+=1
print(res)

Measured memory_bytes: 3064
// 解説解法1

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

string s;
ll n;

ll dp[200010];

void pr(ll a){
    cout << a << endl;
    exit(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin >> s;
    n = SZ(s);
    if(n == 1) pr(1);
    dp[1] = 1;
    dp[2] = (s[0] == s[1] ? 1 : 2);
    repr(i, 2, n){
        if(s[i] != s[i-1]){
            dp[i+1] = dp[i] + 1;
        }else{
            dp[i+1] = dp[i-2] + 2;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;
ll n, m;
ll color[100000];
graph G;

bool dfs(ll v, ll c){
    color[v] = c;
    for(int i=0; i<G[v].size(); ++i){
        int nv = G[v][i];
        if(color[nv]!=-1){
            if(color[nv]==c){return false;}
        }
        else if(!dfs(nv, 1-c)){return false;}
    }
    return true;
}

int main(){
    cin >> n >> m;
    G.resize(n);
    memset(color, -1, sizeof(color));
    for(ll i=0; i<m; ++i){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    ll b = 0, w = 0;
    if(dfs(0, 1)){
        for(ll i=0; i<n; ++i){
            if(color[i]==1){b++;}
            else if(color[i]==0){w++;}
        }
        cout << b*w - m << endl;
    }else{
        cout << n*(n-1)/2 - m << endl;
    }
    return 0;
}

Measured memory_bytes: 10264
n, m = input().split()
n = int(n)
m = int(m)
A = []
B = []

for i in range(n):
    a = [int(e) for e in input().split()]
    A.append(a)
    
for j in range(m):
    b = int(input())
    B.append(b)
    
for x in range(n):
    D = 0
    for y in range(m):
        C = A[x][y] * B[y]
        D += C
    print(D)


Measured memory_bytes: 6008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

ll n, a, b, c, d;
map<ll, ll> memo;

ll rec(ll k) {
    if (memo[k]) return memo[k];
    if (k == 0) return memo[k] = 0;
    if (k == 1) return memo[k] = d;
    ll res = INF;
    res = min(res, (k - k / 2 * 2) * d + rec(k / 2) + a);
    res = min(res, ((k + 1) / 2 * 2 - k) * d + rec((k + 1) / 2) + a);
    res = min(res, (k - k / 3 * 3) * d + rec(k / 3) + b);
    res = min(res, ((k + 2) / 3 * 3 - k) * d + rec((k + 2) / 3) + b);
    res = min(res, (k - k / 5 * 5) * d + rec(k / 5) + c);
    res = min(res, ((k + 4) / 5 * 5 - k) * d + rec((k + 4) / 5) + c);
    if (d <= INF / k) res = min(res, d * k);
    return memo[k] = res;
}

int main() {
    int t;
    cin >> t;
    REP(_, t) {
        cin >> n >> a >> b >> c >> d;
        memo.clear();
        cout << rec(n) << "\n";
    }
    return 0;
}


Measured memory_bytes: 4328
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

string func(string& s){
    int n=s.size();
    int up=0;
    string ret="";
    for(int i=n-1;i>=0;--i){
        up+=9*(s[i]-'0');
        ret+=(up%10)+'0';
        up/=10;
    }
    if(up)ret+=up+'0';
    reverse(ret.begin(),ret.end());
    return ret;
}

int main(){
    string s;
    cin>>s;
    s=func(s);
    int n=s.size();
    vector<int> ret(n+5);
    rep(i,n)ret[i]=s[n-i-1]-'0';
    int sum=0;
    rep(i,n)sum+=ret[i];
    int ans=0;
    while(1){
        int i=0;
        while(ret[i]==9){
            sum-=9;
            ret[i]=0;
            ++i;
        }
        sum+=1;
        ret[i]++;
        ++ans;
        if(sum<=ans)break;
    }
    cout<<(ans+8)/9<<endl;

    return 0;
}

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

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

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

int main() {
    double ans = 0;
    int tmp;
    double n;
	cin >> n;
	
    cout << 2* n * M_PI << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 987654321
#define PI 3.1415926535

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

    int a, b;
    cin >> a >> b;
    cout << 6-a-b;
}

Measured memory_bytes: 256
#create date: 2020-07-01 11:50

import sys
stdin = sys.stdin
import math

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b, h, m = na()
    theta1 = 2 * math.pi * (m/60)
    theta2 = 2 * math.pi * ((h*60+m)/720)
    theta = min(abs(theta1 - theta2), abs(theta2 - theta1))
    d = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(theta))
    print("{:.10f}".format(d))

if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;

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

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

  string ans = "";
  rep(i, n) {
    ans += s[i];
    ans += t[i];
  }

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


Measured memory_bytes: 256
<?php

class Solver
{
    private $number_of_elements;
    private $values = array();

    public function __construct()
    {
        $lines = array();
        while (1) {
            if (!$line = fgets(STDIN)) break;
            $line = trim($line);
            $lines[] = $line;
        }

        $this->number_of_elements = $lines[0];
        $this->values = array_slice($lines, 1);
    }

    public function getAnswer()
    {
        $max_difference = -INF;
        $min_value = $this->values[0];
        for ($i = 1; $i < $this->number_of_elements; $i++) {
            $max_difference = max($max_difference, $this->values[$i] - $min_value);
            $min_value = min($min_value, $this->values[$i]);
        }
        echo $max_difference, PHP_EOL;
    }
}

$answer = new Solver;
$answer->getAnswer();


Measured memory_bytes: 64084
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n,k = NextInts()
st = set()
for i in range(k):
    d = NextInt()
    da = NextIntList()
    for i in da: st.add(i)
print(n-len(st))

Measured memory_bytes: 9232