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

int main() {
    int n,k;
    cin >> n >>k;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    int ans = 1001001001;
    for(int i = 0;i<n-k+1;i++) {
        ans = min(ans,abs(a[i])+abs(a[i]-a[i+k-1]));
        ans = min(ans,abs(a[i+k-1])+abs(a[i+k-1]-a[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import itertools
N = int(input())
ans_a = 0
ans_b = 0
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
k = list(itertools.permutations(range(1,N+1)))
P = tuple(P)
Q = tuple(Q)
for i in range(0,len(k)):
    if P == k[i]:
        ans_a = i
        break
for j in range(0,len(k)):
    if Q == k[j]:
        ans_b = j
        break
print(abs(ans_a-ans_b))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e6+5, maxn1=2e5+3;
#define MAXN 200005
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

bool prime[maxn];
vector<ll> primes;

// Time Complexity: O(loglog(n))
void sieve(ll n)
{
    memset(prime, 1, sizeof(prime));
    prime[1] = 0;
    for (ll i = 2; i <= n; i++)
    {
        if (prime[i])
        {
            for (ll j = i * 2; j <= n; j += i)
                prime[j] = 0;
            primes.pb(i);
        }
    }
}

int main()
{

ll n,i,j,k,b,c,d,test,cnt=0;
cin>>n;
sieve(maxn);
for(auto it:primes)
{
    // cout<<it<<" ";
    if(n%it==0)
    {
        // cout<<it<<" ";
        k=it;
        while(n and n%k==0)
        {
            
            cnt++;
            n/=k;
            // cout << k << " "<<n<<endl;
            k*=it;
        }
    }
}
if(n>1e6)
{
    cnt++;
}
cout<<cnt<<endl;
}


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

using namespace std;

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

using ll = long long;
using ull = unsigned long long;

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int h,n;cin >> h >> n;

  vector<int> a(n);

  for(auto &i: a){
  	cin >> i;
  }

  ll ans = accumulate(a.begin(),a.end(),0ll);

  if(ans >= h){
  	puts("Yes");
  }else{
  	puts("No");
  }

  return 0;
}

Measured memory_bytes: 640
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin>>N;
  vector<LL> d(N);
  REP(i,N){
    cin >> d[i];
  }

  SORT(d);

  cout << d[N / 2] - d[N / 2 - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s, t, ans;
string table = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string p[] = { "101", "000000", "000011", "10010001", "010001", "000001",
"100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000",
"0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111",
"10011111", "1000", "00110", "00111", "10011100", "10011101", "000010",
"10010010", "10010011", "10010000" };
string table2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

int main(){
	while (getline(cin, s)){
		REP(i, s.size()){
			REP(j, table.size()){
				if (s[i] == table[j]){
					t += p[j];
				}
			}
		}		
		if (t.size() % 5 != 0){
			int a = 5 - t.size() % 5;
			REP(i, a){
				t += "0";
			}
		}
		for (int i = 0; i < t.size(); i += 5){
			string k = t.substr(i, 5);
			int sum = 0;
			REP(i, 5){
				if (i != 4) sum += pow(2 * (k[i] - '0'), 4 - i);
				else sum += k[i] - '0';
			}
			ans += table2[sum];
		}
		cout << ans << endl;
		t.clear();
		ans.clear();
	}
}

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

int main (void) {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double minute = 0;
    minute = 60.0 * h + m;

    double theta_a = minute * 0.5;
    double theta_b = m * 6.0;

    double theta = fabs(theta_a - theta_b) * M_PI / 180.0;

    double ans = 0.0;
    ans = sqrt(a*a + b*b - 2.0*a*b*cos(theta));
    
    printf("%.10f\n", ans);

}

Measured memory_bytes: 4216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	static int r;
	static int[] x;
	static long[][] d;
	static long ans = 10000000000L;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		r = Integer.parseInt(sa[2]);

		x = new int[r];
		sa = br.readLine().split(" ");
		for (int i = 0; i < r; i++) {
			x[i] = Integer.parseInt(sa[i]) - 1;
		}

		d = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(d[i], 10000000000L);
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			int c = Integer.parseInt(sa[2]);
			d[a][b] = c;
			d[b][a] = c;
		}
		br.close();

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		dfs(new ArrayList<Integer>());

		System.out.println(ans);
	}

	static void dfs(List<Integer> list) {
		if (list.size() == r) {
			long sum = 0;
			for (int i = 1; i < r; i++) {
				sum += d[list.get(i - 1)][list.get(i)];
			}
			ans = Math.min(ans, sum);
			return;
		}

		for (int i = 0; i < r; i++) {
			if (!list.contains(x[i])) {
				list.add(x[i]);
				dfs(list);;
				list.remove(list.size() - 1);
			}
		}
	}
}


Measured memory_bytes: 35960
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans = 1e9;

    for (int i = 0; i <= max(x, y); i++) {
        ans = min(ans, i * c * 2 + max(0, x - i) * a + max(0, y - i) * b);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
s=input()
tmp=Counter(s)
ans=0
for i in range(n+1):
    l,r=s[:i],s[i:]
    dic={}
    tmp=Counter(r)
    for j in range(i):
        if tmp[l[j]]>0:
            dic[l[j]]=1
    ans=max(len(dic),ans)
    # print(l,r)
print(ans)

Measured memory_bytes: 39536
n, z, w = map(int, input().split())
a = list(map(int, input().split()))

if n >= 2:

    # xがaiをとったときにyが最適に行動した時のスコア
    dp_x = [abs(a[-1] - a[i]) for i in range(n)]
    # yがaiをとったときにxが最適に行動した時のスコア
    dp_y = [abs(a[-1] - a[i]) for i in range(n)]

    for i in reversed(range(n-1)):
        for j in range(i):
            dp_x[j] = min(dp_x[j], dp_y[i])
            dp_y[j] = max(dp_y[j], dp_x[i])

    print(max(abs(a[-1]-w), max(dp_x)))
else:
    print(abs(a[-1]-w))



Measured memory_bytes: 3316
N, M = [int(x) for x in input().split()]
a = set(int(input()) for _ in range(M))
 
MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1#二段目の調節　0段目の場合の数
 
for i in range(1, N + 1):
  if i in a:
    continue
  x = dp[i - 1]
  if i > 1:
    x += dp[i - 2]
  dp[i] = x % MOD

ans = dp[N]
print(ans)

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

class graph
{
public:
	int v;
	list<int> *adj;
	int *par;
	bool *m;
	bool *l;
	bool *visited;
	
	graph(int v)
	{
		this->v = v;
		adj = new list<int>[v];
		par = new int[v];
		m = new bool[v];
		l = new bool[v];
		visited = new bool[v];
		for (int i = 0; i < v; ++i)
		{
			par[i] = -1;
			m[i] = false;
			l[i] = false;
			visited[i] = false;
		}
	}

	void add(int a, int b)
	{
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	void bfs(queue<int>& i);
};

void graph::bfs(queue<int>& i)
{
	if(i.empty())
		return;
	int k = i.front();
	i.pop();
	visited[k] = true;
	for(auto t: adj[k])
	{
		if(!visited[t])
		{
			par[t] = k;
			visited[t] = true;
			i.push(t);
		}
	}
	bfs(i);
}


void solve()
{
	int n,m;
	// cin>>n>>m;
	scanf("%d %d",&n,&m);
	graph g(n);
	for (int i = 0; i < m; ++i)
	{
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		g.add(u,v);
	}
	queue<int> q;
	q.push(0);
	g.visited[0] = true;
	g.bfs(q);
	// cout<<"Yes"<<endl;
	printf("Yes\n");
	for (int i = 1; i < n; ++i)
	{
		// cout<<g.par[i]+1<<endl;
		printf("%d\n", g.par[i]+1);
	}
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

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

using namespace std;

const int N = 1234567;
const int M = 8;

int n;
char s[N];
//char ss[M][16] = {"dream", "dreamer", "erase", "eraser", "dreamdreamer", "dreamerase", "dreameraser", "dreamererase", "dreamereraser", "eraseeraser"};
char ss[M][16] = {"dream", "dreamer", "erase", "eraser", "dreamerase", "dreamererase", "dreamereraser", "dreameraser"};
int len[M];
int p[M];

bool ok(int x, int y) {
  if (x + len[p[y]] > n) return false;
  for (int i = 0; i < len[p[y]]; i++) {
    if (s[i + x] != ss[p[y]][i]) return false;
  }
  return true;
}

int main() {
  scanf("%s", s);
  for (int i = 0; i < M; i++) len[i] = strlen(ss[i]);
  for (int i = 0; i < M; i++) p[i] = i;
  sort(p, p + M, [&](const int i, const int j) {
    return len[i] > len[j];
  });
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    bool can = false;
    for (int j = 0; j < M; j++) {
      if (ok(i, j)) {
        i += len[p[j]] - 1;
        can = true;
        break;
      }
    }
    if (!can) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	set<string> st;
	rep(i, n){
		string s;
		cin >> s;

		st.insert(s);
	}

	cout << st.size() << endl;
}


Measured memory_bytes: 19276
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max_s(a, b int) (int, int) {
	if a > b {
		return a, b
	}
	return b, a
}

const m = 1000000000

func main() {
	sc.Split(bufio.ScanWords)

	S := getInt()
	a := m
	b := 1
	var c, d int
	if S == int(1e18) {
		c = 0
		d = m
	} else if S <= m {
		c = S
		d = 0
	} else {
		c = m - S%m
		d = (S + c) / m
	}

	out(0, 0, a, b, c, d)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    int A;
    double ans[N];
    double cnt = 0;
    cin >> N;
    REP(i,N){
        cin >> A;
      //cout << A[i] << endl;
        ans[i] = 1.0 / (double)A; 
        cnt += ans[i];
    }
  double K = 1.0/cnt;
    cout << K << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<int> b(N, 0);
    for (int i = N; i >= 1; i--) {
        int j = i;
        int count = 0;
        while (j <= N) {
            if (b[j - 1] == 1) count++;
            j += i;
        }
        if (count % 2 != a[i - 1]) b[i - 1] = 1;
    }

    vector<int> output;
    for (int i = 0; i < N; i++) {
        if (b[i] != 0) output.push_back(i + 1);
    }
    cout << output.size() << endl;
    for (int i = 0; i < output.size(); i++) {
        cout << output[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 5416
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   int n;
   cin >> n;
   int a[n];
   rep(i, n) cin >> a[i];

   int count = 0;
   int m = 0;
   rep(i,n-1) {
       if(a[i]>=a[i+1]){
           count++;
       }else{
           m = max(m, count);
           count = 0;
       }
       if(i==n-2)
           m = max(m, count);
   }
   cout << m << endl;
   return 0;
}

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

int dp[3010] = {};

int main(){
	int N,T,S;
	cin >> N >> T >> S;
	for(int i = 0 ; i < N ; i++){
		int A,B;
		cin >> A >> B;
		for(int j = T ; j >= B ; j--){
			if(!(j-B < S && S < j)) dp[j] = max( dp[j] , dp[j-B] + A );
		}
	}
	cout << *max_element(dp,dp+3010) << endl;
}

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

#define N 44

int n;
char s[N][N];
typedef unsigned long long ull;

ull dp[N][N][N][N][2];

int main() {
    scanf("%d", &n); n <<= 1;
    for (int i = 1; i <= n; i ++) scanf("%s", s[i] + 1);
    for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) s[i][j] -= '0';
    for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) dp[i][i-1][j+1][j][0] = dp[i][i-1][j+1][j][1] = 1;

    for (int a = n; a >= 2; a --) {
        for (int b = a; b < n; b ++) {
            for (int c = n; c > b; c --) {
                for (int d = c; d <= n; d ++) {

                    for (int p = a; p <= b; p ++) {
                        for (int q = c; q <= d; q ++) {
                            if (!s[p][q]) continue;
                            dp[a][b][c][d][0] += dp[a][p-1][p+1][b][1] * dp[c][q-1][q+1][d][1];
                        }
                    }
                    for (int p = a; p <= b; p ++) {
                        for (int q = c; q <= d; q ++) {
                            dp[a][b][c][d][1] += dp[a][p][q][d][0] * dp[p+1][b][c][q-1][1];
                        }
                    }
                }
            }
        }
    }
    ull rlt = 0;
    for (int a = 2; a <= n; a ++) if (s[1][a]) rlt += dp[2][a-1][a+1][n][1];
    cout << rlt << endl;
}


Measured memory_bytes: 53504
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        char str[] = scanString().toCharArray();
        out.print(str[2] == str[3] && str[4] == str[5] ? "Yes" : "No");
   }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 22484
#include <iostream>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d = 0;
	int e;
	string t;
	cin >> e;
	for (int i=0; i < e; i++) {
		cin >> t;
		if (t == "AC")a++;
		if (t == "WA")b++;
		if (t == "TLE")c++;
		if (t == "RE")d++;
	}
	cout << "AC x " << a << endl << "WA x " << b << endl << "TLE x " << c << endl << "RE x " << d << endl;
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define MOD 1000000007
#define N 1000006
#define INF 1000000000000000000
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define randright srand(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

void solve(){
    int r;
    cin>>r;
    cout<<(r*r)<<"\n";
}

signed main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

const int MOD = 1e9 + 7;

int n;
vvb v;
vvi memo;

int dp(int pos, int bits) {
	if(pos == n) return 1;
	int& ans = memo[pos][bits];
	if(ans != -1) return ans;
	ans = 0;
	for (int i = 0; i < n; ++i) {
		if(v[pos][i] and (bits & (1 << i))) {
			int new_bits = bits ^ (1 << i);
			ans = (ans + dp(pos+1, new_bits)) % MOD;
		}
	}
	return ans;
}

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	while (cin >> n) {
		v = vvb(n, vb(n));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				int a;
				cin >> a;
				v[i][j] = a;
			}
		}
		memo = vvi(n, vi(1 << n, -1));
		cout << dp(0, (1 << n) - 1) << '\n';
	}
}




Measured memory_bytes: 180608
program atcoder0328_1
  character(6)::S
  read(5,*) S
  if(S(3:3)==S(4:4) .and. S(5:5)==S(6:6)) then
     write(6,*)'Yes'
  else
     write(6,*)'No'
  end if
end program atcoder0328_1

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long 
#define mkp make_pair 
using namespace std;
typedef pair<ll,ll> pa;
const int base = 31;
const int mod = 1e9+7;
map< pa , ll > mp;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int N;
char s[110];
int main()
{
	N=read();N=2*N;scanf("%s",s+1);
	int mx=(1<<(N/2))-1;
	for(register int i=0;i<=mx;++i)
	{
		ll hash1=0;
		for(register int j=1;j<=N/2;++j)
		{
			if((1<<(j-1))&i)
			{
				hash1=(1ll*hash1*base+(s[j]-'a'+1));
			}
		}ll hash2=0;
		for(register int j=N/2;j;--j)
		{
			if(!((1<<(j-1))&i))
			{
				hash2=(1ll*hash2*base+(s[j]-'a'+1));
			}
		}
		mp[mkp(hash1,hash2)]++;
	}ll ans=0;
	for(register int i=0;i<=mx;++i)
	{
		ll hash2=0;
		for(register int j=1;j<=N/2;++j)
		{
			if(((1<<(j-1))&i))
			{
				hash2=(1ll*hash2*base+(s[j+N/2]-'a'+1));
			}
		}ll hash1=0;
		for(register int j=N/2;j;--j)
		{
			if(!((1<<(j-1))&i))
			{
				hash1=(1ll*hash1*base+(s[j+N/2]-'a'+1));
			}
		}
		ans+=mp[mkp(hash1,hash2)];
	}cout<<ans; 
	return 0;
}


Measured memory_bytes: 33024
/*
Template for vjudge.net

	Author: Iqbal Hossain Rasel
	CodeForces: The_Silent_Man
	AtCoder   : IHR57
	TopCoder  : IHR57

*/
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int arr[MAX];

int cs[MAX][22];
ll dp[MAX];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin>>n;

    for(int i = 1; i <= n; i++){
    	cin>>arr[i];
    	for(int j = 0; j < 21; j++){
    		if(check(arr[i], j)){
    			cs[i][j] = cs[i-1][j] + 1;
    		}
    		else
    			cs[i][j] = cs[i-1][j];
    	}
    }

    dp[0] = 0;
    for(int i = 1; i <= n; i++){
    	int low = 1, high = i, mid, ans;
    	while(low <= high){
    		mid = (low + high + 1) >> 1;
    		bool flag = true;
    		for(int j = 0; j < 21; j++){
    			if(cs[i][j] - cs[mid-1][j] >= 2){
    				flag = false;
    				break;
    			}
    		}
    		if(flag){
    			ans = mid;
    			high = mid - 1;
    		}
    		else{
    			low = mid + 1;
    		}
    	}
    	int t = (i - ans + 1);
    	dp[i] = dp[i-1] + t;
    }

    cout<<dp[n]<<endl;

    return 0;
}


Measured memory_bytes: 19840
import numpy as np
import math
A, B, H, M = map(int, input().split())
thetaB = 6 * M
thetaA = 0.5 * (60 * H + M)
Ax = math.sin(math.radians(thetaA)) * A
Ay = math.cos(math.radians(thetaA)) * A
Bx = math.sin(math.radians(thetaB)) * B
By = math.cos(math.radians(thetaB)) * B
AA = np.array([Ax,Ay])
BB = np.array([Bx,By])
print(np.linalg.norm(AA-BB))


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

int main (){
  int n;
  cin >> n;
  int i;
  int a;
  double b;
 for (i = 0;i < n; i++){
   cin >> a;
   b += (double)1/a;
 }
  cout << 1/b;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll x = 0;
  ll ans = 0;
  rep(i, N) {
    ans = (ans + A[i] * x) % mod;
    x = (x + A[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4844
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


int main(){
    
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }

    int threshold = k/2;
    int res = 0;

    for(int i=0;i<n;i++){
        if(x[i]<=threshold){
            res += 2*x[i];
        } else {
            res += 2*(k - x[i]);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
  int n; cin>>n;
  int ans=0;
  int a[100001]={},tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    if(tmp>100000) ans++; 
    else a[tmp]++;
  }
  for(int i=1;i<100001;i++){
    if(a[i]>=i) ans+=a[i]-i;
    else ans+=a[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    string s; cin >> s;

    rep(i, s.size()-1){
        if(s[i]=='?'){
            if( i>=1 && s[i-1]=='P')s[i]='D';
            else if(s[i+1]=='?'){
                s[i]='P';
                s[i+1]='D';
                i++;
            }
            else if(s[i+1]=='D'){
                s[i]='P';
            }
            else{
                s[i]='D';
            }
        }
    }
    if(s[s.size()-1]=='?') s[s.size()-1]='D';

    // int counts=0;
    // // counts += count(s.cbegin(), s.cend(), "D");

    // rep(i, s.size()-1){
    //     if(s[i]=='P'){
    //         if(s[i+1]=='D'){
    //             counts++;
    //             i++;
    //         }
    //     }
    // }
    // rep(i, s.size()){
    //     if(s[i]=='D'){
    //             counts++;
    //     }
    // }
    out(s);

}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    cout << 2 * N - 2 << "\n";

    int bg = 0;

    vi a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (abs(a[i]) > abs(a[bg]))
            bg = i;
    }

    for (int i = 0; i < N; i++) {
        if (i != bg) cout << bg + 1 << " " << i + 1 << "\n";
    }

    if (a[bg] > 0) {
        for (int i = 0; i + 1 < N; i++) {
            cout << i + 1 << " " << i + 2 << "\n";
        }
    } else {
        for (int i = N - 1; i > 0; i--) {
            cout << i + 1 << " " << i << "\n";
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	string line;
	cin >> line;

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

	vector<string> V;

	int maximum = min(K,(int)line.length());

	for(int len = 1; len <= maximum ; len++){

		for(int left = 0; left+len-1 < line.length(); left++){
			string work;
			for(int i = 0; i < len; i++){

				work += line[left+i];
			}
			V.push_back(work);
		}
	}

	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	/*for(int i = 0; i < V.size(); i++){

		printf("V[%d]:%s\n",i,V[i].c_str());
	}*/

	printf("%s\n",V[K-1].c_str());

	return 0;
}


Measured memory_bytes: 4356
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    # key[i]:10進数でiを開けれる鍵の値段
    key = [inf]*(1<<n)
    for _ in range(m):
        a,b = map(int, input().split())
        c = list(map(int, input().split()))
        binary = 0
        for i in c:
            binary += 2**(i-1)
        if key[binary] > a:
            key[binary] = a

    # dp[i]:10進数で宝iを開けてる時の最小値段
    dp = [inf]*(1<<n)
    dp[0] = 0
    for i in range(1<<n):
        if key[i] == inf:
            continue
        for s in range(1<<n):
            if (i|s) == s:
                continue
            dp[i|s] = min(dp[i|s], dp[s]+key[i])
    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 43356
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>




using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << setprecision(7) << (x) << endl;

struct idxx{
    int a;
    int b;
    int c;
};

long double pi = 3.14159265359;
map<tuple<int,int,int>,int> mp;

int n;
int l[10000];
// int minn=10000000;
// int maxn=-1;
int ans= 0;

// void b_search_process(int left, int right, int x){
//     int mid = (right + left)/2;
//     if(right == left){
//         ;
//     }
//     else if(l[mid] < x){    
//         b_search_process(mid+1,right,x);
//         maxn = max(maxn,mid);
//     }
//     else{
//         minn = min(minn,mid);
//         b_search_process(left, mid,x);
//     }
// }

// void b_search(int left, int right, int x){
//     minn=100000000;
//     maxn=-1;
//     b_search_process(left,right,x); //これした後にminnの値が変わってないなら、lはx以上の要素がない。maxnが変わってないなら、lはx未満の要素なし
//     if(minn == 100000000) minn = n;
    
// }

tuple<int ,int> bi_search(int left, int right, int x){
    int minn=right;
    int maxn=left-1;
    while(left!=right){
        int mid = (right+left)/2;
        if(l[mid] < x){
            maxn = max(maxn,mid);
            left = mid+1;
        }
        else{
            minn = min(minn,mid);
            right = mid;
        }
    }
    tuple<int ,int> t = make_tuple(maxn,minn);

    return t;
}

int main(){
    cin >> n;
    rep(i,n) cin >> l[i];
    sort(l,l+n);
    rep(i,n-2){
        for(int j=i+1;j<n-1;j++){
            int a = l[i];
            int b = l[j];
            tuple<int ,int> t = bi_search(0,n,a+b);
            // cout << get<0>(t) << " " << get<1>(t) <<  endl;
            // int idx = maxn;
            // int idx = cmin - 1;
            // ans += cmax - j;
            // ans += idx - j;
            ans += get<0>(t) - j;
        }
    }
    cout << ans << endl;


return 0;
}

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

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] damWater = Console.ReadLine().Split(' ');

            int[] answer = new int[3];

            answer[0] = int.Parse(damWater[0]) + int.Parse(damWater[1]);
            answer[1] = int.Parse(damWater[0]) - int.Parse(damWater[1]);
            answer[2] = int.Parse(damWater[0]) * int.Parse(damWater[1]);

            Console.WriteLine(answer.Max());
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

int digitsum(int N)
{
	int res = 0;
	while(N > 0)
	{
		res += N % 10;
		N /= 10;
	}

	return res;
}

void solve(void){

	int N;
	cin >> N;

	cout << (N % digitsum(N) == 0 ? "Yes" : "No") << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

ll dp[51][51][2501]; // i番目までのカードからj枚選んで合計がk

void solve()
{
    int N, A; cin >> N >> A;
    vll x(N+1); REP1(i, N) cin >> x[i];

    dp[0][0][0] = 1;

    REP(i, N+1)
    {
        REP(j, N+1)
        {
            REP(k, 2501)
            {
                if(i == 0 && j == 0 && k == 0) dp[i][j][k] = 1;
                else if(i >= 1 && x[i] > k) dp[i][j][k] = dp[i-1][j][k];
                else if(i >= 1 && j >= 1 && k >= x[i]) dp[i][j][k] = dp[i-1][j-1][k-x[i]] + dp[i-1][j][k]; 
                else dp[i][j][k] = 0;
            }
        }
    }
    
    ll ans = 0;
    REP1(j, N)
    {
        ans += dp[N][j][j*A];
    }
    cout << ans << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll n;
    ll ans=0;
    cin >> n;
    vector<ll>mon(n+1);
    vector<ll>yusya(n);
    rep(i,n+1) cin >> mon[i];
    rep(i,n) cin >> yusya[i];
    
    rep(i,n){
        ll monsum;
        monsum = mon[i] + mon[i+1];
        if(monsum >= yusya[i]){
            if(mon[i] <= yusya[i]){
                mon[i+1] = monsum - yusya[i];
            }
            ans += yusya[i];
        }
        else{
            mon[i+1] = 0;
            ans += monsum;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll x;cin>>x;
    rep(i,1,1000){
        ll y=x*i;
        if(y%360==0){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

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

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

    ii inp[n];
    for (int i = 0; i < n; i++)
        scanf("%d %d", &inp[i].first, &inp[i].second);

    sort(inp, inp + n);

    ll ans = 0;
    for (int i = 0; m > 0 && i < n; i++) {
        ans += (ll)min(m, inp[i].second) * inp[i].first;
        m -= inp[i].second;
    }

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

    return 0;
}


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

using matrix = vector<vector<double>>;

bool is_zero(double x) {
    return abs(x) < 1e-9;
}

int rank_matrix(matrix a) {
    const int R = a.size(), C = a[0].size();
    int r = 0;
    for(int i = 0; i < C && r < R; ++i) {
        int pivot = r;
        for(int j = r + 1; j < R; ++j) {
            if(abs(a[j][i]) > abs(a[pivot][i])) {
                pivot = j;
            }
        }
        swap(a[pivot], a[r]);
        if(is_zero(a[r][i])) continue;
        for(int k = C - 1; k >= i; --k) {
            a[r][k] /= a[r][i];
        }
        for(int j = r + 1; j < R; ++j) {
            for(int k = C - 1; k >= i; --k) {
                a[j][k] += -a[r][k] * a[j][i];
            }
        }
        ++r;
    }
    return r;
}

int main() {
    mt19937 mt(random_device{}());

    int n, m; cin >> n >> m;
    vector<vector<int>> es(n);
    for(int i = 0; i < m; ++i) {
        int sz; cin >> sz;
        for(int j = 0; j < sz; ++j) {
            int v; cin >> v;
            es[v - 1].push_back(i);
        }
    }

    int ans = 0;
    matrix t(m * 2, vector<double>(m * 2));
    for(int i = 0; i < n; ++i) {
        ans += es[i].empty();
        if(es[i].size() == 2u) {
            const int val = (abs((int)mt()) % 100) + 1;
            int e1 = es[i][0], e2 = es[i][1];
            t[e1][e2] = val;
            t[e2][e1] = -val;
        } else if(es[i].size() == 1u) {
            const int val = (abs((int)mt()) % 100) + 1;
            const int e1 = es[i][0], e2 = e1 + m;
            t[e1][e2] = val;
            t[e2][e1] = -val;
        }
    }
    ans += rank_matrix(t) / 2;
    cout << ans << endl;
}



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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define fi first
#define se second

ll n, a[M];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    a[1]--;
    for (int i = 2; i <= n; i++){
        if (a[i] == a[i - 1]) continue;
        else if (a[i] < a[i - 1]){
            cout << "No";
            return 0;
        }
        else a[i]--;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 1024
x, k, d = gets().chomp.split("\s").map{|x| x.to_i}

start_diff = x.abs #6
max_move = k * d #8

if start_diff > max_move
  puts start_diff - max_move
  exit()
end

steps = start_diff / d #1
moved = steps * d #4
rem = start_diff - moved #2
step_rem = k - steps #1

if step_rem.even?
  puts rem.abs
else
  puts (rem + d).abs > (rem - d).abs ? (rem - d).abs : (rem + d).abs
end


Measured memory_bytes: 14328
#include<iostream>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define N 100
using namespace std;

void trace(int A[], int n) {
  int i;
  rep(i,n) {
    cout << A[i];
    if (i < n-1) cout << " ";
  }
  cout << endl;
}

void swap(int* a, int* b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int main () {
  int n, A[N], count = 0;
  int i, j, mini;
  // input
  cin >> n;
  rep(i,n)  cin >> A[i];

  // sort
  rep(i,n) {
    mini = i;
    for (j = i; j < n; j++) {
      if (A[j] < A[mini]) mini = j;
    }
    if (mini != i) {
      count++;
      swap(A[i], A[mini]);
    }
  }
  trace(A,n);
  cout << count << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>

using namespace std;

int main(){
    int n;cin >> n;
    string s;
    cin >> s;
    int dp[n+1][n+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j] = 0;
        }
    }
    int res = 0;
    for(int i=n-1;i>=0;i--){
        for(int j=n-1;j>i;j--){
            if(s[i] == s[j]){
                dp[i][j] = max(dp[i][j],dp[i+1][j+1] + 1);
            }
            res = max(res,min(dp[i][j],j-i));
            //cout << "i=" << i << "j=" << j << "dp[" << i << "][" << j << "]=" << dp[i][j] << endl;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int a,b;
  int c;
  cin >> a >> b ;
  
  c= (a+b) % 2 ;
  if (c > 0 ) {
      cout << (a+b)/2+1 << endl;
  } 
  else {
      cout << (a+b)/2 << endl;
  }
}


Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    most = A[0]
    res = 0

    for i in range(1,N):
        if most < A[i]:
            most = A[i]
        else:
            res += most - A[i]

    print(res)



main()


Measured memory_bytes: 31296
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

vector<int> graph[200001], subg[200001];
long long val[200001] = { 0, };
long long add[200001] = { 0, };

void dfs(int cur, int parent, long long addval)
{
	int next;
	int i;
	vector<int> ret, rvalue;

	addval += add[cur];

	val[cur] += addval;

	for (i = 0; i < graph[cur].size(); i++)
	{
		next = graph[cur][i];

		if (next == parent)
		{
			continue;
		}

		dfs(next, cur, addval);
	}
}

int main()
{
	int n, m;
	int i, j;
	int u, v;
	long long d;

	scanf("%d %d", &n, &m);

	for (i = 0; i < n - 1; i++)
	{
		scanf("%d %d", &u, &v);

		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	for (i = 0; i < m; i++)
	{
		scanf("%d %lld", &u, &d);

		add[u] += d;
	}

	dfs(1, 0, 0);

	for (i = 1; i <= n; i++)
	{
		printf("%lld ", val[i]);
	}

	return 0;
}


Measured memory_bytes: 33408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
const int INF=10000000;

int main() {
    int dig;
    int n;
    cin >> n;
    int sum=0;
    int num=n;
    while(num){
      dig = num % 10;
      sum = sum + dig;
      num = num / 10;
    }
    if(n%sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;

}



Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = sum(b)

for i in range(N-1):
    if a[i] + 1 == a[i+1]:
        ans += c[a[i]-1]

print(ans)

Measured memory_bytes: 3064
// AOJ ALDS1_9_C Priority Queue
// 2019.8.9 bal4u

#include <stdio.h>
#include <stdlib.h>

// バッファを経ずstdinから数値を得る
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

#define PQSZ 2000002  // キューの大きさ
typedef struct { int t, n, b; } PQ;
PQ *pq; int pqsz, pqmax;
int pqcmp(const void *a, const void *b);

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void pqinit(int sz) {
  pqmax = sz;
  pqsz = 0;
  pq = malloc(sizeof(PQ)*sz);
}

void _heapify(int i) {
  int l, r, min;
  l = LEFT(i), r = RIGHT(i);
  if (l < pqsz && pqcmp(pq+l,pq+i)<0)
    min = l;
  else min = i;
  if (r < pqsz && pqcmp(pq+r,pq+min)<0)
    min = r;
  if (min != i) {
    PQ qt = pq[i];
    pq[i] = pq[min];
    pq[min] = qt;
    _heapify(min);
  }
}

int deq(PQ *p) {
  if (pqsz <= 0) return 0;
  *p = pq[0];
  pq[0]= pq[--pqsz];
  _heapify(0);
  return 1;
}

void enq(PQ *p) {
  int i, min;
  i = pqsz++;
  pq[i] = *p;
  while (i > 0 &&
    pqcmp(pq+(min=PARENT(i)), pq+i)>0) {
    PQ qt = pq[i];
    pq[i] = pq[min];
    pq[min] = qt;
    i = min;
  }
}

int pqcmp(const void *a, const void *b) {
	return ((PQ *)b)->t - ((PQ *)a)->t;
}

int main()
{
	int k;
    PQ p;
    
	pqinit(2000000);
	while (1) {
		if (gc() == 'e') {
			if (gc() == 'n') break;  // end
			k = 6; while (k--) gc(); // extract
			deq(&p);
			out(p.t);
		} else {
			k = 6; while (k--) gc(); // insert
			p.t = in();
			enq(&p);
		}
	}
	return 0;
}



Measured memory_bytes: 13248