akhauriyash/Code-Regression huggingface dataset:
//problem_d.go

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	//"strings"
)

const (
	mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

// -----------------------------------------

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func rsortIntSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

// -----------------------------------------

func solve() {
	n, k := getInt(), getInt()
	p := getIntSlice(n)

	m := 0
	var v float32 = 0.0

	s := 0
	for i := 0; i < k; i++ {
		s += p[i]
	}

	m = s

	for i := k; i < n; i++ {
		s = s + p[i] - p[i-k]

		if s > m {
			m = s
		}

	}

	v = float32(m+k) / 2.0

	fmt.Fprintln(wr, v)

}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 7552
/*    created: 09.08.2020 22:41:29    */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    string s = "abcdefghijklmnopqrstuvwxyz", ans = "";

    while(true){
        n--;
        if(n < 26) {
            ans.PB(s[n]);
            reverse(ALL(ans));
            cout << ans << endl;
            return 0;
        }
        ll tmp = n % 26; n /= 26;
        ans.PB(s[tmp]);
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  ll n;
  cin>>n;
  string name;
  string t="zabcdefghijklmnopqrstuvwxy";
  while(n!=0){
    ll cnt=n%26;
    name.pb(t[cnt]);
    n--;
    n/=26;
  }
  reverse(all(name));
  cout<<name<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int W,a,b;
    cin>>W>>a>>b;
    int rr=a,rl=a+W,br=b,bl=b+W;
    int ans;
    if(rl<br){
        ans=br-rl;
    }else if(bl<rr){
        ans=rr-bl;
    }else{
        ans=0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	cout << (n-30)/2 << endl;
}



Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();

        int x = x2 - x1;
        int y = y2 - y1;
        System.out.println((x2 - y) + " " + (y2 + x) + " " + (x1 - y) + " " + (y1 + x));
    }
}


Measured memory_bytes: 24916
N = int(input())

XA = []
XB = []
for i in range(N):
    A, B = (int(i) for i in input().split())
    XA.append(A)
    XB.append(B)

XA.sort()
XB.sort()

if N % 2 == 1:
    aa = XA[ (N - 1) // 2] 
    bb = XB[ (N - 1) // 2]
    print(bb - aa + 1)
else:
    aa1 = XA[N // 2]
    bb1 = XB[N // 2]
    aa = XA[N // 2 - 1]
    bb = XB[N // 2 - 1]
    print((bb1 + bb) - (aa1 + aa) + 1)




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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()

#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d\n",n)
#define SL(n) scanf("%lld",&n)
#define PL(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
typedef long long int 	LL;
typedef long double 	LD;
typedef pair<int,int>   II;
typedef vector<int>     VI;
const int MOD = 1e9 + 7;
const int N = 100011;

int cnt[26];
char a[123][123];
int n, m;
bool vs[123][123];

bool valid(int i, int j) {
    if(i >= 0 && i < n && j >= 0 && j < m && !vs[i][j])
    return 1;
    return 0;
}

int main() {
    SI(n), SI(m);
    for(int i = 0; i < n; ++i) {
        scanf("%s", a[i]);
        for(int j = 0; j < m; ++j)
            cnt[a[i][j]-'a']++;
    }
    int md4 = 0, md2 = 0, md1 = 0;
    for(int i = 0; i < 26; ++i) {
        md4 += cnt[i]/4;
        cnt[i] %= 4;
    }
    for(int i = 0; i < 26; ++i) {
        md2 += cnt[i]/2;
        cnt[i] %= 2;
    }
    for(int i = 0; i < 26; ++i) {
        md1 += cnt[i];
        cnt[i] %= 1;
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            if(vs[i][j]) continue;
            int cnt = 0;
            int i1 = n - 1 - i, j1 = m - 1 - j;
            int i2 = i, j2 = m - 1 - j;
            int i3 = n - 1 - i, j3 = j;
            vs[i][j] = 1;
            if(valid(i1, j1)) cnt++, vs[i1][j1] = 1;
            if(valid(i2, j2)) cnt++, vs[i2][j2] = 1;
            if(valid(i3, j3)) cnt++, vs[i3][j3] = 1;
            if(cnt == 3) md4--;
            if(cnt == 1) {
                if(md2 == 0) {
                    md4--;
                    md2++;
                }
                else md2--;
            }
            if(cnt == 0) md1--;
        }
    }
    if(md4 == md2 && md2 == md1 && md1 == 0) puts("Yes");
    else puts("No");
    return 0;
}

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

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

    vector<int> d(N);
    for(int i=0; i<N; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    if(!(N%2)) {
        numOfK = d[N/2]-d[N/2-1];
    } else {
        numOfK = 0;
    }   

    cout << numOfK << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

int A[100000+2];

void solve(){
	int n, k;
	cin >> n >> k;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
	}
	sort(A+1,A+n+1);
	int ans = INT_MAX;
	for (int i=1; i<=n-k+1; ++i){
		ans = min(ans,A[i+k-1]-A[i]);
	}
	cout << ans;
}	

int main(){ FIO;
	solve();
return 0;}

Measured memory_bytes: 640
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll X,N;
    cin>>X>>N;
    vector<ll> p(N);
    REP(i,N) cin>>p[i];
    sort(p.begin(),p.end());
    ll ans=INF;
    ll tmp;
    REP(i,102){
        bool flag=true;
        REP(j,N){
            if(i==p[j]){
                flag=false;
                break;
            }
        }
        if(flag){
            if(abs(i-X)<ans){
                ans=abs(i-X);
                tmp=i;
            }
        }
    }
    cout<<tmp<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
int32_t main(){ fast;
	int n, x; cin>>n>>x;
	vector<int> a(n);
	int t = 0;
	rep(i, n){
		cin>>a[i];
		t  += a[i];
	}
	sort(all(a));
	int rest = x - t;
	cout<<n + rest / a[0]<<endl;	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int maxn=5e5+10;
ll gcd(ll a, ll b){return (b==0)?a:gcd(b, a%b);}
bool isPrime(ll n) {
    if(n<=3){
        return n>1;
    }
    if(n%6!=1&&n%6!=5){
        return false;
    }
    ll sqr=sqrt(n);
    for(ll i=5;i<=sqr;i+=6){
        if(n%i==0||n%(i+2)==0){
            return false;
        }
    }
    return true;
}
int dis[4][2]={0,1,0,-1,1,0,-1,0};
 
 
 int main()
 {
 	string s;cin>>s;
 	int n=s.length();
 	int flag=1;
 	for(int i=0;i<s.length();i++)
 	if(s[i]!=s[n-i-1])
 	flag=0;
 	if(n%2==0)
 	flag=0;
 	//cout<<flag<<endl;
 	for(int i=0;i<(n-1)/2;i++)
 	if(s[i]!=s[(n-1)/2-1-i])
 	flag=0;
 	int j=0;
 	for(int i=(n+3)/2-1;i<n;i++,j++)
 	if(s[i]!=s[n-j-1])
 	flag=0;
 	if(flag)
 	cout<<"Yes"<<endl;
 	else
 	cout<<"No"<<endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define INF 999999999
typedef pair<int, int> P;
typedef pair<P, P> PP; // h, w, cost, direction
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};

void solve()
{
	int w, h;
	while(cin >> w >> h, w || h)
	{
		vector< vector<int> > order(h, vector<int>(w));
		for(int i = 0; i < h; ++i)
		{
			for(int j = 0; j < w; ++j)
			{
				cin >> order[i][j];
			}
		}
		int c[4];
		for(int i = 0; i < 4; ++i)
		{
			cin >> c[i];
		}
		int dist[31][31][4];
		for(int i = 0; i < h; ++i)
		{
			for(int j = 0; j < w; ++j)
			{
				for(int k = 0; k < 4; ++k)
				{
					dist[i][j][k] = INF;
				}
			}
		}
		dist[0][0][1] = 0;
		priority_queue<PP, vector<PP>, greater<PP> > pq;
		pq.push(PP(P(0, 0), P(0, 1)));
		while(!pq.empty())
		{
			PP pp = pq.top();
			int y = pq.top().first.first;
			int x = pq.top().first.second;
			int sum_cost = pq.top().second.first;
			int dir = pq.top().second.second;
			pq.pop();
			if(dist[y][x][dir] < sum_cost)
			{
				continue;
			}
			for(int i = 0; i < 4; ++i)
			{
				int cost = c[i];
				if(order[y][x] == i)
				{
					cost = 0;
				}
				int prev = dir;
				int next = (prev + i) % 4;
				int nx = x + dx[next];
				int ny = y + dy[next];

				if(nx < 0 || nx >= w || ny < 0 || ny >= h)
				{
					continue;	
				}
				if(dist[ny][nx][next] > sum_cost + cost)
				{
					dist[ny][nx][next] = sum_cost + cost;
					pq.push(PP(P(ny, nx), P(sum_cost + cost, next)));
				}
			}
		}
		int min_cost = INF;
		for(int i = 0; i < 4; ++i)
		{
			if(min_cost > dist[h - 1][w - 1][i])
			{
				min_cost = dist[h - 1][w - 1][i];
			}
		}
		cout << min_cost << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1252
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	int n;
	int t = 0;
	cin>>n; 
	for(int i=1;i<=n;i++){
		t = t*10+7;
		t%=n;
		if(t%n==0){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep (i, 0, n) cin >> a[i] >> b[i];
    sort (a, a + n);
    sort (b, b + n);
    int ans;
    if (n % 2 == 0) {
        ans = ((b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1])) + 1;
    } else {
        ans = b[n / 2] - a[n / 2] + 1;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6732
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Simple Calculator
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int x, y;
  cin >> x >> y;

  int cnt = 0;
  int ax = abs(x), ay = abs(y);

  if (ax < ay) {
    if (x < 0) x = -x, cnt++;
    cnt += ay - ax;
    x += ay - ax;
  }
  else if (ax > ay) {
    if (x > 0) x = -x, cnt++;
    cnt += ax - ay;
    x += ax - ay;
  }

  if ((x > 0 && y < 0) || (x < 0 && y > 0)) cnt++;

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
from itertools import product

s = input()
n = len(s)

cnt = 0
for bit in product([0, 1], repeat=n - 1):
    tmp = []
    for i, j in enumerate(bit):
        if j == 1:
            tmp.append("+")
        else:
            tmp.append("")
    s_ = s[0]
    for i in range(n - 1):
        s_ += tmp[i] + s[i + 1]
    cnt += eval(s_)
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 cout<<(1000-n%1000)%1000<<'\n';
	 return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N; cin >> N;
    vel a(3 * N); rep(i,3 * N) cin >> a[i];
    sort(rall(a));

    ll ans = 0;
    rep(i,2*N) if(i % 2 == 1) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var tot = P.Sum();
		Console.WriteLine(tot - P.Max() / 2);
		
		
	}
	int N;
	int[] P;
	public Sol(){
		N = ri();
		P = new int[N];
		for(int i=0;i<N;i++) P[i] = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
const ll limit=1000000000000000000;
using namespace std;
ll count(ll n) 
{ 
    return (ll)((-1 + sqrtl(1 + 8 * n)) / 2); 
} 

void primeFactors(ll n)  
{  
    ll ans=0; ll x=0;
    while (n % 2 == 0)  
    {  
        ++x;
        n = n/2;  
        //cout<<2<<" ";
    }  

    ans+=count(x);
    //cout<<n<<" ";
    for (ll i = 3; i <= sqrtl(n); i = i + 2)  
    {  
        x=0;
        while (n % i == 0)  
        {  
            ++x;//cout<<i<<" ";
            n = n/i;  
        }  
        //cout<<x<<" ";
        ans+=count(x);
    }  
  
    if (n > 2)  
        {
		++ans;
		}
	
    cout<<ans<<"\n";
}  



int main()
{
   int t;t=1;
   while(t--)
   {
      ll n;cin>>n;
      primeFactors(n);
     
   }
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using namespace std;

long rui[200010]={0};
bool visited[200010]={0};
vector<int> G[200010];

void dfs(int i=0, long val=0) {
    cerr << i << endl;
    visited[i] = true;
    rui[i] += val;
    for (auto g:G[i]) {
        if (visited[g]) continue;
        dfs(g, rui[i]);
    }
    return;
}

int main() {
    int n, q;
    cin >> n >> q;
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i=0; i<q; i++) {
        long p, x;
        cin >> p >> x;
        rui[p-1] += x;
    }
    dfs();
    for (int i=0; i<n; i++)
        cout << rui[i] << (i < n-1 ? ' ' : '\n');
    return 0;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int M,N;
int w[222222],t[222222];
int sw[222222],st[222222];

int dp[1<<15];
int c[22],b[22];
signed main(){
    cin>>M>>N;
    rep(i,M)cin>>w[i]>>t[i];
    rep(i,M){
        sw[i+1]=sw[i]+w[i];
        st[i+1]=st[i]+t[i];
    }
    rep(i,N)cin>>c[i]>>b[i];

    rep(i,1<<N){
        rep(j,N){
            if(i>>j&1)continue;
            int lb=dp[i],ub=M+1;
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                if(sw[mid]-sw[dp[i]]>c[j]||st[mid]-st[dp[i]]>b[j])ub=mid;
                else lb=mid;
            }
            chmax(dp[i|(1<<j)],lb);
        }
    }

    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}

Measured memory_bytes: 8020
s = input()

if s[0] != 'A' or s[2:-1].count('C') != 1:
  print('WA')
else:
  for i,c in enumerate(s):
    if i == 0 or i>1 and c == 'C':
      continue
    else:
      if not 'a'<=c<='z':
        print('WA')
        break
  else:
    print('AC')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
vector<vector<int> >G(1000010);
int dp[100010];
int dfs(int n){
    if(G[n].size()){
        int ma=0;
        for(auto e :G[n]){
            if(dp[e]>=0)ma=max(ma,dp[e]);
            else ma=max(ma,dfs(e));
        }
        return dp[n]=ma+1;
    }else{
        return dp[n]=0;
    }
}
int main(){
    int n,m;cin>>n>>m;
    REP(i,1,n+1)dp[i]=-1;
    rep(i,m){
        int x,y;cin>>x>>y;
        G[x].push_back(y);
    }
    REP(i,1,n+1){
        if(dp[i]>=0)continue;
        dfs(i);
    }
    int k=0;
    REP(i,1,n+1){
        k=max(k,dp[i]);
    }
    cout<<k<<endl;
}

Measured memory_bytes: 29184
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());
    reverse(sc.begin(), sc.end());

    char next = 'a';
    while (true) {
        if (next == 'a') {
            if (sz(sa) > 0) {
                next = sa.back();
                sa.pop_back();
            } else {
                cout << "A" << endl;
                return 0;
            }
        } else if (next == 'b') {
            if (sz(sb) > 0) {
                next = sb.back();
                sb.pop_back();
            } else {
                cout << "B" << endl;
                return 0;
            }
        } else {
            if (sz(sc) > 0) {
                next = sc.back();
                sc.pop_back();
            } else {
                cout << "C" << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
open Tuple

let dbg x = Printf.eprintf "[debug]%s\n" @@ dump x; x

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.Labels.map
    (List.range 1 `To n)
    ~f:(fun _ -> scan fmt f)
  |> List.enum

let scan_list cnv =
  let l = read_line ()
          |> String.split_on_char ' '
          |> List.map cnv in
  List.enum l

let scan_lists n cnv =
  let ll = List.Labels.map (List.range 1 `To n)
      ~f:(fun _ -> scan_list cnv) in
  List.enum ll

let scan_array n m e conv =
  let arr = Array.make_matrix n m e in
  EnumL.iter (0 --^ n)
    ~f:(fun i -> arr.(i) <- Array.of_enum @@ scan_list conv);
  arr

let (n, m) = scan "%d %d" Tuple2.make
let lights = scan_lists m Int.of_string
let onoff = scan_list Int.of_string

let rec superset = function
  | [] -> [[]]
  | x :: xs ->
    let ps = superset xs in
    ps @ List.map (fun ss -> x :: ss) ps

let rec intersection l = function
  | [] -> []
  | h::t ->
    if List.exists ((=) h) l then
      h::intersection l t
    else intersection l t

let () =
  let sets = List.enum @@ superset (List.range 1 `To n) in
  EnumL.map sets ~f:(fun set ->
      EnumL.map (Enum.combine (Enum.clone onoff, Enum.clone lights))
        ~f:(fun (b, l) ->
            let n = List.length @@
              intersection set @@ List.of_enum @@ Enum.skip 1 @@ Enum.clone l
            in n mod 2 = b)
      |> EnumL.for_all ~f:((=) true))
  |> EnumL.filter ~f:((=) true)
  |> Enum.count
  |> Printf.printf "%d\n"


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

int main()
{
	int n, t, h;
	t = h = 0;
	string tw, hw;
	cin.tie(0);
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> tw >> hw;
		if (tw == hw) {
			t++;
			h++;
		}
		else if (tw < hw) {
			h += 3;
		}
		else {
			t += 3;
		}
	}

	cout << t << " " << h << "\n";
}


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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  bool ok = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) ok = true;
  }
  if (ok) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    string s = to_string(N);
    int ans = N;
    vector<int> d(K);
    for (int i = 0; i < K; i++) {
        cin >> d[i];
    }
    while (true) {
        bool ok = true;
        for (int i = 0; i < s.size(); i++) {
            for (int j = 0; j < d.size(); j++) {
                if (s[i]-'0' == d[j]) ok = false;
            }
        }
        if (ok) break;
        else {
            ans++;
            s = to_string(ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf = 2e5+9;

ll calc(ll  cur){
    if(cur == 1)
        return 1;
    if(cur == 0)
        return 0;
    return 1+2ll*calc(cur/2);
}

int main(){
    ll k;
    cin>>k;
    cout<<calc(k)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){

    int a, b, c;
    cin >> a >> b >> c;
    
    if((a < c && c < b) || (a > c && b < c)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

int main(){
    ll N,K,ans=0;
    cin>>N>>K;
    ll p[N];
    for(int i=0;i<N;i++) cin>>p[i];
    sort(p,p+N);
    for(int i=0;i<K;i++) ans+=p[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3588
import sys
N = int(input())
array = list(map(int,input().split()))

if not ( 1 <= N <= 100 ): sys.exit()
if (min(array) < 1) or (max(array) > 1000) : sys.exit()

sum = 0
for J in array:
    sum += 1/J

print(1/sum)

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

using namespace std;



#define FOR(i,bg,ed) for(int i=bg;i<ed;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

#define fi first
#define se second
#define pb push_back
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;

set<VV> memo; 
set<V> ret;

bool g(VV& dist,int l,int r,map<LL,int>& cnt){
    FOR(k,l+1,r){
        if(dist[k][l]==-1&&dist[r][k]==-1)continue;
        if(dist[k][l]==-1){
            dist[k][l]=dist[r][l]-dist[r][k];
            if(cnt.count(dist[k][l])==0)return false;
            if(--cnt[dist[k][l]]==0)cnt.erase(dist[k][l]);
            if(g(dist,l,k,cnt)==false)return false;
        }
        if(dist[r][k]==-1){
            dist[r][k]=dist[r][l]-dist[k][l];
            if(cnt.count(dist[r][k])==0)return false;
            if(--cnt[dist[r][k]]==0)cnt.erase(dist[r][k]);
            if(g(dist,k,r,cnt)==false)return false;
        }
    }
    return true;
}

void f(int N,VV dist,int l,int r,map<LL,int> m){
    if(memo.count(dist))return;
    memo.insert(dist);
    if(m.size()==0){
        V r;
        REP(i,N-1){
            r.pb(dist[i+1][i]);
        }
        ret.insert(r);
        return;
    }
    const int bg=0;
    const int ed=N-1;
    {
        VV nxt = dist;
        auto cp = m;
        LL x = cp.rbegin()->fi;
        nxt[r][bg]=x;
        if(--cp[x] == 0)cp.erase(x);
        LL y =nxt[ed][bg]-x;
        nxt[ed][r]=y;
        if(cp.count(y)==1){
            if(--cp[y]==0)cp.erase(y);
            if(g(nxt,bg,r,cp)&&g(nxt,r,ed,cp))f(N,nxt,l,r-1,cp);
        }
    }

    {
        VV nxt = dist;
        auto cp = m;
        LL x = cp.rbegin()->fi;
        nxt[ed][l]=x;
        if(--cp[x] == 0)cp.erase(x);
        LL y =nxt[ed][bg]-x;
        nxt[l][bg]=y;
        if(cp.count(y)==1){
            if(--cp[y] == 0)cp.erase(y);
            if(g(nxt,bg,l,cp)&&g(nxt,l,ed,cp))
                f(N,nxt,l+1,r,cp);
        }
    }

}
void solve(int N){
    if(N>=2){    
        memo.clear();
        ret.clear();
        map<LL,int> d;
        int M = N*(N-1) /2;
        VV dist(N);
        REP(i,N)dist[i].assign(i,-1);
        REP(i,M){
            LL x;
            cin>>x;
            if(i==0){
                dist[N-1][0]=x;
            }
            else{
                d[x]++;
            }
        }
        
        f(N,dist,1,N-2,d);
        for(auto &v:ret){
            REP(i,N-1)cout<<" "+(!i)<<v[i];cout<<endl;
        }
    }
    cout<<"-----"<<endl;
}

int main(){
    int N;
    while(cin>>N,N)solve(N);
}

Measured memory_bytes: 4116
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll H;
  cin>>H;
  ll ans = 0;
  ll two = 1;
  while(H>0) {
    H /= 2;
    ans += two;
    two *= 2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3628
a,b,c,k = map(int, input().split())

count = 0

if k >= a:
    k -= a
    count += a
else:
    count += k
    print(count)
    exit()
if k == 0:
    print(count)
    exit()
if k >= b:
    k-= b
else:
    print(count)
    exit()
if k == 0:
    print(count)
    exit()
count += -1*k
print(count)

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

int main(){
    int n,q,k,ans=0;
    int S[1000000];
    int *pos;


    scanf("%d",&n);
    rep(i,n) scanf("%d",&S[i]);

    scanf("%d",&q);
    rep(i,q){
        scanf("%d",&k);
        if(*lower_bound(S,S+n,k)==k) ans++;//イテレータが指す値である*lower_boundがkと同じかどうかを確認。
    }

    cout<<ans<<endl;


    return 0;
}


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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif
#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int n, m, k, x;
string s;

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

    char c;
    cin >> c;
    if (c >= 'a' && c <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++) cin>>d[i];
    int sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++) sum+=d[i]*d[j];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {
	int r;
	cin >> r;
	cout << r * 2 * 3.1415926 << endl;
	
}


Measured memory_bytes: 3776
#include<stdio.h>

int main()
{
	int n;
	long int max=-1000001,min=1000001,sum=0;
	int i,a;
	
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(max<a)max=a;
		if(min>a)min=a;
		sum+=a;
	}
	printf("%ld %ld %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
N = int(input())
nodes = {}
for _ in range(N-1):
    l, r, d = map(int, input().split())
    if nodes.get(str(l)) is None:
        nodes[str(l)] = {'to': [], 'color': -1}
    if nodes.get(str(r)) is None:
        nodes[str(r)] = {'to': [], 'color': -1}

    nodes[str(l)]['to'].append((str(r), d))
    nodes[str(r)]['to'].append((str(l), d))

q = [('1', 0)]
while q:
    node, color = q.pop()

    nodes[node]['color'] = color
    for n, d in nodes[node]['to']:
        if nodes[n]['color'] != -1:
            continue

        if d % 2 == 0:
            q.append((n, color))
        else:
            q.append((n, (color+1) % 2))


for i in range(1, N+1):
    print(nodes[str(i)]['color'])


Measured memory_bytes: 83444
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

"""
5
2 4 4 0 2

2なら、
xOxxx
xxxOx
の2通りしかない
N=9なら
xxxOxxxxx
xxxxxOxxx
の2通りしかない
4なら
Oxxxxと
xxxxO
しかない
これらをもとに確かめていく


Nが奇数の時
3
2 0 2
とすると成り立つ
4のとき
3 1 1 3
まずこれでできない場合をはじける

計算するまでもないのか。

2 4 4 0 2なら
前か後ろか、前か後ろかをかけるだけなので4

"""
if N == 1:
    if A[0] == 0:
        print(1)
    else:
        print(0)
    exit()

A.sort()

if N % 2 == 0:
    correct = list(range(1, N+1, 2))
    correct = correct + correct
    correct.sort()
else:
    # 奇数時
    correct = list(range(0, N+1, 2))
    correct = correct + correct
    correct.sort()
    correct = correct[1:]
if correct == A:
    ans = 2**(N//2)
    print(ans%mod)
else:
    print(0)
    


Measured memory_bytes: 16276
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B;
int main() {
	cin>>A>>B;

	if(A*B%2==0)cout<<"Even"<<endl;
	else cout<<"Odd"<<endl;
 	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	vector< vector<ll> > hol(n);
	vector< vector<ll> > dp(n);
	for(ll i=0;i<n;i++)
	{
		hol[i].resize(3);
		dp[i].resize(3,0);
	}
	
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			cin>>hol[i][j];
		}
	}
	
	dp[0][0]=hol[0][0];
	dp[0][1]=hol[0][1];
	dp[0][2]=hol[0][2];
	for(ll i=1;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			ll val1=dp[i-1][(j+1)%3]+hol[i][j];
			ll val2=dp[i-1][(j+2)%3]+hol[i][j];
			
			dp[i][j]=max(val1,val2);
		}
	}
	
	ll result=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	cout<<result<<endl;
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll h[20];
int main() {
    cin>>n;
    REP(i, 0, n) cin>>h[i];

    ll cnt=1, mx=h[0];
    REP(i, 1, n){
        if(mx<=h[i]){
            mx=h[i];
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,k;
	cin>>k>>a>>b;
	if((a/k)!=(b/k))
	{
		cout<<"OK"<<endl;
	}
	else
	{
		if(a%k==0||b%k==0)
		{
			cout<<"OK"<<endl;
		}
		else
		{
			cout<<"NG"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3640
open System 

type Explicit =          
    static member inline ($) (_:int32, _:Explicit) = int
    static member inline ($) (_:int64, _:Explicit) = int64

let inline convert (value:'a): 'b = 
    (Unchecked.defaultof<'b> $ Unchecked.defaultof<Explicit>) value

let inline fromInt (x: int): 'a = convert x

module NumericLiteralG =
    let inline FromZero(): ^a = LanguagePrimitives.GenericZero
    let inline FromOne(): ^a = LanguagePrimitives.GenericOne
    let inline FromInt32 n = fromInt n

let R() = Console.ReadLine()

let f (x: float): float =
    pown (x / 3.) 3

let L = R() |> float

f L 
|> printfn "%f" 

Measured memory_bytes: 29992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//constexpr ll MOD = 1e9 + 7;
constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll K, N;
  cin >> K >> N;
  vector<ll> A(2 * N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  for (ll i = 0; i < N; i++)
  {
    A.at(N + i) = K + A.at(i);
  }

  ll ans = INF;
  for (ll i = 0; i < N; i++)
  {
    ll tmp = A.at(i + N - 1) - A.at(i);
    chmin(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
n = int(input())

res = 100000
for i6 in range(0, n+1, 6):
    c6, c9 = 0, 0
    i9 = n - i6
    while (i6 > 0):
        c6 = c6 + (i6%6)
        i6 = i6 // 6
    while (i9 > 0):
        c9 = c9 + (i9%9)
        i9 = i9 // 9

    if c6 + c9 < res:
        res = c6 + c9

print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int l = (n - 1) / 2;
		int r = n / 2;
		char c = s.charAt(l);
		while (0 <= l) {
			if (s.charAt(l) == c && s.charAt(r) == c) {
				l--;
				r++;
			} else {
				break;
			}
		}
		System.out.println(r);
		sc.close();
	}
}


Measured memory_bytes: 26616
#define ll long long int
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll x,sum=0,temp=0;
    cin>>x;
    temp=x/500;
    x=x%500;
    sum=temp*1000;
    temp=x/5;
   // x=x%5;
    sum+=temp*5;
    cout<<sum<<endl;

}




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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    int c;
    rep(0, s.size()) {
        c = int(s[i]) + n;
        if ('Z' < char(c)) {
            c = int('A') + (c - int('Z') - 1);
        }

        cout << char(c);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())
S = list(map(int, fin.readline().split()))
q = int(fin.readline())
T = list(map(int, fin.readline().split()))

ret = 0

for t in T:
	for s in S:
		if t == s:
			ret += 1
			break

print(ret)

Measured memory_bytes: 8424
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Integer N = input.nextInt();
        String[] S = new String[N];
        Set<String> types = new HashSet<String>();

        for (int i = 0; i < N; i++) {
            S[i] = input.next();
            types.add(S[i]);
        }

        System.out.println(types.size());
    }
}


Measured memory_bytes: 80076
#include <bits/stdc++.h>
#define lol long long
//#define LIM 9999999
using namespace std;

//const lol mod=1e9+7;

/*  author: H3XoRuSH  */

int main() {
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lol a;
    cin >> a;
    if(a<=999) cout << "ABC";
    else cout << "ABD";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[10101],b[1010];
int a[1010];

int main(void){
	int h,n,i;
	fill(dp,dp+10101,INFLL);
	cin >> h >> n;
	for(i=0; i<n; ++i){
		cin >> a[i] >> b[i];
	}
	dp[h] = 0ll;
	do{
		for(i=0; i<n; ++i){
			dp[max(h-a[i],0)] = min(dp[max(h-a[i],0)],dp[h]+b[i]);
		}
	}while(--h);
	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	int n;
	
	scanf("%d", &n);
	
	if(n % 10 == 3){
		puts("bon");
	}
	else if(n % 10 == 0 ||n % 10 == 1 ||n % 10 == 6 ||n % 10 == 8){
		puts("pon");
	}
	else puts("hon");
	
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuffer str = new StringBuffer(s);
        String r = str.reverse().toString();
        char[] c = r.toCharArray();
        int size = r.length();
        int ans = 0;
        int[] count = new int[2019];
        int total = 0;
        int mod = 2019;
        int exp = 1;
        for (int i = 0; i < size; i++) {
            count[total]++;
            total += Integer.parseInt(String.valueOf(c[i])) * exp;
            total %= mod;
            ans += count[total];
            exp *= 10;
            exp %= mod;
        }
        System.out.println(ans);
    }
}


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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    for (int i=0;i<=100;i++)
        if (a*i%b==c) {
            puts("YES");
            return 0;
        }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>


int selection_sort(int *A,int N){ 
    int i,j,t,sw=0,minj;

    for(i=0;i<N-1;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j]<A[minj])
                minj=j;
        }        
        std::swap(A[i],A[minj]);                           
        if(i!=minj)
            sw++;
    }   
    return sw; 

}

int main(void){
    int A[100],N,i,sw;

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

    for(i=0;i<N;i++){
        if(i)
            putchar(' ');
        printf("%d",A[i]);
    }   
    putchar('\n');
    printf("%d\n",sw);

    return 0;

}


Measured memory_bytes: 3208
#include<stdio.h>
#include<string.h>

int main(){
	int a,n,run=0,point=0,out=0;
	char eve[10];
	scanf("%d",&n);
	for(a=0;a<n;){
		scanf("%s",eve);
		if(strcmp(eve,"HIT")==0){
			if(run!=3) run++;
			else{
				point++;
			}
		}
		else if(strcmp(eve,"HOMERUN")==0){
			point+=run+1;
			run=0;
		}
		else if(strcmp(eve,"OUT")==0){
			if(out!=2) out++;
			else{
				a++;
				printf("%d\n",point);
				run=0,point=0,out=0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
integer N
integer,allocatable,dimension(:)::d
integer ans
read*,N
allocate(d(N))
read*,d

call heapsort(N,d)

if(d(N/2)==d(N/2+1))then
  ans=0
else
  ans=d(N/2+1)-d(N/2)
endif

print"(i0)",ans


contains

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

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

int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    getline(cin, S);
    getline(cin, S);
    for(int i = 0; i < N; i++)
    {
        if(i == K - 1)
        {
            char c = tolower(S[i]);
            cout << c;
        }
        else
        {
            cout << S[i];
        }
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
 
using namespace std;
 
 
 
int main() {
	string input;
	cin >> input;
 
	auto result_a = input.find("AAA");
	auto result_b = input.find("BBB");
 
	if (result_a == string::npos && result_b == string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 256
while True:
  H,W = map(int,input().split())
  if H == W == 0:
    break
  for j in range(H):
    for i in range(W):
      if i==0 or i==W-1 or j==0 or j==H-1:
        print('#', end='')
      else:
        print('.', end='')
    print()
  print() 


Measured memory_bytes: 7004
from collections import defaultdict

n = int(input())
vs = list(map(int, input().split()))

evens = defaultdict(int)
odds = defaultdict(int)

for i in range(n):
    if i % 2 == 0:
        evens[vs[i]] += 1
    else:
        odds[vs[i]] += 1

evens = sorted(list(evens.items()), key=lambda x: x[1], reverse=True)
evens.append((0, 0))
odds = sorted(list(odds.items()), key=lambda x: x[1], reverse=True)
odds.append((0, 0))

if evens[0][0] != odds[0][0]:
    print(n - evens[0][1] - odds[0][1])
else:
    print(min(n - evens[1][1] - odds[0][1],
              n - evens[0][1] - odds[1][1]))

Measured memory_bytes: 18456