akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            int M = Integer.parseInt(in.next());
            Integer[][] AB = new Integer[N][2];
            for (int i = 0; i < N; i++) {
                AB[i][0] = Integer.parseInt(in.next());
                AB[i][1] = Integer.parseInt(in.next());
            }
            Arrays.sort(AB, (x, y) -> Integer.compare(x[0], y[0]));
            long ans = 0;
            for (int i = 0; i < N; i++) {
                long k = AB[i][1];
                M -= k;
                if (M > 0) {
                    ans += AB[i][0] * k;
                } else {
                    ans += AB[i][0] * (M + k);
                    break;
                }
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 64236
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char op;
    cin>>a>>op>>b;
    if(op=='+')
    {
        cout<<a+b;
    }
    if(op=='-')
    {
        cout<<a-b;
    }
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<time.h>
using namespace std;
#define N 314159
int a[N],t[N];
long long ans=0;
void marge_count(int s,int g){
  if(s+1>=g)return;
  if(s+2==g){
    if(a[s]>a[s+1]){
      swap(a[s],a[s+1]);ans++;
    }
    return;
  }
  int m= (s+g)/2;
  marge_count(s,m);
  marge_count(m,g);
  int p=s,q=m,r=s;
  while(p<m&&q<g){
    if(a[p]<=a[q]){
      t[r++]=a[p++];
    }else{
      t[r++]=a[q++];
      ans+=m-p;
    }
  }
  if(p<m){
    while(p<m)t[r++]=a[p++];
  }else{
    while(q<g){
      t[r++]=a[q++];
    }
  }
  if(r!=g)cout<<"error"<<endl;
  for(int i=s;i<g;i++){
    a[i]=t[i];
  }
}
int n;
int main(){
    while(cin>>n&&n){ans=0;
  for(int i=0;i<n;i++)cin>>a[i];
  marge_count(0,n);
//  for(int i=0;i<n;i++)cout<<" "<<a[i];
 // cout<<endl;
  cout<<ans<<endl;}
  return 0;
}

Measured memory_bytes: 1160
N, M = map(int, input().split())
V = [[] for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    V[A].append(B)
    V[B].append(A)

L = [-1]*(N+1)
L[1] = 0
al = False

from collections import deque
Open = deque()
Open.append(1)
Close = set()
while len(Open)>0:
    v = Open.pop()
    Close.add(v)
    for v2 in V[v]:
        if v2 not in Close:
            Open.append(v2)
        if L[v2] == -1:
            L[v2] = 1-L[v]
        elif L[v] + L[v2] != 1:
            al = True
            break
    if al:
        break

if al:
    print(N*(N-1)//2-M)
else:
    c = L.count(1)
    print(c*(N-c)-M)


Measured memory_bytes: 65440
N = int(input())
h = list(map(int, input().split()))
flower=[0]*N
count=0
on=0
for j in range(max(h)):
    for i in range(N):
        if i==0:
            on=0
        if flower[i]<h[i]:
            flower[i]+=1
            on=1
            if i==N-1:
                count+=1
        elif on==1 and flower[i]==h[i]:
            count+=1
            on=0
        #print(flower, i, on)
        #print(count)
print(count)

Measured memory_bytes: 3064
function Main(input) {
	input = input.split("\n");
  	var inputValue = input[0];
  	var mostDivideCount = 0;
  	var mostValue = 0
  for (var i=0; i<=inputValue; i++)
  {
    var divideCount = 0;
    var testValue=i;
    while(testValue>=2 && testValue%2==0){
      divideCount+=1;
      testValue/=2;
    }
    if(divideCount>=mostDivideCount){
      mostDivideCount = divideCount;
      mostValue = i;
    }
  }
	console.log('%d',mostValue);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
	
	static boolean t = true;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int w = sc.nextInt(), h = sc.nextInt();
			
			if(w == 0 && h == 0){
				return;
			}
			
			char[][] map = new char[h][w];
			int s_x = 0,s_y = 0;
			
			for(int i = 0; i < h; i++){
				char[] tmp = sc.next().toCharArray();
				
				for(int j = 0; j < w; j++){
					if(tmp[j] == '@'){
						tmp[j] = '.';
						s_x = j;
						s_y = i;
					}
					map[i][j] = tmp[j];
				}
			}
			
			LinkedList<Integer> list = new LinkedList<Integer>();
			list.add((s_x << 16) + s_y);
			int count = 0;
			
			while(!list.isEmpty()){
				int t = list.poll();
				int x = t >> 16;
				int y = t & 0x00ff;
				
				if(map[y][x] == '.'){
					count++;
					map[y][x] = 'x';
				}else{
					continue;
				}
				
				if(x > 0){
					list.push(((x - 1) << 16) + y);
				}
				
				if(x < (w-1)){
					list.push(((x + 1) << 16) + y);
				}
				
				if(y > 0){
					list.push((x << 16) + (y - 1));
				}
				
				if(y < (h-1)){
					list.push((x << 16) + (y + 1));
				}
			}
			
			System.out.println(count);
		}
		
	}
	
	
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD = (int)1e9 + 7;
const int MaxN = (int)1e5 + 10;
const long long INF = (int)1e18;

int main() {
//	freopen("input.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	multiset <int> s;
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		s.insert(x);
	}
	int ans = 0;
	while (!s.empty()) {
		int x = *s.rbegin();
		s.erase(--s.end());
		for (int bit = 30; bit >= 0; --bit) {
			if (s.count((1 << bit) - x)) {
				s.erase(s.find((1 << bit) - x));
				++ans;
				break;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ab = abs(a - b);
    int bc = abs(b - c);
    int ac = abs(a - c);
    string ans = "No";
    if (ac <= d || (ab <= d && bc <= d)) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

#define debug(x) cout << #x << "==" << x << endl;

using namespace std;

//??\???
#define MAX_LEN 1000
int N;
int dp[MAX_LEN + 1][MAX_LEN + 1];

void print_dp_table(int n, int m) {
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cout <<setw(2) << dp[i][j];
    }
    cout << "\n";
  }
  cout << "\n";
}

int main() {
  ios::sync_with_stdio(false);

  cin >> N;

  string s1, s2;

  while( cin >> s1 >> s2 ) {

    std::vector<char> a;
    std::vector<char> b;
    for(char& c : s1) {
      a.push_back(c);
    }
    for(char& c : s2) {
      b.push_back(c);
    }


    // dp[i][j] := a???i???????????§???b???j???????????§????????¨??????????????±?????¨??????
    // dp ????????????????????????
    fill(dp[0], dp[MAX_LEN + 1], 0);

    for(int i = 1; i <= (int)a.size(); i++ ) {
      for(int j = 1; j <= (int)b.size(); j++) {
        if( a[i-1] == b[j-1] ) {
          dp[i][j] = dp[i-1][j-1] + 1;
        } else {
          dp[i][j] = max( dp[i-1][j], dp[i][j-1] );
        }
      }
    }

    // for( int i = 0; i < (int)a.size(); i++) {
    //   for( int j = 0; j < (int)b.size(); j++) {
    //     if( a[i] == b[j] ) {
    //       dp[i + 1][j + 1] = dp[i][j] + 1;
    //     } else {
    //       dp[i + 1][j + 1] = max( dp[i + 1][j], dp[i][j + 1]);
    //     }
    //   }
    // }

    // print_dp_table(a.size(), b.size());
    cout << dp[a.size()][b.size()] << endl;

  }

  return 0;
}

Measured memory_bytes: 7140
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

const int C = 26;
string s;
int cnt[200001];	//cnt[i] = prefixをi文字切りさった後で, [a-z]をいくつとれるか？

int getOkLength() {
	int i, j;
	bool used[26] = {false};
	int length = 0;
	
	for (i = s.length() - 1; i >= 0; i--) {
		used[s[i] - 'a'] = true;
		for (j = 0; j < C; j++) if (!used[j]) break;
		if (j == C) {
			length++;
			for (j = 0; j < C; j++) used[j] = false;
		}
		cnt[i] = length;
	}
	return length;
}

signed main() {
	int i, j;
	cin >> s;
	
	int length = getOkLength();		//答えの長さ - 1
	bool used[26] = {false};
	
	for (i = 0; i < s.length(); ) {
		if (cnt[i + 1] >= length) {
			used[s[i] - 'a'] = true;
			i++;
		}
		else {
			for (j = 0; j < C; j++) if (!used[j]) break;
			char ans = j + 'a';
			cout << ans;
			for (j = 0; j < C; j++) used[j] = false;
			length--;
			while (i < s.length() && s[i] != ans) i++;
			i++;
		}
	}
	
	for (j = 0; j < C; j++) if (!used[j]) break;
	cout << (char)(j + 'a') << endl;
	return 0;
}

Measured memory_bytes: 2180
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;

    bool hav[n+1];
    memset(hav,false,sizeof hav);
    for(int i=0;i<k;i++){
        int sz;
        cin>>sz;
        for(int j=0;j<sz;j++){
            int a;
            cin>>a;
            hav[a]=true;
        }
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
        if(hav[i]==false)cnt++;
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;
  if(a % 2 == 1 && b % 2 == 1)
  {
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	ll p=0; ll k=0;
	for(int i=0;i<n;i++)
	{
	    int q; cin>>q; p+=q;
	    k+=(q*q);
	}
	ll w=p/n; ll f=w+1;
    ll ans = k + w*w*n - 2*w*p;
    ans = min(ans,k + f*f*n - 2*f*p );
    ans=max(ans,(ll)0);
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
    return 0;
}

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

int main(){
  int cnt = 0;
  vector<int> nums(3);
  for(int i = 0; i < 3; i++){
    int a;
    cin >> a;
    nums.at(i) = a;
  }
  sort(nums.begin(), nums.end());
  int even = 0;
  int odd = 0;
  for(int i = 0; i < 3; i++){
    if(nums.at(i) % 2 == 0){
      even++;
    }
    else{
      odd++;
    }
  }
  if(even > odd){
    for(int i = 0; i < 3; i++){
      if(nums.at(i) % 2 != 0){
        nums.at(i)--;
        cnt++;
      }
    }
  }
  else{
    for(int i = 0; i < 3; i++){
      if(nums.at(i) % 2 == 0){
        nums.at(i)--;
        cnt++;
      }
    }
  }
  int maximum = nums.at(2);
  for(int i = 0; i < 2; i++){
    while(nums.at(i) != maximum){
      nums.at(i) += 2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	long long n, k, a, ans;

	scanf("%lld%lld", &n, &k);
	if (k == 0) {
		printf("%lld\n", n * n);
		return 0;
	}
	ans = 0;
	for (a = k + 1; a <= n; a++)
		ans += n / a * (a - k) + (n % a + 1 >= k ? n % a + 1 - k : 0);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
from numpy import cumsum
N = int(input())
lis = [0]*40
tmp = [0,2]+[2**(i*2) for i in range(1,23)]
rui = cumsum(tmp)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))


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

int main() {
    int H, W; cin >> H >> W;
    string a[H];
    for (int i = 0; i < H; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            if (i == 0 || i == H + 1) {
                cout << '#';
            } else if (j == 0 || j == W + 1) {
                cout << '#';
            } else {
                cout << a[i - 1][j - 1];
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3644
N = int(input())
A = list(map(int,input().split()))
b = 1
c = 0
if A.count(0) != 0:
  print(0)
else:
  for i in range(N):
    b = b * A[i]
    if b > 10 ** 18:
      c = 1
      break
  if c == 0:
    print(b)
  else:
    print(-1)

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

#define ll long long
#define mem(Arr,x) memset(Arr,x,sizeof(Arr))

const int maxN=320;
const int Mod=1e9+7;
const int inf=2147483647;

int n,D[maxN];
int F[maxN][maxN][2];
int Fac[maxN],Ifc[maxN];

int QPow(int x,int cnt);

int main(){
	Fac[0]=Ifc[0]=1;for (int i=1;i<maxN;i++) Fac[i]=1ll*Fac[i-1]*i%Mod;
	Ifc[maxN-1]=QPow(Fac[maxN-1],Mod-2);for (int i=maxN-2;i>=1;i--) Ifc[i]=1ll*Ifc[i+1]*(i+1)%Mod;
	bool fullring=1;
	scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d",&D[i]),fullring&=(D[i]==2);
	if (fullring){
		printf("%lld\n",1ll*Fac[n-1]*Ifc[2]%Mod);return 0;
	}
	F[0][0][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=i;j++)
			for (int k=0;k<=1;k++){
				F[i][j][k]=F[i-1][j][k];
				if ((D[i]>=2)&&(j>0)) F[i][j][k]=(1ll*F[i-1][j-1][k]*(D[i]-1)%Mod+F[i][j][k])%Mod;
				if ((D[i]>=3)&&(j>0)&&(k==1)) F[i][j][k]=(1ll*F[i-1][j-1][0]*(D[i]-1)%Mod*(D[i]-2)%Mod+F[i][j][k])%Mod;
			}
	int Ans=0;
	//for (int i=1;i<=n;i++) cout<<F[n][i][1]<<" ";cout<<endl;
	for (int i=3;i<=n;i++) Ans=(Ans+1ll*F[n][i][1]*Fac[i-1]%Mod*Ifc[2]%Mod*Fac[n-i-1]%Mod)%Mod;
	for (int i=1;i<=n;i++) Ans=1ll*Ans*Ifc[D[i]-1]%Mod;
	printf("%d\n",Ans);return 0;
}

int QPow(int x,int cnt){
	int ret=1;
	while (cnt){
		if (cnt&1) ret=1ll*ret*x%Mod;
		x=1ll*x*x%Mod;cnt>>=1;
	}
	return ret;
}


Measured memory_bytes: 1024
def compress_array_to_hash(array)
  hash = {}
  array.map { |e|
    if hash[e].nil?
      hash[e] = 1
    else
      hash[e] += 1
    end
  }
  hash
end

n = gets
as = compress_array_to_hash(gets.split.map(&:to_i)).sort_by { |key, value| key }.reverse
use = []
until use.length == 2 || as.empty?
  temp = as.shift
  if temp[1] >= 4
    use += [temp[0], temp[0]]
  elsif temp[1] >= 2
    use << temp[0]
  end
end
use += [0, 0]
puts use[0] * use[1]


Measured memory_bytes: 21480
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
void solve();int main() {FastIO;solve();return 0;}
// ====================================================================================
void solve()
{
	int a,b,h;
    cin>>a>>b>>h;
    cout<<((a+b)*h)/2;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define maxn 610
#define ll long long
#define mod 1000000007
using namespace std;
int f[maxn][maxn], pr[maxn], tot[maxn], pre[maxn], g[maxn][maxn];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	n *= 2;
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		pr[x] = y; pr[y] = x;
	}
	for (int i = 1; i <= n; i++)
		if (pr[i] == 0) pre[i] = pre[i - 1] + 1;
		else pre[i] = pre[i - 1];
	for (int i = 1; i <= n - 1; i++)
		if ((pr[i] || pr[i + 1]) && pr[i] != i + 1) f[i][i + 1] = 0;
		else f[i][i + 1] = g[i][i + 1] = 1;
	tot[0] = 1;
	for (int i = 1; i <= n; i++)
		if (i % 2) tot[i] = 0;
		else tot[i] = ((ll)i - 1) * tot[i - 2] % mod;
	for (int len = 4; len <= n; len += 2)
		for (int i = 1; i <= n - len + 1; i++)
		{
			int j = i + len - 1, flag = 1;
			for (int k = i; k <= j; k++)
				if (pr[k] && (pr[k] < i || pr[k] > j)) flag = 0;
			if (flag == 0) continue;
			f[i][j] = g[i][j] = tot[pre[j] - pre[i - 1]];
			for (int k = i + 1; k < j; k += 2)
				f[i][j] = (f[i][j] - (ll)f[i][k] * g[k + 1][j] % mod + mod) % mod;
		}
	int res = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j += 2)
		{
			if (f[i][j] == 0) continue;
			int tmp = pre[n] - (pre[j] - pre[i - 1]);
			res = (res + (ll)f[i][j] * tot[tmp] % mod) % mod;
		}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int X, Y, Z; cin >> X >> Y >> Z;
    vector<int> A(X+Y+Z), B(X+Y+Z), C(X+Y+Z);
    for (int i = 0; i < X+Y+Z; i++) cin >> A[i] >> B[i] >> C[i];
    vector<int> I(X+Y+Z); iota(begin(I), end(I), 0);
    sort(begin(I), end(I), [&](int i, int j) { return (C[i]-A[i])<(C[j]-A[j]); });
    vector<Int> left(X+Y+Z, -1e18), right(X+Y+Z, -1e18);
    left[X] = right[Z] = 0;
    priority_queue<pair<int, int>> Q;
    for (int i = 0; i < X; i++) {
        int idx = I[i];
        left[X] += A[idx];
        Q.emplace(B[idx]-A[idx], idx);
    }
    for (int i = X; i < X+Y; i++) {
        int idx = I[i];
        Q.emplace(B[idx]-A[idx], idx);
        auto p = Q.top();
        Q.pop();
        left[i+1] = left[i] + A[idx] - A[p.second] + B[p.second];
    }
    Q = decltype(Q)();
    for (int i = 0; i < Z; i++) {
        int idx = I[X+Y+Z-1-i];
        right[Z] += C[idx];
        Q.emplace(B[idx]-C[idx], idx);
    }
    for (int i = Z; i < Z+Y; i++) {
        int idx = I[X+Y+Z-1-i];
        Q.emplace(B[idx]-C[idx], idx);
        auto p = Q.top();
        Q.pop();
        right[i+1] = right[i] + C[idx] - C[p.second] + B[p.second];
    }
    Int ans = 0;
    for (int i = 0; i <= Y; i++) {
        ans = max(ans, left[X + i] + right[Y + Z - i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int YY[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx[4] = { -1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int a[100005];
int n, k;
vector<int> dp(100005, -1);

int frogB(int ind) {
	if (ind >= (n - 1)) return 0;
	if (dp[ind] != -1) return dp[ind];
	int c = inf;
	for (int i = 1; i <= k; i++) {
		if (ind + i < n)
			c = min(c, abs(a[ind] - a[ind + i]) + frogB(ind + i));
	}

	return dp[ind] = c;
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

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

	cin >> n >> k;

	for0(i, n) cin >> a[i];

	cout << frogB(0);

	return 0;
}

Measured memory_bytes: 12584
K = int(input())
A,B = map(int,input().split())
x = B - A
ans = "NG"
s = list(range(A,A+x+1))

for i in range(x+1):
  y = s[i]
  if not y%K == 0:
    ans = "NG"
  else:
    ans = "OK"
    break
print(ans)

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

int count_bits(uint32_t bits) {
    int count = 0;
    uint32_t b = bits;
    while (b != 0) {
        int a = (b & 1);
        if (a == 1) {
            count++;
        }

        b >>= 1;
    }

    return count;
}

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

    int A[N+1];
    int x[N+1][N+1];
    int y[N+1][N+1];
    for (int i = 1; i <= N; ++i) {
        std::cin >> A[i];
        for (int j = 1; j <= A[i]; ++j) {
            std::cin >> x[i][j] >> y[i][j];
        }
    }

    int h[N + 1];
    int max = 0;
    for (uint32_t bits = 0; bits < (1u << N); ++bits) {
        for (int i = 1; i <= N; ++i) {
            h[i] = ((bits >> (i - 1)) & 1u);
        }

        bool flag = true;
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= A[i]; ++j) {
                if (h[i] == 1 && h[x[i][j]] != y[i][j]) {
                    flag = false;
                    break;
                }
            }

            if (flag == false) {
                break;
            }
        }

        if (flag) {
            max = std::max(max, count_bits(bits));
        }
    }

    std::cout << max << std::endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())

student =[] 
for _ in range(n):
    a,b=map(int,input().split())
    student.append([a,b])

check=[]

for _ in range(m):
    a,b=map(int,input().split())
    check.append([a,b])

for s in student:
    ans=10**9
    i=0
    for j in range(m):
        c=check[j]
        dist = abs(c[0]-s[0]) + abs(c[1]-s[1])
        if dist<ans:
            ans=dist
            i=j+1

    print(i)

Measured memory_bytes: 9224
H = int(input())
A = [0] + list(map(int, input().split()))

for i in range(1, H+1):
    key = A[i]
    parent = A[i//2] if i//2 >= 1 and i//2 <= H else None
    left = A[2*i] if 2*i >= 1 and 2*i <= H else None
    right = A[2*i+1] if 2*i+1>=1 and 2*i+1 <= H else None
    ans = f"node {i}: key = {key}, "
    if parent is not None:
        ans += f"parent key = {parent}, "
    if left is not None:
        ans += f"left key = {left}, "
    if right is not None:
        ans += f"right key = {right}, "
    print(ans)


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

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

  vector<int> C(26);
  for (int i = 0; i < 26; i++) cin >> C.at(i);

  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) cin >> S.at(i).at(j);
  }

  // i 日目に開くコンテストのタイプを決める
  vector<int> T(D);
  for (int d = 0; d < D; d++) {
    int type = 0;
    int s_max = 0;
    for (int i = 0; i < 26; i++) {
      if (S.at(d).at(i) > s_max) {
        type = i;
        s_max = S.at(d).at(i);
      }
    }
    T.at(d) = type;
  }

  // i 日目に開くコンテストのタイプを出力
  for (int t : T) cout << t + 1 << endl;
}


Measured memory_bytes: 3676
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int is753(int a) {
	int k, flg[4] = { 0, 0, 0, 1};
	while (a > 0) {
		k = a % 10;
		a /= 10;
		if (k == 3) flg[0] = 1;
		else if (k == 5) flg[1] = 1;
		else if (k == 7) flg[2] = 1;
		else {
			flg[3] = 0;
			break;
		}
	}
	return flg[0] && flg[1] && flg[2] && flg[3];
}

int log_10(int a) {
	int cnt = 0;
	while (a > 0) {
		a /= 10;
		cnt++;
	}
	return cnt;
}

int main(void) {
	int n, log_n;
	scanf("%d", &n);
	log_n = log_10(n);

	int dfs(int cur, int a) {
		int ret0, ret3, ret5, ret7;
		ret0 = (is753(a) && a <= n) ? 1 : 0;
		if (cur == log_n) {
			return ret0;
		}
		ret3 = dfs(cur + 1, 10 * a + 3);
		ret5 = dfs(cur + 1, 10 * a + 5);
		ret7 = dfs(cur + 1, 10 * a + 7);
		return ret0 + ret3 + ret5 + ret7;
	}
	
	printf("%d", dfs(0, 0));
	return 0;
}

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

int main(){
    vector<int> A(3); for(int i = 0; i < 3; ++i) cin >> A[i];

    sort(A.begin(), A.end());
    int cnt = 0;
    cnt += abs(A[1] - A[0]);
    cnt += abs(A[2] - A[1]);

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll s, w;
  cin >> s >> w;
  if (s > w) {
    cout << "safe" << endl;
  } else {
    cout << "unsafe" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    int c=0,mx=0;
    for(int i=0; i<3; i++)
    {
        if(s[i]=='R')
            c++;
        else
        {
            mx=max(c,mx);
            c=0;
        }
    }
    mx=max(c,mx);
    cout<<mx<<endl;
}

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

int main() {
    string N;
    bool flag = false;
    while (cin >> N) {
        if (flag) cout << endl;
        flag = true;
        while (N.size() < 5) N = "0" + N;
        vector<string> s(8);
        s[2] = "=====";

        for (int i = 0; i < N.size(); i++) {
            int n = N[i] - '0';
            if (n > 4) {
                s[1] += '*';
                s[0] += ' ';
            } else {
                s[0] += '*';
                s[1] += ' ';
            }

            int p;
            if (n >= 5) p = n - 5;
            else p = n;
            for (int j = 0; j < p; j++) {
                s[3+j] += "*";
            }

            s[3+p] += ' ';

            for (int j = 4+p; j < 8; j++) {
                s[j] += '*';
            }
        }

        for (auto i : s) cout << i << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n,m,x = 0;
    cin >> n >> m >>x;
    vector<vector<ll>> a(n,vector<ll>(m));
    vector<ll> c(n);
    int tmp = 0;
    for(int i = 0;i < n;i++){
        cin >> c[i];
        for(int j = 0;j < m;j++){
            cin >> tmp;
            a.at(i).at(j) = tmp;
        }
    }
/*
for(int i = 0;i < n;i++){
        cout << c[i] << " ";
        for(int j = 0;j < m;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }*/

    ll r = 1001001001;

    for(int s = 0;s < pow(2,n);s++){
        bool flag = true;
        vector<ll> X(m,0);
        ll sum = 0;
        for(int i = 0;i < n;i++){
            if(s>>i&1){
                sum += c[i];
                for(int j = 0;j < m;j++){
                    X[j] += a.at(i).at(j);
                }
            }
        }
        for(int i = 0; i < m;i++){
            //cout << X[i] << " ";
            if(X[i] < x){
                flag = false;
                break;
            }
        }
        //cout << sum << endl;
        if(flag){
            //cout << sum;
            r = min(r,sum);
        }
        //cout << endl;
    }

    if(r != 1001001001){
        cout << r << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 4112
def tax(p, x):
	return p * (100 + x) // 100

while True:
	x, y, s = map(int, input().split())
	if x == y == s == 0:
		break
	m = 0
	for i in range(1, s):
		for j in range(1, s):
			t = tax(i, x) + tax(j, x)
			if t > s:
				break
			if (t) == s:
				m = max(m, tax(i, y) + tax(j, y))
	print(m)


Measured memory_bytes: 5600
# 26

import sys

sys.setrecursionlimit(10**9)

n, q = map(int, input().split())
ans_l = [0] * n
graph = [[] for x in range(n)]

def dfs(v, p=-1):
    if p >= 0:
        ans_l[v] += ans_l[p]
    for i in range(len(graph[v])):
        _v = graph[v][i]
        if _v != p:
            dfs(_v, v)
        
for i in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    
for j in range(q):
    p, x = map(int, input().split())
    ans_l[p-1] += x
    
dfs(0)

print(*ans_l)

Measured memory_bytes: 282856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
bool isPrime(int n){
    if(n<=1)return false;
    if(n==2)return true;
    if(n%2==0)return false;
    int Nsqrt = sqrt(n);
    for(int q=3;q<=Nsqrt;q+=2){
        if(n%q==0)return false;
    }
    return true;
}

int main(void){
    int ans=0,n,x;
    cin>>n;
    rep(i,n){
        cin>>x;
        if(isPrime(x)){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3072
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

const LLONG GCM(const LLONG a, const LLONG b)
{
    if (b == 0) return a;
    return GCM(b, a % b);
}

const LLONG LCM(const LLONG a, const LLONG b)
{
    return a / GCM(a, b) * b;
}

int main()
{
    int A = Cin(), B = Cin();
    cout << LCM(max(A, B), min(A, B)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pai(k) pair<k,k>
#define mod 1000000007
#define mpai make_pair
#define p1 first
#define p2 second
#define pb push_back
#define umap(x,y) unordered_map<x,y>
static void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);}

int main()
{
fast();

    ll n=0;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++){
	cin>>arr[i];
}
ll dp[n]={0};
dp[n-1] =arr[n-1];
for(int i=n-2;i>=0;i--){
	dp[i]=(dp[i+1]+arr[i])%mod;
}
ll sum=0;
for(int i=0;i<n-1;i++){
	sum = (sum+(arr[i]*(dp[i+1])%mod)%mod)%mod;
}
cout<<sum<<"\n";

return 0;
}


Measured memory_bytes: 6724
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    int n, k, a[100005], one;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << (n - k + k - 2) / (k - 1) + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    return 6 - (A+B)


def main():
    A = read_int()
    B = read_int()
    print(slv(A, B))


if __name__ == '__main__':
    main()


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

using namespace std;

int a[6];
    int cnt[4];

int main(void)
{
    bool falg=false;
    for(int i=0;i<6;i++)cin >> a[i];

    for(int i=0;i<6;i++)
    {
        if(a[i]==1)cnt[0]++;
        else if(a[i]==2)cnt[1]++;
        else if(a[i]==3)cnt[2]++;
        else cnt[3]++;
    }

    for(int i=0;i<4;i++)
    {
        if(cnt[0]==3||cnt[1]==3||cnt[2]==3||cnt[3]==3){cout << "NO" << endl;return 0;}
        
    }

    cout << "YES"  << endl;





    
 


    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N;
    string S;
    cin >> N >> S;

    vector<ll> cnt(26, 0);
    REP(i, N) cnt[S[i]-'a']++;

    ll res = 1;
    REP(i, 26){
        res *= (cnt[i]+1);
        res %= mod;
    }
    cout << (res-1+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int h,w;cin >> h >> w;
    vector<vector<bool>> a(h+2, vector<bool>(w+2, false));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char x;cin >> x;
            if(x=='#') a[i+1][j+1]=true;
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(a[i+1][j+1] && !a[i][j+1] && !a[i+1][j] && !a[i+2][j+1] && !a[i+1][j+2]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3632
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	int n;
	cin >> n;
	long long ans = 1;
	long long back = 1;
	for (int i = 0;i < n;++i) {
		int tmp;
		cin >> tmp;
		ans *= 3;
		if (tmp % 2 == 0) {
			back *= 2;
		}else{
			back *= 1;
		}
	}
	cout << ans - back << endl;
	return 0;
}

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

using namespace std;
using LL = long long;

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

    int N;
    LL D, A;
    cin >> N >> D >> A;

    vector< pair< LL, LL>> pro(N);
    for (int i = 0; i < N; i++) cin >> pro[i].first >> pro[i].second;

    LL add = 0;
    set< pair<LL, LL>> st;
    sort(begin(pro), end(pro));
    LL result = 0;

    for (int i = 0; i < N; i++) {
        LL health = pro[i].second;
        while (!st.empty() && st.begin()->first <= pro[i].first) {
            add -= st.begin()->second;
            st.erase(st.begin());
        }
        LL need = (health + A - 1) / A;
        need -= add;
        if (need > 0) {
            add += need;
            result += need;
            st.emplace(pro[i].first + 2 * D + 1, need);
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    Matrix<int> mat(N, vector<int>(N, INF));
    REP(i,N) mat[i][i] = 0;
    VI A,B,C;
    REP(i,M){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        A.pb(a);
        B.pb(b);
        C.pb(c);

        mat[a][b] = c;
        mat[b][a] = c;
    }
    warshall_floyd(mat, INF);
    int ans = 0;
    REP(i,M){
        if(mat[A[i]][B[i]] != C[i]) ans++;
    }
    cout << ans << endl;

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLI = pair<LL, int>;
using VPLI = vector<PLI>;

template<class T> bool chmax(T &a, const T &b) { 
  if(a < b) {
    a=b; return true;
  }
  return false;
}

bool compLines(const PLI &a, const PLI &b) {
  if(a.first > b.first)
    return true;
  if(a.first == b.first && a.second > b.second)
    return true;
  return false;
}

int main()
{
  int N; cin >> N;
  VPLI lines(N+1);
  LL tmp;
  REP(i, N) {
    cin >> tmp;
    lines[i] = make_pair(tmp, i);
  }
  
  sort(lines.begin(), lines.end(), compLines);
  VVL dp(N+1, VL(N+1, 0)); 
  for(int n=0; n<N; n++) {
    LL a; int p;
    tie(a, p) = lines[n];
    for(int x=0; x<=n; x++) {
      int y = n - x;
      dp[x+1][y] = max(dp[x+1][y], dp[x][y]+a*abs(p-x));
      dp[x][y+1] = max(dp[x][y+1], dp[x][y]+a*abs(N-1-y-p));
    }
  }
  LL ans=0;
  REP(i, N+1) {
    chmax(ans, dp[i][N-i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34672
import sys
n, y = map(int, input().split())
for i in range(n+1):
  for j in range(i, n+1):
      if (i*10000+(j-i)*5000+(n-j)*1000 == y):
        print(i, j-i, n-j)
        sys.exit(0)
print('-1 -1 -1')


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        long n = sc.NextLong();
        var ls = new List<char>();
        int ptr = 0;
        while (n > 0)
        {
            n--;
            char d = (char)('a' + n % 26);
            ls.Add(d);
            n /= 26;
        }
        ls.Reverse();
        Console.WriteLine(new string(ls.ToArray()));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27824
#include <iostream>

int main() {
  unsigned int N;
  unsigned int K;

  std::cin >> N;
  std::cin >> K;

  unsigned int ans = (N-1)/(K-1);
  if ((N-1)%(K-1)!=0) ans++;

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

c = N // 15

a = N * 800 - c * 200

print(a)

Measured memory_bytes: 5148
n=int(input())
N=[i+1 for i in range(n)]
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
from itertools import permutations
C=list(permutations(N))
#print(C)

for i,c in enumerate(C):
    if list(c)==list(P):
        f=i
    if list(c)==Q:
        s=i
print(abs(s-f))


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

#define rep(i,N)  for(int i=0; i<N; i++)
#define ol(a) cout << a << endl
#define PI 3.14159265359
using namespace std;

int main(){
  int h,w,k; cin >> h >> w >> k;
  //ol(w);
  
  vector<string> tisa(h);
  
  rep(i,h){
    cin >> tisa[i];
  }
  
  int ans = 0;
  // 3ビットのビット列をすべて列挙する
  int e = h+w;
  //ol(e);
  
  for (int tmp = 0; tmp < (1 << e); tmp++) {
    bitset<12> s(tmp);
    //cout << s << endl;
    //map<int,int> www;
    
    int q = 0;
    rep(i,h){
      rep(j,w){
        //q = 0;
        if(s[i] == 0 && s[h+j] == 0 && tisa[i][j] == '#'){
          q++;
        }
      }
    }
    //ol(q);
    if(q == k){
      ans++;
    }
    
  }
  
  ol(ans);
  
}



Measured memory_bytes: 3600
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H,W = I()
maze = [list(s()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            if i != 0:
                if maze[i-1][j] == '#':
                    continue
            if j != 0:
                if maze[i][j-1] == '#':
                    continue
            if i != H-1:
                if maze[i+1][j] == '#':
                    continue
            if j != W-1:
                if maze[i][j+1] == '#':
                    continue
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 10048
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;
typedef long long ll;
const int maxN=1e5+5,mod=1e9+7;

ll a[maxN];

int main()
{
    ll k,n,m;
    a[1]=1;
    for(k=2;k<maxN;k++)
        a[k]=(a[k-1]*k)%mod;
    cin>>n>>m;
    if(n==m)cout<<(a[n]*a[n]*2)%mod;
    else if(abs(n-m)==1)cout<<(a[n]*a[m])%mod;
    else cout<<0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()

using ll = long long;
constexpr ll INF = 10000000000;

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

using namespace std;

//fixed << setprecision(10)

/////////////////////////////////////////////////////////////////////////////////////////////////////////

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

	string S, T; cin >> S >> T;

	for (int i = 0; i < a; i++) {
		cout << S[i] << T[i];
	}
	cout << endl;
}



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

int to_int(char c) {
    return c - 48;
}
int main() {
    int M,D;
    cin >> M >> D;
    int count = 0;
    for(int i = 1;i <= M;i++) {
        for(int j = 22;j <= D;j++) {
            string s = to_string(j);
            if(to_int(s.at(0)) * to_int(s.at(1)) == i && to_int(s.at(1)) >= 2 && to_int(s.at(0)) >= 2) {
                count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  rep(i,10){
    if(111*i>=n){
      cout<<111*i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d,x=0,0,0
for i in range(n) :
    d = min(int(a[i]-c),b[i])
    c = min(a[i+1],(b[i]-min(int(a[i]-c),b[i])))
    x += c + d
print(x)

Measured memory_bytes: 19156
#include <iostream>

using namespace std;

long long int x;

int main(){
    
    cin >> x;

    int mod;

    if(x % 11 == 0)
        mod = 0;
    else if(x % 11 <= 6)
        mod = 1;
    else 
        mod = 2;

    cout << x/11*2 + mod << '\n';

}


Measured memory_bytes: 256