akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll x1,x2,x3,x4;
  ll y1,y2,y3,y4;
  cin>>x1>>y1>>x2>>y2;
  x3 = x2 - (y2-y1);
  y3 = y2 + (x2-x1);
  x4 = x3 - (x2-x1);
  y4 = y3 - (y2-y1);
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

}

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


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

int main() {
  int n;
  cin >> n;
  int b = n%10;

  if(b==3){
      cout << "bon" << endl;
  }

  else if(b==0 || b==1 || b==6 || b==8){
      cout << "pon" << endl;
  }

  else{
      cout << "hon" << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
typedef long long ll;

int main(){
  ll A;
  double B;
  std::cin >> A >> B;
  ll B100 = std::round(B * 100);
  ll resa = A * B100;
  std::cout << resa / 100 << std::endl;
  return 0;
}


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

using namespace std;

void solve() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  cout << (n < 3200 ? "red" : s) << endl;
}

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


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, k;
  cin >> n >> k;
  vll p(n);
  rep(i, n) {
    cin >> p[i];
  }

  sort(all(p));
  ll ans = 0;
  rep(i, k) {
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: usize,
    }
    println!("{}",n*(n + 1)/2);
}


Measured memory_bytes: 4352
#include <stdio.h>

void quicksort(int *array, int left, int right);

int main(void)
{
  int mfeet[10], i, *p;

  p = mfeet;
  for(i = 0; i < 10; i++)
    {
      scanf("%d", p + i);
    }

  quicksort(p, 0, 9);

  for(i = 0; i < 3; i++)
    {
      printf("%d\n", *(p + i));
    }

  return 0;
}

void quicksort(int *array, int left, int right)
{
  int pivot, k, tmp;
  if(left < right)
    {
      pivot = left;
      for(k = left + 1; k <= right; k++)
        {
          if(*(array + k) > *(array + left))
            {
              tmp = *(array + pivot + 1);
              *(array + pivot + 1) = *(array + k);
              *(array + k) = tmp;
              pivot++;
            }
        }
      tmp = *(array + left);
      *(array + left) = *(array + pivot);
      *(array + pivot) = tmp;
      quicksort(array, left, pivot - 1);
      quicksort(array, pivot + 1, right);
    }
  return;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abc131/tasks/abc131_a

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define FORR(i, m, n) for (int(i) = (n); (i) >= (m); i--)
#define rep(...) _overload3(__VA_ARGS__, FOR, REP, )(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, FORR, REPR, )(__VA_ARGS__)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  string S;
  cin >> S;
  bool easy = true;
  char l = S[0];
  rep(i, 1, 4)
  {
    if (S[i] == l)
      easy = false;
    l = S[i];
  }

  cout << (easy ? "Good" : "Bad") << '\n';

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> T;
    for(int i=0; i<N; i++){
        int c;
        cin >> c;
        T.push_back(c);
    }
    int M;
    cin >> M;
    vector<int> P, X;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        P.push_back(a-1);
        X.push_back(b);
}
// ドリンク1-Mまで順番にみる
for(int i=0;i<M;i++){
    int sum=0;
    // 分かりやすさのために例外処理をする問題番号と変更後の値を変数にとっておく
    int exception_index=P[i];
    int exception_time=X[i];
    // 問題1-Nまでみて合計を出す。例外処理の時は変更後の値を加算(本当は合計を先に出しておいて差分だけ足し引きするほうが早い)
    for(int j=0;j<N;j++){
        if(j ==exception_index){
            sum+=exception_time;
        }else{
            sum+=T[j];
        }
        
    }
    // 一行ずつ出力。vector<int>ansとか作って答えを格納しておいて最後にまとめて出力するのでもいいけど、これでもOK
    cout<<sum<<endl;
    sum =0;
}
}

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

typedef long long int ll;
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)

int N, M;
set<int> v[200001];
set<int>::iterator it[200001];
bool visited[200001] = { 0, };
int cnt;

void DFS(int node) {
	for (it[node] = v[node].begin(); it[node] != v[node].end(); it[node]++) {
		int next = *(it[node]);
		if (visited[next]) continue;
		visited[next] = 1;
		cnt++;
		DFS(next);
	}
}

int main() {
	FASTIO;
	int ans = 0;
	cin >> N >> M;
	FOR(i, 1, M) {
		int a, b;
		cin >> a >> b;
		v[a].insert(b);
		v[b].insert(a);
	}
	FOR(i, 1, N) {
		if (visited[i]) continue;
		cnt = 1;
		visited[i] = 1;
		DFS(i);
		ans = max(ans, cnt);
	}
	cout << ans;

	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  int r, k;

  Real x = 0,
       y = 0;
  Real theta = 0;

  loop {
    char comma;
    cin >> r >> comma >> k;
    if (!r && !k) break;
    x += r * cos(theta);
    y += r * sin(theta);
    theta += k * PI / 180;
  }

  cout << int(y) << endl;
  cout << int(x) << endl;

  return 0;
}

Measured memory_bytes: 1164
n =int(input())
s = input()
cir = ['']*n
judge = ''
def convertSW(x):
  if x == 'S':
    return 'W'
  elif x == 'W':
    return 'S'
for i in range(4):
  if i == 0:
    cir[0],cir[1] = 'S','S'
  elif i == 1:
    cir[0],cir[1] = 'S','W'
  elif i == 2:
    cir[0],cir[1] = 'W','W'
  else:
    cir[0],cir[1] = 'W','S'
  if (s[0] == 'o' and cir[0] == 'S') or (s[0] == 'x' and cir[0] == 'W'):
    judge = cir[1]
  else:
    judge = convertSW(cir[1])
  for j in range(2,n):
    if (s[j-1] == 'o' and cir[j-1] == 'S') or (s[j-1] == 'x' and cir[j-1] == 'W'):
      cir[j] = cir[j-2]
    else:
      cir[j] = convertSW(cir[j-2])
  if (s[-1] == 'o' and cir[-1] == 'S') or (s[-1] == 'x' and cir[-1] == 'W'):
    if (cir[0] == cir[-2]) and (judge == cir[-1]):
      print(''.join(cir))
      exit()
  else:
    if cir[0] == convertSW(cir[-2]) and (judge == cir[-1]):
      print(''.join(cir))
      exit()
print(-1)

Measured memory_bytes: 4212
#!/usr/bin/env python3
import sys
import math
import numpy as np

def get_distance(x, y, i, j):
    a = np.array([x[i], y[i]])
    b = np.array([x[j], y[j]])
    return np.linalg.norm(b-a)

def solve(N: int, x: "List[int]", y: "List[int]"):
    dist_list = []
    num_path = N*(N-1)//2
    for i in range(N):
        for j in range(N):
            if i == j:
                dist = 0
            else:
                dist = get_distance(x, y, i, j)
            dist_list.append(dist)
    K = math.factorial(N-1)*2
    ans = sum(dist_list)/2*K/math.factorial(N)
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12520
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

int n;
string s;

void solve() {
  // dp[i][j]: after figure out the result for the first n number, how many of them end with j
  vector<vector<int> > dp(n, vector<int>(n));
  dp[0][0] = 1;
  for (int i=1; i<n; ++i) {
    char c = s[i-1];
    int count = 0;
    if (c == '>') {
      for (int j=i; ~j; --j) {
        dp[i][j] = count;
        if (j > 0) {
          count = (count + dp[i-1][j-1]) % MOD;
        }
      }
    } else {
      for (int j=0; j<=i; ++j) {
        dp[i][j] = count;
        count = (count + dp[i-1][j]) % MOD;
      }
    }
  }
  int res = 0;
  for (int i=0; i<n; ++i) {
    res = (res + dp[n-1][i]) % MOD;
  }
  cout << (res + MOD) % MOD;
}

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

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<< (((abs(b-a)<=d && abs(c-b)<=d) || abs(c-a)<=d)? "Yes" : "No") <<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))
su = sum(a)
di = {}
for i in a:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1
for b, c in bc:
    if b not in di:
        print(su)
        continue
    su += (c-b)*di[b]
    print(su)
    if c in di:
        di[c] += di[b]
    else:
        di[c] = di[b]
    di[b] = 0

Measured memory_bytes: 31260
# この問題はbit全探索で解く
D, G = map(int, input().split())  # 1~Dのスコア帯, 目標の点数G
# 問題を受け取る
problems = [list(map(int, input().split())) for _ in range(D)]  # pi問存在している, ボーナスci点

# 状態を列挙する
all_status = []
for i in range(1 << D):
    tmp = []
    for j in range(D):
        if (i >> j) & 1:
            tmp.append(1)
        else:
            tmp.append(0)
    all_status.append(tmp)
# 状態の列挙が終わった
ans = float('inf')
for status in all_status:
    # status中の1が立っている部分の問題を全て解く
    score = 0
    solve_count = 0
    for i in range(len(status)):
        if status[i] == 1:
            # i番目の問題を全て解く
            score += (i+1)*100*problems[i][0] + problems[i][1]
            solve_count += problems[i][0]
    # 対象の問題を全部解き終えた
    if score >= G:
        ans = min(ans, solve_count)
    else:
        # 足りない問題を解く
        for i in reversed(range(len(status))):
            if status[i] == 0:  # 解いていない問題の中で一番ポイントが高いものを解く
                for j in range(problems[i][0]):  # 1問ずつ解く
                    score += (i+1)*100
                    solve_count += 1
                    if score >= G:
                        ans = min(ans, solve_count)
                        break
                break
print(ans)


Measured memory_bytes: 3188
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val t = StdIn.readLine().split(" ").map(_.toInt)
  val m = StdIn.readLine().toInt
  val px = (0 until m).map( _ => StdIn.readLine().split(" ").map(_.toInt))
  
  val r = px.map{ pi_xi => 
    (0 until n).foldLeft(0){ (acc, ti) =>
      acc + (if(ti == (pi_xi(0)-1)) pi_xi(1) else t(ti))
    }
  }
  
  r.foreach(println)
  
}


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

using namespace std;

using ll = long long;

void dfs(vector<vector<pair<int, ll>>> &g, vector<int> &color, int v, int cost) {
    if (color[v] != -1) return;

    if (cost % 2) color[v] = 0;
    else color[v] = 1;
    for (auto &&x : g[v]) {
        dfs(g, color, x.first, cost + x.second);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, ll>>> g(n);

    for (int i = 0; i < n - 1; i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--; v--;

        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    vector<int> color(n, -1);
    dfs(g, color, 0, 0);

    for (int x : color) {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 9600
n = gets.chomp.to_i
ab = []
n.times do
  ab << gets.chomp.split(' ').map(&:to_i)
end

ab.sort!{|x, y| x[1] <=> y[1]}

for i in 1..(ab.count-1)
  ab[i][0] = ab[i][0] + ab[i-1][0] 
end

ab.each do |ab|
  if ab[0] > ab[1]
    puts 'No'
    exit
  end
end

puts 'Yes'

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

int main(){
  
  int H, W, i, j;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  vector<int> wc(H, 0), hc(W, 0);
  
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      cin >> a[i][j];
    }
  }
  
  for(i=0; i<H; i++){
    for(j=0; j<W; j++){
      if(a[i][j] == '#') wc[i] = 1;
    }
  }
  
  for(i=0; i<W; i++){
    for(j=0; j<H; j++){
      if(a[j][i] == '#') hc[i] = 1;
    }
  }
  
  for(i=0; i<H; i++){
    bool flag = false;
    for(j=0; j<W; j++){
      if(wc[i] == 1 && hc[j] == 1){
        cout << a[i][j];
        flag = true;
      }
    }
    if(flag) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

void solve(){
	string ori;
	getline(cin,ori);
	char dic[26];
	for (int b = 0; b < 26; b++){
		for (int a = 1; a < 26; a++){
			if(gcd(a,26) != 1) continue;
			string s(ori);
			for (int i = 0; i < 26; i++){
				dic[i] = (a * i + b) % 26;
			}
			for (int i = 0; i < s.length(); i++){
				if(s[i] >= 'a' && s[i] <= 'z')
					s[i] = (dic[s[i] - 'a']) + 'a';
			}
			if(s.find("that") != string::npos || s.find("this") != string::npos){
				cout << s << endl; 
				return;
			}
		}
	}
}

int main()
{
	int t; cin>>t;
	string buf; getline(cin,buf);
	while(t--){
		solve();
	}
}

Measured memory_bytes: 0
#!/usr/bin/env python3

import math
def main():
    N,D = map(int, input().split())
    Dimention = [ [int(s) for s in input().split()] for i in range(N)]
    result = 0
    for i, y in enumerate(Dimention):
        for j, z in enumerate(Dimention):
            if i == j or i > j:
                continue
            kei = 0
            for num in range(D):
                kou = y[num] - z[num]
                kou = kou**2
                kei += kou
            if math.sqrt(kei).is_integer():
                result += 1
    print(result)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <algorithm>

namespace Proxy
{
    const int N=100000*2+5;
    int t, cnt;
    struct NODE
    {
        int knf;
        bool f;
    } a[N];

    inline bool cmp(NODE a, NODE b) { return a.knf > b.knf; }

    #define read(a) do{                                     \
        register char c;                                    \
        while(!isdigit(c=getchar())); a=c^48;               \
        while(isdigit(c=getchar())) a=(a<<1)+(a<<3)+(c^48); \
    } while(false)
} 

using namespace Proxy;

int main(void)
{
	int n, h; read(n); read(h);
	for(int i=1; i<=n; ++i)
	{
		++t; read(a[t].knf);
		++t; read(a[t].knf);
        //a[t++] isn't able!
		a[t].f=true;
	}
	std::sort(a+1, a+t+1, cmp);

	for(int i=1; i<=t; ++i)
	{
		if(a[i].f)
		{
			++cnt, h-=a[i].knf;
			if(h<=0) return printf("%d\n", cnt)&0;
		}
		else
		{
			cnt+=h/a[i].knf+(h%a[i].knf!=0);
            return printf("%d\n", cnt)&0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(A) A.begin(),A.end()
using vi=vector<int>;
using vii=vector<vi>;
signed main(){
  int N,K;
  cin>>N>>K;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  int ans=MOD;
  rep(i,K-1,N) ans=min(ans,A[i]-A[i-K+1]);
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
using System;

class MyClass
{
    static void Main(string[] args)
    {
        bool[] submit = new bool[30];
        for (int i = 0; i < 30; i++)
        {
            submit[i] = false;
        }
        for (int i = 0; i < 28; i++)
        {
            int num = int.Parse(Console.ReadLine()) - 1;
            submit[num] = true;
        }
        for (int i = 0; i < 30; i++)
        {
            if (!submit[i])
            {
                Console.WriteLine(i + 1);
            }
        }
    }
}


Measured memory_bytes: 19932
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a1sum, a2sum, ans = 0, 0, 0
a2sumall = sum(a2)
for i in range(n):
    a1sum += a1[i]
    a2sum += a2[i]
    ans = max(ans, a1sum + a2sumall - a2sum + a2[i])
print(ans)


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    set<int> se;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        se.insert(A[i]);
    }

    cout << se.size() - (N - se.size()) % 2 << endl;
}

Measured memory_bytes: 5376
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
     
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n; i++){
        cout << a[n - i] << " ";
    }
    cout << a[0] << endl;
}

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

#define ll long long
#define w cout
#define e endl

int main() {
    string s;
    cin >> s;
    vector<ll> ans;
    int one = 0;
    for(int i = 0 ; i < s.size() ; i ++ ) {
        int x = s[i] - '0';
        if(x == 1) {
            one++;
        } else {
            break;
        }
    }
    ll k;
    cin >> k;
   // w << one << endl;
    if(k <= one) {
        w << 1;
    } else {
        w << s[one];
    }
}

Measured memory_bytes: 256
// ... (Triple Dots)

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int k;string s;
    cin>>k>>s;
    if(s.size()<=k)cout<<s<<nnn;
    else cout<<s.substr(0,k)<<"..."<<nnn;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  
  int hugs = 0;
  for (int i = 0; i < s.size()/2; i++)
	if (s[i] != s[s.size() - i - 1])
	  hugs++;
		
  cout << hugs << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))
#define PLATEAU 0
#define BASIN 1
#define HILLSIDE 2
#define PEAK 3
#define PIT 4

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int a[100005];
int res[5]; 	// 高原、盆地、山腹、峰、窪地の順
int main()
{
	memset (a, 0, sizeof (a ) );
	memset (res, 0, sizeof (res ) );
	ios_base::sync_with_stdio(0);
	int N; cin >> N;
	rep (i, N ) cin >> a[i];

	bool up = false,  down = false, flat = false;
	for (int i = 1; i < N; i++ ){
		if (a[i-1] < a[i] ){
			if (flat && up ) { res[HILLSIDE]++; up = false; }
			if (flat && down ){ res[BASIN]++; down = false; }
			if (!flat && down ){ res[PIT]++; }
			up = true; down = false;
			flat = false;
		}else
		if (a[i-1] > a[i] ){
			if (flat && down ) { res[HILLSIDE]++; down = false; }
			if (flat && up ) { res[PLATEAU]++; up = false; }
			if (!flat && up ){ res[PEAK]++; }
			up = false, down = true;
			flat = false;
		}else{ // if (a[i-1] == a[i] )
			flat = true;
		} // end if
	} // for
	rep (i, 5 ) cout << res[i] << (i != 5 - 1 ? ' ' : '\n');

	return 0;
}


Measured memory_bytes: 1596
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner =new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int menseki=a*b;
        int syu=2*a+2*b;
        System.out.println(menseki+" "+syu);
        scanner.close();
    }
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    double ans = 0;
    cin >> n;
    while(n--)
    {
        double x;
        cin >> x;
        ans += 1/x;
    }
    cout << fixed << setprecision(9) << 1/ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define CARDS 1024

void swap(char *p,char *q){
	char tmp;
	tmp = *p;
	*p = *q;
	*q = tmp;
}
void swap_int(int *p,int *q){
	int tmp;
	tmp = *p;
	*p = *q;
	*q = tmp;
}

void Bubblesort(char Bubblecards[][3],const int n){
	int i,j;
	int Stablechecker[CARDS][2];
	for(i=0;i<n;i++){
		Stablechecker[i][0]=Bubblecards[i][1]-'0';
		Stablechecker[i][1]=i;
	}
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){
			if(Bubblecards[j][1]-'0'<Bubblecards[j-1][1]-'0'){
				swap_int(&Stablechecker[j][0],&Stablechecker[j-1][0]);
				swap_int(&Stablechecker[j][1],&Stablechecker[j-1][1]);
				swap(&Bubblecards[j][0],&Bubblecards[j-1][0]);
				swap(&Bubblecards[j][1],&Bubblecards[j-1][1]);
			}
		}
	}
	for(i=0;i<(n-1);i++){
	printf("%s ",Bubblecards[i]);
	}
	printf("%s\n",Bubblecards[n-1]);
	
	int check=0;
	for(i=0;i<(n-1);i++){
		if(Stablechecker[i][0]==Stablechecker[i+1][0]){
			if(Stablechecker[i][1]>Stablechecker[i+1][1]) check=-1;
		}
	}
	if(check==0) printf("Stable\n");
	else printf("Not stable\n");
}



void Selectionsort(char Selectioncards[][3],const int n){
	int i,j,minj;
	int Stablechecker[CARDS][2];
	for(i=0;i<n;i++){
		Stablechecker[i][0]=Selectioncards[i][1]-'0';
		Stablechecker[i][1]=i;
	}
	for(i=0;i<(n-1);i++){
		minj=i;
		for(j=i+1;j<n;j++){
			if(Stablechecker[j][0]<Stablechecker[minj][0]){
			minj = j;
			}
		}

				swap_int(&Stablechecker[i][0],&Stablechecker[minj][0]);
				swap_int(&Stablechecker[i][1],&Stablechecker[minj][1]);
				swap(&Selectioncards[i][0],&Selectioncards[minj][0]);
				swap(&Selectioncards[i][1],&Selectioncards[minj][1]);

	}
	for(i=0;i<(n-1);i++){
	printf("%s ",Selectioncards[i]);
	}
	printf("%s\n",Selectioncards[n-1]);
	int check=0;
	for(i=0;i<(n-1);i++){
		if(Stablechecker[i][0]==Stablechecker[i+1][0]){
			if(Stablechecker[i][1]>Stablechecker[i+1][1]) check=-1;
		}
	}
	if(check==0) printf("Stable\n");
	else printf("Not stable\n");
}

int main(void){
	int i,j,n;
	char cards[CARDS][3];
	char Bubblecards[CARDS][3];
	char Selectioncards[CARDS][3];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%s",cards[i]);
	}
	memcpy(Bubblecards,cards,CARDS);
	memcpy(Selectioncards,cards,CARDS);
	
	Bubblesort(Bubblecards,n);
	Selectionsort(Selectioncards,n);
	
	return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int money;
  cin >>money;
  int count;
  if(money%1000==0)
    count =(money/1000)-1;
  else {count =money/1000;}
  cout << (count+1)*1000-money<<endl;
}  


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_set>
using namespace std;

int main()
{
	int a;
	cin >> a;

	vector< int > vec( a );
	unordered_set<int> set;

	for( auto &it : vec )
	{
		cin >> it;
		set.insert( it );
	}

	


	cout << set.size() << endl;

	return 0;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int l, r; cin >> l >> r;
  int d; cin >> d;

  cout << (r / d) - ((l - 1) / d) << endl;
}


Measured memory_bytes: 3556
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int D, G;
int minTotal = INF;
vector<pair<int, int>> questions;
vector<pair<int, int>> totals;

int co = 0;
int calc(int bit) {
  int count = 0;
  int sum = 0;
  for (int i = 0; i < D; i++) {
    if ((bit & (1 << i)) != 0) {
      sum += questions[i].first * 100 * (i + 1);
      sum += questions[i].second;
      count += questions[i].first;
    }
  }
  if (sum >= G) return count;

  for (int j = D - 1; j >= 0; j--) {
    if ((bit & (1 << j)) == 0) {
      for (int i = 0; i < questions[j].first - 1; i++) {
        sum += 100 * (j + 1);
        count += 1;

        if (sum >= G) return count;
      }
    }
  }

  return INF;
}

int main(void) {
  cin >> D >> G;
  questions.resize(D);
  totals.push_back(make_pair(0, 0));
  for (int i = 0; i < D; i++) {
    cin >> questions[i].first >> questions[i].second;
  }

  for (int bit = 0; bit < (1 << D); bit++) {
    minTotal = min(minTotal, calc(bit));
  }

  cout << minTotal << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	long long a; scanf ("%lld", &a);
	int now = 26, sum = 26, p = 1;
	while (sum < a) now *= 26, sum += now, ++p;
	if (sum == a) {		
		for (int i = 1; i <= p; ++i) putchar ('z');
		return 0;
	} //676 //1000000000000001
	a -= (sum - now);
//	printf ("%lld %lld\n", sum , a);
	for (int i = p; i >= 1; --i) {
		int now = pow (26, i - 1);
		int k = a / now, q = a % now;
	//	if (i == 4) printf ("666 %lld %lld\n", k, q);
		if (!q) --k, q = now;
		
		putchar ('a' + k); a = q;	
	} return 0;
}

Measured memory_bytes: 4196
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;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()
const int INF = 1<<30;

int main() {
  int n, m;
  while(cin >> n >> m, n||m) {
    double hi[n][n];
    REP(i,n)
      REP(j,n)
      cin >> hi[i][j];
    double dp[m][n];
    REP(i,n)
      dp[0][i] = 1;
    REP(i,m-1) {
      REP(j,n) {
        double ma = 0;
        REP(k,n) {
          ma = max(ma, dp[i][k] * hi[k][j]);
        }
        dp[i+1][j] = ma;
      }
    }
    double ma = 0;
    REP(i,n)
      ma = max(ma, dp[m-1][i]);
    printf("%.2f\n", ma);
  }
}

Measured memory_bytes: 1064
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	b := ReadString()
	switch b {
	case "A":
		fmt.Println("T")
	case "T":
		fmt.Println("A")
	case "C":
		fmt.Println("G")
	case "G":
		fmt.Println("C")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1840
/*
 * Click `Run` to execute the snippet below!
 */
 
import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next(); //Input String
    int N = s.length(); //Size of the input string    
    //Case 1: 101010101010
    int caseoneanswer = 0;
    for(int i = 1; i<=N; i++){
      if(i%2 == 1 && s.charAt(i-1) == '0'){
        caseoneanswer++; 
      } 
      if(i%2 == 0 && s.charAt(i-1) == '1'){
        caseoneanswer++; 
      }
    }
    //Case 2: 01010101010
    int casetwoanswer = 0;
    for(int i = 1; i<=N; i++){
      if(i%2 == 1 && s.charAt(i-1) == '1'){
        casetwoanswer++;
      }
      if(i%2 == 0 && s.charAt(i-1) == '0'){
        casetwoanswer++; 
      }
    }
    System.out.println(Math.min(caseoneanswer, casetwoanswer));
  }
}


Measured memory_bytes: 39644
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i, n){
        cin >> x[i];
    }

    rep(i, m){
        cin >> y[i];
    }

    sort(x.begin(), x.end(), greater<int>());
    sort(y.begin(), y.end());

    if(x[0] < y[0] and x[0] > X and y[0] <= Y){
        cout << "No War" << endl;
        return 0;
    }

    cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=300;
inline int read(){
	int x=0; char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}

int n;
char s[N];
int mp[N],ch[N],sig=62;
struct node{
	char s[N]; int len; node(){memset(this,0,sizeof(node));}
	node(char *c,int y){memcpy(s,c,sizeof(s));len=y;}
	inline bool friend operator < (node a,node b){return a.len>b.len;}
};
inline bool check(node &x){
	printf("? %s\n",x.s);
	fflush(stdout);
	return read()==n-x.len;
}
inline void ins(char *s,int pos,char x,int len){
	for(int i=len;i>pos;--i) s[i]=s[i-1]; s[pos]=x;
}
inline node merge(node &x,node &y){
	node ans; ans=x;
	for(int i=0,j=0;i<y.len;++i){
		++ans.len;
		node rec=ans;
		for(int pos=j;pos<ans.len;++pos){
			ins(ans.s,pos,y.s[i],ans.len);
			if(!check(ans)) ans=rec;
			else{j=pos+1;break;}
		}
	}
	return ans;
}

priority_queue<node>Q;
int main(){
	for(int i=0;i<10;++i) ch[i]='0'+i;
	for(int i=10;i<36;++i) ch[i]='a'+i-10;
	for(int i=36;i<62;++i) ch[i]='A'+i-36;
	for(int i=0;i<62;++i) mp[ch[i]]=i;
	n=233;
	for(int i=0;i<62;++i){
		printf("? %c\n",ch[i]);
		fflush(stdout);
		n=min(n,read());
	}
	++n;
	for(int i=0;i<62;++i){
		printf("? ");
		for(int j=0;j<n;++j) printf("%c",ch[i]); puts(""); fflush(stdout);
		int w=n-read(); if(!w) continue; memset(s,0,sizeof(s));
		for(int j=0;j<w;++j) s[j]=ch[i]; Q.push(node(s,w));
	}
	while(Q.size()>1){
		node x=Q.top(); Q.pop();
		node y=Q.top(); Q.pop();
		Q.push(merge(x,y));
	}
	printf("! %s\n",Q.top().s);
	return 0;
}

Measured memory_bytes: 3792
/*Flamenco Sketches*/
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
//#define FayeValentine 
void dbg(){cerr<<NL;}template<typename H,typename... T> void dbg(H h,T... t){cerr<<' '<<h;dbg(t... );}
#ifdef  FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg(__VA_ARGS__)
#else
#define debug(...) 
#endif

void absinthe() {
	int n; cin >> n;
	vector<ll>a(n); rep(i, 0, n) { cin >> a[i];} 
	ll gcd = 0;
	for(int i = 0; i < n; i++) gcd =  __gcd(a[i], gcd);	
	cout << abs(gcd) << NL;
}
 
int main(){
  //freopen("input.txt", "r", stdin);
  async();
  int __t = 1; //cin >> __t;
  for(int __c = 1; __c <=__t; __c++) {
    //cout << "Case #" << __c << ": "; 
    absinthe();
  }
}  

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

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

		long a[] = new long[n + 1];


		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();

		}
		Arrays.sort(a);
		long ans = 1;
		int cd = 0;
		for (long i = a[2]; i >=1; i=i-1) {
			for (int j = 1; j <= n; j++) {
				if (a[j] % i != 0) {
					cd++;
					//System.out.println("cd" + i + " " + cd);
				}
				if(cd>=2){
					break;
				}
			}
			//System.out.println("sd#"+cd);


				if (cd <=1) {
					ans = i ;
					break;
				}
			cd = 0;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 60388
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    //aはソート済み
    int64_t Min = 10000000000;
    rep(i,n){
        int64_t c,ac;
        if(i==0){
            c = a[n-1]-a[0];
            ac = a[i]-a[i+1];
        }
        else if(i==n-1){
            c = a[i-1]-a[i];
            ac = a[n-1]-a[0];
        }
        else{
            c = a[i-1]-a[i];
            ac = a[i]-a[i+1];
        }
        if(c<0){
            c += k;
        }
        if(ac<0){
            ac += k;
        }
        //cout<<c<<" "<<ac<<endl;
        Min = min(Min,min(c,ac));
    }
    cout<<Min<<endl;
}

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

int main() {
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if (S == U) {
        cout << A - 1 << ' ' << B << endl;
    } else {
        cout << A << ' ' << B - 1 << endl;
    }
}


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

int main() {
 string S, T; 
  cin >> S >> T;
  int N;
  N = S.size();
  
  if(N+1==T.size()) {
   
    for (int i=0;i<N;i++) {  
     
      if(S.at(i)!=T.at(i)) {
     cout << "No" << endl;
     break;
     }
      else if(i<N-1) {
        continue;
      }
 
    else if(i==N-1&&S.at(N-1)==T.at(N-1)) {
      cout << "Yes" << endl;
    }
  }
  }
  
  else {
    cout << "No" << endl;
  }    
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 


int main() 
{ 
    fastio
    ull n, k;
    cin>>n>>k;

    if(n<=k)
    {
        cout<<min(n, k-n)<<endl;
        return 0;
    }
    else
    {
        cout<<min(n%k, k-(n%k))<<endl;
    }
}


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

using namespace std;

typedef long long ll;

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

	int n;
	while(cin >> n)
	{
		vector<ll> a(n), b(n);
		for(int i=0; i<n; i++)
			cin >> a[i] >> b[i];
		ll moves = 0;
		for(int i=n-1; i>=0; i--)
		{
			a[i] += moves;
			ll extra = a[i] % b[i];
			if(extra)
				moves += b[i] - extra;
		}
		cout << moves << '\n';
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll

int32_t main(){
    FAST
    int n, k; cin >> n >> k;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int ans = 1e9 + 5;
    sort(arr, arr + n);
    for(int i = 0; i + k - 1 < n; i++){
        ans = min(ans, arr[i + k - 1] - arr[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4404
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let f (acc, a0, inc) a =
  let b, i = if a0 = a then true, inc
    else if a0 < a then inc >= 0, if inc = 0 then 1 else inc
    else inc <= 0, if inc = 0 then -1 else inc in
  if b then acc, a, i else acc + 1, a, 0
let c, _, _ = Array.fold_left f (0, a_s.(0), 0) a_s
let _ = Printf.printf "%d\n" @@ c + 1

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

#define X first
#define Y second

using namespace std;

const int N=100;
int n,k;

int cnt;
pair<int,int> Edge[N*N/2];

void Print()
{
	printf("%d\n",cnt);
	for(int k=1;k<=cnt;k++)
		printf("%d %d\n",Edge[k].X,Edge[k].Y);
}

int main()
{
	scanf("%d %d",&n,&k);
	int num=(n-1)*(n-2)/2;
	if(k>num)
	{
		printf("-1\n");
		return 0;
	}

	for(int i=2;i<=n;i++)
		Edge[++cnt]=make_pair(1,i);
	if(num>k)
	{
		for(int i=2;i<=n;i++)
			for(int j=i+1;j<=n;j++)
			{
				Edge[++cnt]=make_pair(i,j);
				if( --num == k )
				{
					Print();
					return 0;
				}
			}
	}
	Print();
	return 0;
}



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

int main()
{
  string S; cin >> S;
  sort(S.begin(), S.end());
  if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define loop(i,a,b) for(ll i=a; i<b; i++)
#define rloop(i,a,b) for(ll i=a; i>b; i--)
#define all(var) var.begin(), var.end()
#define eloop(var) for(auto elem : var)
#define debug(x) cerr<<#x<<" ----> "<<x<<endl;
#define TC ll tt; cin>>tt; while(tt--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define MOD 1000000007
#define MAX 100005
typedef long long ll;
typedef long double ld;

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

    // TC
    {
        ll a,b,v,w,t;
        cin>>a>>v>>b>>w>>t;
        bool fg=false;
        ll a1=a, b1=b;
        if(a<b){
            if(a+t*v >= b+t*w) {
                fg=true;
            }
        }
        else {
            if(a1-t*v<=b1-t*w)
                fg=true;
        }
        if(fg)
            cout<<"YES\n";
        else
            cout<<"NO\n";

    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
struct line
{
	int s,t;
	long long val;
	bool operator <(line y) const
	{
		return val>y.val;
	}
}a[100001];
long long val[100001],sum[100001];
int rk[100001];
int fa[100001];
inline int findx(int x)
{
	if(x!=fa[x])
		return findx(fa[x]);
	return x;
}
bool v[100001];
int belong[100001];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=n;i++)
		scanf("%lld",&val[i]);
	for(i=1;i<=m;i++)
		scanf("%d%d%lld",&a[i].s,&a[i].t,&a[i].val);
	sort(a+1,a+1+m);
	for(i=1;i<=n;i++)
	{
		fa[i]=i;
		sum[i]=val[i];
	}
	for(i=m;i>=1;i--)
	{
		int fx=findx(a[i].s);
		int fy=findx(a[i].t);
		if(fx!=fy)
		{
			v[i]=true;
			if(rk[fx]<rk[fy])
			{
				int t=fx;
				fx=fy;
				fy=t;
			}
			fa[fy]=fx;
			sum[fx]+=sum[fy];
			if(rk[fx]==rk[fy])
				rk[fx]++;
			belong[i]=fy;
		}
	}
	long long ans=0;
	for(i=1;i<=m;i++)
	{
		int fx=findx(a[i].s);
		if(a[i].val>sum[fx])
		{
			ans++;
			if(v[i])
			{
				sum[fx]-=sum[belong[i]];
				fa[belong[i]]=belong[i];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, m; cin >> n >> m;
	if (n > 1 && m > 1) {
		cout << (n * m + 1) / 2 << endl;
	} else  {
		cout << 1 << endl;
	}
	return 0;
}

/*


*/

Measured memory_bytes: 256