akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>

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

using namespace std;

int main() {
	int n,i,ans;
	
	while(1){
		cin>>n;
		if(n==0){
			break;
		}
		int a[n]={0};
		rep(i,n){
			cin>>a[i];
		}
		sort(a,a+n);
		ans=a[1]-a[0];
		
		for(int i=1;i<n-1;i++){
			if(ans>a[i+1]-a[i]){
				ans=a[i+1]-a[i];
			}
		}
		cout<<ans<<endl;
	}
	
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 3156
import java.util.*;
public 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 res=0;
		
		
			res = (b/x) - (a/x);
			if (a%x==0) {
				res++;}
			
		
		System.out.println(res);
	}

}


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

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

int stoi(const char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return -1;
  }
}

int main() {
  ll n, h, ans = 0, dmg = 0;
  cin >> n >> h;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a), greater<int>());
  sort(all(b), greater<int>());

  rep(i, n) {
    if (b[i] > a[0]) {
      h-= b[i];
      ans++;
      if (h <= 0) {
        cout << ans;
        return 0;
      }
    } else {
      break;
    }
  }
  ans += (h + a[0] - 1) / a[0];

  cout << ans;
  return 0;

  return 0;
}


Measured memory_bytes: 1920
using System;

namespace AizuOnLine_Lesson
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = Convert.ToInt32(Console.ReadLine());

            int h = num / 3600;
            num = num % 3600;

            int m = num / 60;
            int s = num % 60;
            
            Console.WriteLine(string.Format("{0}:{1}:{2}", h, m, s));
        }
    }
}

Measured memory_bytes: 17948
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    std::map<char, int> x{};
    std::map<char, int> y{};
    std::map<char, bool> dual{};
    for (int i = 0; i < n; i++) {
        y[s[i]]++;
        dual[s[i]] = false;
    }
    std::vector<int> vec{};
    for (int i = 0; i < n; i++) {
        x[s[i]]++;
        y[s[i]]--;
        if (y[s[i]] > 0) {
            dual[s[i]] = true;
        } else {
            dual[s[i]] = false;
        }
        int num = 0;
        for (auto& x : dual)
            num += x.second;
        vec.push_back(num);
    }
    std::cout << *std::max_element(vec.begin(), vec.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;

#define TMAX 50
#define PMAX 10

struct S{
	int ok,ti,no,wa[PMAX+1],swa;
};

bool operator<(S a,S b){
	return a.ok>b.ok||a.ok==b.ok&&a.ti<b.ti||a.ok==b.ok&&a.ti==b.ti&&a.no>b.no;
}

int main(){
	int M,T,P,R;
	int m,t,p,j;
	vector<S> dia;
	S s;


	while(1){
		cin>>M>>T>>P>>R;
		if(M==0&&T==0&&P==0&&R==0) break;

		for(int i=0;i<=T;i++){
			s.no=i,s.ok=0,s.ti=0,s.swa=0;
			for(int j=1;j<=P;j++) s.wa[j]=0;
			dia.push_back(s);
		}
		dia[0].ok=-1;

		for(int i=0;i<R;i++){
			cin>>m>>t>>p>>j;
			if(j!=0) dia[t].wa[p]++;
			else dia[t].ti+=m,dia[t].swa+=dia[t].wa[p],dia[t].ok++;
		}
		for(int i=1;i<=T;i++){
			dia[i].ti+=dia[i].swa*20;
		}

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

		for(int i=0;i<T-1;i++){
			if(dia[i].ti==dia[i+1].ti&&dia[i].ok==dia[i+1].ok) cout<<dia[i].no<<"=";
			else cout<<dia[i].no<<",";
		}
		cout<<dia[T-1].no<<endl;
		dia.clear();
	}
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> A(N),B(M);
  int maxa=-100;
  int minb=100;
  for(int i;i<N;i++){
    cin>>A.at(i);
    maxa=max(maxa,A.at(i));
  }
  for(int i;i<M;i++){
    cin>>B.at(i);
    minb=min(minb,B.at(i));
  }
  if(maxa<minb&&maxa>=X&&minb<Y){
    cout<<"No War";
  }else{
    cout<<"War";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int main(){
    int n;
    while(cin >> n && n){
        int a[1001];
        rep(i, n) cin >> a[i];
        int ans = 1e9;
        rep(i, n) rep(j, i) ans = min(ans, abs(a[i] - a[j]));
        cout << ans << endl;
    }
}

Measured memory_bytes: 3068
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define F first
#define S second
#define pb push_back
#define endl "\n"

#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define rSORT(a) sort(rALL(a))
#define REV(a) reverse(ALL(a))
#define sqr(x) ((x) * (x))

//===========================================================

int recur_depth = 0;
#ifdef DEBUG
#define xtp(x)                                                           \
	{                                                                    \
		++recur_depth;                                                   \
		auto x_ = x;                                                     \
		--recur_depth;                                                   \
		cerr << string(recur_depth, '\t') << __func__ << ":" << __LINE__ \
			 << "\t" << #x << " = " << x_ << endl;                       \
	}
#else
#define xtp(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
	Ostream& os, const Cont& v) {
	os << "[";
	for (auto& x : v) {
		os << x << ", ";
	}
	return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
	return os << "{" << p.first << ", " << p.second << "}";
}

//===========================================================

#define TEZ                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);

const long double PI = 3.1415926535897932384626433832795;
const ll mod = 1000000007LL;
const int INF = 1000000000;

int main() {
	TEZ;

	int n;
	cin >> n;

	n %= 1000;

	n = 1000 - n;
	n %= 1000;

	cout << n << endl;

	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

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

		// input
		final long NUM = scan.nextLong();
		int keta = 0;
		long temp = NUM;
		int[] nums = new int[20];
		int i = 0;
		int def = 0;
		while(temp > 0){
			nums[i++] = (int)(temp % 10);
			def += nums[i-1];
			temp /= 10;
			keta++;
		}
		
		// search
		int sum = 0;
		for(int j = 0; j < keta; j++){
			if(j == keta - 1){
				sum += nums[j] - 1;
			} else {
				sum += 9;
			}
		}
		
		// answer
		if(sum > def){
			System.out.println(sum);
		} else {
			System.out.println(def);
		}
		
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int k;
    cin >> k;
    if(k%2 == 0 || k%5 == 0){
        cout << -1 << endl;
    }else{
        int ans = 1;
        int cur = 7 % k;
        while(cur){
            cur = (10*cur + 7) % k;
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define int ll
#define inf 0x7f7f7f7f
#define maxn 500450
#define mod 998244353
#define IT set<node>::iterator
inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline int max(int a,int b)
{
	if(a>b) return a;
	return b;
}
int n;
int d[maxn];
int tot[maxn];
ll ans=1;
inline int ksm(int a,int b)
{
	int sum=1;
	a%=mod;
	while(b)
	{
		if(b&1) sum=(sum*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return sum;
}
signed main()
{
	n=read();
	for(rg int i=1;i<=n;++i) d[i]=read(),tot[d[i]]++;
	if(d[1]!=0) cout<<0;
	else
	{
		for(rg int i=2;i<=n;++i)
		{
			if(d[i]==0)
			{
				cout<<0;
				return 0;
			}
		}
		for(rg int i=1;i<=n;++i)
		{
			if(tot[i]!=0&&tot[i-1]==0)
			{
				cout<<0;
				return 0;
			}
		}
		for(rg int i=2;i<=n;++i)
		{
			if(tot[i]==0) break;
			else
			{
				ans*=ksm(tot[i-1],tot[i]);
				ans%=mod;
			}
		}
		cout<<ans;
	}
} 

Measured memory_bytes: 5120
import sys
import math

str = input() # input()で入力を受け取り、それを変数strに代入
#print(str)
#print(str.split(' '))

ary = str.split(' ')
N = int(ary[0])
B = int(ary[1])
R = int(ary[2])

if(B == 0):
  print(B)
  sys.exit()

a = N % (B+R)
ret = math.floor(N / (B+R))*B + (a if a < B else B)
print(ret)  
  

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

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

void solve() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
        x[i] = abs(x[i] - X);
    }

    int ans;
    ans = x[0];
    for (int i = 1; i < N; i++)
    {
        ans = gcd(ans, x[i]);
    }
    
    cout << ans << endl;
}

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

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n, w, h;

struct PP {
	int a, b;
} p[maxx];

int main() {
	cin >> n >> h >> w;
	for(int i = 1; i <= n; i++) cin >> p[i].a >> p[i].b;
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(p[i].a >= h && p[i].b >= w) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
w = [0] * n
for i in range(n):
    w[i] = input()

rule = True
for i in range(1,n):
    if w[i][0] != w[i-1][-1]:
        rule = False
        break

w.sort()

for i in range(1,n):
    if w[i] == w[i-1]:
        rule = False
        break

if rule:
    print("Yes")
else:
    print("No")


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

using namespace std;
typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    string s;
    cin >> s;

    int r[n+2];
    r[0] = 0;
    for (int i = 0; i < n; i++) {
        r[i+1] = r[i] + (s[i]=='R');
    }

    int mn = r[n] - r[r[n]];

    reverse(s.begin(), s.end());
    int w[n+2];
    w[0] = 0;
    for (int i = 0; i < n; i++) {
        w[i+1] = w[i] + (s[i]=='W');
    }

    mn = min(mn, w[n] - w[w[n]]);

    mn = min(mn, min(w[n],r[n]));

    cout << mn;


    return 0;
}



Measured memory_bytes: 5320
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// Union Find

template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};
int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  vvll tomo(n+1,vll(0));
  vvll brok(n+1,vll(0));
  UnionFind<ll> uf(n+1);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    tomo[a].pb(b);
    tomo[b].pb(a);
    uf.unite(a,b);
  }
  rep(i,k){
    ll a,b;
    cin>>a>>b;
    brok[a].pb(b);
    brok[b].pb(a);
  }
  for(int i=1;i<=n;i++){
    ll cu=uf.size(i)-sz(tomo[i])-1;
    rep(j,sz(brok[i])){
      if(uf.same(i,brok[i][j]))cu--;
    }
    cout<<cu<<" ";
  }
}


Measured memory_bytes: 15252
using System;

namespace ABC092_A_Traveling_Budget
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int a = int.Parse(Console.ReadLine());
			int b = int.Parse(Console.ReadLine());
			int c = int.Parse(Console.ReadLine());
			int d = int.Parse(Console.ReadLine());

			int minBus;
			if (a >= b)
			{
				minBus = b;
			}
			else
			{
				minBus = a;
			}

			int minTrain;
			if (c >= d)
			{
				minTrain = d;
			}
			else
			{
				minTrain = c;
			}
			
			Console.WriteLine(minBus + minTrain);
		}
	}
}

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

void attack_cnt(int x, int y){
    if(x%y==0){
        cout << x/y << endl;
    }
    else{
        cout << x/y+1 << endl;
    }
}

int main(){
    int H,A; cin >> H >> A;
    attack_cnt(H,A);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    int A, B, T;
    cin >> A >> B >> T;
    cout << T / A * B << endl;
}


Measured memory_bytes: 3592
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    B = [0] * (N + 1)
    for i, a in enumerate(A):
        B[max(0, i - a)] += 1
        B[min(N, i + a + 1)] -= 1
    for i in range(N):
        B[i + 1] += B[i]
    A = B[:N]

    if min(A) >= N:
        break

print(*A)



Measured memory_bytes: 168544
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int cup[100],stat[100],sum[100],wat[200];
int N,SET;

int search(int cc,int left,int look,int num){
	int i;

	stat[look]=1;

	if(left==0){
		if(cc<N)stat[cc]=2;
		if(num==0)return 1;
		for(i=N-1;i>=0;i--){
			if(stat[i]==0)break;
			if(stat[i]==1 && search(i,cup[i],99,num))return 1;
		}
		if(look<N)stat[look]=0;
		stat[cc]=1;
		return 0;
	}

	int ccc=(look<N) ? look:cc;

	for(i=ccc-1;i>=0;i--){
		if(left<cup[i])continue;
		if(stat[i]==0 && search(cc,left-cup[i],i,num-1))return 1;
		if(i==cc-1 && stat[i]==0)break;
	}

	stat[look]=0;
	return 0;
}

int main(){
    int i,j,k;

    while(scanf("%d",&N)*N){

		for(i=0;i<=100;i++)wat[i]=0;
		for(i=0;i<N;i++){
			scanf("%d",&k);
			wat[k]++;
		}
		for(i=0,j=0,k=0;i<=100,j<N;i++){
			for(;wat[i]>0;wat[i]--){
				cup[j]=i;
				stat[j]=0;
				j++;
			}
		}

		if(search(99,0,N-1,N-1))printf("YES\n"); else printf("NO\n");

    }
 
    return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	unsigned long long int yen,happiness=0,count1=0 ,count2 = 0;
	cin >> yen;
	while(yen>=500){
		count1 = yen /500;
		happiness = happiness + (count1*1000);
		yen = yen-(500*count1);
	}
	while(yen>=5){
		count2 = yen/5;
		happiness = happiness + (count2*5);
		yen = yen-(5*count2);
	}
	cout<<happiness;
	return 0;
}


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

using namespace std;

#define lint long long
#define P pair<int, int>

bool dis(int a){
    
}

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

    set<int> D;

    for(int i = 0 ; i < K; ++i){
        int a;cin >> a;
        D.insert(a);
    }


    for(int i = N; ; ++i){
        bool flag = true;
        int tmp = i;
        while(tmp > 0){
            if(D.find(tmp % 10) != D.end()){
            flag = false;
            break;
            }
            tmp /= 10;
        }

        if(flag){
            cout << i << endl;
            return 0;
        }
    }


    


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define DBP //


int N, N2, Q, P;
short A[22];
short A2[22];
short M[202];

int rrr(short np, short zan) {
        int i, j;
        for (i = np; i < N2; i++) {
                if (A2[i] == zan) return true;
                if (A2[i] < zan) {
                        if (rrr(i + 1, zan - A2[i]) == true) {
                                return true;
                        }
                }
        }
        return false;
}

int checkm(short m) {
        int i, j=0;
        for (i = 0; i < N; i++) {
                if (A[i] <= m) {
                        A2[j++] = A[i];
                        if (A[i] == m) return true;
                }
        }
        N2 = j;
        return rrr( 0, m);
}

int main(void){
        int i;
        int ans;

        cin >> N;
        for (i = 0; i < N; i++) {
                cin >> A[i];
        }
        cin >> Q;
        for (i = 0; i < Q; i++) {
                cin >> M[i];
        }
        for (i = 0; i < Q; i++) {
                if (checkm(M[i]) == true) {
                        cout << "yes" << endl;
                } else {
                        cout << "no" << endl;
                }
        }
        return 0;
}


Measured memory_bytes: 3084
#include<cmath>
#include<queue>
#include<cstdio>

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

using namespace std;

typedef pair<int,int> pii;

const double INF=1e77,EPS=1e-9;

struct Point{
	int x,y;
	Point operator-(const Point &p)const{ return (Point){x-p.x,y-p.y}; }
};

struct Edge{
	int j,v;
	double cost;
	bool warp;
};

struct Floor{
	int n;
	vector<Edge> adj[20];
};

int  dot (const Point &p,const Point &q){ return p.x*q.x+p.y*q.y; }
int cross(const Point &p,const Point &q){ return p.x*q.y-p.y*q.x; }

double norm2(const Point &p){ return dot(p,p); }

double dist(const Point &p,const Point &q){ return sqrt(norm2(p-q)); }

bool identify(int i,int j,const Floor *F,const Point P[50][20],int *sigma){
	if(F[i].n!=F[j].n) return false;

	int n=F[i].n;
	rep(a,n) rep(b,n) if(a!=b) {
		bool ok=true;
		rep(u,n){
			int v;
			for(v=0;v<n;v++){
				Point vec_i[2]={P[i][0]-P[i][u],P[i][1]-P[i][u]};
				Point vec_j[2]={P[j][a]-P[j][v],P[j][b]-P[j][v]};
				if(norm2(vec_i[0])==norm2(vec_j[0])
				&& norm2(vec_i[1])==norm2(vec_j[1])
				&&  dot (vec_i[0],vec_i[1])== dot (vec_j[0],vec_j[1])
				&& cross(vec_i[0],vec_i[1])==cross(vec_j[0],vec_j[1]))
					break;
			}
			if(v<n) sigma[u]=v;
			else    ok=false;
		}
		if(!ok) continue;

		bool adj_i[20][20]={},adj_j[20][20]={};
		rep(u,n) rep(k,F[i].adj[u].size()) {
			Edge e=F[i].adj[u][k];
			if(!e.warp) adj_i[u][e.v]=true;
		}
		rep(u,n) rep(k,F[j].adj[u].size()) {
			Edge e=F[j].adj[u][k];
			if(!e.warp) adj_j[u][e.v]=true;
		}

		rep(u,n) rep(v,n) if(adj_i[u][v]!=adj_j[sigma[u]][sigma[v]]) ok=false;
		if(!ok) continue;

		return true;
	}

	return false;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		Floor F[50];
		Point P[50][20];
		rep(i,n){
			scanf("%d",&F[i].n);
			rep(k,F[i].n) scanf("%d%d",&P[i][k].x,&P[i][k].y);
			int b; scanf("%d",&b);
			rep(k,b){
				int u,v; scanf("%d%d",&u,&v); u--; v--;
				F[i].adj[u].push_back((Edge){i,v,dist(P[i][u],P[i][v])});
				F[i].adj[v].push_back((Edge){i,u,dist(P[i][u],P[i][v])});
			}
			int c; scanf("%d",&c);
			rep(k,c){
				int u,j,v; scanf("%d%d%d",&u,&j,&v); u--; j--; v--;
				F[i].adj[u].push_back((Edge){j,v,0,true});
			}
		}
		int si,su,gi,gu; scanf("%d%d%d%d",&si,&su,&gi,&gu); si--; su--; gi--; gu--;

		rep(j,n) rep(i,j) {
			int sigma[20];
			if(identify(i,j,F,P,sigma)){
				rep(u,F[i].n){
					int v=sigma[u];
					F[i].adj[u].push_back((Edge){j,v,0,true});
					F[j].adj[v].push_back((Edge){i,u,0,true});
				}
			}
		}

		double d[50][20],ans=-1;
		rep(i,n) rep(u,20) d[i][u]=INF;
		d[si][su]=0;

		priority_queue< pair<double,pii> > pq;
		pq.push(make_pair(0,make_pair(si,su)));
		while(!pq.empty()){
			pair<double,pii> a=pq.top(); pq.pop();
			int i=a.second.first,u=a.second.second;
			if(d[i][u]+EPS<-a.first) continue;

			if(i==gi && u==gu){ ans=d[gi][gu]; break; }

			rep(k,F[i].adj[u].size()){
				Edge e=F[i].adj[u][k];
				double nextd=d[i][u]+e.cost;
				if(nextd+EPS<d[e.j][e.v]){
					d[e.j][e.v]=nextd;
					pq.push(make_pair(-nextd,make_pair(e.j,e.v)));
				}
			}
		}

		printf("%f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 984
(r,c) = [int(i) for i in input().split()]

table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])

table.append([0 for  _  in range(c + 1)])

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
   print(' '.join([str(column) for column in row]))

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

using namespace std;

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

inline bool inrange(int x, int y) {
  return (0<=x&&x<8) && (0<=y&&y<8);
}

string F[8];
bool used[8][8];
int turn;

int dx, dy;
int dfs(int x, int y, char me, int cnt) {
  x += dx, y += dy;
  if(!inrange(x, y)) { return 0; }
  if(F[y][x] == '.') { return 0; }
  if(F[y][x] == me) {
    return cnt;
  }
  used[y][x] = 1;
  int r = dfs(x, y, me, cnt+1);
  if(r == 0) { used[y][x] = 0; }
  return r;
}

#define DREP(i, a, b)                                       \
  for(int i=turn&1?a:b; turn&1?i>=b:i<=a; turn&1?i--:i++)

int main() {
  rep(i, 8) cin >> F[i];
  int ucnt = 0;
  for(turn=0; turn<=64; turn++) {
    int pl;
    bool u[8][8] = {};
    int mx = 0;
    DREP(i, 7, 0) DREP(j, 7, 0) {
      if(F[i][j] == '.') {
        rep(a, 8) rep(b, 8) used[a][b] = 0;
        used[i][j] = 1;
        int r = 0;
        for(dy=-1; dy<2; dy++) for(dx=-1; dx<2; dx++) {
          if(dx == 0 && dy == 0) { continue; }
          r += dfs(j, i, "ox"[turn&1], 0);
        }            
        if(mx < r) {
          memcpy(u, used, sizeof u);
          mx = r; pl = turn&1;
        }
      }
    }
    if(mx > 0) {
      rep(i, 8) rep(j, 8)
        if(u[i][j]) { F[i][j] = "ox"[pl]; }
      ucnt = 0;
    }
    else {
      if(ucnt) { break; }
      ucnt ++;
    }
  }
  rep(i, 8) {
    rep(j, 8) {
      cout << F[i][j];
    }
    puts("");
  }
  
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

bool h=false;
ll q;
string s,s1,s2,ans;

int main(void){
	cin>>s>>q;
	rep(i,q){
		int t;
		cin>>t;
		if(t==1){
			h=!h;
		}else{
			int f;
			char c;
			bool a=false;
			cin>>f>>c;
			if(f==1)a=true;
			if(h ^ a){
				s1+=c;
			}else{
				s2+=c;
			}
		}
	}
	if(!h){
		reverse(s1.begin(), s1.end());
		ans=s1+s+s2;
	}else{
		reverse(s.begin(), s.end());
		reverse(s2.begin(), s2.end());
		ans=s2+s+s1;
		cerr<<"反転"<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1348
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(i * 500 + j * 100 + k * 50 == x) cnt++;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
ans = [0 for _ in range(n)]
bal = [1 for _ in range(n)]
ans[0] = 1
for _ in range(m):
    x, y = MAP()
    bal[x - 1] -= 1
    bal[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if not bal[x - 1]:
            ans[x - 1] = 0
print(sum(ans))

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

int main()
{
    string s;
    cin>>s;
   bool flag=1;
   for(int i=0;i<s.length();i=i+2)
   {
       if(s[i]=='L')
       {
           flag = 0;
       }
   }

   for(int i=1;i<s.length();i=i+2)
   {
       if(s[i]=='R')
       {
           flag = 0;
       }
   }

   if(flag)
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }


    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        t: [i64; n],
        m: usize,
        px: [(Usize1, i64); m],
    };
    let sum = t.iter().sum::<i64>();
    for &(p_i, x_i) in px.iter() {
        let ans = sum - t[p_i] + x_i;
        println!("{}", ans);
    }
}


Measured memory_bytes: 2144
import java.io.IOException
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val count = s.count { it == '0' }
    println(Math.min(count, s.length - count) * 2)
}

class Scanner(private val `in`: InputStream) {
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0

    companion object {
        private fun isPrintableChar(b: Byte): Boolean = b in 33..126
        private fun isNumericChar(b: Byte): Boolean = b in 48..57
        private fun digit(b: Byte): Int = b - 48
    }

    fun hasNextByte(): Boolean {
        if (ptr < buflen) return true
        ptr = 0
        try {
            buflen = `in`.read(buffer)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return 0 < buflen
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        return buildString {
            var b = readByte()
            while (isPrintableChar(b)) {
                appendCodePoint(b.toInt())
                b = readByte()
            }
        }
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextInts(n: Int): Array<Int> = Array(n) { nextInt() }

    fun nextIntArray(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextIntArrays(n: Int, m: Int): Array<IntArray> {
        val arrays = Array(m) { IntArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextInt() } }
        return arrays
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextLongs(n: Int): Array<Long> = Array(n) { nextLong() }

    fun nextLongArray(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextLongArrays(n: Int, m: Int): Array<LongArray> {
        val arrays = Array(m) { LongArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextLong() } }
        return arrays
    }

}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename H, typename... T> void debug_out(H h, T... t) {  cerr << " " << (h);  debug_out(t...); }
void read() {}
template <typename H, typename... T> void read(H &h, T&... t) { cin >> h; read(t...) ;}

#ifndef LOCAL
#define endl '\n'
#define debug(...) //
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


void solve() {
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  sort(a.begin(), a.end());

  long long total = accumulate(a.begin(), a.end(), 0);

  long long op1 = 0, op2 = 0;
  for (int i = 0; i < n; i += 2)
    op1 += a[i];
  for (int i = n - 1; i >= 0; i -= 2)
    op2 += a[i];

  if (op1 < op2) {
    swap(op1, op2);
  }
  long long b = total - op1;
  cout << op1 - b << endl;
}

int main() {
#ifndef LOCAL
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
  //int tc; cin >> tc;
  //while (tc--)
  solve();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, ans;
    cin >> n >> k;
    ans = k;
    for (int i = 1; i < n; i++)
    {
        ans *= k - 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	auto b = set<string>();
	string s;
	char c;
	bool ans = true;
	cin >> s;
	b.insert(s);
	c = *s.rbegin();
	for(auto i = 1; i < n; ++i){
		cin >> s;
		if(s[0] != c) ans = false;
		if(!b.insert(s).second) ans = false;
		c = *s.rbegin();
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
s = list(input())

if s == s[-1::-1]:
    s.insert(0, 'Z')
    a = s[1:(len(s)-1)//2+1]
    b = s[(len(s)+3)//2:]

    if a == a[-1::-1]:
        if b == b[-1::-1]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3060
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

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

        // height
        int h = sc.nextInt();

        // width
        int w = sc.nextInt();

        // マス目の状態
        char[][] masu = new char[h][w];

        // BFSのQueueを準備
        Deque<XY> q = new ArrayDeque<>();

        // 入力を受け取る & '#'のマスをEnQueue
        for (int i = 0; i < h; i++) {
            masu[i] = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if ('#' == masu[i][j]) {
                    q.add(new XY(i, j, 0));
                }
            }
        }

        // ans
        int max_depth = 0;

        // BFS主処理
        for (;;) {
            // 無限ループ開始

            // 終了条件
            if (q.size() < 1) {
                break;
            }

            // queueからdequeue
            // pollメソッドはqueueから取り出し & queueから削除
            XY xy = q.poll();
            int x = xy.x;
            int y = xy.y;
            int depth = xy.depth;

            // 操作の回数を記録
            if (depth >= max_depth) {
                max_depth = depth;
            }

            // 現在の位置の周囲を黒にする
            if (x + 1 < w && masu[y][x + 1] == '.') {
                // 右マス
                masu[y][x + 1] = '#';
                q.add(new XY(y, x + 1, depth + 1));
            }
            if (x - 1 >= 0 && masu[y][x - 1] == '.') {
                // 左マス
                masu[y][x - 1] = '#';
                q.add(new XY(y, x - 1, depth + 1));
            }
            if (y + 1 < h && masu[y + 1][x] == '.') {
                // 下マス
                masu[y + 1][x] = '#';
                q.add(new XY(y + 1, x, depth + 1));
            }
            if (y - 1 >= 0 && masu[y - 1][x] == '.') {
                // 上マス
                masu[y - 1][x] = '#';
                q.add(new XY(y - 1, x, depth + 1));
            }

        }

        System.out.println(max_depth);

    }
}

class XY {
    int y;
    int x;

    int depth;

    XY(int y, int x, int d) {
        this.x = x;
        this.y = y;
        depth = d;
    }
}

Measured memory_bytes: 73076
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int ans = 0;
  rep(k,N) {
    if(k+1>K) {
      ans += Y;
    } else {
      ans += X;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
  long long int t = 0, f = 2, s = 1;
  int n;
  scanf("%d", &n);
  if(n == 0) printf("2\n");
  else if(n == 1) printf("1\n");
  else{
    for(int i = 2; i <= n; i++){
      t = f + s;
      f = s;
      s = t;
    }
    printf("%lld\n", t);
  }
  return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int n; cin>>n;
    int A[n+2], L[n+2], R[n+2];
    for(int i = 0; i < n+2; i++) {L[i] = 0; R[i] = 0;}
    for(int i = 1; i <= n; i++)
    {
        cin>>A[i];
        L[i] = __gcd(A[i], L[i-1]);
    }
    int ans = 0;
    for(int i = n; i > 0; i--)
    {
        R[i] = __gcd(R[i+1], A[i]);
        ans = max(ans, __gcd(L[i-1], R[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
from itertools import*
n,c,*L=map(int,open(0).read().split())
a=[0]*(max(L[1::3])+1)
bef=(0,0)
for c,s,t in sorted((c,s,t) for s,t,c in zip(*[iter(L)]*3)):
	a[s-1+(bef==(c,s))]+=1
	a[t]-=1
	bef=(c,t)
print(max(accumulate(a)))

Measured memory_bytes: 30924
#include<stdio.h>
#define N 45
int Fib[N];

int F(int n){
  if(n==0||n==1)return Fib[n]=1;
  if(Fib[n]!=0)return Fib[n];
  return Fib[n]=F(n-1)+F(n-2);
}

int main(){
  int n,i;
  for(i=0;i<N;i++)Fib[i]=0;
  scanf("%d",&n);
  printf("%d\n",F(n));
  return 0;
}




Measured memory_bytes: 2104
import sys
import random
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


def is_prime(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True


def main():
    N = readint()
    if N == 1:
        print(0)
        exit()
    d = make_divisors(N)
    ans = 0
    # print(d)
    p = [i for i in d if is_prime(i)]
    # print(p)
    for i in range(1, 10):
        for z in [j ** i for j in p]:
            if z == 1:
                continue
            if not N % z:
                N //= z
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    string S, T;
    cin >> S >> T;

    int c = 0;

    string ABC = "abcdefghijklmnopqrstuvwxyz";

    for( int i = 0; i < S.length() ; i++ ) {
        if ( S[i] != T[i] ) {
            for ( int j = 0; j < ABC.length() ; j++) {
                S[i] = ABC[j];
                if ( S[i] == T[i] ) {
                    c++;
                }
            }
        }
    }

    cout << c << endl;
}

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

int main(){
  int i,j,k;
  
  char S[1000000];
  scanf("%s",S);
  int flg[26];
  for(i=0;i<strlen(S);i++){
    flg[(int)S[i]-97]=1;
  }
  
  for(i=0;i<26;i++){
    if(flg[i]==0){
      printf("%c\n",i+97);
      return 0;
    }
  }
  
  puts("None");
  return 0;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/


signed main()
{
  int n, k, q;
  cin >> n >> k >> q;

  vi a(n);
  rep(i, n){
    cin >> a[i];
  }

  int ans = inf;
  rep(i, n){
    vi v, w;
    rep(j, n){
      if(a[j] < a[i]){
        if(v.size() >= k){
          sort(all(v));
          rep(l, v.size()-k+1) w.pb(v[l]);
        }
        v.clear();
      }else{
        v.pb(a[j]);
      }
    }

    if(v.size() >= k){
      sort(all(v));
      rep(l, v.size()-k+1) w.pb(v[l]);
    }

    if(w.size() >= q){
      sort(all(w));
      ans = min(ans, w[q-1]-w[0]);
    }
  }

  cout << ans << endl;

  return 0;
}


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

const int N=105;
int n,ans,a[N];

int main()
{
	int i,j,k;
	cin>>n;
	for(i=1;i<=n;i++)
	    cin>>a[i];
	for(i=1;i<=n;i=k)
	{
		j=0,k=i+1;
		while(a[i]==a[k]&&k<=n)
		    k++;
		ans+=(k-i)/2;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int fib[1010];
int d,V;
int parent[1010];
void makefib(){
  fib[0]=2;fib[1]=3;
  for(int i=2;i<1010;i++)fib[i]=(fib[i-1]+fib[i-2])%1001;
  return;
}
void initialize(){
  for(int i=0;i<V;i++){
    parent[i]=i;
    //printf("fib[%d]=%d\n",i,fib[i]);
  }
}
int root(int x){
  return (parent[x]==x)?x:root(parent[x]);
}
bool sameset(int x,int y){
  return root(x)==root(y);
}
void union_set(int x,int y){
  parent[root(y)]=root(x);
}
int main(){
  makefib();
  while(cin>>V>>d){
    initialize();
    for(int i=0;i<V;i++){
      for(int j=0;j<V;j++){
        if(abs(fib[i]-fib[j])<d&&!sameset(i,j))union_set(i,j);
      }
    }
    int cnt=0;
    for(int i=0;i<V;i++){
      //cout<<"root["<<i<<"]="<<root(i)<<endl;
      if(root(i)==i)cnt++;
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 1168
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=100010;
set <int> s[N],s2[N];
set <int> :: iterator it;
int n,t,fa[N];
par q[N<<4];
int get(int x){return fa[x]?fa[x]=get(fa[x]):x;}
int merge(int u,int v){
	if ((u=get(u))==(v=get(v))) return 0;
	if (s[u].size()+s2[u].size()<s[v].size()+s2[v].size()) swap(u,v);
	fa[v]=u;
	s[u].erase(s[u].find(v));
	s2[u].erase(s2[u].find(v));
	for (it=s[v].begin();it!=s[v].end();++it){
		if (*it==u) continue;
		int x=*it;
		s[u].insert(x);
		s[x].erase(s[x].find(v));
		s[x].insert(u);
		if (s2[x].find(u)!=s2[x].end()) q[++t]=(par){x,u};
	}
	for (it=s2[v].begin();it!=s2[v].end();++it){
		if (*it==u) continue;
		int x=*it;
		s2[u].insert(x);
		s2[x].erase(s2[x].find(v));
		s2[x].insert(u);
		if (s[x].find(u)!=s[x].end()) q[++t]=(par){x,u};
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	rep(i,2,n){
		int x,y;
		scanf("%d%d",&x,&y);
		s[x].insert(y);
		s[y].insert(x);
	}
	rep(i,2,n){
		int x,y;
		scanf("%d%d",&x,&y);
		s2[x].insert(y);
		s2[y].insert(x);
		if (s[x].find(y)!=s[x].end()) q[++t]=(par){x,y};
	}
	int tot=n;
	rep(h,1,t) tot-=merge(q[h].fi,q[h].se);
	if (tot==1) puts("YES"); else puts("NO");
	return 0;
}


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

int main(){
	int W,H;
	while(1){
		cin>>H>>W;
		if(H==0&&W==0)
			break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%2==0){
					if(j%2==0)
						cout<<"#";
					else
						cout<<".";
				}
				else{
					if(j%2==0)
						cout<<".";
					else
						cout<<"#";
					}
			}
			cout<<endl;	
		}
		cout<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int sx = in.nextInt(), sy = in.nextInt(), tx = in.nextInt(), ty = in.nextInt();
        int dy = ty - sy, dx = tx - sx;
        char[] ans = new char[dy + dx + dy + dx + 1 + dy + 1 + dx + 1 + 2 + dy + 1 + dx + 1 + 1];
        int j = 0;
        for (int i = 0; i < dy; i++) {
            ans[j++] = U;
        }
        for (int i = 0; i < dx; i++) {
            ans[j++] = R;
        }
        for (int i = 0; i < dy; i++) {
            ans[j++] = D;
        }
        for (int i = 0; i < dx; i++) {
            ans[j++] = L;
        }
        ans[j++] = L;
        for (int i = 0; i < dy + 1; i++) {
            ans[j++] = U;
        }
        for (int i = 0; i < dx + 1; i++) {
            ans[j++] = R;
        }
        ans[j++] = D;
        ans[j++] = R;
        for (int i = 0; i < dy + 1; i++) {
            ans[j++] = D;
        }
        for (int i = 0; i < dx + 1; i++) {
            ans[j++] = L;
        }
        ans[j++] = U;

        System.out.println(new String(ans));
    }

    static final char U = 'U', D = 'D', L = 'L', R = 'R';
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= (0);--i)
#define ALL(v) v.begin(),v.end()
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define LLINF 1000000000000000000LL

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

ll mp[222222];

int main() {

    REP(i, 222222){
        if(i % 2)mp[i] = -LLINF;
        else mp[i] = LLINF;
    }


    ll n, m;cin >> n >> m;
    vector<pair<P, P>> v;
    REP(i, n){
        ll l, r;cin >> l >> r;
        v.PB(MP(MP(l, -1), MP(l, r)));
        v.PB(MP(MP(r, 1), MP(l, r)));
    }

    sort(ALL(v));

    multiset<ll> s_l;
    multiset<ll> s_r;
    REP(i, v.size()){
        auto now = v[i].SE;
        if(v[i].FI.SE < 0){
            s_l.insert(now.FI);
            s_r.insert(now.SE);
        }
        else {
            auto it_l = s_l.find(now.FI);s_l.erase(it_l);
            auto it_r = s_r.find(now.SE);s_r.erase(it_r);
        }

        ll set_size = s_l.size();
        if(set_size == 0)continue;
        if(set_size % 2){
            mp[set_size] = max(mp[set_size], *s_r.begin());
        }
        else {
            mp[set_size] = min(mp[set_size], *s_l.rbegin());
        }
    }

    REV(i, 222222){
        if(abs(mp[i]) != LLINF){
            //cout << "mp " << i << " " << mp[i] << endl;
            ll ans;
            if(i % 2){
                ans = (i - 1) * m + mp[i];
            }
            else {
                ans = (i - 1) * m + (m - mp[i]);
            }
            cout << ans << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 35624
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <functional>


using namespace std;


vector<uint64_t> answer;
// mountains[stone_num] = pair<min_mountain_id, mountain_count>
map<uint64_t, pair<uint64_t, uint64_t>, greater<uint64_t> > mountains;


void count()
{
  while (true) {
    auto it = mountains.begin();
    auto stone_num = it->first;
    auto m_id = it->second.first;
    auto mountain_num = it->second.second;
    it = mountains.erase(it);

    if (it == mountains.end()) {
      answer[m_id] += stone_num * mountain_num;
      return;
    }

    auto stone_diff = stone_num - it->first;
    answer[m_id] += mountain_num * stone_diff;

    if (m_id < it->second.first)
      it->second.first = m_id;
    it->second.second += mountain_num;
  }
}


int main()
{
  uint64_t n;
  cin >> n;
  answer.reserve(n);

  for (uint64_t i=0; i<n; ++i) {
    answer.push_back(0);

    uint64_t s;
    cin >> s;
    auto it = mountains.find(s);
    if (it == mountains.end())
      mountains.emplace(s, make_pair(i, 1));
    else
      it->second.second += 1;
  }

  count();

  for (const auto a : answer) {
    cout << a << endl;
  }

  return 0;
}


Measured memory_bytes: 9472