akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10e13
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;


int main()
{
    ll n;
    cin >> n;
    ll ans = INF;
    for (ll i = 1; i*i <= n; i++)
    {
        if (n % i == 0){
            ans = min(ans, i + (n/i) - 2);
        }
    }
    
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int n;
cin >> n;
cout << 180*(n-2)<<endl;
}


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

int main(void) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << 2 * a - 1;
    }
    else if (a < b) {
        cout << 2 * b - 1;
    }
    if (a == b) {
        cout << a + b;
    }
    return 0;
}

Measured memory_bytes: 256
# nが頂点数、mが辺の本数
n, m = map(int, input().split())

heights = list(map(int, input().split())) 

edges = [list(map(int, input().split())) for _ in range(m)]
edges = [[b[0]-1, b[1]-1] for b in edges]  # 1-idx -> 0-idx

neighbor = [[] for i in range(n)]
# print(neighbor)
for i in range(m):
    a = edges[i][0]
    b = edges[i][1]
    neighbor[a] += [b]
    neighbor[b] += [a]
# print(neighbor)


ans = 0
for vertex in range(n):
    result = True
    for nei in neighbor[vertex]:
        if heights[nei] >= heights[vertex]:
            result = False
        
    if result:
        ans += 1
            
print(ans)


Measured memory_bytes: 46308
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    a = input()
    b = input()
    ans = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            ans += 1
    print(ans)


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy3
main()


Measured memory_bytes: 73660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    string s;
    cin >> s;
    int ans = 700;
    rep(i,3){
        if(s[i]=='o') ans+=100;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);

  rep(i,n) {
    cin >> a.at(i) >> b.at(i);
  }

  ll count = 0;

  //cout << 2 << endl;
  for(int i = n - 1; i >= 0; i--) {
    //cout << i << endl;
    a.at(i) += count;
    ll remainder = b.at(i) - ( a.at(i) % b.at(i) );
    if(remainder == b.at(i) ) remainder = 0;
    count += remainder;
  }

  cout << count << endl;
}


Measured memory_bytes: 1792
n = int(input())
l = {}
ans = 0

for i in range(n):
  a = int(input())
  if a not in l:
    l[a] = 1
  else:
    l[a] += 1

for k in l.values():
  if k%2 == 1:
    ans += 1
print(ans)

Measured memory_bytes: 15076
#include<iostream>
#include<cmath>
using namespace std;
int main (void){
	int a1,a2,a3;
	cin>>a1>>a2>>a3;
	int c1=abs(a2-a1)+abs(a3-a2),c2=abs(a3-a1)+abs(a2-a3),c3=abs(a1-a2)+abs(a1-a3),c4=abs(a3-a2)+abs(a1-a3),c5=abs(a1-a3)+abs(a2-a1),c6=abs(a2-a3)+abs(a2-a1);
	cout<<min(min(min(c1,c2),min(c3,c4)),min(c5,c6))<<endl;
	return 0;
}


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

match_cnt = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for y in range(M):
            if A[y + i][j:j + M] != B[y]:
                flag = False
        if flag:
            match_cnt += 1

if match_cnt > 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9216
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int xyh[n][3];
    for(int i=0;i<n;i++){
        cin >> xyh[i][0] >> xyh[i][1] >> xyh[i][2];
    }
    for(int x=0;x<=100;x++){
        for(int y=0;y<=100;y++){
            long long Ch=0;
            int ok=0;
            for(int i=0;i<n;i++){
                if(xyh[i][2]>=1){
                    Ch=xyh[i][2]+abs(xyh[i][0]-x)+abs(xyh[i][1]-y);
                    Ch=max(Ch,0LL);
                    break;
                }
            }
            for(int i=0;i<n;i++){
                if(xyh[i][2]!=max(0LL,Ch-abs(xyh[i][0]-x)-abs(xyh[i][1]-y))){
                    ok=1;
                }
            }
            if(ok==0){
                cout << x << " " << y << " " << Ch << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NUL -1

struct Node{ int l,p,r; };

int D[MAX], H[MAX], n, l, r, v, i;
struct Node T[MAX];

void start(int);
int check(int);
int divide(int);

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

  for ( i = 0; i < n; i++ ) { T[i].p = NUL; }

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);

    T[v].l = l;
    T[v].r = r;

    if ( l != NUL ) T[l].p = v;
    if ( r != NUL ) T[r].p = v;

  }

  for ( i = 0; i < n; i++ ){

    D[i] = check(i);
    H[i] = 0;

  }

  for ( i = 0; i < n; i++ ){
    if ( T[i].l == NUL && T[i].r == NUL ) { // leaf
      H[i] = 0;
      int p = T[i].p;
      int z = 1;
      while(1){
    if ( p == NUL ) break;
    if ( H[p] < z ) H[p] = z;
    z++;
    p = T[p].p;
      }
    }
  }

  for ( i = 0; i < n; i++ ) start(i);


  return 0;
}

int divide(int u){
  if ( T[u].p == NUL ) return NUL;
  if ( T[T[u].p].l != u && T[T[u].p].l != NUL ) return T[T[u].p].l;
  if ( T[T[u].p].r != u && T[T[u].p].r != NUL ) return T[T[u].p].r;
  return NUL;
}

int check(int u){
  int d = 0;
  while(1){
    u = T[u].p;
    if ( u == NUL ) break;
    d++;
  }
  return d;
}


void start(int u){
  int deg = 0;

  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", divide(u));

  if ( T[u].l != NUL ) deg++;
  if ( T[u].r != NUL ) deg++;

  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].p == NUL ){
    printf("root\n");
  } else if ( T[u].l == NUL && T[u].r == NUL ){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

Measured memory_bytes: 2724
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int tempA = 0;
		int tempB = 0;
		int tempC = 0;
		int count = 0;


		if(a==b && b==c){
			if(a%2!=1){
				System.out.println(-1);
			}else{
				System.out.println(0);
			}
		}else{
			while(a%2!=1 && b%2!=1 && c%2!=1){
				tempA = a/2;
				tempB = b/2;
				tempC = c/2;
				a = tempB + tempC;
				b = tempC + tempA;
				c = tempA + tempB;
				count++;
			}
			System.out.println(count);
		}

	}

}


Measured memory_bytes: 21588
a,b = map(int, input().split())
m = (a+1) //2
n = a // 2
c = (b+1) // 2
d = b // 2
x = (m*c)+(n*d)
if a == 1:
  x = 1
elif b == 1:
  x = 1
print(x)

Measured memory_bytes: 2940
using System;
class Program {
    static void Main() {
        while (true) {
            string[] str =  Console.ReadLine().Split(' ');
            int x = int.Parse(str[0]);
            int y = int.Parse(str[1]);

            int small, big;

            if (x == 0 && y == 0) break;
            else if(x < y) {
                small = x;
                big = y;
            }
            else {
                small = y;
                big = x;
            }

            Console.WriteLine("{0} {1}", small, big);
            
        }
    }
}

Measured memory_bytes: 9408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x, y, a;
        x = input.nextInt();
        y = input.nextInt();
        a = (4 * x - y) / 2;
        System.out.println(y % 2 == 0 && a <= x && a >= 0? "Yes" : "No");
    }
}


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


int main() {
  int n;

  while (cin >> n, n) {
    int m = 1001;  
    int M = -1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int score;
      cin >> score;
      m = min(m, score);
      M = max(M, score);
      sum += score;
    }
    cout << (sum - m - M) / (n - 2) << endl;
  }
  return 0;
}

Measured memory_bytes: 2980
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	ll a, b;
	char op;
	cin >> a >> op >> b;
	if (op == '+')
		cout << a + b;
	else
		cout << a - b;
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    double totalyen = 0.0;
    for(int i = 1; i <= n; i++)
    {
        double x1;
        string type;
        cin >> x1 >> type;
        if(type.compare("BTC") == 0)
        {
            totalyen += x1*380000.0;
            //cout << "h";
        }
        else
        {
            totalyen += x1;
        }
    }
    printf("%0.6f\n", totalyen);
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
S = []
N.times{
  S << gets.chomp.split(" ").map(&:to_i)
}

ans = []
X, Y, H = S.sort_by{|x, y, h| h}[-1]
(0..100).each{|i|
  (0..100).each{|j|
    wk = (i - X).abs + (j - Y).abs + H
    ans = [i, j, wk]
    (0...N).each{|k|
      if S[k][2] == 0 then
        (ans.clear; break) if wk - (i - S[k][0]).abs - (j - S[k][1]).abs > 0
      else
        (ans.clear; break) if wk - (i - S[k][0]).abs - (j - S[k][1]).abs != S[k][2]
      end
    }
    break if not ans.empty?
  }
  break if not ans.empty?
}

puts ans.join(" ")


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

int main() {
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  
  if (a < b) {
    if ((b - a) <= (v - w) * t)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  else {
    if ((a - b) <= (v - w) * t)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> A;
    for(int i = 0; i < M; i++) {
        int buff;
        cin >> buff;
        A.push_back(buff);
    }

    array<int, 2> cost = {0, 0};
    for(int i = 0; i < M; i++) {
        if (A[i] < X)
            cost[0]++;
        else
            cost[1]++;
    }

    cout << *min_element(cost.begin(), cost.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
int main()
{
	boost
	ll x;
	string str;
	cin>>x>>str;
	if(x>=3200)
		cout<<str<<endl;
	else
		cout<<"red"<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N,M,Q = map(int,input().split())
grid = np.zeros((N+1,N+1))
for _ in range(M):
    l,r = map(int,input().split())
    grid[l,r] += 1

grid = grid.cumsum(axis=0).cumsum(axis=1)

for _ in range(Q):
    p,q = map(int,input().split())
    ans = grid[q,q] - grid[p-1,q] - grid[q,p-1] + grid[p-1,p-1]
    print(int(ans))


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define REP(i, a, n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, a[22], b[22], c[22];
	
	cin >> n;
	REP(i, 1, n + 1){
		cin >> a[i];
	}
	REP(i, 1, n + 1){
		cin >> b[i];
	}
	REP(i, 1, n){
		cin >> c[i];
	}
	
	int ans = b[a[1]];
	int p = a[1];
	
	REP(i, 2, n + 1){
		if(a[i] == p + 1){
			ans += c[p];
		}	
		
		ans += b[a[i]];
		
		p = a[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
h,w = gets.chomp.split(' ').map(&:to_i)
strs = h.times.map{ gets.chomp.split('') }
strs.delete(Array.new(w, '.')) #白いマスのみの行を削除

point_idx_ary = []
# 各行で'.'が出現するIndex(列)一覧を取得
strs.each do |str|
  point_idx_ary << str.each_with_index.select{ |ary, idx| ary == '.' }.map(&:last)
end
# 全部の列で'.'が出現している列を取得
del_idx_column = point_idx_ary.flatten.group_by(&:itself).select {|k, v| v.size == strs.size }.keys

# print strs
strs.each_with_index do |str, idx|
  str.each_with_index do |st,i|
    next if del_idx_column.include?(i)
    print st
  end
  puts ''
end

Measured memory_bytes: 3068
#include <iostream>
using namespace std;
 
int main() {
    int input, h, m, s;
    cin >> input;
    h = input /3600;
    m = (input - h*3600)/60;
    s = (input - h*3600)%60;
    cout << h << ":" << m << ":" << s <<endl;
  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};

int main() {
    int n,k;
    cin>>n>>k;
    double res=0;
    for(int i=1;i<n+1;++i){
        double p=1.0;
        int i2=i;
        while(1){
            if(i2>=k)break;
            i2=(i2<<1);
            p*=0.5;
        }
        res+=p;
    }
    printf("%.12f" , res/(double)n);
	return 0;
}


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

using namespace std;

void solveA()
{
    int x;
    cin >> x;
    if (x == 7|| x == 5|| x == 3)
        cout << "YES\n";
    else
        cout << "NO\n";
}

void solveB()
{
    int a, b, c;
    cin >> a >> b >> c;

    int hp = max(a, b);
    hp = max(hp, c);

    int area;

    if (a == hp)
        area = (b * c) / 2;
    if (b == hp)
        area = (a * c) / 2;
    if (c == hp)
        area = (a * b) / 2;

    cout << area;
}

void solveC()
{
    int a, b;
    cin >> a >> b;
    if ((a*b) % 2 == 0)
        cout << "No\n";
    else
        cout << "Yes\n";
}

void solveD()
{
    int n, s=0, cp;

    cin >> n;
    cp = n;

    while (cp){
        s += cp%10;
        cp /= 10;
    }
    if (n % s == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

void solveE()
{
    int n, t;

    cin >> n >> t;

    int rotas[n][2];

    int coast = INT_MAX;

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

        cin >> rotas[i][0] >> rotas[i][1];

        if (rotas[i][1] < t){
            coast = min(coast, rotas[i][0]);
        }
    }
    if (coast == INT_MAX)
        cout << "TLE\n";
    else
        cout << coast << "\n";
}

void solveF()
{
    int k;
    cin >> k;
    int par = 0, impar = 0;
    for (int i = 1; i <= k ; i++){
        if (i % 2 == 0)
            par++;
        else
            impar++;
    }
    cout << par * impar << endl;
}

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);

    solveD();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int w;
    cin>>s>>w;
    for (int i=0;i+w<=s.size();i+=w) {
        cout<<s[i];
    }
    if (s.size()%w!=0) {
        reverse(s.begin(),s.end());
        string tmp=s.substr(0,s.size()%w);
        cout<<tmp[tmp.size()-1];
    }
    cout<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}

const int mod = 1000000007;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint P(int n, int k){
    return fact[n]*ifact[n-k];
  }
}comb(max_n);

int main(){
    ll n;cin >> n;
    mint ans=0;
    repl(i,1,n+1){//iは長さ
        if(n<i*3)break;
        int k=n-i*3;
        ans+=comb(k+i-1,k);
        //cout << ans <<endl;
    }
    cout << ans <<endl;
} 

Measured memory_bytes: 6232
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
using namespace std;

int main(){
    vector <int> col;
    queue <int> row;
    int n, m;
    cin >> n >> m;
    
    char a[110][110];
    for(int i = 0; i < n; i++){
        bool ok = true;
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            if(a[i][j] == '#') ok = false;
        }
        if(ok) row.push(i);
    }
    for(int i = 0; i < m; i++){
        bool ok = true;
        for(int j = 0; j < n; j++){
            if(a[j][i] == '#') ok = false;
        }
        if(ok) col.push_back(i);
    }
    
    
    for(int i = 0; i < n; i++){
        if(!row.empty()){
            if(i == row.front()){
                row.pop();
                continue;
            }
        }
        for(int j = 0; j < m; j++){
            bool ok = true;
            for(auto &k : col){
                if(k == j){
                    ok = false;
                    break;
                }
            }
            if(ok)cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#define ll long long
using namespace std;

int main(){
    string S,T;
    cin>>S>>T;
    ll ans=0;
    for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]) ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

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

	ll MOD = 1e9+7;

	ll N, M;
	cin >> N >> M;

	vector<ll> S(N);
	rep(i, N) cin >> S[i];

	vector<ll> T(M);
	rep(i, M) cin >> T[i];

	vector<vector<ll>> dp(N+1, vector<ll>(M+1, 0));
	vector<vector<ll>> sm(N+1, vector<ll>(M+1, 0));
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			if(S[i] == T[j]){
				dp[i+1][j+1] += sm[i][j]+1;
				dp[i+1][j+1] %= MOD;
			}

			sm[i+1][j+1] = sm[i][j+1] + sm[i+1][j] - sm[i][j] + dp[i+1][j+1] + MOD;
			sm[i+1][j+1] %= MOD;
		}
	}

	cout << (sm[N][M] + 1) % MOD << endl;
}


Measured memory_bytes: 62976
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

}

int main() {

	int a1, a2, a3;
	std::cin >> a1 >> a2 >> a3;

	if (a1 + a2 + a3 >= 22) {
		std::cout << "bust" << std::endl;
	}
	else {
		std::cout << "win" << std::endl;
	}


	return 0;
}

Measured memory_bytes: 256
import numpy as np
# 行数
N,D = input().strip().split()
N= int(N)
D = int(D)
count=0

# 2次元配列
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

for i in np.arange(N):
  if (grid[i][0]*grid[i][0]+grid[i][1]*grid[i][1])<=D*D:
    count+=1
    # print(grid[i][0]**2+grid[i][1]**2)
print(count)
# # S =[1]*N
# stock = 0 #株の数
# money = 1000 #所持金
# for i in range(N):
#   if i>0:
#     if A[i-1]<A[i]: #売る
#       money += stock*A[i]
#       stock = 0
#   if i!=N-1:
#     if A[i]<A[i+1]: #買う
#       stock += int(money/A[i])
#       money -= stock*A[i]
# print(money)


Measured memory_bytes: 65016
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(s == "AAA" || s == "BBB") dunk("No");
    else dunk("Yes");
}

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

int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + 100 * (10 - n) << endl;
}

Measured memory_bytes: 3632
n, a, b = map(int, input(). split())
s = input()
x = "Yes" if a + b < n else "No"
kcnt = 0
Ycnt = 0
for i in range(len(s)):
    if s[i] == "c":
        print("No")
    elif s[i] == "a":
        if Ycnt < a + b:
            Ycnt += 1
            print("Yes")
        else:
            print("No")
    else:
        kcnt += 1
        if kcnt <= b and Ycnt < a + b:
            Ycnt += 1
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 4040
#include<cstdio>
#include<cstring>
int main() {
	int ans=0;
	char s[3],t[3];
	scanf("%s%s",s,t);
	for (int i=0;i<3;++i)
		ans+=(s[i]==t[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<utility>
#include<map>
using namespace std;

int main(){
    int n;
    cin >> n;
    map<pair<int,int>,int>mp;
    for(int i=0;i<n;i++){
        int x,y,w;
        cin >> x >> y >> w;
        mp[make_pair(x,y)]=w;
        mp[make_pair(x-1,y)]=mp[make_pair(x-1,y)];
        mp[make_pair(x,y-1)]=mp[make_pair(x,y-1)];
        mp[make_pair(x-1,y-1)]=mp[make_pair(x-1,y-1)];
    }
    int ans =0;
    for(auto x:mp){
        int a = 0;
        a += x.second;
        int s = x.first.first;
        int t = x.first.second;
        if(mp.find(make_pair(s,t+1))!=mp.end())a += mp[make_pair(s,t+1)];
        
        if(mp.find(make_pair(s+1,t+1))!=mp.end())a += mp[make_pair(s+1,t+1)];
        
        if(mp.find(make_pair(s+1,t))!=mp.end())a += mp[make_pair(s+1,t)];
        ans = max(ans,a);
    }
    cout << ans << " / " << 1 << endl; 
    return 0;
}


Measured memory_bytes: 28072
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

void solve(const vector<int>& v){
  int N = v.size()-1;
  vector<int> ret(v.size(), 0);

  REP(i,N/2+1,N+1){
    ret[i] = v[i];
  }

  for(int i=N/2; i>=1; i--){
    int sum = 0;
    for(int j=i; j<=N; j+=i){
      sum += ret[j];
    }
    //cerr << i << "\t" << sum << "\t" << v[i] << endl;
    if((sum%2 == 0 && v[i] == 1) || (sum%2 == 1 && v[i] == 0)){
      ret[i] = 1;
    }
  }

  vector<int> w;
  REP(i,1,ret.size()) if(ret[i] == 1) w.push_back(i);
  cout << w.size() << endl;
  rep(i,w.size()){
    if(i > 0) cout << " ";
    cout << w[i];
  }
  if(w.size() > 0) cout << endl;
}


int main(){
  int N;
  cin >> N;
  vector<int> v;
  v.push_back(0);
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  solve(v);
  
  return 0;
}


Measured memory_bytes: 3444
<?php
// Your code here!
// $s = trim(fgets(STDIN));
fscanf(STDIN, "%d %d",$a,$b);

for($n=0; $n<10000; $n++){
    $za = intval($n * 8 / 100);
    $zb = intval($n * 10 / 100);
    // var_dump($za);
    if($a == $za && $b == $zb){
        echo $n;
        return 0;
    }
}
echo -1;
return 0;

?>

Measured memory_bytes: 4728
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int D = scanner.nextInt();
    
    double X = Math.ceil((double)C/(double)B);
    double Y = Math.ceil((double)A/(double)D);
    
    if(X <= Y){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

    
    


Measured memory_bytes: 35560
import itertools

n, m, q = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(q)]


ans = 0
for l in itertools.combinations_with_replacement(range(1, m + 1), n):
    tmp_sum = 0
    for a, b, c, d in lst:
        if l[b - 1] - l[a - 1] == c:
            tmp_sum += d
    if ans < tmp_sum:
        ans = tmp_sum

print(ans)


Measured memory_bytes: 9092
N = int(input())
price_list = [int(input()) for _ in range(N)]

purchase_price = price_list[0]
profit = price_list[1] - purchase_price
for price in price_list[1:]:
    profit = max(profit, (price-purchase_price))
    purchase_price = min(price, purchase_price)

print(profit)


Measured memory_bytes: 15100
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long k = sc.nextLong();
      long[] a = new long[n];
      for(int i = 0; i<n; i++)
          a[i] = sc.nextLong();
      Arrays.sort(a);
      long low = 1;
      long high = a[a.length-1];
      long ans = high;
      while(low<=high) {
          long mid = low + (high-low)/2;
          if(isPossible(a, mid, k)) {
              ans = Math.min(ans, mid);
              high = mid-1;
          } else low = mid+1;
      }
      System.out.println(ans);
  }
  static boolean isPossible(long[] a, long mid, long k) {
      long x = 0;
      for(long i: a) {
          if(i%mid==0) x+=i/mid-1;
          else x+=i/mid;
      }
      return x<=k;
  }
}

Measured memory_bytes: 62424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s;cin>>s;
	int a[26]={};
	rep(i,26) a[s[i]-'a']++;
	int l=s.size();
	int ans=inf;
	rep(i,26){
		char c=i+'a';
		int sum=0,now=0;
		for(int j=0;j<l;j++){
			if(c==s[j]){
				sum=max(sum,j-now);
				now=j+1;
			}
		}
		sum=max(sum,l-now);
		ans=min(ans,sum);
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 1000005
using namespace std;
const int P=1e9+7;
char str[5005];
int sum[5005][3];
int main(){
	int n;
	cin>>n;
	scanf("%s",str+1); 
	for(int i=1;i<=n;i++){
		int k=0;
		if(str[i]=='G')k=1;
		if(str[i]=='B')k=2;
		for(int j=0;j<3;j++)sum[i][j]=sum[i-1][j];
		sum[i][k]++;
	}
	long long ans=0;
	for(int j=2;j<n;j++){
		if(str[j]=='R'){// 0
			ans+=(sum[j-1][1])*(sum[n][2]-sum[j][2]);
			ans+=(sum[j-1][2])*(sum[n][1]-sum[j][1]);
		}else if(str[j]=='G'){//1
			ans+=(sum[j-1][0])*(sum[n][2]-sum[j][2]);
			ans+=(sum[j-1][2])*(sum[n][0]-sum[j][0]);
		}else{
			ans+=(sum[j-1][1])*(sum[n][0]-sum[j][0]);
			ans+=(sum[j-1][0])*(sum[n][1]-sum[j][1]);
		}
		for(int k=1;k<j&&j+k<=n;k++){
			if(str[j]!=str[j-k]&&str[j]!=str[j+k]&&str[j-k]!=str[j+k])
				ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3796
#include <stdio.h>

typedef long long ll;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}
int main() {
	ll a, b;
	scanf("%lld %lld", &a, &b);
	printf("%lld", a*b/gcd(a, b));
	return 0;
}

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

using namespace std;

const int N = 2e5 + 5;

int n, freq[N], h;

int main()
{
	cin >> n;
	for(int i = 1 ; i < n; ++i)
	{
		cin >> h;
		++freq[h];
	}
	for(int i = 1; i <= n; ++i)
	{
		cout << freq[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4416
# AGC009
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N-1, -1, -1):
    a = AB[i][0] + ans
    b = AB[i][1]
    if a % b == 0:
        pass
    else:
        ans += (a // b + 1) * b - a
print(ans)

Measured memory_bytes: 27380
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;
int main(){
    string n;
    cin >> n;
    int sum_n = 0;
    for (size_t i = 0; i < n.size(); i++)
    {
        sum_n += n[i] - '0';        
    }
    if(stoi(n) % sum_n == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll K;
string s;
vector<string> sv;

int main() {
    cin >> s >> K;
    REP(i, s.size()) {
        FOR(j, 1, K + 1) { sv.emplace_back(s.substr(i, j)); }
    }
    sort(All(sv));
    sv.erase(unique(All(sv)), sv.end());
    cout << sv[K - 1] << "\n";
}


Measured memory_bytes: 1660
n = str(input())
dic = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10, "k":11, "l":12, "m":13, "n":14, "o":15, "p":16, "q":17, "r":18, "s":19, "t":20, "u":21, "v":22, "w":23, "x":24, "y":25, "z":26}
ans = dic[n] + 1
key = [k for k, v in dic.items() if v == ans][0]
print(key)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

X, Y = map(int, input().split())


def check(x, y):
    k = y - 2 * x
    if k % 2 != 0 or k < 0:
        return 'No'

    k /= 2
    if x - k < 0:
        return 'No'

    return 'Yes'


ans = check(X, Y)
print(ans)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,q;
ll a[100005];
ll sum[100005];
ll sum2[100005];

bool C(int rpos,ll x){
    ll dif=a[rpos]-x;
    int lpos=lower_bound(a,a+n,x-dif)-a;
    int cnt=rpos-lpos+1;
    int cnt2=n-rpos-1;
    if(cnt2>=cnt)return true;
    return false;
}

ll solve(ll x){
    int l=0,r=n;
    while(l+1<r){
        int mid=(l+r)/2;
        if(C(mid,x)){
            l=mid;
        }else{
            r=mid;
        }
    }
    ll ans=sum[n]-sum[l+1];
    int len=n-l-1;
    int n2=n-len*2;
    if(n2>=0){
        ans+=sum2[n2];
    }
    return ans;
}

int main(void){
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        sum[i+1]+=sum[i];
        sum[i+1]+=a[i];
    }
    sum2[1]=a[0];
    sum2[2]=a[1];
    for(int i=2;i<n;i++){
        sum2[i+1]+=sum2[i-1];
        sum2[i+1]+=a[i];
    }
    sort(a,a+n);
    for(int i=0;i<q;i++){
        ll x;
        scanf("%lld",&x);
        printf("%lld\n",solve(x));
    }
    return 0;
}

Measured memory_bytes: 4096
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, H){
        cin >> a[i];
    }
    rep(i, W+2){
        cout << '#';
    }
    cout << endl;
    rep(i, H){
        cout << '#' << a[i] << '#' << endl;
    }
    rep(i, W+2){
        cout << '#';
    }
}

Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<" = "<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define y1 frgrwegreg

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 100017;

int p[200000],q[200000];
int w, h;
LL ans;

int main()
{
	//freopen("C.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(0); cin.tie(0);

	cin >> w >> h;
	FOR (i,0,w) cin >> p[i];
	FOR (j,0,h) cin >> q[j];
	sort(p,p+w);
	sort(q,q+h);
	int num1 = h+1, num2 = w+1;
	int p1 = 0, p2 = 0;
	while (p1 != w || p2 != h)
	{
		//cout << p1<<" "<<p2<<endl;
		int ft = 0;
		if (p1 == w) ft = 2;
		else
		{
			if (p2 == h) ft = 1;
			else
			{
				//cout << "* "<<(p[p1] <= q[p2]);
				if (p[p1] <= q[p2]) ft = 1;
				else ft = 2;
				//cout << "()()"<<ft<<" ";
			}
		}
		//cout << ft<<" "<<p[p1]<<" "<<q[p2]<<" "<<w<<" "<<h<<endl;
		if (ft == 1)
		{
			ans += p[p1++]*1LL*num1;
			num2--;
		}
		else
		{
			ans += q[p2++]*1LL*num2;
			num1--;
		}
	}
	cout << ans;
	return 0;

}


Measured memory_bytes: 1024
H, W = map(int, input().split())
s = list(list(input()) for _ in range(H))

for h in range(H):
    for w in range(W):
        cnt = 0
        if s[h][w] != "#":
            for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)):
                next_h, next_w = h + dh, w + dw
                if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                    continue
                elif s[next_h][next_w] == "#":
                    cnt += 1
            s[h][w] = str(cnt
                          )
for i in s:
    print("".join(i))

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

#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)

int main(){
    int a,b,k,n,m,ans;
    sc3(a,b,k);
    for (int i=100;i>0;i--) {
        if (a%i==0 && b%i==0) k--;
        if (k==0) {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>
#include <set>
#include <map>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 10000000000000000;

const int MOD = 1000000007;

int vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main(){
    map<int, ll> sousuu;
    int Asuu[100100];
    int N, M;
    int A[100100];
    cin >> N >> M;
    Asuu[0] = 0;
    REP(i, N){
        cin >> A[i];
        Asuu[i + 1] = (Asuu[i] + A[i]) % M;
        sousuu[Asuu[i + 1]] = 0;
    }
    int wa = 0;
    sousuu[0] = 1;
    REP(i, N){
        wa = (wa + A[i]) % M;
        sousuu[wa]++;
    }
    ll joukenmitasu = 0;
    REP(i, N){
        joukenmitasu += (sousuu[Asuu[i + 1]] * (sousuu[Asuu[i + 1]] - 1)) / 2;
        sousuu[Asuu[i + 1]] = 0;
    }
    
    printf("%lld\n", joukenmitasu);
    
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int32_t main()
{
	IOS;
	int n, m, x, y;
	cin >> n >> m;
	vector<vi> v(n);
	vi dp(n, 0);
	while (m--)
	{
		cin >> x >> y;
		x--, y--;
		v[x].push_back(y);
	}
	vector<int> vis(n, 0);
	function<void(int)> dfs = [&](int ver) {
		dp[ver] = 0;
		vis[ver] = true;
		trav(it, v[ver])
		{
			if (vis[it] == 0)
				dfs(it);
			dp[ver] = max(dp[ver], dp[it] + 1);
		}
	};
	rep(i, 0, n)
	{
		if (vis[i] == 0)
		{
			dfs(i);
		}
	}
	cout << *max_element(all(dp)) << endl;
	return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int X,Y,Z,k;
int x;
vector<int>a,b,c,d,ans;
signed main(){
	cin>>X>>Y>>Z>>k;
	for(int i=1;i<=X;i++)cin>>x,a.pb(x);
	for(int i=1;i<=Y;i++)cin>>x,b.pb(x);
	for(int i=1;i<=Z;i++)cin>>x,c.pb(x);
	sort(all(a),greater<int>());
	sort(all(b),greater<int>());
	sort(all(c),greater<int>());
	for(int i=0;i<X;i++)
		for(int j=0;j<Y;j++)
			d.pb(a[i]+b[j]);
	sort(all(d),greater<int>());
	for(int i=0;i<min(k,X*Y);i++)
		for(int j=0;j<min(k,Z);j++)
			ans.pb(d[i]+c[j]);
	sort(all(ans),greater<int>());
	for(int i=0;i<k;i++)cout<<ans[i]<<endl;
//	puts("");
	return 0;
}


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

using namespace std;

#define mz 1000000007
#define pq priority_queue

int num[2][2005][2005],k,sum[2][2005][2005];
char c[6];

int sums(int f,int x1,int y1,int x2,int y2)
{
    if(x1 && y1)
        return sum[f][x2][y2]-sum[f][x1-1][y2]-sum[f][x2][y1-1]+sum[f][x1-1][y1-1];
    if(x1)
        return sum[f][x2][y2]-sum[f][x1-1][y2];
    if(y1)
        return sum[f][x2][y2]-sum[f][x2][y1-1];
    return sum[f][x2][y2];
}

int ask(int f,int x,int y)
{
    if(x<=k)
    {
        if(y<=k)
            return sums(f,x,y,x+k-1,y+k-1);
        else
            return sums(f,x,y,x+k-1,2*k-1)+sums(f,x,0,x+k-1,(y+k-1)%(2*k));
    }
    else
    {
        if(y<=k)
            return sums(f,x,y,2*k-1,y+k-1)+sums(f,0,y,(x+k-1)%(2*k),y+k-1);
        else
            return sums(f,x,y,2*k-1,2*k-1)+sums(f,0,0,(x+k-1)%(2*k),(y+k-1)%(2*k))+sums(f,x,0,2*k-1,(y+k-1)%(2*k))+sums(f,0,y,(x+k-1)%(2*k),2*k-1);
    }
}

int main()
{
    int n;
    int x,y;
    int ans=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%s",&x,&y,c);
        if(c[0]=='W')
            num[0][x%(2*k)][y%(2*k)]++;
        else
            num[1][x%(2*k)][y%(2*k)]++;
    }
    for(int f=0;f<2;f++)
    {
        sum[f][0][0]=num[f][0][0];
        for(int i=1;i<2*k;i++)
        {
            sum[f][0][i]=sum[f][0][i-1]+num[f][0][i];
            sum[f][i][0]=sum[f][i-1][0]+num[f][i][0];
        }
        for(int i=1;i<2*k;i++)
            for(int j=1;j<2*k;j++)
                sum[f][i][j]=sum[f][i][j-1]+sum[f][i-1][j]-sum[f][i-1][j-1]+num[f][i][j];
    }
    for(int i=0;i<2*k;i++)
        for(int j=0;j<2*k;j++)
            ans=max(ans,ask(0,i,j)+ask(0,(i+k)%(2*k),(j+k)%(2*k))+ask(1,i,(j+k)%(2*k))+ask(1,(i+k)%(2*k),j));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 62976
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto& i : a){
    cin >> i;
  }
  sort(a.rbegin(), a.rend());
  int ret = 1;
  int prev = a[0];
  for(int i = 1; i < n; ++i ){
    if(a[i] < prev){
      ++ret;
      prev = a[i];
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int q[123456],c[123456];
int main(){
	int a,b,i,j,n;
	cin>>n>>a;
	for (i=0;i<n;++i){
		cin>>q[i];
	}
	for (i=1;i<n;++i){
		c[i]=abs(q[i-1]-q[i])+c[i-1];
		for (j=1;j<=a && i-j>=0;++j){
			c[i]=min(abs(q[i]-q[i-j])+c[i-j],c[i]);
		}
		
	}
	cout <<c[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

int main()
{
    int n, h, w, ans;
    cin >> n >> h >> w;
    ans = (n - h + 1) * (n - w + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <string.h>
#include <queue>
#include <functional>

#define NMAX 200001
#define MOD 1000000007
#define INF 2000000000
#define PI 3.1415926535
#define EPS 1.e10-6

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > 0 ? (a) : (-a))

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

char s[101], t[101];

int main()
{
	cin >> s >> t;
	cout << t << s << '\n';
	return 0;
}

Measured memory_bytes: 256