akhauriyash/Code-Regression huggingface dataset:
"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def solve():
    n = int(sys.stdin.readline())
    print(n + n ** 2 + n ** 3)
    


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()



Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;

int n;
int arr[MAXN];
void solve(){
    int x = 0, i =0;
    for(i = 0; i < n; i++)
        x ^= arr[i];
    for(i = 0; i < n; i++)
        cout << (x ^ arr[i]) << " ";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i = 0;
    cin >> n;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}


Measured memory_bytes: 4476
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    a, b = LI()
    c, d = LI()
    if a != c:
        print(1)
    else:
        print(0)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39024
#ABC091C
#Input
ab=[]
cd=[]
N=int(input())
for i in range(N):
    ab.append(list(map(int, input().split())))
for i in range(N):
    cd.append(list(map(int, input().split())))
ab.sort(key=lambda x:(-x[1],x[0]))
cd.sort()
#Preparation
ans=0
#Processing
for i in range(N):
    #i番目のBlueに着目する
    bx=cd[i][0]
    by=cd[i][1]
    for j in range(N):
        #j番目のRedに着目する
        rx=ab[j][0]
        ry=ab[j][1]
        #Compare
        if bx>rx and by>ry:
            ans+=1
            #Erase the used red point
            ab[j][0]=200
            ab[j][1]=200
            break
#Output
print(ans)

Measured memory_bytes: 3064
//Author:  Pranta
//Date:    2020-Aug-22
//Problem: A_Takoyaki
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    int ans=(n/x);
    if(n%x!=0) ans++;
    cout<<ans*t;
}
int main()
{
    fast;
    int t;
    ///cin>>t;
    ///while(t--)
    solve();
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int n, W;
Int v[110], w[110];
Int dp[110][110000];

int main(){
    cin >> n >> W;
    for(int i = 1;i <= n;i++)cin >> w[i] >> v[i];

    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= W;j++){
            dp[i][j] = dp[i-1][j];
            if(j-w[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 87424
#include <bits/stdc++.h>
using namespace std;
const int N=205;
char mat[N][N];
int dist[N],n;
int BFS(int u)
{
	for(int i=1;i<=n;i++) dist[i]=-1;
	queue<int> q;
	q.push(u);
	dist[u]=1;
	while(q.size())
	{
		int x=q.front();
		q.pop();
		for(int y=1;y<=n;y++) if(mat[x][y]=='1')
		{
			if(dist[y]==-1)
			{
				dist[y]=dist[x]+1;
				q.push(y);
			}
			else if(dist[x]==dist[y])
			{
				printf("-1\n");
				exit(0);
			}
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++) mx=max(mx,dist[i]);
	return mx;
}
int main()
{
	scanf("%i",&n);
	for(int i=1;i<=n;i++) scanf("%s",mat[i]+1);
	int ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,BFS(i));
	printf("%i\n",ans);
	return 0;
}

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

int main() {
  int A , B ,C; cin >> A >> B >> C ;
  int count = 0;
  int a , b ,c; a = b = c = 0;
  while(true){
    if(A == B && B == C && A % 2 == 0){
      cout << -1 << endl;
      break;
  }
    else if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
      cout << count << endl;
      break;
  }
    else{
      count++;
      a = A / 2;
      b = B / 2;
      c = C / 2;
      A = b + c;
      B = a + c;
      C = a + b;
    }

  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
typedef long long ll;
#define max(a,b) ((a)>(b) ? (a) : (b))
using namespace std;
int main(){
  int i,n;
  ll a,b,c;
  ll dp[100010][3]={0};
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a >> b >> c;
    if(i==0){
      dp[i][0]=a;
      dp[i][1]=b;
      dp[i][2]=c;
    }else{
      dp[i][0] = a+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = b+max(dp[i-1][0],dp[i-1][2]);
      dp[i][2] = c+max(dp[i-1][1],dp[i-1][0]);
    }
  }
  cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
  return 0;
}

Measured memory_bytes: 5964
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int k;
	cin >> k;
	vector<ll> v;
	rep(i, 9){
		v.pb(i + 1);
	}
	int cur = 0;
	rep(i, k){
	
		ll cur = v[i] % 10;
		if(cur){
			v.pb(v[i] * 10 + cur - 1);
		}
		v.pb(v[i] * 10 + cur);
		if(cur != 9){
			v.pb(v[i] * 10 + cur + 1);
		}
	}
	cout << v[k - 1];
}


 
 
int main()
{
    Red;
	int T = 1;
	//cin >> T; 
	for(int i = 1; i <= T; ++i){
		solve();
	}
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vp;
typedef vector<ll> vll;

const int INF = 99999999;
const int MAX_V = 1000;

struct edge { int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];       // for DFS

// add graph the edge
void add_edge(int from, int to, int cap) {
    G[from].emplace_back((edge){to, cap, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
	for (auto& e : G[v]) {
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for(;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

signed main() {
	int X, Y, E;
	cin >> X >> Y >> E;
	int N = X + Y;
	int s = N;
	int t = s + 1;
	rep(i, X) {
		add_edge(s, i, 1);
	}
	rep(i, Y) {
		add_edge(i + X, t, 1);
	}
	rep(i, E) {
		int a, b;
		cin >> a >> b;
		add_edge(a, b + X, 1);
	}
	cout << max_flow(s, t) << endl;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i=1; i<=(n); i++)
typedef long long ll;
using namespace std;
 
int main(){
    int N; cin >> N;
    rep(i,9){
        for (int j=1; j<=9; j++){
            if (N==i*j){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
war_flag = 0

str_arr1 = gets.chomp!.split(" ")

n = str_arr1[0].to_i
m = str_arr1[1].to_i
x = str_arr1[2].to_i
y = str_arr1[3].to_i

kouho_arr = []

if x >= y then war_flag = 1
else
  ii = x+1

  while ii <= y do
    kouho_arr.push(ii)
    ii += 1
  end
end

str_arr2 = gets.chomp!.split(" ").map!{|i| i.to_i}

x_max = str_arr2.max

str_arr3 = gets.chomp!.split(" ").map!{|i| i.to_i}

y_min = str_arr3.min

if y_min <= x_max then war_flag = 1 end

if war_flag == 0 then
  kouho_arr.each do |kkk|
    if y_min < kkk || kkk <= x_max then war_flag = 1
    else
      war_flag = 0
      break
    end
  end

end



if war_flag == 1 then
  puts "War"
else
  puts "No War"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int p=0;
    int i;
    for(i=0;i<n;i+=x){
        p+=t;
    }
    cout << p << endl;
    return 0;
}

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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<int> cnt(110000);
  for (int i = 0; i < N; i++) {
    cnt.at(A.at(i))++;
  }
  int ans = -1;
  for (int i = 1; i < 109999; i++) {
    ans = max(ans, cnt.at(i - 1) + cnt.at(i) + cnt.at(i + 1));
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int main(){
	int n,m,a,b;
	while(cin>>n>>m,n||m){
		int a[n],b[m],comp=10000,ans[2];
		bool check=false;
		rep(i,n)cin>>a[i];
		rep(i,m)cin>>b[i];
		rep(i,n){
			rep(j,m){
				int sum[2]={0,0};
				rep(k,n)sum[0]+=(k==i)?b[j]:a[k];
				rep(k,m)sum[1]+=(k==j)?a[i]:b[k];
				if(sum[0]==sum[1] && comp>(a[i]+b[j])){
					ans[0]=a[i];
					ans[1]=b[j];
					comp=a[i]+b[j];
					check=true;
				}
			}
		}
		if(check){
			cout<<ans[0]<<" "<<ans[1]<<endl;
		}else cout<<"-1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3068
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(N)]
    b=[list(map(int,input().split())) for _ in range(M)]
    for x,y in a:
        tmp=INF
        for i,(xx,yy) in enumerate(b):
            if abs(xx-x)+abs(yy-y)<tmp:
                tmp=abs(xx-x)+abs(yy-y)
                ans=i+1
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
# https://pitsbuffersolution.com/compro/atcoder/arc099d.php

k = int(input())

def calc_snuke(n):
    return n/sum(map(int,str(n)))

a = []
for i in range(1000):
    if i% 10 == 9 or i%100 == 99 or i%1000 == 999:
        continue
    a.append(i)

que = []
for i in range(16):
    m = 10**i-1
    for ai in a:
        w = ai*10**i+m
        if 0<w<=10**15-1:
            que.append(w)
que.sort(reverse=True)
mi = float("inf")
ans = []
for i in que:
    q = calc_snuke(i)
    if q > mi:
        continue
    ans.append(i)
    mi = q
ans.sort()
print(*ans[:k], sep="\n")

Measured memory_bytes: 42860
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


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


vector<pair<ll, int>> factrized(ll num){
  vector<pair<ll, int>>  res;
 
  for(ll i = 2; i * i <= num; i++){
    if(num % i)continue;
    res.emplace_back(i, 0);
    while(num % i == 0){
      num /= i;
      res.back().second++;
    }
  }
  if(num != 1) res.emplace_back(num, 1);
  return res;
}

bool solve(vector<pair<ll, int>> vp){

  if(vp.size() == 1 && (vp[0].first == 1 || vp[0].first == -1)){
    return true;
  }
  if(vp.size() == 1 && vp[0].second == 5){
    return true;
  }
  return false;
}

int main(){
  // long long x;
  // cin >> x;

  // long long x_abs = abs(x);
  // long long ans_a = 0;
  // long long ans_b = 0;
  // for(int i=0; pow(i, 5) <= 1e+9; i++){
  //   long long a = pow(i, 5);
  //   long long b = a - x_abs;

  //   vector<pair<ll, int>> vp = factrized(b);

  //   if(solve(vp)){
  //     ans_a = i;
  //     ans_b = vp[0].first;
  //   }
  // }

  // if(x < 0){
  //   swap(ans_a, ans_b);
  // }
  // cout << ans_a << " " << ans_b << endl;

  // cout << pow(ans_a, 5) - pow(ans_b,5) << endl;
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i=0; i<k; i++){
    int d;
    cin >> d;
    for (int j = 0; j<d; j++){
      int a;
      cin >> a;
      a--;
      v[a]++;
    }
  }

  int ans = 0;
  for(int i=0; i<n; i++){
    if(v[i] == 0)ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define M_PI           3.14159265358979323846
using namespace std;

int main()
{
    Start;
    int n,m,x,sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>x,sum+=x;
    if(sum>n)
        cout<<-1;
    else
        cout<<n-sum;




}






Measured memory_bytes: 3692
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    h, w = get_int_list()
    sr, sc = get_int_list()
    er, ec = get_int_list()

    d = [[-1] * (w+2) for _ in range(h+2)]

    for i in range(h):
        wk = get_string()
        for ii in range(w):
            if wk[ii] == ".":
                d[i+1][ii+1] = 10 ** 6

    d[sr][sc] = 0
    q = deque([])
    q2 = deque([])
    q.append([sr,sc])
    q2.append([sr,sc])

    def idou(i,ii,cnt_mahou):
        if 1 <= i <= h and 1 <= ii <= w:
            if d[i][ii] == 10 ** 6:
                q.append([i, ii])
                d[i][ii] = cnt_mahou


    ans = -1
    flg = True
    finish = False
    while flg:
        flg = False
        while q:
            wk = q.popleft()
            q2.append(wk)

            i = wk[0]
            ii = wk[1]
            cnt_mahou = d[i][ii]

            idou(i - 1, ii, cnt_mahou)
            idou(i + 1, ii, cnt_mahou)
            idou(i, ii - 1, cnt_mahou)
            idou(i, ii + 1, cnt_mahou)

            if d[er][ec] != 10 ** 6:
                ans = d[er][ec]
                finish = True
                break

        if finish:
            break

        while q2:
            wk = q2.popleft()
            i = wk[0]
            ii = wk[1]
            # 魔法を使う
            for wk in range(-2, 3):
                for wk2 in range(-2, 3):
                    if abs(wk) + abs(wk2) > 1:
                        flg = True
                        idou(i + wk, ii + wk2, cnt_mahou + 1)

    print(ans)

    #print(time.time() - start)


if __name__ == '__main__':
    main()

Measured memory_bytes: 109452
import math

def pf(n):
    ans=[1]
    i=2
    if(n%i==0):
        while(n%2==0):
            n = n/i
        ans.append(i)
    i+=1
    while(i<math.sqrt(n) and n!=1):
        if (n%i==0):
            while(n%i==0):
                n=n/i
            ans.append(i)
        i+=2
    if(n!=1):
        ans.append(n)
    return set(ans)

a,b = map(int,input().split())
pfa=pf(a)
a=0
for i in pfa:
    if(b%i==0):
        a+=1
print(a)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<map>

#define x first
#define y second

using namespace std;
typedef pair<int, int> P;
P hosi[220];
P hosi2[1010];
P shift;
bool flag;
int main(){
  int m, n;
  while(1){
    cin >> m;
    if(!m) break;
    for(int i = 0; i < m; i++){
      cin >> hosi[i].x >> hosi[i].y;
    }
    
    cin >> n;
    for(int i = 0; i < n; i++){
      cin >> hosi2[i].x >> hosi2[i].y;
    }
    
    sort(hosi, hosi + m);
    sort(hosi2, hosi2 + n);
    
    for(int i = 0; i < n; i++){
      flag = true;
      shift.x = hosi2[i].x - hosi[0].x;
      shift.y = hosi2[i].y - hosi[0].y;
      for(int j = 0; j < m; j++){
	if(!binary_search(hosi2, hosi2 + n, P(hosi[j].x + shift.x, hosi[j].y + shift.y))){
	  flag = false;
	  break;
	}
      }
      if(flag == true) break;
    }
    cout << shift.x << " " << shift.y << endl;
  }
}

Measured memory_bytes: 1172
#include <iostream>
#include<algorithm>
using namespace std;
const int maxn = 200005;
int main(void){
    int list[maxn] = {0};
    int number;
    int maxnum = -2000000000;
    int minnum;
    cin >> number;
    for(int i = 0;i < number;i++)
        cin >> list[i];
        minnum = list[0];
    for(int i = 1;i < number;i++){
            maxnum = max(maxnum ,list[i] - minnum);
            minnum = min(minnum ,list[i]);
    }

    cout << maxnum <<endl;
    return 0;

}


Measured memory_bytes: 3896
#include <iostream>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
using namespace std;
using ll = long long;

int memo[100100];
int rec(int n) {
    if (n == 0) return 0;

    if (memo[n] != -1) return memo[n];

    int res = n;

    for (int pow6 = 1; pow6 <= n; pow6 *= 6) {
        res = min(res, rec(n - pow6) + 1);
    }

    for (int pow9 = 1; pow9 <= n; pow9 *= 9) {
        res = min(res, rec(n - pow9) + 1);
    }

    return memo[n] = res;
}


int main() {
    int n; cin >> n;
    rep(i, 100100) memo[i] = -1;
    cout << rec(n) << endl;
}

Measured memory_bytes: 3712
// DFS     <-
// 桁 DP
// 包除が考えられる

// 7 5 3 が 1 つ以上含まれており, n >= x で

#include<bits/stdc++.h>
using namespace std;
#define int long long

void dfs(int cur, int n, int &ans){

    if(cur > n) return;
    bool flag3 = false;
    bool flag5 = false;
    bool flag7 = false;

    int num = cur;
    while(num > 0){
        if(num % 10 == 3) flag3 = true;
        if(num % 10 == 5) flag5 = true;
        if(num % 10 == 7) flag7 = true;
        num /= 10;
    }

    // 7 5 3 数なら ans をインクリメント
    if(flag3 && flag5 && flag7) ans++;

    cur *= 10;
    
    dfs(cur + 3, n, ans);
    dfs(cur + 5, n, ans);
    dfs(cur + 7, n, ans);
    return;
}

signed main(){

    int n; cin >> n;
    int ans = 0;
    dfs(0, n, ans);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	cout << fixed << setprecision(15);
	if(n & 1){
		ld n1 = n;
		cout << (ld)(((n1 + 1) / 2) / n1) << endl;
	}
	else cout << 0.5 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
k, s = map(int, input().split())

if k > s:
    k = s

ans = 0
for x in range(k+1):
    rem = s - x
    if rem > 2 * k:
        continue
    elif rem > k:
        ans += 2 * k - rem + 1
    else:
        ans += rem + 1

print(ans)

Measured memory_bytes: 64180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
#define pri 100000000007
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll a=0;
ll b[3000];
ll n;
ll f=0;
ll dp[3000][3000]={0};

ll ans(ll i,ll j)
  {
    if(dp[i][j]!=pri)return dp[i][j];
    if(i>j)
      return 0;
    else
    {
      if(a)
      { 
        if((j-i+1)%2==0)
           f=max(ans(i+1,j)+b[i],ans(i,j-1)+b[j]);
         else
          f=min(ans(i+1,j)-b[i],ans(i,j-1)-b[j]);
      }

      else
      {
        if((j-i+1)%2!=0)
           f=max(ans(i+1,j)+b[i],ans(i,j-1)+b[j]);
         else
          f=min(ans(i+1,j)-b[i],ans(i,j-1)-b[j]);
      }
return dp[i][j]=f;
  }
  }
         
   



int main()
{    
 

   #ifdef APNA_IO
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
   #endif
          ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    for(ll i=0;i<3000;i++){
      for(ll j=0;j<3000;j++){
        dp[i][j]=pri;
      }
    }
    cin>>n;
    
    

    if(n%2==0)
      a=1;

    for(ll i=0;i<n;i++)
    {
      cin>>b[i];
    }

    ans(0,n-1);

    cout<<f<<endl;



}

Measured memory_bytes: 73216
inxx = input()
inxx = inxx.split()

n = int(inxx[0])

inxx = input()
inxx = inxx.split()

arr = []
for x in inxx:
    arr.append(int(x))

import collections
cc = collections.Counter(arr)

def choose2(m):
    return (m*(m-1))//2

s = sum(choose2(x) for x in cc.values())

for x in arr:
    sol = s - cc[x] + 1
    print(sol)


Measured memory_bytes: 35472
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */
 
#include <iostream>
#include <fstream>
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;
 
int a[132456];
unordered_map<int,int>mp;
class CGCDOnBlackboard {
public:
    void solve(std::istream& in, std::ostream& out) {
        mp.clear();
        int N;
        in>>N;
        int t = 1;
        for(int i = 0; i < N; ++i){
            in>>a[i];
        }
        int res = 1;
        for(int i = 0; i < 2; ++i){
            int x = a[i];
            int t = 0;
            for(int j = 1; j * j <= x; ++j){
                if(x % j == 0){
                    t = 0;
                    for(int k = 0; k < N; ++k){
                        if(a[k] % j == 0)continue;
                        if(t == 2)break;
                        t ++;
                    }
                    if(t <= 1)res = max(res, j);
                    t = 0;
                    for(int k = 0; k < N; ++k){
                        if(a[k] % (x/j) == 0)continue;
                        if(t == 2)break;
                        t ++;
                    }
                    if(t <= 1)res = max(res, x/j);
                }
            }
        }
        // for(auto it = mp.begin(); it != mp.end(); ++it){
        //     if(it->second >= min(2, N-1))res = max(res, it->first);
        // }
        out<<res<<endl;
    }
};
 
 
int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    CGCDOnBlackboard solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

vector<vector<int>> X(3, vector<int>(3));

int solver(void){
    int flag = 0;
    REP(i, 3){
        if(X[i][0] == 1 and X[i][1] == 1 and X[i][2] == 1){
            flag = 1;
        }
        if(X[0][i] == 1 and X[1][i] == 1 and X[2][i] == 1){
            flag = 1;
        }
    }

    if(X[0][0] == 1 and X[1][1] == 1 and X[2][2]) flag = 1;
    if(X[0][2] == 1 and X[1][1] == 1 and X[2][0]) flag = 1;

    return flag;
}

int main() {
    vector<vector<int>> A(3, vector<int>(3));
    int N;
    vector<int> B;
    int flag = 0;

    REP(i, 3){
        REP(j, 3){
            cin >> A[i][j];
        }
    }

    cin >> N;

    REP(i, N){
        int b;
        cin >> b;

        B.push_back(b);

        REP(j, 3){
            REP(k, 3){
                if(A[j][k] == b){
                    X[j][k] = 1;
                    flag = solver();
                }
            }
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3512
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sqr(x) (x) * (x)
#define cube(x) (z) * (z) * (x)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
unordered_map<int, int> element_num; //change type if you need
template <class T>
void counter(T container) {
  for (int i = 0; i < container.size(); i++) {
    element_num[container[i]] += 1;
  }
}
signed main() {
  int n = in();
  vector<int> check(26, INF);
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  string temp;
  rep(i, n) {
    element_num = {};
    cin >> temp;
    counter(temp);
    rep(j, 26) {
      check[j] = min(check[j], element_num[alphabet[j]]);
    }
  }
  string ans = "";
  rep(i, 26) {
    if (check[i] != INF) {
      ans += string(check[i], alphabet[i]);
    }
  }
  cout << ans << endl;
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  vector<ll> f(8);
  ll x = 0;
  for(int i=0;i<n;i++){
    if(a.at(i) < 400 ) f.at(0) = 1;
    else if( a.at(i) < 800 ) f.at(1) = 1;
    else if( a.at(i) < 1200 ) f.at(2) = 1;
    else if( a.at(i) < 1600 ) f.at(3) = 1;
    else if( a.at(i) < 2000 ) f.at(4) = 1;
    else if( a.at(i) < 2400 ) f.at(5) = 1;
    else if( a.at(i) < 2800 ) f.at(6) = 1;
    else if( a.at(i) < 3200 ) f.at(7) = 1;
    else x++;
  }
  ll ans = 0;
  rep(i,8) ans += f.at(i);
  cout << max(ans,(ll)1) << " " << ans+x << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
  int n;
  scanf("%d",&n);
  while(1){
    scanf("%d",&n);
    if(n==0) break;

    int player[10]={};
    int ba=0;
    char c;
    int turn;
    for(int i=0;i<100;i++){
      turn=i%n;
      scanf(" %c",&c);

      if(c=='M') player[turn]++;
      else if(c=='S'){
	ba+=player[turn]+1;
	player[turn]=0;
      }else if(c=='L'){
	player[turn]+=ba+1;
	ba=0;
      }
    }
    
    sort(player,player+n);
    for(int i=0;i<n;i++) printf("%d ",player[i]);
    printf("%d\n",ba);
  }

  return 0;
}



Measured memory_bytes: 3248
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int h1, m1, h2, m2, k;cin>>h1>>m1>>h2>>m2>>k;
  cout<<(h2-h1)*60+(m2-m1)-k<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3640
def resolve():
	ans=0
	n,m=map(int,input().split())
	xyz=[list(map(int,input().split())) for i in range(n)]
	t=[(1,1,1),(1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)]
	for k in t:
		l=[k[0]*x+k[1]*y+k[2]*z for x,y,z in xyz ]
		l.sort(reverse=True)
		ans=max(ans,sum(l[:m]))
	print(ans)

resolve()

Measured memory_bytes: 39792
#include<stdio.h>
#include<string.h>
int main(void){
  int n,k,i,j,sum=0,tmp;
  scanf("%d %d",&n,&k);
  int toy[n];
  for(i=0;i<n;i++){
    scanf("%d",&toy[i]);
  }
  for(i=0;i<n;i++){
    for(j=i;j<n;j++){
      if(toy[i]<toy[j]){
        tmp=toy[j];
        toy[j]=toy[i];
        toy[i]=tmp;
      }
    }
  }
  for(i=0;i<k;i++){
    sum+=toy[i];
  }
  printf("%d ",sum);
  return 0;
}

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

int main(){
    int n, k; cin >> n >> k;
    vector<bool> d(10, false);
    for (auto i = 0; i < k; i++) { int a; cin >> a; d[a] = true; }
    for (auto i = n; i < 100000; i++) {
        int tmp = i;
        while(tmp > 0) {
            if(d[tmp % 10]) break;
            tmp /= 10;
        }
        if(tmp == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 mut $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")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::io::{Write, BufWriter, stdout};
use std::iter::FromIterator;
const MOD: usize = 1000_000_007;
fn main() {
    input! {
        N: usize,
        S1: chars,
        S2: chars,
    }

    let mut ind = 0;
    let mut prev = Prev::No;
    let mut sum = 1;
    while ind < N {
        if S1[ind] == S2[ind] {
            match prev {
                Prev::No => sum = (sum * 3) % MOD,
                Prev::Tate => sum = (sum * 2) % MOD,
                Prev::Yoko => sum = (sum * 1) % MOD,
            }
            prev = Prev::Tate;
        } else {
            match prev {
                Prev::No => sum = (sum * 6) % MOD,
                Prev::Tate => sum = (sum * 2) % MOD,
                Prev::Yoko => sum = (sum * 3) % MOD,
            }
            prev = Prev::Yoko;
            ind += 1;
        }
        ind += 1;
    }
    println!("{}", sum);
}

enum Prev {
    No,
    Tate,
    Yoko,
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int x[4];
    int y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    int dx = x[1] - x[0];
    int dy = y[1] - y[0];
    cout << x[1]-dy << " " << y[1]+dx << " ";
    cout << x[0]-dy << " " << y[0]+dx << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
    int n; cin  >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int max = a[0];
    ll sum = 0;
    for(int i = 1;i < n;i++){
        if(max>a[i]){
            sum += max-a[i];
        }else max = a[i];
    }
    cout << sum << endl;
    
}

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

int main() {
    int c1,c5,c10,c50,c100,c500;
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;

    if (
        (c1 * 1) +
        (c5 * 5) +
        (c10 * 10) +
        (c50 * 50) +
        (c100 * 100) +
        (c500 * 500)
        >= 1000
    ) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}



Measured memory_bytes: 3096
"use strict";

const genPatten = function (n) {
    let ret = []
    const helper = function (sub) {
        if (sub.length == n) {
            ret.push([...sub])
            return
        }
        helper([...sub, true])
        helper([...sub, false])
    }
    helper([])
    return ret
}

const main = arg => {
    const input = arg.trim().split("\n");

    const [n, m, x] = input[0].split(" ").map(i => parseInt(i))
    let mat = []
    let costs = []
    for (let i = 1; i <= n; i++) {
        let tmp = input[i].split(" ").map(i => parseInt(i))
        costs[i - 1] = tmp.shift()
        mat.push(tmp)   // [Ci, A(i,1), A(i,2),,,A(i, m)]
    }
    let pats = genPatten(n)
    
    let fee = Number.POSITIVE_INFINITY
    for (let pat of pats) {
        let tmp = 0
        let level = new Array(m).fill(0)
        for (let i = 0; i < n; i++) {
            if (pat[i]) {
                tmp = tmp + costs[i]
                for (let j = 0; j < m; j++) {
                    level[j] = level[j] + mat[i][j]
                }
            }
        }
        if (level.every(el => el >= x)) {
            fee = Math.min(fee, tmp)
        }
    }
    if (fee == Number.POSITIVE_INFINITY) console.log(-1)
    else console.log(fee)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 35680
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let c: i64 = sc.cin();

    let mut goal = max!(a, b, c);
    while (goal * 3 - (a + b + c)) % 2 != 0 {
        goal += 1;
    }
    put!((goal * 3 - (a + b + c)) / 2);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！


int main(){
    int n,k;
    std::cin >> n>>k;
    VEC(int,a,n);
    sort(all(a));
    int ans=INF;
    rep(i,n-k+1){
        chmin(ans,a[i+k-1]-a[i]);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, a[15], x, y, ans = 0, b[15] = {};
  vector<pair<int, int> > p[15];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    for (int j = 0; j < a[i]; j++) {
      scanf("%d%d", &x, &y);
      x--;
      p[i].push_back({x, y});
    }
  }
  for (int i = 0; i < (1 << n); i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        b[j] = 1;
        flag++;
      } else {
        b[j] = 0;
      }
    }
    for (int j = 0; j < n; j++) {
      if (b[j]) {
        for (int k = 0; k < a[j]; k++) {
          if (b[p[j][k].first] != p[j][k].second) {
            flag = 0;
            break;
          }
        }
      }
    }
    if (flag) {
      ans = max(ans, flag);
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
using namespace std;
int main() {
	int H, W;
	while(true) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
				break;
		}
		for (int i=0; i < H; i++) {
			for (int j=0; j < W; j++) {
				printf("%c", '#');
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
int maxn;
int mak[100005];
LL fac[100005]={1,1};
LL opp[100005]={1,1};
LL op_fa[100005]={1,1}; 
void init()
{
    for(int i=2; i<=100000+3; ++i)
    {
        fac[i] = fac[i-1]*i%mod;
        opp[i] = (mod-mod/i)*opp[mod%i]%mod;
        op_fa[i] = op_fa[i-1]*opp[i]%mod;
    }
}
LL c(LL n, LL m)
{
    return fac[n]*op_fa[n-m]%mod*op_fa[m]%mod;
}
int main()
{
	init();
	int n,dist;
	scanf("%d",&n);
	for(int i=1;i<=n+1;i++)
	{
		int temp;
		scanf("%d",&temp);
		if(mak[temp]) 
			dist = mak[temp] + n - i;	
		mak[temp] = i;
	}	
	long long ans;
	for(int i=1;i<=n+1;i++)
	{
		ans = c((long long)(n+1), (long long)(i))%mod;
		if(dist>=i-1)
		{
			ans= (ans - c((long long)dist, (long long)(i-1)) + mod)%mod;
		}
		printf("%lld\n",ans);	
	}
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e4+20;
const int mod=998244353;

int n,m;

int f[maxn][maxn],jc[maxn],jcn[maxn],inv[maxn];

inline void init()
{
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,1e4)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
	char A[maxn],B[maxn];
	scanf("%s",A+1);
	int len=strlen(A+1);
	scanf("%s",B+1);
	REP(i,1,len)if(A[i]=='1')
	{
		if(B[i]=='1')n++;
		else m++;
	}
}

inline void doing()
{
	f[0][0]=1;
	REP(i,0,n)REP(j,0,m)
	{
		if(i)
		{
			//f[i][j]=(f[i][j]+(ll)f[i-1][j]*i)%mod;
			if(j)f[i][j]=(f[i][j]+(ll)f[i-1][j]*i*j)%mod;
		}
		if(j)f[i][j]=(f[i][j]+(ll)f[i][j-1]*j*j)%mod;
	}
	int ans=0;
	REP(i,0,n)
	{
		ans=(ans+(ll)jc[n]*jcn[i]%mod*jcn[n-i]%mod*jc[i]%mod*jc[i]%mod*jc[n+m]%mod*jcn[i]%mod*jcn[n+m-i]%mod*f[n-i][m])%mod;
	}
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 389760
#define N_MAX 10000
 
int main(void){
 
  int a[N_MAX]={0},n,i,j,work;
  double sum;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
   
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      if(a[j]>a[j+1]){
    work = a[j];
    a[j] = a[j+1];
    a[j+1] = work;
      }
    }
  }
   
  printf("%d %d %.0f\n",a[0],a[n-1],sum);
 
  return 0;
}

Measured memory_bytes: 680
#include <iostream>

using namespace std;

int main()
{
    int w, h, n, a, b, c, d;
    cin>>w>>h>>n;
    a = 0, b = w, c = 0, d = h;
    while( n-- )
    {
        int x, y, m;
        cin>>x>>y>>m;
        if( m == 1 ) a = max( a, x );
        if( m == 2 ) b = min( b, x );
        if( m == 3 ) c = max( c, y );
        if( m == 4 ) d = min( d, y );
    }
    w = (b-a<0?0:b-a);
    h = (d-c<0?0:d-c);
    cout<<w*h<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        for(int i = 0; i < N-1;i++){
            long B = sc.nextLong();
            long a = A;
            long b = B;
            while(a%b != 0){
                long tmp = a;
                a = b;
                b = tmp%b;
            }
            A = A/b*B;
        }
        System.out.println(A);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  if(a[0] != 0){
    cout << -1;
    return 0;
  }
  ll ans = 0;
  rep(i,n){
    if(i+1 != n){
      if(a[i]+1 == a[i+1]) continue;
      if(a[i]+2 <= a[i+1]){
        cout << -1;
        return 0;
      }
    }
    ans += a[i];
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3972