akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int main() {
  int n, k;
  cin >> n >> k;
  int ans = (n % k == 0 ? 0 : 1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                long A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
                if (A*B*C%2==0) {
                        System.out.println(0);
                } else {
                        System.out.println(Math.min(A*B,Math.min(B*C,A*C)));
                }
        }
}

Measured memory_bytes: 9556
package main

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

type tree []int

func (uft *tree) init(n int) {
	*uft = make([]int, n)
	for i := 0; i < n; i++ {
		(*uft)[i] = i
	}
}
func (uft *tree) find(x int) int {
	if x == (*uft)[x] {
		return x
	}
	(*uft)[x] = uft.find((*uft)[x]) // 経路圧縮あり
	return (*uft)[x]
}
func (uft *tree) same(x, y int) bool {
	return uft.find(x) == uft.find(y)
}
func (uft *tree) unite(x, y int) {
	x = uft.find(x)
	y = uft.find(y)
	if x == y {
		return
	}
	(*uft)[x] = y
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	K := nextInt(sc)
	L := nextInt(sc)
	var roadconn, railconn tree
	roadconn.init(N)
	railconn.init(N)
	for i := 0; i < K; i++ {
		p, q := nextInt(sc), nextInt(sc)
		p--
		q--
		roadconn.unite(p, q)
	}
	for i := 0; i < L; i++ {
		r, s := nextInt(sc), nextInt(sc)
		r--
		s--
		railconn.unite(r, s)
	}
	/*
		fmt.Println("N", N, "K", K, "L", L)
		fmt.Println("roadconn:")
		fmt.Println(roadconn)
		fmt.Println("railconn:")
		fmt.Println(railconn)
	*/
	ans := make(map[int]map[int]int)
	for i := 0; i < N; i++ { // 全ての都市について調べる
		x := roadconn.find(i) // 都市iの道路グループラベル(UnionFind木の根)
		y := railconn.find(i) // 都市iの鉄道グループラベル(UnionFind木の根)
		if ans[x] == nil {
			ans[x] = make(map[int]int)
		}
		ans[x][y]++ // 道路グループxと鉄道グループyを使ってたどり着ける都市のペアの数
	}
	wtr := bufio.NewWriter(os.Stdout)
	// fmt.Fprintln(wtr, ans)
	for i := 0; i < N; i++ {
		x := roadconn.find(i)
		y := railconn.find(i)
		fmt.Fprintf(wtr, "%d ", ans[x][y])
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 50944
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c == 17 && a*b*c == 175) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int digitsum(int x){
  int sum=0;
  while(x>0){
    sum+=(x%10);
    x/=10;
  }
  return sum;
}

int main() {
  ll n,x,m;
  cin>>n>>x>>m;
  set<int> memo;
  vector<int> p;
  ll now=x;
  int a,b;
  bool check=false;
  for(int i=0;i<n;i++){
    if(i==0){
      p.push_back(x);
      memo.insert(x);
      continue;
    }
    now=mod(now*now,m);
    if(memo.count(now)){
      check=true;
      for(int j=0;j<p.size();j++){
        if(p[j]==now){
          a=j;
          b=i-1;
        }
      }
      break;
    }
    else{
      p.push_back(now);
      memo.insert(now);
    }
  }
  if(!check){
    ll ans=0;
    for(int i=0;i<p.size();i++){
      ans+=p[i];
    }
    cout<<ans<<endl;
    return 0;
  }
  ll ans=0;
  for(int i=0;i<a;i++){
    ans+=p[i];
  }
  ll temp=0;
  for(int i=a;i<=b;i++){
    temp+=p[i];
  }
  ll shuuki=b-a+1,kuri=(n-a)/shuuki,amari=(n-a)%shuuki;
  for(int i=0;i<amari;i++){
    ans+=p[a+i];
  }
  ans+=temp*kuri;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5900
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,0);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};

int main()
{
  int n,m; cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int res = 0;
  rep(i,m) {
    UFT uf(n);
    rep(j,m) {
      if(i == j) continue;
      uf.unite(a[j], b[j]);
    }
    bool f = true;
    rep(j,n) {
      if( !uf.same(0, j) ) f = false;
    }
    if(f) res++;
  }
  cout << m - res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;

int line;
vector<string> S;
enum Operator { add, mul };

int cnt(string s){
    int ret=0;
    for(auto c:s){
        if(c=='.') ret++;
        else break;
    }
    return ret;
}

int dfs(int depth){
    string s=S[line];
    if(isdigit(s[depth])){
        return s[depth]-'0';
    }else{
        int ret;
        if(s[depth]=='+'){
            ret=0;
            while(line+1<S.size()&&cnt(S[line+1])==depth+1){
                line++;
                ret+=dfs(depth+1);
            }
        }else if(s[depth]=='*'){
            ret=1;
            while(line+1<S.size()&&cnt(S[line+1])==depth+1){
                line++;
                ret*=dfs(depth+1);
            }
        }else{
            cout<<"error"<<endl;
            exit(1);
        }
        return ret;
    }
}

int main(){
    int n;
    while(cin>>n,n){
        S.clear();
        line=0;
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            S.push_back(s);
        }
        cout<<dfs(0)<<endl;
    }

    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

map<int, int> prime_factors(int n) {
    map<int, int> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(int i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

signed main(){
    int n, p;
    cin >> n >> p;
    int ans = 1;
    map<int, int> res = prime_factors(p);
    for(map<int,int>::iterator it = res.begin(), end=res.end(); it != end; ++it) {
        if(it->second>=n) {
            ans*= pow(it->first, it->second/n);
            //cout << it->first << " " <<it->second << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d %d", &x, &y, &z);
	ans = x + y + z;
	n = max(x, max(y, z));
	ans += (n * 9);


	printf("%d\n", ans);


	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int i,j,N,p[10],f,a;
	char c[100];
	
	while(1){
		scanf("%d",&N);
		if(N==0){
			break;
		}
		
		f = 0;
		for(i=0;i<N;i++){
			p[i]=0;
		}
		
		scanf("%*c");
		for(i=0;i<100;i++){
			scanf("%c",&c[i]);
			j=i%N;
			if(c[i]=='M'){
				p[j]++;
			}else if(c[i]=='S'){
				f+=p[j]+1;
				p[j]=0;
			}else if(c[i]=='L'){
				p[j]+=f+1;
				f=0;
			}
		}
		scanf("%*c");
		for(i=0;i<N;i++){
			for(j=i+1;j<N;j++){
				if(p[i]>p[j]){
					a=p[i];
					p[i]=p[j];
					p[j]=a;
				}
			}
		}
		for(i=0;i<N;i++){
			if(i!=0){
				printf(" ");
			}
			printf("%d",p[i]);
		}printf(" %d\n",f);
	}
return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if(S == U) A--;
  if(T == U) B--;
  cout << A << " " << B << endl;
  return 0;
}


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

const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)

#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void solve(long long A, long long B, long long C) {
  // main coding
  cout<<max(0LL,C-(A-B))<<endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


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

num_list=[0]*n
for i in range(n):
    num_list[a[i]-1]+=1

sm_all=0
for i in range(n):
    k=num_list[i]
    sm_all+=(k*(k-1))//2

for i in range(n):
    print(sm_all-(num_list[a[i]-1]-1))

Measured memory_bytes: 26268
N = int(input())
L = list(range(1, 2*N+1))
print("?", " ".join(map(str, L[:N])))
color_init = input()
rev = {"Red": "Blue", "Blue": "Red"}
col_t = 0
col_f = N
while col_t + 1 < col_f:
    c = (col_t+col_f)//2
    print("?", " ".join(map(str, L[c:c+N])))
    color = input()
    if color == color_init:
        col_t = c
    else:
        col_f = c
Ans = ["_"] * (2*N)
Ans[col_t] = color_init[0]
Ans[col_t+N] = rev[color_init][0]
E1 = list(range(col_t+1, col_t+N))
E2 = [i for i in range(2*N) if i not in E1 and i != col_t and i != col_t+N]
assert len(E2) == len(E1)
for i in range(2*N):
    if Ans[i] != "_":
        continue
    if i not in E1:
        E = E1
    else:
        E = E2
    print("?", i+1, " ".join([str(i+1) for i in E]))
    Ans[i] = input()[0]

print("!", "".join(Ans))


Measured memory_bytes: 3904
import numpy as np

H, W, K = [int(i) for i in input().split()]
A = np.zeros([H, W], dtype=bool)
for i in range(H):
    A[i] = np.array([False if i=="." else True for i in input()])

T = A.sum()
T_row = A.sum(1)
T_col = A.sum(0)

def calc(I, J):
    return T - T_row[I].sum() - T_col[J].sum() + A[I][:,J].sum()

def repr(i, W):
    s = np.binary_repr(i, width=W)[::-1]
    return [i for i, j in enumerate(s) if j == "1"]

count = 0
for i in range(2**H-1):
    for j in range(2**W-1):
        row = repr(i, H)
        col = repr(j, W)
        if calc(row, col) == K:
            count += 1

print(count)

Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n, m; scanf("%d%d", &n, &m);
	printf("%d\n", n*(n-1)/2 + m*(m-1)/2);
}


Measured memory_bytes: 256
n,m=map(int,input().split())
l1=[]
ln=[]

for i in range(m):
    ai,bi=map(int,input().split())
    if ai==1:
        l1.append(bi)
    if bi==n:
        ln.append(ai)
    

if len(set(l1) & set(ln))==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

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

//諸機能
#pragma region MACRO 
#define putans(x)  cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define input ifs >>
#else //いい感じにやる
#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

char alphabet[26] =
{ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

int main() {
	string s; input s;
	char tyumoku = 'a' - 'a';
	int ruiseki[100000 + 1];
	int pp = 0;
	rep(i, 26) {
		tyumoku = alphabet[i] - 'a';
		ruiseki[0] = 0;
		rep(j, s.length()) {
			if (alphabet[tyumoku] == s[j]) {
				pp++;
			}
			ruiseki[j+1] = pp;
		}
		REP(k, 2, 4) {

			rep(j, s.length() - k+1) {
				//if (alphabet[tyumoku] == 'e') {
				//	cout << "e" << endl;	
				//	cout << k << endl;
				//	int unti = 0;
				//}
				int m = ruiseki[k + j] - ruiseki[j];
				dbg3(ruiseki[k + j], ruiseki[j],m);
				if (2 * m > k) {
					putans(to_string(j+1) + " " + to_string(k + j));
					return 0;
				}
			}
		}
		pp = 0;
	}
	putans("-1 -1");
	return 0;
}

//C
//int n; input n;
//int a[100];
//rep(i, n) input a[i];
//ll mn = INF;

//REP(i,-100 ,101) {
//	ll tmp = 0;
//	rep(j, n) {
//		tmp += ( i - a[j] )*( i - a[j] );
//	}
//	mn = min(tmp, mn);
//}
//putans(mn);
//B
//
//string s; input s;
//	int seek = 0;
//	vector<char> ans;
//	rep(i, s.length()) {
//		if(s[i] != 'B'){
//			seek++; 
//			ans.push_back(s[i]);
//		}
//		else {
//			if (seek != 0) {
//				ans.erase(ans.begin() + seek-1);
//				seek--;
//			}
//		}
//	}
//	rep(i, ans.size()) {
//		cout << ans[i];
//	}
//	cout << endl;

Measured memory_bytes: 896
#include <stdio.h>
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	int w, a, b;
	scanf("%d%d%d", &w, &a, &b);
	printf("%d\n", a + w <= b ? b - a - w : max(0, a - b - w));
	return 0;
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if ( (0 <= x-r && x+r <= W) && (0 <= y-r && y+r <= H) )
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3112
using System;

class Atcoder60
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]);
        int t = int.Parse(input[1]);

        if (x >= t)
            Console.WriteLine(x - t);
        else
            Console.WriteLine("0");
    }
}

Measured memory_bytes: 11092
// vim: ts=2 sw=2 sts=2
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, p, w, g, y;
  p = w = g = y = 0;

  cin >> n;
  for(int i = 0; i <= n; i++){
    string ar;
    cin >> ar;
  if (ar == "P")
    p = 1;
  if (ar == "W")
    w = 1;
  if (ar == "G")
    g = 1;
  if (ar == "Y")
    y = 1;
  }

  if (p + w + g + y == 3) {
    cout << "Three" << endl;
  } else {
    cout << "Four"  << endl;
  }
}


Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;


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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    vector<ll> v(n);
    vector<ll> w(n);
    rep(i,n) cin>>v[i];
    rep(i,n) cin>>w[i];
    rep(i,n){
        sum=0;
        for(ll j=0;j<=i;j++){
            sum+=v[j];
        }
        for(ll j=i;j<n;j++){
            sum+=w[j];
        }
        //cout<<sum<<endl;
        maxi=max(maxi,sum);
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod ((int)1e9+7)
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)2e5+5;

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

    int k,n;
    cin>>k>>n;
    vector<int> a(n*2);
    for(int i=0;i<n;i++) {
        cin>>a[i];
        a[n+i] = a[i]+k;
    }
    int ans = 1e7;
    for(int i=0;i<n;i++) {
        ans = min(ans,a[i+n-1]-a[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	long long int ans=0;
	scanf("%d %d", &n, &k);
	
	for(int b=k+1; b<=n; b++){
		for(int x=0; x<=((n-k)/b); x++){
			if(x==0 && k==0 && n-b*x<=b-1){
				ans=ans+n-k;
			}else if(x==0 && k==0 && n-b*x>b-1){
				ans=ans+b-1;
			}else if(n-b*x<=b-1){
				ans=ans+n-k-b*x+1;
			}else{
				ans=ans+b-k;

			}
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 128
Q = 10**9+7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

B, W = map( int, input().split())
Z = getInv(B+W)
I = [1]*(B+W+1)
for i in range(1,B+W+1):
    I[i] = (I[i-1]*Z[i])%Q

F = [1]*(B+W+1)
for i in range(1,B+W+1):
    F[i] = F[i-1]*i%Q
w = 0
b = 0
for i in range(1,B+W+1):
    if i - 1 < B and i - 1 < W:
        print(I[2])
    elif i - 1 == W and i - 1< B:
        w = pow(I[2],i-1,Q)
        print(((1 -  w)%Q*I[2]%Q + w)%Q)
    elif i - 1 >= W and i - 1< B: #i > B
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        print(((1 -  w)%Q*I[2]%Q + w)%Q)
    elif i - 1 == B and i - 1 < W:
        b = pow(I[2],i-1,Q)
        print((1-b)%Q*I[2]%Q)
    elif i - 1 >= B and i - 1 < W: #i > W
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print((1-b)%Q*I[2]%Q)
    elif i - 1 == B and i - 1 == W:
        w = pow(I[2],i-1,Q)
        b = pow(I[2],i-1,Q)
        print(((1 -  w - b)%Q*I[2]%Q + w)%Q)
    else:
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print(((1 -  w - b)%Q*I[2]%Q + w)%Q)


Measured memory_bytes: 28912
import java.util.Scanner;

public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		input();
		solve();
	}

	static int n,m,a[][],b[],c[];
	private static void input(){
		n=s.nextInt();
		m=s.nextInt();
		a=new int[n][m];
		b=new int[m];
		c=new int[n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=s.nextInt();
			}
		}
			for(int j=0;j<m;j++) {
				b[j]=s.nextInt();
			}
	}
	private static void solve(){
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				c[i]+=a[i][j]*b[j];
			}
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 40836
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m;){
		vector<pair<int,int> > ps(n);
		for(int i=0;i<n;i++) cin>>ps[i].first>>ps[i].second;
		
		vector<int> xs,ys;
		for(int i=0;i<n;i++){
			xs.push_back(ps[i].first);
			ys.push_back(ps[i].second);
		}
		sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
		sort(ys.begin(),ys.end()); ys.erase(unique(ys.begin(),ys.end()),ys.end());
		for(int i=0;i<n;i++)
			ps[i]=make_pair(lower_bound(xs.begin(),xs.end(),ps[i].first)-xs.begin(),
							lower_bound(ys.begin(),ys.end(),ps[i].second)-ys.begin());
		
		vector<vector<int> > grid(ys.size(),vector<int>(xs.size()));
		for(int i=0;i<n;i++)
			grid[ps[i].second][ps[i].first]++;
		vector<vector<int> > sum(ys.size()+1,vector<int>(xs.size()+1));
		for(int i=0;i<ys.size();i++) for(int j=0;j<xs.size();j++)
			sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+grid[i][j];
		
		for(int i=0;i<m;i++){
			int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
			x1=lower_bound(xs.begin(),xs.end(),x1)-xs.begin();
			y1=lower_bound(ys.begin(),ys.end(),y1)-ys.begin();
			x2=upper_bound(xs.begin(),xs.end(),x2)-xs.begin();
			y2=upper_bound(ys.begin(),ys.end(),y2)-ys.begin();
			cout<<sum[y2][x2]-sum[y1][x2]-sum[y2][x1]+sum[y1][x1]<<endl;
		}
	}
}

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

long long p(long long a,long long b,long long c){
    return max(max(abs(a-b),abs(a-c)),abs(b-c));
}

int main(void){
    long long h,w;
    cin>>h>>w;
    if(h%3==0||w%3==0){
        cout<<0<<endl;
    }else{
        long long l=min(h,w);
        for(long long i=1;i<h;i++){
            l=min(l,p(w*(h-i),i*(w-w/2),i*(w/2)));
        }
        for(long long i=1;i<w;i++){
            l=min(l,p(h*(w-i),i*(h-h/2),i*(h/2)));
        }
        cout<<l<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll n, x;
	cin >> n >> x;
	vll w(n), v(n);
	rep(i, n) cin >> w[i] >> v[i];

	vector<vll> dp(n+1, vll(x+1));
	rep(i, n) rep1(j, x) {
		dp[i+1][j] = dp[i][j];
		if(j - w[i] >= 0) chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
	}
	cout << dp[n][x] << endl;
}


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

int main(){
  string s;
  cin >> s;
  int slen = s.size();
  if (s[slen-1]=='1'||s[0]=='0'){
    cout << -1 << endl;
    return 0;
  }
  for (int i=0; i<slen-1; i++){
    if (s[i] != s[slen-2-i]){
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> lis;
  for (int i=0; i<slen-1; i++){
    if (s[i]=='1'){
      for (auto k: lis){
        cout << i+1 << ' ' << k << endl;
      }
      lis.clear();
      lis.push_back(i+1);
    }
    else lis.push_back(i+1);
  }
  cout << slen-1 << ' ' << slen << endl;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,k,m;
string s,t;

int main() {
  cin >> n ;
  pair<int,int> p[n]; int a,b;
  rep(i,n){
    cin >> a >> b;  p[i]={b,a};
  } 
  sort(p,p+n); int t=0;
  rep(i,n){
    if(t+p[i].second<=p[i].first) t+=p[i].second;
    else{
      cout << "No" << endl; 
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

#define EPS 1e-10
//ここから編集

struct Mo
{
  vector<int> left, right, order;
  vector<bool> v;
  int width;
  int nl, nr, ptr;

  Mo(int n, int q) : width(sqrt(n)), nl(0), nr(0), ptr(0), v(n), left(q), right(q){}

  void insert(int l, int r)
  {
    left[ptr] = l;
    right[ptr] = r;
    ptr++;
  }

  void build()
  {
    ptr =  0;
    order.resize(left.size());
    iota(all(order), 0);
    sort(all(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      else{
        if ((left[a] / width) % 2 == 0) return right[a] < right[b];
        else return right[a] > right[b];
      }
    });
  }

  inline int process()
  {
    const auto id = order[ptr];
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return order[ptr++];
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx])add(idx);
    else del(idx);
  }

  inline void add(int idx);

  inline void del(int idx);
};

int N, A[501010], Q;
int ans[501010];
int cnt[1010101], sum;

inline void Mo::add(int idx)
{
  if(cnt[A[idx]]++ == 0) ++ sum;
}

inline void Mo::del(int idx) 
{
  if(--cnt[A[idx]] == 0) --sum;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  scanf("%d %d", &N, &Q);
  for(int i=0; i<N; i++) scanf("%d", &A[i]);

  Mo mo(N,Q);
  for(int i=0; i<Q; i++){
    int a, b; scanf("%d %d", &a, &b);
    mo.insert(--a, b);
  }

  mo.build();
  for(int i=0; i<Q; i++){
    int idx = mo.process();
    ans[idx] = sum;
  }
  for(int i=0; i<Q; i++){
    printf("%d\n", ans[i]);
  }
  return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define re register
#define il inline
#define inf 0x3f3f3f

#define maxn 1000005

int n, pos, ans, head, tail;
int q[maxn];
char s[maxn], t[maxn];

int main() {
  scanf("%d%s%s", &n, s + 1, t + 1);
  if (strcmp(s + 1, t + 1) == 0) {
    putchar('0');
    return 0;
  }
  pos = n;
  head = 1;
  tail = 0;
  for (int i = n; i >= 1; i--) {
    if (t[i] == t[i - 1])
      continue;
    pos = min(pos, i);
    while (pos && t[i] != s[pos])
      pos--;
    if (pos == 0) {
      putchar('-');
      putchar('1');
      return 0;
    }
    while (head <= tail) {
      if (q[head] - (tail - head + 1) + 1 > i)
        head++;
      else
        break;
    }
    q[++tail] = pos;
    if (i != pos)
      ans = max(ans, tail - head + 1);
  }
  printf("%d\n", ans + 1);
  return 0;
}


Measured memory_bytes: 6144
from typing import Collection


def multply(nums: Collection[int]) -> int:
    if 0 in nums:
        return 0

    result = 1

    for i in nums:
        result *= i
        if result > 10**18:
            return -1

    return result

count_num = int(input())
nums = map(int, input().split())
print(multply(list(nums)))


Measured memory_bytes: 23772
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll q = n/(a+b);
    ll m = n%(a+b);
    if(a==0) {
        cout << 0 << endl;
        return 0;
    }
    ll r = m;
    if(m>=a) {
        r = a;
    }
    cout << q*a+r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n, q;
    cin >> n >> q;
    int a[n], b[n];
    ll black = (ll)(n - 2) * (n - 2);
    rep(i, n) a[i] = b[i] = n - 1;
    int h = n - 1, w = n - 1;
    while(q--){
        int t, x;
        cin >> t >> x;
        t--; x--;
        if(t == 1){
            if(x < w){
                for (int i = x; i < w; i++){
                    b[i] = h;
                }
                w = x;
            }
            black -= b[x] - 1;
        }else{
            if(x < h){
                for (int i = x; i < h; i++){
                    a[i] = w;
                }
                h = x;
            }
            black -= a[x] - 1;
        }
    }
    cout << black << endl;
}

Measured memory_bytes: 5184
#include <iostream>
#include <sstream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <queue>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ul;
typedef pair<int,int> P;
#define X first
#define Y second

void go() {
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	// int t; cin >> t; for(;t--;)
	go();
	return 0;
}



Measured memory_bytes: 256
N, X, M = map(int, input().split())
checklist = [True] * 100000
ind = 0
l = [X]
while True:
  t = l[-1] ** 2 % M
  if checklist[t]:
    l.append(t)
    checklist[t] = False
  else:
    ind = l.index(t)
    break
S = sum(l[ind:])
L = len(l)
ans = 0
if N <= L:
  ans = sum(l[:N])
else:
  ans = sum(l)
  N -= L
  ans += S * (N // (L - ind))
  ans += sum(l[ind:ind+(N % (L - ind))])
print(ans)

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

template<typename T> struct UnionFind {
  vector<int> par, rank;
  vector<T> wSum;

  UnionFind(int n = 1, T init = 0)
      : par(n), rank(n, 0), wSum(n, init) {
    iota(begin(par), end(par), 0);
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      wSum[x] += wSum[par[x]];
      return par[x] = r;
    }
  }
  T weight(int x) {
    root(x);
    return wSum[x];
  }
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y, T w = 0) {
    w += weight(x) - weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank[x] < rank[y]) swap(x, y), w = negate<T>()(w);
    rank[x] += rank[y];
    par[y] = x;
    wSum[y] = w;
  }
  T getDiff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int main() {
  int N, M; cin >> N >> M;
  int cnt = 0;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
    --p[i];
  }
  UnionFind<int> uf(N);
  // vector<int> x(M), y(M);
  for (int i = 0; i < M; ++i) {
    // cin >> x[i] >> y[i];
    int x, y; cin >> x >> y;
    --x; --y;
    uf.unite(x, y);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += (i == p[i]) ? 1 : uf.isSame(i, p[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
x,k,d = gets.chomp.split(" ").map(&:to_i)
x = -x if x < 0
num = x / d
if k <= num
  puts x - k*d
else
  cnt = k - num
  dis = x - num*d
  cnt = cnt % 2
  if cnt == 1
    dis = dis - d
  end
  puts dis.abs
end


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> vec(H * W);
  for (int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  for (int k = 0; k < H; k++){
  cout << "#";
  for (int j = k * W; j < (k + 1) * W; j++){
    cin >> vec.at(j);
    cout << vec.at(j);
  }
  cout << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++){
    cout << "#";
  }
}

Measured memory_bytes: 256
from collections import deque

def bfs():
  queue = deque([[0, 0]])
  visited[0][0] = 0
  while queue:
    y, x = queue.popleft()
    if [y, x] == [h-1, w-1]:
      return visited[y][x]

    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_y, new_x = y+j, x+k
      if not (0 <= new_y < h) or not (0 <= new_x < w):
        continue

      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
        visited[new_y][new_x] = visited[y][x] + 1
        queue.append([new_y, new_x])

h,w = map(int, input().split())

maze=[]
w_space=0
for _ in range(h):
  t=input()
  maze.append(t)
  w_space += t.count(".")
visited = [[-1]*w for _ in range(h)]

ans = bfs()
if ans and ans != -1:
  print(w_space - ans - 1)
else:
  print(-1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define INF (int)1e8
#define EPS 1e-9

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int N, K;
  cin >> N >> K;
  vi l(N);
  rep(i, N) cin >> l[i];

  int res = 0;
  sort(all(l), greater<int>());
  rep(i, K) res += l[i];

  cout << res << endl;
}

Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
  bool operator<(const Card& rhs) { return rank < rhs.rank; }
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (unsigned int i = 0u; i < n; ++i) {
    std::cout << sep << cards[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (unsigned int j = 0u; j < n-1; ++j) {
    for (unsigned int i = n-1; i > j; --i) {
      if (cards[i] < cards[i-1]) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (unsigned int i = 0u; i < n-1; ++i) {
    unsigned int min_j = i;
    for (unsigned int j = i+1; j < n; ++j) {
      if (cards[j] < cards[min_j]) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (unsigned int i = 0u; i < n; ++i) {
    std::cin >> cards1[i];
  }
  //std::memcpy(cards2, cards1, sizeof(cards1));
  for (unsigned int i = 0u; i < n; ++i) {
    cards2[i] = cards1[i];
  }

  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);
  /*
  if (std::memcmp(cards1, cards2, sizeof(cards1)) == 0) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
  */
  for (unsigned int i = 0u; i < n; ++i) {
    if (!(cards2[i].rank == cards1[i].rank &&
          cards2[i].suit == cards1[i].suit)) {
      std::cout << "Not stable" << std::endl;
      return 0;
    }
  }
  std::cout << "Stable" << std::endl;
}

// eof

Measured memory_bytes: 3108
n = int(input())
h = [0 for i in range(6)]
for i in range(n):
    a = float(input())
    if(a < 165.0):
        h[0] += 1
    elif(165.0 <= a and a < 170.0):
        h[1] += 1
    elif(170.0 <= a and a < 175.0):
        h[2] += 1
    elif(175.0 <= a and a < 180.0):
        h[3] += 1
    elif(180.0 <= a and a < 185.0):
        h[4] += 1
    else:
        h[5] += 1

for i in range(len(h)):
    print(str(i + 1) + ":" + "*"*h[i])




Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int p,q,r; cin>>p>>q>>r;

    cout<<p+q+r-max<int>({p,q,r})<<endl;

}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
        for j in range(b+1):
                for k in range(c+1):
                        d = 500*i+100*j+50*k
                        if d == x:
                                cnt += 1
print (cnt)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
int main(){
    int N;
    scanf("%d",&N);
    if(N%10==3) printf("bon");
    else if(N%10==0 || N%10==1 || N%10==6 || N%10==8) printf("pon");
    else printf("hon");
}


Measured memory_bytes: 1732
k=int(input())
if k<=9:
    print(k)
    exit()
a=[1,2,3,4,5,6,7,8,9]
cnt=9
while True:
    q=[]
    for i in a:
       for j in range(10):
            if abs(int(str(i)[-1])-j)<=1:
                cnt+=1
                if cnt==k:
                    print(int(str(i)+str(j)))
                    exit()
                q.append(int(str(i)+str(j)))         
    a=list(sorted(set(q)))


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n, k; cin >> n >> k;
    vector<int> lis(n);
    REP(i, 0, n){cin >> lis[i];}
    sort(ALL(lis));
    int ans = 0;
    REP(i, 0, k){
        ans += lis[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
N=int(input())
T, A = [int(i) for i in input().split()]
H = list(map(int, input().split()))

K = []
index = 10000
ans=0
for i in H:
        j = T - i * 0.006
        K.append(j)

for i in range(len(K)):
       if abs(K[i] - A) < index:
               ans = i+1
               index = abs(K[i] - A)

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int a, b, c, d;
    int n, count;
    
    while (scanf("%d", &n) != EOF){
        count = 0;
        for (a=0; a<=9; a++) {
            for (b=0; b<=9; b++) {
                for (c=0; c<=9; c++) {
                    for (d=0; d<=9; d++) {
                        if (n == a+b+c+d) count++;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    
    return 0;
}

Measured memory_bytes: 596
D = int(input())

cs = [int(i) for i in input().split()]

last = {n: 0 for n in range(1, 27)}

for day in range(1, D+1):
    ss = [int(i) for i in input().split()]
    max_score = 0
    max_i = 1
    for i, s in enumerate(ss, 1):
        human = day-last[i]
        s_human = s + cs[i-1] * human
        if s_human > max_score:
            max_score = s_human
            max_i = i
    print(max_i)
    last[max_i] = day

Measured memory_bytes: 9224
#include<stdio.h>

int main(){
   int n,m;
   scanf("%d %d", &n, &m);
   int a[n];
   int sum = 0;
   int count = 0;
   for(int i = 0; i < n; i++){
      scanf("%d", &a[i]);
      sum += a[i];
   }
   double x = sum/(4.0*m);

   for(int i = 0; i < n; i++){
      if(a[i] >= x){
         count++;
      }
   }
   if(count >= m){
      printf("Yes\n");
   }else{
      printf("No\n");
   }
   return 0;
}


Measured memory_bytes: 1632
#include<bits/stdc++.h>
#define MAX 3007
using namespace std;

struct str
{
    int l,r;
};

int dp[MAX][MAX];
str in[MAX][MAX];
string st,st1;

int solve(int l,int r)
{
    if(l>=st.size() || r>=st1.size())
        return 0;
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(st[l]==st1[r])
    {
        dp[l][r]=1+solve(l+1,r+1);
        in[l][r]= {l+1,r+1};
    }
    else
    {
        int a=solve(l+1,r);
        int b=solve(l,r+1);
        if(a>b)
        {
            dp[l][r]=a;
            in[l][r]= {l+1,r};
        }
        else
        {
            dp[l][r]=b;
            in[l][r]= {l,r+1};
        }
    }
    return dp[l][r];
}

string final_string;
void backtrack(int l,int r)
{
    if(in[l][r].l==l && in[l][r].r==r)
        return;
    if(st[l]==st1[r])
        final_string.push_back(st[l]);
    backtrack(in[l][r].l,in[l][r].r);
}


int main()
{
    int i,j,mx=0,l,r,flag=0;
    cin >> st >> st1;
    memset(dp,-1,sizeof(dp));
    for(i=0; i<=MAX-4; i++)
    {
        for(j=0; j<=MAX-4; j++)
            in[i][j]= {i,j};
    }
    mx=solve(0,0);
    for(i=0; i<MAX-4; i++)
    {
        for(j=0; j<MAX-4; j++)
        {
            if(dp[i][j]==mx)
            {
                l=i,r=j,flag=1;
                break;
            }
        }
        if(flag)
            break;
    }
    backtrack(l,r);

    cout << final_string << "\n";


    return 0;
}


Measured memory_bytes: 106752
import std.stdio, std.string, std.conv;

void main() {
	int _n = stdin.readln.chomp.to!int;
	auto input = stdin.readln.chomp.split(" ").to!(int[]);
	for (auto j=0; j<input.length; j++) {
		for (auto i=j-1; i>=0; i--) {
			if (input[i] > input[i+1]) {
				auto tmp = input[i];
				input[i] = input[i+1];
				input[i+1] = tmp;
			}
		}
		input.to!(string[]).join(" ").writeln;
	}
}

Measured memory_bytes: 2588
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n, a;

    bool approved = true;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a%2 == 0) {
            if (a%3 != 0 && a%5 != 0) {
                approved = false;
                break;
            }
        }
    }
    if (approved) {
        cout << "APPROVED";
    }
    else {
        cout << "DENIED";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    struct node {
        int d, lch, rch;
    };
    vector<node> nodes;
    nodes.push_back({0, -1, -1});
    for (int i = 0; i < n; ++i) {
        int c = 0;
        for (int j = 0; j < (int)s[i].size(); ++j) {
            if (s[i][j] == '0') {
                if (nodes[c].lch == -1) {
                    nodes[c].lch = nodes.size();
                    nodes.push_back({nodes[c].d + 1, -1, -1});
                    c = nodes[c].lch;
                } else {
                    c = nodes[c].lch;
                }
            } else {
                if (nodes[c].rch == -1) {
                    nodes[c].rch = nodes.size();
                    nodes.push_back({nodes[c].d + 1, -1, -1});
                    c = nodes[c].rch;
                } else {
                    c = nodes[c].rch;
                }
            }
        }
    }
    lint gr = 0;
    for (auto &v : nodes) {
        if (v.lch == -1 && v.rch == -1) {
            continue;
        } else if (v.lch == -1 || v.rch == -1) {
            lint t = (v.d - l) & (l - v.d);
            gr     = gr ^ t;
        }
    }
    if (gr == 0) {
        cout << "Bob"
             << "\n";
    } else {
        cout << "Alice"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 2088
N, A, B = map(int, input().split())
answer = 0
for i in range(N + 1):
    t = 0
    k = i # int型の場合はコピーされる
    while i > 0:
        t += i % 10
        i = i //10
    if A<= t <= B:
        answer += k
print(answer)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
int a[200000];
int b[200000];
int main() {
	int n;
	cin >> n;
	rep(i, n) cin >> a[i];
	int cnt = 0;
	if (n % 2 == 0) {
		for (int i = n; i > 0; i -= 2) b[cnt++] = i;
		for (int i = 1; i < n; i += 2) b[cnt++] = i;
	}
	else {
		for (int i = n; i > 0; i -= 2) b[cnt++] = i;
		for (int i = 2; i < n; i += 2) b[cnt++] = i;
	}
	rep(i, n) cout << a[b[i] - 1] << " ";
	cout << endl;
}

Measured memory_bytes: 3712