akhauriyash/Code-Regression huggingface dataset:
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    ll ans=0;
    READV(N);
    FORI(i,1,N+1)
    {
        READV(x);
        if(i%2==1)
        {
            if(x%2==1)
            {
                ans++;
            }
        }
    }
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
vector<bool> is_prime;
ll const MAX = 1e6;

void Sieve(size_t max){
    if(max+1 > is_prime.size()){
        is_prime.resize(max+1,true);
    }
    is_prime[0] = false;
    is_prime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(is_prime[i])
            for(size_t j=2; i*j<=max; ++j)
                is_prime[i*j] = false;
}

int main() {
  ll x;
  cin >> x;

  Sieve(MAX);
  ll ans = 0;
  while(!ans) {
    if (is_prime[x]) ans = x;
    x++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int dp[105][N], wt[105], val[105];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, w;
	cin >> n >> w;
	for(int i = 1; i <= n; i++){
		cin >> wt[i] >> val[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= w; j++){
			if(j - wt[i] >= 0){
				dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - wt[i]]);
			}else{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[n][w];
}

Measured memory_bytes: 79360
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  int x = abs(a - b);
  bool ans = false;
  if ((n - 1) * c <= x && x <= (n - 1) * d) {
    ans = true;
  }
  if (x < (n - 1) * c) {
    for (int i = 0; i < n; i++) {
      int t = i * c - (n - 1 - i) * d;
      if (t <= x && x <= t + (n - 1) * (d - c)) {
        ans = true;
      }
    }
  }
  if (ans == true) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n, k;
    cin >> n >> k;
    long long t = 0;
    long long d = 0;
    for(int i = 1; i <= n;i++)
    {
        if(i %k == k / 2)
        {
            d++;
        }
        if(i%k ==0)
            t++;
    }
    if(k % 2)
    {
        cout << t * t * t;
    }
    else
        cout << t * t * t + d  * d * d;
}


Measured memory_bytes: 764
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
int		cnt;

int		main(void)
{
	int		N;
	double	A;
	double	ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A, ans += 1 / A;
	cout << 1 / ans << endl;
}


Measured memory_bytes: 256
a, b, c, x, y = STDIN.gets.split(' ').map(&:to_i)

max = x < y ? y : x

min = 10**9
0.step(max * 2, 2) do |i|
  num_a = (x - i / 2 < 0) ? 0 : x - i / 2
  num_b = (y - i / 2 < 0) ? 0 : y - i / 2
  num_c = i
  
  price = a*num_a + b*num_b + c*num_c
  
  # p "num_a #{num_a}, num_b #{num_b} num_c: #{num_c} price #{price}"
  if (a*num_a + b*num_b + c*num_c < min)
    min = price
  end
end

puts min

Measured memory_bytes: 1788
#include<cstdio>

using namespace std;

int main(){
    char s[101];
    scanf("%s", s);
    int s_size;
    for(int i = 0; i < 101; i++){
        if (s[i] == 0){
            s_size = i;
            break;
        }
    }
    for(int i = 0; i < s_size; i++){
        printf("x");
    }
    puts("");
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <vector>

int P[200000];  // オリジナルの順列

int main() {
  // 情報を読み取る
  size_t N = 0;  // 要素の個数
  size_t K = 0;  // 並び替える要素の個数
  std::cin >> N >> K;

  // 列の値を読み取る
  for (size_t i = 0; i < N; ++i) {
    std::cin >> P[i];
  }

  // ソート範囲内が既にソート済みかどうかを調べる
  std::vector<bool> sorted(N - K + 1);
  for (size_t i = 0, j = 0, count = 0; i < sorted.size(); ++i) {
    // 降順になっている要素を累積的に数える
    while (j < i + K - 1) {
      if (P[j] > P[j + 1]) count++;
      j++;
    }

    sorted[i] = (count == 0);

    // 先頭の要素を取り除く
    if (P[i] > P[i + 1]) count--;
  }

  // ソート範囲が重なる場合を調べる
  std::set<int> sub;  // ソートされた値を取り出すためのコンテナ
  bool orig = sorted.front();  // オリジナルの順列パターンを含むか
  size_t result = orig ? 0 : 1;  // パターンの個数。0
  for (size_t i = 0, j = 0; i < N - K; ++i) {
    // ソート範囲を累積的にソートする
    while (j < i + K + 1) {
      sub.insert(P[j]);
      j++;
    }

    // 重複しないパターンかどうかを調べる
    if (*sub.cbegin() != P[i] || *--sub.cend() != P[i + K]) {
      // 既にソート済みであれば、オリジナルの順列パターンとして数える
      if (sorted[i + 1]) {
        orig = true;
      } else {
        result++;
      }
    }

    // 先頭の要素を取り除く
    sub.erase(P[i]);
  }

  // オリジナルの順列パターンを加える
  result += orig ? 1 : 0;

  // 結果発表
  std::cout << result;
  return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
constexpr int N = 100000 + 2;
long long n;
// long long collect(int n, int m){
//     long long ans = 1;
//     for (int i = 1; i <= m;i++){
//         ans *= (n - i + 1);
//         ans /= i;
//     }
//     return ans;
// }
// long long store[43];
// int ans[201];
// int main(){
//     cin >> n;
//     for (int i = 2; i <= 42;i += 2){
//         for (int j = 2; j <= i;j += 2)
//             store[i] += collect(i, j);
//         //cout << store[i] << endl;
//     }
//     int x = 1;
//     int y = 42;
//     int z = 1;
//     while (y >= 2){
//         if (store[y] <= n){
//             for (int i = 1; i <= y;i++)
//                 ans[z++] = x;
//             x++;
//             n -= store[y];
//         }
//         else
//             y -= 2;
//     }
//     cout << z - 1 << endl;
//     for (int i = 1; i < z;i++)
//         printf("%d%c", ans[i], i == z - 1 ? '\n' : ' ');
//     return 0;
// }

// int main(){
//     cout << collect(4, 4) << endl;
//     return 0;
// }
int a[N], b[N];
//reference:https://blog.csdn.net/junior19/article/details/71434787
int main(){
    cin >> n;
    n++;
    constexpr int sup = 90;
    int m = sup;
    int i = 0, j = 0;
    while (n > 1)
    {
        if (n & 1){
            a[++i] = m--;
            n--;
        }
        else{
            b[++j] = m--;
            n >>= 1;
        }
    }
    cout << ((i + j) << 1) << endl;
    for (int k = 1; k <= i; k++)
        cout << a[k] << ' ';
    for (int k = j; k;k--)
        cout << b[k] << ' ';
    for (int k = sup - i - j + 1; k <= sup; k++)
        cout << k << ' ';
    return 0;
}
//reference:https://blog.csdn.net/junior19/article/details/71434787

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);
	int x = 0, max = 0;
	for(int i = 0; s[i] != '\0'; i++){
		if(s[i] == 'I'){
			x++;
		}else if(s[i] == 'D'){
			x--;
		}
		if (max < x){
			max = x;
		}
	}
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 1732
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    A = LI()
    A.sort()
    MAX = 10**6+1
    All = [0] * MAX

    setA = set(A)
    for i in A:
        k = i
        All[k] += 1
        k += i
        if All[i] >= 2:
            continue
        while k < MAX:
            All[k] += 1
            k += i

    ans = 0
    for i in range(1, MAX):
        if All[i] == 1 and i in setA:
            ans += 1

    print(ans)

    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()


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

using i64 = int64_t;

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<i64> dp(n+4);
        dp[0] = 1;
        for(int i=0;i<n;++i){
            dp[i+1] += dp[i];
            dp[i+2] += dp[i];
            dp[i+3] += dp[i];
        }
        cout << (dp[n] + 3649) / 3650 << endl;
    }

    return 0;
}



Measured memory_bytes: 3032
# AGC039B - Graph Partition (156ms)
from collections import deque


def is_bipartite() -> bool:
    stack = [(1, 1)]
    color = [0] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = -cur_color
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if not color[u]:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = deque([start])
    dist = [0] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 1
    while que:
        v = que.popleft()
        cur = dist[v]
        for u in E[v]:
            if not dist[u]:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1))
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3692
#include <stdio.h>

int main(){
    int k;
    int a[1000001];

    scanf("%d", &k);

    a[1] = 7 % k;
    for(int i = 2; i <= k; ++i){
        a[i] = (10 * a[i-1] + 7) % k;
    }

    int flag = 0;
    for(int i = 1; i <= k; ++i){
        if(a[i] == 0){
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");

    return 0;
}


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e6+10;

int a[MAXN],sum[MAXN];
int main() {
    int K,N,res=-1;
    cin>>K>>N;
    cin>>a[1];
    for (int i=2;i<=N;i++) {
        cin>>a[i];
        int sub=a[i]-a[i-1];
        res=max(res,sub);
    }
    res=max(res,K-(a[N]-a[1]));
    cout<<K-res<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include<stdio.h>
int sum(int x, int y){
    return x+y;
}
int sub(int x, int y){
    return x-y;
}
int mul(int x, int y){
    return x*y;
}
int main(){
    int a, b, sm, sb, ml, gr;
    scanf("%d %d", &a, &b);
    sm = sum(a, b);
    sb = sub(a, b);
    ml = mul(a, b);
    if(sm > sb && sm > ml) gr = sm;
    else if(sb > sm && sb > ml) gr = sb;
    else if(ml > sm && ml > sb) gr = ml;
    
    printf("%d\n", gr);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int64_t ans = 1;
  vector<int64_t> vec(n);
  rep(i, n) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  if (vec.at(0) == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    if (vec.at(i) > 1000000000000000000 /ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= vec.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll n, k;
    cin>>n>>k;
    ll a[n+1] = {0};
    loop(i,0,k){
        ll d;
        cin>>d;
        loop(j,0,d){
            ll x;
            cin>>x;
            a[x]++;
        }
    }

    ll ans = 0;
    for(ll i=1; i<=n; i++){
        if(a[i] == 0) ans++;
    }
    print(ans);

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


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

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

  VAR(int, n, k);

  rep(i, n) {
    VAR(int, a);
  }

  OUTL((n - 1 + (k - 2)) / (k - 1));

  return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'L' && i > 0 && s[i-1] == 'L') ans++;
		if (s[i] == 'R' && i < n-1 && s[i+1] == 'R') ans++;
	}
	ans = min(ans + 2*k, n-1);
	cout << ans << endl;
	return 0;
}

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

int main()
{
    string s; cin >> s;
    int n = s.length();

    ll ans = 0;

    for (int bit = 0; bit < (1 << (n - 1)); bit++) {
        ll sum = 0;
        ll tmp = s[0] - '0';
        for (int i = 0; i < n - 1; i++) {
            if (bit & (1 << i)) {
                sum += tmp;
                tmp = s[i + 1] - '0';
            } else {
                tmp = tmp * 10 + s[i + 1] - '0';
            }
        }
        sum += tmp;
        ans += sum;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
scop = [] #高低差,min値
scom = []
ssum = 0

for i in range(n):
    s = input()
    sa = 0
    ms = 0
    for i in range(len(s)):
        if s[i] == "(":
            sa += 1
        else:
            sa -= 1
        if ms > sa:
            ms = sa
    if sa > 0:
        scop.append([ms,sa])
    elif not sa == ms:
        scom.append([ms,sa])
    ssum += sa

if not ssum == 0:
    print("No")
    exit()

scop.sort(reverse = True)
scom.sort()

now = 0
for i in scop:
    if now + i[0] < 0:
        print("No")
        exit()
    now += i[1]
for i in scom:
    if now + i[0] < 0:
        print("No")
        exit()
    now += i[1]

print("Yes")


Measured memory_bytes: 52472
#include <stdio.h>

int main(void) {
    long long A, B, N, x, y;
    scanf("%lld%lld%lld", &A, &B, &N);
    if (N>=B) {
        x=B-1;
        y=A*x/B-A*(x/B);
    }
    else {
        x=N;
        y=A*x/B-A*(x/B);
    }
    printf("%lld", y);
    return 0;
}


Measured memory_bytes: 1736
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x,y;
    cin >> x >>y;
    if((y-2*x)%2==0){
        if((y-2*x)/2>=0){
            if((2*x-y/2)>=0){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";


    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll lcm(ll a, ll b)
{
    ll t = __gcd(a, b);
    return t ? (a / t * b) : 0;
}
int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
ll a,b;cin>>a>>b;
cout<<lcm(a,b)<<endl;

  
  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using LL = long long;
using namespace std;
int main() {
	LL K;
	cin >> K;
	if (K % 2 == 0 || K % 5 == 0) {
		cout << -1 << endl;
		return 0;
	}
	int num = 7;
	LL cnt = 1;
	while (true) {
		num = num % K;
		if (num == 0) {
			break;
		}
		num = num * 10 + 7;
		cnt++;
	}
	cout << cnt << endl;
	return 0;

}



Measured memory_bytes: 3632
#include <stdio.h>

int main(){

	int n, max, min, i;
	int R[200000];

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &R[i]);
	}

	max = R[1] - R[0];
	min = R[0];

	for(i=1; i<n; i++){
		if(R[i]-min>max){
			max = R[i] - min;
		}
		if(R[i]<min){
			min = R[i];
		}
	}

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

	return 0;
}

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

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m,nax = 0;
	cin >>n >>m;
	vector<vector<int> > edges(n+1);
	vector<int> dp(n+1,0),leaf(n+1,0);
	for(int i = 0,x,y;i<m;i++) {
		cin >>x>>y;
		edges[x].push_back(y);
		leaf[y]++;
	}
	queue <int> que;
	for(int i = 1;i<=n;i++) {
		if(leaf[i]==0) que.push(i);
	}
	while(!que.empty()) {
		int a,b;
		a = que.front();
		que.pop();
		b=(int)edges[a].size();
		for(int i = 0;i<b;i++){
			dp[edges[a][i]] = max(dp[a]+1,dp[edges[a][i]]);
			nax = max(nax,dp[edges[a][i]]);
			--leaf[edges[a][i]];
			if(leaf[edges[a][i]]==0) que.push(edges[a][i]);
		}
	}
	cout <<nax<<'\n';
	return 0;
}

Measured memory_bytes: 9428
def main():
    import sys
    input = sys.stdin.readline

    RESULT = 'AC', 'WA', 'TLE', 'RE'

    N = int(input())

    ctr = [0] * 4
    for _ in range(N):
        s = input().rstrip()
        ind = RESULT.index(s)
        ctr[ind] += 1

    for key, cnt in zip(RESULT, ctr):
        print(f'{key} x {cnt}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner input;
    static void Main()
    {

        input = new Scanner();
        input.skip();
        int[] arr = input.arrayInt();
        WriteLine(arr.Max()<arr.Sum()-arr.Max()?"Yes":"No");

    }
    static long GCD(long a, long b)
    {
        long m = a % b;
        if (m == 0)
        {
            return b;
        }
        else
        {
            return GCD(b, m);
        }

    }
}





class Scanner
{

    public Scanner()
    {
    }

    public void skip()
    {
        ReadLine();
        return;
    }
    public string String()
    {
        return ReadLine();
    }
    public string[] arrayString()
    {
        return ReadLine().Split();
    }
    public int Int()
    {
        return int.Parse(ReadLine());
    }
    public int[] arrayInt()
    {
        return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
    }
    public long Long()
    {
        return long.Parse(ReadLine());
    }
    public long[] arrayLong()
    {
        return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
    }
    public double Double()
    {
        return double.Parse(ReadLine());
    }
    public double[] arrayDouble()
    {
        return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
    }
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if ((A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5) || (A == 5 && B == 5 && C == 7)){
   cout << "YES" << endl;
  }else{
   cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return list(map(lambda x: x + d, A))
def ldec(A, d=1): return list(map(lambda x: x - d, A))

H, W, M = nn()
T = nm(M)

for i in range(M):
    T[i] = ldec(T[i])

dh = array1(H)
dw = array1(W)

dic = {}

for i in range(M):
    dh[T[i][0]] += 1
    dw[T[i][1]] += 1
    dic[(T[i][0], T[i][1])] = True

dhlist = []
dwlist = []

ansh = max(dh)
for i in range(len(dh)):
    if dh[i] == ansh:
        dhlist.append(i)

answ = max(dw)
for i in range(len(dw)):
    if dw[i] == answ:
        dwlist.append(i)

ans = ansh + answ

for i in dhlist:
    for j in dwlist:
        if (i, j) not in dic:
            print(ans)
            exit(0)

print(ans-1)


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

using namespace std;
typedef long long int lli;

lli map[200000];

int main(void) {
    int n;
    scanf("%d",&n);
    for(int i=0; i<150000; i++)
        map[i] = 2e9;
    for(int i=0; i<n; i++) {
        lli a;
        scanf("%lld",&a);
        lli *p = lower_bound(map, map+200000, a);
        *p = min(*p, a);
    }
    printf("%d\n", lower_bound(map, map+200000, 2e9)-map);
    return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll n, k;
  cin >> n >> k;

  vll as(n), fs(n);
  rep(i, n) cin >> as[i];
  rep(i, n) cin >> fs[i];

  Sort(as), rSort(fs);

  auto f = [&](ll x) {
    ll shu = 0;
    rep(i, n) {
      ll del = as[i] - x / fs[i];
      if (del > 0) shu += del;
      if(shu > k) return false;
    }
    return (shu <= k);
  };

  if(f(0)) {
    cout << 0 << endl;
    return 0;
  }

  ll l = 0, r = INF;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    if (f(m)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int N, W;
int v[110], w[110];
int dp[101][10101];

void solve_dp() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
}

int main() {
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];
    solve_dp();
}


Measured memory_bytes: 7044
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim();
    var r = Number(inputs);

    console.log(
        Math.PI * Math.pow(r, 2), 2 * Math.PI * r
    );
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m, X, Y, z;
    int x[101], y[101];
    cin >> n >> m >> X >> Y;
    for (int i = 0; i < n; i++)
        cin >> x[i];
    for (int i = 0; i < m; i++)
        cin >> y[i];

    bool f;
    for (z = X + 1; z <= Y; z++)
    {
        f = true;
        for (int i = 0; i < n; i++)
        {
            if (z <= x[i])
                f = false;
        }
        for (int i = 0; i < m; i++)
        {
            if (z > y[i])
                f = false;
        }
        if (f)
            break;
    }
    if (f)
        cout << "No War" << endl;
    else
        cout << "War" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int B=1000000;
struct edge{int to,cost;};
int N,M;
int d[100][100];
vector<edge>G[100];
void dijkstra(int s){
      d[s][s]=0;
      priority_queue<P,vector<P>,greater<P> >Q;
      Q.push(P(0,s));
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(p.first>d[s][v])continue;
            for(int i=0;i<G[v].size();i++){
                  edge e=G[v][i];
                  if(d[s][e.to]>d[s][v]+e.cost){
                        d[s][e.to]=d[s][v]+e.cost;
                        Q.push(P(d[s][e.to],e.to));
                  }
            }
      }
}
int main(){
      while(cin>>N>>M&&(N||M)){
            REP(i,N)G[i].clear();
            REP(i,100)REP(j,100)d[i][j]=INF;
//            REP(i,N)REP(j,N)printf("%d%c",d[i][j],j==N-1?'\n':' ');
            REP(i,M){
                  int a,b,c;
                  cin>>a>>b>>c;a--;b--;
                  G[a].PB((edge){b,c});
                  G[b].PB((edge){a,c});
            }
            REP(i,N)dijkstra(i);
            vector<P>V;
            set<P> f;
            REP(i,N){
                  REP(j,G[i].size()){
                        int mid=G[i][j].to;
                        REP(k,G[mid].size()){
                              if(f.count(P(i,G[mid][k].to))==0){
                                    f.insert(P(i,G[mid][k].to));
                                    V.PB(P(i,G[mid][k].to));
                              }
                        }
                  }
            }
            int ans=INF;
            REP(i,V.size()){
                  if(ans>d[0][V[i].first]+d[V[i].second][N-1]){
                        ans=d[0][V[i].first]+d[V[i].second][N-1];
//                        cout<<V[i].first<<" "<<V[i].second<<" "<<ans<<endl;
                  }
            }
            cout<<ans<<endl;
      }
}

Measured memory_bytes: 1356
N = gets.to_i
B = gets.split.map(&:to_i)

A = []
N.times do |n|
  if n == 0
    A[n] = B[n]
  elsif n == N - 1
    A[n] = B[n-1]
  else
    A[n] = [B[n], B[n-1]].min
  end
end
puts A.inject(&:+)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[32]={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};
  cin>>n;
  cout<<a[n-1];
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define true 1
#define false 0
#define N 20
#define F 200

int solve(int,int);
int array1[N];
int m,n,i,b,a,res=0;

int main(){
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&array1[i]);
  }

  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&m);
    res = solve(0,m);
    if(res == 0){
      printf("no\n");
    }
    else if(res == 1){
      printf("yes\n");
    }
  }
  return 0;
}

int solve(int i, int m){
  int res=0;
  if(m == 0)
    return true;
  if(i >= a)
    return false;
  res = solve(i + 1, m) || solve(i + 1, m - array1[i]);
  return res;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c;
  int b[100009];
  int cnt=0;
  cin>>n>>m>>c;
  for(int i=0;i<m;i++)cin>>b[i];
  for(int i=0;i<n;i++){
    int sum=c;
    for(int j=0;j<m;j++){
      int a;
      cin>>a;
      sum+=b[j]*a;
    }
    if(sum>0)cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}


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

int n;
vector<int> graph[200000];
int decided[200000];
int cdecided[200000];
int visited[200000];
int searched[200000];
int circle[200000];
int asign[200000];

int loop(int p){
    if(searched[p] == 1){
        circle[p] = 1;
        return p;
    }
    visited[p] = 1;
    searched[p] = 1;
    int f = -1;
    for(int i = 0;i < graph[p].size();i++){
        int r = loop(graph[p][i]);
        if(r != -1 && r != p){
            f = r;
        }
    }
    searched[p] = 0;
    if(f > -1){
        circle[p] = 1;
        return f;
    }
    return -1;
}

void decide(int p){
    vector<int> t(graph[p].size()+1,0);
    for(int i = 0;i < graph[p].size();i++){
        if(decided[graph[p][i]] == -1) decide(graph[p][i]);
        if(decided[graph[p][i]] < t.size())
            t[decided[graph[p][i]]] = 1;
    }
    for(int i = 0;i < t.size();i++){
        if(t[i] == 0){
            decided[p] = i;
            break;
        }
    }
}

int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        int p;
        cin >> p;
        p--;
        graph[p].push_back(i);
    }
    for(int i = 0;i < n;i++){
        if(visited[i] == 0){
            loop(i);
        }
    }
    memset(decided,-1,sizeof(decided));
    memset(visited,0,sizeof(visited));
    int c,b;
    for(int i = 0;i < n;i++){
        if(circle[i] == 1){
            c = i;
            for(int j = 0;j < graph[i].size();j++){
                if(circle[graph[i][j]] == 0){
                    decide(graph[i][j]);
                    asign[decided[graph[i][j]]] = 1;
                } else {
                    b = graph[i][j];
                }
            }
            break;
        }
    }
    int small,big;
    for(int i = 0;i < n;i++){
        if(asign[i] == 0){
            small = i;
            for(int j = i+1;j < n;j++){
                if(asign[j] == 0){
                    big = j;
                    break;
                }
            }
            break;
        }
    }
    for(int i = 0;i < n;i++) cdecided[i] = decided[i];
    decided[c] = small;
    for(int i = 0;i < n;i++){
        if(decided[i] == -1) decide(i);
    }
    if(decided[b] != small){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    for(int i = 0;i < n;i++) decided[i] = cdecided[i];
    decided[c] = big;
    for(int i = 0;i < n;i++){
        if(decided[i] == -1) decide(i);
    }
    if(decided[b] == small){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 27008
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<int,int>;

int main(){

  int N, a;
  cin >> N;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());

  double avg = vec.at(0);
  for (int i = 1; i < N; i++){
    avg = (avg+vec.at(i))/2;
    // cout << avg << endl;
  }

  printf("%.5lf\n", avg);

  return 0;
}

Measured memory_bytes: 3696
#include<stdio.h>
int main()
{
    //first input n(city number),m(road number)
    int n,m,j,i;
    scanf("%d%d",&n,&m);
    int city[n+1],a[m+1],b[m+1];
    for(i=1;i<=m;i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    for(i=1;i<=n;i++){
        city[i]=0;
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(a[j]==i)city[i]++;
            if(b[j]==i)city[i]++;
        }
    }
    for(i=1;i<=n;i++){
        printf("%d\n",city[i]);
    }
    return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
#define MAX 200010

int modulo=1000000007;

typedef long long ll;

int nex[MAX];
int last[MAX];

ll dp[MAX];

ll solve(int n, int N){
	if (n==N) return 1;
	
	if (dp[n]!=-1) return dp[n];
	
	if (nex[n]==-1 or nex[n]==n+1) dp[n]=solve(n+1,N)%modulo;
	
	else dp[n]=(solve(n+1,N)%modulo+solve(nex[n],N)%modulo)%modulo;
	
	return dp[n];
	
}



int main(){
	memset(nex, -1, sizeof(nex));
	memset(last, -1, sizeof(last));
	memset(dp, -1, sizeof(dp));
	
	
	int n;
	cin>>n;
	
	int l[n];
	
	for (int i=0; i<n; i++) cin>>l[i];
	
	for (int i=n-1; i>=0; i--){
		if (last[l[i]]==-1){
			last[l[i]]=i;
			continue;
		}
		nex[i]=last[l[i]];
		last[l[i]]=i;
	}
	
	//for (int i=0; i<n; i++) cout<<nex[i]<<endl;
	
	cout<<solve(0,n)<<endl;
	
}


Measured memory_bytes: 10368
#include<stdio.h>

int main (void) {
   int a, b, c, tmp;
   scanf("%d %d %d", &a, &b, &c);

   if (a>b){
    tmp = a;
    a = b;
    b = tmp;
   } 
   if (b>c){
    tmp = b;
    b = c;
    c = tmp;
    if (a>b){
    tmp = a;
    a = b;
    b = tmp;
    }
   }
   printf("%d %d %d\n", a, b, c);
    
   return 0;
}


Measured memory_bytes: 2712
// Problem : A - Table Tennis Training
// Contest : AtCoder - AtCoder Grand Contest 041
// URL : https://atcoder.jp/contests/agc041/tasks/agc041_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void solve(){
	int n,a,b;
	rd(n,a,b);
	int dif=abs(a-b);
	if(dif%2==0)pp((dif/2));
	else{
		pp(min(abs(1-a),abs(n-b))+1+(b-a-1)/2);
	}
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3624
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()


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

int main() {
  ll n,k;
  cin >> n >> k;
  double ans=0;
  for(ll i=1;i<=n;i++) {
    double tans=1/double(n);
    ll temp=i;
    while(temp<k) {
      tans*=0.5;
      temp*=2;
    }
    ans+=tans;
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

pi fun(string & s){
	int count = 0, mini = 0;
	for(char c : s){
		if(c == '('){
			count++;
		}
		else{
			count--;
		}
		mini = min(mini, count);
	}
	return {mini, count};
}

bool f1(pi p1, pi p2){
	return p1.first < p2.first;
}

bool f2(pi p1, pi p2){
	return p1.second - p1.first < p2.second - p2.first;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s[n];
	int cur = 0, sum = 0;
	vector<pi> v1, v2;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		pi p = fun(s[i]);
		sum += p.second;
		if(p.first >= 0){
			cur += p.second;
		}
		else{
			p.first *= -1;
			if(p.second >= 0){
				v1.pb(p);
			}
			else{
				p.second *= -1;
				v2.pb(p);
			}
		}
	}
	if(sum != 0){
		cout<<"No"<<endl;
		return 0;
	}
	bool flag = 1;
	sort(v1.begin(), v1.end(), f1);
	for(pi p : v1){
		if(cur - p.first < 0){
			flag = 0;
			break;
		}
		else{
			cur += p.second;
		}
	}
	if(!flag){
		cout<<"No"<<endl;
		return 0;
	}
	sort(v2.begin(), v2.end(), f2);
	for(pi p : v2){
		if(cur - p.first < 0){
			flag = 0;
			break;
		}
		else{
			cur -= p.second;
		}
	}
	if(!flag || cur != 0){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 38684
#include <cstdio>
#include <iostream>

using namespace std;

int INFTY_ALDS16B = 2000000000;
int cnt_ALDS16B = 0;

int partition(int A[], int p, int r) {

	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; ++j) {
		if (A[j] <= x) {
			++i;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	int tmp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = tmp;
	return i + 1;
}

int main() {
	int n;
	scanf("%d", &n);

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}

	int base = partition(A, 0, n - 1);

	for (int i = 0; i < n; ++i) {
		if (i != 0) {
			cout << " ";
		}
		if (i == base) {
			cout << "[" << A[i] << "]";
		} else {
			cout << A[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3504
unittest
{
	assert( [ "2", "1 2", "2 3" ].parse.expand.solve == 3 );
	assert( [ "3", "100 100", "10 10000", "1 1000000000" ].parse.expand.solve == 9991 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	auto bs = new long[ n ];
	foreach( ref a, ref b; lockstep( as, bs ) )
	{
		input.popFront;
		auto ab = input.front.split.to!( long[] );
		a = ab[ 0 ];
		b = ab[ 1 ];
	}
	return tuple( as, bs );
}

auto solve( long[] as, long[] bs )
{
	as.sort();
	bs.sort();
	
	// 最小値配列の中央値から最大値配列の中央値までの範囲が答えになる
	auto ans = 0L;
	if( as.length % 2 == 0 ) ans = 1 + ( bs[ $ / 2 - 1 ] + bs[ $ / 2 ] ) - ( as[ $ / 2 - 1 ] + as[ $ / 2 ] );
	else                     ans = 1 + bs[ $ / 2 ] - as[ $ / 2 ];
	return ans;
}


Measured memory_bytes: 7052
#include <iostream>
using namespace std;
int main(){
  int N;cin>>N;
  int A[N];
  for (int i=0;i<N;++i)cin>>A[i];
  int ans=0;
  int tmp=0;
  for (int i=0;i<N-1;++i){
    if (A[i+1]<=A[i])  ++tmp;
    else tmp=0;
    ans =max(ans,tmp);
  }
  cout<<ans<<endl;
}
    
  
      
  
 

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
	int a[3];
	for(int i=0; i<3; i++) cin >> a[i];
	
	sort(a, a+3);

	if(a[0] + a[1] == a[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())

ans = [0]*N

for i in range(1,101,1):
  for j in range(1,101,1):
    for k in range(1,101,1):
      n = i**2+j**2+k**2+i*j+j*k+k*i
      if n > N:
        continue
      else:
        ans[n-1]+=1
      
for i in range(N):
  print(ans[i])
                           


Measured memory_bytes: 9304
let () =
  let n, c = Scanf.scanf "%d %d\n" (fun n c -> n, c) in
  let cs = Array.make c []
  in
  for i = 0 to n - 1 do
    Scanf.scanf "%d %d %d\n" (fun s t c ->
      cs.(c - 1) <- (s, t) :: cs.(c - 1))
  done;
  let channels = Array.make 200003 0 in
  begin Array.map (fun sts ->
    match List.sort compare sts with
    | [] -> []
    | (s, t) :: sts ->
        List.fold_left (fun (s, t, acc) (s', t') ->
          if t = s' then (s, t', acc)
          else (s', t', (s, t) :: acc)) (s, t, []) sts
        |> (fun (s, t, acc) -> (s, t) :: acc)) cs
  |> Array.to_list
  |> List.concat
  |> List.iter (fun (s, t) ->
      channels.(2 * s - 1) <- channels.(2 * s - 1) + 1;
      channels.(2 * t) <- channels.(2 * t) - 1)
  end;
  for i = 1 to Array.length channels - 1 do
    channels.(i) <- channels.(i) + channels.(i - 1)
  done;
  Printf.printf "%d\n" (Array.fold_left max 0 channels)

Measured memory_bytes: 17152
def cmb(n,r):
    if n==0 or r==0:
        return 1
    else:
        ans=1
        for i in range(1,min(r,n-r)+1):
            ans=ans*(n-i+1)//i
        return ans

n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(a.count(0))
else:
    a_sum=[a[0]]
    a_i=a[0]
    ans=0
    if a_i==0:
        ans+=1
    for i in range(1,n):
        a_i+=a[i]
        if a_i==0:
            ans+=1
        a_sum.append(a_i)
    a_sum.sort()
    a_sum.append(-10**18)
    cnt=1
    for i in range(n):
        if a_sum[i]==a_sum[i+1]:
            cnt+=1
        else:
            if cnt>=2:
                ans+=cmb(cnt,2)
            cnt=1
    print(ans)

Measured memory_bytes: 25724