akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String sentence = reader.readLine();
		String[] data = sentence.split(" ");
		String longestString = "";
		HashMap<String,Integer> freq = new HashMap<String, Integer>();
		for(String elem : data){
			if (longestString.length() < elem.length()){
				longestString = elem;
			}
			if(freq.containsKey(elem)){
				freq.put(elem, freq.get(elem)+1);
			}else{
				freq.put(elem, 1);
			}
		}
		Entry<String,Integer> maxEntry = null;
		for(Entry<String,Integer> entry : freq.entrySet()) {
		    if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
		        maxEntry = entry;
		    }
		}
		System.out.println(maxEntry.getKey() + " " + longestString);

	}

}

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

int main(void){
  char S[100000];
  int T[100000] = {0};
  int counter = 1;
  scanf("%s",S);
  int i,j;

  for(i=0;i<strlen(S);i++){
    if(S[i] == 'e' &&S[i+1] == 'r'&&S[i+2] == 'a'&&S[i+3] == 's'&&S[i+4] == 'e'&&S[i+5] == 'r'){
      for(j=0;j<=5;j++){ T[i+j] = 1;}
      }else if(S[i] == 'e' &&S[i+1] == 'r'&&S[i+2] == 'a'&&S[i+3] == 's'&&S[i+4] == 'e'){
        for(j=0;j<=4;j++){ T[i+j] = 1; }
      }else if(S[i] == 'd' &&S[i+1] == 'r'&&S[i+2] == 'e'&&S[i+3] == 'a'&&S[i+4] == 'm'&&S[i+5] == 'e'&&S[i+6] == 'r'){
        for(j=0;j<=6;j++){ T[i+j] = 1; }
        }else if(S[i] == 'd' &&S[i+1] == 'r'&&S[i+2] == 'e'&&S[i+3] == 'a'&&S[i+4] == 'm'){
          for(j=0;j<=4;j++){ T[i+j] = 1; }
        }
      }

    for(i=0;i<strlen(S);i++){
      counter *= T[i];
    }
    if(counter == 1){
      printf("YES\n");
    }else printf("NO\n");

    return 0;
}


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

#define INF 1000000000
using namespace std;

struct edge {
    int from;
    int to;
    int w;
};
struct node {
    node() : id {-1}, d {INF}, ns {} {};
    node(int i, vector<edge>& vec) : id {i}, d {INF}, ns {vec} {};
    int id;
    int d;
    vector<edge> ns;
};

vector<int> dijkstra(node* graph, int n, int st){
    auto ds = vector<int>(n, INF);
    auto comp = [](node* x, node* y){return x->d > y->d;};
    priority_queue<node*, vector<node*>, decltype(comp)> que(comp);
    node* start = &graph[st];
    start->d = 0;
    que.push(start);
    while(que.size()){
        node* n = que.top();
        //cout << n->id << ' ' << n->d << endl;
        que.pop();
        if(n->d < ds[n->id]){
            ds[n->id] = n->d;
            for(auto e : n->ns){
                node* next_n = &graph[e.to];
                if(ds[next_n->id] < INF){
                    continue;
                }
                next_n->d = min(next_n->d, n->d + e.w);
                que.push(next_n);
            }
        }
    }
    return ds;
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n;
    cin >> n;
    node graph[n];
    for(int i = 0; i < n; ++i){
        int id;
        int m;
        cin >> id >> m;
        auto vec = vector<edge>(m);
        int v, c;
        for(int j = 0; j < m; ++j){
            cin >> v >> c;
            vec[j] = edge {id, v, c};
        }
        graph[id] = node(id, vec);
    }
    auto ds = dijkstra(graph, n, 0);
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << ds[i] << endl;
    }
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, x, y;
	int ans[2000];
	for(int i = 0;i < 2000;i++){
		ans[i] = 0;
	}
	cin >> n >> x >> y;
	x--;
	y--;
	for(int i = 0;i < n - 1;i++){
		for(int j = i;j < n;j++){
			if(j <= x || i >= y){
				ans[j - i]++;
			}else{
				ans[min(j - i, abs(x - i) + 1 + abs(j - y))]++;
			}
		}
	}
	for(int i = 1;i < n;i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)

if x - k * d >= 0:
    print(x - k * d)
elif x % d == 0:
    k -= x // d
    if k % 2 == 0:
        print(0)
    else:
        print(d)
else:
    k -= x // d
    x %= d
    if k % 2 == 0:
        print(x)
    else:
        print(d - x)
    


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
    ll res=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
    return res*f;
}
void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10|'0');
}
int n,a[55],b[55],c[55];

int ans;
signed main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++) b[i]=read(),ans+=b[i];
    for(int i=1;i<=n-1;i++) c[i]=read();
    for(int i=1;i<=n;i++)if(a[i]==a[i+1]-1) ans+=c[a[i]];
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    // sort(A.begin(), A.end());
    // vector<int> B = A;
    // B.erase(unique(B.begin(), B.end()), B.end());
    map<int, int> C;
    for(int x : A) C[x] ++;

    int ans = C.size();

    int sum = 0;
    for(auto p : C) {
        sum += p.second - 1;
    }

    if(sum % 2 == 1) ans--;

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 5376
import java.io.*;
import java.util.ArrayList;
public class Main{
	public static void main(String args[]){
    int a=0,b=0,c=0,i=0,j=0,k=0,minj=0;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    ArrayList<Integer> SortArray = new ArrayList<Integer>();
    try{
      String line = reader.readLine();
      b = Integer.parseInt(line);
      line = reader.readLine();
      for(String splitted: line.split(" ")){
        SortArray.add(Integer.parseInt(splitted));
      }
		}catch(Exception e){
    }

    int sortArray[] = new int[b];
    for(k = 0;k < b; k++){
      sortArray[k] = SortArray.get(k);
    }

  for(i = b-1;i >= 0;i--){
    System.out.print(sortArray[i]);
    if(i == 0){
    }else{
      System.out.print(" ");
    }
  }
  System.out.print("\r\n");

  }
}


Measured memory_bytes: 24428
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;
const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true, flag = false;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };
string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	int c[100] = { 0 }, p = -1;
	string s;
	cin >> s;
	char C = s[s.size() - 1];
	for (int i = 0;i < s.size();i++) {
		c[s[i] - 'a']++;
	}
	for (int i = 0;i < 26;i++) {
		if (c[i] == 0)fl = false;
	}
	if (fl) {
		if (s == "zyxwvutsrqponmlkjihgfedcba") {
			cout << -1 << endl;
			exit(0);
		}
		for (int i = s.size() - 1;i > 0;i--) {
			if (s[i - 1] - s[i] > 0) {
				if (C > s[i])C = s[i];
			}
			else {
				p = i - 1;
				char h = s[p];
				int cou[100] = { 0 };
				for (int j = 0;j <= p;j++) {
					cou[s[j] - 'a']++;
				}
				for (int j = 25;j > p;j--) {
					if (s[j] > h&&s[p] == h)s[p] = s[j];
					else if (s[j] > h&&s[p] > s[j])s[p] = s[j];
				}
				break;
			}
		}
		if (p != -1) {
			for (int i = 0;i <= p;i++)cout << s[i];
			cout << endl;
		}
		else cout << -1 << endl;
	}
	else{
		for (int i = 0;i < 26;i++) {
			if (c[i] == 0) {
				s += i + 'a';
				break;
			}
		}
		cout << s << endl;
	}
	
	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
}

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

int main(){
  string L[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string S;
  cin >> S;
  rep(i,7){
    if(S == L[i]){
      cout << (7-i) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(){
  int n,a,b;
  std::cin >> n >>a >>b;

  int d=0;
  int arank=0;
  rep(i,n){
      char c;
      bool ok=false;
      std::cin >> c;

      if(c=='b'){
        arank++;
        if(arank<=b && d<a+b){ok=true;}
      }else if(c=='a'){
        if(d<a+b)ok=true;
      }

      if(ok){std::cout << "Yes" << '\n';d++;}
      else std::cout << "No" << '\n';


  }

  return 0;
}


Measured memory_bytes: 640
n, k = map(int, input().split())
if k %2 !=0:
    num = n // k
    print(num**3)
else:
    num1=  n // k
    num2 = 0
    for i in range(1, n+1):
        if i % k == int(k/2):
            num2+=1
    print(num1**3 + num2**3)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string.h>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace std;

class node{
public:
  double x, y;
};

void koch(int i, node p1, node p2){
  if(i == 0) return;

  node s, u, t;

  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (2 * p2.x + 1 * p1.x) / 3;
  t.y = (2 * p2.y + 1 * p1.y) / 3;

  u.x = (t.x - s.x) * cos((double)1/3*M_PI) - (t.y - s.y) * sin((double)1/3*M_PI) +s.x;
  u.y = (t.x - s.x) * sin((double)1/3*M_PI) + (t.y - s.y) * cos((double)1/3*M_PI) +s.y;

  koch(i - 1, p1, s);
  cout << s.x << " " << s.y << endl;
  koch(i - 1, s, u);
  cout << u.x << " " << u.y << endl;
  koch(i - 1, u, t);
  cout << t.x << " " << t.y << endl;
  koch(i - 1, t, p2);
}

int main(){

  int n;
  cin >> n;

  node p1;
  p1.x = 0;
  p1.y = 0;
  node p2;
  p2.x = 100;
  p2.y = 0;
  cout << p1.x << " " << p1.y << endl;
  koch(n, p1, p2);
  cout << p2.x << " " << p2.y << endl;
  return 0;

}


Measured memory_bytes: 3288
#!/usr/bin/env python3
import sys


def solve(N: int):
    res = 0
    for i in range(1, N+1):
        if len(str(i)) % 2 == 1:
            res += 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39920
<?php
  fscanf(STDIN,"%d %d",$n,$l);
  $aji = [];
  for($i=1; $i<=$n; $i++){
    $aji[] = $l+$i-1;
  }
  $sa = [];
  for($i=0; $i<$n; $i++){
    $sa[] = abs(0-$aji[$i]);
  }
  $total = 0;
  for($i=0; $i<$n; $i++){
    if(min($sa) != abs(0-$aji[$i])){
      $total += $aji[$i];
    }
  }
  
  echo $total."\n";
  

Measured memory_bytes: 4856
#include <iostream>

using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
char field[51][51];
int w, h;
bool b_flag;
bool w_flag;
int count;

void dfs1(int y, int x)
{
	if(y < 0 || h <= y || x < 0 || w <= x || field[y][x] == '#')
	{
		return;
	}
	else
	{
		if(field[y][x] == 'W')
		{
			w_flag = true;
			return;
		}
		else if(field[y][x] == 'B')
		{
			b_flag = true;
			return;
		}
		else if(field[y][x] == '.')
		{
			field[y][x] = '#';
			++count;
		}
	}
	for(int i = 0; i < 4; ++i)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		dfs1(ny, nx);
	}
}

void solve()
{
	while(cin >> w >> h, w || h)
	{
		for(int i = 0; i < h; ++i)
		{
			for(int j = 0; j < w; ++j)
			{
				cin >> field[i][j];
			}
		}
		int b_count = 0, w_count = 0;
		for(int i = 0; i < h; ++i)
		{
			for(int j = 0; j < w; ++j)
			{
				if(field[i][j] == '.')
				{
					count = 0;
					b_flag = false;
					w_flag = false;
					dfs1(i, j);
					if(b_flag == true && w_flag == false)
					{
						b_count += count;
					}
					else if(b_flag == false && w_flag == true)
					{
						w_count += count;
					}
				}
			}
		}
		cout << b_count << " " << w_count << endl;
	}
}

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

Measured memory_bytes: 1232
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val Xs = readInputLine().split(" ").map {it.toInt()}.toList()
    
    val (lower, higher) = Xs.sorted().toIntArray().let {Pair(it[N / 2 - 1], it[N / 2])}
    
    for (x in Xs) {
        if (x >= higher) {
            println(lower)
        } else {
            println(higher)
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 98852
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 5e5+6;
const ll inf =1e12;

ll a[MAX],nl[MAX],ac[MAX];

int main(){
	fastio;
	ll n;
	cin>>n;
	f(i,0,n+1) cin>>a[i];
	af(i,n,0) ac[i]=a[i]+ac[i+1];
	if(n==0 ){
		if(a[0]==1) cout<<"1\n";
		else cout<<"-1\n";
		return 0;
	}
	if(a[0]!=0){
		cout<<"-1\n";
		return  0;
	}
	nl[0]=1;
	f(i,1,n+1){
		if(a[i]>2*(nl[i-1])){
			cout<<"-1\n";
			return 0;
		}
		nl[i]=min(ac[i+1],2*(nl[i-1]) -a[i])	;
	}
	ll ans=0;
	f(i,0,n+1) ans+=(a[i]+nl[i]);
	cout<<ans<<endl;
}


 

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

int main()
{
	long long n;
	cin >> n;
	long long ret = 0;
	for (long long i = 1; i <= n; ++i) {
		if (i % 3 != 0 && i% 5 != 0) {
			ret += i;
		}
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (100010)

int main()
{
	int N, K;
	scanf("%d%d", &N, &K);

	pair<int, int> sushi[MAX_N];
	for (int i = 0; i < N; i++)
		scanf("%d%d", &sushi[i].second, &sushi[i].first);
	sort(sushi, sushi + N, greater<pair<int, int>>());

	map<int, int> sushi_type;
	ll min_delicious = 0;
	priority_queue<int, vector<int>, greater<int>> candidates;
	for (int i = 0; i < K; i++) {
		if (sushi_type.count(sushi[i].second) > 0) {
			candidates.push(sushi[i].first);
		}
		sushi_type[sushi[i].second]++;
		min_delicious += (ll)sushi[i].first;
	}

	ll min_type_num = sushi_type.size();
	min_delicious += min_type_num * min_type_num;

	priority_queue<int, vector<int>> additional_types;
	for (int i = K; i < N; i++) {
		if (sushi_type.count(sushi[i].second) == 0) {
			additional_types.push(sushi[i].first);
		}
		sushi_type[sushi[i].second]++;
	}

	ll res = min_delicious;
	ll prev = min_delicious;
	for (int k = min_type_num + 1; k <= K; k++) {
		if (candidates.size() < 1 || additional_types.size() < 1)
			break;

		ll local = prev;
		local -= (ll)candidates.top(); candidates.pop();
		local += (ll)additional_types.top(); additional_types.pop();

		local -= (ll)(k - 1) * (ll)(k - 1);
		local += (ll)k * (ll)k;

		res = max(res, local);
		prev = local;
	}

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

	return 0;
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int n;
    cin >> n;
    V<int> p(n), x(n), mn(n);
    V<bitset<5050>> b(n, 1);
    FOR(i, 1, n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) cin >> x[i];
    FORR(i, n) {
        int mx = x[i];
        while(mx >= 0 && !b[i][mx])
            mx--;
        if(mx < 0) {
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        mn[i] -= mx;
        b[p[i]] = b[p[i]] << x[i] | b[p[i]] << mn[i];
        mn[p[i]] += x[i] + mn[i];
    }
    cout << "POSSIBLE" << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    vector<tuple<ll,ll,ll>> v;
    for(int i=0;i<n;++i){
        ll x,y,z;
        cin>>x>>y>>z;
        v.emplace_back(x,y,z);
    }
    ll ret = 0ll;
    for(int mask=0;mask<1<<3;++mask){
        vector<int> bi(3,1);
        for(int i=0;i<3;++i){
            if((mask>>i)&1) bi[i] = -1;
        }
        sort(v.begin(),v.end(),[&](auto a,auto b){
            ll ax,ay,az;
            tie(ax,ay,az) = a;
            ll bx,by,bz;
            tie(bx,by,bz) =b;
            
            return (ax*bi[0] + ay*bi[1] + az*bi[2]) > (bx*bi[0] + by*bi[1] + bz*bi[2]);
        });
        ll x{},y{},z{};
        for(int i=0;i<m;++i){
            ll xi,yi,zi;
            tie(xi,yi,zi) = v[i];
            x += xi;
            y += yi;
            z += zi;
        }
        ret = max(ret,abs(x) + abs(y) + abs(z));
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;

struct DATA{
  int number;
  int count;
};

bool Compare(const DATA&, const DATA&);

int main(){
  int i, j, n, m, x;
  DATA onedata;
  vector<DATA> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<m; ++i){
      onedata.number = i+1;
      onedata.count = 0;
      data.push_back(onedata);
    }

    for(i=0; i<n; ++i){
      for(j=0; j<m; ++j){
        cin >> x;
        if(x == 1) ++data[j].count;
      }
    }

    sort(data.begin(), data.end(), Compare);

    for(i=0; i<data.size()-1; ++i)
      cout << data[i].number << " ";
    cout << data[data.size()-1].number << endl;

    data.clear();
  }

  return 0;
}

bool Compare(const DATA& x, const DATA& y){
  if(x.count == y.count)
    return (x.number < y.number);
  else
    return (x.count > y.count);
}

Measured memory_bytes: 0
#include<cstdio>
using namespace std;
int abs(const int &x)
{
	if(x < 0)	return -x;
	return x;
}
int main()
{
	int aj,bj,a,b;
	bool af,bf;
	scanf("%d%d",&a,&b);
	aj = abs(a);
	bj = abs(b);
	if(a > 0)
		af = 1;
	else
		af = 0;
	if(b > 0)
		bf = 1;
	else
		bf = 0;
	if(aj == 0 && bj != 0)
	{
		if(bf)
			printf("%d",bj);
		else
			printf("%d",bj + 1);
	}
	else if(aj != 0 && bj == 0)
	{
		if(af)
			printf("%d",aj + 1);
		else
			printf("%d",aj);
	}
	else if(aj == 0 && bj == 0)
	{
		printf("0");
	}
	else if(af ^ bf)
	{
		printf("%d",abs(aj - bj) + 1);
	}
	else
	{
		if(af)
		{
			if(aj <= bj)
				printf("%d",bj - aj);
			else
				printf("%d",aj - bj + 2);
		}
		else
		{
			if(aj >= bj)
				printf("%d",aj - bj);
			else
				printf("%d",bj - aj + 2);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main() {
  int n,a[10000],b[10000],i;
  long long x=0,y=0,l=0,m=0,z;
  scanf("%d",&n);
  for (i=0;i<n;i++) {
    scanf("%d",&a[i]);
    x+=a[i];
  }
  for (i=0;i<n;i++) {
    scanf("%d",&b[i]);
    y+=b[i];
    if (a[i]>=b[i]) {
      l+=a[i]-b[i];
    } else {
      m+=(b[i]-a[i])/2+(b[i]-a[i])%2;
    }
  }
  z=y-x;
  if (z<0) {
    printf("No\n");
  } else if (m<=y-x&&l<=y-x) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main () {
	string str;
	getline(cin, str);
	for (int i=0; i<str.length(); i++) {
		if (65 <= str[i] && str[i] <= 90) str[i] += 32;
		else if (97 <= str[i] && str[i] <= 122) str[i] -= 32;
	}
	cout << str << endl;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define vll         vector<pll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
const int N=1e6+6;
vl prime;
bool p[N];

void sieve()
{
    memset(p,1,sizeof p);
    for(ll i=2; i<=N; i++){
        if(p[i]){
            prime.pb(i);
            for(ll j=2*i; j<=N; j+=i)
                p[j]=0;
        }
    }
}

void solve()
{
    ll n,k; cin>>n>>k;
    if(n==1) { cout<<k; exit(0); }
    sieve();
    ll ans=1;
    for(ll x:prime){
        ll res=0,tmp=k;
        while(tmp%x==0) { tmp/=x; res++; }
        if(res>=n){
            rep(i,0,res/n) ans*=x;
        }
    }
    cout<<ans;
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define showdp(d,n,m) fab(i,0,n){ fab(j,0,m) if(d[i][j]==-1 || d[i][j]>9) cout<<d[i][j]<<" "; else cout<<" "<<d[i][j]<<" "; cout<<endl; }
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
#define N 300005
#define inf 1e18+7
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}
 
bool isPrime(ll p)
{
    for(ll i=2;i*i<=p;i++)
        if(p%i==0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n+1];
    memset(prime,true,sizeof(prime));
    for(ll i=3;i*i<=n;i+=2)
        if(prime[i])
            for(ll j=i;j*i<=n;j+=2)
                prime[j*i]=false;
        
    for(ll i=3;i<=n;i+=2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result=n;
    for(ll p=2;p*p<=n;p++)
    {
        if(n%p==0)
        {
            while(n%p==0)
                n/=p;
            result-=result/p;
        }
    }

    if(n>1)
        result-=result/n;
    return result;
}


int main()
{
	sup;
    
    ll n,m;
    cin>>n>>m;
    if(m>=n) cout<<"Yes";
    else cout<<"No";
	
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self, idx):
    self.idx = idx
    self.edges = []
    self.sign = None


def main():
  N, M = map(int, input().split())
  nodes = [Node(i + 1) for i in range(N)]

  for _ in range(M):
    a, b = map(int, input().split())
    nodes[a - 1].edges.append(nodes[b - 1])
    nodes[b - 1].edges.append(nodes[a - 1])

  nodes[0].sign = 0
  count = 1

  queue = collections.deque()
  queue.append(nodes[0])

  while len(queue) != 0:
    n = queue.popleft()

    for e in n.edges:
      if e.sign is None:
        e.sign = n.idx
        count += 1
        queue.append(e)

  if count == len(nodes):
    print('Yes')
    for n in nodes[1:]:
      print(n.sign)
  else:
    print('No')


if __name__ == '__main__':
  main()


Measured memory_bytes: 99748
import numpy as np
X, N = list(map(int, input().split()))
try:
	p = np.array(list(map(int, input().split())))
except EOFError:
    print(X)
    exit()
I = np.arange(0, 102)
indices = np.argsort(np.abs(I - X), kind='stable')
for idx in indices:
    if I[idx] not in p:
        print(I[idx])
        break

Measured memory_bytes: 27424
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const long MOD = 1000000007;

int N, C;
int D[31][31];
int t[3][31];

int calc(int a, int b, int c) {
  int value = 0;
  for (int i = 1; i <= C; i++) {
    value += t[0][i] * D[i][a];
  }
  for (int i = 1; i <= C; i++) {
    value += t[1][i] * D[i][b];
  }
  for (int i = 1; i <= C; i++) {
    value += t[2][i] * D[i][c];
  }
  return value;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> C;
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j <= C; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      int c;
      cin >> c;
      t[(i + j) % 3][c]++;
    }
  }

  int ans = INT_MAX;
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j <= C; j++) {
      if (i == j) {
        continue;
      }
      for (int k = 1; k <= C; k++) {
        if (i == k || j == k) {
          continue;
        }

        ans = min(ans, calc(i, j, k));
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <cmath>
using namespace std;

double readReal(void) {
	double d;
	cin >> d;
	return d;
}
void println(void) {
	cout << endl;
}
void printFixed(double d, int digit) {
	cout << fixed << setprecision(digit) << d;
}
void printlnFixed(double d, int digit) {
	printFixed(d, digit);
	println();
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double x1 = readReal();
	double y1 = readReal();
	double dist_x = x1 - readReal();
	double dist_y = y1 - readReal();

	double distance = sqrt(dist_x * dist_x + dist_y * dist_y);
	printlnFixed(distance, 5);
	return 0;
}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll X;
  cin >>N>>X;
  
  vl x(N+1);
  rep(i,N) {
cin >>x.at(i);
  }
  x.at(N)=X;
  sort(all(x));
  vl vec(N);
  rep(i,N) {
vec.at(i)=x.at(i+1)-x.at(i);
  }
  sort(all(vec));
  ll xa=vec.at(0);
 rep(i,N) {
   xa=__gcd(xa,vec.at(i));
 }
  cout<<xa<<endl;
}
  
  

Measured memory_bytes: 1792
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  string s;
  cin>>s;
  int ln=s.length();
  int ct=0;
  for(i=0;i<ln/2;i++){
    if(s[i]=='i'||s[i]=='w'){
      if(s[i]!=s[ln-i-1])
	ct++;
    }else{
      if(s[ln-i-1]=='i'||s[ln-i-1]=='w'||s[i]==s[ln-i-1])
	ct++;
    }
  }
  if(ln%2){
    if(s[ln/2]=='('||s[ln/2]==')')
      ct++;
  }
  cout<<ct<<endl;
  return 0;
}

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


int main(){ 
int n,m;
cin>>n>>m;
vector<int>h(n+1);
for(int i=1;i<=n;++i)
cin>>h[i];
vector<vector<int>> v(n+1);
for(int i=1;i<=m;++i){
    int a,b;
    cin>>a>>b;
    v[a].push_back(h[b]);
    v[b].push_back(h[a]);

}
int cnt=0;
for(int i=1;i<=n;++i){
    int mark=0;
for(int j=0;j<v[i].size();++j){
    if(h[i]<=v[i][j])
    break;
    else ++mark;
}
if(mark==v[i].size())
++cnt;
}
cout<<cnt;
    return 0;
}



Measured memory_bytes: 8804
#include <stdio.h>

const int inf = -1;
int leaf[100001];

typedef struct {
	int left, right, max;
} seg_node;

void init_node(seg_node v[], int k, int l, int r)
{
	v[k].left = l;
	v[k].right = r;
	v[k].max = inf;
	if (l < r) {
		init_node(v, k << 1, l, (l + r) / 2);
		init_node(v, (k << 1) ^ 1, (l + r) / 2 + 1, r);
	} else leaf[l] = k;
}

void update_node(seg_node v[], int k, int x)
{
	int i, j = leaf[k];
	v[j].max = x;
	for (i = j >> 1; i > 0; j = i, i >>= 1) v[i].max = (v[j].max > v[j^1].max)? v[j].max: v[j^1].max;
}

int BS_left(seg_node v[], int k, int l, int r, int x)
{
	int tmp;
	if (v[k].max < x || v[k].right < l || v[k].left > r) return r + 1;
	else if (v[k].left == v[k].right) return v[k].left;
	else {
		tmp = BS_left(v, k << 1, l, r, x);
		if (tmp <= r) return tmp;
		else return BS_left(v, (k << 1) ^ 1, l, r, x);
	}
}

int BS_right(seg_node v[], int k, int l, int r, int x)
{
	int tmp;
	if (v[k].max < x || v[k].right < l || v[k].left > r) return l - 1;
	else if (v[k].left == v[k].right) return v[k].left;
	else {
		tmp = BS_right(v, (k << 1) ^ 1, l, r, x);
		if (tmp >= l) return tmp;
		else return BS_right(v, k << 1, l, r, x);
	}
}

int main()
{
	int i, N, P[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	
	seg_node v[300001];
	init_node(v, 1, 1, N);
	for (i = 1; i <= N; i++) update_node(v, i, P[i]);
	
	int l[2], r[2];
	long long ans = 0;
	for (i = 1; i <= N; i++) {
		l[0] = BS_right(v, 1, 1, i - 1, P[i]);
		l[1] = BS_right(v, 1, 1, l[0] - 1, P[i]);
		r[0] = BS_left(v, 1, i + 1, N, P[i]);
		r[1] = BS_left(v, 1, r[0] + 1, N, P[i]);
		ans += ((long long)(i - l[0]) * (r[1] - r[0]) + (long long)(r[0] - i) * (l[0] - l[1])) * P[i];
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5532
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		cnt[scanInt()]++
	}

	c := []int{}
	for _, e := range cnt {
		c = append(c, e)
	}

	sort.Ints(c)

	s := make([]int, len(c)+1)
	for i := 0; i < len(c); i++ {
		s[i+1] += s[i] + c[i]
	}

	p := 1
	for i := n; i >= 1; i-- {
		idx := sort.Search(len(c), func(idx int) bool { return i <= c[idx] })
		t := (s[idx] + i*(len(c)-idx)) / i
		for t >= p {
			fmt.Fprintln(wr, i)
			p++
		}
	}
	for i := p; i <= n; i++ {
		fmt.Fprintln(wr, 0)
	}
}


Measured memory_bytes: 28672
using System;
using System.Collections.Generic;

class AOJ
{

    public static void Main()
    {
        string str;
        int[] a = new int[10] {1,2,4,8,16,32,64,128,256,512};


        while ((str = Console.ReadLine()) != null)
        {

            int n = int.Parse(str);
            List<int> b = new List<int>();

            while (n != 0)
            {
                for (int i = 9; i >= 0; i--)
                {
                  if (a[i] <= n)
                    {
                        n -= a[i];
                        b.Add(i);
                    }
                }
            }

            b.Sort();

            for (int i = 0; i < b.Count; i++)
            {
                Console.Write(a[b[i]]);
                if (i != b.Count - 1)
                    Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5768
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 30, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int div2count(int n) {
  int ret = 0;
  if (!n) return 0;
  for (;;) {
    if (n & 1) {
      return ret;
    }
    ret++;
    n >>= 1;
  }
}
void solve() {
  ;
  ;
  // auto gcd = [](int a, int b) { return b ? gcd(a % b, a) : a; };
  // auto lcm = [](int a, int b) { return a * b / gcd(a, b); };
  each(x, va) {
    x >>= 1;  // ぐうすうなので
  }
  //

  int cnt2 = div2count(va[0]);
  for (auto x : va) {
    if (cnt2 != div2count(x)) {
      cout << 0 << endl;
      return;
    }
  }

  int al = 1;
  rep(i, 0, N - 1) {
    al = lcm(al, va[i]);
    // debug2(i, al);
  }
  if (al > M) {
    cout << 0;
    return;
  }
  if (M / al % 2 == 1) {
    cout << M / al / 2 + 1 << endl;
    return;
  } else {
    cout << M / al / 2 << endl;
  }

  // //  al = accumulate(all(va), 1, lcm);
  // auto isOK = [&](int mid, int key) {
  //   return al * mid + al / 2 <= M;  // for now
  // };
  // auto binary_search = [&](int key) {
  //   int ng = INF;
  //   int ok = -1;
  //   while (abs(ok - ng) > 1) {
  //     int mid = (ok + ng) >> 1;
  //     (isOK(mid, key) ? ok : ng) = mid;
  //   }
  //   return ok;
  // };
  // int kk = binary_search(0);
  // cout << kk + 1 << endl;
  // M += al;
  // cout << M / 2 / al << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
#include <fstream>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e9 
typedef long long ll;
typedef long double ld;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(n,vector<int> (2));
    REP(i,n){
        cin>>v[i][0]>>v[i][1];
    }
    int cnt=0;
    bool is=false;
    REP(i,n){
        if(v[i][0]==v[i][1]){
            cnt++;
        }else{
            cnt=0;
        }
        if(cnt>=3){
            is=true;
            break;
        }
    }
    cout<<(is?"Yes":"No")<<endl;
    return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int k,n;
int solve(){
    int ans=0;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    int mx = k-a[n-1]+a[0];
    rep(i,n-1){
        chmax(mx, a[i+1]-a[i]);
    }
    return k-mx;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    while(cin >> k >> n){
        int ans = 0;
        cout << solve() << endl;
        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// 2???????????????????????????????±???????
double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if( cross(b,c) > EPS ) return +1;
    if( cross(b,c) < -EPS ) return -1;
    if( dot(b,c) < 0 ) return +2;
    if( norm(b) < norm(c) ) return -2;
    return 0;
}

// ???????§???¢????????¨?????? O(n)
int inPolygon(P p, const vector<P> &ps) {
    int n = ps.size();
    bool in = false;
    rep(i,0,n) {
        P a = ps[i] - p;
        P b = ps[(i+1) % n] - p;
        if(EQ(cross(a,b), 0) && LE(dot(a,b), 0)) return 2;
        if(a.Y > b.Y) swap(a,b);
        if((a.Y * b.Y < 0 || (a.Y * b.Y < EPS && b.Y > EPS)) && LE(cross(a,b), 0)) in = !in;
    }
    return in;
}

int main() {
    int n; cin >> n;
    vector<P> ps;
    P a;
    rep(i,0,n) {
        cin >> a.X >> a.Y;
        ps.pb(a);
    }

    map<int, int> d;
    d[2] = 1;
    d[1] = 2;

    int m; P b;
    cin >> m;
    rep(i,0,m) {
        cin >> b.X >> b.Y;
        cout << d[inPolygon(b, ps)] << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a[N*3];
  for (int i = 0; i < N * 3; i++) cin >> a[i];
  sort(a, a + N * 3, greater<int>());
  long ans = 0;
  for (int i = 0; i < N * 2; i++) {
    if (i % 2 == 1) ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int K,N=0;
  cin >> K >> N;
  int A[N];
    for (int i = 0; i < N; i++) {
    cin >> A[i];
//    cout << A[i] << endl;
  }
  
  int max = 0;
  for (int i = 0; i < N; i++) {
    if(i==0){
      max = abs(K -(A[N-1] - A[0]));
//    continue;
    }else{
      if(max < A[i] - A[i-1]){
      max = A[i] - A[i-1];
      }
    }
//      cout << "max  " << i << " = " << max << endl;  
  }
//  cout << "result : " << K - max << endl;
  cout << K - max << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        String ans = "No";
        String S = sc.next();
        String[] s;
        try {
            s = S.split("-");
            if(s.length == 2) {
                if(s[0].length() == a && s[1].length() == b) {
                    ans = "Yes";
                } 
            }
            System.out.println(ans);
        }catch(Exception e) {
            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;
using un = unsigned;

int main()
{
	int n; 
	cin >> n;
	int md = n % 10;
	switch(md)
	{
	case 2: case 4: case 5: case 7: case 9:
		cout << "hon";
		break;
	case 0: case 1: case 6: case 8:
		cout << "pon";
		break;
	case 3:
		cout << "bon";
		break;
	}
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main (void){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if((x-r)>=0 && (y-r)>=0 && (x+r)<=w && (y+r)<=h){
        printf("Yes\n");
    }
    else{
        printf("No\n");
        
    }
    return 0;
}


Measured memory_bytes: 2132
P = 2019


def main():
    S = [int(s) for s in input()[::-1]]
    N = len(S)
    A = [0]*N
    d = 1
    for i, s in enumerate(S):
        A[i] = (s * d) % P
        d *= 10
        d %= P
    ans = 0
    from collections import Counter
    acc = [0]*(N+1)
    for i in range(N):
        acc[i+1] = acc[i] + A[i]
        acc[i+1] %= P
    c = Counter(acc)
    for v in c.values():
        ans += v*(v-1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78676
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
#define INF 1LL << 60
#define MAX 100000
#define MAX_LOG 17// 5/log10_2
vector<pair<int, ll>> G[MAX];
int parent[MAX_LOG][MAX];
ll depth[MAX], depth2[MAX];
void dfs(int v, int p, ll d, int d2) {
	parent[0][v] = p;
	depth[v] = d;
	depth2[v] = d2;
	rep(i, 0, G[v].size()) {
		if (G[v][i].first != p)dfs(G[v][i].first, v, d + G[v][i].second, d2 + 1);
	}
}
void init(int root, int V) {
	dfs(root, -1, 0, 0);//parent[0]だけ初期化
	rep(k, 0, MAX_LOG - 1) {
		rep(v, 0, V) {
			if (parent[k][v] < 0)parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}
int lca(int u, int v) {
	if (depth2[u] > depth2[v])swap(u, v);
	rep(k, 0, MAX_LOG) {
		if ((depth2[v] - depth2[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if (u == v)return u;
	//u,vを同時にあげる
	for (int k = MAX_LOG - 1; k >= 0; k--) {
		if (parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}
int main() {
	int N, Q, a, b, c, K;
	vector<ll> ans;
	scanf("%d", &N);
	rep(i, 0, N - 1)scanf("%d%d%d", &a, &b, &c), a--, b--, G[a].push_back(make_pair(b, c)), G[b].push_back(make_pair(a, c));
	init(0, N);
	scanf("%d%d", &Q, &K);
	K--;
	rep(i, 0, Q) {
		scanf("%d %d", &a, &b);
		a--, b--;
		ans.push_back(depth[a] + depth[K] - depth[lca(a, K)] * 2
			+ depth[b] + depth[K] - depth[lca(b, K)] * 2);
	}
	rep(i, 0, Q)printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 25716
#include <bits/stdc++.h>
using namespace std;
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>


#define MOD 1000000007ll
#define MX 2000006 //200005

ll m, n;
ll a[MX];
int main()
{
    #ifndef ONLINE_JUDGE
    //Fin;
    #endif
    int test=1;
    ll x,y, k, ans;
    ll r,g,b,i;
    //cin>>test;
    //test=1;
    while(test--)
    {
        r=1;
        cin>>n>>k;
        for(i=1;i<=n;i++)scanf("%lld",&a[i]);
         //for(i=1;i<=k;i++)r*=a[i];
        for(i=k+1;i<=n;i++)
        {
            //g=r/(a[i-k]);
            //g*=a[i];
            if(a[i]>a[i-k])puts("Yes");
            else puts("No");
        }

    }
    return 0;
}



Measured memory_bytes: 5248