akhauriyash/Code-Regression huggingface dataset:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    mat = []

    for _ in range(n):
        x, l = map(int, readline().split())
        left, right = x - l, x + l
        mat.append([left, right])

    mat.sort()

    i = 1
    cur_l, cur_r = mat[0]
    ans = 1

    while i < n:
        next_l, next_r = mat[i]
        if next_l < cur_r:
            if next_r < cur_r:
                cur_l, cur_r = next_l, next_r
        else:
            cur_l, cur_r = next_l, next_r
            ans += 1
        i += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 86280
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string strs[3] = { "Sunny", "Cloudy", "Rainy" };
	string s; cin >> s;
	int c = 0;
	FOR_LT(i, 0, 3) {
		if (strs[i] == s) {
			c = i;
			break;
		}
	}

	c++;
	if (c == 3) c = 0;

	cout << strs[c] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<ll,ll> pi;

int main()
{
  IOS();
    int n;
    cin>>n;
    int f[n+1];
    for(int i=1;i<=n;i++)
    cin>>f[i];

    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(f[2]-f[1]);

    for(int i=3;i<=n;i++)
    {
      dp[i]=std::min(dp[i-1]+abs(f[i]-f[i-1]),dp[i-2]+abs(f[i]-f[i-2]));
    }
    cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 4448
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n,k;
int a[2002],b[2002];
vector<int> G[2002];

int par[2002][13] = {};
int dep[2002] = {};
void dfs(int v,int p,int d){
	par[v][0] = p;
	dep[v] = d;
	rep(i,G[v].size()){
		if(G[v][i] == p)continue;
		dfs(G[v][i],v,d+1);
	}
}
void lca_init(){
	rep1(j,12){
		rep(i,2002){
			par[i][j] = par[par[i][j-1]][j-1];
		}
	}
}
int lca(int u,int v){
	if(dep[u] > dep[v])swap(u,v);
	rrep(j,13){
		if(dep[par[v][j]] >= dep[u])v = par[v][j];
	}
	if(u == v)return u;
	rrep(j,13){
		if(par[v][j] != par[u][j]){
			v = par[v][j];
			u = par[u][j];
		}
	}
	return par[v][0];
}
int dist(int u,int v){
	return dep[u]+dep[v]-2*dep[lca(u,v)];
}
		

int main(){
	scanf("%d%d",&n,&k);
	rep(i,n-1){
		scanf("%d%d",&a[i],&b[i]);
		G[a[i]].pb(b[i]);
		G[b[i]].pb(a[i]);
	}
	
	dfs(1,0,1);
	lca_init();
	int ret = 0;
	rep1(i,n){
		//cout << i << " " << dep[i] << ":\n";
		int cnt = 0;
		rep1(j,n){
			//cout << j << " " << dep[j] << " " << dist(i,j) << " " << lca(i,j) << endl;
			if(dep[i] >= dep[j] && dist(i,j) <= k)cnt ++;
		}
		ret = max ( ret , cnt );
	}
	cout << n-ret << endl;
}
	


Measured memory_bytes: 512
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2020;
int n , m , Q;
char s[N];
int a[N][N] , hori[N][N] , vert[N][N];
void prepare(int a[N][N]){
    rep(i,1,n+1) rep(j,1,m+1) a[i][j]+=a[i-1][j];
    rep(i,1,n+1) rep(j,1,m+1) a[i][j]+=a[i][j-1];
}
int query(int s[N][N],int a,int b,int c,int d){
    if(a>c||b>d) return 0;
    --a;--b;
    return s[c][d]+s[a][b]-s[a][d]-s[c][b];
}

int main(){
    scanf("%d%d%d",&n,&m,&Q);
    rep(i,1,n+1) {
        scanf("%s",s + 1);
        rep(j,1,m+1) a[i][j] = s[j] == '1';
    }
    rep(i,1,n+1) rep(j,1,m) hori[i][j] = a[i][j] == 1 && a[i][j+1] == 1;
    rep(i,1,n) rep(j,1,m+1) vert[i][j] = a[i][j] == 1 && a[i+1][j] == 1;
    prepare(a);
    prepare(hori);
    prepare(vert);
    rep(i,0,Q){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int p=query(::a,a,b,c,d);
        int l=query(hori,a,b,c,d-1)+query(vert,a,b,c-1,d);
        printf("%d\n",p-l);
    }
    return 0;
}


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

using namespace std;

int SideLength[3];

bool judgeResult(int r) {
	int squareOfSide;

	sort(SideLength, SideLength + 3);
	squareOfSide = pow(SideLength[0], 2) + pow(SideLength[1], 2);
	
	if (squareOfSide < r*r * 4) {
		return true;
	}
	return false;
}

int main() {
	int n, r;

	while (1) {
		cin >> SideLength[0] >> SideLength[1] >> SideLength[2];
		if (SideLength[0] == 0 && SideLength[1] == 0 && SideLength[2] == 0) {
			break;
		}

		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> r;
			if (judgeResult(r)) {
				cout << "OK" << endl;
			}
			else {
				cout << "NA" << endl;
			}
			
		}
	}


	return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int N, A[100000], B[100000];
    cin >> N;
    ll a = 0, b = 0;
    rep(i, N) {
        cin >> A[i];
        a += A[i];
    }
    rep(i, N) {
        cin >> B[i];
        b += B[i];
    }
    if (a < b) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> C;
    ll p = 0;
    int ans = 0;
    rep(i, N) {
        C.push_back(A[i] - B[i]);
        if (A[i] - B[i] < 0) {
            p -= A[i] - B[i];
            ans++;
        }
    }
    sort(C.begin(), C.end());
    for (int i = N - 1; p > 0; i--) {
        p -= C[i];
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  cout << a * b << "\n";
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
long long n,m,s,x,b[200010];
int main(){
    cin>>n;
    for(int i=0;cin>>x;i++){
        if(!i) b[i]=x;
        else b[i]=b[i-1]+x;
        s+=x;
    }
    if(b[0]>s-b[0]) m=b[0]+b[0]-s;
    else m=s-b[0]-b[0];
    for(int i=1;i<(n-1);i++)
        m=min(m,abs(s-b[i]-b[i]));
    cout<<m<<endl;
    return 0;
} 

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int ans;
    int up = m/n;
    for (int i = up; i>=1; i--)
    {
        if(m % i == 0 && m / i >= n)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<LL> dp(n+1,0);
  int x;
  rep(i,m){
    cin >> x;
    dp[x]=-1;
  }
  dp[0]=1;
  if(dp[1]!=-1) dp[1]=1;
  repp(i,2,n+1){
    if(dp[i]!=-1) dp[i]=((dp[i-1]!=-1?dp[i-1]:0)+(dp[i-2]!=-1?dp[i-2]:0))%MOD;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
#require 'pp'

def modinv(a, m)
    b = m
    u = 1
    v = 0

    while b != 0
        t = a / b
        a -= t * b;
        tmp = a
        a = b
        b = tmp

        u -= t * v
        tmp = u
        u = v
        v = tmp
    end

    u = u % m
    if u < 0
        u += m
    end

    return u
end

MOD = 10 ** 9 + 7
n, a, b = gets.split.map(&:to_i)
ans = 1
if n == 2
    puts 0
    exit 0
end

j = n
h = 2
while j > 0
    if j % 2 == 0
        j /= 2
        h = (h ** 2) % MOD
    else
        j -= 1
        ans = (ans * h) % MOD
    end
end

def calc_c(n, r)
    npr = 1
    r.times do |i|
        npr = (npr * (n - i)) % MOD
    end

    r_x = 1
    r.downto(1) do |i|
        r_x = (r_x * i) % MOD
    end

    return (npr * modinv(r_x, MOD)) % MOD
end

x = calc_c(n, a)
y = calc_c(n, b)

ans = (ans - x) % MOD
ans = (ans - y) % MOD
ans = (ans - 1) % MOD
puts ans


Measured memory_bytes: 3836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	class DisjointSet {
		
		int[] p, r, w;
		
		public DisjointSet(int size) {
			p = new int[size];
			r = new int[size];
			w = new int[size];
			for (int i = 0; i < size; i++) makeSet(i);
		}

		private void makeSet(int x) {
			p[x] = x;
			r[x] = w[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			if (x != p[x]) {
				int tmp = findSet(p[x]);
				w[x] += w[p[x]];
				p[x] = tmp;
			}
			return p[x];
		}
		
		public void relate(int x, int y, int z) {
			link(findSet(x), findSet(y), z - w[x] + w[y]);
		}

		private void link(int x, int y, int cost) {
			if (r[x] > r[y]) {
				p[y] = x;
				w[y] -= cost;
			} else {
				p[x] = y;
				w[x] += cost;
				if (r[x] == r[y]) {
					r[y]++;
				}
			}
		}
		
		public int sum(int x) {
			int sum = 0;
			int cur = x;
			while (cur != p[cur]) {
				sum += w[cur];
				cur = p[cur];
			}
			return sum;
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				int z = Integer.parseInt(st.nextToken());
				ds.relate(x, y, z);
			} else {
				if (!ds.same(x, y)) {
					System.out.println("?");
				} else {
					System.out.println(ds.sum(x) - ds.sum(y));
				}
			}
		}
		reader.close();
	}
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll mod = 1000000007;

ll n;
graph t;
ll a[100000];
ll b[100000];
ll ans;


void dfs(ll from,ll to){
  ll c = t[from][to];
  ll idx = 0;
  for(auto x : t[to]){
    if(x.first == from) continue;
    do{
      idx++;
    }while(idx == c);
    t[to][x.first] = t[x.first][to] = idx;
    dfs(to,x.first);
    ans = max(ans,idx);
  }
}

int main(){
  cin >> n;
  for(ll i = 0;i < n-1;i++){
    ll from,to;
    cin >> from >> to;
    a[i] = from;
    b[i] = to;
    t[from][to] = t[to][from] = 0;
  }
  t[0][1] = t[1][0] = 0;
  dfs(0,1);
  cout << ans << endl;
  for(ll i = 0;i < n-1;i++){
    cout << t[a[i]][b[i]] << endl;
  }

}


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

int main(int argc, char const *argv[]) {
    int count = 0;
    string W;
    cin >> W;

    string T;
    while (1) {
        cin >> T;
        if (T == "END_OF_TEXT") {
            break;
        } else {
            int len = T.length();
            for (int i = 0; i < len; i++) {
                T[i] = tolower(T[i]);
            }

            if (W == T) {
                count++;
            }
        }
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3184
#include<iostream>
#include<stack>

using namespace std;

int main(){
	stack<int> train;
	int n;
	while(cin>>n){
		if(n==0){
			cout<<train.top()<<endl;
			train.pop();
		}else{
			train.push(n);
		}
	}
	return 0;
}
	

Measured memory_bytes: 1200
def divde(argv):

    dlist=[]
    i = 1
    for i in range (1,int(argv)+1):
        if(int(argv)%i==0):
            dlist.append(i)
    return dlist

def compare(A,B):
    D =[]
    for i in range (len(A)):
        for j in range(len(B)):
            if A[i]==B[j]:
                D.append(B[j])
    return D

if __name__ == "__main__":
    string = input()
    a, b, c = string.split()

    A = []
    A = divde(a)
    B = []
    B = divde(int(b))
    D = []
    D = compare(A,B)

    D.reverse()

    q = int(c)-1
    print(D[q])

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#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)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
int main() {
    string S;
    int K; cin >> S >> K;

    for(char &c: S){
        if(K>=('z'+1-c)%26){
            K-=('z'+1-c)%26;
            c='a';
        }
    }

    S[S.size()-1]=(S[S.size()-1]-'a'+K)%26+'a';

    cout << S << endl;
    return 0;
}

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

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int h,w,mod=1e9+7;
 cin>>h>>w;
 int dp[h+5][w+5];
 char ch[h+5][w+5];
 memset(dp,0,sizeof(dp));
 dp[0][0]=1;
 for(int i=0;i<h;i++)
 {
      for(int j=0;j<w;j++)
      {
           cin>>ch[i][j];
      }
 }
 
 for(int i=0;i<h;i++)
 {
      for(int j=0;j<w;j++)
      {
           if(ch[i][j]=='#')
           continue;
           if(ch[i+1][j]=='.')
           dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
           
           if(ch[i][j+1]=='.')
           dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod;
      }
 }
 cout<<dp[h-1][w-1];
}

Measured memory_bytes: 9088
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def prime_factorization(n):
    d = {}
    i = 2
    while i * i <= n:
        if n % i == 0:
            d[i] = 1
            n //= i
            while n % i == 0:
                n //= i
                d[i] += 1
        i += 1
    if n > 1:
        d[n] = 1
    return d

def main():
    N = int(readline())

    d = prime_factorization(N)
    
    ans = 0
    for k, v in d.items():
        e = 0
        for i in range(1, v+1):
            e += i
            if e > v:
                break
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9224
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 500050;
const int K = 230000;
const int M = 1e9;
const int mod = 1e9 + 7;
int n;
vector <pair <int,int>> s1[N], s2[N], s3[N], s4[N], s5[N], s6[N];
int solve(vector <pair<int,int>> a){
    sort(a.begin(), a.end());
    int res = 1e9;
    for (int i = 0; i < (int)a.size() - 1; i++){
        if (a[i].S == 1 && a[i + 1].S <= 0){
            res = min(res, 10 * (a[i + 1].F - a[i].F) / (a[i].S - a[i + 1].S));
        }
        if (a[i + 1].S == -1 && a[i].S >= 0){
            res = min(res, 10 * (a[i + 1].F - a[i].F) / (a[i].S - a[i + 1].S));
        }
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, y;
        string d;
        cin >> x >> y;
        cin >> d;
        if (d == "U"){
            s1[x].pb({y, 1});
            s3[x + y].pb({x, 0});
            s4[x - y + K].pb({x, 0});
        }
        if (d == "D"){
            s1[x].pb({y, -1});
            s5[x + y].pb({x, 0});
            s6[x - y + K].pb({x, 0});
        }
        if (d == "L"){
            s2[y].pb({x, -1});
            s5[x + y].pb({x, -1});
            s4[x - y + K].pb({x, -1});
        }
        if (d == "R"){
            s2[y].pb({x, 1});
            s3[x + y].pb({x, 1});
            s6[x - y + K].pb({x, 1});
        }
    }
    int ans = 1e9;
    for (int i = 0; i < K + K; i++){
        ans = min(ans, solve(s1[i]));
        ans = min(ans, solve(s2[i]));
        ans = min(ans, solve(s3[i]));
        ans = min(ans, solve(s4[i]));
        ans = min(ans, solve(s5[i]));
        ans = min(ans, solve(s6[i]));
    }
    if (ans == 1e9){
        cout << "SAFE";
    } else{
        cout << ans;
    }
}


Measured memory_bytes: 92464
#include<iostream>
using namespace std;
typedef long long ll;

ll calc_gcd(ll a, ll b) {
    if (a % b == 0) return b;
    else return calc_gcd(b, a % b);
}

ll calc_lcm(ll a, ll b) {
    return a * b / calc_gcd(a, b);
}

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

    ll n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    ll ans = calc_lcm(n, m);
    ll gcd = calc_gcd(n, m);
    bool ok = true;
    for (int i = 0; i < gcd; i++) {
        int s_idx = i * n / gcd;
        int t_idx = i * m / gcd;
        if (s[s_idx] != t[t_idx]) ok = false;
    }

    if (ok) cout << ans << endl;
    else cout << -1 << endl;
}

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

ans = 0
l = r = 0
x = 0
for l in range(N):
  # x&A[r] != 0 となるのは、どこかの桁で2回目の1が現れたということ。
  while(r < N and x&A[r] == 0):
    x |= A[r]
    r += 1
  ans += r-l
  # xにおいて、A[l]によって1になった桁を0にする。
  # xのある桁を1にしたAは高々1個。2個あったらwhile文の条件x&A[r] == 0が成立しない。
  x ^= A[l]
print(ans)

Measured memory_bytes: 77772
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(long[]);

    auto dp = new long[][](N, 3);
    fillAll(dp, -infl);

    dp[N - 1][2] = a[N - 1];
    dp[N - 2][0] = max(a[N - 1], a[N - 2]);

    foreach_reverse (i ; 0 .. N - 2) {
        if ((N - i) % 2 == 0) {
            dp[i][0] = max(a[i] + dp[i + 2][0], 
                            a[i + 1] + (i + 3 < N ? dp[i + 3][2] : 0));
        }
        else {
            dp[i][1] = max(a[i] + dp[i + 2][1], 
                            a[i + 1] + (i + 3 < N ? dp[i + 3][0] : 0),
                            a[i + 2] + (i + 4 < N ? dp[i + 4][2] : 0));
        }
        dp[i][2] = a[i] + dp[i + 2][2];
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    long ans;

    if (N % 2 == 0) {
        ans = dp[0][0];
    }
    else {
        ans = dp[0][1];
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 21324
def bubble_sort(array):
    count = 0
    n = len(array)
    for i in range(n-1):
        for j in range(n-1, i, -1):
            if array[j] < array[j-1]:
                tmp = array[j]
                array[j] = array[j-1]
                array[j-1] = tmp
                count += 1

    print(" ".join(map(str,array)))
    print(count)

times = int(input())
array = list(map(int,input().split()))

bubble_sort(array)

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int H,W,K;
char A[888][888];
int dist[888][888];

vector<vector<int> > dir = {{0,1},{1,0},{-1,0},{0,-1}};

bool valid(int i,int j){
	if(i<0 or i>=H)return false;
	if(j<0 or j>=W)return false;
	if(A[i][j]=='#')return false;
	return true;
}

int bfs(int i,int j){
	dist[i][j] = 0;
	queue<pii> q;
	q.push({i,j});
	while(!q.empty()){
		pii p = q.front();q.pop();
		REP(i,4){
			pii p2(p.first+dir[i][0],p.second+dir[i][1]);
			if(!valid(p2.first,p2.second))continue;
			if(dist[p2.first][p2.second]>dist[p.first][p.second]+1){
				dist[p2.first][p2.second]=dist[p.first][p.second]+1;
				q.push({p2.first,p2.second});
			}
		}
	}
}

int main(){
	cin>>H>>W>>K;
	REP(i,H)cin>>A[i];
	int sx, sy;
	REP(i,H)REP(j,W){
		if(A[i][j]=='S'){
			sx = i;
			sy = j;
		}
	}
	memset(dist,63,sizeof(dist));
	bfs(sx,sy);
	int ans = INF;
	REP(i,H)REP(j,W){
		if(dist[i][j]<=K){
			int d = min(min(abs(i),abs(H-1-i)),min(abs(j),abs(W-1-j)));
			ans = min(ans,(d+K-1)/K+1);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4096
fun gcd(a: Int, b: Int): Int {
    if(a < b) return gcd(b, a)
    if(b == 0) return a
    return gcd(b, a % b)
}

fun main(args: Array<String>){
    val oppai = readLine()!!.split(" ").map{s -> s.toInt()}
    val sdkys: Int = gcd(oppai[0], oppai[1])
    var count: Int = 0
    
    for (i in 1 .. sdkys){
        if (sdkys % i == 0){
            count++
            if (count == oppai[2]){
                println(sdkys / i)
                break
            }
        }
    }
}

Measured memory_bytes: 37928
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n,m,i,j,a[15];
string st;
char s[15];
bool check(int x)
{
	sprintf(s,"%d",x);
	st=s;
	for (i=1;i<=m;i++)
	{
		if ((int)st.find(a[i]+'0')!=-1)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=m;i++) cin>>a[i];
	while (!check(n)) 
		n++;
	cout<<n;
	return 0;
}
		

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<int>v[50];
  int n,m;
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a,b;
    cin >> a >> b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
  }

  for(int i = 0; i < n; ++i) {
    cout << v[i].size() << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque
import itertools
import time

n, k = map(int, input().split())
p = list(map(int, input().split()))

kukan = 0
for i in range(k):
    kukan += p[i]

kukan_max = kukan
for i in range(n - k + 1):
    kukan_max = max(kukan_max, kukan)
    if i+k<n:
        kukan += p[i+k]
        kukan -= p[i]
ans = kukan_max / 2 + 0.5 * k
print(ans)


Measured memory_bytes: 25568
using System;
using System.Linq;
namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            int[] a = Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);
            int[] ene = new int[1000001];
            int count = 0;
            foreach(int i in a)
            {
              if(ene[i]>=1)
                {
                    ene[i] += 1;
                    continue;
                }
              for(int j=i;j<=1000000; j+=i)
                {
                    ene[j]++;
                }
            }
            foreach(int i in a)
            {
                if (ene[i] <= 1)
                {
                    count++;
                }
            }
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 46752
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k - 1] = tolower(s[k - 1]);
	dunk(s);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define all(c) c.begin(),c.end()

#include<vector>
#define INF 10000000
using namespace std;
int n;
int t[20][20];
vector<int> dp((1<<18));
int ret(int now){
	if(now==(1<<n)-1)
		return 0;
	if(dp[now]!=-1)
		return dp[now];
	int ans=INF;
	for(int i=0;i<n;i++){
		if(!(now&(1<<i)))
		for(int j=0;j<=n;j++){
			if(!j||(now&(1<<(j-1))))
				ans=min(ans,ret(now|(1<<i))+t[i][j]);
		}
	}
	return dp[now]=ans;
}
int main(){
	while(cin>>n,n){
		fill(all(dp),-1);
	for(int i=0;i<n;i++){
		for(int j=0;j<n+1;j++)
			cin>>t[i][j];
	}
	cout<<ret(0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int a, b, c;
int main(void) {
	
	cin >> a >> b >> c;
	bool can = false;
	for (int i = 1; i <= b; i++)
	{
		if (a*i%b==c)
		{
			can = true;
		}
	}
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;

	
}

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

int main() {
	int n;
	cin >> n;
	int f[n][5][2];
	int p[n][11];
	for(int i=0;i<n;i++){
		for(int j=0;j<5;j++){
			for(int k=0;k<2;k++){
				cin >> f[i][j][k];
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=10;j++){
			cin >> p[i][j];
		}
	}
	long long ans=-1000000000000;
	for(int bit=1;bit<(1<<10);bit++){
		long long com=0;
		vector<int>a(10,0);
		for(int i=0;i<10;i++){
			if(bit&(1<<i)) a[i]=1;
		}
		vector<int>count(n,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<5;j++){
				for(int k=0;k<2;k++){
					if(f[i][j][k]==1&&a[j*2+k]==1) count[i]++;
				}
			}
		}
		for(int i=0;i<n;i++){
			com+=p[i][count[i]];
		}
		ans=max(ans,com);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
from copy import deepcopy
n, k = map(int, input().split())
v = deque(map(int, input().split()))
# 取り出せる最大回数
t = min(n, k)
ans = 0
# A,Bの操作の回数で全探索
for a in range(t + 1):
    for b in range(t + 1 - a):
        # 初期化
        vv = deepcopy(v)
        # 今持っている宝石たち
        belongings = []
        # 取り出していく
        for _ in range(a):
            if vv:
                jewelry = vv.popleft()
                belongings.append(jewelry)
        for _ in range(b):
            if vv:
                jewelry = vv.pop()
                belongings.append(jewelry)
        # ソートして、負の宝石は可能な限り筒に戻す
        belongings.sort()
        for i in range(a + b):
            if belongings[i] < 0 and i < (k - a - b):
                belongings[i] = 0
        ans = max(sum(belongings), ans)
print(ans)


Measured memory_bytes: 47832
#include <cstdio>
#include <algorithm>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, M, Q;
int I[510][510], S[510][510];

int main()
{
  scanf( "%d%d%d", &N, &M, &Q );
  rep( i, M )
  {
    int L, R;
    scanf( "%d%d", &L, &R );

    ++S[L][R];
  }

  rep( i, N+1 ) rep( j, N+1 )
    S[i][j+1] += S[i][j];

  rep( j, N+1 ) rep( i, N+1 )
    S[i+1][j] += S[i][j];

  rep( t, Q )
  {
    int p, q;
    scanf( "%d%d", &p, &q );

    printf( "%d\n", S[q][q]-S[q][p-1]-S[p-1][q]+S[p-1][p-1] );
  }
  
  return 0;
}

Measured memory_bytes: 1920
N = int(input())
P = list(map(int,input().split()))

lN=[]
for i in range(1,N+1):
  lN.append(i)
  
cnt = 0  
for i in range(N):
  if lN[i] != P[i]:
    cnt += 1
      
if cnt == 0 or cnt == 2:    
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
L, R = (int(x) for x in input().split())
l, r = L%2019, R%2019
if l >= r or (R-L)>= 2019:
    print(0)
else:
    tmp = (l*r)%2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            if (i*j)%2019 < tmp:
                tmp = (i*j)%2019

    print(tmp)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
	std::string s; std::cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long x  = sc.nextLong();
		long ans = 0;

//		if (x > 10){
			ans = x/11*2;
			x = x%11;

//		}

//		System.out.println(ans+" " +x);

		if (x <= 0) {
			System.out.println(ans);
			System.exit(0);
		}

		for (;;) {
			ans +=1;
			if (ans%2 != 0){
				x -= 6;
			}else {
				x -= 5;
			}

			if (x <= 0) {
				System.out.println(ans);
				break;
			}
		}
	}

}


Measured memory_bytes: 9804
#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX_N (1000)
#define MAX_M (2 * 1e8)

using namespace std;

int field[MAX_N + 1];
int fld[(MAX_N + 1) * (MAX_N + 1)];

int N,M;

int ans;

int bin_search(int tar,int *s,int *e){
	int result;
	int width = e - s;
	while(true){
		width = e - s;
		if(width <= 1){
			result = *s;
			break;
		}

		if(*(s + (width / 2)) <= tar){
			s = s + (width / 2);
		}
		else{
			e = s + (width / 2);
		}
	}
	
	return result;
}

void solve(){
	for(int i = 0;i <= N;i++){
		for(int j = 0;j <= N;j++){
			fld[(N + 1) * i + j] = field[i] + field[j];
		}
	}

	sort(fld,fld + (N + 1) * (N + 1));

	ans = 0;
	int rest;
	int sample;
	for(int i = 0;i <= N;i++){
		for(int j = 0;j <= N;j++){
			rest = M - (field[i] + field[j]);
			if(rest < 0) break;
			sample = bin_search(rest,fld,fld + (N + 1) * (N + 1));
			ans = max(ans,field[i] + field[j] + sample);
		}
	}

	return ;
}

int main(){

	while(true){
		scanf("%d%d",&N,&M);
		if(N == 0 && M == 0) break;
		for(int i = 1;i <= N;i++){	//fiest element is 0;
			scanf("%d",field + i);
		}

		solve();

		printf("%d\n",ans);

	}

	return 0;
}

Measured memory_bytes: 5120
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args){
    	Scanner sn = new Scanner(System.in);
      	int n = sn.nextInt();
      	int[][] d = new int[n+1][4];
      	for(int i=1;i<=n;i++){
          for(int j=1;j<=3;j++){
         	d[i][j] = sn.nextInt();   
          }
        }
      	
      	int[][] ans = new int[n+1][4];
      	ans[n][1] = d[n][1];
      	ans[n][2] = d[n][2];
        ans[n][3] = d[n][3];
      
      	for(int i=n-1;i>=1;i--){
          for(int j=1;j<=3;j++){
          	if(j==1){
              ans[i][1] = d[i][1] + Math.max(ans[i+1][2],ans[i+1][3]);
            }else if(j==2){
              ans[i][2] = d[i][2] + Math.max(ans[i+1][1],ans[i+1][3]);
            }else if(j==3){
              ans[i][3] = d[i][3] + Math.max(ans[i+1][1],ans[i+1][2]);
            }
          }
        }
        int pv =  Math.max(ans[1][1] ,Math.max(ans[1][2],ans[1][3]));
      	System.out.println(pv);
    }
}

Measured memory_bytes: 101544
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    ans = 0
    for i in h:
        if i >= k:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18596
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   string s, t; cin >> s >> t;
   int a = s.size(), b = t.size();

   V<V<int>> dp(a+1, V<int>(b+1));
   for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
         if (s[i] == t[j]) {
            dp[i+1][j+1] = dp[i][j] + 1;
         } else {
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
         }
      }
   }
   stack<char> ans;
   int i = a-1, j = b-1;
   while (dp[i+1][j+1] > 0) {
      if (s[i] == t[j]) {
         ans.push(s[i]);
         i--; j--;
      } else if (i > 0 && dp[i][j+1] == dp[i+1][j+1]) {
         i--;
      } else {
         j--;
      }
   }
   while (!ans.empty()) {
      cout << ans.top(); ans.pop();
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 70784
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int getAvr(int* p,int n){
	int sum = 0;
	for(int i=0;i<n;i++){
		sum += p[i];
	}

	return sum/3;
}

int main(){
	int n;	
	while(~scanf("%d",&n)){	
		if(n==0) break;
		
		for(int i=0;i<n;i++){
			int p[3];
			//math,english,japanese			
			scanf("%d %d %d",p,p+1,p+2);

			for(int i=0;i<3;i++){
				if(p[i]==100){
					printf("A\n");
					goto next;
				}
			}

			if(p[0] + p[1] >= 180 || getAvr(p,3) >= 80){
				printf("A\n");
			}

			else if(getAvr(p,3) >= 70
				|| (getAvr(p,3) >= 50 && (p[0] >= 80 || p[1] >= 80))){
				printf("B\n");
			}

			else{
				printf("C\n");
			}
next:;

		}
		
	}
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

int threemax(int a, int b, int c) {
	if (a >= b && a >= c) {
		return a;
	}
	else if (b >= a && b >= c) {
		return b;
	}
	else {
		return c;
	}
}

int threemin(int a, int b, int c) {
	if (a <= b && a <= c) {
		return a;
	}
	else if (b <= a && b <= c) {
		return b;
	}
	else {
		return c;
	}
}

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(ALL(vec));
  int ans=vec.at(vec.size()/2)-vec.at(vec.size()/2-1);
  cout << ans;
}

Measured memory_bytes: 640
import scala.io.StdIn._
object Main extends App {
  val Array(h, w) = readLine.split(" ").map(_.toInt)
  val array = Array.fill(h + 2, w + 2)('.')
  (1 to h).foreach { i =>
    val s = readLine
    (1 to w).foreach { j =>
      array(i)(j) = s(j - 1)
    }
  }
  var res = false
  for (i <- 1 to h) {
    val target = array(i)
    for (j <- 1 to w) {
      if (target(j) == '#') {
        if (array(i - 1)(j) == '.' &&
            array(i + 1)(j) == '.' &&
            array(i)(j - 1) == '.' &&
            array(i)(j + 1) == '.') {
          res = true
        }
      }
    }
  }
  println(if(res) "No" else "Yes")
}


Measured memory_bytes: 25404
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int sum=0;
    rep(i,n)sum+=a[i];
    sum/=n;
    int ans1=0,ans2=0;
    rep(i,n){
        ans1+=(a[i]-sum)*(a[i]-sum);
        ans2+=(a[i]-sum-1)*(a[i]-sum-1);
    }
    int ans=min(ans1,ans2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int N=800020;
const long long Inf=1ll<<60;
typedef long long ll;
int n,q,a,b,x[N],i;
ll D,d,g;
int abs(int x){
	return x>0?x:-x;
}
ll min(ll x,ll y){
	return x<y?x:y;
}
struct Seg{
	ll p[N];
	void Build(int rt,int l,int r,int x,int y){
		if(l==r){
			if(l==x)p[rt]=y;
			else p[rt]=Inf;
			return;
		}
		int mid=l+r>>1;
		Build(rt<<1,l,mid,x,y);
		Build(rt<<1|1,mid+1,r,x,y);
		p[rt]=min(p[rt<<1],p[rt<<1|1]);
	}
	ll Query(int rt,int l,int r,int x,int y){
		if(x<=l&&r<=y)
			return p[rt];
		ll f=1ll<<60;
		int mid=l+r>>1;
		if(x<=mid)f=min(f,Query(rt<<1,l,mid,x,y));
		if(y>mid)f=min(f,Query(rt<<1|1,mid+1,r,x,y));
		return f;
	}
	void Update(int rt,int l,int r,int x,ll y){
		if(l==r){
			p[rt]=min(p[rt],y);
			return;
		}
		int mid=l+r>>1;
		if(x<=mid)
			Update(rt<<1,l,mid,x,y);
		else
			Update(rt<<1|1,mid+1,r,x,y);
		p[rt]=min(p[rt<<1],p[rt<<1|1]);
	}
}T1,T2,T3;
void init(){
	scanf("%d%d%d%d",&n,&q,&a,&b);
	x[0]=a;
	for(i=1;i<=q;i++)
		scanf("%d",x+i);
	T1.Build(1,1,n,b,0);
	T2.Build(1,1,n,b,-b);
	T3.Build(1,1,n,b,b);
}
void work(){
	for(i=1;i<=q;i++){
		D=abs(x[i]-x[i-1]);
		g=min(T2.Query(1,1,n,1,x[i])+x[i],T3.Query(1,1,n,x[i],n)-x[i]);
		T1.Update(1,1,n,x[i-1],g-D);
		T2.Update(1,1,n,x[i-1],g-D-x[i-1]);
		T3.Update(1,1,n,x[i-1],g-D+x[i-1]);
		d+=D;
	}		
	printf("%lld",T1.Query(1,1,n,1,n)+d);
	//while(1);
}
int main(){
	init();
	work();
	return 0;
}

Measured memory_bytes: 20608
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    string s;
    cin >> s;
    string s1 = s.substr(0, s.size()/2);
    string s2 = s.substr(s.size()/2, s.size()/2);
    cerr << s1 << ", " << s2 << endl;
    if(n%2==0 && s1 == s2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//priority_queue<ll, vector<ll>, std::greater<ll> > q;
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			emplace_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) // gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define hell 		(ull)1e9
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
using namespace std;
vi adj[100005];
ll vis[100005];
ll d1[100005];
void boost()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    cout.tie(NULL);
}

void dfs(ll k){
    vis[k] = 1;
    ll t1;
    rep(i,0,adj[k].size()){
        t1 = adj[k][i];
        if (vis[t1] == 0){
            
            //cout<<k<<" "<<t1<<"\n";
            dfs(t1);
        }
    }
    rep(i,0,adj[k].size()){
        t1 = adj[k][i];
        //cout<<k<<" "<<t1<<"\n";
        d1[k] = max(d1[t1]+1,d1[k]);
    }
}



int main(void)
{
    boost();
    ll n , m;
    cin>>n>>m;
    ll t1 , t2;
    rep(i,0,m){
        cin>>t1>>t2;
        adj[t1].pb(t2);
    }
    rep(i,0,100005)
        vis[i] = 0;
    rep(i,0,100005)
        d1[i] = 0;
    rep(i,1,n+1){
        if (vis[i] == 0){
            dfs(i);
        }
    }
    
    // rep(i,1,n+1){
    //     rep(j,0,adj[i].size()){
    //         cout<<adj[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    ll maxi = 0;
    rep(i,1,n+1)
        maxi = max(maxi,d1[i]);
    // rep(i,1,n+1)
    //     cout<<d1[i]<<" ";
    // cout<<"\n";
    cout<<maxi;
    
    

}   

Measured memory_bytes: 9344
#include<iostream>


using namespace std;

int V,E,R,S[500010],T[500010],D[500010];
int C[100010];

const int Inf=10000*100000+100;

int main(){
    cin>>V>>E>>R;
    for(int i=0;i<E;i++){
        cin>>S[i]>>T[i]>>D[i];
    }
    for(int i=0;i<V;i++){
        C[i]=Inf;
        if(i==R){
            C[i]=0;
        }
    }
    for(int t=0;t<V;t++){
        bool update=false;
        for(int i=0;i<E;i++){
            int s=S[i],t=T[i],d=D[i];
            if(C[s]<Inf && C[s]+d<C[t] ){
                C[t]=C[s]+d;
                update=true;
            }
        }
        if(!update) break;
    }
    for(int i=0;i<V;i++){
        if(C[i]!=Inf){
            cout<<C[i]<<endl;
        }
        else{
            cout<<"INF"<<endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 9144
#include    <iostream>
#include    <queue>
#include    <algorithm>

using namespace std;

int main() {
    using player = pair<int, int>;
    
    int n;
    priority_queue<player> score;
    
    cin >> n;

    for(int i = 0; i < n; i++) {
        int sc, num;
        cin >> num >> sc;
        score.push(make_pair(sc, -num));
    }

    cout << score.top().second * -1 << ' ' << score.top().first << endl;

    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
int R,C;
vector<vector<int> >v;

void solve(){
  int i,j,n_2 = 1 << R;
  int broad = n_2-1;
  vector<int> prep(n_2,0);
  vector<int> n_Osen(n_2,0);
  vector<int> v_sub(C,0);
  //準備
  REP(i,n_2){
    int num = 0,n = i;
    while(n){
      if(n%2==1)num++;
      n/=2;
    }
    prep[i] = R-num;
  }
  //行を二進数表記(O(1)で操作するため)
  REP(j,C)REP(i,R){
    v_sub[j] = v_sub[j]*2+v[i][j];
  }
  int m = 0;
  REP(i,n_2){
    REP(j,C){
      int n = v_sub[j]^i;
      n_Osen[i] += max(prep[n],prep[n^broad]);
    }
    if(n_Osen[i] > m)m = n_Osen[i];
  }
  cout << m << endl;
}

int main(void){
  while(true){
    int i,j;
    cin >> R >> C;
    if(R*C==0)break;
    v.resize(R);
    REP(i,R){
      v[i].resize(C);
      REP(j,C) cin >> v[i][j];
    }
    solve();
  }
  return 0;
}


Measured memory_bytes: 3400