akhauriyash/Code-Regression huggingface dataset:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

C = [0] * (len(A) + 1)
for i in range(1, len(C)):
    C[i] = C[i-1] + A[i-1]
D = [0] * (len(B) + 1)
for j in range(1, len(D)):
    D[j] = D[j-1] + B[j-1]

ans = 0
j = M
for i in range(N+1):
    if C[i] > K:
        break
    while D[j] > K - C[i]:
        j -= 1
    ans = max(ans, i+j)
    # jの初期化は不要 <- しゃくとり法
print(ans)


Measured memory_bytes: 111808
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, k, s;
  cin >> n >> k >> s;
  int ok = s;
  int ng = s == int(1e9) ? s - 1 : s + 1;
  rep (i, n) cout << (i < k ? ok : ng) << (i == n - 1 ? "\n" : " ");
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long   ll;
typedef pair<ll,ll> pll;
typedef long double ld; 
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb           push_back
#define F            first
#define S            second
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell   998244353LL
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0) {if (y & 1) res = (res*x) % p;y = y>>1;
  x = (x*x) % p;} return res;} 

const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
ll euclid(ll x,ll y,ll a,ll b){
  return (a-x)*(a-x)+(b-y)*(b-y);
}

// #define hell 1000000007

void solve()
{
  ll a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
}
int main()
{ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t,i=1;
  t=1;
  // cin>>t;
  // preprocess();
  while(i<=t)
  {
    // cout<<"Case #"+to_string(i)+": ";
    solve();
    i++;
  }
  return 0;
}

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

using namespace std;

map<int, int> a;

int main() {
	int n;
	ignore = scanf("%d", &n);
	while (n--) {
		int x;
		ignore = scanf("%d", &x);
		a[x]++;
	}
	
	ignore = scanf("%d", &n);
	while (n--) {
		int x;
		ignore = scanf("%d", &x);
		a[x]--;
	}
	
	bool ok = true;
	for (auto& p : a) ok = ok && p.second >= 0;
	
	printf(ok ? "YES\n" : "NO\n");
	
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;


char judge(string a, string b, string c) {
	int aidx = -1;
	int bidx = -1;
	int cidx = -1;
	char current = 'a';
	while(true) {
		switch(current) {
			case 'a':
				aidx++;
				if(aidx == a.length()) {
					return 'A';
				}
				current = a[aidx];
				break;
			case 'b':
				bidx++;
				if(bidx == b.length()) {
					return 'B';
				}
				current = b[bidx];
				break;
			case 'c':
				cidx++;
				if(cidx == c.length()) {
					return 'C';
				}
				current = c[cidx];
				break;
		}
	}
}

int main() {
	string a, b, c;
	cin >> a >> b >> c;

	cout << judge(a, b, c) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int x, y,i , j=0;
  cin>>x>>y;
  for(i=0;i<=x;i++){
  	if((x-i)*2+i*4==y){
      cout<<"Yes"<<endl;
      j=1;


    }

  }
  if(j==0)cout<<"No"<<endl;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 1000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  ll N;cin >> N;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  ll ans = 0;
  /*for(int i = 0;i < N;i++){
    cout << A[i] << " " ;
  }
  cout << endl;*/
  for(int i = 0;i < N-2;i++){
    for(int j = i+1;j < N-1;j++){
      int l = j,r = N;
      while(r-l > 1){
        int mid = (r+l)/2;
        if(A[mid] >= A[j] + A[i]){
          r = mid;
        }else{
          l = mid;
        }
      }
      //cout << "(" <<i<< "," <<j<< ','<<A[i]+A[j]<<")" <<' '<<r<<' '<<r-j-1<< endl;
      ans += r-j-1;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int X;
  cin >> X;
  int Y;
  Y = X;
  int S = 0;
  while (Y >= 10) {
    S += Y % 10;
    Y /= 10;
  }
  S += Y;
  if (X % S == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
main(void){
	int T;cin>>T;
	double x1,x2,x3,x4,y1,y2,y3,y4;
	for(int t=1;t<=T;t++){
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		if(abs((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4))<0.0000000001)
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1224
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	if N == 2 {
		if 0 < K {
			fmt.Fprintln(wtr, -1)
			return
		}
	} else {
		if (N-1)*(N-2)/2 < K {
			fmt.Fprintln(wtr, -1)
			return
		}
	}
	G := make([][]int, N)
	for i := 1; i < N; i++ {
		G[0] = append(G[0], i)
	}
	now := (N - 1) * (N - 2) / 2
	for i := 1; i < N-1 && K < now; i++ {
		for j := i + 1; j < N && K < now; j++ {
			G[i] = append(G[i], j)
			now--
		}
	}

	m := 0
	for i := 0; i < N; i++ {
		m += len(G[i])
	}
	fmt.Fprintln(wtr, m)
	for i := 0; i < N; i++ {
		for j := 0; j < len(G[i]); j++ {
			fmt.Fprintln(wtr, i+1, G[i][j]+1)
		}
	}
}


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

int main() {
    int64_t N, K;
    cin >> N >> K;

    vector<int64_t> num(N, 0);
    for (int64_t i = 0; i < K; i++) {
        int64_t d;
        cin >> d;
        for (int64_t j = 0; j < d; j++) {
            int64_t A;
            cin >> A;
            num[A - 1]++;
        }
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        ans += (num[i] == 0);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll H, W, N; cin >> H >> W >> N;
  vector<ll> a(N);
  REP(i, N) cin >> a[i];
  vector<ll> sum(N+1,0);
  REP(i, N) sum[i+1] = sum[i] + a[i];
  vector<vector<ll>> grid(H, vector<ll>(W,-1));

  FOR(i,1,N+1){
    FOR(j,sum[i-1], sum[i]){
      ll tate = j/W;
      ll yoko = tate%2==0? j%W : W-1 - j%W; 
      grid[tate][yoko] = i;
    }
  }  

  REP(i, H) REP(j, W){
    cout << grid[i][j];
    if(j==W-1) cout << endl;
    else cout << " ";
  }
}



Measured memory_bytes: 512
/**In The Name Of Allah*/

#include<bits/stdc++.h>
#include<numeric>

using namespace std;
#define pri(n)          printf("%d\n",n)
#define prll(n)         printf("%lld\n",n)
#define prd(n)          printf("%lf\n",n)
#define scll(n)         scanf("%lld",&n)
#define sci(n)          scanf("%d",&n)
#define scd(n)          scanf("%lf",&n)
#define pi              acos(-1)//inbuilt M_PI
#define ll              long long
#define pb              push_back
#define vsort(v)        sort(v.begin(),v.end())
#define asort(n)        sort(ar,ar+n)
#define yes             cout<<"Yes\n"
#define no              cout<<"No\n"
#define for1(i,n)       for(i=1;i<=n;i++)
#define for0(i,n)       for(i=0;i<n;i++)
#define mod             1000000007
#define watch(x)        cout << (#x) << " is " << (x) <<"\n";

ll cal(ll x,ll y,ll z)
{
    return ((x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x));
}

int main()
{
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);/**Dont't use scanf of printf*/
    ll i,a,b,len,j,k,root,l,r,d,n,t,minn,sum=0,cnt=0,odd;
    cin>>n;
    ll ar[10009];
    memset(ar,0,sizeof(ar));
    root=sqrt(n);
    for1(i,root){
        for1(j,root){
            for1(k,root){
                sum=cal(i,j,k);
                if(sum<=n) ar[sum]++;
                else break;
            }
        }
    }
    for1(i,n) cout<<ar[i]<<endl;

    return 0;
}


Measured memory_bytes: 3752
n = int(input())
w = []
correct = 0

for i in range(n):
    w.append(input())
    
if len(set(w))==n:
    for i in range(n-1):
        if w[i][-1] == w[i+1][0]:
            correct += 1
            
    if correct == n-1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import bisect
M = 1000000007

# def dfs(i):
#     if i >= n - 1:
#         return 1
#     if dp[i] is not None:
#         return dp[i]
#     if i <= maxv and a[bisect.bisect_left(a, i)] == i:
#         dp[i] = 0
#         return 0
#     r = (dfs(i + 1) + dfs(i + 2)) % M
#     dp[i] = r
#     return r

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
a.sort()
maxv = m and max(a) or -1
# dp = [None] * n
# print(dfs(0) % M)

dp = [1] * (n + 2)
dp[-1] = 0
for i in range(n - 1, -1, -1):
    if i <= maxv and a[bisect.bisect_left(a, i)] == i:
        dp[i] = 0
    else:
        dp[i] = (dp[i + 1] + dp[i + 2]) % M

print(dp[0] % M)


Measured memory_bytes: 7848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e10;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    vector<ll> dp(n+1, INF);
    dp[0] = 0;
    for(int i = 0; i+1 < n; i++)
    {
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
#include <stdio.h>
 
int main(){
    int i, j, tmp, n[5];
     
    for(i = 0; i < 5; i++) scanf("%d", &n[i]);
    
    for(i = 0; i < 4; i++)
        for(j = 0; j < 4; j++)
            if(n[j] < n[j + 1]){
                tmp  = n[j];
                n[j] = n[j + 1];
                n[j + 1] = tmp;
            }
        
    printf("%d", n[0]);
    
    for(i = 1; i < 5; i++) printf(" %d", n[i]);
    
    printf("\n");
     
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct CumulativeSum{
    vector<int> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            (data[i] += data[i - 1]) %= mod;
        }
    }
    int query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    int query(int l, int r){
        return (query(r - 1) - query(l - 1) + mod) % mod;
    }
};
int dp[110][100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    dp[0][0] = 1;
    rep(i, 0, n){
        CumulativeSum cs(k + 1);
        rep(j, 0, k + 1) cs.add(j, dp[i][j]);
        cs.build();
        rep(j, 0, k + 1){
            dp[i + 1][j] = cs.query(max(0LL, j - a[i]), j + 1);
        }
    }
    cout << dp[n][k] << endl;
}

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

#define ld long double
#define eps 1e-9
struct vec{
	ld x , y;
	vec(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
	friend vec operator +(vec A , vec B){return vec(A.x + B.x , A.y + B.y);}
	friend vec operator -(vec A , vec B){return vec(A.x - B.x , A.y - B.y);}
	friend ld operator *(vec A , vec B){return A.x * B.x + A.y * B.y;}
	friend ld operator %(vec A , vec B){return A.x * B.y - A.y * B.x;}
	ld len(){return sqrt(x * x + y * y);}
};

vec getvec(){int x , y; cin >> x >> y; return vec(x , y);}

int main(){
	vec A = getvec() , B = getvec() - A; int Q;
	for(cin >> Q ; Q ; --Q){
		vec C = getvec() - A;
		if(B % C > eps) puts("COUNTER_CLOCKWISE");
		else if(B % C < -eps) puts("CLOCKWISE");
		else if(B * C < 0) puts("ONLINE_BACK");
		else puts(B.len() + eps > C.len() ? "ON_SEGMENT" : "ONLINE_FRONT");
	}
	return 0;
}



Measured memory_bytes: 3048
/*
*                                 Name : chaitanya
*
*                         Institute : ANITS,Visakhapatnam
*   "Don't regret anything you do, because in the end it makes you who you are."
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#include<sstream>
#include <assert.h>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
using namespace std;

int main()
{  
    int n,c =0,f = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int a,b;
        cin >> a >> b;
        if( a == b)
            c++;
        else
            c = 0;
        if (c >= 3)
            f = 1;
    }
    if (c >= 3)
        f = 1;
    if (f == 1)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int h, w;
vector<string> mp;
vector<bool> used, usedx;
vector<int> ps;
vector<int> t;

bool f() {
  for (int i = 0; i < h / 2; i++) {
    t[i] = ps[i * 2];
    t[h - i - 1] = ps[i * 2 + 1];
  }
  if (h % 2 == 1) {
    t[h / 2] = ps[h - 1];
  }
  int inv = 0;
  usedx.clear();
  usedx.resize(w);
  for (int i = 0; i < w; i++) {
    if (usedx[i])
      continue;
    for (int j = i + 1; j < w; j++) {
      if (usedx[i] || usedx[j])
        continue;
      bool ok = true;
      for (int k = 0; k < h; k++) {
        if (mp[t[k]][i] != mp[t[h - k - 1]][j]) {
          ok = false;
        }
      }
      if (ok) {
        usedx[i] = usedx[j] = true;
        inv += 2;
      }
    }
  }
  if (w % 2 == 0 && inv == w) {
    return true;
  }
  if (w % 2 == 1 && inv == w - 1) {
    bool ok = true;
    for (int i = 0; i < w; i++) {
      if (usedx[i])
        continue;
      for (int j = 0; j < h; j++) {
        if (mp[t[j]][i] != mp[t[h - j - 1]][i])
          ok = false;
      }
    }
    return ok;
  }
  return false;
}

bool dfs(int now) {
  if (now == h || (h % 2 == 1 && now == h - 1)) {
    return f();
  }
  if (now % 2 == 0) {
    for (int i = 0; i < h; i++) {
      if (!used[i]) {
        ps[now] = i;
        used[i] = true;
        bool ret = dfs(now + 1);
        used[i] = false;
        return ret;
      }
    }
  }
  bool ret = false;
  for (int i = 0; i < h; i++) {
    if (!used[i]) {
      ps[now] = i;
      used[i] = true;
      if (dfs(now + 1))
        ret = true;
      used[i] = false;
    }
  }
  return ret;
}

int main() {
  cin >> h >> w;
  mp.resize(h);
  for (int i = 0; i < h; i++)
    cin >> mp[i];

  used.resize(h);
  ps.resize(h);
  t.resize(h);

  bool ok = false;
  if (h % 2 == 0) {
    ok = dfs(0);
  } else {
    for (int i = 0; i < h; i++) {
      used[i] = true;
      ps[h - 1] = i;
      if (dfs(0))
        ok = true;
      used[i] = false;
    }
  }
  if (ok) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if(x == 3) ans += 100000;
  if(x == 2) ans += 200000;
  if(x == 1) ans += 300000;
  if(y == 3) ans += 100000;
  if(y == 2) ans += 200000;
  if(y == 1) ans += 300000;
  if(x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define deb(x) cout << #x << " is " << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define fo(i, n) for (ll i = 0; i < n; i++)
#define rep(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define pb push_back
#define ff first
#define ss second
#define mk make_pair

//-----PREPROCESSORS-------
//Use emplace_back instead of push_back for faster execution...
typedef long long int ll;
const ll INF = 1e18 + 10;
const ll mod = 1000000007;
const double PI = acos(-1);
const int N = 1e7 + 2;
//-----------------------------------------------------------
//Function to return gcd of a and b
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//------------------------------------------
ll power(ll x, ll y, ll p) //x^y %p
{
    ll res = 1;
    x %= p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        x = (x * x) % p;
        y >>= 1;
    }
    return res;
}
bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
//-----------------------------------------------
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;string s;
    int t = 1;
    char c;
    //cin >> t;
    while (t--)
    {  
        cin>>k>>s;
        if(s.length()<=k)
        cout<<s<<endl;
        else cout<<s.substr(0,k)+"..."<<endl;
        // set<ll> factors;
        // factors.insert(1);
        // factors.insert(n);
        // for(int i=2;i<=sqrt(n)+1;i++)
        // {
        //     if(n%i==0)
        //     {
        //         factors.insert(i);
        //         factors.insert(n/i);
        //     }
        // }
        // auto it = factors.upper_bound(k);
        // --it;
        // ll g = *it;
        // cout<<(n/g)<<"\n";
    }
}



Measured memory_bytes: 3628
import scala.io.StdIn.{readInt,readLine}

object Main {
  def isSequence(h:Array[Long]) = {
    val diff = h(1)-h(0)
    def scan(i:Int):Boolean = {
      if(i==h.length) true
      else if(h(i)-h(i-1) != diff) false
      else scan(i+1)
    }
    scan(1)
  }

  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readInt).takeWhile(_!=0).map { n=>
        val h = readLine.split(" ").map(_.toLong).toBuffer
        def scan(i:Int):Long= {
          val a = h.toBuffer
          a.remove(i)
          if(i==h.length) -1
          else if(isSequence(a.toArray)) h(i)
          else scan(i+1)
        }
        scan(0)
      }.mkString("\n")
    }
  }
}

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

using namespace std;

int N;
int h[112345];
int dp[112345];

int main () {
    cin >> N;
    for(int i=0; i<N; i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs( h[1] - h[0]);
    for(int i=2; i<N; i++) {
        dp[i] += min( dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]) );
    }
    cout << dp[N-1] << endl;
    return 0;
}


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    int n, w, r;
    string s;
    cin >> n >> s;
    rep(i, n) if (s[i] == 'W') w++; else r++;

    if (n == w || n == r) {
        cout << 0 << endl;
        return;
    }

    int x = 0, y = n - 1, z = 0;
    while(x < y) {
        if (s[x] == 'W' && s[y] == 'R') {
            z++;
            x++;
            y--;
        } else if (s[x] == 'R') {
            x++;
        } else if (s[y] == 'W') {
            y--;
        }
    }
    cout << z << endl;
}


Measured memory_bytes: 3740
package main

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

func main() {
	n, m := ScanInt(), ScanInt()
	v := ScanIntSlice(n)

	c := 0
	sum := int64(0)
	for i := 0; i < n; i++ {
		sum += int64(v[i])
	}

	th := float64(sum) / float64(4*m)
	for i := 0; i < n; i++ {
		if float64(v[i]) >= th {
			c++
		}
	}
	if c >= m {
		P("Yes")
	} else {
		P("No")
	}
}

/*********************** I/O ***********************/

var in *bufio.Scanner
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: chars,
    }
    println!(
        "{}",
        if (n[0] == n[1] && n[0] == n[2]) || (n[1] == n[2] && n[1] == n[3]) {
            "Yes"
        } else {
            "No"
        }
    );
}


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

int n,arr[1000000][3],dp[1000000][3],mx=0;
int vacation(){
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			mx=0;
			for(int k=0;k<3;k++){
				if(k!=j && dp[i-1][k]>mx)
					mx=dp[i-1][k];
			}
			dp[i][j]=arr[i][j]+mx;
		}
	}
	return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
		if(i==0){
			dp[i][0]=arr[i][0];
			dp[i][1]=arr[i][1];
			dp[i][2]=arr[i][2];
		}
	}
	cout<<vacation();
	return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> node;
const ll MOD = 998244353;

int A,B,C,D;

vector<vector<ll> > dp;

ll mod(ll a)
{
    return (a + MOD) % MOD;
}

int main()
{

    for (int i = 0; i < 3001; i++)
    {
        vector<ll> tmp;
        for(int j = 0; j < 3001; j++)
        {
            tmp.push_back(0);
        }
        dp.push_back(tmp);
    }

    cin >> A >> B >> C >> D;

    ll acc_a=A; ll acc_b = B;
    for (int i = B+1; i <= D; i++)
    {
        dp[A][i] = acc_a;
        acc_a = mod(acc_a * A);
    }

    for (int i = A+1; i <= C; i++)
    {
        dp[i][B] = acc_b;
        acc_b = mod(acc_b * B);
    }

    dp[A][B] = 1;

    for (int i = A+1; i <= C; i++)
    {
        for(int j = B+1; j <= D; j++)
        {
            dp[i][j] = mod(mod(mod(mod(dp[i-1][j]) * (j)) + mod(dp[i][j-1] * (i))) - mod(mod(dp[i-1][j-1] * (i-1)) * (j-1)));
            // dp[i][j] = mod(dp[i-1][j-1] * (i+j-1) * (i+j-2) / 2, MOD);
            // cout << dp[i][j] << endl;
            // cout << dp[i-1][j] * j + dp[i][j-1] * i - 1 << endl;
            // cout << dp[i-1][j] << endl;
        }
    }

    cout << dp[C][D] << endl;

}

Measured memory_bytes: 73536
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

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

//const ll dx[] = {1,0,0,-1};const ll dy[] = {0,1,-1,0};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S,T;
    cin >> S >> T;
    if(S[0] == T[2] && S[1] == T[1] && S[2] == T[0]){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 3624
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  int n;
  cin >> n;
  vector<int> a(n+2);
  a[0] = 0;
  a[n+1] = 0;

  ll total = 0;
  for(int i=1;i<=n;i++) {
    cin >> a[i];
    total += abs(a[i] - a[i-1]);
  }
  total += abs(a[n]);

  for(int i=1;i<=n;i++) {
    cout << total + abs(a[i-1] - a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])) << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

class Main {

    static Scanner scan;

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

        int a = scan.nextInt();
        int b = scan.nextInt();

        System.out.printf("%d %d\n", a*b, a*2+b*2);
    }
}




Measured memory_bytes: 26168
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();

    double sum = 0;
    for (int i = 0; i < N; i++) {
      sum += 1 / scn.nextDouble();
    }

    System.out.println(1 / sum);
  }

}


Measured memory_bytes: 23508
#include <stdio.h>

int main(){
  int n,d,x;
  scanf("%d%d%d", &n, &d, &x);
  int a[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
  }
  int ans = x;
  for(i=0;i<n;i++){
    ans += (d-1)/a[i] + 1;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
var h = [],hs = 0;
h[0] = new Array(2);
h[0][0] = -1;h[0][1] = -1;
 
function insert(key){
    h[++hs] = key;
 
    var i = hs;
 
    while(h[i][1] < h[Math.floor(i / 2)][1]){
        var ex = h[i];
        h[i] = h[Math.floor(i / 2)];
        h[Math.floor(i / 2)] = ex;
        i = Math.floor(i / 2);
    }
}
 
function extract(){
    if(hs <= 0)
        return;
 
    var ret = h[1];
 
    h[1] = h[hs--];
 
    i = 1;
    while((i * 2 <= hs && h[i][1] > h[i * 2][1]) || (i * 2 + 1 <= hs && h[i][1] > h[i * 2 + 1][1])){
        var l = i * 2;var r = i * 2;
        if(i * 2 + 1 <= hs)
            r++;
        var m = h[l][1] <= h[r][1] ? l : r;
        var ex = h[i];
        h[i] = h[m];
        h[m] = ex;
        i = m;
 
    }
    return ret;
}


function Main(input){
    input = input.split("\n");
    var n = parseInt(input[0],10);

    var graph = new Array(n);
    var k = new Array(n);

    for(var i = 0;i < n;i++){
        input[i + 1] = input[i + 1].split(" ");
        var u = parseInt(input[i + 1][0],10);
        k[u] = parseInt(input[i + 1][1],10);
        graph[u] = new Array(k[u]);
        for(var j = 0;j < k[u];j++)
            graph[u][j] = new Array(2);
        for(var j = 0;j < k[u];j++){
            graph[u][j][0] = parseInt(input[i + 1][j * 2 + 2],10);
            graph[u][j][1] = parseInt(input[i + 1][j * 2 + 3],10);
        }
    }

    var count = 1;
    var sum = Array(n);
    for(var i = 0;i < n;i++)
        sum[i] = 1000000000;
    sum[0] = 0;
    for(var i = 0;i < k[0];i++){
        insert(graph[0][i]);
    } 
    while(count < n){
        var aa = extract();
        if(sum[aa[0]] < 1000000000)
            continue;

        sum[aa[0]] = aa[1];
        count++;

        for(var i = 0;i < k[aa[0]];i++){
            graph[aa[0]][i][1] += sum[aa[0]];
            insert(graph[aa[0]][i]);
        }
    }

    for(var i = 0;i < n;i++){
        console.log(i + " " + sum[i]);
    }
}

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

Measured memory_bytes: 18388
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);
 
int main()
{
	vi a(5);
	rep(i,5) cin >> a[i];
	int k;
	cin >> k;
	cout << (a[4]-a[0] > k ? ":(" : "Yay!") << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int l[3];
    for (int i = 0; i < 4; i++)
    {
        scanf("%d",&l[i]);
    }
    int a=l[0]*l[1];
    int b=l[2]*l[3];
    if (a>b)
        printf("%d",a);
    else
        printf("%d",b);
    
    return 0;
}

Measured memory_bytes: 128
import math

class Position:
    def __init__(self, r, sita):
        self.x = r * math.cos(sita)
        self.y = r * math.sin(sita)

def main():
    a, b, h, m = map(int, input().split())
    ans = solve(a, b, h, m)
    print(ans)


def solve(a, b, h, m):
    t = 60 * h + m
    Rh, Rm = math.pi / 2 - (t % 720) / 360 * math.pi, math.pi / 2 - (t % 60) / 30 * math.pi
    H = Position(a, Rh)
    M = Position(b, Rm)
    ans = (abs(H.x - M.x) ** 2 + abs(H.y - M.y) ** 2) ** (1 / 2)
    return ans


if __name__ == '__main__':
    main()

Measured memory_bytes: 9604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 998244353
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;}

/*方針*/
/*
➀dijkstra法で最短経路を見つけて(経路復元)、通った辺に判定をつける
➁通っていない辺の数を数える
*/
ll n,m;

void dijkstra(Graph &G,map<P,ll> &bet,ll start,vector<ll> &dist,vector<ll> &prev){
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,start});
    
    prev.assign(n,-1);
    dist.assign(n,INF);
    dist[start]=0;

    while(que.size()){
        P now=que.top();
        que.pop();
        if(dist[now.second]<now.first) continue;//今、最短距離でないなら無視する

        for(auto next:G[now.second]){
            if(dist[next]>dist[now.second]+bet[make_pair(now.second,next)]){//最短になる場合
                dist[next]=dist[now.second]+bet[make_pair(now.second,next)];//最短距離更新
                que.push(make_pair(dist[next],next));
            
                prev[next]=now.second;//now.secondを通って、nextに到着
            }
        }
    }
}

vector<ll> get_path(vector<ll> &prev,int goal){//経路復元
    vector<ll> path;
    for (ll cur=goal;cur!=-1;cur=prev[cur]){
        path.push_back(cur);
    }
    reverse(path.begin(),path.end());//逆順なのでひっくり返す
    return path;
}

int main(){
    cin>>n>>m;
    Graph G(n);
    map<P,ll> bet;//2点間距離
    vector<P> stay;//pairを保存

    rep(i,m){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
        bet[make_pair(a,b)]=c;//a-b間距離
        bet[make_pair(b,a)]=c;

        stay.push_back(make_pair(a,b));//頂点を保存
        stay.push_back(make_pair(b,a));
    }

    map<P,bool> visit;//ある辺について訪れたかどうかの判定
    rep(i,stay.size()){
        visit[stay[i]]=false;//初期化
    }

    rep(i,n){
        rep(j,n){
            if(i==j) continue;
            vector<ll> dist,prev;

            dijkstra(G,bet,i,dist,prev);
            vector<ll> path=get_path(prev,j);

            rep(k,path.size()-1){
                visit[make_pair(path[k],path[k+1])]=true;//訪れた辺はtrue
                visit[make_pair(path[k+1],path[k])]=true;
            }
        }
    }

    ll ans=2*m;
    rep(i,stay.size()){
        if(visit[stay[i]]){
            ans--;//訪れていたら、-1
        }
    }

    cout<<ans/2<<endl;//(a,b),(b,a)のように二つずつ数えているから2で割る

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, Z, W;
  cin >> N >> Z >> W;
  vector<ll> A;
  A.push_back(Z);
  A.push_back(W);
  for (ll i = 0; i < N; ++i)
  {
    ll a;
    cin >> a;
    A.push_back(a);
  }
  cout << max(abs(A.at(N + 1) - A.at(1)), abs(A.at(N + 1) - A.at(N))) << endl;
}


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

int main(){
    int l;
    cin>>l;
    int a[l];
    for(int i=0;i<l;i++){
        cin>>a[i];
    }
    ll dp[l+1][5];
    fill(dp[0],dp[l+1],LINF);
    dp[0][0]=0;
    for(int i=1;i<=l;i++){
        for(int j=0;j<5;j++){
            for(int k=0;k<=j;k++){
                if(j==0||j==4)dp[i][j]=min(dp[i][j],dp[i-1][k]+a[i-1]);
                else if(j==1||j==3)dp[i][j]=min(dp[i][j],dp[i-1][k]+(a[i-1]?a[i-1]%2:2LL));
                else dp[i][j]=min(dp[i][j],dp[i-1][k]+(a[i-1]+1)%2);
            }
        }
    }
    ll ans=LINF;
    for(int i=0;i<5;i++){
        ans=min(ans,dp[l][i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define maxn 100
#define maxk 100001
using namespace std;

int n,k;
int ar[maxn];
bool dp[maxk];

int main() {
	cin >> n >> k;
	for( int i = 0 ; i < n ; i++ )
		cin >> ar[i];
	dp[0] = false;
	for( int i = 1 ; i <= k ; i++ )
		for( int j = 0 ; !dp[i] && j < n ; j++ )
			if( i >= ar[j] && !dp[i-ar[j]] )
				dp[i] = true;
	if( dp[k] )
		cout << "First" << endl;
	else
		cout << "Second" << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
//#define int long long

void solve() {
	int n,k,a,b,ans = 0;
 	cin >> n;
 	cin >> k;
 	cin >> a;
 	cin >> b;
 	
 	ans += (min(n,k))*a + (max(0, n-k))*b;
 	
 	cout << ans;
 	
}
		
			
		

int32_t main() {
	IOS;
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int[] ps = { 10, 50, 100, 500 };

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        boolean init = true;
        while (true) {
            int m = sc.nextInt();
            if (m == 0)
                break;
            if(init )init = false;
            else System.out.println();
            int ns[] = new int[4];
            int sum = 0;
            for (int i = 0; i < 4; i++) {
                ns[i] = sc.nextInt();
                sum += ns[i];
            }
            int[] ans = new int[4];
            int min = Integer.MAX_VALUE;
            for (int i = 0; i <= ns[0]; i++) {
                for (int j = 0; j <= ns[1]; j++) {
                    for (int k = 0; k <= ns[2]; k++) {
                        for (int l = 0; l <= ns[3]; l++) {
                            if (i * ps[0] + j * ps[1] + k * ps[2] + l * ps[3] < m)
                                continue;
                            int[] cs = { i, j, k, l };
                            int[] turi = change(i * ps[0] + j * ps[1] + k
                                    * ps[2] + l * ps[3] - m);
                            boolean bad = check(cs, turi);
                            if (bad)
                                continue;
                            int res = 0;
                            for (int p = 0; p < 4; p++) {
                                res += turi[p];
                            }
                            if (min > sum - (i + j + k + l) + res) {
                                min = sum - (i + j + k + l) + res;
                                ans = cs;
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < 4; i++) {
                if (ans[i] == 0)
                    continue;
                System.out.println(ps[i] + " " + ans[i]);
            }
        }
    }

    static boolean check(int a[], int b[]) {
        boolean res = false;
        for (int i = 0; i < a.length; i++) {
            if (a[i] > 0 && b[i] > 0)
                res = true;
        }
        return res;
    }

    static int[] change(int n) {
        int cs[] = new int[4];
        for (int i = 3; i >= 0; i--) {
            cs[i] = n / ps[i];
            n %= ps[i];
        }
        return cs;
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int L, R; cin >> L >> R;
        ans += R - L + 1;
    }
    cout << ans;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.range;
import std.array;
import std.string;
import std.conv;

void main(){
	auto n = readln.chomp.to!long;
	if(is_harshad(n)){
		writeln("Yes");
	}else{
		writeln("No");
	}
}

bool is_harshad(long n){
	auto fx = n.to!string.map!((c) => [c].to!long).reduce!("a+b");
	return n % fx == 0;
}

Measured memory_bytes: 256
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
x,y = map(int,input().split())
if x == y:
    print("Yes")
elif x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9032
/*
	@・ω・@ <だれだろうね
*/

/*****/

#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<long long>;
using pll = pair<long long, long long>;
template<class T> using pr = pair<T, T>;
template<class T> using vec = vector<T>;

#define debug(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t",n) << (x) << "\n")
#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 str(n)	(n.toString())

#define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(ll i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(ll 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 MOD = 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; }
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 = math_P(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool cmp_2nd(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 mod_pow(T x, T n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) { (ret *= x) %= p; } (x *= x) %= p; n >>= 1; } return ret; }

/*****/



void Main()
{
	ll x;
	cin >> x;

	ll ret = 0;

	ret += (x / 500) * 1000;
	x %= 500;
	ret += (x / 5) * 5;

	cout << ret;
}

/*****/

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();
	cout << /**/ endl /*/ flush /**/;

	return 0;
}


Measured memory_bytes: 256