akhauriyash/Code-Regression huggingface dataset:
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"3 4 5
" => r"6",

r"5 12 13
" => r"30",

r"45 28 53
" => r"630"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: f32,
        b: f32,
        c: f32
    }

    let s = (a + b + c) / 2.0;

    unsafe { (s * (s - a) * (s - b) * (s - c)).sqrt().to_string() }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


ll solve(ll N,ll K,vector<ll> P,vector<ll> M) {
    ll ans = INF;
    if (P.size() == 0) return -M.at(K-1);
    if (M.size() == 0) return P.at(K-1);
    for (ll i = 0;i<P.size();i++) { //プラスでi+1個つける
        //cout << i << endl;
        ll p = P.at(i); //pで折り返す
        if (K - (i+1) - 1 < 0) break;
        if (M.size() >= K - (i+1)) {
            //cout << K - (i+1) << endl;
            ll m;
            m = M.at(K-(i+1)-1); //マイナスでK - (i+1)個つける
            ans = min(ans,p*2+(-m)); //プラスで引き返す
            ans = min(ans,p+(-m*2)); //マイナスで引き返す
        }
        else continue;
    }
    return ans;
}

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> P;
    vector<ll> M;
    for (ll i = 0;i<N;i++) {
        ll a;
        cin >> a;
        if (a >= 0) P.push_back(a);
        else M.push_back(a);
    }
    sort(M.begin(),M.end());
    reverse(M.begin(),M.end());
    ll res; 
    res = solve(N,K,P,M);
    cout << res << endl;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    long long mod = 1e9+7;
    
    vector<bool> oks(n+1,true);
    int i,a;
    for(i = 0;i < m;++i){
        cin >> a;
        oks.at(a) = false;
    }

    vector<long long> dp(n+1,0);
    dp.at(0) = 1;
    for(int now = 0;now < n;++now){
        for(int next = now+1;next <= min(n,now+2);++next){
            if(oks.at(next)){
                dp.at(next) += dp.at(now);
                dp.at(next) %= mod;
            }
        }
    }
    cout << dp.at(n) << endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# coding: utf-8

# In[70]:


N = int(input())


# In[71]:


num2alpha = lambda c: chr(c%26+97)


# In[72]:


def dfs(s,n,cnt):
    if n == 0:
        print(s)
        return
    for i in range(cnt+2):
        if i == cnt+1:
            dfs(s+num2alpha(i),n-1,cnt+1)
        else:
            dfs(s+num2alpha(i),n-1,cnt)
dfs("a",N-1,0)


# In[ ]:






Measured memory_bytes: 9204
from collections import Counter
n,m = map(int,input().split())
a = list(map(int,input().split()))
s = [0]*(n+1)
for i in range(1,n+1):
    s[i] = (s[i-1]+a[i-1])%m
c = Counter(s)
ans = 0
for k,v in c.items():
    if k == 0:
        ans += v-1+(v-2)*(v-1)//2
    else:
        ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 21508
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long
using namespace std;

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

ll n, x, ans = 1e18;
ll a[mnx], b[mnx];

int main(){

cin >> n >> x;

for(int i = 0; i < n; i++){
    cin >> a[i];
    b[i] = a[i];
}

for(int i = 0; i <= n; i++){
    ll cur = 0;
    for(int j = 0; j < n; j++){
        b[j] = min(b[j], a[(j - i + n) % n]);
        cur += b[j];
    }
    ans = min(ans, cur + i * x);
}

cout << ans;

return 0;

}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int H,W;
  cin >> H >> W;
  v(string) G(H+2,string(W+2,'#'));
  rep(i,H) {
    string s;
    cin >> s;
    rep(j,W) {
      G[i+1][j+1] = s[j];
    }
  }
  rep(i,H+2) {
    cout << G[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = 1e5;

int n;
vector<pii> edge;
char s[maxn + 2];

int main(void) {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) s[i] -= '0';
  if (s[n]) {
    puts("-1");
    return 0;
  }
  if (!s[1]) {
    puts("-1");
    return 0;
  }
  s[n] = 1;

  for (int i = 1; i < n; ++i) {
    if (s[i] != s[n - i]) {
      puts("-1");
      return 0;
    }
  }
  int cnt = 1;
  int root = 0;
  for (int i = 2; i <= n; ++i) {
    if (s[i]) {
      int new_root = cnt;
      ++cnt;
      edge.push_back({new_root, root});
      while (cnt < i) {
        edge.push_back({new_root, cnt});
        ++cnt;
      }
      root = new_root;
    }
  }

  for (int i = 0; i < n - 1; ++i) {
    printf("%d %d\n", edge[i].first + 1, edge[i].second + 1);
  }
}


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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;


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

    const int M = 1e5 + 10;
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> dp(N + 1, vector<ll> (M + 1, 1e18));
    
    ll ans = 0;
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            if (j < v[i - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            else dp[i][j] = min(dp[i - 1][j - v[i - 1]] + w[i - 1], dp[i - 1][j]);
            if (dp[i][j] <= W) ans = max(ans, (ll)j);
        }
    }
    cout << ans << endl;


}	

  // cout << "Case #" << caseNum++ << ": " << ans << endl;  


Measured memory_bytes: 80256
n = int(input())
h = list(map(int, input().split()))
cnt = 0

while True:
    if max(h) == 0:
        break
    i = 0
    while i < n:
        if h[i] == 0:
            i += 1
        else:
            cnt += 1
            while i < n and h[i] > 0:
                h[i] -= 1
                i += 1
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
long long d;
string s;

int main() {
	cin >> d;
	cout << 0 << ' ' << 0 << ' ';
	if (d == 1000000000000000000) {
		cout << 1000000000 << ' ' << 0 << ' ' << 0 << ' ' << 1000000000 << endl;return 0;
	}
	long long e = 1000000000 - (d % (long long)1000000000);
	cout << ((d / 1000000000) + 1) << ' ' << e << ' ' << 1 << ' ' << 1000000000 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

int n;

double d(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}

int fact(int i)
{
    if(i==1)return 1;
    return i*fact(i-1);
}

main()
{
    cin>>n;

    vv v;
    rep(i,n)
    {
        int x,y;
        cin>>x>>y;
        v.push_back({i,x,y});
    }


    double ans=0;
    do{
        rep(i,n-1)ans+=d(v[i][1],v[i][2],v[i+1][1],v[i+1][2]);

        /*
        each(it,v)printf("{%d,%d}",it[1],it[2]);
        cout<<endl;*/
    }while(next_permutation(all(v)));

    ans/=fact(n);

    printf("%.12lf\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

const int SIZE = 100001;
int group[SIZE];

void assignGroup(int u, int g, std::vector<int> *a) {
  if (group[u] != 0) return;

  group[u] = g;
  // for (int i = 0; i < a[u].size(); ++i) {
  //   if (a[u][i] && group[i] == 0) assignGroup(i, g, a);
  // }
  for (auto v : a[u]) {
    // printf("u: %d, v: %d, group[u]: %d, group[v]: %d\n", u, v, group[u],
    //        group[v]);
    if (group[v] == 0) assignGroup(v, g, a);
  }
}

bool isConnected(int s, int t) { return group[s] == group[t]; }

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a[n];

  rep(i, m) {
    int s, t;
    std::cin >> s >> t;
    a[s].push_back(t);
    a[t].push_back(s);
  }

  // std::cout << "/* message */" << '\n';
  // rep(i, n) {
  //   for (auto v : a[i]) std::cout << v << ' ';
  //   std::cout << '\n';
  // }
  // std::cout << "/* message */" << '\n';

  int g = 0;
  rep(i, n) {
    if (group[i] == 0) { assignGroup(i, ++g, a); }
  }

  // rep(i, n) std::cout << group[i] << ' ';

  int q;
  std::cin >> q;
  rep(i, q) {
    int s, t;
    std::cin >> s >> t;
    if (isConnected(s, t))
      std::cout << "yes" << '\n';
    else
      std::cout << "no" << '\n';
  }

  return 0;
}



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

int main()
{
  int a;
  cin>>a;
  vector<int> n(a);
  int i=0;
  while(i<a)
  {
    cin>>n[i];
    i++;
  }
  sort(n.begin(),n.end());
  i=0;
  int ans=0;
  while(i<a-1)
  {
    if(n[i]==n[i+1])
      ans=1;
    i++;
  }
  if(ans==0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
    return 0;
}

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

int main()
{
    int n,i,t;
    scanf("%d",&n);
    set<int> a;
    for(i=0;i<n;i++){
        scanf("%d",&t);
        if(a.end()==a.find(t))
            a.insert(t);
        else
            a.erase(t);
    }
    printf("%d",a.size());
}


Measured memory_bytes: 4864
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>

using namespace std;

long long N,A[100000],B[100000];

int main()
{
  cin >> N;
  for(int i=0;i<N;i++)
  {
    cin >> A[i];
  }
  A[N]=A[0];

  B[0]=0;
  for(int i=0;i<N;i++)
  {
    if(i%2==0)
    {
      B[0]+=A[i];
    }
    else
    {
      B[0]-=A[i];
    }
  }
  
  for(int i=1;i<N;i++)
  {
    B[i]=2*A[i-1]-B[i-1];
  }
  
    for(int i=0;i<N;i++)
  {
    cout << B[i] << " ";
  }
    
  
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

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

    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

void countingSort(vector<int>& A, vector<int>& B, int k) {
  vector<int> C(k, 0);
  for (int i = 0; i < A.size(); ++i) {
    ++C[A[i]];
  }
  for (int i = 1; i < k; ++i) {
    C[i] = C[i] + C[i - 1];
  }
  for (int i = A.size() - 1; i >= 0; --i) {
    int x = A[i];
    B[--C[x]] = x;
  }
}

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

  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }

  vector<int> B(n);
  countingSort(A, B, 10001);

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



Measured memory_bytes: 18496
#include <bits/stdc++.h>
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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

ll modPow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
 
ll choose(ll n, ll r, ll mod){
    ll mul = 1, div = 1;
    for(ll i = 0; i < r; i++){
        mul *= n - i;
        div *= i + 1;
        mul %= mod;
        div %= mod;
    }   
    return mul * modPow(div, mod - 2, mod) % mod;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = modPow(2, n, mod);
    ans--;
    ans -= choose(n, a, mod);
    ans -= choose(n, b, mod);
    cout << (ans+10*mod)%mod << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
        char[]c = s.toCharArray();
        int count0 = 0;
        int count1 = 0;
        
        if(c[0] == '0'){
            for(int i = 1; i < c.length; i++) {
              if(i % 2 == 1){
                if( c[i] == '0'){
                    count0++;
                }
              }else{
                if( c[i] == '1'){
                    count0++;
                } 
              }
            }   
        }
        if(c[0] == '1'){
            for(int i = 1; i < c.length; i++) {
              if(i % 2 == 1){
                if( c[i] == '1'){
                    count1++;
                }
              }else{
                if( c[i] == '0'){
                    count1++;
                } 
              }
            }
            
        }
        System.out.println(Math.max(count0, count1));
    }
}  
  

Measured memory_bytes: 26316
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll X[N], L[N];
    REP(i, 0, N) {
        cin >> X[i] >> L[i];
    }
    plglg rob[N];
    REP(i, 0, N) {
        rob[i] = plglg(X[i] - L[i], X[i] + L[i]);
    }
    sort(rob, rob + N, [](plglg a, plglg b){
        return a.second < b.second;
    });
    // REP(i, 0, N) {
    //     cout << rob[i].first << " " << rob[i].second << endl;
    // }
    ll ans = 0;
    ll right = -inf;
    REP(i, 0, N) {
        if (right <= rob[i].first) {
            ans++;
            right = rob[i].second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<double,double> pd;
#define MAXN 100005

int N;
vector<int> P;
vector<int> Q;
vector<int> temp;
vector<vector<int>> Permut;
bool choosen[10];

void solve(){
    if(temp.size() == N){
        Permut.push_back(temp);
    }else{
        for(int i = 1 ; i <= N ; i++){
            if(choosen[i])continue;
            choosen[i] = true;
            temp.push_back(i);
            solve();
            temp.pop_back();
            choosen[i] = false;
        }
    }
}

int binser(vector<int> X){
    int l = 0;
    int r = N-1;
    int pos = -1;
    while(l <= r){
        int m = (l+r)/2;
        if(Permut[m] == X){
            pos = m;
            break;
        }
        if(Permut[m] < X)
            r = m - 1;
        if(Permut[m] > X)
            l = m + 1;
        
    }
    return pos;
}

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

    cin >> N;
    for(int i = 0 ; i < N ; i++){
        int x;cin >> x;
        P.push_back(x);
    }
    for(int i = 0 ; i < N ; i++){
        int x;cin >> x;
        Q.push_back(x);
    }
    solve();
    int a , b;
    for(int i = 0 ; i < (int)Permut.size() ; i++){
        if(Permut[i] == P)
            a = i;
        if(Permut[i] == Q)
            b = i;
    }
    cout << abs(a-b) << '\n';

    return 0;
}

Measured memory_bytes: 3384
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
	string s;
	while(getline(cin, s)){
		if(s=="END OF INPUT") break;
		int a=0;
		
		while(a<s.size()){
			int count=0;
			while(a<s.size() && s[a] != ' '){
				++a;
				++count;
			}
			printf("%d", count);
			++a;
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>

int main() {
    int n,y;
    std::cin >> n >> y;
    int nn,nnn,yy,yyy;
    for(int i = 0; i <= y/10000; i++){
        nn = n - i;
        yy = y - 10000*i;
        for(int j = 0; j <= yy/5000; j++){
            nnn = nn - j;
            if(10000*i + 5000*j + 1000*nnn == y){
                std::cout << i << " " << j << " " << nnn << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  long sum =0;
  for(int i=1; i<=N; i++){
    if(i%3==0 || i%5==0) continue;
    else sum+=i;
  }
  cout << sum <<endl;
}


Measured memory_bytes: 3632
n,k = map(int,input().split())
n -= 1
s = (n-1)*n//2
if k > s:
  print(-1)
else:    
  m = s-k+n
  print(m)
  for i in range(n):
    print(1,2+i)
    m -= 1
  if m > 0:
    for i in range(1,n):
      if m == 0:
          break
      for j in range(2,n-i+2):
        if m > 0:
          print(j,j+i)
          m -= 1

Measured memory_bytes: 3644
n,m=map(int,input().split())
def exit():
    import sys
    print(-1)
    sys.exit()
num=['']*n
for s,c in (map(int,input().split()) for i in range(m)):
    if n>1 and [s,c]==[1,0]:
        exit()
    if num[s-1]!='':
        if num[s-1]==c:
            continue
        else:
            exit()
    else:
        num[s-1]=c
else:
    if n==1:
        print(num[0] if num[0]!='' else 0, end='')
    else:
        print(num[0] if num[0]!='' else 1, end='')
    for i in range(1,n):
        print(num[i] if num[i]!='' else 0, end='')

Measured memory_bytes: 9264
def parallel?(x1, y1, x2, y2, x3, y3, x4, y4)
  return ((x1 - x2) * (y3 - y4)).round(11) == ((y1 - y2) * (x3 - x4)).round(11)
end
gets.to_i.times do
  if parallel?(*gets.split(" ").map(&:to_f))
    puts "YES"
  else
    puts "NO"
  end
end

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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main(){
  int A, B;
  cin >> A >> B;
  cout << max(max(A-B,A+B), A*B) << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int ans[21][11][156];

int main(void){

  for(int k = 1 ; k <= 10 ; k++){
    for(int s = 1 ; s <= 155 ; s++){
      ans[1][k][s] = 0;
      }
    }
  ans[1][1][1] = 1;

  for(int n = 1 ; n <= 20 ; n++){
    for(int s = 1 ; s <= 155 ; s++){
      ans[n][1][s] = (n >= s)?(1):(0);
      }
    }

  for(int n = 2 ; n <= 20 ; n++){
    for(int k = 2 ; k <= 10 ; k++){
      for(int s = 1 ; s <= 155 ; s++){
        ans[n][k][s] = ans[n - 1][k][s] + ans[n - 1][k - 1][s - n];
      }
    }
  }

  while(1){
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0){
      return 0;
    }else{
      cout << ans[n][k][s] << endl;
    }
  }

}



Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<map>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 2e5+7;
int a[maxn];
char s[1000][1000];
int main()
{
    long long a,b;
    char c;
    scanf("%lld %c %lld",&a,&c,&b);
    if(c == '+')cout << a+b << endl;
    else cout << a-b << endl;
    return 0;
}


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

//0 1->codeforces
#define LL "%lld"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf(LL,&a);return a;}

int main() {
  char s[100], p[100];
  int ix=0;
  scanf("%s",p);
  int len=strlen(p);
  for(int i=0;i<len;i++){
    if(p[i]=='0')s[ix++]='0';
    else if(p[i]=='1')s[ix++]='1';
    else if(ix>0) ix--;
  }
  for(int i=0;i<ix;i++){
    putchar(s[i]);
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Edge>[] list = new ArrayList[n+1];
		for(int i = 1; i <= n; i++){
		    list[i] = new ArrayList<Edge>();
		}
		for(int i = 0; i < m; i++){
		    int l = sc.nextInt();
		    int r = sc.nextInt();
		    int d = sc.nextInt();
		    list[l].add(new Edge(l, r, d));
		    list[r].add(new Edge(r, l, -d));
		}

		// 計算
		String result = "Yes";
		int[] dist = new int[n+1];
		Arrays.fill(dist, Integer.MAX_VALUE);
		int[] visited = new int[n+1];
		for(int i = 1; i < n+1; i++){
		    if(visited[i] == 1) continue;
		    PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		    dist[i] = 0;
		    pq.add(i);
		    while(!pq.isEmpty()){
		        int now = pq.poll();
		        if(visited[now] == 1) continue;
		        visited[now] = 1;
		        for(Edge e : list[now]){
		            int from = e.from;
		            int to = e.to;
		            int d = e.weight;
		            if(dist[to] == Integer.MAX_VALUE){
		                dist[to] = dist[from] + d;
		            }else{
		                if(dist[to] != dist[from] + d) result = "No";
		            }
		            pq.add(to);
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}

class Edge {
    int from;
    int to;
    int weight;
    
    Edge(int from, int to, int weight){
        this.from = from;
        this.to = to;
        this.weight = weight;
    }

    public String toString(){
        return "from:" + from + " to:" + to + " weight:" + weight;
    }   
}


Measured memory_bytes: 172436
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;


int main() {
	int N, M;
	cin >> N >> M;
	vector<int> v(M);
	rep(i, M) {
		cin >> v[i];
	}
	vector<vector<int>> dp(M+1);
	rep(i, M+1) {
		dp[i].resize(N + 1);
		rep(j, N + 1) dp[i][j] = j == 0 ? 0 : 1e9;
	}
	repi(i, 1, M + 1) {
		rep(j, N + 1) {
			dp[i][j] = dp[i - 1][j];
			if (j - v[i - 1] >= 0) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i-1]] + 1);
				dp[i][j] = min(dp[i][j], dp[i][j - v[i-1]] + 1);
			}
		}
	}
	cout << dp[M][N] << endl;
	return 0;
}



Measured memory_bytes: 7024
#include <bits/stdc++.h>
#define ld long double
#define MOD 1000000007
#define N 1000006
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define INF 1000000000000000000
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define randright srand(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;
// int my_rand(){ int a=rand(); int b=rand(); return a*(RAND_MAX+1)+b; }

#define int long long int

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}

void solve(){
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='7'){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}

signed main(){
    fastio
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void) {
  int n, t, x, y, d;
  int xx=0;
  int yy=0;
  int tt=0;

  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>t>>x>>y;
    d=abs(x-xx)+abs(y-yy);
    if(d<=t-tt and (d%2)==((t-tt)%2)) {
      xx=x;
      yy=y;
      tt=t;
    } else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define MAX 10030
using namespace std;
typedef long long lld;
typedef pair<int,int> pii;
int n;
char str[100];
int getval(int x){
    printf("%d\n",x);
    fflush(stdout);
    scanf(" %s",str);
    if(str[0]=='V') return 2;
    else if(str[0]=='M') return 0;
    else return 1;
}
void query(int l,int r,int x,int y){
    int p=(l+r)/2,q=(x==y);
    int t=getval(p);
    if(t==2) return;
    if((t==x)==(p-l-1)%2) query(p,r,t,y);
    else query(l,p,x,t);
}
int main(){
    scanf("%d",&n);
    int t=getval(0);
    if(t==2) return 0;
    else if(t==0){
        query(0,n,0,0);
    }
    else query(0,n,1,1);
}


Measured memory_bytes: 760
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;

const int N=1005;
const ll inf=1000000000000000000ll;

int n,m;
char c[2][N][N];

int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++){
		scanf("%s",c[0][i]+1);
		for (j=1;j<=m;j++) c[1][i][j]=c[0][i][j];
	}
	for (i=2;i<n;i++)
		for (j=2;j<m;j++) c[i&1][i][j]='#';
	for (i=1;i<=n;i++) c[0][i][1]='#',c[1][i][m]='#';
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++) printf("%c",c[0][i][j]);
		printf("\n");
	}
	printf("\n");
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++) printf("%c",c[1][i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int a, b, c,d,e;
	cin >> a >> b >> c>> d >>e;
	if (e <= c && c <= a - e && e <= d && d <= b - e) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);  cin.tie(NULL);
    int n, i,cant;
    bool f;
    long long rta;

    rta = 0;
    f = false;
    cin >> n;
    for( i = 1; i <= n; i++ ){
        cin >> cant;
        if( f && cant > 0 ){
            rta++;
            cant--;
        }

        rta += cant/2;
        if( cant % 2 != 0 ) f = true;
        else f = false;
    }

    cout << rta << "\n";

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){

	int n, i;
	float x1, x2, x3, x4, y1, y2, y3, y4;
	float ab, cd;

	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%f %f %f %f %f %f %f %f",&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
		ab = (y2 - y1) / (x2 - x1);
		cd = (y4 - y3) / (x4 - x3);
		
		if( ab == cd ){
			printf("YES\n");
		}else{
		 	printf("NO\n");
		}
	}
		
	return 0;

}


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

typedef long long LL;
const LL mod = 1e9 + 7;

char g[1010][1010] = {};
LL dp[1010][1010] = {};

int main() {
	int H, W;
	cin >> H >> W;
	for(int i=1;i<=H;i++) {
		cin >> g[i]+1;
	}
	dp[1][1] = 1;
	for(int i=1;i<=H;i++) {
		for(int j=1;j<=W;j++) {
			if(j==1&&i==1) continue;
			if(g[i][j] != '#') {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
			}
		}
	}
	cout << dp[H][W];
}

Measured memory_bytes: 9216
n,a,b = map(int,input().split())
ans = 0
i = 1
while i <= n:
    x = 0
    li = list(str(i))
    for p in li:
        x += int(p)
    if a <= x <= b:
        ans += i
        i += 1
    else:
        i += 1
print(ans)

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main(){
    int N, M;
    cin>>N>>M;
    vvi Friend(N);
    REP(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        Friend[a].push_back(b);
        Friend[b].push_back(a);
    }
    vi Group(N, -1);
    vi GroupSize(N, 0);
    REP(i, 0, N){
        if(Group[i] != -1) continue;
        queue<int> que;
        que.push(i);
        while(!que.empty()){
            auto cur = que.front(); que.pop();
            Group[cur] = i;
            for(int f: Friend[cur]){
                if(Group[f] == -1){
                    que.push(f);
                }
            }
        }
    }
    REP(i, 0, N) GroupSize[Group[i]]++;
    int ans = 0;
    REP(i, 0, N) ans = max(ans, GroupSize[i]);
    cout << ans << endl;
}

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

int main(){

  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;

  if(e-a>k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

const int N=4e2;

string s[N];
bool dp[N][N][N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    if(n==1)
        cout<<1,exit(0);
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int k=1;k<=n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(k==1)
                    dp[k][i][j]=s[(i+1)%n][j]==s[i][(j+1)%n];
                else
                    dp[k][i][j]=dp[k-1][i][j]&&dp[k-1][(i+1)%n][(j+1)%n]&&s[(i+k-1)%n][j]==s[i][(j+k-1)%n];
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            ans+=dp[n][i][j];
    cout<<ans;
}


Measured memory_bytes: 46848
TestNum = int(input())
TimeList = list(map(int,input().split()))
DrinkNum = int(input())
DrinkList = [list(map(int, input().split())) for _ in range(DrinkNum)]
TimeSum = sum(TimeList)
for i in DrinkList:
    print(TimeSum - (TimeList[i[0] -1] - i[1]))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

string S;
ll ans = 700;

void solve(){
    rep(i, S.size()){
    if(S[i]=='o') ans += 100;
    }

    cout << ans << endl;
}

int main(){
    cin >> S;

    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
vector <string> str;
string mem[15][15];
typedef pair <string,int> P;

string con(string a,string b){
  int K=0;
  for(int i=0;i<a.size();i++){
    int j=i,k=0;
    while(a[j]&&b[k]&&a[j]==b[k]) j++,k++;
    if(!a[j]||!b[k])K=max(K,k);
  }
  return b.substr(K,b.size());
}

string solve(){
  string dp[1<<14][14];
  for(int i=0;i<n;i++) dp[1<<i][i]=str[i];
  
  for(int i=0;i<(1<<n);i++)
    for(int k=0;k<n;k++){
      if(dp[i][k]=="")continue;
      for(int j=0;j<n;j++){
	if((i&(1<<j)))continue;
	string nx=dp[i][k]+mem[k][j];
	int ni=i|1<<j;
	if(!dp[ni][j].size()||nx.size()<dp[ni][j].size()) dp[ni][j]=nx;
	else if(nx.size()==dp[ni][j].size()&&dp[ni][j]>nx)dp[ni][j]=nx;
      }
    }

  string res;
  for(int i=0;i<n;i++) {
    if(dp[(1<<n)-1][i]=="")continue;
    if(res==""||res.size()>dp[(1<<n)-1][i].size()) res=dp[(1<<n)-1][i];
    else if(dp[(1<<n)-1][i].size()==res.size()) res=min(res,dp[(1<<n)-1][i]);
  }
  return res;
}

int main(){
  
  while(cin>>n,n){
    str.resize(n);
    for(int i=0;i<n;i++)cin>>str[i];

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	if(i==j)continue;
	if(con(str[i],str[j])==""){
	  str.erase(str.begin()+j);
	  n--;
	  i=-1;
	  break;
	}
      }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)mem[i][j]=con(str[i],str[j]);

    cout<<solve().size()<<endl;
  }

  return 0;
}

Measured memory_bytes: 30792
'use strict';
{
  const lines = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
  const ary = lines.map(str => Number(str));

  if ((ary[0] - ary[1]) > 0) {
    console.log(ary[2] * ary[1] + ary[3] * (ary[0] - ary[1]));
  } else {
    console.log(ary[2] * ary[0]);
  }
}


Measured memory_bytes: 7624
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}


int main() {
    int i,j;
    int n;
    int k;
    int* a;
    int* a2a;
    int tmp,max = 0,max_i;
    int sum = 0;

    scanf("%d %d", &k, &n);
    a = (int*)malloc(sizeof(int) * n);
    a2a = (int*)malloc(sizeof(int) * n);

    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
        if(i >= 1){
            a2a[i-1] = a[i] - a[i-1];
            if(a2a[i-1] > max){
                max = a2a[i-1];
                max_i = i-1;
            }
        }
    }

    a2a[n-1] = a[0] + (k-a[n-1]);
    if(a2a[n-1] > max){
        max = a2a[n-1];
        max_i = n-1;
    }

    for(i=0;i<n;i++){
        if(i != max_i) sum += a2a[i];
    }
    
    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  int H,W,a,b,k=0;
  while(k != -1){
  scanf("%d %d",&H,&W);
  if(H==0 && W==0){
    break;
  }
    for(a=1;a<=H;a++){
      for(b=1;b<=W;b++){
        if(b==1 || b==W || a==1 || a==H){
          printf("#");
        }else{
          printf(".");
        }
      }
    printf("\n");
    }
    printf("\n");
  }
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

ll gcd(ll a, ll b){
    if (b == 0) return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int K;
    cin >> K;

    int even, odd;

    if (K & 1) {
        even = (K-1) / 2;
        odd = (K + 1) / 2;
    }else{
        even = K / 2;
        odd = K / 2;
    }

    cout << even * odd << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 764
N = int(input())
A = [int(i) for i in input().split()]

mi = 1e20
for sign in [-1, 1]:
    res, acc = 0, 0
    for a in A:
        acc += a
        if sign * acc <= 0:
            res += abs(acc - sign)
            acc = sign
        sign *= -1
    mi = min(mi, res)

print(mi)

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
int s, t, n, m;
void chkmax(int &a, int b) {a = a > b ? a : b;}
void chkmin(int &a, int b) {a = a < b ? a : b;}
int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) {
		if(c == '-') f = -f;
		c = getchar();
	}
	while(isdigit(c)) {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * f;
}
void write(int x) {
	char c[33] = {0}, tot = 0;
	if(x == 0) {puts("0"); return;}
	while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
	while(tot) {putchar(c[tot --]);}
	return ;
}
int main() {
	string s;
	cin >> s;
	if(s[1] == '7' || s[2] == '7' || s[0] == '7')
		puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void) {
	char s[10000];
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	if (a >= 3200) {
		printf("%s\n", s);
	}
	else {
		printf("red\n");
	}
	return 0; 
}

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

int main() {
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    int N;
    int64_t Z=0;
    cin>>N;
    vector<pair<int,int64_t>> l;
    vector<pair<int,int64_t>> r;
    for(int i=0;i<N;i++){
      int a;
      int64_t b,c;
      cin>>a>>b>>c;
      if(b>c){
        Z+=c;
        l.push_back(make_pair(a,b-c));
      }
      else if(c>b&&a!=N){
        Z+=b;
        r.push_back(make_pair(N-a,c-b));
      }
      else{
        Z+=b;
      }
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    priority_queue<int64_t, vector<int64_t>, greater<int64_t>> pq;
    for(auto x:l){
      int a;
      int64_t b;
      tie(a,b)=x;
      pq.push(b);
      if(a<pq.size()){
        pq.pop();
      }
    }
    while(!pq.empty()){
      Z+=pq.top();
      pq.pop();
    }
    for(auto x:r){
      int a;
      int64_t b;
      tie(a,b)=x;
      pq.push(b);
      if(a<pq.size()){
        pq.pop();
      }
    }
    while(!pq.empty()){
      Z+=pq.top();
      pq.pop();
    }
    cout<<Z<<endl;
  }
}

Measured memory_bytes: 8216
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

const long MAX = 10000;
const long INFTY = (1<<20);
const long WHITE = 0;
const long GRAY = 1;
const long BLACK = 2;

long n;
vector<pair<long, long> > adj[MAX];

void dijkstra(){
	priority_queue<pair<long, long> > PQ;
	long color[MAX], d[MAX];
	for (long i = 0; i < n; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;

	while (!PQ.empty()){
		pair<long, long> f = PQ.top();
		PQ.pop();
		long u = f.second;

		color[u] = BLACK;

		if (d[u] < f.first * (-1)) continue;

		for (long j = 0; j < adj[u].size(); j++){
			long v = adj[u][j].first;
			if (color[v] == BLACK) continue;
			if (d[v] > d[u] + adj[u][j].second){
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}

	for (long i = 0; i < n; i++){
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main(){
	long k, u, v, c;

	cin >> n;
	for (long i = 0; i < n; i++){
		cin >> u >> k;
		for (long j = 0; j < k; j++){
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}

	dijkstra();

	return 0;
}

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

using namespace std;

#define FOR(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;

int main() {
  string s; cin >> s;
  int ans = 0, g = 0, p = 0;
  REP(i,s.size()) {
    if (s[i] == 'g') {
      if (g > p) ans++, p++;
      else g++;
    } else {
      if (g > p) p++;
      else g++, ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int f_maxi(int N, int* a){
    int i;
    int ans = 0;
    for (i = 1; i < N; i++) {
        if (a[i] > a[ans]) {
            ans = i;
        }
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    int a[N];
    int i;
    for (i = 0; i < N; i++) cin >> a[i];

    int alice = 0;
    int bob = 0;
    int maxi;
    while(1){
        maxi = f_maxi(N, a);
        if (a[maxi] == 0) break;
        alice += a[maxi];
        a[maxi] = 0;

        maxi = f_maxi(N, a);
        if (a[maxi] == 0) break;
        bob += a[maxi];
        a[maxi] = 0;
    }
    cout << alice - bob << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <set>
using namespace std;

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
void setIO(string s = ""){
	unsyncIO();
	if(s.size()){
		setIn(s + ".in");
		setOut(s + ".out");
	}
}


#define ll long long
const ll mod = 998244353;
const int MX = 5005;

int main(){
	setIO();
	string s, t;
	cin >> s >> t;
	int ans = 1000005;
	for(int i = t.size() - 1; i < s.size(); i ++){
		int cnt = 0;
		for(int j = i - t.size() + 1; j <= i; j ++)
			cnt += (s[j] != t[j - i + t.size() - 1]);
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3656