akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110
string s[Max];
string t[Max];
int N, M;

int main(int argc, const char * argv[]) {
    N = inputValue();
    inputArray(s, N);
    M = inputValue();
    inputArray(t, M);

    sort(s, s+N);

    int maximum = 0;
    rep(i, N) {
        int ans = 0;
        if (i > 0 && s[i-1].compare(s[i]) == 0) continue;
        rep(j, N) {
            if (s[i].compare(s[j]) == 0) {
                ans += 1;
            }
        }
        rep(j, M) {
            if (s[i].compare(t[j]) == 0) {
                ans -= 1;
            }
        }
        if (ans > maximum) maximum = ans;
    }

    output(maximum);

    return 0;
}

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

/*RMQ  update:O(logN)  query:O(lonN)*/
const int MAX_N = 1<<20;

struct data{
  int l,r;
};

data dat[2*MAX_N-1];
int n;

//?????????
void init(int n_){
  //????´???°n???2???????????????
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)
    dat[i].l=dat[i].r=0;
}

//[a,b)
//query(a,b,0,0,n)
void query(int a,int b,int k,int l,int r,int x){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b){
    if(!dat[k].l)dat[k].l=dat[k].r=x;
    else if(dat[k].r+1==x)dat[k].r=x;
    else dat[k].l=dat[k].r=-1;
  }else{
    if(dat[k].l){
      if(!dat[k*2+1].l)dat[k*2+1].l=dat[k].l,dat[k*2+1].r=dat[k].r;
      else if(dat[k*2+1].r+1==dat[k].l)dat[k*2+1].r=dat[k].r;
      else dat[k*2+1].l=dat[k*2+1].r=-1;
      if(!dat[k*2+2].l)dat[k*2+2].l=dat[k].l,dat[k*2+2].r=dat[k].r;
      else if(dat[k*2+2].r+1==dat[k].l)dat[k*2+2].r=dat[k].r;
      else dat[k*2+2].l=dat[k*2+2].r=-1;
      dat[k].l=dat[k].r=0;
    }
    query(a,b,k*2+1,l,(l+r)/2,x);
    query(a,b,k*2+2,(l+r)/2,r,x);
  }
}

int main(){
  int k,t,l,r,x;
  cin>>n>>k>>t;
  init(n);
  for(int i=0;i<t;i++){
    scanf("%d%d%d",&l,&r,&x);
    l--,r--;
    query(l,r+1,0,0,n,x);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    query(i,i+1,0,0,n,k+1);
    if(dat[n+i-1].l==1&&dat[n+i-1].r==k+1)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7324
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

string func(string s, string t){
    if(s=="T" && t=="F") return "F";
    else return "T";
}

int main(){
    int n; cin>>n;
    vector<string> p(n);
    for(int i=0; i<n; i++) cin>>p[i];

    string ans=func(p[0], p[1]);
    for(int i=2; i<n; i++){
        ans=func(ans, p[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8460
#include<bits/stdc++.h> //ABC 164_c
using namespace std;
map<string,int> mp;
int num,n;
string s;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		if(mp[s]) mp[s]++;
		else{
			num++;
			mp[s]=1;
		}
	}
	cout<<num;
	return 0;
}

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

int gcd(int x, int y){
    if( x < y ){
        int t = x;
        x = y;
        y = t;
    }
    while( x%y ){
        int t = x%y;
        x = y;
        y = t;
    }
    return y;
}

int main(){
    int a, b;
    while( cin >> a >> b ) cout << gcd(a, b) << endl;
    return 0;
}

Measured memory_bytes: 1160
H, W = map(int, input().split())
S = [input().split() for k in range(H)]
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for k in range(H):
    for l in range(W):
        if S[k][l]=="snuke":
            print("".join([A[l],str(k+1)]))
            exit(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
inline int read() 
{   
	int x=0,f=1;char c=getchar();  
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}   
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}   
	return x*f; 
}     
int h,w,k,num,s,ans;
string str;
int a[10][10],b[10][10];
int main() 
{ 
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++)
	{
		cin>>str;
		for(int j=0;j<str.length();j++)
		if(str[j]=='#')
		{
			a[i][j+1]=1;
			num++;
		}
	}
	for(int i=0;i<(1<<h);i++)
		for(int j=0;j<(1<<w);j++)
		{
			memcpy(b,a,sizeof(a));
			int t=i,p=0;
			s=0;
			while(t)
			{
				p++;
				if(t&1)
					for(int r=1;r<=w;r++)
						if(b[p][r]==1)
						{
							s++;
							b[p][r]=0;
						}
				t>>=1;
			}
			t=j;p=0;
			while(t)
			{
				p++;
				if(t&1)
					for(int r=1;r<=h;r++)
						if(b[r][p]==1)
						{
							s++;
							b[r][p]=0;
						}
				t>>=1;
			}
			if(s+k==num)
				ans++;
			/*cout<<"tim: "<<i<<" "<<j<<" "<<s<<endl;
			for(int i1=1;i1<=h;i1++)
			{
				for(int j1=1;j1<=w;j1++)
					cout<<b[i1][j1]<<" ";
				cout<<endl;
			}*/
		}
	cout<<ans<<endl;
	return 0;
} 
/*
2 3 2
..#
###
*/

Measured memory_bytes: 3592
function check(n)
  
  prime = false
  for i in round(Int,sqrt(n)):-1:2
    
    if n % i == 0
      prime = true
      return i
      break
    end
    
  end
  
  if prime == false
    return n
  end
  
end

function main()
  
  N = parse(Int,readline())
  
  a = check(N)
  b = div(N,a)
  
  println((a-1)+(b-1))
  
end

main()

Measured memory_bytes: 111444
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

int main() {
  string  s,t, u;
  int a,b; 
  cin>>s>>t;
  cin>>a>>b;
  cin >>u;
  if (u==s) a--;
  else b--;
  printf("%d %d\n", a,b);
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n),b(n),c(n);
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i]>>c[i];
	}

	vector<int> x(n),y(n),z(n);
	x[0]=a[0],y[0]=b[0],z[0]=c[0];

	for(int i=1; i<n; i++){
		x[i]=max(y[i-1],z[i-1])+a[i];
		y[i]=max(z[i-1],x[i-1])+b[i];
		z[i]=max(x[i-1],y[i-1])+c[i];
	}
	
	cout<<max(max(x[n-1],y[n-1]),z[n-1])<<endl;
}
		

Measured memory_bytes: 2688
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()

    ex_comb =  defaultdict(int)
    all_comb = 0
    cnt = defaultdict(int)
    for a in A:
        cnt[a] += 1
    for a,c in cnt.items():
        val = c*(c-1)//2
        all_comb += val
        ex_comb[a] = val
    for a in A:
        whole = all_comb - ex_comb[a]
        whole += (cnt[a]-2)*(cnt[a]-1)//2
        print(whole)


if __name__ == '__main__':
    main()

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

#define M 1000000
#define L 12

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key%M; 
}
int h2(int key){
	return 1+(key%(M-1)); 
}
int find(char str[]){
	long long key, i, op;
    key = getKey(str);
    for (i=0;;i++) {
        op=(h1(key) + i * h2(key))%M;
        if(strcmp(H[op], str)==0) return 1;
        else if(strlen(H[op])==0) return 0;
    }
    return 0;
}
int insert(char str[]){
	long long key,i,optimas;
    key=getKey(str);
    for(i=0;;i++) {
        optimas = h1((key)+i*h2(key))%M;
        if (strcmp(H[optimas], str)==0) return 1;
        else if (strlen(H[optimas])==0) {
            strcpy(H[optimas],str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
		if ( com[0] == 'i' ){
	    	insert(str);
		}
    	else {
	    	if(find(str)){
			printf("yes\n");
	 	    }
    		else {
			printf("no\n");
	    	}
		}
    }	
    return 0;
}


Measured memory_bytes: 13468
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun 21 21:01:21 JST 2020
 **/

signed main() {
    Int n, K;
    std::cin >> n >> K;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    std::cout << accumulate(a.begin(), a.begin() + K, 0LL) << std::endl;
}


Measured memory_bytes: 3664
using System;
using System.Linq;

namespace abc062_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (x.Contains(2))
            {
                Console.WriteLine("No");
            }
            else
            {
                int[] a = new int[] { 4, 6, 9, 11 };
                bool b1 = a.Contains(x[0]);
                bool b2 = a.Contains(x[1]);
                Console.WriteLine(b1 == b2 ? "Yes" : "No");
            }
        }
    }
}

Measured memory_bytes: 13652
#include <iostream>//cout
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>//swap
using namespace std;
static const int MAX = 200000;
#define rep(i,n) for(int i=0;i<n;i++)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
int main() {
  long long int n, h;
  cin >> n >> h;
  int x,y;
  vector<long long int> a, b;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }
  sort(b.rbegin(), b.rend());
  sort(a.rbegin(), a.rend());
  int a_max = a[0];
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (a_max < b[i]){
      num = i+1;
    }
  }
  int t = 0;
  for (int i = 0; i < num; i++) {
    t += b[i];
    if (h <= t) {
      cout << i+1 << endl;
      return 0;
    }
  }
  if ((h-t)%(a_max)==0){
    cout <<  (h-t)/a_max + num << endl;
  } else {
    cout <<  (h-t)/a_max + 1 + num << endl;
  }
  return 0;
}


Measured memory_bytes: 2036
#include <cstdio>
#include <list>
using namespace std;
int main(){
    int n, q, x;
    scanf("%d" ,&n);
    list<int> lst;
    list<int>::iterator it = lst.begin();
    for(int i = 0; i < n; i++){
        scanf("%d", &q);
        switch(q){
            case 0:
                scanf("%d", &x);
                it = lst.insert(it, x);
                break;
            case 1:
                scanf("%d", &x);
                if(x < 0){
                    for(int j = x; j < 0; j++) --it;
                }else{
                    for(int j = 0; j < x; j++) ++it;
                }
                
                break;
            case 2:
                it = lst.erase(it);
                break;
        }
    }
    for(it = lst.begin(); it != lst.end(); ++it) printf("%d\n", *it);
}


Measured memory_bytes: 18232
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int r[111][111];

Int mod_pow(Int x,Int y,Int mod){
  Int res = 1;
  while(y){
    if(y&1) res = res * x % mod;
    x = x * x % mod;
    y /= 2;
  }
  return res;
}

Int extgcd(Int a,Int b,Int &x,Int &y){
  Int d = a;
  if(b != 0){
    d = extgcd(b, a%b, y,x);
    y -= (a/b) * x;
  } else{
    x = 1, y = 0;
  }
  return d;
}

Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
  //return mod_pow(x, mod-2, mod);

}

pair<Int, Int> linear_congruence(const vector<Int> &A, const vector<Int> &B,const vector<Int> &M){
  Int x = 0 ,m = 1;
  for(Int i=0;i<(Int)A.size();i++){
    Int a = A[i] * m , b = B[i] - A[i] * x, d = __gcd(M[i], a);
    if(b%d!=0) return make_pair(0,-1);
    Int t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
    x = x + m * t;
    m *= M[i]/d;
  }
  return make_pair(x%m,m);
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m,d;
  cin>>n>>m>>d;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];

  for(Int i=0;i<d;i++)
    for(Int j=0;j<m;j++)
      cin>>r[i][j];

  for(Int i=0;i<d;i++){
    vector<Int> A,B,M;
    for(Int j=0;j<m;j++){
      if(r[i][j]<0) continue;
      A.emplace_back(1);
      B.emplace_back(r[i][j]);
      M.emplace_back(a[j]);
    }
    auto p=linear_congruence(A,B,M);
    //cout<<i<<":"<<p.first<<" "<<p.second<<endl;
    if(p.second<0){
      n=-1;
      break;
    }
    if(p.second<0) p.first+=p.second;
    n=(n-p.first)/p.second*p.second+p.first;
  }
  
  cout<<n<<endl;
  return 0;
}



Measured memory_bytes: 3304
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){
  int pos = 1;
    for(int i = 1;i<=5;i++){
      int x;
      I(x);
      if(x == 0)pos = i;
    }
    cout<<pos<<endl;
    
    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const ll mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int H, W, K;
vector<vector<ll> > lines, dp;
/* function */
void makeLines() {
    int upper = 1 << (W - 1);
    vector<ll> tmp(W - 1);
    for (int b = 0; b < upper; b++) {
        for (int i = 0; i < W - 1; i++) tmp[i] = b >> i & 1;
        bool canLine = true;
        for (int i = 0; i < W - 2; i++) {
            if (tmp[i] + tmp [i + 1] == 2) {
                canLine = false;
                break;
            }
        }
        if (canLine) lines.push_back(tmp);
    }
}
void calcDPTable() {
    dp.assign(H + 1, vector<ll>(W));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (vector<ll> line : lines) {
            for (int j = 0; j < W; j++) {
                if (j > 0 && line[j - 1]) { dp[i + 1][j - 1] += dp[i][j] %= mod; }
                else if (j < W - 1 && line[j]) { dp[i + 1][j + 1] += dp[i][j] %= mod; }
                else { dp[i + 1][j] += dp[i][j] %= mod; }
            }
        }
    }
}

void calcAns() { cout << dp[H][K - 1] % mod << '\n'; }
/* main */
int main(){
    cin >> H >> W >> K;
    if (W == 1) { cout << 1 << '\n'; return 0; }
    makeLines();
    calcDPTable();
    calcAns();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long K, N;
    cin >> K >> N;
    vector<long> A(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
    }
    vector<long> dist(N);
    for(size_t i=0;i<N; i++)
    {
        if(i!=N-1) dist[i] = A[i+1] - A[i];
        else dist[i] = K - A[i] + A[0];
        //cerr << dist[i] << endl;
    }
    sort(dist.begin(), dist.end());
    long total = 0;
    for(size_t i=0;i<N-1; i++)
    {
        total += dist[i];
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3456
n=int(input())
A=[int(x) for x in input().split()]

u=10**6+1
C=[0]*u
D=[0]*2+[1]*(u-2)

def gcd(a,b):
   while a%b:
     a,b=b,a%b
   return b

n=4
while n<u:
  D[n]=0
  n+=2
i=3
while i*i<u:
  if D[i]:
    n=i*2
    while n<u:
      D[n]=0
      n+=i
  i+=2

for a in A:
  C[a]+=1
for i in [x for x in range(2,u) if D[x]==1]:
  if sum(C[i::i])>1:
    break
else:
  print('pairwise coprime')
  exit()

c=A[0]
for a in A:
  c=gcd(c,a)
  if c==1:
    break
else:
  print('not coprime')
  exit()

print('setwise coprime')


Measured memory_bytes: 127068
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ss () = read_line () |> split_on_char ' '

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

module SeguementTree = struct

  let default_val = ref 0

  let size = ref 0

  let make n init =
    default_val := init;
    let rec pow_of_2 i =
      if i >= n then i
      else pow_of_2 (2 * i) in
    size := pow_of_2 1;
    Array.make (2 * (!size) - 1) init

  let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

  let left i = 2*i + 1

  let right i = 2*i + 2

  let update (s : int array) i x =
    let j = !size + i - 1 in
    s.(j) <- x;
    let rec doit j =
      if j <= 0 then () else
      begin
        let p = parent j in
        let l = s.(left p) in
        let r = s.(right p) in
        s.(p) <- if l < r then l else r;
        doit p
      end in
    doit j

  let find s a b =
    let rec doit a b k l r =
      if r <= a || b <= l then !default_val
      else if a <= l && r <= b then s.(k)
      else begin
        let m = (l + r) / 2 in
        let v = doit a b (left k) l m in
        let w = doit a b (right k) m r in
        if v < w then v else w
      end in
    doit a b 0 0 !size

end

module S = SeguementTree

let solve n q =
  let s = S.make n 2147483647 in
  for _ = 0 to q - 1 do
    match IO.read_ns () with
    | c :: x :: y :: _ ->
      if c = 0 then S.update s x y
      else begin
        S.find s x (y + 1) |> print_int;
        print_newline ();
      end
    | _ -> assert false
  done

let () =
  match IO.read_ns () with
  | [n; q] -> solve n q
  | _ -> assert false

Measured memory_bytes: 6436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const int MAX_V = 201;

ll d[MAX_V][MAX_V]; // d[u][c]は辺e=(u,v)のコスト(存在しない場合はINF.ただしd[i][i]=0とする)
int N;               // 頂点数

void Warshall_Floyd(){
    for(int k = 1; k < N+1; k++)
        for(int i = 1; i < N+1; i++)
            for(int j = 1; j < N+1; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll M, R;
    cin >> N >> M >> R;
    vll r(R);
    rep(i, R){
        cin >> r[i];
    }
    rep(i, N+1)rep(j, N+1) d[i][j] = INF;
    rep(i, N+1) d[i][i] = 0;
    vll A(M), B(M), C(M);
    rep(i, M){
        cin >> A[i] >> B[i] >> C[i];
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }
    Warshall_Floyd();
    sort(ALL(r));
    ll ans = INF;
    do{
        ll anst = 0;
        rep(i, R-1){
            anst += d[r[i]][r[i+1]];
        }
        chmin(ans, anst);
    }while(next_permutation(ALL(r)));
    cout << ans << endl;
    return 0;
}

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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 2000111;
LL n, a, b, c, d, dist[maxn], val[maxn];

std::map<LL, int> all;
int tot;

void dfs(LL n)
{
	if(all.find(n) != all.end()) return;
	all[n] = ++tot;
	val[tot] = n;
	dfs(n / 2);
	dfs(n / 3);
	dfs(n / 5);
}

std::priority_queue<std::pair<LL, LL>> pq;
void update(LL val, LL d)
{
	if(all.find(val) == all.end()) return;
	int id = all[val];
	if(dist[id] > d)
	{
		dist[id] = d;
		pq.emplace(-dist[id], id);
	}
}
void dijkstra()
{
	for(int i=1; i<=tot; i++)
	{
		if(val[i] == 0) dist[i] = 0;
		else if(Linf / val[i] >= d) dist[i] = val[i] * d;
		else dist[i] = Linf;
		pq.emplace(-dist[i], i);
	}
	while(!pq.empty())
	{
		int id = pq.top().ss; LL D = -pq.top().ff; pq.pop();
		if(dist[id] != D) continue;
		// printf("v= %lld d= %lld\n", val[id], D);
		update(val[id] * 2, D + a);
		update(val[id] * 3, D + b);
		update(val[id] * 5, D + c);
		update(val[id] + 1, D + d);
		update(val[id] - 1, D + d);
	}
}

void solve()
{
	get1(n);
	get4(a, b, c, d);
	all.clear(); tot = 0;
	dfs(n);
	std::vector<LL> candidate;
	for(auto v : all) candidate.pb(v.ff);
	for(auto v : candidate) for(int i=-4; i<=4; i++)
	{
		if(all.find(v + i) == all.end())
		{
			all[v + i] = ++tot;
			val[tot] = v + i;
		}
	}
	dijkstra();
	printendl(dist[all[n]]);
}

int main()
{
	int tc;
	get1(tc);
	while(tc--) solve();
	return 0;
}

Measured memory_bytes: 8680
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c=0;cin>>a>>b;
  vector<pair<long long int,long long int>>d(a);
  rep(i,a)cin>>d[i].first>>d[i].second;
  sort(d.begin(),d.end());
  long long int o=0;
  while(b>0){
c+=d[o].second*d[o].first;
    if(b-d[o].second<0){
      
      c-=d[o].first*(d[o].second-b);
      break;
    }
    b-=d[o].second;
    o++;
  }
  cout<<c;
}


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

int main(){
  int n, k, s;
  cin >> n >> k >> s;
  int s2 = s+1;
  if(s2 > 100000) s2 = 1;
  for(int i=0; i<n; ++i){
    if(i == n-1) printf("%d\n", (i<k ? s:s2));
    else printf("%d ", (i<k ? s:s2));
  }
}

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

	int a, b, c, d, x, y;

	cin >> a >> b >> c;

	d = 0;

	for (int x = a, y = b; x <= y; x++){

		if (c%x == 0){
			d++;
		}
	}

	cout << d << endl;

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    string S;
    cin >> S;
    int A = (int)(S.at(0) - '0');
    int B = (int)(S.at(1) - '0');
    int C = (int)(S.at(2) - '0');
    int D = (int)(S.at(3) - '0');
    int AB, AC, AD;
    char a[2];
    a[0] = '+', a[1] = '-';
    for(int i = 0; i < 2; i++){
        if(i == 0) AB = A + B;
        else AB = A - B;
        for(int j = 0; j < 2; j++){
            if(j == 0) AC = AB + C;
            else AC = AB - C;
            for(int k = 0; k < 2; k++){
                if(k == 0) AD = AC + D;
                else AD = AC - D;
                if(AD == 7){
                    cout << A << a[i] << B << a[j] << C << a[k] << D << "=7" << endl;
                    return 0;
                }
            }
        }
    }
}

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

int main(void){
   int swap,i,len;
   char str[10000];

   scanf("%d%s",&swap,str);

   len = strlen(str);

   for(i=0;i<len;i++)
      str[i] = 'A' + (str[i] - 'A' + swap) % 26;

   printf("%s\n",str);
   return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string N=in<string>();
	if(N[2]==N[3] && N[4]==N[5]) out("Yes");
	else out("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
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; }
ll MOD = 1000000007;
ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	ll N,x;
	cin >> N >> x;
	ll a[N];
	for(int i = 0; i < N; i++) cin >> a[i];
	ll count = 0;
	for(int i = 0; i < N -1; i++)
	{
		ll sum = a[i] + a[i + 1];
		if(sum > x)
		{
			ll diff = sum - x;
			if(diff <= a[i + 1]) count += diff,a[i + 1] -= diff;
			else
			{
				a[i + 1] = 0; count += diff;
			}
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int n, int k) {
    auto m = new long[k];
    for (int i = 1; i <= n; i++)
        m[i % k]++;

    long ans = 0;
    for (int i = 1; i <= n; i++) { // a を固定
        int a = i % k;
        int b = (k - a) % k;
        int c = (k - a) % k;
        if ((b + c) % k == 0) {
            ans += m[b] * m[c];
        }
    }
    return ans;
}

long calc2(int n, int k) {
    long ans = 0;
    for (int i = 1; i <= n; i++) { // a を固定
        int a = i % k;
        long b = (k - a) % k;
        long c = (k - a) % k;
        if ((b + c) % k == 0) {
            ans += ((n + b) / k) * ((n + c) / k);
        }
    }
    return ans;
}

void main() {
    int n, k; scan(n, k);
    writeln(calc2(n, k));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)

using namespace std;
const int N = 2005, MI = 1e6;
int read() {
	static streambuf* in = cin.rdbuf();
	#define gc (p1 == p2 && (p2 = (p1 = buf) + in -> sgetn(buf, MI), p1 == p2) ? -1 : *p1++)
	static char buf[MI], *p1, *p2;
	int c = gc, r = 0;
	while(c < 48) c = gc;
	while(c > 47) r = (r << 3) + (r << 1) + (c & 15), c = gc;
	return r;
}
int n, a[N], sum;
bitset <N*N> bst;
int main() {
	#ifdef local
		freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	n = read();
	bst[0] = 1;
	rep(i, 1, n) sum += a[i] = read(), bst |= bst << a[i];
	sum = (sum + 1) / 2;
	while(!bst[sum]) sum++;
	return !(cout << sum);
}

Measured memory_bytes: 5108
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

ll n;

bool ok(ll a) {
	assert(n%a==0);
	ll m=n/a-1;
	return m>=1&&a<m;
}

ll solve() {
	ll ret=0;
	for(ll a=1;a*a<=n;++a) if(n%a==0) {
		if(ok(a)) ret+=n/a-1;
		if(a*a!=n&&ok(n/a)) ret+=n/(n/a)-1;
	}
	return ret;
}

void run() {
	scanf("%lld",&n);
	printf("%lld\n",solve());
}

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

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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="776755555555555555555555555555555555555554555555555555555555555555555555555555555555555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int a[3];
  rep(i,3)cin >> a[i];
  if((a[0] + a[1] + a[2]) >= 22)cout << "bust" << endl;
  else cout << "win" << endl;
}


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

double pi = 3.14159265358979323846;

double getAng(int h, int m){
    double hourAngle = h*30+m/2.0;
    double minAngle = m*6;
    if(abs(hourAngle-minAngle) > 180) return 360-abs(hourAngle-minAngle);
    return abs(hourAngle-minAngle);
}

void testCase(){
	int a, b, h, m;
    cin>>a>>b>>h>>m;
    double angle = 0;
    angle = getAng(h, m);

    double ans = sqrt(a*a+b*b-2*a*b*cos(angle*pi/180));
    if(ans == 0) ans = abs(a-b);
    if(angle == 180) ans = a+b;
    printf("%.20lf\n", ans);
}

int main(){
    int t = 1;
    // cin>>t;
    while(t--){
        testCase();
    }
}


Measured memory_bytes: 4192
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
for a in A:
    if a % 2 == 0:
        if (a % 3 != 0) and (a % 5 != 0):
            flag = False
if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n,x,num=0;
  cin>>n;
  x=n;
  while(x){
    num+=x%10;
    x/=10;
  }
  cout<<(n%num?"No":"Yes")<<endl;
  return 0;
}

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

int main() {
  int N;
  int A = 0;
  cin >> N ;
  int M = N;
  for(int i = 0; i<9; i++) {
     A+=N%10;
    N=N/10;
  }
   if(M%A==0){
     
     cout<<"Yes";}
  else{cout<<"No";}
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct Point {
	int x, y;

	bool operator<=(const Point &lhs) const { return (x <= lhs.x && y <= lhs.y); }

	Point() {}
	Point(int x, int y) : x(x), y(y) {}

};

int main() {

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

	int N, K;
	cin >> N >> K;

	vector<Point> pnts(N);
	for (int i = 0; i < N; i++) cin >> pnts[i].x >> pnts[i].y;

	lint ans = numeric_limits<lint>::max();
	for (int p1 = 0; p1 < N; p1++) {
		for (int p2 = 0; p2 < N; p2++) {
			for (int p3 = 0; p3 < N; p3++) {
				for (int p4 = 0; p4 < N; p4++) {

					Point upright(max({ pnts[p1].x,pnts[p2].x,pnts[p3].x,pnts[p4].x }),
							max({ pnts[p1].y,pnts[p2].y,pnts[p3].y,pnts[p4].y }));
					Point lowleft(min({ pnts[p1].x,pnts[p2].x,pnts[p3].x,pnts[p4].x }),
							min({ pnts[p1].y,pnts[p2].y,pnts[p3].y,pnts[p4].y }));

					int cnt = 0;
					for (int i = 0; i < N; i++) if (lowleft <= pnts[i] && pnts[i] <= upright) cnt++;
					if (cnt == K) ans = min(ans, 1LL * (upright.x - lowleft.x) * (upright.y - lowleft.y));

				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

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

const double eps = 1e-9;

bool same(double a, double b) { return abs(a - b) < eps; }

struct P {
    double x, y;
    P() : x(0), y(0) {}
    P(double x, double y) : x(x), y(y) {}
    P operator + (P b) { return P(x + b.x, y + b.y); }
    P operator - (P b) { return P(x - b.x, y - b.y); }
    P operator * (double b) { return P(x * b, y * b); }
    P operator / (double b) { return P(x / b, y / b); }
    double operator * (P b) { return x * b.x + y * b.y; }
    double operator ^ (P b) { return x * b.y - y * b.x; }
    double abs() { return hypot(x, y); }
    P unit() { return *this / abs(); }
};

struct L{
    // ax + by + c = 0
    double a, b ,c, o;
    P pa, pb;
    L() : a(0), b(0), c(0), o(0), pa(), pb() {}
    L(P pa, P pb) : a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}
    P project(P p) { return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs()); }
    P reflect(P p) { return p + (project(p) - p) * 2; }
    double get_ratio(P p) { return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs()); }
};

bool parallel(L x, L y) { return same(x.a * y.b, x.b * y.a); }

P intersect(L x, L y) { return P(-x.b * y.c + x.c * y.b, x.a * y.c - x.c * y.a) / (-x.a * y.b + x.b * y.a); }

int main() {
    P p0, p1; cin >> p0.x >> p0.y >> p1.x >> p1.y;
    int q; cin >> q; while (q--) {
        P p2; cin >> p2.x >> p2.y;
        if (((p1 - p0) ^ (p2 - p0)) > eps) cout << "COUNTER_CLOCKWISE" << '\n';
        else if (((p1 - p0) ^ (p2 - p0)) < -eps) cout << "CLOCKWISE" << '\n';
        else if (((p1 - p0) * (p2 - p0)) < 0) cout << "ONLINE_BACK" << '\n';
        else if ((p1 - p0).abs() < (p2 - p0).abs()) cout << "ONLINE_FRONT" << '\n';
        else cout << "ON_SEGMENT" << '\n';
    }
}



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

int main() {
    int N,M;
    cin>>N>>M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1);
    queue<int> que;
    vector<int> pre(N,-1);
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            pre[nv]=v;
            que.push(nv);
        }
    }
    cout<<"Yes"<<endl;
    for (int i = 1; i < N; ++i){
        int ans=pre[i];
        ++ans;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 10728
function main(input){
  var n = parseInt(input[0]);
  var a = [];
  var b = [];
  for (var i = 0; i< n; i++) {
    var ab = input[i+1].split(' ');
    a.push(parseInt(ab[0]));
    b.push(parseInt(ab[1]));
  }

  var score = [];
  for (var i = 0; i< n; i++) {
    score.push({score: a[i]+b[i], a: a[i], b:b[i]});
  }

  score = score.sort((a,b) => b.score-a.score);
  var as = 0;
  var bs = 0;
  for (var i = 0; i < n; i++){
    if (i%2 === 0) {
      as+= score[i].a;
    } else {
      bs+=score[i].b;
    }
  }
  console.log(as-bs);
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


Measured memory_bytes: 33680
n=int(input())
if n<10:
    print(n)
elif n<100:
    print(9)
elif n<1000:
    print(9+n-100+1)
elif n<10000:
    print(909)
elif n<100000:
    print(9+900+n-10000+1)
else:
    print(90909)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int q = sc.nextInt();
		boolean reverseFlag = false;

		StringBuilder front = new StringBuilder();
		StringBuilder back = new StringBuilder();
		for(int i =0;i < q;i++) {
			int t = sc.nextInt();
			if(t ==1) {
				reverseFlag = !reverseFlag;
			}else {
				int f = sc.nextInt();
				if(f == 1) {
					if(reverseFlag) {
						back.append(sc.next());
					}else {
						front.append(sc.next());
					}
				}else {
					if(reverseFlag) {
						front.append(sc.next());
					}else {
						back.append(sc.next());
					}
				}
			}
		}
		StringBuilder answer = new StringBuilder();
		answer.append(front.reverse());
		answer.append(s);
		answer.append(back);
		if(reverseFlag) {
			System.out.println(answer.reverse());

		}else {
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 124056
s = int(input())
li = [s]
num = s

for i in range(1,1000000):
    if num%2 == 0:
        num = num//2
    else:
        num = 3*num+1
    if num in li:
        print(i+1)
        exit(0)
    else:
        li.append(num)

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

int main(){
    int n,x;
    cin >> n >> x;
    int l;
    int d=0,counter=0;
    for(int i=0;i<=n;i++){
        counter++;
        cin >> l;
        d+=l;
        if(d>x) break;
    }
    cout << counter;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  double a,b,d=1,c=0;
  cin>>a>>b;
  while(d<b){
    d*=2;
  }
  for(double i=1;i<=a;i++){
    double e=i,cnt=1;
    while(e<b){
      e*=2;
      cnt*=2;
    }
    c+=(d/cnt);
  }
  cout<<fixed<<setprecision(11)<<c/(d*a);
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long sum = 0;
        
        sum = (b / x) - (a / x);
        if (a % x == 0) {
            sum++;
        }
        
        /*if (a % x == 0 || b % x == 0) {
            sum++;
        } */
        
        /*if (a != b && (a % x == 0 || b % x == 0)) {
            sum++;
        }
        if (a != b && (b > x && b - a < x)) {
            sum++;
        }
        if (a == b && a == x) {
            sum++;
        }*/
        System.out.println(sum);
    }
}

Measured memory_bytes: 23764
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
ls = []
for _ in range(m):
    ls.append([int(x) for x in input().split()])


obscanreach = [[] for _ in range(n)]
for x in ls:
    obscanreach[x[0]-1].append(x[1])
    obscanreach[x[1]-1].append(x[0])

res = 0
for i,x in enumerate(obscanreach):
    check = 0
    if not x:
        res += 1
        continue
    for ev in x:
        check = max(check, h[ev-1])
    if h[i] > check:
        res += 1
print(res)

Measured memory_bytes: 39648
#include <iostream>

    using namespace std;

    int num1, num2, num3;

    int main() {
        cin >> num1 >> num2 >> num3;

        if (num3>num2 && num3>num1){
            int first_digit = num3 * 10;
            cout << first_digit + num2 + num1;
        }
        else if (num2 > num1 && num2 > num3 ){
            int first_digit = num2 * 10;
            cout << first_digit + num3 + num1;
        }
        else {int first_digit = num1 * 10;
        cout << first_digit + num2 + num3;}



        return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if(a < b){
        printf("a < b\n");
    }
    
    else if(a > b){
        printf("a > b\n");
    }
    
    else 
        printf("a == b\n");
    
    
    return 0;
}

Measured memory_bytes: 580
str1 = str(input(' '))
l = str1.split(' ')
a = int(l[0])
b = int(l[1])
n = int(l[2])

if n<b:
    print((a*(n))//b - a*((n)//b))
else:
    print((a*(b-1)//b) - a*((b-1)//b))

Measured memory_bytes: 9196
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<set>


using namespace std;
using vi=vector<int>;
using seti=set<int>;
using vseti=vector<seti>;
using vvseti=vector<vseti>;

#define F_SIZE 100

void marge(seti&a, seti&b)
{
	seti result;

	for(int ma:a)
	{
		if(b.find(ma)!=b.end()) result.insert(ma);
	}
	a=result;
}


void calc(vi&x, vi&y, vi&h, int&cx, int&cy, int&ch)
{
	int n=x.size();

	for(cx=0;cx<=F_SIZE;cx++)
	{
		for(cy=0;cy<=F_SIZE;cy++)
		{
			int is_ok=1;

			for(int i=0;i<n;i++)
			{
				ch=h[i]+abs(cx-x[i])+abs(cy-y[i]);
				if(h[i]>0) break;
			}
			for(int i=0;i<n;i++)
			{
				if(max(ch-abs(cx-x[i])-abs(cy-y[i]), 0)!=h[i]) is_ok=0;
			}
			if(is_ok) return;
		}
	}
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi x(n), y(n), h(n);
		vvseti f(F_SIZE+1);

		for(auto&mf:f) mf.resize(F_SIZE+1);

		for(int i=0;i<n;i++)
		{
			scanf("%d%d%d", &x[i], &y[i], &h[i]);
		}

		int cx=-1, cy=-1, ch=-1;
		calc(x, y, h, cx, cy, ch);

		printf("%d %d %d\n", cx, cy, ch);
	}

	return 0;
}


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

int main(){
  int n,ans,ans2;
  
  cin >> n;
  
  ans = ceil(n / 1.08);
  ans2 = ans * 1.08;
  if(n == ans2){
    cout << ans << endl;
  }else{
    cout << ":(" << endl;
  }
  
  
}

Measured memory_bytes: 256