akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Transfer
// Contest : AtCoder Beginner Contest 136
// URL : https://atcoder.jp/contests/abc136/tasks/abc136_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define f first
#define se second
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a,b,c;
cin>>a>>b>>c;
int x=a-b;
cout<<max(0,c-x);
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t;
//cin>>t;
t=1;
while(t--)
{
    solve();
}
}


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

int main() {
  string S;
  cin>>S;
  int64_t ans=0,k=S.size();
  vector<int64_t> T(2019,0);
  T.at(0)++;
  int64_t h=0,t=1;
  for(int64_t i=k-1;i>=0;i--){
    int64_t a=(S.at(i)-'0');
    h+=a*t;
    h%=2019;
    T.at(h)++;
    t*=10;
    t%=2019;
  }
  for(int64_t i=0;i<2019;i++){
    auto a=T.at(i);
    if(a>1) ans+=a*(a-1)/2;
  }
  cout<<ans;
}


Measured memory_bytes: 3720
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
    int c[3][3],a[3], b[3];
    rep(i, 3) rep(j, 3)cin >> c[i][j];
    rep(i,3) a[i] = c[0][i] - c[1][i];
    rep(i, 3)b[i] = c[1][i] - c[2][i];
    if (a[0] == a[1] && a[0] == a[2] && b[0] == b[1] && b[0] == b[2])
        cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;

int64_t gcd(int64_t a, int64_t b) {
	int64_t c;
	while(a) {
		c = a; a = b%a; b = c;
	}
	return b;
}
int main() {
    int N;
    i64 K;
    cin >> N >> K;
    i64 M, G;
    for(int i = 0; i < N; i++) {
        i64 A;
        cin >> A;
        if(i == 0) {
            M = A, G = A;
        } else {
            M = max(M, A);
            G = gcd(G, A);
        }
    }
    if(M >= K && K % G == 0 ) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll a, b;

	cin >> a >> b;

	if (a % 2 == 0 || b % 2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
LL f[(int)1e5 + 10];
int main(){
    ios::sync_with_stdio(false);
    memset(f, 0x7f, sizeof(f));
    f[0] = 0;
    int n, W; cin>>n>>W;
    int maxl = 0, ans = 0;
    for(int i = 1; i <= n; i++){
        int wi, vi; cin>>wi>>vi;
        maxl += vi;
        for(int j = maxl; j >= vi; j--){
            f[j] = min(f[j], f[j - vi] + wi);
            if(f[j] <= W) ans = max(ans, j);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
char s[11];
cin.getline(s,10);
if(sizeof(s)<4)
cout<<"No";
else if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
cout<<"Yes";
else
cout<<"No";
return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    ll n;
    cin>>n;
    vv32 grph(n);
    string temp;
    forn(i, n)
    {
    	cin>>temp;
    	forn(j, n)
    	{
    		grph[i].pb(ll(temp[j]-'0'));
    	}
    }
    ll ans = -1;
    forn(i, n)
    {
    	v32 lvl(n, -1);
    	ll curr = 0;
    	queue<ll> qu;
    	qu.push(i);
    	qu.push(-1);
    	lvl[i] = 0;
    	ll flg = 1;
    	while(!qu.empty())
    	{
    		ll tmp = qu.front();
    		qu.pop();
    		if(tmp == -1)
    		{
    			if(!qu.empty())
    			{
    				curr++;
    				qu.push(-1);
    			}
    		}
    		else
    		{
    			forn(j, n)
    			{
    				if(grph[tmp][j] == 1 && lvl[j] == -1)
    				{
    					qu.push(j);
    					lvl[j] = curr+1;
    				}
    				else if(grph[tmp][j] == 1)
    				{
    					if(lvl[j] == lvl[tmp])
    					{
    						flg = 0;
    					}
    				}
    			}
    		}
    	}
    	if(flg)
    	{
    		ans = max(ans, curr+1);
    	}
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        String[] str1 = str.split(" ");
        int a = Integer.parseInt(str1[0]);
        int b = Integer.parseInt(str1[1]);

        if (a < b){
            System.out.println("a < b");
        } else if (a > b){
            System.out.println("a > b");
        } else if (a == b){
            System.out.println("a == b");
        }
    
    
    
    }

  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}



Measured memory_bytes: 26128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
  cin.tie(0);
  int a, b;
  cin >> a >> b;

  if (a >= 13) cout << b << endl;
  else if (a >= 6 && a <= 12) cout << b / 2 << endl;
  else cout << 0 << endl;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Cost(usize);

impl Ord for Cost {
    fn cmp(&self, other: &Cost) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl PartialOrd for Cost {
    fn partial_cmp(&self, other: &Cost) -> Option<Ordering> {
        Some(other.0.cmp(&self.0))
    }
}


fn main() {
    input!{
      k: usize,
    }

    let mut g = vec![vec![]; k];
    for i in 1..k {
        let n = (i+1)%k;
        g[i].push( (n, 1) );

        let n = (i*10)%k;
        if i != n {
            g[i].push( (n, 0) );
        }
    }

    const INF: usize = 1 << 32;
    let mut ds = vec![INF; k];
    ds[1] = 1;

    let mut q = BinaryHeap::new();
    q.push((Cost(1),1));

    while q.len() > 0 {
        // debug!(q);
        let (ttl_cost, v) = q.pop().unwrap();
        if ds[v] < ttl_cost.0 {
            continue;
        }

        for &(n, nc) in &g[v] {
            if ds[v] + nc < ds[n] {
                ds[n] = ds[v] + nc;
                q.push((Cost(ds[v] + nc), n));
            }
        }
    }
    println!("{}", ds[0]);
}


Measured memory_bytes: 16636
import numpy as np

n = int(input())
A = list(map(int, input().split()))

A = np.array(A)

A = np.sort(A)

B = np.copy(A)
if n == 2:
    print(A[1] - A[0])
    print(A[1], A[0])

elif A[0] <= 0 and A[n-1] >= 0:
    for i in range(n-1):
        A[i] = min(A[i], -A[i])

    print(np.sum(A[:-1]) * -1 + A[n-1])

    k = n - 2
    a = B[0]
    while B[k] >= 0:
        print(a, B[k])
        a = a - B[k]
        k -= 1
        if k == 0:
            break

    b = B[n-1]

    while k != 0:
        print(b, B[k])
        b = b - B[k]
        k -= 1

    print(b, a)

elif A[n-1] < 0:
    A[n-1] = A[n-1] - A[n-2]
    A[n-2] = 0
    for i in range(n-1):
        A[i] = min(A[i], -A[i])

    print(np.sum(A[:-1]) * -1 + A[n-1])

    a = B[n-1]
    for i in range(n-1):
        print(a, B[i])
        a = a - B[i]

else:
    A[0] = A[0] - A[1]
    A[1] = 0
    for i in range(n-1):
        A[i] = min(A[i], -A[i])

    print(np.sum(A[:-1]) * -1 + A[n-1])

    k = n - 2
    a = B[0]
    while B[k] >= 0:
        print(a, B[k])
        a = a - B[k]
        k -= 1
        if k == 0:
            break

    b = B[n-1]

    while k != 0:
        print(b, B[k])
        b = b - B[k]
        k -= 1

    print(b, a)


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


ll  N, P[1000*1000];


ll mk[1000 * 1000];
ll mk2[1000 * 1000];
ll g[8];
ll i, j, k;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N*N){
        scanf("%lld", &P[i]);
        P[i]--;
    }
    fornum(i,0,N){
        fornum(j,0,N){
            mk[i * N + j] = min(min(i, N - i - 1), min(j, N - j - 1));
        }
    }
    g[0] = 1;
    g[1] = N;
    g[2] = -1;
    g[3] = -N;
    ll ans = 0;
    fornum(i,0,N*N){
        //printf("%lld ", P[i]);
        ans += mk[P[i]];
        mk2[P[i]] = 1;
        queue<ll> q;
        q.push(P[i]);
        //printf("\n%lld:\n", P[i]);
        while(q.size()){
            ll qa = q.front();
            //printf("%lld,", qa);
            q.pop();
            fornum(j,0,4){
                ll nx = qa + g[j];
                if(nx<0||N*N<=nx||(qa%N!=nx%N&&qa/N!=nx/N))
                    continue;
                //printf("%lld,%lld,%lld,%lld\n", qa, nx, mk[qa] + 1 - mk2[qa], mk[nx]);
                if(mk[qa] + 1 - mk2[qa]<mk[nx]){
                    mk[nx] = mk[qa] + 1 - mk2[qa];
                    q.push(nx);
                }
            }
        }

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

Measured memory_bytes: 9620
#include <bits/stdc++.h>
#define maxn 300010
#define ms(x,y) memset(x,y,sizeof x)
#define inf 0x3f3f3f3f
#define fir first
#define sec second
#define lb(x) (x&(-x))
const int mod=1e9+7;
using namespace std;
typedef long long ll;
typedef pair<int,ll> pi;
int n,m,t[maxn];ll sum[maxn],dpf[maxn],dpb[maxn],f[maxn];
ll slop(ll *dp,int j){
	return dp[j]+sum[j]+1ll*(j-1)*j/2;
}
ll q[maxn],mx[maxn];
void pre(ll *dp){
	int top=1;ms(q,0);
	for(int i=1;i<=n;i++){
		while(top>=2&&slop(dp,q[top])-slop(dp,q[top-1])<=i*(q[top]-q[top-1]))top--;
		dp[i]=max(dp[i-1],dp[q[top]]-sum[i]+sum[q[top]]+(i-q[top]+1)*(i-q[top])/2);
		while(top>=2&&(slop(dp,q[top])-slop(dp,q[top-1]))*(i-q[top])<=
		(slop(dp,i)-slop(dp,q[top]))*(q[top]-q[top-1]))top--;
		q[++top]=i;
	}
}
void solve(int l,int r,int ty){
	if(l==r)return (void)(f[l]=max(dpf[l-1]+dpb[l+1]+1-t[l],f[l]));
	int mid=l+r-ty>>1;
	solve(l,mid,ty);solve(mid+1,r,ty);
	int top=0;
	for(int i=l-1;i<=mid;i++){
		while(top>=2&&(slop(dpf,q[top])-slop(dpf,q[top-1]))*(i-q[top])<=
		(slop(dpf,i)-slop(dpf,q[top]))*(q[top]-q[top-1]))top--;
		q[++top]=i;
	}
	for(int i=mid+1;i<=r;i++){
		while(top>=2&&slop(dpf,q[top])-slop(dpf,q[top-1])<=i*(q[top]-q[top-1]))top--;
		mx[i]=dpb[i+1]+dpf[q[top]]-sum[i]+sum[q[top]]+(i-q[top]+1)*(i-q[top])/2;
	}
//	mx[r+1]=0;
	for(int i=r;i>mid;i--){if(i!=r)mx[i]=max(mx[i],mx[i+1]);f[i]=max(f[i],mx[i]);}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&t[i]),sum[i]=sum[i-1]+t[i],f[i]=-1e18;
	pre(dpf);
	reverse(t+1,t+n+1);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
	pre(dpb);
	reverse(t+1,t+n+1);
	reverse(dpb+1,dpb+n+1);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
	solve(1,n,0);
	reverse(t+1,t+n+1);
	reverse(f+1,f+n+1);
	reverse(dpf+1,dpf+n+1);
	reverse(dpb+1,dpb+n+1);
	swap(dpf,dpb);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+t[i];
	solve(1,n,1);
	reverse(t+1,t+n+1);
	reverse(f+1,f+n+1);
	reverse(dpf+1,dpf+n+1);
	reverse(dpb+1,dpb+n+1);
	swap(dpf,dpb);
	scanf("%d",&m);int p,x;
	while(m--){
		scanf("%d%d",&p,&x);
		printf("%lld\n",max(dpf[p-1]+dpb[p+1],f[p]-x+t[p]));
	}
	return 0;
}


Measured memory_bytes: 17792
#include <unordered_set>
#include <string>
#include <iostream>
using namespace std;

int main(){
  typedef unordered_set<string> set_t;
  set_t A;
  int n;
  cin >> n;
  string inst, word;
  for(int i=0; i<n; i++){
    cin >> inst >> word;
    if(inst == "insert"){
      A.insert(word);
    }
    else{
      int m = A.count(word);
      if(m==0)cout << "no" << endl;
      else cout << "yes" << endl;
    }
  }
}

Measured memory_bytes: 30568
import java.util.*;

public class Main{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
		
        int N = sc.nextInt();
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		
		int minj, count = 0, temp;
		
		for(int i = 0; i < N; i++){
			minj = i;
			for(int j = i; j < N; j++) if(A[j] < A[minj]) minj = j;
			if(A[i] != A[minj]){
				temp = A[i];
				A[i] = A[minj];
				A[minj] = temp;
				count++;
			}
		}
		
		System.out.print(A[0]);
		for(int i = 1; i < N; i++) System.out.print(" " + A[i]);
		System.out.println();
		System.out.println(count);
	}
}


Measured memory_bytes: 26464
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC166B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);

            var sunukeNum = new List<string>();
            for (var i = 1; i <= k; i++)
            {
                var d = Console.ReadLine();
                var sunukeNo = Console.ReadLine().Split(' ').ToList<string>();
                sunukeNum.AddRange(sunukeNo);
            }
            var ans = 0;
            for (var j = 1; j <= n; j++)
            {
                if (!sunukeNum.Contains(j.ToString()))
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 19404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nm =Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);
            int[] ka = new int[n];
            for (int i = 0; i < n; i++)
            {
                ka[i] = -1;
            }
            int[] s = new int[m];
            int[] c = new int[m];
            for (int i = 0; i < m; i++)
            {
                string[] sc = Console.ReadLine().Split(' ');
                s[i] = int.Parse(sc[0])-1;
                c[i] = int.Parse(sc[1]);
                if (ka[s[i]] != -1 && ka[s[i]] != c[i]) { Console.WriteLine("-1"); return; }
                else
                {
                    ka[s[i]] = c[i];
                }
            }
            if (n != 1 && ka[0] == 0)
            {
                Console.WriteLine(-1); return;
            }
            for (int i = 0; i < n; i++)
            {

                if (ka[i] == -1)
                    if (i == 0 && n != 1) { ka[i] = 1; }
                    else { ka[i] = 0; }
                Console.Write(ka[i]);
            }
            Console.WriteLine();
            
        }
    }
}


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

long long A, B, N;
int main(){
	scanf("%lld %lld %lld", &N, &A, &B);
	if(A > B)swap(A, B);
	
	if(A % 2 != B % 2){
		printf("%lld\n", min(A + (B - A - 1) / 2, (N + 1 - B) + (B - A - 1) / 2));
	}else{
		printf("%lld\n", (B - A) / 2);
	}
	
	return 0;
}


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

int main(void){
 
  int a[4],i,Tmin,Bmin;
  char str[100];
  
  for(i=0;i<4;i++){
   fgets(str,sizeof(str),stdin);
    a[i]=atoi(str);
  }
  if(a[0]<=a[1]){
   Tmin=a[0]; 
  }else{
   Tmin=a[1]; 
  }
  
  if(a[2]<=a[3]){
   Bmin=a[2]; 
  }else{
   Bmin=a[3]; 
  }
  
  printf("%d\n",Tmin+Bmin);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int A, B, K;
int GCD(int a, int b) {
    if(a == 0) {
        return b;
    }else if(b == 0) {
        return a;
    }else {
        int r, temp;
        if(a < b) {
            temp = a;
            a = b;
            b = temp;
        }

        r = a % b;
        while(r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }
}
int main() {
    cin >> A >> B >> K;
    int g = GCD(A, B);
    int count = 0;
    for(int i = g; i >= 1; --i) {
        if(g % i == 0) {
            count++;
        }
        if(count == K) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string s,t,x;
int a,b;

void solve(){
    cin >> s >> t;
    cin >> a >> b;
    cin >> x;
    if(s==x) a--;
    else b--;
    cout << a << " " << b << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int L,R,d;
  cin >> L >> R >> d;
  int cnt = 0;
  FOR(i,L,R+1){
    if(i%d==0){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3628
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <algorithm>
typedef long long ll;
using namespace std;

class ERedScarf {
public:
  void solve(std::istream& in, std::ostream& out) {
    ll n;
    in >> n;
    ll a[n];
    for (int i = 0; i < n; ++i) {
      in >> a[i];
    }
    ll x[n];
    fill(x, x + n, 0);
    for (int i = 0; i < 32; ++i) {
      int xo = 0;
      for (int j = 0; j < n; ++j) {
        if (a[j] & (1 << i)) xo ^= 1;
      }
      for (int j = 0; j < n; ++j) {
        x[j] += (a[j] & (1 << i)) ^ (xo << i);
      }
    }
    for (int i = 0; i < n; ++i) {
      out << x[i] << " ";
    }
    out << endl;
  }
};


int main() {
	ERedScarf solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6260
#include<stdio.h>

int main(){
  int n,i,j,v,k;
  int a[100];
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&a[i]);
  for(k = 0; k < n-1; k++)
      printf("%d ",a[k]);
    printf("%d\n",a[k]);
  for(i = 1; i < n; i++){
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v){
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    for(k = 0; k < n-1; k++)
      printf("%d ",a[k]);
    printf("%d\n",a[k]);
  }
  return 0;
}



Measured memory_bytes: 2064
a = input()
b = len(a)
c = (b-1)//2
d = (b+3)//2 - 1
e = a[0: c]
f = a[d: b]

if a == a[::-1] and e == e[::-1] and f == f[::-1]:
    print("Yes")
else:
    print("No")


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

using namespace std;

string S;

void solve(){
    for(int bit = 0; bit < 1<<3; bit++){
        char op[3];
        int ans = S[0]-'0';
        for(int j = 0; j <= 2; j++){
            if(bit & 1<<j){
                op[j] = '+';
                ans += S[j+1]-'0';
            }
            else{
                op[j] = '-';
                ans -= S[j+1]-'0';
            }
        }
        if(ans == 7){
        for(int i = 0; i < 3; i++)
            cout << S[i] << op[i];
            cout << S[3] << "=" << ans << endl;
            break;
        }
    }
}

int main(){
    cin >> S;

    solve();
}


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

int main(void){
    int N, result = 0;
    scanf("%d", &N);

    vector<int> d(N);

    for(int i = 0; i < N; i++)
        scanf("%d", &d[i]);

    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            result += d[i] * d[j];
        }
    }

    cout << result << endl;

    return 0;
}

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

vector<long long int> fibonatti;
long long int  dp[10000];
int calc(int n){
  if(n <= 1) return 1;
  if(dp[n] != -1)return dp[n];
  fibonatti[n] = calc(n - 1) + calc(n - 2);
  return dp[n] = fibonatti[n];
}

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  fibonatti.resize(n + 1);
  fibonatti[0] = fibonatti[1] = 1;
  for (int i = 0; i <= n; i++) {
    dp[i] = -1;
  }
  dp[0] = dp[1] = 1;
  std::cout << calc(n) << std::endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int sum = 0;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }

    int mean = sum / N ;

    int ans = INF;
    for(int y = mean - 1; y <= mean + 1; y++){
        int tmp = 0;
        rep(i, N){
           tmp += (A[i] - y) * (A[i] - y);
        }
        ans = min(ans, tmp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;
 
int main() {
    int r;
    cin >>r;
    r=pow(r,2);
    cout<<r<<endl;

return 0;
}

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

using namespace std;

#define INF 1 << 20

typedef complex<int> P;

struct point {
	P p1, p2;
	int step;

	point(P p1, P p2, int step) : p1(p1), p2(p2), step(step) { }
	point() { this -> p1 = this -> p2 = P(0, 0); this -> step = 0; }
};

bool step[50][50][50][50] = {0};

int main() {
	int W, H;
	while (cin >> W >> H, W || H) {
		int s1x, s1y; cin >> s1x >> s1y;
		int s2x, s2y; cin >> s2x >> s2y;

		int wall[50][50];
		for (int y = 0; y < H; ++y)
			for (int x = 0; x < W; ++x)
				cin >> wall[y][x];

		bool f = false; fill(&step[0][0][0][0], &step[0][0][0][0]+50*50*50*50, false);
		queue<point> que; que.push( point( P(s1x-1, s1y-1), P(s2x-1, s2y-1), 0 ) );
		queue<P> dirs; dirs.push( P(0, 0) );
		while ( !que.empty() ) {
			point p = que.front(); que.pop();
			P dir = dirs.front(); dirs.pop();

			p.p1 += dir, p.p2 -= dir;

			if (p.step >= 100) continue;
			if (p.p1.real() < 0 || p.p1.real() >= W || p.p1.imag() < 0 || p.p1.imag() >= H) p.p1 -= dir;
			if (p.p2.real() < 0 || p.p2.real() >= W || p.p2.imag() < 0 || p.p2.imag() >= H) p.p2 += dir;
			if (wall[p.p1.imag()][p.p1.real()]) p.p1 -= dir;
			if (wall[p.p2.imag()][p.p2.real()]) p.p2 += dir;
			if (step[p.p1.real()][p.p1.imag()][p.p2.real()][p.p2.imag()]) continue;
			step[p.p1.real()][p.p1.imag()][p.p2.real()][p.p2.imag()] = true;

			if (wall[p.p1.imag()][p.p1.real()]) continue;
			if (wall[p.p2.imag()][p.p2.real()]) continue;

// cout << p.p1.real() << " " << p.p1.imag() << " " << p.p2.real() << " " << p.p2.imag() << endl;

			if (p.p1 == p.p2) {
				cout << p.step << endl;
				f = true;
				break;
			}

			++p.step;
			que.push(p); dirs.push( P(1, 0) );
			que.push(p); dirs.push( P(-1, 0) );
			que.push(p); dirs.push( P(0, 1) );
			que.push(p); dirs.push( P(0, -1) );
		}
		if (f) continue;
		cout << "NA" << endl;

	}
}

Measured memory_bytes: 8440
#include <iostream>
#include <utility>
#include <stdint.h>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
  int N, X, Y;
  cin >> N >> X >> Y;

  --X;
  --Y;

  vector<int> D(N,0);
  
  for (int x=0; x<N; ++x) {
    for (int y=x+1; y<N; ++y) {
      int direct = y-x;
      int shortcut = abs(Y-y)+abs(X-x)+1;
      D[min(direct, shortcut)]++;
    }
  }

  for (int n=1; n<N; ++n) {
    cout << D[n] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A= [int(c) for c in input().strip().split(' ')]
# s = input().strip()
A = sorted(A)
cnt =0
for i in range(n-1,1,-1):
    l,r=0,i-1

    while(l<r):
        # print(l,r,i)
        if(A[l]+A[r]>A[i]):
            cnt+=r-l
            r-=1
        else:
            l+=1
print(cnt)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newline "\n"
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template
int n,k,x[200000];
int mn = INT_MAX;
int mini (int idx1,int idx2){
    int z;
    z = min (abs(x[idx1]) + abs(x[idx1]-x[idx2]) , abs(x[idx2]) + abs(x[idx1]-x[idx2]));
    return z;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>x[i];
    sort(x+1,x+1+n);

    int l,r;
    l = 1;
    r = k;

    while(r<=n){
        mn = min (mn , mini(l,r));
        l++;
        r++;
    }
    cout<<mn<<newline;



}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//解説AC2回目
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n);//スイッチ
  for(int i=0;i<m;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      s--;
      a[s] |= 1<<i;//スイッチでボタンを押す
    }
  }
  int p=0;
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    p |= x<<i;//スイッチの点灯条件(偶奇)
  }
  int kotae = 0;
  for(int s=0;s<(1<<n);s++) {  
    int t=0;
    for(int i=0;i<n;i++) {
      if(s>>i&1) {  // i番目のbitが立っていれば加算する
        t^=a[i];
      }
    }
    if(t==p)kotae++;
  }
  cout<<kotae<<endl;
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, k; cin >> n >> k;
        vector<int> lose(n, 1);
        while (k--) {
                int m; cin >> m;
                while (m--) {
                        int x; cin >> x;
                        lose[x - 1] = 0;
                }
        }
        cout << accumulate(all(lose), 0);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3656
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	gcd_l := make([]int, n)
	gcd_r := make([]int, n)
	gcd_l[0] = a[0]
	for i := 1; i < n; i++ {
		gcd_l[i] = gcd(gcd_l[i-1], a[i])
	}
	gcd_r[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		gcd_r[i] = gcd(gcd_r[i+1], a[i])
	}
	ans := max(gcd_l[n-2], gcd_r[1])
	for i := 1; i < n-1; i++ {
		g := gcd(gcd_l[i-1], gcd_r[i+1])
		if g > ans {
			ans = g
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

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

  string s;
  cin >> s;

  int ans = 0;
  for(int i=1;i<s.length()+1;i++) {
    if(s[i] != s[i-1]) {
      ans++;
    }
  }

  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 512
(* Examples *)
(*
stdin.ReadLine()
printfn "%d"
printfn "%s"
*)

(* Library *)
module Library =
  let powerSet (n : int) =
    [|0 .. (1 <<< n) - 1|]
    |> Array.map (fun x ->
      [|0 .. n - 1|]
      |> Array.map(fun y -> x &&& (1 <<< y) <> 0)
    )

(* Standard Input *)
let readSplit elementFun=
  stdin.ReadLine().Split()
  |> Array.map elementFun

let read elementFun =
  stdin.ReadLine() |> elementFun

let readMap H =
  [|for i in 1..H -> stdin.ReadLine()|]
  |> Array.map(fun line ->
    line.ToCharArray()
  )
  |> array2D

(* Main *)
open Library

let N = read int

let table = 
  [|for i in 1..N ->
    let A = read int
    [|for j in 1..A ->
      readSplit int
    |]
  |]

powerSet N
|> Array.filter (fun group ->
  let mutable p = -1
  group |> Array.forall (fun person ->
    p <- p + 1
    match person with 
    | true ->
      table.[p] |> Array.forall (fun pre ->
        group.[pre.[0] - 1] = (if pre.[1] = 1 then true else false)
      )
    | false -> true
  )
)
|> Array.map(fun group ->
  group |> Array.fold (fun count i -> count + (if i then 1 else 0)) 0
)
|> Array.max
|> printfn "%d"

Measured memory_bytes: 22732
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    char s[26] = {};
    bool c[26] = {};

    string str;
    cin >> str;

    if (str.length() < 26) {
        // append
        for (int i = 0; i < str.length(); i++) {
            char j = str[i] - 'a';
            c[j] = true;
        }
        char app;
        for (int j = 0; j < 26; j++) {
            if (!c[j]) {
                app = j + 'a';
                break;
            }
        }
        cout << str << app << endl;
    } else {
        // alter
        for (int i = 0; i < str.length(); i++) {
            char j = str[i] - 'a';
            c[j] = true;
            while (j < 25) {
                j++;
                if (!c[j]) {
                    s[i] = j + 'a';
                    break;
                }
            }
        }
        for (int i = str.length() - 1; i >= 0; i--) {
            if (s[i]) {
                cout << str.substr(0, i) << s[i] << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }

    return 0;
}


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

int main() {
  int N,K;
  cin>>N>>K;
  int ans=0;
  int h;
  for(int i=0; i<N; i++){
    cin>>h;
    if(h>=K) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdio.h>
#define X first
#define Y second

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long
#define all(v) v.begin(), v.end()

using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

int main()
{
    std::ios::sync_with_stdio(false);

    int n;
    std::cin>> n;

    ll sum_all = 0;
    ll a[n + 1];
    for (int i = 1; i <= n; i++)
    {
        std::cin >> a[i];
        sum_all += a[i];
    }

    ll sum_left = a[1];
    ll ans = 1e18;
    for (int i = 2; i <= n; i++)
    {
        ans = std::min(ans, std::abs(sum_left - (sum_all - sum_left)));
        sum_left += a[i];
    }

    std::cout << ans << std::endl;
    return 0;
}

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

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

    int ans = a ;
    if(b<a) ans-=1 ;
    
    cout << ans << endl ;  
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    double p = 0;

    if(n >= k){
        FOR(i,1,k){
            p += pow(2, -ceil(log2((double)k / i)));
        }
        p += n - k + 1;
    }
    else{
        FOR(i,1,n+1){
            p += pow(2, -ceil(log2((double)k / i)));
        }
    }

    printf("%.10lf", p / n);

    return 0;
}

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	ll H=in(),W=in();
	map<char,ll> M;
	REP(i,H){
		string S=in<string>();
		REP(j,W){
			M[S[j]]++;
		}
	}

	ll one=0,two=0,four=(H/2)*(W/2);
	if((H%2) && (W%2)){
		one=1,two=H/2+W/2;
		four=(H/2)*(W/2);
	}
	else if((H%2) || (W%2)){
		two=(H%2)?W/2:H/2;
		four=(H/2)*(W/2);
	}
	
	for(auto& x:M){
		if((x.second%4)==1 || (x.second%4)==3){
			x.second--;
			one--;
		}
	}
	if(one){
		out("No");
		return 0;
	}

	for(auto& x:M){
		if((x.second%4)==2){
			x.second-=2;
			two--;
		}
	}
	if(two){
		if(two>0 && !(two%2)){
			for(auto& x:M){
				while(two>0 && x.second){
					x.second-=4;
					two-=2;
				}
				if(!two) break;
			}
		}
		else{
			out("No");
			return 0;
		}
		
	}

	for(auto& x:M){
		while(x.second){
			x.second-=4;
			four--;
		}
	}

	if(four){
		out("No");
		return 0;
	}
	out("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<4;i++){
        if(s[i]=='2') count++;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 256
# coding: utf-8
import math

N, D = list(map(int, input().split()))

XY = [list(map(int, input().split())) for _ in range(N)]

cnt = 0

for X, Y in XY:
    dist = math.sqrt(X**2 + Y**2)
    
    if dist <= D:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 45456
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n, m, c;
vi b;
void in(){
    cin >> n >> m >> c;
    rep(i,0,m) b.push_back(input());
}

void solve(){
    
    int cnt = 0;
    rep(i,0,n){
        int ret = 0;
        rep(i,0,m){
            ret += input() * b[i];
        }
        if(ret + c > 0) cnt++;
    }
    print(cnt);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

using namespace std;

int main() {
    int n, k, x, y, ans;
    scanf("%d %d %d %d", &n, &k, &x, &y);

    if (n > k) {
        ans = (x * k) + (y * (n - k));
    } else {
        ans = x * n;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int a,b;
    cin >> a >> b;
    int defference = b - a;
    
    int west = 1;
    int east = 3;
    for(int i = 3; i <= 1000;i++){
        if(east - west == defference){
            cout << east - b << endl;
            break;
        }
        west = east;
        east += i;
    }
    
}



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

int main(){
    ll n,i,j;
    string s,t,u,uu,v,vv;
    cin>>s;
    t=s;
    reverse(s.begin(),s.end());
    if(s==t)
    {
        u=s.substr(0,(s.size()-1)/2);
        uu=u;
        reverse(u.begin(),u.end());
        v=s.substr((s.size()+3)/2-1,(s.size()-1)/2);
        vv=v;
        reverse(v.begin(),v.end());
        if(u==uu&&v==vv)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }
        else
            cout<<"No"<<endl;
    return 0;
}





Measured memory_bytes: 3620