akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
constexpr int calc(int n, int c1, int c2, int s1, int s2, int options[],
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return diff1 * c1 - diff2 * c2 + s1 - s2;
}

static unsigned int myrand() {
	static unsigned int x=192047155,y=392751284,z=194681846,w=193571838;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return w=(w^(w>>19))^(t^(t>>8));
}

constexpr bool check(int diff, int time) {
  return diff >= 0 || rand() >= (-diff) * (clock()-time) * 1.4;
}

int main() {
  int n;
  cin >> n;
  int c[26], last[26], s[n][26], op[n];
  
  for (int i = 0; i < 26; ++i) {
    cin >> c[i];
    last[i] = -1;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  int total(0);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1), max_score(-1e9);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    op[i] = test;
    last[test] = i;
  }
  
  // stochastic
  time_t time = clock();
  while ((clock()-time)<=1.97*CLOCKS_PER_SEC) {
    if (rand() & 1) {
      int dd(rand() % n), ot(op[dd]), tt;
      do { tt = rand() % 26; } while (ot == tt);
      
      op[dd] = tt;
      int ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot], op, dd, tt, ot);
      
      if (check(ns,time)) {
        total += ns;
      } else {
        op[dd] = ot;
      }
    } else {
      int dd1(rand() % n), ot1(op[dd1]), dd2, ot2;
      do { dd2 = rand() % n; ot2 = op[dd2]; } while (ot1 == ot2);
      
      op[dd1] = ot2;
      int ns1 = calc(n, c[ot2], c[ot1], s[dd1][ot2], s[dd1][ot1], op, dd1, ot2, ot1);
      op[dd2] = ot1;
      int ns2 = calc(n, c[ot1], c[ot2], s[dd2][ot1], s[dd2][ot2], op, dd2, ot1, ot2);
      
      if (check(ns1+ns2,time)) {
        total += ns1 + ns2;
      } else {
        op[dd1] = ot1;
        op[dd2] = ot2;
      }
    }
  }
  
  for (const int& i: op) cout << i + 1 << endl;
  
  return 0;
}


Measured memory_bytes: 3676
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, input().rstrip('\n').split()))
    s = []
    b_cnt = 0
    for i in range(h):
        st = list(str(input().rstrip('\n')))
        s.append(st)
        b_cnt += st.count("#")

    ql = [[0, 0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(int)
    fq[0, 0] = 1
    m_cost = 10 ** 10
    while True:
        if len(ql) != 0:
            cost, x, y = ql.popleft()
            if x == h - 1 and y == w - 1:
                m_cost = min(m_cost, cost)
            for x, y in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
                if 0 <= x < h and 0 <= y < w:
                    if (x, y) not in fq and s[x][y] == ".":
                        ql.append([cost+1, x, y])
                        fq[x, y] += 1
        else:
            break
    if m_cost == 10 ** 10:
        print(-1)
    else:
        print(h * w - b_cnt - m_cost - 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40944
List=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
# print(List)
k = int(input())
print(List[k - 1])

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

typedef long long ll;
using namespace std;

struct UnionFind {
    int par[1000001]; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) { //最初は全てが根であるとして初期化 
        for(int i = 0; i < N; i++) { 
          par[i] = i; 
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

bool isRoot[100001];

int main(void) {
  int n, m; cin >> n >> m;

  UnionFind tree(n);

  for (int i = 0; i < m; i++) {
    int x, y, z; cin >> x >> y >> z;
    tree.unite(x, y);
  }

  //cout << "aaa" <<endl;

  for (int i = 0; i < n; i++) {
    isRoot[i] = false;
  }
  //cout << "aaa" <<endl;


  for (int i = 0; i < n; i++) {
    isRoot[tree.root(i)] = true;
    //cout << tree.root(i) << endl;
  }

  //cout << "aaa" <<endl;

  int cnt = 0;
  for (int i = 0; i < n; i++) 
    cnt += isRoot[i] ? 1 : 0;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 2432
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v : Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let ans = std::cmp::min(v[0] * v[1], v[2]);
    println!("{}", ans);
}


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

int main(void){
    int a,b=0;
    cin >> a;
    if((a/10) == 9)b += 1;
    else if((a%10) == 9)b += 1;
    if(b > 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

char next_anima(char who, char ans, char form){
	bool res = ((form == 'S')? true : false);
	if(who == 'S'){
		if(ans == 'x')res = !res;
	}else{
		if(ans == 'o')res = !res;
	}
	return ((res)? 'S' : 'W');
}

int main(){
	int N;
	string s;
	cin >> N >> s;
	rep(i,2){
		rep(j,2){
			vector<char> ans(N);
			if(i == 0)ans[0] = 'S';
			else ans[0] = 'W';
			if(j == 0)ans[1] = 'S';
			else ans[1] = 'W';
			for(int k = 1; k < N-1; ++k){
				ans[k+1] = next_anima(ans[k], s[k], ans[k-1]);
			}
			if(ans[0] == next_anima(ans[N-1], s[N-1], ans[N-2]) && ans[1] == next_anima(ans[0], s[0], ans[N-1])){
				for(auto x:ans)cout << x;
				cout << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


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


using namespace std;

#ifdef CLION
ifstream ifs("/home/kyuridenamida/CLionProjects/project/input.txt");
#define cin ifs
#define scanf DONT_USE_SCANF
#endif

typedef long long ll;

template<typename T>
class CumulativeSum {
    const int n;
    std::vector<T> sum_data;
public:
    CumulativeSum(vector<T> data) : n(data.size()) {
        sum_data.resize(n + 1);
        for (int i = 0; i < n; i++) {
            sum_data[i + 1] = sum_data[i] + data[i];
        }
    }

    // 区間 [l, r) 番目の範囲の和を求める．(l = r のときは 0 を返す．)
    T sum(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        return sum_data[r] - sum_data[l];
    }
};

typedef CumulativeSum<ll> CumSum;

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

    vector<ll> p(N);

    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]++;
        p[i] *= 2;
    }
    CumSum s(p);
    ll ans = 0;
    for (int i = 0; i <= N - K; i++) {
        ans = max(ans, s.sum(i, i + K));
    }
    printf("%.10lf\n", ans / 4.0);

}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 2e5 + 5;
int v[N];
void solve() {
    int n;
    cin >> n;
    for (int i=0;i<n;++i) cin >> v[i];
    sort(v, v+n);
    int need = n-1;
    LL ans = 0;
    for (int i=n-1;i>=0;--i) {
        if (need > 0) {
            need--;
            ans += v[i];
        }
        if (i < n-1 && need > 0) {
            need--;
            ans += v[i];
        }
    }
    cout << ans << '\n';
} 

int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 4440
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int log(int a, int b) {
    int i = 0;
    int A = a;
    while(a<b) {
        a*=2;
        i++;
    }
    return i;
}
signed main() {
    long double n,k;cin >> n >> k;
    long double ans = 0;
    rep1(i, n) {
        ans+=(1/n)*pow(0.5,log(i,k));
    }
    cout << fixed << setprecision(10) << ans << endl;
    // cout << log(2,10) << endl;
    return 0;
}

Measured memory_bytes: 4292
n = input()
length0 = len(n)
ans = 0

for h in range(3,length0 + 1):
    if h == length0:
        N = n
    else:
        N = "9"*h

    length = len(N)

    dp = [[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(length+1)]
    dp[0][0][0][0][0] = 1

    s1 = [3,5,7]
    for i in range(length):
        max_digit = int(N[i])
        for flag_less in range(2):
            for flag_siti in range(2):
                for flag_go in range(2):
                    for flag_san in range(2):
                        range_digit = s1 if flag_less else [i for i in s1 if i <= max_digit]
                        for d in range_digit:
                            flag_less_next = 0
                            flag_siti_next = 0
                            flag_go_next = 0
                            flag_san_next = 0
                            if flag_less == 1 or d < max_digit:
                                flag_less_next = 1
                            if flag_siti == 1 or d == 7:
                                flag_siti_next = 1
                            if flag_go == 1 or d == 5:
                                flag_go_next = 1
                            if flag_san == 1 or d == 3:
                                flag_san_next = 1
                            dp[i+1][flag_less_next][flag_siti_next][flag_go_next][flag_san_next] += dp[i][flag_less][flag_siti][flag_go][flag_san]

    ans += (dp[length][0][1][1][1] + dp[length][1][1][1][1])

print(ans)


Measured memory_bytes: 39664
n = int(input())
a = [0,1,2,3,4,5,6,7,8,9]
count = 9
idx = 1
while count < n:
  pick = a[idx]
  if pick % 10 == 0:
    a.extend([pick*10+0, pick*10+1])
    count += 2
  elif pick % 10 == 9:
    a.extend([pick*10+8, pick*10+9])
    count += 2
  else:
    lsn = pick % 10
    a.extend([pick*10+lsn-1, pick*10+lsn, pick*10+lsn+1])
    count += 3
  idx += 1
print(a[n])


Measured memory_bytes: 7260
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll x;
    cin >> x;
    PRINT(1 - x);
    return 0;
}

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

using namespace std;

const int MAX_N = 1e2 + 10;
int numbers[MAX_N];

int main () {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int N, ans = INT_MAX;
    scanf("%d", &N);
    int a = 1, b = N - 1;
    while(a != N && b != 0) {
        int sum = 0;
        int first = a, second = b;
        while(first != 0) {
            sum += first % 10;
            first /= 10;
        }
        while(second != 0) {
            sum += second % 10;
            second /= 10;
        }
        ans = min(ans, sum);
        a += 1;
        b -= 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9012337203685477580
using ll = long long;
using namespace std;

struct thing {
    int a, b, c, d;
    friend ostream& operator<<(ostream& os, thing t) {
        return os << t.a+1 << " " << t.b+1 << " " << t.c+1 << " " << t.d+1;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    int cnt = 0;
    vector<vector<int>> A(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A[i][j];
        }
    }
    vector<thing> B;
    for (int i = 0; i < H; i++)
    {
        if (H % 2 == 0) {
            for (int j = 0; j < W; j++)
            {
                if (A[i][j] % 2 == 1) {
                    //奇数
                    if (j == W - 1) {
                        //右端
                        if (i != H - 1) {
                            //下に移す
                            A[i][j]--;
                            A[i + 1][j]++;
                            B.push_back(thing{i,j,i + 1,j});
                        }
                    }
                    else {
                        //その他
                        A[i][j]--;
                        A[i][j + 1]++;
                        B.push_back(thing{i,j,i,j+1});
                    }
                }
            }
        }
        else {
            for (int j = W - 1; j >= 0; j--)
            {
                if (A[i][j] % 2 == 1) {
                    //奇数
                    if (j == 0) {
                        //左端
                        if (i != H - 1) {
                            //下に移す
                            A[i][j]--;
                            A[i + 1][j]++;
                            B.push_back(thing{i,j,i + 1,j});
                        }
                    }
                    else {
                        //その他
                        A[i][j]--;
                        A[i][j - 1]++;
                        B.push_back(thing{i,j,i,j - 1});
                    }
                }
            }
        }
    }
    cout << B.size() << endl;
    for (int i = 0; i < B.size(); i++)
    {
        cout << B[i] << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 5236
M,D = map(int,input().split())
if D<=21:
    print(0)
else:
    D10 = D//10
    D1 = D%10
    cnt = 0
    for i in range(2,D10+1):
       for j in range(2,10):
           if i*10 + j > D:
               break
           if 1 <= i*j <= M:
               cnt += 1
    print(cnt)           

Measured memory_bytes: 3060
n, k = map(int, input().split())
a = list(map(int, input().split()))
a2 = {}
for i in a:
    a2.setdefault(i, 0)
    a2[i] += 1
a3 = list(a2.values())
a3.sort()
if len(a3) <= k:
    print(0)
else:
    num = 0
    for i in range(len(a3) - k):
        num += a3[i]
    print(num)

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

int main()
{
    long long A,B,K,result;
    cin >> A >> B >> K;

    if(A<K){
        K -= A;
        A=0;
    }else{
        A -= K;
        K = 0;
    }


    if(B<K){
        K -= B;
        B=0;
    }else{
        B -= K;
        K = 0;
    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
T intceil(T a, T b) {
    return (a + (b - 1)) / b;
}

signed main() {
    INIT;
    map<char, string> mp;
    cin >> mp['a'] >> mp['b'] >> mp['c'];
    for (auto &x : mp)
        reverse(ALL(x.second));
    dump(mp);
    char now = 'a';
    while (mp[now].size() != 0) {
        char tmp = mp[now].back();
        mp[now].pop_back();
        now = tmp;
    }
    cout << char('A' + now - 'a') << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define fi first
#define se second

struct UnionFind{
	vector<int> ran, par;
	void init(int n){
		for(int i = 0;i < n;i++){
			par.push_back(i);
			ran.push_back(0);
		}
	}
	
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y){
		x = find(par[x]);
		y = find(par[y]);
		if(x == y)return;
		if(ran[x] < ran[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(par[x] == par[y])ran[x]++;
		}
	}
	
	bool same(int x, int y){
		return find(par[x]) == find(par[y]);
	}
};

int main(){
	vector<P> xs, ys;
	vector<PP> c;
	UnionFind UF;
	int n;
	scanf("%d", &n);
	UF.init(n);
	
	for(int i = 0;i < n;i++){
		int x, y;
		scanf("%d%d", &x, &y);
		xs.push_back(P(x, i));
		ys.push_back(P(y, i));
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	
	for(int i = 1;i < n;i++){
		int d = xs[i].fi-xs[i-1].fi;
		c.push_back(PP(d, P(xs[i].se, xs[i-1].se)));
	}
	for(int i = 1;i < n;i++){
		int d = ys[i].fi-ys[i-1].fi;
		c.push_back(PP(d, P(ys[i].se, ys[i-1].se)));
	}
	sort(c.begin(), c.end());
	
	int ans = 0;
	for(int i = 0;i < c.size();i++){
		int d = c[i].fi;
		int x = c[i].se.fi, y = c[i].se.se;
		if(UF.same(x, y) == 0){
			UF.unite(x, y);
			ans += d;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 7916
def main():
    N,A,B  = map(int, input().split()) 
    while True:
        if(A+1==B):
            print('Borys')
            return
        A = A+1
        if(B-1==A):
            print('Alice')
            return
        B = B-1


if __name__ == '__main__':
    main()


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

void uniq(vector<double> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

double sq(double x) {
	return x * x;
}

bool intersect(double x1, double y1, double x2, double y2, double cx, double cy, double r) {
	if (x1 <= cx && cx <= x2 && y1 - r < cy && cy < y2 + r) return true;
	if (y1 <= cy && cy <= y2 && x1 - r < cx && cx < x2 + r) return true;
	if (sq(x1 - cx) + sq(y1 - cy) < sq(r)) return true;
	if (sq(x1 - cx) + sq(y2 - cy) < sq(r)) return true;
	if (sq(x2 - cx) + sq(y1 - cy) < sq(r)) return true;
	if (sq(x2 - cx) + sq(y2 - cy) < sq(r)) return true;
	return false;
}

int main() {
	double r, n;
	while (cin >> r >> n) {
		if (r == 0) break;

		vector<double> xl(n), xr(n), h(n);
		vector<double> xs({-99, 99}), ys({0, 99});
		for (int i=0; i<n; ++i) {
			cin >> xl[i] >> xr[i] >> h[i];
			xs.push_back(xl[i]);
			xs.push_back(xr[i]);
			ys.push_back(h[i]);
		}
		uniq(xs);
		uniq(ys);

		int seg_h = ys.size() - 1;
		int seg_w = xs.size() - 1;
		vector<vector<bool>> seg(seg_h, vector<bool>(seg_w, false)); // 遮られている区画はtrue

		for (int i=0; i<n; ++i) {
			//          (x2, y2) 
			// (x1, y1)
			int y1 = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();
			int y2 = lower_bound(ys.begin(), ys.end(), h[i]) - ys.begin();
			int x1 = lower_bound(xs.begin(), xs.end(), xl[i]) - xs.begin();
			int x2 = lower_bound(xs.begin(), xs.end(), xr[i]) - xs.begin();
			for (int j=y1; j<y2; ++j) {
				for (int k=x1; k<x2; ++k) {
					seg[j][k] = true;
				}
			}
		}

		auto is_blocked = [&](double y) {
			for (int i=0; i<seg_h; ++i) {
				for (int j=0; j<seg_w; ++j) {
					if ( ! seg[i][j] && intersect(xs[j], ys[i], xs[j+1], ys[i+1], 0, y, r)) {
						return false;
					}
				}
			}
			return true;
		};
		
		double lo = -r;
		double hi = 21;
		while (hi - lo > 1e-6) {
			double mid = (lo + hi) / 2.0;
			if (is_blocked(mid)) {
				lo = mid;
			} else {
				hi = mid;
			}
		}
		printf("%.4f\n", hi + r);
	}
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const ll N=1e3+5;

ll n,m,mem[N][N],mod=1e9+7;

vector<int>adj[N];

char ch[N][N];

ll dp(int i,int j)
{
    if (i==n&&j==m)return 1;
    if (mem[i][j]!=-1)return mem[i][j];
    ll ans=0;
    if (i+1<=n&&ch[i+1][j]=='.'){ans+=dp(i+1,j);ans%=mod;}
    if (j+1<=m&&ch[i][j+1]=='.'){ans+=dp(i,j+1);ans%=mod;}
    return mem[i][j]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> n >> m;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        cin >> ch[i][j];
    }
    cout << dp(1,1)%mod << endl;
}


Measured memory_bytes: 9216
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("vowel");
    } else {
        println!("consonant");
    }
}

fn main() {
    let c = read::<String>().chars().nth(0).unwrap();

    yn(c=='a' || c=='e' || c=='i' || c=='o' || c=='u');
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool is[1000050];
const int maxn = 1000000;
int prm[1000050], tot;
typedef long long ll;
int n;
void shai() {
	int i;
	for(i = 2; i <= maxn; ++i) is[i] = 1;// cerr << 1 << endl;
	int j, t;
	for(i = 2; i <= maxn; i++) {
		if(is[i]) prm[++tot] = i; 
		//	if(i <= 50) cerr << i << endl;
			for(j = 1; j <= tot; ++j) {
				t = i * prm[j];
				if(t > maxn) break;
				is[t] = 0;
				if(i % prm[j] == 0) break;
			}	
	}
} 
int main() {
	shai();//cout << 1 << endl;
	int i;
	//for(i = 1; i <= 30; ++i) cout << prm[i] << endl; 
	cin >> n;
	ll ans, an;
	int j, t, cnt;
	an = 0;
	for(i = 1; i <= n - 1; ++i) {
		ans = 1;
		t = i;
		for(j = 1; (j <= tot) && (prm[j] * prm[j] <= i); ++j) {
			cnt = 0;
			//if(is[j]) continue;
			while(!(t % prm[j])) {
				++cnt;
				t /= prm[j];
			}
			if(cnt > 0) ans = ans * (cnt + 1);
		}
		if(t > 1) ans = ans * 2;
		//if(i <= 15) cout << i << " " << ans << endl;
		an += ans;
	}
	cout << an;
	return 0;
}

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

int main(){
  ll A,B,K;cin>>A>>B>>K;
  if(A-K>=0)cout<<A-K<<" "<<B<<"\n";
  else cout<<0<<" "<<(max((ll)0,B+A-K))<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s;
  cin >> s;
  int maxi = 0;
  rep (i, s.size()) {
    int start = i;
    while (i < s.size() && (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')) ++i;
    maxi = max(maxi, i - start);
  }
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> s(n);
    vector<int> r(n,10000);
    int sum=0;
    int smin=100;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
        if(s[i]%10!=0){
            r[i]=s[i];
        }
    }
    sort(r.begin(),r.end());
    int ans=sum;
    if(ans%10==0){
        ans=ans-r[0];
        if(ans%10==0){
            ans=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
I=[[*map(int,input().split())]for _ in[0]*N]
C=[0]*-~W
for i in range(1,N+1):
 v,w=I[~-i]
 for j in range(W,w-1,-1):
  t=v+C[j-w]
  if t>C[j]:C[j]=t
print(C[W])


Measured memory_bytes: 5920
n, K = map(int,input().split())
xarr = []
yarr = []
src = []
for _ in range(n):
    x, y = map(int,input().split())
    src.append([x,y])
    xarr.append(x)
    yarr.append(y)

xarr.sort()
yarr.sort()
ans = float('inf')
for i in range(n):
    for j in range(i + 1, n):
        for k in range(n):
            for l in range(k + 1, n):
                cnt = 0
                for m in range(n):
                    if src[m][0] >= xarr[i] and src[m][0] <= xarr[j] and src[m][1] >= yarr[k] and src[m][1] <= yarr[l]:
                        cnt += 1
                if cnt >= K:
                    ans = min((xarr[i]-xarr[j])*(yarr[k]-yarr[l]), ans)

print(ans)

Measured memory_bytes: 48476
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i,i+2):
        dif = b[i] - a[j]
        if dif<0:
            ans+= b[i]
            b[i]=0
            a[j]=-dif
        elif dif >=0:
            ans+= a[j]
            b[i] = dif
            a[j] = 0
print(ans)

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


int main()
{ int h,w;cin>>h>>w;char a[h][w];int p=1000000007;
for (int i=0;i<h;i++)for (int j=0;j<w;j++)cin>>a[i][j];
int ans[h][w];ans[0][0]=1;
for (int i=1;i<h;i++)
{   
    if (a[i][0]=='#')
    ans[i][0]=0;
    else
    ans[i][0]=ans[i-1][0];
}
for (int i=1;i<w;i++)
{   
    if (a[0][i]=='#')
    ans[0][i]=0;
    else
    ans[0][i]=ans[0][i-1];
}
for (int i=1;i<h;i++)
for (int j=1;j<w;j++)
    if (a[i][j]=='#')ans[i][j]=0;
    else ans[i][j]=(ans[i-1][j]+ans[i][j-1])%p;
cout<<ans[h-1][w-1];
 return 0;   
}

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

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

#define MAX_N 200005
#define INF 1000000000000000000 // 2^63 

int N;
ll a[MAX_N];

ll get_max(int l,int r,int n){
	if(n==0) return 0;
	if(l>=r || l<0 || r>N){
		// cout << "error l:" << l << " r:"<< r << " n:" << n << endl;
		return 0;
	} 
	if(r-l==1){
		// if(n!=1) cout << "error l:" << l << " r:"<< r << " n:" << n << endl;
		return a[l];
	}
	if(r-l==2){
		// if(n!=1) cout << "error l:" << l << " r:"<< r << " n:" << n << endl;
		return max(a[l],a[l+1]);
	}
	if(2*n-1 == r-l){
		ll sum=0;
		for(int i=l;i<r;i+=2){
			sum += a[i];
		}
		return sum;
	}
	int c=(l+r)/2;
	if((r-l)%2){
		ll sum1 = get_max(l,c,n/2) + get_max(c+1,r,n-n/2);
		ll sum2 = get_max(l,c,n-n/2) + get_max(c+1,r,n/2);
		ll sum3 = get_max(l,c-1,n/2) + get_max(c,r,n-n/2);
		ll sum4 = get_max(l,c+1,n-n/2) + get_max(c+2,r,n/2);
		return max(max(sum1,sum2),max(sum3,sum4));
	}else{
		ll sum1 = get_max(l,c-1,n/2) + get_max(c,r,n-n/2);
		ll sum2 = get_max(l,c,n-n/2) + get_max(c+1,r,n/2);
		return max(sum1,sum2);
	}
}

int main() {
    cin >> N;
	rep(i,N) cin >> a[i];
	cout << get_max(0,N,N/2) << endl;
    return 0;
}


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

int main(){
  vector<vector<int> > graph;
  int n;

  cin >> n;
  graph.resize(n);
  for(int i=0;i<n;i++){
    graph[i].resize(n);
    for(int j=0;j<n;j++){
      graph[i][j]=0;
    }
  }

  for(int i=0;i<n;i++){
    int idx,times;

    cin >> idx >> times;
    for(int j=0;j<times;j++){
      int path;

      cin >> path;
      graph[idx-1][path-1]=1;
    }
  }

  for(int i=0;i<n;i++){
    cout << graph[i][0];
    for(int j=1;j<n;j++){
      cout << " " << graph[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3128
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;

public class Main {

	final static int INF = Integer.MAX_VALUE;

	public static void main(String[] args) {
		Locale.setDefault(Locale.ENGLISH);
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		solve(in, System.out);
		in.close();
	}

	protected static void solve(Scanner in, PrintStream out) {
		int n = in.nextInt();
		int[][] a = new int[n][3];
		for (int j = 0; j < n; j++) {
			a[j][0] = in.nextInt();
			a[j][1] = in.nextInt();
			a[j][2] = in.nextInt();
		}
		int ret = solveLine(n, a);
		out.printf(Locale.ENGLISH, "%s%n", ret);
	}

	private static int solveLine(int n, int[][] ar) {
		int[][] dp = new int[n + 2][3];
		dp[0][0] = dp[0][1] = dp[0][2] = 0;
		for (int i = 0; i < n; i++) {
			dp[i+1][0] = max(dp[i][1],dp[i][2]) + ar[i][0];
			dp[i+1][1] = max(dp[i][0],dp[i][2]) + ar[i][1];
			dp[i+1][2] = max(dp[i][0],dp[i][1]) + ar[i][2];
		}
		return max(dp[n][0], max(dp[n][1],dp[n][2]));
	}

}

Measured memory_bytes: 99496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
void dfs(int num, int var, string res) {
  if (num == n) {
    cout << res << endl;
    return;
  }
  rep(i, var) {
    if (i < var-1)
      dfs(num+1, var, res+char('a'+i));
    else
      dfs(num+1, var+1, res+char('a'+i));
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  dfs(0, 1, "");
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int N;
int A[100000];
int P[100002];
int Q[100002];
int saidai = 0;

int kouyaku(int a, int b);

signed main(void) {
    cin >> N;
    rep(i,N){
        cin >> A[i];
    }

    P[0] = 0;
    Q[0] = 0;
    Rep(i,1,N){
        P[i] = kouyaku(P[i-1], A[i-1]);
        Q[i] = kouyaku(Q[i-1], A[N-i]);
    }

    rep(i,N){
        int a = kouyaku(P[i], Q[N-1-i]);
        if(a > saidai){
            saidai = a;
        }
    }

    cout << saidai << endl;

    return 0;
}

int kouyaku(int a, int b){
    if(a==0 || b==0){
        return a+b;
    }

    int c= a%b;
    return kouyaku(b,c);
}

Measured memory_bytes: 2560
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, m, res = 1, ile[N];
bool moze[N];

int main()
{
    init_ios();
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    	ile[i] = 1;
    moze[1] = true;
    while (m--) {
    	int x, y;
    	cin >> x >> y;
    	++ile[y];
    	--ile[x];
    	if (moze[x]) {
    		if (!moze[y]) {
    			moze[y] = true;
    			++res;
    		}
    		if (ile[x] == 0) {
    			moze[x] = false;
    			--res;
    		}
    	}
    }
    cout<<res<<"\n";
}

Measured memory_bytes: 768
#include <vector>
#include <iostream>
#include <cmath>

#define llint long long int

int main(void){

  llint s;
  std::cin >> s;

  llint a = std::ceil(std::sqrt(s));
  llint b = (s+a-1)/a;

  std::cout << a << " " << b << " " << 0 << " " << ((a*b)==s?b:b-1) << " " << a-((a*b)-s) << " 0" << std::endl;

  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

Measured memory_bytes: 3600
S = input()

mod = 10**9+7
N = len(S)

s = S[-1]
dp = [0]*13
if s=="?":
    dp[:10] = [1]*10
else:
    dp[int(s)] = 1

dig = 1
for c,s in enumerate(S[:-1][::-1],1):
    dig = dig*10%13
    dp2 = [0]*13
    if s=="?":
        for i in range(10):
            for j,n in enumerate(dp):
                dp2[(i*dig+j)%13] += n
    else:
        i = int(s)
        for j,n in enumerate(dp):
            dp2[(i*dig+j)%13] += n
    dp = [n%mod for n in dp2]
print(dp[5])

Measured memory_bytes: 43756
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n;
  cin >> n;
  int f[n][10];
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> f[i][j];
    }
  }
  long long p[n][11];
  for(int i=0;i<n;i++){
    for(int j=0;j<11;j++){
      cin >> p[i][j];
    }
  }
  int joi[10];
  int c[n];
  long long ans = -10000000000;
  long long temp;
  for(int i=1;i<(1 << 10);i++){
    temp = 0;
    for(int j=0;j<10;j++){
      if(i & (1 << j)) joi[j] = 1;
      else joi[j] = 0;
    }
    for(int j=0;j<n;j++){
      c[j] = 0;
      for(int t=0;t<10;t++){
        if(f[j][t] == 1 && joi[t] == 1) c[j] += 1;
      }
      temp += p[j][c[j]];
    }
    ans = max(ans,temp);

  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 110

typedef struct __stack_ {
  int stack[MAX];
  int top;
} __stack_t;
__stack_t S;

void initialize() {
  S.top = 0;
}

int isEmpty() {
  return 0 == S.top;
}


int isFull() {
  return S.top >= (MAX - 1);
}

void push(const int x) {
  if (isFull()) {
    printf("Error: Overflow\n");
    return;
  }
  S.stack[++S.top] = x;
}

int pop() {
  if (isEmpty()) {
    printf("Error: Underflow\n");
    return 0;
  }
  return S.stack[S.top--];
}

void showStack() {
  int i;
  for (i = 1; i < S.top; i++) {
    printf("%d ", S.stack[i]);
  }
  printf("%d\n", S.stack[S.top]);
}

int main() {
  char c[128];
  while (scanf("%s", c) != EOF) {
    if (isdigit(c[0])) {
      push(atoi(c));
    } else {
      int a, b;
      a = pop();
      b = pop();
      switch (c[0]) {
        case '+':
          push(a + b);
          break;
        case '-':
          push(b - a);
          break;
        case '*':
          push(a * b);
          break;
        default:
          return 1;
          break;
      }
    }
//    showStack();
  }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 548
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        System.out.println(Math.max(0,Math.min(B,D)-Math.max(A,C)));
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    ll n,m,x,y;
    cin>>n>>m>>x>>y;
    ll ar[n];
    for(ll i=0;i<n;++i){cin>>ar[i];}
    sort(ar,ar+n);
    ll br[m];
    for(ll i=0;i<m;++i){cin>>br[i];}
    sort(br,br+m);

    if(ar[n-1]<br[0]&&br[0]>x&&br[0]<=y){
        cout<<"No War";
    }
    else{cout<<"War";}

    return (0);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        Integer[] a = new Integer[N];
        
        for(int i = 0; i < N ; i++){
            a[i] = sc.nextInt();
        }
        
        Arrays.sort(a, Collections.reverseOrder());
        
        int result = 0;
        int box = 0;
        
        for(int i = 0; i < N ; i++){
            if(i == 0){
                box = a[i];
                result++;
            }else{
                
                if(box > a[i]){
                    result++;
                    box = a[i];
                }else{
                    box = a[i];
                }
            }
        }
        System.out.println(result);
    }
    
}


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

typedef vector<int> vec;
typedef vector<vec> mat;

int INF = 1 << 28;
int N;
void solve() {
    vector<string> str(N);
    for (auto& i : str) cin >> i;

    vector<bool> use(N, true);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i != j && str[i].find(str[j]) != string::npos) use[j] = false;
        }
    }

    auto tmp_str = str;
    str.resize(0);
    for (int i = 0; i < N; i++) if (use[i]) str.push_back(tmp_str[i]);

    int n = str.size();
    mat num(n, vec(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            for (int k = 1, s1 = str[i].size(), s2 = str[j].size(); k < s1 && k < s2; k++) {
                if (string(str[i].end() - k, str[i].end()) == string(str[j].begin(), str[j].begin() + k))
                    num[i][j] = k;
            }
        }
    }

    mat dp(1 << n, vec(n, INF));
    for (int i = 0; i < n; i++) dp[1 << i][i] = str[i].size();
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j) == 0) continue;
            for (int k = 0; k < n; k++) {
                if (j == k || i & (1 << k)) continue;
                dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] - num[j][k] + (int)str[k].size());
            }
        }
    }

    int ans = INF;
    for (int i = 0; i < n; i++)
        ans = min(ans, dp[(1 << n) - 1][i]);
    cout << ans << endl;
}

int main() {
    while (cin >> N, N) solve();

    return 0;
}

Measured memory_bytes: 4348
big = int(input())
mid = int(input())
small = int(input())
input_money = int(input())

cnt = 0
for i in range(big+1):
    for j in range(mid+1):
        for k in range(small+1):
            if input_money==(500*i + 100*j + 50*k):
                cnt += 1

print(cnt)

Measured memory_bytes: 3060
def main():
    N = int(input())
    A = map(int, input().split())

    A = sorted(A, reverse=True)
    alice, bob = 0, 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            alice += a
        else:
            bob += a

    ans = alice - bob
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>
int H,W,N,K,pow2[5010];
int solve(int u,int d,int l,int r,int know,int&val){
	if(know==-1){
		printf("? %d %d %d %d\n",u,l,d-1,r-1);
		fflush(stdout);
		int tmp;
		scanf("%d",&tmp);
		val=tmp;
		know=tmp;
	}
	if(!know)return 0;
	int tmp;
	if(d-u==1&&r-l==1)return pow2[u*W+l];
	if(d-u>r-l){
		int ans0=solve(u,u+d>>1,l,r,-1,tmp),no;
		return (ans0+solve(u+d>>1,d,l,r,know-tmp,no))%K;
	}
	int ans0=solve(u,d,l,l+r>>1,-1,tmp),no;
	return (ans0+solve(u,d,l+r>>1,r,know-tmp,no))%K;
}
int main(){
	scanf("%d%d%d%d",&H,&W,&N,&K);
	for(int i=pow2[0]=1;i<=5000;i++)pow2[i]=(pow2[i-1]<<1)%K;
	int tmp=0;
	printf("! %d\n",solve(0,H,0,W,-1,tmp));
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main{

	int N;
	int A;
	int B;
	int C;
	int imihu;
	int [] list;

	public static void main (String[] args) {

		Main main = new Main();
		main.solve();
	}

	private void solve() {

		Scanner sc = new Scanner (System.in);

		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();

		 list = new int [N];

		for (int index=0; index<N; index++) {
			list[index]=sc.nextInt();
		}

		imihu = (int) Math.pow(10, 9);

		int answer = calculate (0,0,0,0);

		System.out.println(answer);
	}

	private int calculate (int nowTake, int aTake, int bTake, int cTake) {

		if (nowTake==N) {
			int min = aTake;
			if (min>bTake) {
				min=bTake;
			}
			if (min>cTake) {
				min=cTake;
			}
			if (min>0) {
				return Math.abs(A-aTake)+Math.abs(B-bTake)+Math.abs(C-cTake)-30;
			} else {
				return imihu;
			}
		}
		int first = calculate (nowTake+1, aTake, bTake, cTake);
		int second = calculate (nowTake+1,aTake+list[nowTake],bTake,cTake)+10;
		int third = calculate (nowTake+1,aTake,bTake+list[nowTake],cTake)+10;
		int fourth = calculate (nowTake+1,aTake,bTake,cTake+list[nowTake])+10;

		int min=first;
		if (min>second) {
			min=second;
		}
		if (min>third) {
			min=third;
		}
		if (min>fourth) {
			min=fourth;
		}
		return min;
	}
}

Measured memory_bytes: 22864
#include<bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main()
{
	int n, num;
	cin>>n;
	for(int i=0; i<n;i++)
	{
		mp.insert({i+1,0});
	}
	for(int i=0; i<n-1;i++)
	{
		cin>>num;
		mp[num]++;
	}
	for(int i=0; i<n;i++)
	{
		cout<<mp[i+1]<<"\n";
	}
}

Measured memory_bytes: 13012
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		if( a!=1 && b!=1 ){
			ans = 1;
		}
		if( a!=2 && b!=2 ){
			ans = 2;
		}
		if( a!=3 && b!=3 ){
			ans = 3;
		}
		System.out.println(ans);
	}
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
//ループ, 0からn-1までのn個

#define rep1(i, n) for(int i = 1; i <= (n); i++)
//ループ, 1からnまでのn個

#define co(x) cout << (x) << "\n"
//出力

#define cosp(x) cout << (x) << " "
//?
#define ce(x) cerr << (x) << "\n"
//?
#define cesp(x) cerr << (x) << " "
//?
#define pb push_back
//最後に追加
//void push_back(const T& x); // (1)
//void push_back(T&& x);      // (2) C++11
#define mp make_pair
//make_pair


//メイン関数
//デバッグ
//;と:のミス
//;を忘れずに
//,と.のミス

//structの作成
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	//入力
	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll> > v(N);

	for (ll i = 0; i < N; i++) {
		cin >> v[i].first >> v[i].second;
	}
	//入力終わり
	

	// priceをキーに昇順でソート
	sort(v.begin(), v.end());

	//最安×本数を計算して、足していき、望みの本数になったら終了
	//答えの数字
	ll honsu_all = 0;
	ll price_all = 0;
	ll tmp_honsu;
	ll tmp_price;

	ll j = 0;
	while (j < N) {
		tmp_honsu = v[j].second;
		tmp_price = v[j].first;
		honsu_all += tmp_honsu;
		price_all += tmp_honsu * tmp_price;
		//honsu_all>Mのときは、差額分をそのときのpriceで割って、その余りが0なら商、
		//余りが0以外なら商＋1本を追加
		if (honsu_all >= M) {
			price_all -= (honsu_all - M) * tmp_price;
		break;
		}
		j++;
	}

	

	
//	co(kotae);
	co(price_all);
	return 0;
}

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

vector<vector<bool>> S;

void paint(int Y,int H,int X,int W){
    for(int h=Y;h<H;++h){
        for(int w=X;w<W;++w){
            S[h][w] = false;
        }
    }
}

int main(){
    int W,H,N,X,Y,A,ans=0;
    cin>>W>>H>>N;
    S.assign(H,vector<bool>(W,true));
    
    for(int i=0;i<N;++i){
        cin>>X>>Y>>A;
        switch(A){
            case 1: paint(0,H,0,X);break;
            case 2: paint(0,H,X,W);break;
            case 3: paint(0,Y,0,W);break;
            case 4: paint(Y,H,0,W);break;
        }
    }
    
    for(int h=0;h<H;++h){
        for(int w=0;w<W;++w){
            if(S[h][w]) ++ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    count=0
    n, s = tuple([int(x) for x in raw_input().split(" ")])

    if n==0 and s==0:
        break
    
    for i in range(1, n-1):
        for j in range(i+1, n):
            r = s - (i + j)
            if j < r and r <= n:
                count+=1
    print count

Measured memory_bytes: 4212