akhauriyash/Code-Regression huggingface dataset:
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
const long long maxn=2e6+1e5;
vector<pair<long long,long long> > v[maxn];vector<long long> col[maxn];long long vis[maxn];
long long bark[maxn];vector<long long> qzr[maxn];long long ful;
long long dis[maxn];
int main()
{
	long long n,m;cin>>n>>m;
	for(long long i=0;i<m;i++)
	{
		long long a,b,c;cin>>a>>b>>c;
		v[a].push_back(make_pair(c,b));v[b].push_back(make_pair(c,a));
		col[c].push_back(a);col[c].push_back(b);
	} 
	for(long long i=1;i<=n;i++)
	{
		sort(v[i].begin(),v[i].end());
	}
	ful=1e6+5;
	for(long long asd=1;asd<=1e6+500;asd++)
	{
		if(col[asd].size()==0) continue;
		for(long long it=0;it<col[asd].size();it++)
		{
			long long  p=col[asd][it];
			if(vis[p]==asd) continue;
			queue<long long> q;vector<long long> kl;kl.clear();
			q.push(p);vis[p]=asd;kl.push_back(p);
			while(!q.empty())
			{
				if(q.size()==0) break; 
				long long t=q.front();q.pop();
				for(long long i=max(bark[t]-10,(long long)0);i<v[t].size();i++)
				{
					pair<long long,long long> u=v[t][i];
					if(vis[u.second]==asd) continue;
					if(u.first>asd)
					{
						bark[t]=i;break;
					}	
					if(u.first<asd)
					{
						continue;
						//bark[t]=i;break;
					}
					kl.push_back(u.second);q.push(u.second);vis[u.second]=asd;
				}
			}
			for(long long i=0;i<kl.size();i++)
			{
			//	cout<<kl[i]<<" ";
				long long t=kl[i];qzr[t].push_back(ful),qzr[ful].push_back(t);
			}//cout<<"\n";
			ful++;
		}
	}
	memset(dis,-1,sizeof(dis));
	priority_queue<pair<long long,long long> > q;
	q.push(make_pair(-0,1));dis[1]=0;
	while(!q.empty())
	{
		if(q.size()==0) break; 
		long long t=(q.top()).second;q.pop();	
		for(long long i=0;i<qzr[t].size();i++)
		{
			long long j=qzr[t][i];
			if(dis[j]==-1)
			{
				dis[j]=dis[t]+1;q.push(make_pair(-dis[j],j));
			}

		}
	}
	if(dis[n]==-1) dis[n]--;
	cout<<dis[n]/2;
	return 0;
}

Measured memory_bytes: 199160
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    cin >> n;
    vll a(n),dp(n);
    rep(i,n) cin >> a[i];
    rep(i,n) dp[i]=9999999999;
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1920
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD (1e9+7)
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int n;cin>>n;
  vector<P> A[n];
  for(int i = 0; n > i; i++){
    int a;cin>>a;
    for(int j = 0; a > j; j++){
      int b,c;cin>>b>>c;b--;
      A[i].push_back({b,c});
    }
  }
  int ans = 0;
  for(int bit = 0; (1<<n) > bit; bit++){
    bool dta[n];
    int aa = 0;
    for(int i = 0; n > i; i++){
      if(bit & (1<<i)){
        dta[i] = true;
        aa++;
      }else{
        dta[i] = false;
      }
      //cout << dta[i] << " ";
    }
    //cout << endl;
    bool ok = true;
    for(int i = 0; n > i; i++){
      for(int j = 0; A[i].size() > j; j++){
        if(dta[i]){
          //正直者
          //cout << "!" << i << " " << j << " " << dta[A[i][j].first] << " " << A[i][j].second << endl;
          if(dta[A[i][j].first] != A[i][j].second){
            ok = false;
            break;
          }
        }
      }
      if(!ok){
        break;
      }
    }
    if(ok){
      ans = max(aa,ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
  n,m = [int(x) for x in input().split()]
  a = [int(x) for x in input().split()]
  total = sum(a)
  
  can_be_selected = list(filter(lambda x: x >= total/4/m, a))
  if len(can_be_selected) >= m:
    print("Yes")
  else:
    print("No")

main()

Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long k = in.nextLong();

            long p = k / 50;
            long q = k % 50;

            long[] ans = new long[50];
            Arrays.fill(ans, 49 + p);

            for (int i = 0; i < q; i++) {
                for (int j = 0; j < 50; j++) {
                    if (j == i) {
                        ans[j] += 50;
                    } else {
                        ans[j]--;
                    }
                }
            }

            out.println(ans.length);
            for (int i = 0; i < ans.length; i++) {
                if (i > 0) out.print(" ");
                out.print(ans[i]);
            }
            out.println();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        int plus = a + b;
        int mainasu = a - b;
        int jyozan = a * b;
        int anserw = 0;
        if (plus > mainasu) {
            anserw = plus;
        } else {
            anserw = mainasu;
        }
        if (anserw > jyozan ) {
            System.out.print(anserw);
        } else {
            System.out.print(jyozan);
        }

    }
}



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

int main(){

  ll N;cin>>N;
  ll Ans=0;
  for(ll j=1;j<=N;j++){
    ll X=N/j;
    Ans += X*j*(X+1)/2;
  }
  cout<<Ans<<endl;
    
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
    private static int gcd(int p,int q){
        int temp=p%q;
        while (temp!=0) {
            p = q;
            q = temp;
            temp = p % q;
        }
        return q;
    }

    public static int gcd(int a,int b,int c){
        return gcd(gcd(a,b),c);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();

        int sum=0;
        for(int i=1;i<k+1;i++){
            for(int j=1;j<k+1;j++){
                for(int m=1;m<k+1;m++){
                    sum+=gcd(i,j,m);
                }
            }
        }
        System.out.println(sum);


    }
}


Measured memory_bytes: 35764
import java.util.Scanner

import scala.annotation.tailrec

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  def solve(sc: => Scanner): Long = {
    val N, M = sc.nextInt
    val A = Array.fill(M)((sc.nextInt - 1, sc.nextInt - 1))
    var ans = 0
    for (i <- 0 until M) {
      val uf = new IUnionFind(N)
      for (j <- 0 until M) {
        if (i != j) {
          uf.union(A(j)._1, A(j)._2)
        }
      }
      if (!uf.connected(A(i)._1, A(i)._2)) (ans += 1)
    }
    ans
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    println(solve(sc))
  }
}


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

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

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int M[N][N];

int main() {
	int n; cin >> n;
	rep(i, n) rep(j, n) M[i][j] = 0;
	rep(i, n) {
		int _n, n2; cin >> _n >> n2;
		rep(j, n2) {
			int k; cin >> k;
			M[i][k-1] = 1;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (j < n-1) cout << M[i][j] << ' ';
			else cout << M[i][j];
		}
		cout << endl;
	}
}



Measured memory_bytes: 3112
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>	
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>	
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <fstream>
#include <cstdio>
#include <memory.h>

using namespace std;

int main(void)
{
	int x, a, b, res;

	cin >> x >> a >> b;
	x -= a;
	res = x%b;
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int A;
    static int B;
    static int C;
    static int D;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        A = s.charAt(0) - '0';
        B = s.charAt(1) - '0';
        C = s.charAt(2) - '0';
        D = s.charAt(3) - '0';
        System.out.println( solve() );
    }

    private static String solve() {
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    if( calc(calc(calc(A, B, i), C, j), D, k) == 7 ) {
                        return mkFormula(i, j, k);
                    }
                }
            }
        }
        throw new RuntimeException("wtf");
    }

    private static String mkFormula(int i, int j, int k) {
        StringBuilder b = new StringBuilder();
        b.append(Integer.toString(A));
        b.append(i == 0 ? "+" : "-");
        b.append(Integer.toString(B));
        b.append(j == 0 ? "+" : "-");
        b.append(Integer.toString(C));
        b.append(k == 0 ? "+" : "-");
        b.append(Integer.toString(D));
        b.append("=7");
        return b.toString();
    }

    private static int calc(int a, int b, int op) {
        if( op == 0 ) {
            return a + b;
        } else {
            return a - b;
        }
    }
}


Measured memory_bytes: 21844
N, K, *AS = $stdin.read.split.map(&:to_i)

h = Hash.new{|h, k| h[k] = 0} 
AS.each do |a|
  h[a] += 1
end

sorted = h.sort_by{|k, v| v}
todo = sorted.size - K
#pp sorted: sorted, todo: todo
if todo <= 0
  p 0
else
  p sorted.first(todo).map(&:last).inject(:+)
end


Measured memory_bytes: 42488
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int m=sc.nextInt();
			int[] num=new int[n]; Arrays.fill(num,1);
			boolean[] red=new boolean[n]; Arrays.fill(red,false);
			red[0]=true;
			for(int i=0;i<m;i++){
				int x=sc.nextInt(); x--;
				int y=sc.nextInt(); y--;
				if(red[x]){
					if(num[x]==1){
						num[x]--; num[y]++;
						red[x]=false; red[y]=true;
					}
					else{
						num[x]--; num[y]++;
						red[y]=true;
					}
				}
				else{
					num[x]--;  num[y]++;
				}
			}
			int ans=0;
			for(int i=0;i<n;i++) if(red[i]) ans++;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23724
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20

class Polynomial:
    def __init__(self,dim=0,const=1):
        self.values = [(dim,const)]
    def __add__(self,other):
        return self.values + other.values


class PolySolver:
    def __init__(self,size):
        self.size = size
        self.f = np.zeros(size, np.int64)
        self.f[0] = 1


    def multiple(self,polynomial,MOD): # const1 * x^dim1 + const2 * x^dim2 + ... をfにかけ合わせる
        new_F = np.zeros(self.size, np.int64)
        for dim,const in polynomial:
            if dim != 0:
                g = np.zeros(self.size, np.int64)
                g[dim:] += self.f[:-dim]
            else:
                g = const * self.f.copy()
            new_F += g

        self.f = new_F
        self.f %= MOD

    
    def get_coefficient(self,dim):
        return self.f[dim]
    
def main():
    N,S=mi()
    A=list(mi())
    MOD = 998244353

    poly = PolySolver(3010)
    for a in A:
        f = Polynomial(const=2) + Polynomial(dim=a)
        poly.multiple(f,MOD)

    print(poly.get_coefficient(S))



if __name__ == "__main__":
    main()

Measured memory_bytes: 27512
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    cout << (n -1 )*(m-1);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final int n = scanner.nextInt();
    final int k = scanner.nextInt();
    final int x = scanner.nextInt();
    final int y = scanner.nextInt();

    if (k <= n) {
      System.out.println(k * x + (n - k) * y);
    } else {
      System.out.println(n * x);
    }
  }
}


Measured memory_bytes: 23124
n, k, s = map(int, input().split())
a = []
for i in range(k):
    a.append(s)
if s > 10**8:
    for i in range(n - k):
        a.append(1)
else:
    for i in range(n - k):
        a.append(10**9)
a = list(map(str, a))
print(" ".join(a))

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

int main(){
    int X,Y;
    int a,b;
    cin>>X>>Y;
    b=Y-2*X;
    b/=2;
    a=X-b;
    if(a<0||b<0){
        cout<<"No"<<endl;
    }else if(2*a+4*b==Y){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

int solve(const string& s)
{
	int l = 0;
	int r = s.length() - 1;

	int ans = 0;
	while (l < r) {
		if (s[l] == s[r]) {
			++l;
			--r;
		}
		else if (s[l] == 'x') {
			++l;
			++ans;
		}
		else if (s[r] == 'x') {
			--r;
			++ans;
		}
		else {
			return -1;
		}
	}
	return ans;
}


int main()
{
	string s;
	cin >> s;
	cout << solve(s) << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
int n,m,a,b,dp[10][1<<9]={},ans=0;
bool f[10][1<<9]={};
vector<int> e[10];
int pn(int i,int s){
  if(f[i][s]) return dp[i][s];
  f[i][s]=1;
  for(auto it=e[i].begin();it!=e[i].end();it++){
    if((s>>*it)&1) dp[i][s]+=pn(*it,s-(1<<i));
  }
  return dp[i][s];
}

int main(){
  f[0][1]=1;dp[0][1]=1;
  cin>>n>>m;
  fr(i,m){cin>>a>>b;e[--a].pb(--b);e[b].pb(a);}
  fr(i,n) ans+=pn(i,(1<<n)-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Point{
	double x,y;
	Point(){}
	Point(double _x,double _y){
		x = _x;
		y = _y;
	}
	Point operator + (Point p){
		return Point(x+p.x,y+p.y);
	}

	Point operator - (Point p){
		return Point(x-p.x,y-p.y);
	}

	Point operator * (double k){
		return Point(k*x,k*y);
	}


	bool operator<(const Point &p)const{
		return x!=p.x?x<p.x:y<p.y;
	}

	Point& operator=(Point p){
		x = p.x;
		y = p.y;
		return *this;
	}

	Point& operator-=(Point p){
		x -= p.x;
		y -= p.y;
		return *this;
	}	
};
double dot(Point p, Point q){
	return p.x*q.x+p.y*q.y;
}

double cross(Point p,Point q){
	return p.x*q.y-q.x*p.y;
}

double norm(Point p){
	return p.x*p.x+p.y*p.y;
}

double pabs(Point p){
	return sqrt(norm(p));
}
typedef vector<Point> Polygon;
struct Line : Polygon{
	Line(){}
	Line(Point p,Point q){
		PB(p);
		PB(q);	
	}
};
struct Circle{
	Point p;
	double r;
	Circle(){}
	Circle(Point _p,double _r){
		p = _p;
		r = _r;
	}
};
int ccw(Point a,Point b,Point c){
	b = b-a;
	c = c-a;
	if(cross(b,c) > 0)return +1; //ccw
	if(cross(b,c) < 0)return -1; //cw
	if(dot(b,c) < 0)return +2; // c--a--b;
	if(pabs(b)<pabs(c))return -2; //a--b--c
	return 0;
}

string ccw_s(Point a,Point b,Point c){
	b -= a;
	c -= a;
	if(cross(b,c) > 0)return "COUNTER_CLOCKWISE"; //ccw
	if(cross(b,c) < 0)return "CLOCKWISE"; //cw
	if(dot(b,c) < 0)return "ONLINE_BACK"; // c--a--b;
	if(norm(b)<norm(c))return "ONLINE_FRONT"; //a--b--c
	return "ON_SEGMENT"; //
}

int main(){
	double xp0,yp0,xp1,yp1;
	cin >> xp0 >> yp0 >> xp1 >> yp1;
	Point p1 = Point(xp0,yp0);
	Point p2 = Point(xp1,yp1);
	int Q;
	cin >> Q;
	while(Q--){
		double x,y;
		cin >> x >> y;
		Point p3 = Point(x,y);
		cout << ccw_s(p1,p2,p3) << "\n";
	}
	return 0;
}

Measured memory_bytes: 1216
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

class Data{
public:
	string mName;
	int mC,mV,mD,mL;
	Data(string _n,int _c,int _v,int _d,int _l){
		mName = _n;
		mC = _c;
		mV = _v;
		mD = _d;
		mL = _l;
	}
};

int dp[301][3];

int main(){
	int N,M;

	string line;
	stringstream ss;
	while(getline(cin,line)){
		ss << line;
		ss >> N >> M;
		ss.clear();

		vector<Data> idols;
		for(int i=0;i<N;i++){
			
			getline(cin,line);
			string name = line;

			getline(cin,line);
			ss << line;

			int C,V,D,L;
			ss >> C >> V >> D >> L;
			ss.clear();

			idols.push_back(Data(name,C,V,D,L));
		}


		memset(dp,0,sizeof(dp));

		for(int i=0;i<=M;i++){
			for(int j=0;j<idols.size();j++){
				for(int k=0;k<=M;k++){
					if(i-idols[j].mC*k < 0) break;
					dp[i][0] = max(dp[i-idols[j].mC*k][0] + idols[j].mV*k,dp[i][0]);
					dp[i][1] = max(dp[i-idols[j].mC*k][1] + idols[j].mD*k,dp[i][1]);
					dp[i][2] = max(dp[i-idols[j].mC*k][2] + idols[j].mL*k,dp[i][2]);
				}
			}
		}

		int maxv = 0;
		for(int i=0;i<=M;i++){
			for(int j=0;j<3;j++){
				maxv = max(dp[i][j],maxv);
			}
		}
		printf("%d\n",maxv);

	}
}

Measured memory_bytes: 2152
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;
    
#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;
    
int n;
multiset<int> a;
int ans[100000][2];
int result;
int in;
int main(){
    cin >> n;
    rep(i,n){
        cin >> in;
        a.insert(in);
    }
    
    for(int i=0; i<n-2; i++){
        /*
        cout << "\t";
        for(int j=0; j<a.size(); j++){
            cout << a[j] << " ";
        }
        cout << endl;
        */
       auto target = a.begin();
       target ++; 
       auto bottom = a.end();
       bottom --;

        if(*target <= 0){
            ans[i][0] = *bottom;
            ans[i][1] = *target;
            a.erase(target);
            a.erase(bottom);
            a.insert(ans[i][0] - ans[i][1]);
        }else{
            ans[i][0] = *a.begin();
            ans[i][1] = *target;
            a.erase(target);
            a.erase(a.begin());
            a.insert(ans[i][0] - ans[i][1]);
        }
    }
    
        // cout << "\t";
        // for(int j=0; j<a.size(); j++){
        //     cout << a[j] << " ";
        // }
        // cout << endl;
    auto itr = a.begin();
    ans[n-2][1] = *itr;
    itr ++;
    ans[n-2][0] = *itr;
    //cout << "a:" << ans[n-2][0] << "\tb:" << ans[n
    result = ans[n-2][0] - ans[n-2][1];
    
    cout << result << endl;
    for(int i=0; i<n-1; i++){
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<list>
using namespace std;
int main(){
    int n;
    cin>>n;
    char com[10];
    int x;
    list<int> data;
    list<int>::iterator it;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com[0]=='i'){
            cin>>x;
            data.push_front(x);
        }
        else if(com[6]=='F'){
            data.pop_front();
        }
        else if(com[6]=='L'){
            data.pop_back();
        }
        else if(com[0]=='d'){
            cin>>x;
            for(it=data.begin();it!=data.end();it++){
                if(*it==x){
                    data.erase(it);
                    break;
                }
            }
        }
        
    }
    
     for(it=data.begin();it!=--data.end();++it) cout << *it << " ";
      cout << *it << endl;
     
     
    return 0;
}


Measured memory_bytes: 34296
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
const int INF = 1001001001;

int main(){
    string s;
    cin >> s;
    int ans = INF;
    
    set<char> st;
    for(int i = 0; i < s.length(); ++i){
        st.insert(s[i]);
    }
    
    int cnt = 0;
    for(char c = 'a'; c <= 'z'; ++c){
        if(st.find(c) == st.end())      continue;
        
        int counter = 0;
        int temp = 0;
        bool flag = true;
        for(int i = 0; i < s.length(); ++i){
            if(s[i] == c){
                temp = max(temp, counter);
                counter = 0;
                flag = true;
                continue;
            }
            
            if(flag){
                counter++;
                flag = false;
            }
            else{
                counter++;
            }
        }
        
        if(!flag)   temp = max(temp, counter);
        
        ans = min(ans, temp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,i,j,c[505],s[505],f[505];
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>c[i]>>s[i]>>f[i];
    }
    for(i=0;i<n-1;i++)
    {
        int ans=0;
        for(j=i;j<n-1;j++)
        {
            if(ans<s[j])ans=s[j];
            if(ans%f[j]!=0)ans=ans+f[j]-ans%f[j];
            ans+=c[j];
        }
        cout<<ans<<endl;
    }
    cout<<'0'<<endl;
}


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

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  char a[100][100],b[100][100];
  
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++)
      cin >> a[i][j];
  }
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < m; j++)
      cin >> b[i][j];
  }
    
  int x = 0, y = 0, r = 0;
  bool flag = 0;
  for(int i = 0; i < n; i++) {
    for(int j = r; j < n; j++) {
      if(a[i][j] == b[x][y]) {
        if(x == m-1 & y == m-1) {
          cout << "Yes" << endl;
          return 0;
        }
        else if(y == m-1) {
          flag = 1;
          break;
        }
        else {
          if(y == 0) r = j;
          y++;
        }
      }
      else {
        x = 0; y = 0; r = 0;
        flag = 0;
      }
    }
    y = 0;
    if(flag) x++;
    else x = 0; 
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i + 1;}


int main() {
    int n;
    int A[251];
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> A[i];
    for(int i = 1; i <= n; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i)>=1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i)<=n) cout << "left key = " << A[left(i)] << ", ";
        if(right(i)<=n) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;

int h, w;

signed main() {
  cin >> h >> w;

  if (h == 1 || w == 1) {
    cout << 1 << endl;
  } else {
    cout << (h * w + 1) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <string>
#include <tuple>

bool includes(std::string const& s, std::string const& t) {
  // s == "ab", t == "a"  => true
  // s == "a",  t == "a"  => false
  // s == "a",  t == "ab" => false
  if (s.length() <= t.length()) return false;
  return (s.compare(0, t.length(), t) == 0);
}

std::pair<char, char> critical(std::string const& s, std::string const& t) {
  size_t n = std::min(s.length(), t.length());
  for (size_t i = 0; i <= n; ++i) {
    if (s[i] == t[i]) continue;
    if (s[i] == 0 || t[i] == 0) return {0, 0};  // no constraints
    return {s[i]-'a', t[i]-'a'};
  }
  return {0, 0};  // no constraints
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<std::string> s(n);
  for (size_t i = 0; i < n; ++i) {
    char buf[16];
    scanf("%s", buf);
    s[i] = buf;
  }

  size_t sigma = 26;
  std::vector<std::vector<int>> g0(sigma, std::vector<int>(sigma));

  for (size_t i = 0; i < n; ++i)
    for (size_t j = i+1; j < n; ++j) {
      size_t lc, gc;
      if (includes(s[i], s[j])) return puts("no"), 0;
      std::tie(lc, gc) = critical(s[i], s[j]);
      g0[lc][gc] = 1;
    }

  std::vector<std::vector<size_t>> g(sigma);
  std::vector<size_t> indeg(sigma);
  for (size_t i = 0; i < sigma; ++i)
    for (size_t j = 0; j < sigma; ++j)
      if (i != j && g0[i][j]) {
        g[i].push_back(j);
        // fprintf(stderr, "%c -> %c\n", char(i+'a'), char(j+'a'));
        ++indeg[j];
      }

  std::queue<size_t> q;
  for (size_t i = 0; i < sigma; ++i)
    if (indeg[i] == 0) q.push(i);

  while (!q.empty()) {
    size_t v = q.front();
    // fprintf(stderr, "pop: %c\n", char(v+'a'));
    q.pop();
    for (auto u: g[v]) {
      // fprintf(stderr, "reached: %c\n", char(u+'a'));
      if (--indeg[u] == 0) q.push(u);
    }
  }

  if (*std::max_element(indeg.begin(), indeg.end()) != 0) {
    puts("no");
  } else {
    puts("yes");
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



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

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  double H[1100];

  for(int i = 0; i < N; ++i) {
    int temp;
    cin >> temp;
    H[i] = T - 0.006 * temp;
  }

  double dif = abs(A - H[0]);
  int ans = 1;
  for(int i = 0; i < N; ++i) {
    double tmp = abs(A - H[i]);
    if(dif > tmp) {
      dif = tmp;
      ans = i + 1;
    }
  }

  cout << ans << endl;
}

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

using namespace std;

#define MAX 1050

char S[MAX][MAX];
int K[MAX];

void print(int N){
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < K[i] ; j++){
      if(S[i][j] == '.'){
        cout << " ";
      }else{
        cout << S[i][j];
      }
    }
    cout << endl;
  }
}

int main(){
  int N;
  string str;

  while(cin >> N,N){
    for(int i = 0 ; i < N ; i++){
      cin >> str; K[i] = str.size();
      for(int j = 0 ; j < K[i] ; j++){
        S[i][j] = str[j];
      }
    }

    for(int i = 1 ; i < N ; i++){
      for(int j = 0 ; j < K[i]-1 ; j++){
        if(islower(S[i][j+1])){
          S[i][j] = '+';
          break;
        }
      }
    }
    for(int i = 1 ; i < N ; i++){
      for(int j = 0 ; j < K[i] ; j++){
        if(S[i][j] == '+'){
          for(int k = i-1 ; k > 0 ; k--){
            if(S[k][j] != '.') break;
            S[k][j] = '|';
          }
        }
      }
    }
    print(N);
  }

  return 0;
}

Measured memory_bytes: 2232
#pragma region declaration
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <algorithm>
#include <set>
#include <deque>
using namespace std;
using ll = long long;
constexpr double INF{ 1e9 };
constexpr int MOD{ 1000000000 + 7 };
#define rep(i,n) for (int i = 0; i < n; ++i)
constexpr array<int, 4> dy{ -1, 1, 0, 0 };
constexpr array<int, 4> dx{ 0, 0, -1, 1 };
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
#pragma endregion
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x : a)
        cin >> x;

    vector<int> c(8);
    int rainbow = 0;

    for (int& x : a) {
        const int color = x / 400;
        if (color >= 8)
            rainbow++;
        else
            c[color]++;
    }

    int count = 0;

    for (int& x : c)
        if (x > 0)
            count++;

    const int min_colors = max(count,1);
    const int max_colors = count + rainbow;

    cout << min_colors << " " << max_colors << endl;
}
// vector<vector<int>> mm(h, vector<int>(w, -1));


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

int main() {
  int N, sum;
  cin >> N;
  sum = 0;
  for (int i =0 ; i <N ; i++) {
  int a, b;
  cin >> a >> b;
  sum +=b-a + 1;
  } 
  cout << sum << endl;
}

Measured memory_bytes: 256
N = gets.to_i
s_list = N.times.map { gets.to_i }
dp = Array.new(N + 10)
dp[0] = Hash.new
(0...(s_list.size)).each do |i|
  s = s_list[i]
  dp[i + 1] = dp[i].dup
  dp[i].keys.each do |j|
    dp[i + 1][j + s] = true
  end
  dp[i + 1][s] = true
end
ans = dp[N].select do |k, _|
  k % 10 != 0
end.map { |k, _| k }.max || 0
puts ans


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

using namespace std;

int main(void){
    string s;
    cin>>s;
    if(s=="SUN") cout<<7<<endl;
    if(s=="MON") cout<<6<<endl;
    if(s=="TUE") cout<<5<<endl;
    if(s=="WED") cout<<4<<endl;
    if(s=="THU") cout<<3<<endl;
    if(s=="FRI") cout<<2<<endl;
    if(s=="SAT") cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 256
module AtCoder
  class DSU
    def initialize(n = 0)
      @n = n
      @parent_or_size = Array.new(n, -1)
    end

    def merge(a, b)
      x, y = leader(a), leader(b)
      return x if x == y

      x, y = y, x if -@parent_or_size[x] < -@parent_or_size[y]
      @parent_or_size[x] += @parent_or_size[y]
      @parent_or_size[y] = x
    end

    def same(a, b)
      leader(a) == leader(b)
    end

    def leader(a)
      return a if @parent_or_size[a] < 0

      @parent_or_size[a] = leader(@parent_or_size[a])
    end

    def size(a)
      -@parent_or_size[leader(a)]
    end

    def groups
      @n.times.group_by { |i| leader(i) }.values
    end
  end
end

n, m = gets.split.map!(&:to_i)

dsu = AtCoder::DSU.new(n + 1)
m.times do
  a, b = gets.split.map!(&:to_i)
  dsu.merge(a, b)
end

puts dsu.groups.size - 2


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

int f(int a){
  if(a%2==0)
    return a/2;
  else
    return 3*a+1;
}

int main(){
  vector<int>a(1);
  cin>>a.at(0);
  bool OK=false;
  for(int i=0;true;i++){
    a.push_back(f(a.at(i)));
    for(int j=0;j<i+1;j++){
      if(a.at(i+1)==a.at(j)){
        cout<<i+2;
        OK=true;
        break;
      }
    }
    if(OK)
      break;
  }
}

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

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

void fail(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i] /= 2;
    }
    int64_t l = 1;
    for(int a : A){
        l = lcm(l, a);
        if(l > 1e9) fail();
    }
    for(int a : A) if((l/a) % 2 == 0) fail();
    int num = M/l;
    int ans = (num+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        
        
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            long ans = 0;
            for(var i = A; i <= B; i++)
            {
                string I = i.ToString();
                if (I[0] == I[4] && I[1] == I[3])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
           
            //Console.Out.Flush();

        }

        
    }

    public class Calculation
    {

    }

    public class Graph
    {
        
    }
}




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

int main(){
    int K, N, leng_max;
    leng_max = 0;
    cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N-1; i++) leng_max = max(leng_max, A[i+1] - A[i]);
    leng_max = max(leng_max, K - A[N-1] + A[0]);
    cout << K - leng_max <<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

const int N_MAX = 100005;
int F[N_MAX];
int B[N_MAX];
vector<pair<int, int>> BLO;

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n+3);
    memset(F, 0, sizeof(F));
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
        F[a]++;
        F[b]++;
    }
    memset(B, 0, sizeof(B));
    for(int i = 0; i < k; i++){
        int c, d;
        cin >> c >> d;
        if (uf.find(c) == uf.find(d)){
            B[c]++;
            B[d]++;
        }
    }
    for(int j = 1; j <= n; j++){
        cout << uf.size(j) - B[j] - F[j] - 1;
        if (j != n) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    int n;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        sc.close();

        // 解答処理
        int ans = solve((int)(n/1.08-5));
        if (ans != -1) {
            System.out.println(ans);
        } else {
            System.out.println(":(");
        }
    }
    
    private int solve(int a) {
        if ((int) (a * 1.08) == n) {
            return a;
        } else if(a <= n * 1.08){
            return solve(a + 1);
        } else {
            return -1;
        }
    }
}

Measured memory_bytes: 22996
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }
    int sum = 0;
    rep(i, N) { sum ^= A[i]; }
    rep(i, N) { cout << (sum ^ A[i]) << (i == N - 1 ? "\n" : " "); }

    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  a.push_back(a[0] + k);
  int ans = k;
  rep(i, n) {
    chmin(ans, k - (a[i + 1] - a[i]));
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main()
{int A,B,C,D,E,F; cin >> A >> B >> C >> D >> E >> F;
 
  int sugerwater = 0; int suger = 0; 
 
 double condense_origin = 0.00; //
 
 //a,b,c,dはそれぞれ操作1,2,3,4を何回繰り返すかを表す
 
 for(int a = 0 ; a <= F /(100* A) ; a++){ //少なくとも操作１はF/A回以下
   for(int b = 0; b <= F /(100 * B) ; b++){ //以下同様
     for(int c = 0; c <= F / C; c++){
       for(int d = 0 ; d <= F / D; d++){
         
         int X = 100*a*A + 100*b*B;//水の質量をXで表す
         int Y = c*C + d*D; //砂糖の質量をYで表す
         
         if(X == 0 && Y == 0){continue;} //0除算避け
         else{
           
           if( X + Y <= F && Y*(100 + E) <= E*(X + Y)){ //質量と濃度の制約満たしていたら通す
           double  condense_New = (double) Y /(double) (X + Y);
             if( condense_origin <= condense_New){ //新しい水溶液の方が濃度が高かったら
               
               suger = Y; //砂糖の質量を更新
               sugerwater = X + Y; //水溶液の質量を更新
               condense_origin = condense_New;}}} //濃度も更新
       }}}}
 
 cout << sugerwater << ' ' << suger; //水溶液⇨砂糖の順で空白つき出力
 
 return 0;
}
             
         


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(long long int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
using namespace std;
signed main() 
{
    fast
    ll t=1;
  // cin>>t;
    while(t--)
    {
           ll n,k;
           cin>>n>>k;
           ll a[n],dp[n]={0};
           for(ll i=0;i<n;i++) cin>>a[i];
           for(ll i=1;i<n;i++)
           {
                  vector<ll>v;
                  for(ll j=1;j<=k;j++)
                  {
                        if((i-j)>=0) v.pb(dp[i-j]+abs(a[i]-a[i-j]));
                        //cout<<b[j-1]<<" ";
                  }
                  //cout<<"\n";
                  sort(v.begin(),v.end());
                  dp[i]=v[0];
                  //cout<<dp[i]<<" ";
           }
           cout<<dp[n-1]<<"\n";
    }
}

Measured memory_bytes: 5196
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string s, t;
	cin >> s >> t;

	sort(ALL(s));
	sort(RALL(t));
	
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define F(i,n) for(int i=0;i<n;i++)
#define G(i,j,n) for(int i=j;i<n;i++)
int main()
{
ll n;
cin>> n;
ll arr[n];
ll sum=0,k=0;
F(i,n)
{
    cin>>arr[i];
}
F(i,n-1)
{
    if(arr[i+1]<arr[i])
    {

        k=arr[i]-arr[i+1];
        sum+=k;

    }

    arr[i+1]+=k;
    k=0;

}
cout<<sum;
return 0;
}


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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 26;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
ll ans;
ll a[N];

void solve1()
{
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    sort( a + 1 , a + n + 1 );
    reverse( a + 1 , a + n + 1 );
    ans = a[1];
    for( int i = 3 , j = 2 , h = 0; i <= n; i++ ){
        if( h < 2 ){
            ans += a[j];
            h += 1;
        }else{
            i -= 1 , h = 0 , j += 1;
        }
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 5212
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;


int h,g[11][11];

bool fall(int x,int y){

  if(g[y][x]==0)return false;

  bool fg=false;
  int tmp=g[y][x];
  g[y][x]=0;
  while(y>0 && g[y-1][x]==0)y--,fg=true;
  g[y][x]=tmp;
  return fg;
}

int remove(int x,int y){

  if(g[y][x]==0)return 0;
  
  int res=g[y][x],cnt=0;
  while(g[y][x]==g[y][x+cnt])cnt++;

  if(cnt<3)return 0;
    
  for(int i=0;i<cnt;i++)g[y][x+i]=0;
  
  return res*cnt;
}

int solve(){

  bool fg;
  int res=0;

  while(true){
    fg=false;
    
    for(int i=0;i<h;i++){
      for(int j=0;j<5;j++){
	res+=remove(j,i);
	fg|=fall(j,i);
      }
    }

    if(!fg)return res;
  }
}

int main(void){
  
  while(cin >> h,h){

    for(int i=0;i<11;i++)
      for(int j=0;j<11;j++)g[i][j]=0;

    for(int i=h-1;i>=0;i--){
      for(int j=0;j<5;j++)cin >> g[i][j];
    }

    cout << solve() << endl;
  }

  return 0;
}

Measured memory_bytes: 1160