akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	long double pi = atan(1) * 4;

	int a, b, h, m;
	cin >> a >> b >> h >> m;
	long double ax = a * cos((2 * pi / 12) * (h + m / 60.));
	long double bx = b * cos((2 * pi / 60) * m);
	long double ay = a * sin((2 * pi / 12) * (h + m / 60.));
	long double by = b * sin((2 * pi / 60) * m);
	cerr << ax << ' ' << bx << ' ' << ay << ' ' << by << '\n';
	cout << fixed << setprecision(10) << sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}


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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> P(N);
    for (int i=0; i<N; i++) {
        cin >> P.at(i);
    }
    sort(P.begin(),P.end());
    int ans = 0;
    for (int i=0;i<K;i++){
        ans += P[i] ;
    }
    cout << ans;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n;
int p[maxN];

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    int ans = 0;
    set<int> all;
    for (int i = 0; i < n; i ++)
    {
      scanf("%d", &p[i]);
      p[i] --;
      all.insert(p[i]);
      ans += *all.begin() == p[i];
    }

    printf("%d\n", ans);
  }
  return 0;
}

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

using namespace std;

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    int arr[m];
    for(int i = 0; i < m; ++i){
        cin >> arr[i];
    }
    int ans = 0, tmp = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            int garbo; cin >> garbo;
            tmp += garbo * arr[j];
        }
        tmp += c;
        if(tmp > 0)ans++;
        tmp = 0;
    }
    cout << ans;
    return 0;

}


Measured memory_bytes: 256
main :: IO ()
main = do input <- getLine
          let sec = read input :: Int
          let h = sec `div` 3600
          let sec' = sec `mod` 3600
          let m = sec' `div` 60
          let s = sec' `mod` 60
          putStrLn $ show h ++ ":" ++ show m ++ ":" ++ show s

Measured memory_bytes: 3684
#abc152 d
n=int(input())

def first_num(x):
    l=x
    while int(x/10)>0:
        x=int(x/10)
        l=x
    return l

kiroku=dict()
for i in range(1,n+1):
    first=first_num(i)
    last=i%10
    #組はタプルに入ってる
    if (first,last) in kiroku:
        kiroku[first,last]+=1
    else:
        kiroku[first,last]=1

ans=0
for key in kiroku.keys():
    f,l=key
    if (l,f) in kiroku:
        kumi=kiroku[f,l]*kiroku[l,f]
        ans+=kumi
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int A, B;
	cin >> A >> B;
    string res;
    if (A == 1) {
        A = 14;
    }
    if (B == 1) {
        B = 14;
    }
    if (A > B) {
        res = "Alice";
    } else if (A < B) {
        res = "Bob";
    } else {
        res = "Draw";
    }
    cout << res << endl;   
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	string ans = "";
	for(int i = 0; i < (int)s.size(); ++i) {
		if( ans != "" && s[i] == 'B' ) {
			ans.pop_back();
		} else if( s[i] != 'B' ) {
			ans += s[i];
		}			
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
# 入力を整数に変換して受け取る
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, input().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n, k, q = MI()
    A = [II() for _ in range(q)]

    ini = k-q
    point = [ini for _ in range(n)]
    for a in A.copy():
        point[int1(a)] += 1

    for p in point:
        print('Yes' if p > 0 else 'No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 10548
# https://atcoder.jp/contests/abc096/tasks/abc096_c

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

# 隣に # が一つ以上あるかどうか
def has_neighbor(y, x):
    dhs = [1, -1, 0, 0]
    dws = [0, 0, 1, -1]
    for dh, dw in zip(dhs, dws):
        if 0 <= y + dh < H and 0 <= x + dw < W:
            if S[y + dh][x + dw] == "#":
                return True
    return False


for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if not has_neighbor(h, w):
                print("No")
                exit()

print("Yes")




Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  vector<int> rate(9);
  for(int i=0;i<N;i++){
    if(a.at(i)<400) rate.at(0)++;
    else if(a.at(i)<800) rate.at(1)++;
    else if(a.at(i)<1200) rate.at(2)++;
    else if(a.at(i)<1600) rate.at(3)++;
    else if(a.at(i)<2000) rate.at(4)++;
    else if(a.at(i)<2400) rate.at(5)++;
    else if(a.at(i)<2800) rate.at(6)++;
    else if(a.at(i)<3200) rate.at(7)++;
    else  rate.at(8)++;
  }

  int mi=0;
  int ma=0;
  for(int i=0;i<8;i++){
    if(rate.at(i)!=0){
      mi++;
      ma++;
    }
  }
  if(rate.at(8)!=0){
    mi=max(mi,1);
    ma=ma+rate.at(8);
  }

  cout << mi << " " << ma << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int32_t main(){
    fast;
    int n{};    cin>>n;
    int B[n]{};
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp; 
        B[temp]++; 
    }
    for(int i=0;i<n;i++){
        if(B[i]>2){
            cout<<0<<endl;
            return 0;
        }
        // cout<<i<<">>>>>>>>>>>"<<B[i]<<endl;
    }
    if(B[0]>1){
        cout<<0<<endl;
        return 0;
    }
    int ans = 1;
    for(int i=0;i<n/2;i++){
        ans*=2;
        ans%=1000000007;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
for i,j in zip(data,range(1,N+1)):
    if i != j:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2e5 + 10;
const ll mod = 1e9 + 7;

int n, k;
ll a[maxN];

int minProduct() {
  ll ret = 1;
  if (k == n) {
    for (int i = 1; i <= n; ++i) {
      ret = (ret * a[i] + mod * mod) % mod;
    }
    return ret;
  }
  if (a[1] >= 0) {
    for (int i = n; i > n - k; --i) {
      ret = (ret * a[i] + mod * mod) % mod;
    }
    return ret;
  }
  if (a[n] < 0){
    if (k % 2 == 0) {
      for (int i = 1; i <= k; ++i) {
        ret = (ret * a[i] + mod * mod) % mod;
      }
      return ret;
    } else {
      for (int i = n; i > n - k; --i) {
        ret = (ret * a[i] + mod * mod) % mod;
      }
      return ret;
    }
  }
  int i = 1, j = n;
  if (k % 2 == 1) {
    ret = a[j]; --j; --k;
  }
  while (1) {
    if (k == 0) break;
    k -= 2;
    if (a[i] * a[i+1] > a[j] * a[j-1]) {
      ret = (ret * a[i] + mod * mod) % mod;
      ret = (ret * a[i+1] + mod * mod) % mod;
      i += 2;
    } else {
      ret = (ret * a[j] + mod * mod) % mod;
      ret = (ret * a[j-1] + mod * mod) % mod;
      j -= 2;
    }
  }

  return ret;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);

  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  cout << minProduct();

  return 0;
}


Measured memory_bytes: 5196
import java.util.*;

class Main {
  public static void main (String[] args) {

    Calendar m = Calendar.getInstance();
    Calendar t = Calendar.getInstance();
    Calendar s = Calendar.getInstance();
    Calendar h = Calendar.getInstance();

    m.set(1868, 9, 8);
    t.set(1912, 7, 30);
    s.set(1926, 12, 25);
    h.set(1989, 1, 8);

    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      int yyyy = scanner.nextInt();
      int mm = scanner.nextInt();
      int dd = scanner.nextInt();
      Calendar in = Calendar.getInstance();
      in.set(yyyy, mm, dd);
      if (in.compareTo(m) < 0) {
        out += "pre-meiji\n";
        continue;
      }
      if (in.compareTo(t) < 0) {
        out += "meiji " + ((yyyy - 1868) + 1) + " " + mm + " " + dd + "\n";
        continue;
      }
      if (in.compareTo(s) < 0) {
        out += "taisho " + ((yyyy - 1912) + 1) + " " + mm + " " + dd + "\n";
        continue;
      }
      if (in.compareTo(h) < 0) {
        out += "showa " + ((yyyy - 1926) + 1) + " " + mm + " " + dd + "\n";
        continue;
      }
      out += "heisei " + ((yyyy - 1989) + 1) + " " + mm + " " + dd + "\n";
      continue;
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 17304
#include<bits/stdc++.h>
#define INF            1e9
#define REP(i,n)       for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n)  for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPR(i,n)      for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(lint i=(n);i>0;--i)
#define REPRI(i,ini,n) for(lint i=(ini)-1,i##_len=(n);i>=i##_len;--i)
#define REPC(i,obj)    for(auto i:obj)
#define R_UP(a,b)      (((a)+(b)-1)/(b))
#define ALL(obj)       (obj).begin(),(obj).end()
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
int binary_search_p(int first_w, int last_w, int k, int max_w, const vector<int>&w)
{
	auto get_minimum_k = [&w](int p_candidate)
	{
		int result = 1;
		int temp = 0;
		REPC(i, w)
		{
			if (temp + i <= p_candidate)temp += i;
			else
			{
				result++;
				temp = i;
			}
		}
		return result;
	};
	int p_candidate = first_w + (last_w - first_w) / 2;
	int min_k = get_minimum_k(p_candidate);
	if (first_w > last_w)for (int i = max(p_candidate, max_w);; i++)if (get_minimum_k(i) <= k)return i;
	return min_k <= k ? binary_search_p(first_w, p_candidate - 1, k, max_w, w) : binary_search_p(p_candidate + 1, last_w, k, max_w, w);
}
signed main()
{
	int n = in(), k = in();
	vector<int>w(n);
	int min_w = 10001, max_w = -1, sum_w = 0;
	REPC(&i, w)
	{
		i = in();
		if (min_w > i)min_w = i;
		if (max_w < i)max_w = i;
		sum_w += i;
	}
	cout << binary_search_p(min_w, sum_w, k, max_w, w) << endl;
}


Measured memory_bytes: 3112
def main
  n = gets.to_i
  linked_list = LinkedList.new

  n.times do
    command = gets.split
    if command[1]
      linked_list.send(command[0], command[1].to_i)
    else
      linked_list.send(command[0])
    end
  end

  linked_list.print
end

class LinkedList
  def initialize
    @keys = []
  end

  def insert(key)
    @keys.unshift(key)
  end

  def delete(key)
    index = @keys.find_index(key)
    @keys.delete_at(index) if index
  end

  def deleteFirst
    @keys.shift
  end

  def deleteLast
    @keys.pop
  end

  def print
    puts @keys.join(" ")
  end
end

main


Measured memory_bytes: 21180
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int inf = 2e9;

int n;
int dp[100000];

int main(){
	scanf("%d", &n);
	fill_n(dp, n, inf);
	rep(i, n){
		int a;
		scanf("%d", &a);
		*lower_bound(dp, dp + n, a) = a;
	}
	for(int i = n - 1; i >= 0; --i){
		if(dp[i] != inf){
			printf("%d\n", i + 1);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     string a,b;
     cin>>a>>b;
     sort(a.begin(),a.end());
     sort(b.rbegin(),b.rend());
     cout<<(a<b ? "Yes\n" : "No\n");
     time();
     return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      String s = sc.next();
      int lng = s.length();
      char[] c = new char[lng];
      for(int i=0;i<lng;i++){
        c[i] = s.charAt(i);
      }

      int flag = 0;

      if(lng%2==1){
        flag = 1;
      }
      else{
        int lng2 = lng/2;
        for(int i=0;i<lng2;i++){
          if(c[i]!=c[lng2+i]){
            flag = 1;
            break;
          }
        }
      }


      if(flag==0){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }

    }
}


Measured memory_bytes: 23508
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
#include <bits/stdc++.h>
//codeforces
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846

vector<int> cur;
ll len = 1;
ll tot;
ll n;
bool flag = false;
void gen(ll idx) {
	if (flag)
		return;
	if (idx == len) {
		tot++;
		if (tot == n) {
			for ( int k = 0; k < len; k++ )
				cout << cur[k];
			cout << endl;
			flag = true;
		}
		return;
	}
	if (idx == 0) {
		for ( int k = 1; k < 10; k++ ){
			cur.pb(k);
			gen(idx + 1);
			cur.pop_back();
		}
		return;
	}
	if (cur[idx - 1] != 0) {
		cur.pb(cur[idx - 1] - 1);
		gen(idx + 1);
		cur.pop_back();
	}
	cur.pb(cur[idx - 1]);
	gen(idx + 1);
	cur.pop_back();
	if (cur[idx - 1] != 9) {
		cur.pb(cur[idx - 1] + 1);
		gen(idx + 1);
		cur.pop_back();
	}
}

int main(){
	FASTIO;
	cin >> n;
	while (!flag) {
		gen(0);
		len++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int v;
  int gene;

  Node(int v = -1, int gene = -1) {
    this->v = v;
    this->gene = gene;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> S;

  int s;
  for (int i = 0; i < pow(2, N); ++i) {
    cin >> s;
    S.push_back(s);
  }

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

  queue<Node> que;
  que.push(Node(S.back(), 0));
  S.erase(S.begin() + S.size() - 1);

  while (!que.empty()) {
    Node node = que.front();
    que.pop();

    // fprintf(stderr, "parent: %d, gene: %d, S = %d\n", node.v, node.gene, (int) S.size());

    int L = S.size();
    int idx = lower_bound(S.begin(), S.end(), node.v) - S.begin();

    if (idx == L) {
      idx = L - 1;
    } else {
      idx = max(0, idx - 1);
    }

    // fprintf(stderr, "idx = %d\n", idx);

    int child = S[idx];

    if (node.v <= child) {
      cout << "No" << endl;
      return 0;
    }

    S.erase(S.begin() + idx);

    if (node.gene + 1 < N) {
      que.push(Node(node.v, node.gene + 1));
      que.push(Node(child, node.gene + 1));
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 2420
/* Filename: ARC059D.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main{

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

		while (input.hasNext()) {
			String s = input.next();
			int[] countChar = new int[26];
			int[] countPrevFreq = new int[s.length()];
			int[] prevPos = new int[26];
			Arrays.fill(prevPos, -1);

			int a = -1, b = -1;
			for (int i = 0; i < s.length(); ++i) {
				int currentChar = s.charAt(i) - 'a';
				countPrevFreq[i] = countChar[currentChar];
				++countChar[currentChar];

				if (prevPos[currentChar] > -1) {
					int len = i - prevPos[currentChar] + 1;
					int freqDiff = countPrevFreq[i]
							- countPrevFreq[prevPos[currentChar]] + 1;

					if (freqDiff * 2 > len) {
						a = prevPos[currentChar] + 1;
						b = i + 1;
					}

				}

				prevPos[currentChar] = i;
			}

			System.out.printf("%d %d\n", a, b);
		}
	}
}


Measured memory_bytes: 13168
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    string S;
    cin >> N >> S;

    ll count = 0;
    ll ans = 0;
    rep(i, N){
        if(S[i] == 'I'){
            count++;
            if(count > ans){
                ans = count;
            }
        }else if(S[i] == 'D'){
            count--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

def gcd2(array):
    t = array[0]
    for i in array:
        t = gcd(t,i)
    return t

N,X=map(int,input().split())
x=list(map(int,input().split()))

dif=[abs(a-b)  for a,b in zip([X]+x,x)]
print(gcd2(dif))

Measured memory_bytes: 14480
# 単純 : 多重辺と自己ループがない
# 連結 : ひとかたまり

N, K = map(int, input().split())

e_max = (N - 1) * (N - 2) // 2
# 最短距離2の組数が最大となる
# ウニグラフの組数

if e_max < K:
    print(-1)
    exit()
# 構成可能な組数を超えており、不可能

es = []
for j in range(2, N + 1):
    es.append((1, j))
# print(es)
# ウニグラフ

to_join = e_max - K
# print(to_join)
# Kを達成するために、つなぐ必要がある辺の数

for i in range(2, N):
    for j in range(i + 1, N + 1):
        if to_join == 0:
            print(len(es))
            for i, j in es:
                print(i, j)
            exit()
        es.append((i, j))
        to_join -= 1

if to_join == 0:
    print(len(es))
    for i, j in es:
        print(i, j)
# ウニグラフに辺を追加していく（組数e_maxから開始）
# 辺を追加する度に、最短距離1の組数が1増える
# -> 最短距離2の組数が1減る
# 組数がKのとき、条件を満たすグラフが構築されている


Measured memory_bytes: 43376
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int N,a[MAXN];
bool candetermine(int x,int y)
{
    return (a[x+1]<y+1);
}
int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]);
    sort(a+1,a+N+1,greater<int>());
    int id=-1;
    for(int i=1;i<=N;i++)
    {
        if(candetermine(i,i))
        {
            int cnt1=(a[i]-i),cnt2=0;
            for(int j=i+1;j<=N;j++) if(a[j]>=i) cnt2++;
            if(cnt1%2==0&&cnt2%2==0) puts("Second"); else puts("First");
            return 0;
        }
    }
    return 0;
}


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

ll A, B, K;

int main(){
  cin >> A >> B >> K;
  if(A >= K) cout << A-K << " " << B << endl;
  else cout << 0 << " " << max(B - (K-A), ll(0)) << endl;
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    if(a+b < c+d) cout << "Right" << endl;
    else if(a+b == c+d) cout << "Balanced" << endl;
    else cout << "Left" << endl;
    return 0;
}

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

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

    int n, k; cin >> n >> k;
    int a[n], ans, dp[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    dp[0] = 0;
    for (int i=1; i<n; i++){
        dp[i] = 2e9;
        for (int d = 1; d<=k && i - d >= 0; d++){
            dp[i] = min(dp[i], dp[i-d] + abs(a[i] - a[i-d]));
        }
    }
    cout << dp[n-1] << endl;

}

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

int n;
vector<int> a;
vector<bool> p(2005,false);
void judge(){
  rep(bit,1<<n){
    int y = 0;
    rep(j,n){
      if(bit&(1<<j)) y += a[j];
    }
    p.at(y) = true;
  }
}

int main(){
  cin>>n;
  a.resize(n);
  rep(i,n) cin>>a[i];
  int q;
  cin>>q;
  vector<int> m(q);
  rep(i,q) cin>>m[i];
  
  judge();
  rep(i,q){
    if(p[m[i]]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  
}


Measured memory_bytes: 3136
def roll(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

dice = gets.split(" ").map{|i| i.to_i}

for i in 0..gets.to_i-1
  u,f = gets.split(" ").map{|i| i.to_i}
  
  turn = 0
  while dice[1] != f
    turn += 1
    dice = roll(dice,"N")
    break if dice[1] == f
    dice = roll(dice,"W") if turn%4 == 0
  end

  while dice[0] != u
    dice = roll(dice,"W")
  end

  puts dice[2] 
end

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



int main(){
int n,m;
cin>>n>>m;
vector<int> x(m);
for(int i=0;i<m;i++)cin>>x[i];
sort(x.begin(),x.end());
vector<int> d(m-1);
for(int i=0;i<m-1;i++){
d[i] = x[i+1]-x[i];
}
int sum=0;
sort(d.begin(),d.end());
for(int i=0;i<m-n;i++){
sum+=d[i];
}
cout<<sum<<endl;
	
	return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n,m;

bool check(int x, vector<int> v){
	string s = to_string(x);
	// cout << s << endl;
	if(s.size() != n)return false;
	
	for(int i = 0; i < s.size(); i++){
		// cout << (s[i]-'0') << " " << v[i+1] << endl;
		if(v[i+1] == -1)continue;
		if((s[i]-'0') != v[i+1])return false;
	}
	return true;
}

int main(){
	cin >> n >> m;
	vector<int> s(m),c(m);
	vector<int>v(n+1);
	rep(i,0,n+1)v[i] = -1;
	rep(i,0,m){
		cin >> s[i] >> c[i];
		if(v[s[i]] != -1 and v[s[i]] != c[i]){
			cout << -1 << endl;
			return 0;
		}
		v[s[i]] = c[i];
	}
	for(int i = pow(10, n-1) -1; i < pow(10, n); i++){
		// cout << i << endl;
		if(check(i, v)){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	long N; cin >> N;
	long* a = new long[N];
	long* b = new long[N];

	priority_queue<pair<long, long>> que; // 降順に出力

	for (long i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (long i = 0; i < N; i++) {
		cin >> b[i];
		if (b[i] < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		else if (b[i] > a[i]) {
			pair<long, long> p = pair<long, long>(b[i], i);
			que.push(p);
		}
	}

	long count = 0;

	while (que.size() > 0) {
		pair<long, long>p = que.top();
		que.pop();
		long i = p.second;
		long k = p.first;
		long left = b[(i + 1) % N];
		long right = b[(i + N - 1) % N];

		if (a[i] < k) {
			if (left + right > k - a[i]) {
				cout << -1 << endl;
				return 0;
			}

			long s = max(a[i], max(left, right));
			long r = (k - s) / (left + right);
			if (r > 0) {
				count += r;
				k -= (left + right) * r;
			}
			
			if (k == a[i]) {
				continue;
			}
			else if (k > a[i]) {
				if (k == left || k == right) {
					cout << -1 << endl;
					return 0;
				}
				k -= (left + right);
				count++;
			}

			b[i] = k;
			if (k < a[i]) {
				cout << -1 << endl;
				return 0;
			}
			else if (k > a[i]) {
				p.first = k;
				que.push(p);
			}
		}
	}

	cout << count << endl;

	return 0;
}


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

int main(){
  int n; cin>>n;
  int a[n];
  int even=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==0) even++;
  }
  long long ans=1;
  for(int i=0;i<n;i++) ans*=3;
  long long temp=1;
  for(int i=0;i<even;i++) temp*=2;
  cout<<ans-temp<<endl;
}

Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int r, D, x; cin >> r >> D >> x;
  REP(i, 10){
    x = r*x - D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int c;
  if(a>=13){
    c=b;
  }
  if(12>=a && a>=6){
    c=b/2;
  }
  if(5>=a){
    c=0;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int d,e;
    while (cin>>d>>e) {
        if (d==0&&e==0) {
            break;
        } else {
            double min=100000.0;
            double hoge,ans;
            for (int i=0;i<d;i++) {
                hoge=sqrt(i*i+(d-i)*(d-i));
                ans=abs(hoge-e);
                if (ans<min) {
                    min=ans;
                }
            }
            if (min==int(min)) {
                cout<<min<<endl;
            } else {
                printf("%.10f",min);
                cout<<endl;
            }
        }
    }
}



Measured memory_bytes: 3280
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        s: String,
    }

    let mut sc: Vec<char> = s.chars().collect();
    let cnt = 0;

    if s == "RSR" {
        println!("{}", 1);
        return;
    }

    println!("{}", sc.iter().filter(|&x| *x == 'R').count());
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9+7;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

lli mul(lli a,lli b){
  return (a%mod * b%mod)%mod;
}

lli add(lli a,lli b){
  return (a%mod + b%mod)%mod;
}

lli sub(lli a,lli b){
  return (a%mod-b%mod+mod)%mod;
}
 
//############################ENDOFTEMPLATE############################
vector<vi> adj(100005);
//vector<vi> adjb(100005);

vi link(100005);
vi sze(100005);

int find(int x){
  while(x!=link[x]) x = link[x];
  return x;
}

bool same(int a,int b){
  if(find(a)==find(b))
    return true;
  return false;
}

void unite(int a,int b){
  a = find(a);
  b = find(b);

  if(sze[a]<sze[b]) swap(a,b);
  sze[a]+=sze[b];
  link[b] = a;
}


void solve(){
  int n,m,k;
  cin>>n>>m>>k;

  for(int i = 1;i<=n;i++) 
    link[i] = i;

  for(int i = 1;i<=n;i++) 
    sze[i] = 1;


  vi deg(n+1);
  for(int i = 0;i<m;i++){
    int u,v;
    cin>>u>>v;
    deg[u]++;
    deg[v]++;

    if(!same(u,v))
      unite(u,v);
  }

  vector<int> ans(n+1);

  for(int i = 1;i<=n;i++){
    int h = find(i);
    //cout<<size[h]<<endl;
    ans[i] = sze[h]-deg[i]-1;
  }

  for(int i = 0;i<k;i++){
    int u,v;
    cin>>u>>v;
    if(same(u,v)){
      ans[u]--;
      ans[v]--;

    }
  }

  for(int i = 1;i<=n;i++){
    cout<<ans[i]<<" ";
  }







}

 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 7080
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List <Integer> H = new ArrayList <Integer> ();
		List <Integer> W = new ArrayList <Integer> ();
		
		int lastH = 0;
		int lastW = 0;
		do {
			lastH = stdIn.nextInt();
			lastW = stdIn.nextInt();
			
			H.add(lastH);
			W.add(lastW);
		} while (lastH != 0 || lastW != 0);
		
		for(int i = 0; i < H.size()-1; i++) {
			for(int j = 0; j < H.get(i); j++) {
				if(j % 2 == 0) {
					for(int k = 0; k < W.get(i); k++) {
						if(k % 2 == 0) {
							System.out.print("#");
						}
						else {
							System.out.print(".");
						}
					}
				}
				else {
					for(int k = 0; k < W.get(i); k++) {
						if(k % 2 == 0) {
							System.out.print(".");
						}
						else {
							System.out.print("#");
						}
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 25196
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

	map <char,bool> dir;
	dir['N'] = false;
	dir['S'] = false;
	dir['E'] = false;
	dir['W'] = false;

	for(int i=0; i<S.size(); i++){
		dir[S[i]] = true;
	}

	int count=0;
	for(auto a:dir){
		if(a.second == true)
			count++;
	}

	if(count%2 == 1)
		cout << "No" << endl;
	else{
		if(dir['N'] && dir['S'] && dir['E'] && dir['W']){
			cout << "Yes" << endl;
		}else{
			if(dir['N'] && dir['E'] || dir['N'] && dir['W']){
				cout << "No" << endl;
			}else if(dir['S'] && dir['E'] || dir['S'] && dir['W']){
				cout << "No" << endl;
			}else{
				cout << "Yes" << endl;
			}
		}
	}

	// cout << "N: " << dir['N'] << endl;
	// cout << "S: " << dir['S'] << endl;
	// cout << "E: " << dir['E'] << endl;
	// cout << "W: " << dir['W'] << endl;

}

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

void fnInput(vector<int> &rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
} 

void fnTrace(const vector<int> &cnrvnSort)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int> &rvnSort)
{
  for (int nSorting = 1; nSorting < rvnSort.size(); nSorting++)
  {
    int nTrg = rvnSort[nSorting];
    int nSorted = nSorting - 1;

    while (nSorted >= 0          &&
           nTrg  < rvnSort[nSorted])
    {
      rvnSort[nSorted + 1] = rvnSort[nSorted];
      nSorted--;
    }
    rvnSort[nSorted + 1] = nTrg;
    fnTrace(rvnSort);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnSort;

  fnInput(vnSort);
  fnTrace(vnSort);
  fnInsertionSort(vnSort);

  return 0;
}

Measured memory_bytes: 3100
package main
import "fmt"
func main() {
  var a,b int
  fmt.Scan(&a)
  fmt.Scan(&b)
  if a == 1 {
    a = 14
  }
  if b == 1 {
    b = 14
  }
  if a > b {
    fmt.Println("Alice")
  } else if a < b {
    fmt.Println("Bob")
  } else {
    fmt.Println("Draw")
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	string ss, t;
	cin >> ss >> t;
	bool ans = false;
	int tmpi = 0;
	rep(i, ss.size()-t.size()+1) {
		bool flag = true;
		rep(j, t.size()) {
			if (ss[i + j] != '?'
				and ss[i + j] != t[j]) {
				flag = false;
				j = t.size();
			}
		}
		if (flag) {
			tmpi = i;
			ans = true;
		}
	}
	if (ans) {
		rep(j, t.size()) {
			ss[tmpi + j] = t[j];
		}
		rep(i, ss.size()) {
			if (ss[i] == '?') {
				ss[i] = 'a';
			}
		}
		cout << ss << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<string>

using namespace std;
long long dis[100005];
long long vis[100005];
long long p[100005];
long long q[100005];

int main()
{
    //long long  dis[100005],vis[100005],p[100005],q[100005];
    long long  temp,before,i,n,a,c,you,zuo,ymax,zmax;
    cin>>n>>c;
    for(i=0,temp=zmax=zuo=before=0; i<n; i++)
    {
        cin>>dis[i]>>vis[i];
        temp=vis[i]+temp-(dis[i]-before);
        before=dis[i];
        if(zmax<temp-dis[i])
            zmax=temp-dis[i];
        q[i+1]=zmax;
        if(zuo<temp)
            zuo=temp;
    }
    q[0]=0;
    for(i=n-1,temp=ymax=you=0,before=c; i>=0; i--)
    {
        temp=vis[i]+temp-(before-dis[i]);
        before=dis[i];
        if(ymax<temp-(c-dis[i]))
            ymax=temp-(c-dis[i]);
        p[i]=ymax;
        if(you<temp+q[i])
            you=temp+q[i];
    }
    p[n]=0;
    for(i=0,temp=before=0; i<n; i++)
    {
        temp=vis[i]+temp-(dis[i]-before);
        before=dis[i];
        if(zuo<temp+p[i+1])
            zuo=temp+p[i+1];
    }
    a=zuo>you?zuo:you;
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>

int is_same(char hit[],char ticket[]){
  int i;
  int digit;

  for(i=7;i>=0;i--)
    if(hit[i]=='*')
      break;
  digit=i;

  for(i=7;i>digit;i--)
    if(hit[i]!=ticket[i])
      return 0;

  return 1;
}

int main(void){
  int i,j;
  int n,m;
  char hit[100][9];
  int prize[100];
  char ticket[1000][9];
  int cur;

  for(;;){
    scanf("%d%d",&n,&m);
    if(!n)
      break;

    for(i=0;i<n;i++)
      scanf("%s%d",hit[i],&prize[i]);
    for(i=0;i<m;i++)
      scanf("%s",ticket[i]);

    cur=0;
    for(i=0;i<m;i++){
      for(j=0;j<n;j++)
        if(is_same(hit[j],ticket[i])){
          cur+=prize[j];
          break;
        }
    }

    printf("%d\n",cur);
  }

  return 0;
}

Measured memory_bytes: 0
/*input
100 0
*/

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> a(105);
  rep(i, n) {
    int p;
    cin >> p;
    a[p] = 1;
  }
  int l = x, r = x;
  int ans = x;
  while (1) {
    if (a[l] == 0) {
      ans = l;
      break;
    }
    else if (a[r] == 0) {
      ans = r;
      break;
    }
    if (l >= 1) l--;
    if (r <= 100) r++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
ll n,k;
cin >> n >> k;
vector<ll>a(n);
ll ans = 0;
for(ll i=0;i<n;i++){
    cin >> a.at(i);
    ans+=a.at(i);
}
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
for(ll i=0;i<k;i++){
    if(i>=n)continue;
ans-=a.at(i);
}
cout <<ans<<endl;
}





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

#define DO(n) for ( int ____n = n; ____n-->0; )
#define REP(i, n) for (int i=0;i<n;++i)
#define FOR(i, a, b) for (int i=a;i<b;++i)
#define DWN(i, b, a) for (int i=b-1;i>=a;--i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define FOR_1(i, a, b) for (int i=a;i<=b;++i)
#define DWN_1(i, b, a) for (int i=b;i>=a;--i)
#define RST(A) memset(A, 0, sizeof(A))
#define FLC(A, x) memset(A, x, sizeof(A))

typedef double DB;

const int N = int(1e2) + 9, M = int(5e1) + 9;
DB p[N][M], sp[N][M], t[N], t0[N];
int n, m, l;

DB f(int i, DB ti){
    DB z = 1; REP(j, n) if (i != j){
        if (t0[j] + m*t[j] <= ti) return 0;
        REP(k, m+1) if (t0[j] + k*t[j] > ti){
            z *= (1 - sp[j][k]);
            break;
        }
    }
    return z;
}

int main(){

    while (~scanf("%d%d%d", &n, &m, &l)){

        RST(p); REP(i, n){
            int _p, v; scanf("%d%lf%d", &_p, &t[i], &v); t0[i] = (DB) l / v; DB pp = (DB) _p / 100;
            //cout <<" " << pp << endl;
            p[i][0] = 1; DO(m){
                DWN_1(j, m, 1) p[i][j] = p[i][j-1] * pp + p[i][j] * (1-pp);
                p[i][0] = p[i][0] * (1-pp);
            }

            REP_1(j, m) sp[i][j] = sp[i][j-1] + p[i][j-1];
        }

        REP(i, n){
            DB z = 0; REP(j, m+1) z += p[i][j] * f(i, t0[i] + t[i]*j);
            printf("%.9f\n", z);
        }
    }
}

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

const int N = 3005, mod = 1000000007;
int dp[2][N][2], n, m, ans;

void up(int &x, int y) { x += y - mod, x += x >> 31 & mod; }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m;
	int now = 0, lst = 1;
	for (int i = 0; i <= n; ++i)
		dp[now][i][i == 0] = 1;
	while (m--) {
		std::swap(now, lst), std::memset(dp[now], 0, sizeof dp[0]);
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j < 2; ++j) if (int v = dp[lst][i][j]) {
				if (i > 0) {
					up(dp[now][i][j || i == 1], v);
					up(dp[now][i - 1][j || i == 1], v);
				}
				if (i < n) {
					up(dp[now][i][j], v);
					up(dp[now][i + 1][j], v);
				}
			}
	}
	for (int i = 0; i <= n; ++i)
		up(ans, dp[now][i][1]);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int memo[100][100];
int n;
int card[100];

#define ABS(x) ((x) < 0 ? -(x) : (x))

int solve(int a, int b){
  if(a == b) return 0;
  if(b == a + 1 || (b == n-1 && a == 0)) return ABS(card[b] - card[a]);
  if(memo[a][b] != -1) return memo[a][b];

  int ret = 0;
  int bb = b;
  if(a > b) bb = n + b;
  for(int c = a; c < bb; c++)
    ret = max(ret, solve(a, c%n) + solve((c+1)%n, b) + ABS(card[a] - card[(c+1)%n]));

  return memo[a][b] = ret;
}

int main(){
  int cc = getInt();
  while( cc --> 0 ){
    int ans = 0;
    n = getInt();
    REP(i,n) card[i] = getInt();
    memset(memo,-1,sizeof(memo));
    REP(i,n) ans = max(ans, solve(i, (i+n-1)%n));
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 876
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N, K; cin >> N >> K;
  V H(N+1);
  rep(i, N) cin >> H[i+1];

  VVll dp(N+1, Vll(K+1, INFll));
  rep(k, K+1) dp[0][k] = 0;

  rep(i, N) rep(k, K+1) {
    rep(j, k+1) {
      if (i-j < 0) continue;
      chmin(dp[i+1][k], dp[i-j][k-j] + max(H[i+1] - H[i-j], 0));
    }
  }
  ll ans = INFll;
  rep(j, K+1) chmin(ans, dp[N-j][K-j]);
  cout << ans << endl;
  return 0;
}


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

const int MAXN = 20005;

ll n, q[MAXN], a[MAXN], b[MAXN];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        x--;
        q[x] = i;
    }

    for (int i = 0; i < n; ++i) {
        a[i] = 30000*i + 1 + q[i];
        b[i] = 30000*(n-i) + 1;
    }

    for (int i = 0; i < n; ++i)
        cout << a[i] << ' ';
    cout << endl;
    for (int i = 0; i < n; ++i)
        cout << b[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
	int n,flag=0;
	cin >> n ;
	if (n > 1) {
		string s;
		cin >> s;
		if (n % 2 == 1) {
			flag = 1;
		}
		else{
			for (int i = 0; i < (n / 2); i++) {
				if (s.at(i) != s.at(n / 2 + i)) {
					flag = 1;
					break;
				}
			}
		}
		}
	else {
		char s;
		cin >> s;
		flag = 1;
	}

	if (flag == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   vector<string>v={"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
   cin>>s;
  int ans;
   for(int i=0;i<7;i++)
   {
     if(v[i]==s)
       ans=i-0;
   }
  cout<<7-ans;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
int DP[110][200100];
int W[110],V[110];
signed main()
{
  int N,K;
  cin>>N>>K;
  for(int i=0;i<N;i++)
    cin>>W[i]>>V[i];
  for(int i=0;i<N;i++)
    for(int j=0;j<=K;j++)
      DP[i+1][j+W[i]]=max(DP[i+1][j+W[i]],DP[i][j]+V[i]),
  	  DP[i+1][j]=max(DP[i+1][j],DP[i][j]);
  int Ans=0;
  for(int i=0;i<=K;i++)
    Ans=max(Ans,DP[N][i]);
  cout<<Ans;
  return 0;
}

Measured memory_bytes: 156416