akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, m, h[N], t[N], ans;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)scanf("%d", &h[i]);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		if (h[u] <= h[v])t[u] = 1;
		if (h[v] <= h[u])t[v] = 1;
	}
	for (int i = 1; i <= n; i++)if (!t[i])ans++;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 1e6;
const int LOG = 21;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLMOD = 998244353;
const ll LLINF = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ld> a(n);
    forn(i, n) cin >> a[i];
    sort(all(a));
    ld ans = a[0];
    forab(i, 1, n) {
        ans += a[i];
        ans /= 2;
    }
    cout << ans << "\n";
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;

ll n, m;
vector<ll> a;
bool valid(ll x) {
    ll cnt = 0;
    rep(i, n) {
        auto iter = lower_bound(all(a), x - a[i]);
        cnt += a.end() - iter;
    }
    if (cnt >= m) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n >> m;
    a.resize(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<ll> cusum(n, 0);
    rep(i, n) {
        if (i == 0) cusum[0] = a[0];
        cusum[i] = cusum[i - 1] + a[i];
    }

    ll lb = 0, ub = 1e10;
    while (ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if (valid(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }

    ll cnt = 0, ans = 0, tmp = 0;
    rep(i, n) {
        auto iter = lower_bound(all(a), ub - a[i]);
        cnt = a.end() - iter;
        tmp += cnt;
        ans += cusum[a.end() - a.begin() - 1] - cusum[iter - a.begin() - 1];
        ans += cnt * a[i];
    }
    ll diff = m - tmp;
    ans += diff * lb;
    out(ans);
}


Measured memory_bytes: 1792
h, w = gets.chomp.split(" ").map(&:to_i)
c = []
10.times do
    c << gets.chomp.split(" ").map(&:to_i)
end
a = []
h.times do
    a << gets.chomp.split(" ").map(&:to_i)
end
10.times do |k|
    10.times do |i|
        10.times do |j|
            c[i][j] = [c[i][j], c[i][k] + c[k][j]].min
        end
    end
end
ans = 0
a.each do |arr|
    arr.each do |e|
        next if e == -1 || e == 1
        ans += c[e][1]
    end
end
puts ans

Measured memory_bytes: 3836
#include <stdio.h>
#include <math.h>

int main(){
	double w,h,m,s;
	scanf("%lf", &w);
	h = floor(w / 3600);
	
	m = floor((w-3600*h)/60);
	
	s = w - h * 3600 - m * 60;
	

	printf("%d:%d:%d\n", (int)h,(int)m,(int)s);
	return 0;
}

Measured memory_bytes: 624
#include <stdio.h>
#include <math.h>

#ifndef M_PI
#define M_PI (3.1415926535f)
#endif

int main(int argc, char *argv[])
{
    double r;

    scanf("%lf", &r);
    printf("%lf %lf\n", r * r * M_PI, 2 * r * M_PI);
    
    return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),r=nxt();
    if(n>=10)
        cout<<r<<endl;
    else
        cout<<r+100*(10-n)<<endl;

    return 0;   
}


 
 


Measured memory_bytes: 256
I=lambda:map(int,input().split())
n,m=I()
d=[0]+[9**9]*2**n
while m:
 m-=1;a,_=I();s=sum(1<<c-1for c in I())
 for j in range(2**n):d[s|j]=min(d[s|j],d[j]+a)
print(d[-2]%9**9or-1)

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

using ll=long long;
const ll MOD=1e9+7;
const int SIZE=2*1e5;
ll dp[41][SIZE];
int main(){
    int n,x,y,z;
    cin>>n>>x>>y>>z;
    int sum=x+y+z;
    vector<ll> tenp(n+1);
    tenp[0]=1;
    for(int i=0;i<n;i++) tenp[i+1]=tenp[i]*10%MOD;
    dp[0][0]=1;
    const int mask=(1<<sum)-1;
    ll res=0;
    for(int i=0;i<n;i++){
        for(int bit=0;bit<(1<<sum);bit++){
            if(!dp[i][bit]) continue;
            for(int j=1;j<=7;j++){
                int tobit=((bit<<j)+(1<<(j-1)))&mask;
                bool bx=(tobit>>(x-1))&1;
                bool by=(tobit>>(x+y-1))&1;
                bool bz=(tobit>>(x+y+z-1))&1;
                if(bx && by && bz){
                    res+=dp[i][bit]*tenp[n-1-i];
                    res%=MOD;
                }
                else{
                    dp[i+1][tobit]+=dp[i][bit];
                    dp[i+1][tobit]%=MOD;
                }
            }
            dp[i+1][0]+=dp[i][bit]*3;
            dp[i+1][0]%=MOD;
        }
    }
    cout<<res<<endl;
    return 0;
}

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

int main(void)
{
	char map_1[32][2][6] = {{"A", "00000"}, {"B", "00001"}, {"C", "00010"}, {"D", "00011"},
					 	   	{"E", "00100"}, {"F", "00101"}, {"G", "00110"}, {"H", "00111"},
					 	   	{"I", "01000"}, {"J", "01001"}, {"K", "01010"}, {"L", "01011"},
					    	{"M", "01100"}, {"N", "01101"}, {"O", "01110"}, {"P", "01111"},
					   	 	{"Q", "10000"}, {"R", "10001"}, {"S", "10010"}, {"T", "10011"},
					   	 	{"U", "10100"}, {"V", "10101"}, {"W", "10110"}, {"X", "10111"},
					   	 	{"Y", "11000"}, {"Z", "11001"}, {" ", "11010"}, {".", "11011"},
					    	{",", "11100"}, {"-", "11101"}, {"'", "11110"}, {"?", "11111"} };
	char map_2[32][2][9] = {{"A", "100101"},   {"B", "10011010"}, {"C", "0101"},     {"D", "0001"},
					    	{"E", "110"},      {"F", "01001"},    {"G", "10011011"}, {"H", "010000"},
					    	{"I", "0111"},     {"J", "10011000"}, {"K", "0110"},     {"L", "00100"},
					    	{"M", "10011001"}, {"N", "10011110"}, {"O", "00101"},  	 {"P", "111"},
					   		{"Q", "10011111"}, {"R", "1000"},	  {"S", "00110"},  	 {"T", "00111"},
					    	{"U", "10011100"}, {"V", "10011101"}, {"W", "000010"},   {"X", "10010010"},
					    	{"Y", "10010011"}, {"Z", "10010000"}, {" ", "101"},      {".", "010001"},
					    	{",", "000011"},   {"-", "10010001"}, {"'", "000000"},   {"?", "000001"} };
	char str[50001];
	char temp[50001], *ptr;
	int i, flag;
	int ch;
	
	memset(str, '\0', sizeof(str));
	while (scanf("%[^\n]", str) != EOF){
		getchar();
		
		memset(temp, 0, sizeof(temp));
		
		i = 0;
		while (str[i] != '\0'){
				if ('A' <= str[i] && str[i] <= 'Z') ch = str[i] - 'A';
				else {
					switch (str[i]){
						case ' ' : ch = 26; break;
						case '.' : ch = 27; break;
						case ',' : ch = 28; break;
						case '-' : ch = 29; break;
						case '\'': ch = 30; break;
						case '?' : ch = 31; break;
					}
				}
				strcat(temp, map_1[ch][1]);
				i++;
		}
		memset(str, '\0', sizeof(str));
		
		flag = 1;
		ptr = &temp[0];
		while (flag){
			flag = 0;
			for (i = 0; i < 32; i++){
				if (strncmp(map_2[i][1], ptr, strlen(map_2[i][1])) == 0){
					strcat(str, map_2[i][0]);
					ptr += strlen(map_2[i][1]);
					flag = 1;
				}
			}
		}
		printf("%s\n", str);
		memset(str, '\0', sizeof(str));
	}
	return (0);
}

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

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xx(n);
    vector<int> yy(m);
    int maxx = -101;
    int miny = 101;
    for (int i = 0; i < n; i++) {
        cin >> xx.at(i);
        maxx = max(maxx, xx.at(i));
    }
    for (int i = 0; i < m; i++) {
        cin >> yy.at(i);
        miny = min(miny, yy.at(i));
    }
    if (maxx < miny) {
        for (int i = maxx + 1; i <= miny; i++) {
            if(x < i && i <= y) {
                cout << "No War" << endl;
                return 0;
            }
        }
    }
    cout << "War" << endl;
}

Measured memory_bytes: 256
#include<iostream> 
#include<cstdio>
#include<algorithm>
using namespace std;
int one,two,a[1000001],c[1000001],d[1000001];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i+=2)
	{
		c[++one]=a[i];
	}
	for(int i=2;i<=n;i+=2)
	{
		d[++two]=a[i];
	}
	if(n%2==0)
	{
		for(int i=two;i>=1;i--)
		printf("%d ",d[i]);
		for(int i=1;i<=one;i++)
		printf("%d ",c[i]);		
	}
	if(n%2==1)
	{
		for(int i=one;i>=1;i--)
		printf("%d ",c[i]);
		for(int i=1;i<=two;i++)
		printf("%d ",d[i]);		
	}
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const int MOD = pow(10, 9) + 7;
//const int LLINF = pow(2, 61) - 1;
//const int INF = pow(2, 30) - 1;
const int MAX = MOD;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)

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

  int N,A,B;

  cin >> N;

  if(N%2==1){
    cout << N / 2 + 1 << endl;
  }

  else{
    cout << N / 2 << endl;
  }
}

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

long dp[25][200][30]; //dp[何個目まで足したか][残ってる数]
int n, k;

long rec(int a, int b, int c){ //a番目,残りb,前に足した数c
	if(dp[a][b][c]>=0) return dp[a][b][c];
	
	long ret=0;
	if(a==k && b>=0){
		if(b==0) ret=1;
		else ret=0;	
	}
	else if(b<0) ret=0;
	else{
		for(int i=c-1; i>0; --i) ret+=rec(a+1, b-i, i);
		//printf("%d %d = %ld\n", a, b, ret);
	}
	//printf("ret dp[%d][%d] = %ld\n", a, b, ret);
	return dp[a][b][c]=ret;
}

int main(){
	while(1){
		int s;
		scanf(" %d %d %d", &n, &k, &s);
		if(n==0) break;	
		
		memset(dp, -1, sizeof(dp));
		printf("%ld\n", rec(0, s, n+1) );
	}
	return 0;
}

Measured memory_bytes: 2368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5,mod=998244353;
vector<int>v[N];
int n,a[N],tot,head[N],nex[N*20],to[N*20];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
ll sum[N],p[N],f[N],inv[N];
int main()
{
    inv[1]=1;
    for(int i=2;i<=1000000;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    int tot=0;
    for(int i=1;i<=1000000;i++)
        for(int j=i;j<=1000000;j+=i)
            add(j,i);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        for(int j=head[a[i]];j;j=nex[j])
        {
            int v=to[j];
            p[v]=(p[v]+sum[v]*a[i])%mod;
            sum[v]=(sum[v]+a[i])%mod;
        }
    }
    ll ans=0;
    for(int i=1000000;i>=1;i--)
    {
        ans=(ans+p[i]*inv[i])%mod;
        for(int j=head[i];j;j=nex[j])
        {
            int v=to[j];if(v==i) continue;
            p[v]=(p[v]-p[i])%mod;
        }
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}
/*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5,mod=998244353;
vector<int>v[N];
int n,a[N];
ll sum[N],f[N],inv[N];
int main()
{
    inv[1]=1;
    for(int i=2;i<=1000000;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    int tot=0;
    for(int i=1;i<=1000000;i++)
        for(int j=i;j<=1000000;j+=i)
            v[j].push_back(i),tot++;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        for(int j=0;j<v[a[i]].size();j++)
            sum[v[a[i]][j]]=(sum[v[a[i]][j]]+a[i])%mod;
    }
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[a[i]].size();j++)
        {
            int x=v[a[i]][j];
            sum[x]=(sum[x]-a[i])%mod,f[x]=sum[x];
        }
        for(int j=v[a[i]].size()-1;j>=0;j--)
        {
            int x=v[a[i]][j];
            ans=(ans+f[x]*a[i]%mod*inv[x])%mod;
            for(int k=0;k<v[x].size()-1;k++)
                f[v[x][k]]=(f[v[x][k]]-f[x])%mod;
        }
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}
*/


Measured memory_bytes: 167936
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
#define MOD 1000000007
#define FormulaToConvertMicrosecondsToSeconds(duration) duration / 1e+6
#define _CRT_SECURE_NO_DEPRECATE
#define ll                    long long
#define nl                    '\n'                             // NL - sign of new line

#define upperString(str)      transform(str.begin(), str.end(), str.begin(), ::toupper); // make entire string uppercase
#define lowerString(str)      transform(str.begin(), str.end(), str.begin(), ::tolower); // make entire string lowercase

#define ps(x,y)               fixed << setprecision(y) << x     // usage: t=1.1234; cout << ps(t,4); // it means it will print 4 decimal places.

#define eb                    emplace_back
#define sortv(v)              sort(v.begin(), v.end());
#define rsortv(v)             sort(v.rbegin(), v.rend());
#define rev(v)		          reverse(v.begin(), v.end())       // reverse the vector

#define si                    set<int>

#define mii			          std::map <int,int>
#define multimii		      std::multimap <int,int>
#define mss			          map <string, string>

mt19937                       rng(chrono::steady_clock::now().time_since_epoch().count());

void solve();
//==================================

bool isPrime(int num) {
	if (num == 1) return false;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num % i == 0) return false;
	}
	return true;
}

ll binarySearch(int a[], int l, int r, int x)
{
	while (l <= r)
	{
		int mid_index = l + (r - l) / 2;

		if (a[mid_index] == x)
			return mid_index;
		else if ( x > a[mid_index])
		{
			l = mid_index + 1;
		}
		else if ( x < a[mid_index])
		{
			r = mid_index - 1;
		}
	}
	return -1;
}

ll fast_power(ll base, ll power) {
	ll result = 1;
	while (power > 0) {

		// if( power % 2 == 1)
		if (power & 1) { // Can also use (power & 1) to make code even faster
			result = (result * base) % MOD;
		}
		base = (base * base) % MOD;

		// power /= 2
		power >>= 1; // Can also use power >>= 1; to make code even faster
	}
	return result;
}

//==================================
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//--------------------------------
	auto t1 = std::chrono::high_resolution_clock::now();

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

	solve();
	//}



	auto t2 = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();

	cerr << "\nTime taken : " << FormulaToConvertMicrosecondsToSeconds(duration) << " secs" << nl;
	return 0;
}

void solve() //Task A. Double Cola!!! Two teams composing !
{

	int n; cin >> n;

	int num = 0;
	while (num < n)
	{
		num += 1000;
	}

	cout << num - n;



} // !solve


/* TESTS:


*/

Measured memory_bytes: 3860
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll H,W;
string S;


//解法
void solve() {
	/*
	string key = "keyence";

	if (equal(key.begin(), key.end(), S.begin())) {
		cout << "YES";
		return;
	}

	if (S.find(key) == S.size() - key.size()) {
		cout << "YES";
		return;
	}
	*/

	string keyF = "";
	string keyE = "keyence";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "k";
	keyE = "eyence";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "ke";
	keyE = "yence";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "key";
	keyE = "ence";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "keye";
	keyE = "nce";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}
	
	keyF = "keyen";
	keyE = "ce";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "keyenc";
	keyE = "e";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	keyF = "keyence";
	keyE = "";

	if (equal(keyF.begin(), keyF.end(), S.begin()) && S.find(keyE,S.size()-keyE.size()) != string::npos) {
		cout << "YES";
		return;
	}

	cout << "NO";
	return;
}

int main() {
	//入力

	cin >> S;

	solve();
	cout << endl;
	return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){
    ll k,n;
    cin>>k>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll d = a[n-1] - a[0];
    for(ll i =1;i<n-1;i++){
        ll dd = a[i+1] - a[i];
        dd = k - dd;
        d = min(d,dd); 
    }
        cout << d ;
}

int main(){
    #ifdef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

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

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> P, Q;

	cin >> N;
	P.resize(N);
	Q.resize(N);
	for (auto &in: P) {
		cin >> in;
	}
	for (auto &in: Q) {
		cin >> in;
	}

	vector<int> check(N);
	int pid = 0, qid = 0;

	iota(ALL(check), 1);
	do {
		bool same = true;
		for (int i = 0; i < N; ++i) {
			same &= P[i] == check[i];
		}
		if (same) break;

		++pid;
	} while (next_permutation(ALL(check)));

	iota(ALL(check), 1);
	do {
		bool same = true;
		for (int i = 0; i < N; ++i) {
			same &= Q[i] == check[i];
		}

		if (same) break;
		++qid;
	} while (next_permutation(ALL(check)));

	cout << abs(pid - qid) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

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

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(3 * n);
	rep(i, 3 * n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	ll res = 0;
	for (ll i = 3 * n - 2;i >= 0;i -= 2) {
		ans += a[i];
		res++;
		if (res == n)break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5560
#include <iostream>
#include <cmath>
using namespace std;
 
const int MAX=pow(10,5);
const int INF=pow(10,9);
long long int DP[MAX+105];
long long int Tab[MAX+105];
 
int N,K;
int main()
{
   ios::sync_with_stdio(false);
   cin >> N >> K;
   for(int i=0;i<N;i++)
   {
      cin >> Tab[i];
      DP[i]=INF;
   }
   DP[0]=0;
    
    for(int i=1;i<N;i++)
       for(int j=1;j<=K;j++)
          if(i-j>=0)
             DP[i]=min(DP[i],DP[i-j]+abs(Tab[i]-Tab[i-j]));

     cout<< DP[N-1];
}   

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 // freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
 	ll n;
 	cin>>n;
 	ll ans=0,i=1,j,k;
 	while(i<=n)
 	{
 		j=1;
 		while(j<=n)
 		{
 			k=1;
 			while(k<=n)
 			{
 				ans+=__gcd(i,__gcd(j,k));
 				k++;
 			}
 			j++;
 		}
 		i++;
 	}
 	deb(ans);
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p, d;

    cin >> n >> m >> x;
    a = max(n,m);
    b = ceil((double)x/a);
    cout << b;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    string s,t,r;
    cin>>s>>t;
    for(i=0;i<n;i++)
    {
        r=r+s[i];
        r=r+t[i];
    }
    cout<<r;
}

Measured memory_bytes: 3580
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

int main(){

	int n,m,a,b;
	cin >> n >> m;

	int x,s=m,t=m; bool f=true;
	rep(i,n){
		cin >> a >> b;
		s+=a-b;
		if(s<0){
		cout << 0 << endl; f=false; break;
		}
		else{
		x=s;
		if(x>t) t=x;
		}
	}

    if(f) cout << t << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int grid[1000][1000] = {};
int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0;i < h;++i) {
		string s;
		cin >> s;
		for (int q = 0;q < w;++q) {
			if (s[q] == '#') grid[i][q] = 1;
		}
	}
	for (int i = 0;i < h;++i) {
		for (int q = 0;q < w;++q) {
			if (q == 0 || q == w - 1 || i == 0 || i == h - 1||grid[i][q] == 1) {
				cout << "#";
			}else if(i % 2 == 1 && q != 1){
				cout << "#";
			}
			else cout << ".";
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0;i < h;++i) {
		for (int q = 0;q < w;++q) {
			if ((q == 1&&i != 0&&i != h-1) || grid[i][q] == 1 || (i % 2 == 0 && i != 0 && i != h - 1 && q != 0 && q != w - 1)) {
				cout << "#";
			}
			else cout << ".";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <set>

int main(int argc, char *argv[]) {
  int n, m;
  std::cin >> n;
  std::set<int> a, b;
  int x;
  for (int i = 0; i < n; ++i) {
    std::cin >> x;
    a.insert(x);
  }
  std::cin >> m;
  for (int i = 0; i < m; ++i) {
    std::cin >> x;
    b.insert(x);
  }

  std::set<int> res;
  std::set_intersection(a.begin(), a.end(), b.begin(), b.end(),
                 std::inserter(res, res.end()));
  for (auto &v : res)
    std::cout << v << std::endl;
}



Measured memory_bytes: 23760
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n;
  string S;
  cin >> n >> S;
  int bl[n+1], wl[n+1];
  int b=0,w=0;
  int ans = INF;
  LOOP(i,n){
    if(S[i]=='.')w++;
    else b++;
    wl[i]=w;
    bl[i]=b;
  }
  wl[n]=w, bl[n]=b;
  ans = w;
  LOOP(i,n){
    int an = bl[i] + (w-wl[i]);
    ans = min(ans,an);
    // cerr <<i << " "<< bl[i] << " " << wl[i] << " " << an << endl;
  }
  cout << ans << endl;
}
/*                 |
##>#>>####>#|>>>|>>##|#>#>#
12 3  4567 8|8   |  90|1 2 3
  1 23    4 |567|89  | 0 1
1212101234343210-0121212
i = # + >
  */


Measured memory_bytes: 2180
#include <stdio.h>
#include <math.h>

int main()
{
        int n,ans;
        double xa,ya,ra,xb,yb,rb;
        double d;

        scanf("%d",&n);
        while(n--){
                scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
                d=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); ans=1;
                if(d<fabs(ra-rb)){
                        ans=2;
                        if(ra<rb)ans=-2;
                }
                else if(d>(ra+rb))ans=0;
                printf("%d\n",ans);
        }
        return 0;
}

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

int main()

{
   long long a=0,b=0,c,d,e,f,g,h,i,j,k,l,m,n,t;

   string s;

   cin>>s;

   if(s.size()==1) cout<<0<<endl;

   else

   {
       for(i=0;i<s.size();i++)
       {
           if(s[i]=='1' && i%2!=0) a++;

           else if(s[i]=='0' && i%2!=1) a++;
       }

       for(i=0;i<s.size();i++)

       {
           if(s[i]=='1' && i%2!=1) b++;
            else if(s[i]=='0' && i%2!=0) b++;
       }

       c=min(a,b);

       cout<<c<<endl;


   }
}


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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 2e5 + 10;

int a[maxn];

int main(int argc, char *argv[]) {
	int n;
	scanf("%d", &n);
	long long ans = -1;
	a[0] = -1;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		if(a[i] - a[i - 1] > 1) {
			puts("-1");
			return 0;
		}
		if(a[i] - a[i - 1] == 1) {
			++ans;
		}
		else {
			ans += a[i];
		}
	}
	printf("%"LLFORMAT"d\n", ans);
	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
 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");
 }
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;

int a,b,q;
long long s[maxn],t[maxn];

long long solve(long long x, long long s[], int a) {
	int i = upper_bound(s,s+a,x)-s;
	long long ret = infLL;
	if (i < a) ret = min(ret, s[i]-x);
	if (i > 0) ret = min(ret, x - s[i-1]);
	return ret;
}

long long solve(long long x, long long s[],int a,long long t[],int b) {
	int i = upper_bound(s,s+a,x)-s;
	long long ret = infLL;
	if (i < a) ret = min(ret, s[i]-x+solve(s[i],t,b));
	if (i > 0) ret = min(ret, x - s[i-1]+solve(s[i-1],t,b));
	return ret;
}

int main() {
	scanf("%d%d%d",&a,&b,&q);
	for (int i = 0; i < a; i++) scanf("%lld",&s[i]);
	for (int i = 0; i < b; i++) scanf("%lld",&t[i]);
	for (int i = 0; i < q; i++) {
		long long x;
		scanf("%lld",&x);
		printf("%lld\n",min(solve(x,s,a,t,b),solve(x,t,b,s,a)));
	}
}

Measured memory_bytes: 5316
#include <iostream>
using namespace std;
using ll = long long;
int main(){
  ll n,m;
  cin >> n >> m;
  ll ans;
  if(m >= 2*n){
    ans = n + (m-2*n)/4;
  }else{
    ans = m/2;
  }
  cout << ans << endl;
}


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


#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

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; }
template<class T> inline bool chmin(T a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
typedef long long int ll ;


#define INF 2000000000


int main() {
 
    int n;
    bool res ;
    
    cin >> n ;
    vector<int> a(n);
    
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    
    sort(a.begin(),a.end());

    auto z = unique(a.begin(),a.end());
    //a.erase(z,a.end());
    
    *z > 0 ? (cout << "NO") : (cout <<"YES") ;
    
    
//    for(auto z:a){
//        cout << z << endl;
//    }
    
  
}


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

int Dice[6];

void shake(char c){
  if(c == 'E'){
    swap(Dice[0], Dice[3]);
    swap(Dice[3], Dice[5]);
    swap(Dice[5], Dice[2]);
  }
  if(c == 'N'){
    swap(Dice[0], Dice[1]);
    swap(Dice[1], Dice[5]);
    swap(Dice[5], Dice[4]);
  }
  if(c == 'S'){
    swap(Dice[1], Dice[0]);
    swap(Dice[0], Dice[4]);
    swap(Dice[4], Dice[5]);
  }
  if(c == 'W'){
    swap(Dice[3], Dice[0]);
    swap(Dice[0], Dice[2]);
    swap(Dice[2], Dice[5]);
  }
}
int main(){
  int q, i, j, k, a, b;
  char direction[10] = {"NNNNWNNNN"};
  for(i = 0; i < 6; i++) cin >> Dice[i];
  cin >> q;
  for(i = 0; i < q; i++){
    cin >> a >> b;
    for(j = 0; j < 10; j++){
      if(Dice[1] == b) break;
      shake(direction[j]);
    }
    for(k = 0; k < 4; k++){
      if(Dice[0] == a){
        cout << Dice[2] << endl;
        break;
      }
      shake('W');
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm> // min()
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <tuple>
#include <climits> // INT_MAX
#include <cmath> // ceil()
#define rep(i, n) for (int i = 0; i < n; ++i)

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



int main() {
	int h, w, black_num = 0, times = 0;
	cin >> h >> w;

	auto max_black = h * w;

	vector<string> mp(h);
	queue<P> q;
	rep(i, h) {
		cin >> mp[i];
		rep(j, w) {
			if (mp[i][j] == '#') {
				q.emplace(j, i);
				++black_num;
			}
		}
	}

	if (max_black == black_num) {
		cout << 0 << endl;
		return 0;
	}

	int dx[] = { 1, -1, 0, 0 };
	int dy[] = { 0, 0, 1, -1 };
	queue<P> p;

	int x, y, x_next, y_next;
	while (true) {
		while (!q.empty()) {

			x = q.front().first;
			y = q.front().second;
			q.pop();

			rep(i, 4) {
				x_next = x + dx[i];
				y_next = y + dy[i];
				if (x_next < 0 || x_next >= w) continue;
				if (y_next < 0 || y_next >= h) continue;
				if (mp[y_next][x_next] == '#') continue;

				p.emplace(x_next, y_next);
				mp[y_next][x_next] = '#';
				++black_num;
			}
		}
		q.swap(p);
		++times;
		if (black_num == max_black) break;
	}

	cout << times << endl;
	return 0;
}


Measured memory_bytes: 9488
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll MOD = (ll)1e9 + 7 ;
const int MAXN = 1e5 + 100;

void solve(){
    ll x; cin >> x;
    ll ans = 0;
    ll temp = x/500;
    ans += temp * 1000;
    x %= 500;
    ans += (x/5) * 5;
    cout << ans << '\n';

}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    cout << min((n+a-1)/a*b, (n+c-1)/c*d) << "\n";
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 100100100100100100;
ll N,d[100000];vector<P> G1[100000],G2[100000];
void dijkstra1(ll s){
  ll fn,fc,i;
  priority_queue<P,vector<P>,greater<P>> q;
  fill(d,d+N,inf);q.push(P(0,s));d[s] = 0;//コスト、頂点
  while(!q.empty()){
    fn = q.top().second;fc = q.top().first;q.pop();
    if(d[fn]<fc) continue;
    for(i=0;i<G1[fn].size();i++){
      if(d[G1[fn][i].first]>d[fn]+G1[fn][i].second){
        d[G1[fn][i].first] = d[fn]+G1[fn][i].second;
        q.push(P(d[G1[fn][i].first],G1[fn][i].first));
      }
    }
  }
}
void dijkstra2(ll s){
  ll fn,fc,i;
  priority_queue<P,vector<P>,greater<P>> q;
  fill(d,d+N,inf);q.push(P(0,s));d[s] = 0;//コスト、頂点
  while(!q.empty()){
    fn = q.top().second;fc = q.top().first;q.pop();
    if(d[fn]<fc) continue;
    for(i=0;i<G2[fn].size();i++){
      if(d[G2[fn][i].first]>d[fn]+G2[fn][i].second){
        d[G2[fn][i].first] = d[fn]+G2[fn][i].second;
        q.push(P(d[G2[fn][i].first],G2[fn][i].first));
      }
    }
  }
}
int main(){
  ll m,s,t,i,j,w,u,a,b;scanf("%lld%lld%lld%lld",&N,&m,&s,&t);s--;t--;
  ll anss[N],anst[N],ansm[N];
  for(i=0;i<m;i++){
    scanf("%lld%lld%lld%lld",&w,&u,&a,&b);w--;u--;
    G1[w].push_back(P(u,a));
    G2[w].push_back(P(u,b));
    G1[u].push_back(P(w,a));
    G2[u].push_back(P(w,b));
  }
  dijkstra1(s);
  for(i=0;i<N;i++) anss[i] = d[i];
  dijkstra2(t);
  for(i=0;i<N;i++) anst[i] = d[i];
  for(i=0;i<N;i++) ansm[i] = anss[i]+anst[i];
  for(i=N-2;i>=0;i--) ansm[i] = min(ansm[i],ansm[i+1]);
  for(i=0;i<N;i++) printf("%lld\n",1000000000000000-ansm[i]);
}

Measured memory_bytes: 19840
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int N;
    static void Main()
    {
        N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x=>Int32.Parse(x)).ToArray();
        var ball = new int[N];

        for (int i=N-1;0<=i;--i)
        {
            var other = (calc(ball, i + 1)) % 2;
            ball[i] = other == 0 ? a[i] : a[i] == 0 ? 1 : 0 ;
        }

        var b = ball.Where(x => x == 1).ToArray();
        var count = b.Count();
        if (count == 0)
        {
            Console.WriteLine(0);
            return;
        }
        Console.WriteLine(count);
        var c = 0;
        for (int i=0;i<N;++i) {
            if (ball[i] == 1)
            {
                Console.Write(i+1);
                c++;
            }
            if (c!=count)Console.Write(" ");
        }
        Console.WriteLine();
    }

    static int calc(int[] ball,int num)
    {
        var index = num;
        var n = 0;
        for (int i=2; ;++i)
        {
            if (N < index*i) break;
            n += ball[index*i - 1];
        }
        return n;
    }
}


Measured memory_bytes: 29404
import itertools
import collections

k = int(input())

Z = []

for kk in range(k):
    x, y = map(int, input().split())
    Z.append((x, y))

a = ()

for v in itertools.permutations(range(8)):
    X = []
    Y = []
    V = []
    for i, vv in enumerate(v):
        V.append((i, vv))
    flag = False
    for kk in range(k):
        if Z[kk] not in V:
            flag = True
            break
    if flag:
        continue
    for i, vv in enumerate(v):
        X.append(i+vv)
        Y.append(i-vv)
    x = collections.Counter(X)
    y = collections.Counter(Y)
    if x.most_common()[0][1] >= 2 or y.most_common()[0][1] >= 2:
        continue
    a = v
    break

for i in range(8):
    print('.'*a[i] + 'Q' + '.'*(7-a[i]))


Measured memory_bytes: 6032
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < ll, ll >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 100005
   /* string with spaces   getline(cin,s);*/
   /*
          integer to string              ll n=0;  ostringstream o1;  string s; o1<<n; s=o1.str();
    */

   void SieveOfEratosthenes(int n,map<ll,ll> &m)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
            prime[i] = false;}}
    for (int p=2; p<=n; p++)
       if (prime[p]) m[p]++;

}
ll isprime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return 0;
    return 1;
}


int main()
{

        ll m,n;
        cin>>n>>m;
        ll mat[n][m];
        ll dp[n][m];
        forl(i,0,n,n)
        {
            forl(j,0,n,m)
            {
                dp[i][j]=0;
                char x;
                cin>>x;
                if(x=='#')mat[i][j]=-1;
                else
                    mat[i][j]=0;
            }
        }

        dp[0][0]=1;
        forl(i,0,n,n)
        {
            if(mat[i][0]!=-1){dp[i][0]=1;}
            else{
                dp[i][0]=0;
                break;}
        }
        forl(j,0,n,m)
        {            if(mat[0][j]!=-1)dp[0][j]=1;
            else
               {
                dp[0][j]=0;
                break;
               }

        }
        forl(i,1,n,n)
        {
            forl(j,1,n,m)
            {
                if(mat[i][j]==-1)dp[i][j]=0;
                else
                dp[i][j]=(dp[i-1][j]%1000000007+dp[i][j-1]%1000000007)%1000000007;
            }
        }

        cout<<dp[n-1][m-1]%1000000007<<endl;


}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
bool f[1005005];

int main(){
    int k;
    cin >> k;
    int surplus = 7%k;
    for(int i = 1; ; i++) {
        if(f[surplus]) { //余りのループ判定
            cout << -1 << endl;
            return 0;
        }
        if(surplus == 0) { //割り切れたかどうか判定
            cout << i << endl;
            break;
        }
        f[surplus] = true;
        surplus = (7 + (surplus*10)%k) % k;
    }
    return 0;
}

Measured memory_bytes: 4572
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();

		for (int i = 0; i < 10; i++) {
			x = r * x - d;
			System.out.println(x);
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int n;cin>>n;int a[n],b[n+1]={1},cnt=0;bool ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n+1;i++){
        b[i]=a[b[i-1]-1];
        cnt++;
        if(b[i]==2){
            ans=1;
            break;
        }
        else if(b[i]==1&&i!=0) break;
    }
    if(ans) cout<<cnt<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 1024
/*

tags: [树形DP] [DFS] 

题解：
任取一个非叶子节点，经过它的路径有两种：
1. 经过它的一个儿子。
2. 经过它的两个儿子。

对于点i, 设它的儿子的权值和为sum，儿子中权值最大的为mx，设有x条第2️种路径经过点i。

那么 cnt[i] - x = sum - 2 * x;

解得：x = sum - cnt[i];

若能找到合法解，那么 cnt[i] >= x >= 0， 



*/

#include <iostream>
#include <vector>
using namespace std;
const int N = 111111;
vector<int> a[N];
long long cnt[N];

long long dfs(int v, int p = -1) 
{
    if (a[v].size() == 1) 
    {
        return cnt[v];
    }
    long long mx = 0;
    long long sum = 0;
    for (int i=0;i<a[v].size();i++) 
    { 
        int cur = a[v][i];
        if (cur == p) continue; 
        long long mn = dfs(cur, v); 
        mx = max(mx, mn); sum += mn; 
    }
    long long x = sum - cnt[v];
    int num_sm = (sum - max(sum % 2, 2 * mx - sum)) / 2;
    //if (sum - num_sm <= cnt[v] && sum >= cnt[v]) 
    //    return sum - 2 * (sum - cnt[v]); 
    if(cnt[v] >= x && x >= 0 && x <= sum - mx) 
        return 2 * cnt[v] - sum;
    else {
        puts("NO");
        exit(0);
    }
}
 
int main() 
{ 
    int n; cin >> n; 
    for (int i = 0; i < n; ++i) cin >> cnt[i];
    for (int i = 0; i < n - 1; ++i) 
    { 
        int u, v;  cin >> u >> v; --u, --v; 
        a[u].push_back(v); a[v].push_back(u); 
    }
    int root = 0;
    if (n == 2) 
    {
        if (cnt[0] == cnt[1]) puts("YES"); 
        else puts("NO"); return 0;
    }
    while (a[root].size() == 1) ++root;
    if (dfs(root)) puts("NO"); 
    else puts("YES");
}


Measured memory_bytes: 13440
x,y,a,b,c=map(int, input().split())
*p,=map(int, input().split())
*q,=map(int, input().split())
*r,=map(int, input().split())
from heapq import *
p=[-i for i in p]
q=[-i for i in q]
r=[-i for i in r]
heapify(p)
heapify(q)
heapify(r)
ans=0
cnt=0
pt=heappop(p)
qt=heappop(q)
rt=heappop(r)
n=x+y
while (x>=0 or y>=0) and cnt<n:
  if rt==0:
    if pt<=qt:
      ans-=pt
      x-=1
      cnt+=1
      if p and x>0: pt=heappop(p)
      else: pt=0
    else:
      ans-=qt
      y-=1
      cnt+=1
      if q and y>0: qt=heappop(q)
      else: qt=0
  elif pt<=rt:
    ans-=pt
    x-=1
    cnt+=1
    if p and x>0: pt=heappop(p)
    else: pt=0
  elif qt<=rt:
    ans-=qt
    y-=1
    cnt+=1
    if q and y>0: qt=heappop(q)
    else: qt=0
  else:
    ans-=rt
    cnt+=1
    if r: rt=heappop(r)
    else: rt=0
print(ans)


Measured memory_bytes: 123936
n, c, k = gets.split.map(&:to_i)
t = n.times.map { gets.to_i }.sort

ans = 0
j = 0
cnt = 1
1.upto(n-1) do |i|
  if k >= t[i] - t[j] && c > cnt
    cnt += 1
  else
    cnt = 1
    ans += 1
    j = i
  end
end
p ans + 1

Measured memory_bytes: 4656
def insertion_sort(a, n)
    for i in 1...n do
        puts a.join(" ")
        j = i - 1
        v = a[i]
        while j >=0 && a[j] > v do
            a[j + 1] = a[j]
            j -= 1
        end
        a[j+1] = v
    end
end

n = gets.to_i
a = gets.split.map(&:to_i)

insertion_sort(a, n)
puts a.join(" ")


Measured memory_bytes: 6892
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstdlib>
using namespace std;

typedef long long LL;

const LL inf = LLONG_MAX / 2;

struct node{
	char ch;
	LL refcnt;
	LL len;
	vector<node*> to;
	
	node(char c, LL r = 0, LL len = -1)
	: ch(c), refcnt(r), len(len) {}
};

struct state{
	int stnum;
	node *nd;
	LL a, b;
	size_t cntr;
	
	state(int s, node *nd, LL a, LL b, size_t c)
	: stnum(s), nd(nd), a(a), b(b), cntr(c) {}
};

node *alp[26];
node emp(0, inf, 0);
string ans;

node *getnode(int c){
	if(c == '.'){ return &emp; }
	node *&ret = alp[c - 'a'];
	if(!ret){ ret = new node(c); }
	return ret;
}

void delnode(node *nd){
	queue<node*> q;
	q.push(nd);
	while(q.empty()){
		nd = q.front();
		q.pop();
		for(size_t i = 0; i < nd->to.size(); ++i){
			node *next = nd->to[i];
			if(!--next->refcnt){
				q.push(next);
			}
		}
		delete nd;
	}
}


void dfs(node *nd0, LL a0, LL b0){
	stack<state> stk;
	stk.push(state(0, nd0, a0, b0, 0));
	while(!stk.empty()){
		state &tp = stk.top();
		int &num = tp.stnum;
		node *&nd = tp.nd;
		LL &a = tp.a;
		LL &b = tp.b;
		size_t &cntr = tp.cntr;

		if(num == 0){
			if(a >= b){
				stk.pop();
				continue;
			}
			if(nd->ch){
				nd->len = 1;
				if(a == 0){
					ans += nd->ch;
				}
				stk.pop();
				continue;
			}
			if(nd->len >= 0 && nd->len <= a){
				stk.pop();
				continue;
			}

			nd->len = 0;
			num = 1;
		}
		else if(num == 1){
			if(cntr >= nd->to.size()){
				stk.pop();
				continue;
			}
			node *next = nd->to[cntr];
			
			while(next->to.size() == 1){
				node *tmp = next;
				nd->to[cntr] = next->to[0];
				next = next->to[0];

				if(--tmp->refcnt){
					++next->refcnt;
				}
				else{
					delete tmp;
				}
			}

			num = 2;
			stk.push(state(0, next, a, b, 0));
		}
		else if(num == 2){
			node *next = nd->to[cntr];
			LL olen = next->len;
			a = max(a - olen, 0LL);
			b = max(b - olen, 0LL);
			nd->len = min(nd->len + olen, inf);

			if(next->len == 0){
				nd->to.erase(nd->to.begin() + cntr);
				--cntr;
				if(!--next->refcnt){
					delnode(next);
				}
			}
			
			++cntr;
			num = 1;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);

	string s;
	LL q, a, b;
	char c;
	cin >> s >> q >> a >> b;
	--a;

	node *root = new node(0);
	root->to.resize(s.size());
	for(size_t i = 0; i < s.size(); ++i){
		node *next = getnode(s[i]);
		root->to[i] = next;
		++next->refcnt;
	}

	for(LL i = 0; i < q; ++i){
		cin >> c >> s;
		node *nd = alp[c - 'a'];
		if(!nd){ continue; }
		alp[c - 'a'] = 0;

		nd->ch = 0;
		nd->to.resize(s.size());
		for(size_t j = 0; j < s.size(); ++j){
			node *next = getnode(s[j]);
			nd->to[j] = next;
			++next->refcnt;
		}
	}

	dfs(root, a, b);
	if(ans.size() < b - a){
		ans = ".";
	}
	cout << ans << '\n';
	
	delnode(root);
}

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

int main()
{
  long long a, b, c;

  cin >> a >> b >> c;
  if (c - a - b >= 0 && 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256