akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#define Max (int)1e5+5
#define MAX_INT (int)1e9+2

long long int dp[102][Max];

void init(){
	int i,j;
	for(i=0;i<102;i++)
		for(j=0;j<Max;j++)
			dp[i][j] = -1;	
}

long long int getMax(long long int a,long long int b){
	return (a<b)?b:a;
}

long long int solve(int pos,int w,int weight[],long long int val[]){
	if(pos == -1 || w == 0){
		return 0;
	}

	if(dp[pos][w] != -1)
		return dp[pos][w];


	dp[pos][w] = solve(pos-1,w,weight,val);
	if(w - weight[pos] >= 0){
		dp[pos][w] = getMax(dp[pos][w],val[pos]+solve(pos-1,w-weight[pos],weight,val));
	}
	//printf("%d %d %lld\n",pos,w,dp[pos][w]);
	return dp[pos][w];
}

int main(){
	
	int n,w,weight[Max],i;
	long long int val[Max];
	init();
	scanf("%d%d",&n,&w);
	for(i=0;i<n;i++)
		scanf("%d%lld",&weight[i],&val[i]);
	long long int tmp = solve(n-1,w,weight,val);
	printf("%lld\n",tmp);
	return 0;
}


Measured memory_bytes: 79872
def factorization(n):
    if n == 1:
        return []
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    n = int(input())
    primes = factorization(n)
    count = 0
    for prime in primes:
        e = prime[1]
        k = 1
        while e >= 0:
            e -= k
            k += 1
            if e >= 0:
                count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63060
(eval-when  (:compile-toplevel :load-toplevel :execute)
  (defun script-p ()
    (eql sb-sys:*stdin* *standard-input*)))

(macrolet ((optimize (pred)
	     (if pred
		 `(declaim (optimize (speed 3) (debug 0) (safety 0)))
		 `(declaim (optimize (speed 0) (debug 3) (safety 3))))))
  (optimize #. (script-p)))

(defun xclip ()
  (with-output-to-string (s)
    (sb-ext:run-program "/usr/bin/xclip" '("-o") :output s)))

(defun test ()
  (with-input-from-string (*standard-input* (xclip))
    (main)))

(defun main ()
  (let* ((n (read))
	 (as (sort (loop :repeat (* 3 n)
		      :collect (read))
		   #'>)))
    (format t "~a~%"
	    (loop :repeat n
	       :for x :in (cdr as) :by #'cddr
	       :sum x))))

(when (script-p) (main))


Measured memory_bytes: 63972
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>
#include <iomanip>

typedef long long ll;
using namespace std;
int main(){
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
    return 0;
}




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

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int N, L;
    cin >> N >> L;

    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    sort(S.begin(), S.end());
    string ret = "";
    for (int i = 0; i < N; i++) {
        ret += S[i];
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  vector<ll> x(5);
  rep(i, 5)
  {
    cin >> x.at(i);
    {
      if (x.at(i) == 0)
      {
        cout << i + 1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m,d;
  cin>>n>>m>>d;
  string str[n];
  for(int i=0;i<n;i++)
    cin>>str[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m-d+1;j++){
      int flag=1;
      for(int k=0;k<d;k++){
	if(str[i][j+k]=='#'){
	  flag=0;
	}
      }
      if(flag)
	ans++;
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n-d+1;j++){
      int flag=1;
      for(int k=0;k<d;k++){
	if(str[j+k][i]=='#'){
	  flag=0;
	}
      }
      if(flag)
	ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(void) {
  char strRing[256];
  char strStr[108];
  int lenRing, lenStr;

  scanf("%s\n", strRing); lenRing = strlen(strRing);
  scanf("%s\n", strStr);  lenStr  = strlen(strStr);

  strncpy(&strRing[lenRing], strRing, (size_t)lenStr);
  strRing[lenRing+lenStr] = 0;

  if (strstr(strRing, strStr)) printf("Yes\n");
  else                         printf("No\n");
  return 0;
}

Measured memory_bytes: 540
import java.util.Scanner;

/**
 * Handshake
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int MAX = 100000;

            int N = sc.nextInt();
            long M = sc.nextLong();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }

            long[] C = new long[MAX + 2];
            for (int a : A) {
                C[a]++;
            }
            for (int i = MAX - 1; i >= 0; i--) {
                C[i] += C[i + 1];
            }

            long[] CS = new long[MAX + 2];
            for (int a : A) {
                CS[a] += a;
            }
            for (int i = MAX - 1; i >= 0; i--) {
                CS[i] += CS[i + 1];
            }

            int min = 0;
            int max = MAX * 2 + 1;

            while (Math.abs(min - max) > 1) {
                int mid = (min + max) / 2;

                long K = 0;
                for (int i = 0; i < N; i++) {
                    K += C[Math.min(MAX + 1, Math.max(0, mid - A[i]))];
                }

                if (K < M) {
                    max = mid;
                } else {
                    min = mid;
                }
            }

            long H = 0;
            long K = 0;
            for (int a : A) {
                H += a * C[Math.min(MAX + 1, Math.max(0, min + 1 - a))]
                        + CS[Math.min(MAX + 1, Math.max(0, min + 1 - a))];
                K += C[Math.min(MAX + 1, Math.max(0, min + 1 - a))];
            }

            H += min * (M - K);

            System.out.println(H);
        }
    }

}


Measured memory_bytes: 51404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>

using namespace std;

constexpr int inf = 1e9+7;

int d[1001];
int dp[1001][5001]; // i:i番目までの子を使う j:X[n]までの和の列 内容:他方の色の最小和

int main () {
    int N;
    cin>>N;
    vector<int> P(N);
    vector<vector<int>> children(N+1);
    for (int n = 2; n <= N; n++) {
        int p;
        cin>>p;
        children[p].push_back(n);
    }
    vector<int> X(N+1);
    for (int n = 1; n <= N; n++) cin>>X[n];
    
    for (int n = N; n > 0; n--) {
        if (children[n].empty()) d[n] = 0;
        else {
            for (int i = 0; i <= children[n].size(); i++)
                for (int j = 0; j <= X[n]; j++)
                    dp[i][j] = inf;
            dp[0][0] = 0;
            
            for (int i = 1; i <= children[n].size(); i++) {
                for (int j = 0; j <= X[n]; j++) {
                    int child = children[n][i-1];
                    if (j+d[child] <= X[n]) dp[i][j+d[child]] = min(dp[i][j+d[child]], dp[i-1][j] + X[child]);
                    if (j+X[child] <= X[n]) dp[i][j+X[child]] = min(dp[i][j+X[child]], dp[i-1][j] + d[child]);
                }
            }
            int mn = inf;
            for (int j = 0; j <= X[n]; j++) mn = min(mn, dp[children[n].size()][j]);
            if (mn == inf) {
                cout<<"IMPOSSIBLE"<<endl;
                return 0;
            }
            d[n] = mn;
        }
    }
    cout<<"POSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 17280
#coding:utf-8
import math
n, d = map(int, input().split())

grid = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    grid.append(array)

#print(grid)
counter = 0

for i in range(n):
    for j in range(i+1,n):
        tmp = 0
        for k in range(d):
            tmp += (grid[i][k] - grid[j][k])**2

        #y^2がkと等しければ整数があることになる
        if int(round(math.sqrt(float(tmp)))**2) == tmp:
            counter += 1


print(counter)


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  int n;
  cin >> n;
  vector<string> v;
  v.resize(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  bool good = true;
  for(int i = 1; i < n; i++) {
    good &= v[i-1][v[i-1].size()-1] == v[i][0];
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < i; j++) {
      good &= v[i] != v[j];
    }
  }
  if(good) cout << "Yes\n";
  else cout << "No\n";
}

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


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

int main(){
    int m, k;
    cin >> m >> k;
    if((1<<m)-1 < k || m==1&&k==1){
        cout << -1 << endl;
        return 0;
    }
    if(k == 0){
        for(int i = 0; i < 1<<m; i++){
            cout << i << " " << i << " \n"[i==(1<<m)-1];
        }
        return 0;
    }
    list<int> ans;
    ans.push_back(k);
    for(int i = 0; i < 1<<m; i++){
        if(i==k)    continue;
        ans.push_front(i);
        ans.push_back(i);
    }
    ans.push_back(k);
    auto it = ans.begin();
    for(int i = 0; i < 1<<(m+1); i++){
        cout << *it << " \n"[i==((1<<(m+1))-1)];
        it++;
    }
    return 0;
}

Measured memory_bytes: 9984
n = int(input())
As = list(map(int, input().split()))

ans_list = list()

v_min = min(As)
v_max = max(As)
As.remove(v_max)
As.remove(v_min)
for a in As:
    if a >= 0:
        ans_list.append((v_min, a))
        v_min = v_min - a
    else:
        ans_list.append((v_max, a))
        v_max = v_max - a

ans_list.append((v_max, v_min))
ans = v_max - v_min

print(ans)
for a in ans_list:
    print(a[0], a[1])

Measured memory_bytes: 19776
#include <bits/stdc++.h>
using namespace std;
 
  
int main()
{
  int N;
  cin >> N;
  
  int A[100];
  int total = 0;
  for(int nn=0; nn<N; nn++)
  {
   cin >> A[nn];
    total += A[nn];
  }
  
  double aveD  = double(total) / double(N);
  int ave = round(aveD);
  int cost = 0;
  
  for(int nn=0; nn<N; nn++)
  {
    int diff = A[nn] - ave; 
    cost += diff * diff;
  }
  cout << cost << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(b>a+w){
    cout << b-a-w;
  }else if(a>b+w){
    cout << a-b-w;
  }else{
    cout << 0;
  }
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1e18;

typedef struct edge_ {
		int from, to;
		ll cost;
		edge_(int f, int t, int c): from(f), to(t), cost(c){};
} edge;

vector<edge> ed;
int v, e;

bool comp (const edge &ed1, const edge &ed2){
		return ed1.cost < ed2.cost;
}

int par[10001];
int r[10001];

void init(){
		for(int i = 0; i < v; i++)par[i] = i;
}

int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
}

void unite(int x, int y){
		int xp = find(x);
		int yp = find(y);
		if(xp == yp)return;
		if(r[xp] > r[yp]){
				par[yp] = xp;
		}else{
				par[xp] = yp;
				if(r[xp] == r[yp])r[yp]++;
		}
}

int main(int argc, char const* argv[])
{
	cin >> v >> e;
	for(int i = 0; i < e; i++){
			int s, t, w;
			cin >> s >> t >> w;
			ed.pb(edge(s, t, w));
	}
	init();
	sort(ed.begin(), ed.end(), comp);
	ll res = 0;
	for(auto itr = ed.begin(); itr != ed.end(); ++itr){
			int from = (*itr).from;
			int to = (*itr).to;
			ll cost = (*itr).cost;
			if(find(from) != find(to)){
					res += cost;
					unite(from, to);
			}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 4932
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;

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

    static class CManyMedians {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] x = IntStream.range(0, n).map(o -> in.nextInt()).toArray();
            int[] s = Arrays.stream(x).sorted().toArray();
            int c = (n - 1) / 2;
            int m = s[c];
            for (int i = 0; i < n; i++) {
                if (x[i] > m) {
                    out.println(m);
                } else {
                    out.println(s[c + 1]);
                }
            }
        }

    }
}



Measured memory_bytes: 74508
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> v;

int main(void){
	int n,i,p;
	cin >> n;
	for(i=1; i<=n; ++i){
		cin >> p;
		v.push_back(P(p,i));
	}
	sort(v.begin(),v.end());
	for(i=0; i<n; ++i){
		cout << (i?" ":"") << v[i].second;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1780
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll N;
    cin >> N;
    ll ans = 0;
    rep(a,1,N){
        ll max_b = N / a;
        ans += max_b;
        if(N % a == 0) ans--;
    }
    print(ans);
    

}

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

Measured memory_bytes: 3668
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=0;R=10**9
while(R-L>1):
	M=L+R>>1;C=0
	for i in A:C+=(i-1)//M
	if C<=K:R=M
	else:L=M
print(R)

Measured memory_bytes: 30704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n, l;
    cin >> n >> l;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll last = -1;
    rep(i, 0, n-1) if(a[i] + a[i+1] >= l) last = i;
    if(last == -1) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    rep(i, 0, last) cout << i+1 << endl;
    for(ll i = n-2; i > last; i--) cout << i+1 << endl;
    cout << last + 1 << endl;
    return 0;
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (b % a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }
}

Measured memory_bytes: 23892
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()
 
class UnionFind:
    def __init__(self, n):
        self.n = n + 1
        self.parents = [-1] * (n + 1)
        self.mem = [[] for _ in range(n+1)]
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        if not self.mem[root]:
            self.mem[root] = [i for i in range(1, self.n) if self.find(i) == root]
        return self.mem[root]
 
def main():
    N, M, K = map(int, input().split())
 
    friends = defaultdict(lambda : 1)
    friendsGroup = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        friendsGroup.union(a, b)
        friends[a] += 1
        friends[b] += 1
 
    block_and_same = defaultdict(int)
    for _ in range(K):
        c, d = map(int, input().split())
        if friendsGroup.same(c, d):
            block_and_same[c] += 1
            block_and_same[d] += 1
 
    ans = [0] * (N + 1)
    for i in range(1, N+1):
        ans[i] = friendsGroup.size(i) - friends[i] - block_and_same[i]
    print(*ans[1:])
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 43056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    if(N + M == 2) {
        cout << 1 << "\n";
        return 0;
    }
    if(N == 1 || M == 1) {
        cout << max(0LL, max(N, M) - 2) << "\n";
        return 0;
    }
    cout << N * M - 2 * N - 2 * M + 4 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int an[SIZE];
void print_array(int arr[],int n){
    REP(i,n){
        if(i)printf(" ");
        printf("%d",arr[i]);
    }
    puts("");
}
struct data{
    int x,dir,id;
    data(int _x=0,int _dir=0,int _id=0):x(_x),dir(_dir),id(_id){}
    bool operator<(const data& b)const{return x<b.x;}
}a[SIZE];
int b[SIZE];
int main(){
    DRII(n,m);
    LL t;
    cin>>t;
    REP(i,n){
        RI(a[i].x);
        a[i].x%=m;
        a[i].id=i;
        int dir;
        RI(dir);
        if(dir==1)
        	a[i].dir=1;
        else 
        	a[i].dir=-1;
    }
    sort(a,a+n);
    bool dif=0;
    REPP(i,1,n){
        if(a[i].dir!=a[i-1].dir)dif=1;
    }
    if(!dif){
        if(a[0].dir==1){
            REP(i,n)an[a[i].id]=(a[i].x+t)%m;
        }
        else{
            REP(i,n)an[a[i].id]=((a[i].x-t)%m+m)%m;
        }
    }
    else{
        int st=0;
        while(a[st].dir==-1)st++;
        int neg=0,lst_neg=0;
        REP(i,n){
            if(a[i].dir==-1){
                neg+=2;
                if((a[i].x-a[st].x+m)%m<t%m*2)lst_neg++;
                if((a[i].x-a[st].x+m)%m+m<t%m*2)lst_neg++;
            }
        }
        int ch=(neg*(t/m)+lst_neg)%n;
        REP(i,n){
            if(a[i].dir==1)b[i]=(a[i].x+t)%m;
            else b[i]=((a[i].x-t)%m+m)%m;
        }
        sort(b,b+n);
        int st_new_pos=(a[st].x+t)%m;
        int new_st=0;
        while(b[new_st]<st_new_pos)new_st++;
        REP(i,n)
            an[a[(st+i+ch)%n].id]=b[(new_st+i)%n];
    }
    print_array(an,n);
    return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = Integer.parseInt(scan.next());
		int w = Integer.parseInt(scan.next());
		System.out.println("");
		char[][] str = new char[h][w];
		for(int i=0; i<h; ++i) {
			String s = scan.next();
			for(int j=0; j<w; ++j) {
				str[i][j] = s.charAt(j);
			}
		}
		scan.close();

		for(int i=0; i<h; ++i) {
			for(int j=0; j<w;++j) {
				if(str[i][j] == '#') {
					System.out.print('#');
				} else {
					int bobNum = search(str, i, j, h, w);
					System.out.print(bobNum);
				}

			}
			System.out.println("");
		}
	}

	public static int search(char[][] str, int i, int j, int h, int w) {
		int bobNum = 0;
		for(int a=i-1; a <= i+1; ++a) {
			for(int b=j-1; b<=j+1; ++b) {
				if((0<= a && a<=h-1) && (0<= b && b<=w-1)) {
					char mas = str[a][b];
					if(mas == '#') {
						++bobNum;
					}
				}

			}
		}
		return bobNum;
	}

}

Measured memory_bytes: 22484
#include<iostream>
#include<set>
using namespace std;
int main()
{
  int n,sx,sy,x,y;
  bool f;
  set< pair<int,int> >asterism,star;
  set< pair<int,int> >::iterator it1,it2;
  while(cin>>n,n){
    asterism.clear();
    star.clear();

    cin>>sx>>sy;
    n--;
    while(n-->0){
      cin>>x>>y;
      x-=sx;y-=sy;
      asterism.insert(make_pair(x,y));
    }

    cin>>n;
    while(n-->0){
      cin>>x>>y;
      star.insert(make_pair(x,y));
    }

    for(it1=star.begin();it1!=star.end();it1++){
      f=true;
      for(it2=asterism.begin();it2!=asterism.end();it2++){
	if( star.count( make_pair(it1->first+it2->first,it1->second+it2->second) ) )continue;
	f=false;
      }
      if(f)break;
    }

    cout<<(it1->first - sx)<<" "<<(it1->second - sy)<<endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r<0||x+r>W||y-r<0||y+r>H){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    return 0;
}

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

int i, k;
int a[7], b[7];
int t;
char str[100];

void input()
{
    //さいころに数字を割り当てる
    for (i = 1; i <= 6; i++){
        scanf("%d", &a[i]);
    }

    for (i = 1; i <= 6; i++){
        scanf("%d", &b[i]);
    }
}

void divide()
{
    if (b[1] == a[1]){
        if (b[2] == a[3]){
            strcpy(str, "NWS");
        }else if (b[2] == a[4]){
            strcpy(str, "NES");
        }else if (b[2] == a[5]){
            strcpy(str, "NWWS");
        }else if (b[2] == a[6]){
            strcpy(str, "N");
        }
    }else if (b[1] == a[2]){
        if (b[2] == a[1]){
            strcpy(str, "WWN");
        }else if (b[2] == a[3]){
            strcpy(str, "EN");
        }else if (b[2] == a[4]){
            strcpy(str, "WN");
        }else if (b[2] == a[6]){
            strcpy(str, "N");
        }
    }else if (b[1] == a[3]){
        if (b[2] == a[1]){
            strcpy(str, "SW");
        }else if (b[2] == a[2]){
            strcpy(str, "W");
        }else if (b[2] == a[5]){
            strcpy(str, "NNW");
        }else if (b[2] == a[6]){
            strcpy(str, "NW");
        }
    }else if (b[1] == a[4]){
        if (b[2] == a[1]){
            strcpy(str, "SE");
        }else if (b[2] == a[2]){
            strcpy(str, "E");
        }else if (b[2] == a[5]){
            strcpy(str, "NNE");
        }else if (b[2] == a[6]){
            strcpy(str, "NE");
        }
    }else if (b[1] == a[5]){
        if (b[2] == a[1]){
            strcpy(str, "S");
        }else if (b[2] == a[3]){
            strcpy(str, "WS");
        }else if (b[2] == a[4]){
            strcpy(str, "ES");
        }else if (b[2] == a[6]){
            strcpy(str, "WWS");
        }
    }else if (b[1] == a[6]){
        if (b[2] == a[2]){
            strcpy(str, "WW");
        }else if (b[2] == a[3]){
            strcpy(str, "SWS");
        }else if (b[2] == a[4]){
            strcpy(str, "SES");
        }else if (b[2] == a[5]){
            strcpy(str, "NN");
        }
    }
}

//Nが入力されたらの数字の移動を行う
void N()
{
    t = a[1];
    a[1] = a[2];
    a[2] = a[6];
    a[6] = a[5];
    a[5] = t;
}

//Eが入力されたらの数字の移動を行う
void E()
{
    t = a[1];
    a[1] = a[4];
    a[4] = a[6];
    a[6] = a[3];
    a[3] = t;
}

//Sが入力されたらの数字の移動を行う
void S()
{
    t = a[1];
    a[1] = a[5];
    a[5] = a[6];
    a[6] = a[2];
    a[2] = t;
}

//Nが入力されたらの数字の移動を行う
void W()
{
    t = a[1];
    a[1] = a[3];
    a[3] = a[6];
    a[6] = a[4];
    a[4] = t;
}

void ass()
{
    for (i = 0; i < strlen(str); i++){
        if (str[i] == 'N'){
            N();
        }else if (str[i] == 'E'){
            E();
        }else if (str[i] == 'S'){
            S();
        }else if (str[i] == 'W'){
            W();
        }
    }
}

void output()
{
    /*for (i = 1; i <= 6; i++){
        printf("%d %d\n",a[i],b[i]);
    }*/
    k = 0;
    for (i = 1; i <= 6; i++){
        if (b[i] == a[i]){
            k++;
        }
    }

    if (k == 6){
        printf("Yes\n");
    }else {
        printf("No\n");
    }
}

int main(void)
{
    input();

    divide();

    ass();

    output();

    return (0);
}



Measured memory_bytes: 2100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0];
			var P = retreiveLongArray();
			var Q = retreiveLongArray();

			var nArray = new List<int>();

			for (int i = 1; i <= N; i++) {
				nArray.Add(i);
			}
			//すべての順列を列挙する
			var Permutations= enumeratePermutation(nArray);
			var PermutationStrings = Permutations.Select(x => string.Join("", x)).OrderBy(x =>x).ToList();

			var pString = string.Join("", P);
			var qString = string.Join("", Q);

			var pnum = PermutationStrings.IndexOf(pString);
			var qnum = PermutationStrings.IndexOf(qString);

			Console.WriteLine( Math.Abs(pnum - qnum));


		}



		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}

		/// <summary>
		/// 順列をすべて返す
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="items"></param>
		/// <returns></returns>
		private static IEnumerable<T[]> enumeratePermutation<T>(IEnumerable<T> items) {
			if (items.Count() == 1) {
				yield return new T[] { items.First() };
				yield break;
			}
			foreach (var item in items) {
				var leftside = new T[] { item };
				var unused = items.Except(leftside);
				foreach (var rightside in enumeratePermutation(unused)) {
					yield return leftside.Concat(rightside).ToArray();
				}
			}
		}
	}
}


Measured memory_bytes: 24252
import java.util.Scanner;

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

		//入居者の情報件数
		int infoNum = scan.nextInt();

		//入居者の情報
		int[][][] infoStay = new int[4][3][10];

		for(int i = 0 ;i < infoNum;i++){
			//情報の入力
			infoStay[scan.nextInt()-1][scan.nextInt()-1][scan.nextInt()-1] += scan.nextInt();
		}

		//棟の数ループ
		for(int building = 0 ;building < 4;building++){
			//階数ループ
			for(int storey = 0 ;storey < 3;storey++){
				//階ごとの部屋の数ループ
				for(int room = 0;room < 10;room++){
					System.out.print(" " + infoStay[building][storey][room]);
				}
				//AOJの制約による改行
				System.out.println("");
			}
			//AOJの制約のよるの条件
			if(building < 3 ){
				System.out.println("####################");
			}
		}
		scan.close();
	}
}



Measured memory_bytes: 29552
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i=1;
  while(++i<=n){
    int x=i;
    if(x%3==0){
      cout << " " << i;
      continue;
    }
    while(x){
      if(x%10==3){
	cout << " " << i;
	break;
      }
      x/=10;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info{
	Info(){
		to_left_id = to_right_id = -1;
	}
	void init(){
		to_left_id = to_right_id = -1;
	}
	int to_left_id,to_right_id;
};

void func(int N,int L){

	Info info[L+1],work[L+1];

	int ant_loc;
	char dist[2];

	for(int ant_id = 1; ant_id <= N; ant_id++){
		scanf("%s %d",dist,&ant_loc);

		if(dist[0] == 'L'){
			info[ant_loc].to_left_id = ant_id;
		}else{
			info[ant_loc].to_right_id = ant_id;
		}
	}

	int count,sum_time = 0,final_ant,final_time = 0;

	while(true){

		for(int i = 1; i <= L-1; i++)work[i].init();

		count = 0;
		for(int i = 1; i <= L-1; i++){
			if(info[i].to_left_id != -1 && info[i].to_right_id != -1){
				count += 2;

				work[i+1].to_right_id = info[i].to_left_id;
				work[i-1].to_left_id = info[i].to_right_id;

			}else if(info[i].to_left_id != -1 && info[i].to_right_id == -1){
				count++;
				work[i-1].to_left_id = info[i].to_left_id;
				if(i == 1){
					final_ant = info[i].to_left_id;
					final_time = sum_time;
				}
			}else if(info[i].to_left_id == -1 && info[i].to_right_id != -1){
				count++;
				work[i+1].to_right_id = info[i].to_right_id;
				if(i == L-1 && final_time < sum_time){
					final_ant = info[i].to_right_id;
					final_time = sum_time;
				}
			}
		}
		if(count == 0)break;
		sum_time++;

		for(int i = 1; i <= L-1; i++){
			info[i].to_left_id = work[i].to_left_id;
			info[i].to_right_id = work[i].to_right_id;
		}
	}

	printf("%d %d\n",sum_time,final_ant);

}

int main(){

	int N,L;
	while(true){
		scanf("%d %d",&N,&L);
		if(N == 0 && L == 0)break;

		func(N,L);
	}

	return 0;
}

Measured memory_bytes: 2596
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
#define ll long long

int main () {
  string h;
  cin >> h;
  // 区切って行く.
  vector<ll> tate, yoko;
  ll now = 0;
  ll itr = -1;
  ll right = 0;
  ll x, y;
  cin >> x >> y;
  for (ll i = 0; i < h.size(); i++) {
    if (h[i] == 'T') {
      itr = i;
      right = now;
      break;
    }
    else {
      now++;   
    }
    if (i == h.size() - 1) {
      itr = i;  
      right = now;
    }
  }
  now = 0;
  for (ll i = itr + 1; i < h.size(); i++) {
    if (h[i] == 'T') {
      if (tate.size() > yoko.size()) {
        yoko.push_back(now);  
      }
      else {
        tate.push_back(now);  
      }
      now = 0;
    }
    else {
      now++;  
    }
    if (i == h.size() - 1 && h[i] == 'F') {
      if (tate.size() > yoko.size()) {
        yoko.push_back(now);  
      }
      else {
        tate.push_back(now);  
      }
    }
  }

  // xについて
  bool dp1[yoko.size() + 1][8000 * 2 + 1];
  for (ll i = 0; i <= yoko.size(); i++) {
    for (ll j = 0; j <= 8000 * 2; j++) {
      dp1[i][j] = false;
    }  
  }
  dp1[0][right + 8000] = true;
  for (ll i = 1; i <= yoko.size(); i++) {
    for (ll j = 0; j <= 8000 * 2; j++) {
      if (dp1[i - 1][j] == true) {
        dp1[i][j + yoko[i - 1]] = true;
        dp1[i][j - yoko[i - 1]] = true;
      }   
    }  
  }
  // yについて
  bool dp2[tate.size() + 1][8000 * 2 + 1];
  for (ll i = 0; i <= tate.size(); i++) {
    for (ll j = 0; j <= 8000 * 2; j++) {
      dp2[i][j] = false;  
    }  
  }
  dp2[0][8000] = true;
  for (ll i = 1; i <= tate.size(); i++) {
    for (ll j = 0; j <= 8000 * 2; j++) {
      if (dp2[i - 1][j] == true) {
        dp2[i][j + tate[i - 1]] = true;  
        dp2[i][j - tate[i - 1]] = true;  
      }   
    }  
  }
  if (dp1[yoko.size()][8000 + x] == true && dp2[tate.size()][8000 + y] == true) {
    cout << "Yes" << endl;  
  }
  else {
    cout << "No" << endl;  
  }

  
}


Measured memory_bytes: 124416
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 1000005;
int bit[MAX_N+1][26];
int nn = MAX_N; //　1-index

void adds(int a, int w, int m){
    for(int x = a; x <= nn; x += x & -x) bit[x][m] += w;
}
int sums(int a, int m){ // bit[1,a]の和を返す.
    int ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x][m];  
    return ret;
}


int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,n){
        adds(i+1, 1, s[i] - 'a');
    }

    int q;
    cin >> q;
    rep(loop, q){
        int x;
        cin >> x;
        if(x == 1){
            int y;
            char c;
            cin >> y >> c;
            y--;
            adds(y+1,-1,s[y] - 'a');
            adds(y+1,1,c - 'a');
            s[y] = c;
        }else{
            int l, r;
            cin >> l >> r;
            int ans = 0;
            
            rep(i,26){
                int tmp = sums(r,i);
                if(1 < l)tmp -= sums(l-1,i);
                if(tmp > 0)ans++;    
            }
            cout << ans << endl;
        }
    }
    
    return 0;
}
 
 


Measured memory_bytes: 56196
n=int(raw_input())
N=map(int,raw_input().split())
a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(N[i])
    else:
        b.append(N[i])
if n%2==0:
    b.reverse()
    for i in b+a:
        print i,
else:
    a.reverse()
    for i in a+b:
        print i,


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

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var days = int.Parse(Console.ReadLine());

            var scoreDownCoefficients = Console.ReadLine().Split(" ")
                .Select((x, i) => (score: int.Parse(x), questionNumber: i + 1))
                .OrderByDescending(x => x.score)
                .ToDictionary(x => x.questionNumber, x => x.score);

            Hoge(days, scoreDownCoefficients);
        }

        private static void Hoge(int days, IReadOnlyDictionary<int, int> scoreDownCoefficients)
        {
            var lastDictionary = new Dictionary<int, int>();

            foreach (var today in Enumerable.Range(1, days))
            {
                var downScoreDictionary = GetAll(today, lastDictionary, scoreDownCoefficients);
                var overallDownScore = downScoreDictionary.Values.Sum();

                var scoreUpNumber = Console.ReadLine().Split(" ")
                    .Select((score, i) => (score: int.Parse(score), questionNumber: i + 1))
                    .OrderByDescending(x =>
                    {
                        lastDictionary.TryGetValue(x.questionNumber, out var lastHeld);

                        return x.score - overallDownScore + downScoreDictionary[x.questionNumber];
                    })
                    .First();

                lastDictionary[scoreUpNumber.questionNumber] = today;

                Console.WriteLine(scoreUpNumber.questionNumber);
            }
        }

        private static Dictionary<int, int> GetAll(int today, Dictionary<int, int> lastDictionary, IReadOnlyDictionary<int, int> scoreDownCoefficients)
        {
            return Enumerable.Range(1, 26).Select(x =>
                {
                    lastDictionary.TryGetValue(x, out var lastHeld);
                    return (QuestionNumber: x, DownScore: (today - lastHeld) * scoreDownCoefficients[x]);
                })
                .ToDictionary(x => x.QuestionNumber, x => x.DownScore);
        }
    }
}


Measured memory_bytes: 29940
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;

LL inf = 1000000000000;
LL mod = 1000000007;

int main()
{
	string s;
	cin >> s;

	deque<char> d;

	for (auto e : s) {
		d.emplace_back(e);
	}

	LL q;
	cin >> q;
	LL rev = 2, fro = 1;

	LL tone = 0;
	while (q--) {
		LL t;
		cin >> t;
		if (t == 1) {
			tone++;
			swap(fro, rev);
		}
		else {
			LL f;
			char c;
			cin >> f >> c;

			if (f == fro) {
				d.emplace_front(c);
			}
			else {
				d.emplace_back(c);
			}
		}
	}

	if (tone%2) {
		reverse(d.begin(), d.end());
	}

	for (auto e : d) {
		cout << e;
	}
	cout << "\n";

}

Measured memory_bytes: 896
using System;

namespace newEx
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] l = Console.ReadLine().Split(' ');
            int p = int.Parse(l[0]);
            int q = int.Parse(l[1]);
            int r = int.Parse(l[2]);


            Console.WriteLine(Solve(p, q, r));
        }

        public static int Solve(int p, int q, int r)
        {
            int ret = p + r;
            int ret2 = p + q; //修正200630 
            int ret3 = r + q;    //修正200630

            //ret = 2;
            //ret2 = 3;
            //ret3 = 1;
            if (ret <= ret2 && ret <= ret3)  //修正200630
            {
                // Console.WriteLine("最短距離:"+ p+r +"時間");
                return ret;
            }
            else if (ret2 <= ret && ret2 <= ret3)  //修正200630
            {
                // Console.WriteLine("最短距離:" + p+q + "時間");
                return ret2;      //修正200630
            }
            else
            //else if (ret3 < ret && ret3 < ret2)   //修正200630
            {
                //  Console.WriteLine("最短距離:" + r+q + "時間");
                return ret3;     //修正200630
            }
        }
    }
}


Measured memory_bytes: 27428
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;scan(N);
	prin((N-2)*180);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <numeric>
#include <map>
#include <sstream>
#include <bitset>
using namespace std;


int main()
{
    char b;
    cin>>b;
    if(b=='A'){
        cout<<'T'<<endl;
    }
    else if(b=='T'){
        cout<<'A'<<endl;
    }
    else if(b=='G'){
        cout<<'C'<<endl;
    }
    else{
        cout<<'G'<<endl;
    }
    
}


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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n; cin >> n; if(n == 0) break;
    vi a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    int minv = inf;
    rep(i,n-1) minv = min(minv, a[i+1] - a[i]);
    cout << minv << endl;
  }
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
       x %= MOD;
       if (t == 0) {
               return 1;
       }
       else {
               ll v = mod_pow(x, t / 2);
               if (t % 2 == 0) {
                       return v * v % MOD;
               }
               else {
                       return v * v%MOD * x %MOD;
               }
       }
}

ll mod_inv(ll x) {
       return mod_pow(x, MOD - 2);
}

vll fct(5000);
vll invfct(5000);

void init(){
        fct[0] = invfct[0] = 1;
        REP(i,1,2000){
                fct[i] = mod_m(fct[i-1], i);
                invfct[i] = mod_inv(fct[i]);
        }
}

ll ncr(ll x,ll y){
        return mod_m(fct[x], mod_m(invfct[y], invfct[x-y]));
}
int main(){
        init();
        ll n; ll k;
        cin >> n >> k;
        vll a(k+1);
        REP(i,1,k){
                cin >> a[i];
        }
        vvll dp(k+2, vll(n+2));
        dp[0][n] = 1;
        REP(y,1,k){
                REP(x,0,n){
                        REP(i,0,min(n-x, a[y])){
                                ll tmp = mod_m(ncr(x + i, i), mod_m(dp[y-1][x + i], ncr(n-i, a[y]-i)));
                                dp[y][x] = mod_p(dp[y][x], tmp);
                        }
                }
        }
        cout << dp[k][0] << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int r,c;
        r = sc.nextInt();
        c = sc.nextInt();
        char grid[][] = new char[r][c];

        for(int i=0;i<r;i++){
                 grid[i] = sc.next().toCharArray();
        }

        int dp[][] = new int[r][c];

        dp[0][0] = 1;
        for(int i=1;i<r;i++){
            if(grid[i][0] == '#') dp[i][0] = 0;
            else dp[i][0] = dp[i-1][0];
        }

        for(int j=1;j<c;j++){
            if(grid[0][j] == '#') dp[0][j] = 0;
            else dp[0][j] = dp[0][j-1];
        }

        int modulo = (int) Math.pow(10,9) + 7;

        for(int i=1;i<r;i++){
            for(int j=1;j<c;j++){
                if(grid[i][j] == '#') dp[i][j] = 0;
                else{
                    int ans  = dp[i-1][j]%modulo + dp[i][j-1]%modulo;
                    dp[i][j] = ans%modulo;
                }
            }
        }

        System.out.println(dp[r-1][c-1]);
    }
}


Measured memory_bytes: 37624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll x;cin >> x;
    vl v;
    v.pb(0);
    rep(i,130){
        ll a=pow(i+1,5);
        v.pb(a);
    }
    rep(i,131){
        rep(j,131){
            if(v[i]+v[j]==x){
                cout << i << " " << -(j) <<endl;
                return 0;
            }
            if(v[i]-v[j]==x){
                cout << i << " " << (j) <<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4076
#include<cstdio>
#include<cstring>
const int N=57;
struct node
{
	int to,next;
}e[N*N];
int first[N],cnt;
inline void insert(int u,int v)
{
	e[++cnt]=(node){v,first[u]};first[u]=cnt;
	e[++cnt]=(node){u,first[v]};first[v]=cnt;
}
int dfn[N],low[N];
int sum;
inline int min(int a,int b)
{
	return a<b?a:b;
}
void tarjan(int x,int fa)
{
	dfn[x]=low[x]=++cnt;
	for(int k=first[x];k;k=e[k].next)
	{
		if(!dfn[e[k].to])	
		{
			tarjan(e[k].to,x),low[x]=min(low[x],low[e[k].to]);
			if(low[e[k].to]>dfn[x])		sum++;
		}
		else if(e[k].to!=fa)	low[x]=min(low[x],dfn[e[k].to]);
	}
}
int main()
{
	int n,m,u,v;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)	scanf("%d %d",&u,&v),insert(u,v);
	cnt=0;
	for(int i=1;i<=n;i++)	if(!dfn[i])	tarjan(i,-1);
	printf("%d\n",sum);
	return 0;
}

/*
*/


Measured memory_bytes: 128