akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define INF 2147483647
 
using namespace std;

int main(void)
{
	int n, k, u, v;
	int G[101][101];

	cin >> n;

	memset(G, 0, sizeof(G));

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			G[u][v] = 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << G[i][j];  
			if (n != j)cout << " "; 
		}
		cout << endl;
	}

	return (0);
}

Measured memory_bytes: 1208
n=int(input())
field=[[0 for i in range(20)]for j in range(15)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    h=(b-1)*4+f-1
    w=r*2-1
    n=v
    field[h][w]+=n
for y in range(15):
    for x in range(20):
        if(y%4==3):field[y][x]='#'
        elif x%2==0 :field[y][x]=' '
        print(field[y][x],end='')
    print()

Measured memory_bytes: 7684
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
total = 0
for i in range(N+1):
    total += abs(a[i] - a[i+1])

total0 = total
for i in range(1, N+1):
    total0 -= abs(a[i] - a[i+1]) + abs(a[i-1] - a[i])
    total0 += abs(a[i-1] - a[i+1])
    print(total0)
    total0 = total


Measured memory_bytes: 20636
// AOJ 1306 Balloon Collecting
// 2018.1.31 bal4u

#include <stdio.h>
#include <string.h>

#define INF 0x30303030
#define ABS(a)  ((a)>=0?(a):-(a))

int p[41], t[41];
int dp[41][4];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, j, d, x, id, ans;
	
	while(n = in()){
		for (i = 1; i <= n; i++) p[i] = in(), t[i] = in();
		if (p[1] > t[1]) { puts("NG 1"); continue; }

		memset(dp, INF, sizeof(dp));
		dp[0][0] = 0, id = 1;
		for (i = 0; i < n; i++) for (j = 0; j < 4; j++) if (dp[i][j] < INF) {
			id = i;
			d = ABS(p[i+1]-p[i]);
			if (j < 3 && d*(j+1) <= t[i+1]-t[i]) {
				x = dp[i][j] + d;
				if (dp[i+1][j+1] > x) dp[i+1][j+1] = x;
			}
			if (p[i]*(j+1)+p[i+1] <= t[i+1]-t[i]) {
				x = dp[i][j] + p[i] + p[i+1];
				if (dp[i+1][1] > x) dp[i+1][1] = x;
			}
		}

		ans = INF;
		for (j = 0; j < 4; j++) if (dp[n][j] < ans) ans = dp[n][j];
		if (ans < INF) printf("OK %d\n", ans + p[n]);
		else printf("NG %d\n", id+1);
	}
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	char ch;
	vector<int> counter(26);
	while (cin >> ch) {
		int num = ch - 'a';
		if (0 <= num && num <= 25) counter[num]++;

		num = ch - 'A';
		if (0 <= num && num <= 25) counter[num]++;
	}

	for (int i = 0; i < counter.size(); i++) {
		cout << char(i + 'a') << " : " << counter[i] << endl;
	}
}


Measured memory_bytes: 3092
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

inline ll cal(ll a,ll b,ll x)
{
	ll p=(a*x)/b,p2=a*(x/b);
	return p-p2;
}

int main()
{
	ll a,b,n; cin>>a>>b>>n;
	ll p=n/b;
	if(p==0) cout<<cal(a,b,n);
	else
	{
		cout<<cal(a,b,p*b-1);
	}
	return 0;
}

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

using namespace std;

const int N = 2000 + 7;
int n, k, mindel[N][N], dep[N][N];
vector<int> g[N];
bool vis[N];

void dfs(int a) {
  mindel[a][0] = 1;
  vector<int> kids;
  vis[a] = 1;
  for (auto &b : g[a]) {
    if (vis[b] == 0) {
      dfs(b);
      mindel[a][0] += mindel[b][0];
      kids.push_back(b);
    }
  }
  if (kids.empty()) {
    for (int i = 1; i <= k; i++) {
      mindel[a][i] = 0;
    }
    return;
  }
  for (int len = 1; len <= k; len++) {
    mindel[a][len] = mindel[a][len - 1];
    int other = k - len;
    other = min(other, len - 1);
    for (auto &power : kids) {
      int cur = mindel[power][len - 1];
      for (auto &b : kids) {
        if (b != power) {
          cur += mindel[b][other];
        }
      }
      mindel[a][len] = min(mindel[a][len], cur);
    }
  }
}

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

  cin >> n >> k;
  k++;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  int ans = (int) 1e9;

  for (int i = 1; i <= n; i++) {
    ans = min(ans, mindel[i][k] + n - mindel[i][0]);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
    
int main(){
	int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    REP(i,x){
        cin>>a.at(i);
    }
    REP(i,y){
        cin>>b.at(i);
    }
    REP(i,z){
        cin>>c.at(i);
    }
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    reverse(ALL(a));
    reverse(ALL(b));
    reverse(ALL(c));
    //priority_queue<int> Q;
    vector<ll> ans;
    vector<ll> tmp;
    REP(i,x){
        REP(j,y){
            tmp.push_back(a[i]+b[j]);
        }
    } 
    sort(ALL(tmp));
    reverse(ALL(tmp));
    REP(i,min(k,x*y)){
        REP(j,z){
            ans.push_back(tmp[i]+c[j]);
        }
    }
    sort(ALL(ans));
    reverse(ALL(ans));
    REP(i,k){
        OUT(ans[i]);
    }
	return 0;
}

Measured memory_bytes: 43368
using System;

namespace CodeFest2016
{
	class Program
	{
		static void Main(string[] args)
		{
			var debug = false;

			var input = debug ? "CODEFESTIVAL" : Console.ReadLine();
            Console.WriteLine($"{input.Substring(0,4)} {input.Substring(4, input.Length-4)}");
		}
	}
}


Measured memory_bytes: 2648
import java.util.*;

public class Main{
    
    void solve(){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        System.out.println(x + y / 2);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 26740
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	int n;
	while(cin >> n, n) {
		int s = 32, cnt = 0, a[25] = {};
		rep(i,n) {
			cin >> a[i];
		}
		while(1) {
			s -= (s-1)%5;
			if(s<=0) {
				cout << 0 << endl;
				break;
			}
			cout << s << endl;
			s -= a[cnt%n];
			if(s<=0) {
				cout << 0 << endl;
				break;
			}
			++cnt;
			cout << s << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1156
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  s = input()
  n = len(s)
  ans = [1]*n
  for i in range(0, n-2):
    if s[i] == "R" and s[i+1] == "R":
      ans[i+2] += ans[i]
      ans[i] = 0
  for i in range(n-1, -1, -1):
    if s[i] == "L" and s[i-1] == "L":
      ans[i-2] += ans[i]
      ans[i] = 0
  print(*ans)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Measured memory_bytes: 73152
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

if l > 0:
    print(int((2 + n) * (n - 1) / 2 + (l - 1) * (n - 1)))
elif (l * -1) < n:
    print(int((1 + n) * (n - 0) / 2 + (l - 1) * (n - 0)))
else:
    print(int((1 + n - 1) * (n - 1) / 2 + (l - 1) * (n - 1)))


Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n=10;
	int[][] a;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			a=new int[n][n];
			for(int j=0; j<n; j++){
				String s=sc.next();
				for(int i=0; i<n; i++){
					a[j][i]=s.charAt(i)=='.'?0:1;
				}
			}
			solve();
		}
	}

	void solve(){
		int[][] dp=new int[n][n];
		int max=0;
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				if(a[j][i]==0){
					if(i>0&&j>0){
						int n=Math.min(dp[j-1][i-1],
								Math.min(dp[j][i-1], dp[j-1][i]));
						dp[j][i]=n+1;
					}else{
						dp[j][i]=1;
					}
				}else{
					dp[j][i]=0;
				}
				max=Math.max(max, dp[j][i]);
			}
		}
		println(""+max);
	}

	void solve_(){
		int[][] hor=new int[n][n];
		int[][] ver=new int[n][n];
		@SuppressWarnings("unchecked")
		TreeSet<P>[][] sets=new TreeSet[n][n];
		for(int j=0; j<n; j++){
			int k=0;
			for(int i=0; i<n; i++){
				if(a[j][i]==0){
					k++;
				}else{
					k=0;
				}
				hor[j][i]=k;
			}
		}
		for(int i=0; i<n; i++){
			int k=0;
			for(int j=0; j<n; j++){
				if(a[j][i]==0){
					k++;
				}else{
					k=0;
				}
				ver[j][i]=k;
			}
		}

		int max=0;

		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				if(a[j][i]==0){
					TreeSet<P> set=new TreeSet<P>();
					set.add(new P(1, 1));
					if(i>0){
						for(P p : sets[j][i-1]){
							set.add(new P(p.w+1, Math.min(ver[j][i], p.h)));
						}
					}
					if(j>0){
						for(P p : sets[j-1][i]){
							set.add(new P(Math.min(hor[j][i], p.w), p.h+1));
						}
					}
					sets[j][i]=new TreeSet<P>();
					for(P p : set){
						boolean f=true;
						for(P q : set){
							if((p.w<=q.w&&p.h<q.h)||(p.w<q.w&&p.h<=q.h)){
								f=false;
								break;
							}
						}
						if(f){
							sets[j][i].add(p);
						}
					}
					for(P p : set){
						if(p.w==p.h&&p.w>max){
							max=p.w;
						}
					}
					// debug(i, j, set);
					// debug(i, j, sets[j][i]);
				}else{
					sets[j][i]=new TreeSet<P>();
				}
			}
		}
		println(""+max);
	}

	class P implements Comparable<P>{
		int w, h;

		P(int w, int h){
			this.w=w;
			this.h=h;
		}

		@Override
		public int compareTo(P p){
			if(h!=p.h){
				return h-p.h;
			}else{
				return w-p.w;
			}
		}

		@Override
		public String toString(){
			return w+","+h;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    int ans = 0;
    for(int i=1; i<s.size(); i++){
        if(s.at(i-1)==s.at(i)) ans++;
    }

    ans = min(ans+2*k, n-1);
    cout << ans << endl;
    return 0;
}


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

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

    cout << "#" << endl;
  }
  
  for (int n = 0; n < N + 2; n++){
    cout << "#";
  }

  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=16;
int n;
vector<int>v[N][2];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;
		scanf("%d",&x);
        for(int j=1;j<=x;j++)
        {
            int y,z;scanf("%d%d",&z,&y);
            v[i][y].push_back(z);
        }
    }
    int ans=0;
    for(int i=0;i<1<<n;i++)
    {
        bool flag=true;
        for(int j=1;j<=n;j++)
        {
            bool f=true;
            for(int k=0;k<v[j][0].size();k++)
                if(1<<(v[j][0][k]-1)&i)
					f=false;
            for(int k=0;k<v[j][1].size();k++)
                if(!((1<<v[j][1][k]-1)&i))
					f=false;
            if(f&&(!(1<<(j-1)&i)))
				flag=false;
            if(!f&&(1<<(j-1)&i))
				flag=false;
        }
        if(flag) ans=max(ans,__builtin_popcount(i));
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#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>;

const int T = 26;

int main()
{
    int D;
    cin >> D;
    vector<long> c(T);
    rep(i, T) cin >> c[i];
    vector<vector<long>> s(D);
    rep(i, D) {
        s[i] = vector<long>(T);
        rep(j, T) cin >> s[i][j];
    }


    // vector<int> randomAns(D);
    // vector<int> randoms(T);
    // rep(j, T) { randoms[j] = j + 1; }
    // rep(i, D) {
    //     // シャッフル
    //     if (i % T == 0) {
    //         std::random_device seed_gen;
    //         std::mt19937 engine(seed_gen());
    //         std::shuffle(randoms.begin(), randoms.end(), engine);
    //     }

    //     randomAns[i] = randoms[i % T];
    // }


    long ansFin = 0;
    vector<long> cc(T);
    vector<long> pair;
    vector<int> donyokuAns(D);

    rep(i, T) cc[i] = -1;
    rep(i, D) {
        pair = vector<long>(T);
        rep(j, T) {
            vector<long> ccc = cc;
            long ans = ansFin;
            ans += s[i][j];
            ccc[j] = i;
            rep(k, T) {
                ans -= c[j] * (i - ccc[j]);
            }
            pair[j] = ans;
        }
        auto iter = max_element(pair.begin(), pair.end());
        auto index = distance(pair.begin(), iter);
        ansFin += pair[index];
        cc[index] = i;
        donyokuAns[i] = index + 1;
    }

    auto makeQuery = [D]() {
        return make_pair(rand() % D, rand() % T);
    };

    int oldAns = 0;
    rep(i, 100000) {
        auto qu = makeQuery();
        auto old = donyokuAns[qu.first];
        donyokuAns[qu.first] = qu.second;

        long ans = 0;
        vector<long> cc(T);
        rep(i, T) cc[i] = -1;
        rep(i, D) {
            ans += s[i][donyokuAns[i]];
            cc[donyokuAns[i]] = i;
            rep(j, T) {
                ans -= c[j] * (i - cc[j]);
            }
        }

        if (ans < oldAns) {
            donyokuAns[qu.first] = old;
        } else {
            oldAns = ans;
        }
    }

    rep(i, D) cout << donyokuAns[i] << endl;
    return 0;






    return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  vector<string> vs(3);
  for (int i = 0; i < 3; ++i) {
    cin >> vs[i];
  }

  vector<int> cur(3, 0);
  int t = 0;
  char ans;
  while (true) {
    if (cur[t] >= vs[t].size()) {
      ans = 'A' + t;
      break;
    }

    cur[t]++;
    t = vs[t][cur[t] - 1] - 'a';
  }

  cout << ans << '\n';
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>

int main() {
  char buf[128];
  scanf("%s", buf);
  std::string s = buf;

  printf("%s\n", std::string(s.length(), 'x').c_str());
}


Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const N = nextInt()
    let m = {}
    while(hasNext()){
        let tmp = next().split("").sort().join("")
        if(!m[tmp]) m[tmp] = 1
        else m[tmp]++
    }
    let ans = 0
    for(let key of Object.keys(m)){
        let tmp = m[key]
        if(tmp >1) ans += tmp*(tmp-1)/2
    }
    console.log(ans)
}
Main()


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

using namespace std;

void solve() {

    int n;
    scanf("%d", &n);
    map<int, int> cnt;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        ans += cnt[i-x];
        cnt[i+x]++;
    }
    printf("%lld\n", ans);

}

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

Measured memory_bytes: 20816
#include<stdio.h>
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
long long p[200010],q[200010],M=1e9+7;
long long aCb(int a,int b){
  //printf("%d %d\n",a,b);
  if(a<=b)return 1;
  if(b==0)return 1;
  return (p[a]*q[b])%M*q[a-b]%M;
}
int main(){
  int h,w,a,b,i;
  long long ans=0;
  scanf("%d %d %d %d",&h,&w,&a,&b);
  p[0]=1;
  for(i=1;i<200005;i++)p[i]=(p[i-1]*i)%M;
  for(i=0;i<200005;i++)q[i]=inv(p[i],M);
  for(i=0;i<h-a;i++){
    ans=(ans+(aCb(b-1+i,i)*aCb(h-i-1+w-b-1,h-i-1)%M))%M;
  }
  printf("%lld\n",ans);
  return 0;
}
    


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

int main()
{
  int s ;
  cin>>s ;
  vector<int>a ;
  a.push_back(s) ;
  
  for(int i=1;;i++){
    if(a.at(i-1)%2==0) a.push_back(a.at(i-1)/2) ;
    else a.push_back(3*a.at(i-1)+1) ;
    for(int j=0;j<i;j++){
      if(a.at(j)==a.at(i)){
        cout<<i+1<<endl ;
        return 0 ;
      }
    }
   }
  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  if(S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else{
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b,maxdep,depth[100010],check[100010],parent[100010];
vector<int> v[100010];
void dfs(int x,int d)
{
    depth[x]=d;
    check[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(!check[v[x][i]])
        {
            parent[v[x][i]]=x;
            dfs(v[x][i],d+1);
        }
    }
}
void dfs2(int x)
{
    check[x]=2;
    check[parent[x]]=2;
    maxdep=max(maxdep,depth[x]);
    for(int i=0;i<v[x].size();i++)
    {
        if(check[v[x][i]]!=2)
        {
            dfs2(v[x][i]);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(b,0);
    int u=a;
    while(depth[u]-1>depth[a]-depth[u]+1)
    {
        u=parent[u];
    }
    dfs2(u);
    printf("%d",maxdep-1);
}

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

using namespace std;

struct P{
  int year,base;
  string name;
  
  bool operator < (const P &a)const{
    if(year != a.year){
      return year < a.year;
    }
    else{
      return base < a.base;
    }
  }

  P(int y = 0,int b = 0,string s = "") : year(y),base(b),name(s){}

};

int main(){
  int N,Q,b,y;
  string str;


  while(cin >> N >> Q){
    vector<P> v;

    for(int i = 0 ; i < N ; i++){
      cin >> str >> b >> y;
      v.push_back(P(y,b,str));
    }

    sort(v.begin(),v.end());

    int in;

    for(int i = 0 ; i < Q ; i++){
      bool found = false;

      cin >> in;
      for(int j = 0 ; j < N ; j++){
	if(in <= v[j].year){ 
	  if(v[j].year-v[j].base < in){
	    cout << v[j].name << " " << in-(v[j].year-v[j].base) << endl;
	    found = true;
	    break;
	  }
	}
      }

      if(!found) cout << "Unknown" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1288
#include<stdio.h>
#include<stdlib.h>
#define N 100000
int int_sort(const void *a, const void *b){

  if (*(int *)a < *(int *)b){
    return -1;
  }else
  if (*(int *)a == *(int *)b){
    return 0;
  }
  return 1;
}

int main(){
  int *hairetu, *tmp;
  int n, i, j, fig, mp;
  int sum = 0;
  int frag = 0;
  size_t data_cnt, k;

  scanf("%d", &n);

  if((hairetu = (int *)calloc(n, sizeof(int))) == NULL){
    fprintf(stderr, "メモリエラー\n");
    return 1;
  }
  for(i = 0; i < n; i++){
    scanf("%d", &hairetu[i]);
  }
//クイックソート実装
  data_cnt = n;
  qsort((void *)hairetu, data_cnt, sizeof(hairetu[0]), int_sort);


  /*for(i = 0; i < n - 1; i++){
    for(j = n - 1; j > i; j--){
      if(hairetu[j-1] > hairetu[j]){
        mp = hairetu[j];
        hairetu[j] = hairetu[j-1];
        hairetu[j-1] = mp;
      }
    }
  }
*/
  /*for(i = 0; i < n; i++){
    printf("%d\n", hairetu[i]);
  }*/
  for(i = 0;i < n; i++){
    if(hairetu[i] > n){
      sum += n - i;
      break;
    }
    if(hairetu[i] + i < n){
      if(hairetu[i+hairetu[i]] == hairetu[i] ){
        frag = hairetu[i];
      }
    } 
    for(j = frag; hairetu[i+j] == hairetu[i]; j++){
    }

    //printf("%d", j);
    if(j > hairetu[i]){
      sum += j - hairetu[i];
    }else if(j < hairetu[i]){
      sum += j;
    }else{

    }
    i += j-1;
    frag = 0;
  }
  printf("%d", sum);
  return 0;
}


Measured memory_bytes: 892
#include <stdio.h>

int fibo[45];
int main(void){

int n;
int i;
scanf("%d",&n);
fibo[0]=1;
fibo[1]=1;
for(i=2;i<=n;i++)fibo[i]=fibo[i-1]+fibo[i-2];

printf("%d\n",fibo[n]);
return 0;
}

Measured memory_bytes: 1796
#include <iostream>
using namespace std;
static const int MAX = 100005;
static const int NIL = -1;

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

Node T[MAX];
int D[MAX], n;

void print(int u)
{
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if (T[u].p == NIL) cout << "root";
    else if (T[u].l == NIL) cout << "leaf";
    else cout << "internal node";
    cout << ", [";

    for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p)
{
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main(int argc, char const *argv[])
{
    int i, j, v, d, c;
    cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].p = T[i].l = T[i].r = NIL;
    }    
    int l;
    for (int i = 0; i < n; i++) {
        cin >> v >> d;
        for (int i = 0; i < d; i++) {
            cin >> c;
            if (i == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    int r;
    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);

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



Measured memory_bytes: 7660
#include <iostream>
#define int long long int
using namespace std;
signed main()
{
    int a, b, k;
    cin >> a >> b >> k;
    if (k <= a)
        a -= k;
    else
    {
        b -= (k - a);
        a = 0;
    }
    if (b < 0)
        b = 0;
    cout << a << " " << b << endl;
    return 0;
}


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


if n == 1 or w == 1: 
    ans = 1
elif n % 2 == 0 or w % 2 == 0:
    ans = int((n * w) / 2.)

else:
    ans = int((n * w) / 2.) + 1

print(ans)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    
    int n;
    cin >> n;
    if(n >= 400 && n <= 599){
    	cout << 8 << endl;
    } else if(n >= 600 && n <= 799) {
    	cout << 7 << endl;
    } else if(n >= 800 && n <= 999) {
    	cout << 6 << endl;
    } else if(n >= 1000 && n <= 1199) {
    	cout << 5 << endl;
    } else if(n >= 1200 && n <= 1399) {
    	cout << 4 << endl;
    } else if(n >= 1400 && n <= 1599) {
    	cout << 3 << endl;
    } else if(n >= 1600 && n <= 1799) {
    	cout << 2 << endl;
    } else if(n >= 1800 && n <= 1999) {
    	cout << 1 << endl;
    }
}



Measured memory_bytes: 3632
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])

masu = []
for i in range(n + 1):
    masu.append(False)

v = input().split()
for i in range(m):
    z = int(v[i])
    masu[z] = True

left = 0
right = 0

for i in range(x):
    if masu[i]:
        left += 1

for i in range(x, len(masu)):
    if masu[i]:
        right += 1



answer = min(left, right)
print(answer)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

class UF{
public:
  int V;
  vector<int> par,rnk,sz;
  UF(){}
  UF(int V):V(V),par(V),rnk(V,0),sz(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}

  int size(int x){return sz[find(x)];}
};



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin>>N>>M;

  UF uf(N);
  for(int i=0;i<M;i++){
    int x, y, z;
    cin>>x>>y>>z;
    x--, y--;
    uf.unite(x,y);
  }

  int ans = 0;
  for(int i=0;i<N;i++) if(uf.find(i) == i) ans++;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1408
#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>;

const int INF = 1001001001;
int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	sort(h.begin(),h.end());
	int ans = INF;
	rep(i,n-k+1){
		int sa = 0;
		sa = h[i+k-1] - h[i];
		ans = min(ans,sa);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3712
#

import sys
from copy import deepcopy
input=sys.stdin.readline

def main():
    N=int(input())
    A=[int(input()) for i in range(N)]
    B=deepcopy(A)
    B.sort()
    M=max(A)
    if A.count(M)>1:
        for i in range(N):
            print(M)
    else:
        for i in range(N):
            if A[i] == M:
                print(B[N-2])
            else:
                print(M)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 14568
import sys
import copy

sys.setrecursionlimit(1000)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N, M = LIST()

A = [[0]*(N+1) for _ in range(N+1)]

for _ in range(M):
    a, b = LIST()
    A[a][b] = A[b][a] = 1



def check(current, tovisit):
    if tovisit == []:
        return 1
    
    count = 0

    for i in tovisit:
        if A[current][i] == 1:
            tmp = copy.deepcopy(tovisit)
            tmp.remove(i)
            count += check(i, tmp)

    return count

print(check(1, list(range(2, N+1))))


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int ans = 0;
    for (int i = 1;i<=n;i++){
        if (i%3!=0 && i%5!=0)ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std ;
#define endl '\n' 

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
unordered_map<pair<int,int>,int,HASH>mp;

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

queue < pair <string , int> > que ;
int n , q ;

int main()
{
	string name ; int time ; 
	cin >> n >> q ;
	for(int i = 0 ; i < n ; i++){ 
		cin >> name >> time ;
		que.push(make_pair(name , time)) ;
	}
	
	pair <string , int> u ;
	int sum = 0 , a ;
	while(!que.empty()){ 
		u = que.front() ;
		que.pop() ;
		a = min(u.second , q) ;
		u.second -= a ;
		sum += a ;
		if(u.second > 0){ 
			que.push(u) ; // Main queue is reserved 
		} //Everything calculated in new queue ;
		else{
			cout << u.first << ' ' << sum << endl ;
		}
	} 
	return 0 ;
}



Measured memory_bytes: 6244
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <cstdlib>
using namespace std;

#define MAX(i, j) ((i) > (j)) ? (i) : (j)
#define MIN(i, j) ((i) < (j)) ? (i) : (j)
#define ABS(i) (i) < 0 ? -(i) : i
#define PI (2 * acos(0))
#define SZ 100

int main(void){

	int k,s;
	int cont=0;


	scanf("%d  %d ",&k,&s);
	for(int x=0;x<=k;x++){

			for(int y=0;y<=k;y++){
				int z=s-x-y;
								if(0<=z &&  z<=k)
									cont++;
			}
	}
	printf("%d  \n",cont);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=n;i>=0;i++)
#define all(vec) vec.begin(),vec.end()
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;

signed main() {
	int n,a,b,c,d,e;
	cin>>n>>a>>b>>c>>d>>e;
	int ans=n/min({a,b,c,d,e});
	if(n%min({a,b,c,d,e})!=0) {
		ans++;
	}
	cout<<ans+4<<endl;
}



Measured memory_bytes: 256
/**
 * auther: moririn_cocoa
 */
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main(int argc, char* argv[]) {
  
  int N;
  int K;
  int X;
  int Y;
  
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;
  
  if ( N > K ) {
    
    cout << K * X + ( N - K ) * Y << endl;
  }
  
  else {
    
    cout << N * X << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int main() {
	bool flag = false;
	for (;;) {
		int x; cin >> x;
		if (x == 0) break;
		if (flag) cout << endl;
		flag = true;
		vector<int> a(4);
		for (int i = 0; i < 4; i++) cin >> a[i];
		x = a[0] * 10 + a[1] * 50 + a[2] * 100 + a[3] * 500 - x;
		vector<int> b(4);
		b[3] = x / 500; x %= 500;
		b[2] = x / 100; x %= 100;
		b[1] = x / 50; x %= 50;
		b[0] = x / 10; x %= 10;
		vector<int> k(4);
		for (int i = 0; i < 4; i++) k[i] = max(0, a[i] - b[i]);
		if (k[0]) cout << 10 << ' ' << k[0] << endl;
		if (k[1]) cout << 50 << ' ' << k[1] << endl;
		if (k[2]) cout << 100 << ' ' << k[2] << endl;
		if (k[3]) cout << 500 << ' ' << k[3] << endl;
	}
}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int main(void){
  long N,M;
  cin >> N >> M;
  
  if(N == 1 && M == 1)
    cout << 1 << endl;
  else if(N == 1)
    cout << M - 2 << endl;
  else if(M == 1)
    cout << N - 2 << endl;
  else
    cout << (N - 2) * (M - 2) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   string s;cin>>s;
   int res = 0;
   rep(i,3)if(s[i] == '1')res++;
   cout<<res;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str1,str2;
    cin >> str1 >> str2;
    reverse(str1.begin(), str1.end());
    if(str1 == str2) cout <<"YES"<< endl;
    else cout <<"NO"<< endl;
    return 0;
}


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

using namespace std;

int main(void){
  int N;
  string S;
  cin >> N >> S;
  int r = 0;
  int b = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == 'R') r++;
    else b++;
  }
  if(r > b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,n;cin>>x>>n;
    vector<ll>v(2*n);
    FOR(i,0,n)cin>>v[i];
    FOR(i,0,n)v[n+i] = v[i]+x;
    ll ans = 1e9;
    FOR(i,0,n){
        ans = min(ans,v[n-1+i]-v[i]);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3456
let readInt () = stdin.ReadLine() |> int
let choice ok ng bool = if bool then ok else ng

readInt ()
|> fun x ->
    Array.allPairs [| 0 .. x / 4 |] [| 0 .. x / 7 |]
    |> Array.tryFind (fun (f, s) -> (f * 4 + s * 7) = x)
    |> Option.isSome
    |> choice "Yes" "No"
    |> printfn "%s"


Measured memory_bytes: 29612
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		int k=sc.nextInt();
		HashSet<String> list=new HashSet<>();
		
		for(int i=0; i<s.length(); i++){
			for(int j=1; j<=Math.min(k,s.length()-i); j++){
				list.add(s.substring(i,i+j));
			}
		}
		ArrayList<String> ll=new ArrayList<>(list);
		Collections.sort(ll);
		System.out.println(ll.get(k-1));
	}
}



Measured memory_bytes: 26964
from heapq import heappush,heappop
n,k = map(int,input().split())
kind_value = [[] for _ in range((n+1))]
for i in range(n):
    t,d = map(int,input().split())
    kind_value[t].append(d)
for li in kind_value:
    li.sort()
first_type = [(li[-1],i)for i,li in enumerate(kind_value) if li]
first_type.sort(reverse = True)
kind = 0
value_type1 = 0
second_type = []
second_type_sum = 0
second_type_cnt = 0

answer = 0
for v,i in first_type:
    kind += 1
    if kind > k:
        break
    value_type1 += v
    for d in kind_value[i][:-1]:
        heappush(second_type,d)
        second_type_sum += d
        second_type_cnt += 1
    while second_type_cnt > k-kind:
        d = heappop(second_type)
        second_type_cnt -= 1
        second_type_sum -= d
    value = kind*kind + value_type1 + second_type_sum
    if answer < value:
        answer = value

print(answer)

Measured memory_bytes: 28880
N, M = gets.split.map(&:to_i)
A = [*0..N]
c = N
$<.each{|ln|
	x, y, = ln.split.map(&:to_i)
	a, b = [x, y].map{|i| i = A[i] until i == A[i]; i }
	next if a == b
	A[x] = A[y] = A[a] = A[b] = [a, b].min
	c -= 1
}
p c


Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> A)
{
    deque<int> d;

    for (int i = 0; i < N; i++)
    {
        int p = lower_bound(d.begin(), d.end(), A[i]) - d.begin();
        if (p == 0)
        {
            d.push_front(A[i]);
        }
        else
        {
            d[p - 1] = A[i];
        }
    }
    cout << d.size() << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;

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

	string s; cin >> s;

	int k; cin >> k;

	vector<string> r;

	for (int i = 1;i <= 5;i++){
		//cout << s.substr(0,1) << endl;
		if (i > s.length()) continue;
		for (int j = 0;j <= s.length() - i;j++){
			r.push_back(s.substr(j,i));
		}
	}

	sort(r.begin(),r.end());

	int now = 0;
	int cnt = 0;
	string p = "####";

	while(1){
		if(r[now] != p){
			cnt++;
		}
		if(cnt == k) break;
		else {
			p = r[now];
			now++;
		}
	}

	cout << r[now] << endl;

	return 0;

}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 105;
int cnt, n;
#define B __int128
map <B, int> F[N];
B S;
int solve(B x, int n)
{
    if (F[n].count(x)) return F[n][x];
    int d = 1, res = 0;
    for (int l = 0; l < n; ++ l)
    {
        for (int s = 1; l + s * 2 - 1 < n; ++ s)
        {
            B y = (x >> l) & ((((B)1) << s) - 1);
            for (int c = 2; l + s * c - 1 < n; ++ c)
            {
                y &= (x >> (l + s * (c - 1)));
                res = (res + 1ll * solve(y, s) * solve(x >> (l + s * c), n - (l + s * c)) % MOD * d) % MOD;
            }
        }
        if ((x >> l) & 1) d = (d + d) % MOD;
    }
    res = (res + d) % MOD;
    return F[n][x] = res;
}
string st;
int main()
{
    cin >> st;
    for (int i = 0; i < st.size(); ++ i)
        S |= ((B)(st[i] - '0')) << i;
    cout << solve(S, st.size()) << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath> 
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[100];
    for(int i=0;i<N;i++)
        cin >> a[i];

    //M個連続
    int M = 1, j, count = 0;
    for(int i=0;i<N;i++){
        //cout << i << endl;
        for(j=i;j<N && a[j] == a[j+1];j++)
            M++;
        count += M/2;
        i = j;
        M = 1;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
int n;
struct eg{ int v,w;};
vector<eg> grf[MAXN];
int in[MAXN],out[MAXN];

void dfs1(int u,int par){
    for(auto nbr: grf[u]){
        if(nbr.v == par)continue;
        dfs1(nbr.v,u);
        in[u] = max(in[u], in[nbr.v]+nbr.w);
    }
}

void dfs2(int u,int par){
    // out[u]=0;
    int mx1=-1, mx2= -1;
    for(auto nbr : grf[u]){
        if( nbr.v == par) continue;
        if( in[nbr.v] + nbr.w>= mx1){
            mx2 = mx1; mx1= in[nbr.v]+nbr.w;
        }
        else if( in[nbr.v] +nbr.w > mx2){
            mx2 = in[nbr.v]+nbr.w;
        }
    }
    for(auto nbr: grf[u]){
        if(nbr.v == par)continue;
        int use = mx1;
        if( in[nbr.v]+nbr.w == mx1){ use=mx2; }
        out[nbr.v] =  max(out[u]+nbr.w, use+nbr.w );
        dfs2(nbr.v,u);
    }
}

int main() {
    // freopen("./input.txt","r",stdin);
    // freopen("./output.txt","w",stdout);

    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin>>n;
    for(int i=0; i<n-1; i++){
        int a,b,c; cin>>a>>b>>c;
        grf[a].push_back({b,c});
        grf[b].push_back({a,c});
    }
    dfs1(0,-1);
    dfs2(0,-1);
    for(int i=0; i<n; i++){
        cout<< max(in[i],out[i])<<"\n";
    }
}


Measured memory_bytes: 4592
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
int main()
{
    lli n;
    cin>>n;
    if(n%2==0 || n%5==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    lli cnt=0,x=7;
    while(1)
    {
        if(x%n==0)
        {
            cout<<cnt+1<<endl;
            break;
        }
        cnt++;
        x=(x%n)*10+7;
        if(cnt>=n and x%n!=0)
        {
            cout<<-1<<endl;
            break;
        }
    }

}


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

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

  
 vector<vector<int>> A(2, vector<int>(N));
 for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  int max = 0;
  for (int i = 0; i < N; i++){
    max += A.at(0).at(i);
  }
  
  max += A.at(1).at(N-1);
  int total = max;
  
  for (int i = N-1; i > 0; i--){
    total = total - A.at(0).at(i) + A.at(1).at(i-1);
    if(max < total) max = total;
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256