akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
V = list(map(int, input().split()))

rich = 0
# bring k jewels
for k in range(1, min(K+1, N+1)):
    for rot in range(k+1):
        jewels = (V[-rot:] + V[:-rot])[:k]
        jewels.sort()
        neg = [i < 0 for i in jewels].count(True)
        # return r jewels
        for ret in range(min(neg+1,K-k+1)):
            rich = max(sum(jewels[ret:]), rich)

print(rich)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MX = 1000;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int s=0;
  rep(i,n) s ^= a[i];
  rep(i,n){
    a[i] ^= s;
    cout << a[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> E(N+2),W(N+2);  
    for(int i = 0;i < N;i++){
        E[i+1] = E[i];
        W[i+1] = W[i];
        if(S[i] == 'E') E[i+1] ++;
        else            W[i+1] ++;
    }
    E[N+1] = E[N];
    int mini = INF;
    for(int i = 0;i < N;i++){
        int l = W[i];
        int r = E[N+1] - E[i+1];
        mini = min(mini, l + r);
    }
    cout << mini << endl;
}

Measured memory_bytes: 3076
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
ll mod;

struct matrix{
  //1-indexed
public:
  ll H,W;
  vector<vector<ll>> num;
  matrix(ll x,ll y){
    H=x;
    W=y;
    num.resize(H+5);
    for(int i=0;i<H+5;i++) num[i].resize(W+5,0);
  }
  matrix(const matrix &M_){
    H=M_.H;
    W=M_.W;
    num.resize(H+5);
    for(int i=0;i<H+5;i++) num[i].resize(W+5,0);
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++) num[i][j]=M_.num[i][j];
    }
  }
  void set_val(ll x,ll y,ll v){
    if(x<=0||x>H||y<=0||y>W) return;
    num[x][y]=v;
  }
  matrix operator +(const matrix &M_){
    matrix res=matrix(H,W);
    if(H!=M_.H||W!=M_.W) return res;
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
        res.num[i][j]=num[i][j]+M_.num[i][j];
        res.num[i][j]%=mod;
      }
    }
    return res;
  }
  matrix operator -(const matrix& M_){
    ll x1=H,y1=W,x2=M_.H,y2=M_.W;
    matrix res(x1,y1);
    if(x1!=x2||y1!=y2) return res;
    for(int i=1;i<=x1;i++){
      for(int j=1;j<=y1;j++){
        res.num[i][j]=(num[i][j]-M_.num[i][j])%mod;
        res.num[i][j]+=mod;
        res.num[i][j]%=mod;
      }
    }
    return res;
  }
  matrix operator *(const matrix& M_){
    ll x1=H,y1=W,x2=M_.H,y2=M_.W;
    matrix res(x1,y2);
    if(y1!=x2) return res;
    for(int i=1;i<=x1;i++){
      for(int j=1;j<=y2;j++){
        for(int k=1;k<=y1;k++){
          res.num[i][j]+=num[i][k]*M_.num[k][j];
          res.num[i][j]%=mod;
        }
      }
    }
    return res;
  }
  void operator =(const matrix &M_){
    H=M_.H;
    W=M_.W;
    num.resize(H+5);
    for(int i=0;i<H+5;i++) num[i].resize(W+5,0);
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++) num[i][j]=M_.num[i][j];
    }
  }
  void print(){
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++) cout<<num[i][j]<<" ";
      cout<<endl;
    }
  }
};
matrix pow(matrix m,ll y){
  if(y==0){
    matrix e=m;
    for(int i=1;i<=e.H;i++){
      for(int j=1;j<=e.W;j++){
        if(i==j) e.set_val(i,j,1);
        else e.set_val(i,j,0);
      }
    }
    return e;
  }
  matrix res=pow(m,y/2);
  res=res*res;
  if(y%2==1) res=res*m;
  return res;
}
int main(){
  ll l,a,b;
  cin>>l>>a>>b>>mod;
  matrix ans(1,3);
  ans.set_val(1,1,0);
  ans.set_val(1,2,a);
  ans.set_val(1,3,1);
  ll past=-1;
  for(int d=1;d<=18;d++){
    matrix mt(3,3);
    ll tens=1;
    for(int i=0;i<d;i++) tens*=10;

    mt.set_val(1,1,tens%mod);
    mt.set_val(2,1,1);
    mt.set_val(2,2,1);
    mt.set_val(3,2,b);
    mt.set_val(3,3,1);

    ll lb=-1,rb=l;
    while(rb-lb>1){
      ll mid=(lb+rb)/2;
      if(a+mid*b<tens) lb=mid;
      else rb=mid;
    }
    ans=ans*pow(mt,lb-past);
    past=lb;
  }
  cout<<ans.num[1][1]<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int K = sc.nextInt();
   int[] l = new int[N];
   
   for(int i=0;i<N;i++) l[i] = sc.nextInt();
   Arrays.sort(l);
   
   int ans=0;
   
   for(int i = N-K;i<N;i++) ans+= l[i];
   System.out.println(ans);
 }
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);





int main() {
	

	ll n;
	string s;
	cin >>n>> s;
	ll ans=0;
	ll r = 0, g = 0, b = 0;

	for (ll i = 0;i < n;i++) {
		if (s[i] == 'R')r = r + 1;;
		if (s[i] == 'G')g =g+ 1;
		if (s[i] == 'B')b =b+1;
	}
	ans = r * g*b;
	for (ll i = 0;i < n;i++) {
		for (ll k = i+1;k < n;k++) {
			if ((i + k) % 2 == 0) {
				ll j = (i + k) / 2;
				if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])ans--;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        for i in range(ai - 1, ai + 2):
            d[i] += 1
    m = max(d.items(), key=lambda x: x[1])
    print(m[1])


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 21000
N, M = map(int, input().split())
A = list(map(int, input().split()))
X = []
for _ in range(M):
    b, c = map(int, input().split())
    X.append((b, c))
X = sorted(X, key=lambda x: -x[1])
Y = []
for i in range(M):
    ly = len(Y)
    b, c = X[i]
    if ly + b < N:
        Y += [c] * b
    else:
        Y += [c] * (N-ly)
Z=A+Y 
print(sum(sorted(Z)[-N:]))


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

int N, M;
bool mp[10][10], d[10];

int dfs(int a) {
    bool all_visited = true;
    for (int i = 0; i < N; i++) {
        if (!d[i]) all_visited = false;
    }

    int mem = 0;
    if (all_visited) return 1;
    for (int i = 0; i < N; i++) {
        if (!mp[a][i]) continue;
        if (d[i]) continue;
        d[i] = true;
        mem += dfs(i);
        d[i] = false;
    }
    return mem;
}

int main(void) {
    cin >> N >> M;
    for (int i = 0; i < 10; i++) d[i] = false;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        mp[a-1][b-1] = mp[b-1][a-1] = true;
    }
    
    d[0] = true;
    cout << dfs(0) << endl;
    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    string S;

    cin >> S;

    if(S.length() % 2 != 0){
        cout << "No" << endl;

        return 0;
    }
    for(int i = 0; i < S.length(); i += 2){
        if(S[i] != 'h'){
            cout << "No" << endl;

            return 0;
        }
    }
    for(int i = 1; i < S.length(); i += 2){
        if(S[i] != 'i'){
            cout << "No" << endl;

            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int i,j,n,ans=INF,tmp;
	string s;
	cin >> s;
	n = s.l_ength();
	for(i=2; i<n; ++i){
		tmp = 0;
		for(j=2; j>=0; --j){
			tmp *= 10;
			tmp += s[i-j]-'0';
		}
		ans = min(ans,abs(753-tmp));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N,M,Q=map(int,input().split())
ABCD=[list(map(int,input().split())) for i in range(Q)]


nlst=[[1]]
while len(nlst[0])<N:
    lst=nlst
    nlst=[]
    while lst:
        l=lst.pop()

        for i in range(l[-1],M+1):
            ll=copy.copy(l)
            ll.append(i)
            nlst.append(ll)
#print(nlst)
ans=0
for lst in nlst:
    value=0
    for a,b,c,d in ABCD:
        if lst[b-1]-lst[a-1]==c:
            value+=d
    ans=max(ans,value)
print(ans)


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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int N;
    string s;
    cin >> N >> s;
    
    int R=0,B=0;
    for(int i=0;i<N;i++){
        if(s[i]=='R')R++;
        else B++;
    }
    
    if(R>B) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> score(100010);
int main()
{
	int n,k,q,x;
	cin>>n>>k>>q;
	for(int i=0;i<q;i++)
	{
        cin>>x;
        score[x-1]++;
    }
    for(int i=0;i<n;i++)
    {
    	int t=(score[i]-q)+k;
    	if(t<=0)cout<<"No\n";
    	else cout<<"Yes\n";
	}
	return 0;
}


Measured memory_bytes: 1024
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func main() {
	lines := inputs(2)

	N, _ := strconv.Atoi(lines[0])

	A := make([]int, N+1)

	tmpArray := strings.Split(lines[1], " ")
	for i := 2; i <= N; i++ {
		A[i], _ = strconv.Atoi(tmpArray[i-2])
	}

	cnt := make([]int, N+1)

	for i := 2; i <= N; i++ {
		cnt[A[i]]++
	}

	for i := 1; i <= N; i++ {
		fmt.Println(cnt[i])
	}

}

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

int main() {
    int n, l;
    cin >> n >> l;

    int pie = l*n - n;
    for (int i = 1; i <= n; i++) {
        pie += i;
    }

    if (l < 0) {
        if (n-1 < abs(l)) pie -= l+n-1;
    }
    else {
        pie -= l;
    }

    cout << pie << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
  int x = 0;
  int y = 0;

  while(scanf("%d %d", &x, &y) != EOF){
    if( x == 0){
      if(y == 0){
      break;
      }else{
	 if (x > y){
	   printf("%d %d\n", y, x);
  }
      }
    }
    	 if (x > y){
	   printf("%d %d\n", y, x);
  }else if(x < y){
    printf("%d %d\n", x, y);
	 }else if(x == y ){
    printf("%d %d\n", x, y);
  }
  }
  return 0;
}



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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define M 1000000007

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % M;
		a = (a * a) % M;
		b >>= 1;
	}
	return res;
}

vi a[100001];
int vis[100001] , par[100001];

void bfs(int node)
{
	vis[node] = 1;
	par[node] = -1;
	queue<int> q;

	q.push(node);

	while (!q.empty())
	{
		int curr = q.front();
		q.pop();

		for (auto child : a[curr]) {

			if (vis[child] == 0) {

				vis[child] = 1;
				q.push(child);
				par[child] = curr;
			}
		}
	}
}
void solve()
{
	int n, m;
	cin >> n >> m;

	for (int i = 1 ; i <= m ; i++)
	{
		int u, v;
		cin >> u >> v;

		a[u].pb(v) , a[v].pb(u);
	}

	bfs(1);

	for (int i = 2 ; i <= n ; i++)
	{
		if (vis[i] == 0)
		{
			cout << "No\n";
			return;
		}
	}

	cout << "Yes\n";
	for (int i = 2 ; i <= n ; i++)
	{
		cout << par[i] << "\n";
	}
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin>>t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 10900
// 2018/07/04 Tazoe

#include <iostream>
#include <queue>
#include <map>
using namespace std;

class Point2{
public:
	int tx;
	int ty;
	int kx;
	int ky;
};

int mk(Point2 p)		// キーを生成
{
	return (((p.tx-1)*50+(p.ty-1))*50+(p.kx-1))*50+(p.ky-1);
}

int main()
{
	while(true){
		int W, H;
		cin >> W >> H;

		if(W==0 && H==0)
			break;

		Point2 p;
		cin >> p.tx >> p.ty;
		cin >> p.kx >> p.ky;

		int d[52][52];
		for(int y=0; y<=H+1; y++){
			for(int x=0; x<=W+1; x++){
				d[y][x] = 1;			// 番兵
			}
		}

		for(int y=1; y<=H; y++){
			for(int x=1; x<=W; x++){
				cin >> d[y][x];
			}
		}

		queue<Point2> que;		// キュー
		que.push(p);

		map<int, int> n;			// マップ（時間）
		n[mk(p)] = 0;

		while(true){
			if(que.empty()){			// 出会うことができない場合
				cout << "NA" << endl;
				break;
			}

			p = que.front();
			que.pop();

			if(n[mk(p)]>=100){		// 100以上の時間を要する場合
				cout << "NA" << endl;
				break;
			}

			if(p.tx==p.kx && p.ty==p.ky){		// 2人が出会う
				cout << n[mk(p)] << endl;
				break;
			}

			Point2 q;

			// 東
			q = p;
			if(d[q.ty][q.tx+1]==0){
				q.tx = q.tx+1;
			}
			if(d[q.ky][q.kx-1]==0){
				q.kx = q.kx-1;
			}
			if(n.find(mk(q))==n.end()){
				que.push(q);
				n[mk(q)] = n[mk(p)]+1;
			}

			// 西
			q = p;
			if(d[q.ty][q.tx-1]==0){
				q.tx = q.tx-1;
			}
			if(d[q.ky][q.kx+1]==0){
				q.kx = q.kx+1;
			}
			if(n.find(mk(q))==n.end()){
				que.push(q);
				n[mk(q)] = n[mk(p)]+1;
			}

			// 南
			q = p;
			if(d[q.ty+1][q.tx]==0){
				q.ty = q.ty+1;
			}
			if(d[q.ky-1][q.kx]==0){
				q.ky = q.ky-1;
			}
			if(n.find(mk(q))==n.end()){
				que.push(q);
				n[mk(q)] = n[mk(p)]+1;
			}

			// 北
			q = p;
			if(d[q.ty-1][q.tx]==0){
				q.ty = q.ty-1;
			}
			if(d[q.ky+1][q.kx]==0){
				q.ky = q.ky+1;
			}
			if(n.find(mk(q))==n.end()){
				que.push(q);
				n[mk(q)] = n[mk(p)]+1;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 11372
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    int n,m,a; cin >> n >> m ;
    vector<int> dp(1000000);
    bool flag = false;

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

    rep(i,m){
        cin >> a;
        dp[a] = -1;
    }

    if(dp[1] == -1) dp[1] = 0;

    for(int i = 2; i <= n; i ++){

        if(dp[i] == -1){
            dp[i] = 0;
        }else{
            dp[i] = dp[i-1] + dp[i-2];
        }
        dp[i] %= 1000000007;
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 7108
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    ll N, A, B, a, ans, amod;

    cin >> N >> A >> B;

    if(A==0) {
        cout << 0;
    } else if(B==0) {
        cout << N;
    } else {
        a = N/(A+B);
        amod = N%(A+B);
        if(amod<=A) {
            ans = a*A+amod;
            cout << ans;
        } else {
            ans = a*A+A;
            cout << ans;
        }
    }

}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define p 1000000007
using namespace std;
namespace ywy{
	ll dp[20][65536],jc[65537],jcny[65537];int bits[65536],diren[20];
	inline ll mi(int a,int b){
		ll ans=1,tmp=a;while(b){
			if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1;
		}return(ans);
	}
	inline ll cnm(int n,int m){
		if(n<m)return(0);ll cjr=jc[n];cjr*=jcny[m];cjr%=p;cjr*=jcny[n-m];return(cjr%p);
	}
	inline void pre(int n){
		jc[0]=1;for(register int i=1;i<=n;i++)jc[i]=(jc[i-1]*i)%p;jcny[n]=mi(jc[n],p-2);
		for(register int i=n-1;i>=0;i--)jcny[i]=(jcny[i+1]*(i+1))%p;
	}
	void ywymain(){
		int n,m;cin>>n>>m;for(register int i=1;i<=m;i++)cin>>diren[i];sort(diren+1,diren+1+m);
		reverse(diren+1,diren+1+m);pre(1<<n);dp[0][0]=1;for(register int i=1;i<=m;i++){
			for(register int j=0;j<(1<<n);j++){
				if(!dp[i-1][j])continue;dp[i][j]=(dp[i][j]+dp[i-1][j])%p;for(register int k=0;k<n;k++){
					if(j&(1<<k))continue;
					dp[i][j|(1<<k)]=(dp[i][j|(1<<k)]+((dp[i-1][j]*cnm((1<<n)-diren[i]-j,(1<<k)-1))%p)*jc[1<<k])%p;
				}
			}
		}for(register int i=1;i<(1<<n);i++)bits[i]=bits[i-(i&-i)]+1;ll ans=0;
		for(register int i=0;i<(1<<n);i++){
			if(bits[i]&1){
				ans-=dp[m][i]*jc[(1<<n)-i-1];ans%=p;ans+=p;ans%=p;
			}else ans=(ans+dp[m][i]*jc[(1<<n)-i-1])%p;
		}ans*=(1<<n);ans%=p;cout<<ans<<endl;
	}
}
int main(){
	ywy::ywymain();return(0);
}

Measured memory_bytes: 9728
#include <cstdio>
#include <cmath>

#include <vector>
#include <map>
#include <utility>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, k;
bool c[40000];
LL p[20], e[20], pn;
const LL MOD = 1000000007;
std::vector<LL> divisor;
std::map<LL, LL> mu, gg;
LL ans;

LL g(LL x) {
	LL ex = (x + 1) / 2;
	LL ans = 1, prod = k;
	while(ex) {
		if(ex & 1) { (ans *= prod) %= MOD; }
		(prod *= prod) %= MOD;
		ex /= 2;
	}
	
	return ans;
}

int main() {
	scanf("%lld%lld", &n, &k);
	
	for(LL i = 2; i * i > 1000000000; i++) {
		if(c[i]) { continue; }
		for(LL j = i * 2; j < 40000; j += i) { c[j] = true; }
	}
	LL nn = n;
	incID(i, 2, 40000) {
		if(! c[i] && nn % i == 0) {
			p[pn] = i;
			while(nn % i == 0) {
				e[pn]++;
				nn /= i;
			}
			pn++;
		}
	}
	if(nn != 1) {
		p[pn] = nn;
		e[pn] = 1;
		pn++;
	}
	
	// printf("%lld = ", n); inc(i, pn) { printf(i == 0 ? "%lld^%lld" : " * %lld^%lld", p[i], e[i]); } printf("\n");
	
	LL count[21];
	inc(i, pn) { count[i] = 0; }
	LL prod = 1;
	LL test = 0;
	while(true) {
		test++;
		if(test > 1000000) { return 1; }
		
		divisor.push_back(prod);
		LL m = 1;
		inc(i, pn) { if(count[i] > 1) { m = 0; } else if(count[i] == 1) { m *= -1; } }
		// mu[prod] = m;
		mu.insert(std::make_pair(prod, m));
		
		LL i = 0;
		while(i < pn && count[i] == e[i]) {
			inc(j, e[i]) { prod /= p[i]; }
			count[i++] = 0;
		}
		if(i == pn) { break; }
		prod *= p[i];
		count[i]++;
	}
	
	
	for(auto && e : divisor) {
		// gg[e] = g(e);
		gg.insert(std::make_pair(e, g(e)));
	}
	
	for(auto && x : divisor) {
	for(auto && t : divisor) {
		if(t % x == 0) {
			(ans += mu[t / x] * (t % 2 == 0 ? t / 2 : t) * gg[x]) %= MOD;
		}
	}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
#define P pair<int,int>
using namespace std;
const int mod = 1000000007;
//char c[MAX][MAX];
int step[MAX][MAX];
int H,W,N; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    ll n,m,x; cin >> n >> m >> x;
    ll c[12],a[12][12],ans[12]={};
    rep(i,n){
        cin >> c[i];
        rep(j,m) {
            cin >> a[i][j];
            ans[j] += a[i][j];
        }
    }
    rep(i,m){
        if(ans[i] < x) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll buy=INF; 

    for(ll k=0; k < (1 << n); k++){
        ll nowb=0,nowa[12]={};
        bool flg=1;
        for(ll i = 0; i < n; i++){
            if(k & (1 << i)){
                nowb += c[i];
                rep(j,m){
                    nowa[j] += a[i][j];
                }
            }
        }
        rep(j,m){
            if(nowa[j] < x) flg =0;   
        }
        if(flg){
            if(buy > nowb) buy = nowb;
        }
    }

    cout << buy << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;


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

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

using namespace std;

int main(){
  int n,m,c; cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  int count=0;
  for(int i=0;i<n;i++){
    int sum=0;
    vector<int> a(m);
    for(int j=0;j<m;j++){
      cin >> a[j];
      sum += b[j]*a[j];
    }
    if(sum+c>0){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = input[0];
            int B = input[1];
            int X = input[2];

            if (X >= A && X - A <= B)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int A, B;
  cin >> A >> B;
  if(A + B >= 10){
    cout << "error" << endl;
  }else{
    cout << A + B << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n=1;
	int k;
	cin >> n >> k;

	int res = 0;
	for(int i = 0; i<n; i++) {
		int temp;
		cin >> temp;
		if (temp>=k) {
			res++;
		}
	}

	cout << res;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n+1];
  vector<int> p, m;
  int np = 0, nm = 0;
  for ( int i = 0; i < n; i++ ) {
    cin >> a[i];
    if ( a[i] >= 0 ) { p.push_back(a[i]); np++; } else
    if ( a[i] <  0 ) { m.push_back(a[i]); nm++; }
  }
  vector<int> x, y;
  int ct = 0;
  
  if ( np == 0 && nm >= 2 ) {
    vector<int>::iterator iter = max_element(m.begin(), m.end());
    size_t index = distance(m.begin(), iter);
    int max = m[index];
    m.erase(m.begin() + index);
    iter = min_element(m.begin(), m.end());
    index = distance(m.begin(), iter);
    int min = m[index];
    m.erase(m.begin() + index);
    x.push_back(max);
    y.push_back(min);
    p.push_back(max - min);
    ct++;
    np++;
    nm -= 2;
  } else if ( nm == 0 && np > 2 ) {
    vector<int>::iterator iter = max_element(p.begin(), p.end());
    size_t index = distance(p.begin(), iter);
    int max = p[index];
    p.erase(p.begin() + index);
    iter = min_element(p.begin(), p.end());
    index = distance(p.begin(), iter);
    int min = p[index];
    p.erase(p.begin() + index);
    x.push_back(min);
    y.push_back(max);
    m.push_back(min - max);
    ct++;
    nm++;
    np -= 2;
  } else if ( nm == 0 && np == 2 ) {
    int max = (p[0] > p[1]) ? p[0] : p[1];
    int min = (p[0] < p[1]) ? p[0] : p[1];
    x.push_back(max);
    y.push_back(min);
    p.pop_back();
    p.pop_back();
    p.push_back(max-min);
    np--;
    ct++;
  }

  while ( np+nm > 1 ) {
    if ( np <= nm ) {
      x.push_back(p[np-1]);
      y.push_back(m[nm-1]);
      p[np-1] = x[ct]-y[ct];
      m.pop_back();
      nm--;
      ct++;
    } else {
      x.push_back(m[nm-1]);
      y.push_back(p[np-1]);
      m[nm-1] = x[ct]-y[ct];
      p.pop_back();
      np--;
      ct++;
    }
      
  }

  cout << x[ct-1] - y[ct-1] << endl;
  for ( int i = 0; i < ct; i++ ) {
    cout << x[i] << ' ' << y[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3960
import static java.lang.System.out;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    }
}

Measured memory_bytes: 28316
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))

pN.sort()

diff = 0

if n == 0:
    print(x)
else:
    while(1):
        if x-diff not in pN:
            print(x-diff)
            exit()
        elif x+diff not in pN:
            print(x+diff)
            exit()
        diff+=1

Measured memory_bytes: 9128
def main():
    L = int(input())

    n = 1
    var = 1  # 辺の長さを2冪でとったときに取れる長さの種数
    while n <= 20 and (var << 1) <= L:
        n += 1
        var <<= 1

    g = tuple(set() for _ in range(n))
    for v in range(n - 1):
        g[v].add((v + 1, 0))  # (to,cost)

    t = 1
    for v in range(n - 1):
        g[v].add((v + 1, t))
        t <<= 1

    m = var
    rest = L - var
    for v in range(n - 1, -1, -1):
        if rest >= t:
            g[v].add((n - 1, m))
            rest -= t
            m += (1 << v)
            if rest == 0: break
        t >>= 1

    print(n, sum(len(g[v]) for v in range(n)))
    for v in range(n):
        for u, c in g[v]:
            print(v + 1, u + 1, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9;

int C, N, M, S, T;

class Cl{
  public:
    int n, c, cost;
    Cl(){}
    Cl(int nn, int cc, int co) { n = nn; c = cc; cost = co; }
    bool operator < (const Cl &tmp) const { return cost > tmp.cost; }
};

int solve(vector< vector<P> > &v){
  priority_queue<Cl> open;
  open.push(Cl(S, C, 0));
  vector< vector<int> > closed(N, vector<int>(C + 1, INF));
  closed[S][C] = 0;
  while(!open.empty()){
    Cl cl = open.top(); open.pop();
    if(closed[cl.n][cl.c] < cl.cost) continue;
    REP(i, v[cl.n].size()){
      P nx = v[cl.n][i];
      if(closed[nx.first][cl.c] > cl.cost + nx.second){
        closed[nx.first][cl.c] = cl.cost + nx.second;
        open.push(Cl(nx.first, cl.c, cl.cost + nx.second));
      }
      if(cl.c > 0 && closed[nx.first][cl.c - 1] > cl.cost + nx.second / 2){
        closed[nx.first][cl.c - 1] = cl.cost + nx.second / 2;
        open.push(Cl(nx.first, cl.c - 1, cl.cost + nx.second / 2));
      }
    }
  }
  int res = INF;
  REP(i, C) res = min(res, closed[T][i]);
  return res;
}

int main() {
  while(cin >>C >>N >>M >>S >>T && C && N && M && S && T){
    --T; --S;
    vector< vector<P> > v(N);
    REP(i, M){
      int a, b, f; cin >>a >>b >>f;
      --a; --b;
      v[a].push_back(P(b, f));
      v[b].push_back(P(a, f));
    }
    cout <<solve(v) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
def gcd(a, b):
  if b == 0: return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b//gcd(a,b)

MOD = 1000000000 + 7

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

L = 1
for a in A:
  L = lcm(L, a)
ans = 0
for a in A:
  ans += L // a
ans %= MOD
print(ans)


Measured memory_bytes: 4084
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b=parseMap(split(readline()))
    if a+b<24
        println(a+b)
    else
        println(a+b-24)
    end
end
main()

Measured memory_bytes: 111140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;
	double ans = 0;
#define For(N,i) for(int i = 0; i < N; i++)

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
	int A;
	cin>>A;
	while(1){
		if(IsPrime(A)){
			cout<<A<<endl;
			break;
		}
		else{
			A++;
		}
	}






}

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

int main() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	cout.precision(18);
	cout << 0.5*w*h << ' ';
	cout << (x + x == w && y + y == h ? 1 : 0) << endl;
	return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
c=[]
#print(c)
#
amax=0
temp=-1
for i in range(n):
    a,b=map(int,input().split())
    if a>amax:amax=a;temp=i
    c.append(b)
#k=c[temp]
import math
c.sort(reverse = True)
rt=[num for num in c if num>amax]
if h<=sum(rt):
    sum1=0
    i=0
    while sum1<h:
        sum1+=rt[i]
        i+=1
    print(i)
else:
    nt=math.ceil((h-sum(rt))/amax)
    print(len(rt)+nt)


Measured memory_bytes: 8144
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  sort(A.begin(), A.end());
  int sum[N];
  sum[0] = A[0];
  for(int i=1;i<N;i++){
    sum[i] = sum[i-1] + A[i];
  }

  if(P >= V){
    int W = A[N-P]-M;
    auto itr_a = lower_bound(A.begin(), A.end(), W);
    int ab = itr_a - A.begin();
    cout << N - ab << endl;
    return 0;
  }


  int left = -1, right = N-1;
  int middle = (left+right)/2;
  while(right - left > 1){
    middle = (left+right)/2;
    int W = A[middle]+M;
    int res = 0;

    if(W < A[N-P]){
      left = middle;
      continue;
    }

    for(int i=0;i<=N-P;i++){
      res += min(M , W - A[i]);
    }
    if(res < M*(V-P+1)){
      left = middle;
      continue;
    }
    
    right = middle;
  }

  cout << N-right << endl;

}

Measured memory_bytes: 1792
#input
N, K = map(int, input().split())
S = str(input())

#output
for i in range(K-1):
    print(S[i], sep = "", end = "")
print(S[K-1].lower(), sep = "", end = "")
for i in range(K, N):
    print(S[i], sep = "", end = "")

Measured memory_bytes: 3060
x=[int(k) for k in input().split()]
while x[0]!=-1 or x[1]!=-1 or x[2]!=-1:
    ans=x[0]+x[1]
    if x[0]==-1 or x[1]==-1:
        print('F')
    elif ans>=80:
        print('A')
    elif ans>=65:
        print('B')
    elif ans>=50 or (ans>=30 and x[2]>=50):
        print('C')
    elif ans>=30 and x[2]<50:
        print('D')
    else:
        print('F')
    x=[int(k) for k in input().split()]



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#include <iomanip>
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main(){
  double l;
  cin >> l;

  double n = l/3.0;

  double ans = n * n *n;
  printf("%.12lf\n", n*n*n);
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

dx = (0,1,0,-1); dy = (1,0,-1,0)
h,w = inpl()
s = []
res = [[0] * w for _ in range(h)]
q = deque()
for i in range(h):
    s.append(list(input()))
    for j in range(w):
        if s[i][j] == '#':
            q.append((i,j))
mx = 0
while q:
    ny,nx = q.popleft()
    for di in range(4):
        y = ny + dy[di]
        x = nx + dx[di]
        if 0 <= y < h and 0 <= x < w:
            if s[y][x] == '.':
                res[y][x] = res[ny][nx] + 1
                mx = max(mx, res[y][x])
                s[y][x] = '#'
                q.append((y,x))
print(mx)

Measured memory_bytes: 140632
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

P f(int x) {
	int a = x % 10;
	int b = 0;
	while (x) {
		b = x;
		x /= 10;
	}
	return P(a, b);
}

int main() {
	int n;
	cin >> n;
	map<P, int>freq;
	for (int i = 1;i <= n;++i) {
		P p = f(i);
		freq[p]++;
	}
	ll ans = 0;
	for (int i = 1;i <= n;++i) {
		P p = f(i);
		P q(p.second, p.first);
		ans += freq[q];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;

const long long INF = 1LL << 60;
//---//


int main() {
    int x, y, a, b, c, p[100010] = {}, q[100010] = {}, r;
    vector<int> in;
    INT sum=0;
    cin >> x >> y >> a >> b >> c;

    rep(i, a)cin >> p[i];
    rep(i, b)cin >> q[i];

    sort(p, p + a, greater<int>());
    sort(q, q + b, greater<int>());
    rep(i, x)in.emplace_back(p[i]);
    rep(i, y)in.emplace_back(q[i]);

    rep(i, c) {
        cin >> r;
        in.emplace_back(r);
    }

    sort(in.rbegin(), in.rend());
    rep(i, x + y)sum += in[i];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 510;
ll dp[MAX_N][MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    dp[0][0] = 0;
    for(int i = 0; i < 100; i ++) {
        for(int j = 0; j < 100; j ++) {
            chkmax(dp[i + j + 1][j + 1], dp[i][j] + 1);
            chkmax(dp[i][j + 1], dp[i][j]);
        }
    }
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll x = 2; x * x <= n; x ++) {
        ll curr = 0;
        while(n % x == 0) {
            curr ++;
            n /= x;
        }
        ans += dp[curr][curr];
    }
    if(n > 1) {
        ans ++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4440
_n, m = gets.chomp.split(' ').map(&:to_i)
list = []
h = {}
m.times.each do
  a, b = gets.chomp.split(' ').map(&:to_i)
  if h.key?(a)
    h[a][b] = true
  else
    h[a] = { b => true }
  end
  if h.key?(b)
    h[b][a] = true
  else
    h[b] = { a => true }
  end
  list << [a, b]
end

def bfs(list, done, goal, h)
  new_list = []
  list.each do |current|
    return true if h[current][goal]
    new_list += h[current].keys.select {|k| h[current][k] }.reject { |k| done.include?(k) }
    done << current
  end
  new_list.empty? ? false : bfs(new_list, done, goal, h)
end

count = 0
list.each do |a, b|
  h[a][b] = false
  h[b][a] = false

  count += 1 unless bfs([a], [], b, h)

  h[a][b] = true
  h[b][a] = true
end
puts count


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

int main()
{
  int N, T, S;
  int A[3000], B[3000];

  cin >> N >> T >> S;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  int dp[3001];
  fill_n( dp, 3001, 0);
  for(int i = 0; i < N; i++) {
    for(int j = 1; j <= T; j++) {
      dp[j] = max(dp[j], dp[j - 1]);
    }
    for(int j = T - B[i]; j >= 0; j--) {
      if(dp[j] == -1) continue;
      if(j < S && S < j + B[i]) continue;
      dp[j + B[i]] = max(dp[j + B[i]], dp[j] + A[i]);
    }
  }
  cout << dp[T] << endl;

  return(0);
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

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

    ll ans=0;
    for(ll i=0;i<n-1;i++){
        if(a[i]%2==1 && a[i+1]>0){
            a[i]--;
            a[i+1]--;
            ans++;
        }
    }
    
    for(ll i=0;i<n;i++){
        ans+=(a[i]/2);
    }

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

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int n, x, cnt;
    while (true) {
        cin >> n >> x;
        if (!n && !x) break;
        cnt = 0;
        for (int i = 1; i < n - 1; ++i)
            for (int j = i + 1; j < n; ++j)
                for (int k = j + 1; k <= n; ++k) {
                    if (i + j + k == x)cnt++;
                    if (i + j + k >= x)break;
                }
        cout << cnt << endl;
    }
    return 0;
}



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

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

  double ans = 0;
  for (int i = 0; i < N; i++) {
    double A; cin >> A;
    ans += 1 / A;
  }
  cout << fixed << setprecision(5) << 1 / ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, const tuple<T...> &t){
    os << (n == 0 ? "" : " ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T> ostream &operator << (ostream &os, const tuple<T...> &t){
    _ot<0>(os, t); return os;
}
template<class T, class U> ostream & operator << (ostream &os, const pair<T,U> &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T> ostream &operator << (ostream &os, const vector<T> &v){
    for(size_t i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : ", "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << make_tuple(__VA_ARGS__) \
                   << " (L : " << __LINE__ << ")" << endl)
#else
#define dump(...)
#endif
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using ll = long long;
// #define int ll
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); }
int const mod = 1000000007;
auto const inf = numeric_limits<int>::max()/8;


using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

int chinesePostman(const Graph &g) {
    Weight total = 0;
    int n = g.size();
    vector<int> odds;
    static Weight dist[17][17];
    for(int i = 0; i < n; ++i){
        fill(dist[i], dist[i]+n, inf);
        for(auto &e : g[i]){
            int s = e.src, d = e.dst; Weight w = e.weight;
            total += w;
            dist[s][d] = min(dist[s][d], w);
        }
        if(g[i].size() % 2 == 1) odds.push_back(i);
    }
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    static Weight dp[1<<17];
    int k = odds.size();
    fill(dp, dp+(1<<k), inf);
    dp[0] = 0;
    for(int S = 0; S < 1<<k; ++S)
        for(int i = 0; i < k; ++i)if(~S >> i & 1)
            for(int j = 0; j < i; j++)if(~S >> j & 1)
                dp[S|1<<i|1<<j] = min(dp[S|1<<i|1<<j], dp[S] + dist[odds[i]][odds[j]]);
    return total/2 + dp[(1<<k)-1];
}

int main(){
    int n,m;
    while(cin >> n >> m){
        Graph g(n);
        rep(i,m){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
            g[b].eb(b,a,c);
        }
        cout << chinesePostman(g) << endl;
    }
}

Measured memory_bytes: 3208
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0;
	//string s;
	cin >> n;

	

	cout << n*n*n << endl;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

Ans = 0
for i in range(N):
  t = C
  for j in range(M):
    t += A[i][j] * B[j]
  if t > 0:
    Ans += 1

print(Ans)

Measured memory_bytes: 3064
def gcd(a,b):
    if(b):
        return gcd(b,a%b)
    return a

l = raw_input().split()
if(int(l[0]) > int(l[1])):
    print gcd(int(l[0]),int(l[1]))
else:
    print gcd(int(l[1]),int(l[0]))


Measured memory_bytes: 4648