akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct FenwickTree{
  static const int SIZE = 1<<22;
  int n, tree[SIZE+1];
public:
  FenwickTree(int n_){
    n = n_;
    for(int i=0; i<n+1; i++) tree[i] = 0;
  }
  void add(int i, int value){
    for(; i<n; i|=i+1) tree[i] += value;
  }
  int sum(int i){
    int s = 0;
    for(; i>=0; i=(i&i+1)-1) s += tree[i];
    return s;
  }
};

int main(){
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<ll> w;
  w.push_back(0);
  ll sum = 0;
  rep(i,N){
    sum += v[i];
    w.push_back(sum-(i+1)*K);
  }

  map<ll,ll> memo;
  vector<ll> ws = w;
  sort(ALLOF(ws));
  ll id = 0;
  rep(i,ws.size()){
    if(memo.count(ws[i]) > 0) continue;
    memo[ws[i]] = id++;
  }
  rep(i,w.size()){
    //cout << w[i] << "(" << memo[w[i]] << ") " ;
    w[i] = memo[w[i]];
  }
  //cout << endl;

  ll ret = 0;
  FenwickTree ft(id+5);
  rep(i,w.size()){
    ret += ft.sum(w[i]);
    ft.add(w[i],1);
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 19952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string S, T;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> S >> T;
    bool f = true;
    for(int i = 0; i < S.length(); i++){
        if(S[i] != T[i]) f = false; 
    }
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var n = int.Parse(list[0]);
        var a = int.Parse(list[1]);
        var b = int.Parse(list[2]);
        var c = int.Parse(list[3]);
        var d = int.Parse(list[4]);

        var s = Console.ReadLine();
        var routes = new int[n];
        routes[0] = s[0] == '#' ? -1 : 0;
        if (s[1] == '#')
        {
            routes[1] = -1;
        }
        else
        {
            routes[1] = 0;
            if (routes[0] != -1)
                ++routes[0];
        }

        for (int i = 2; i < routes.Length; ++i)
        {
            if (s[i] == '#')
            {
                routes[i] = -1;
            }
            else
            {
                routes[i] = 0;
                if (routes[i - 1] != -1)
                    ++routes[i - 1];
                if (routes[i - 2] != -1)
                    ++routes[i - 2];
            }
        }

        bool ac = true, bd = true, over = false;
        for (int i = a - 1, end = c - 1; i < end; ++i)
        {
            if (routes[i] == 0)
            {
                ac = false;
                break;
            }
        }

        over = c < d || routes[b - 2] == 2;
        for (int i = b - 1, end = d - 1; i < end; ++i)
        {
            if (routes[i] == 0)
            {
                bd = false;
                break;
            }
            else if (routes[i] == 2)
            {
                over = true;
            }
        }

        Console.WriteLine((ac && bd && over) ? "Yes" : "No");
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  int ans = 0;
  rep(i,n){
    ans += b[a[i]];
    if(i > 0 && a[i] == a[i-1] + 1) {
      ans += c[a[i-1]];
    }
  }
  cout << ans << endl;
}

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

int main(void) {

	int a, b;

	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;

	if (a > b) cout << "Alice" << endl;
	else if (a == b) cout << "Draw" << endl;
	else cout << "Bob" << endl;

	return 0;

}

Measured memory_bytes: 256
using System;
using System.Linq;

class prog{
  static void Main(){
    
    int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int D = input[0];
    int N = input[1];
    
    int ans;
    if(D == 0) ans = (N == 100) ? 101 : N;
    else if(D == 1) ans = (N == 100) ? 10100 : 100 * N;
    else ans = (N == 100) ? 1010000 : 10000 * N;
    
    Console.WriteLine(ans);
    
  }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A==1&&B==2) {
			System.out.println(3);
		}
		if (A==1&&B==3) {
			System.out.println(2);
		}
		if (A==3&&B==2) {
			System.out.println(1);
		}
		if (A==3&&B==1) {
			System.out.println(2);
		}
		if (A==2&&B==3) {
			System.out.println(1);
		}
		if (A==2&&B==1) {
			System.out.println(3);
		}
	}
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n, 0);  // 街iが何個道につながっているかを記録
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    // 添字で使うので-1する
    a--, b--;
    cnt[a]++;
    cnt[b]++;
  }

  for (int i = 0; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

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

int main(){
  int n,x;cin>>n>>x;
  int l[n];
  rep(i,n){
    cin>>l[i];
  	x -= l[i];
    if(x<0){
      cout << i+1;
      return 0;
    }
  }
  cout << n+1;
}

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

//const int INF = 1001001001;
//const ll INF18 = 1000000000000000000;
//const ll INF15 = 1000000000000000;
const ll mod = 1000000007;

int main() {
	string s, t;
	cin >> s >> t;

	int ans = 0;
	rep(i,s.size()) {
		int cnt = 0;
		if (i + t.size() > s.size()) break;
		rep(j,t.size()) {
			if (s[i + j] == t[j]) cnt++;
		}
		ans = max(ans, cnt);
	}
	ans = t.size() - ans;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;
typedef pair<int, int> P;
char a[55][55];
int h, w;
int xb[] = { 1,0,-1,0 }, yb[] = { 0,-1,0,1 };
const int INF = 100000000;
int BFS() {
	int d[55][55];
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= w; j++) {
			d[i][j] = INF;
		}
	}
	queue<P> que;
	que.push(P(1,1));
	d[1][1] = 1;
	while (que.size()) {
		P pa = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = pa.first + xb[i];
			int ny = pa.second + yb[i];
			if (1 <= nx&&nx <= h && 1 <= ny&&ny <= w&&a[nx][ny] == '.'&&d[nx][ny]>=INF) {
				d[nx][ny] = d[pa.first][pa.second] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	return d[h][w];
}
int main() {
	cin >> h >> w;
	int bknum = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') bknum++;
		}
	}
	int ans = BFS();
	if (ans < INF) ans = h*w - bknum - ans;
	else ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int X, Y;
    cin >> X >> Y;
    REP(i,X+1) {
        if(X*2 + i*2 == Y) {
            OUT("Yes")
            return 0;
        }
    }

    OUT("No")

    return 0;
}

Measured memory_bytes: 3636
program ABC088B;
{$mode Delphi}
uses SysUtils,fgl;

function intcompare(n1,n2:longint):longint;
begin
	result:=n2-n1;
end;

var
	n,i,r,t: longint;
	arr: TFPGList<longint>;
begin
	read(n);
	arr:=TFPGList<longint>.Create();
	for i:=0 to n-1 do begin
		read(r);
		arr.Add(r);
	end;
	arr.Sort(@intcompare);
	// reverse(arr,0,arr.Count);
	r:=0;
	t:=1;
	for i:=0 to n-1 do begin
		r:=r+t*arr[i];
		t:=-t;
	end;
	writeln(r);
end.


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

/*
100000
*/

const int MAX = 100000;

int main(){
    int n;
    cin >> n;
    vector<long long> x(100010);
    for(int i = 0;i < n;i++){
        long long a;
        cin >> a;
        x[a]++;
    }

    int q;
    cin >> q;
    int b[q + 1],c[q + 1];

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

    unsigned long long ans = 0;

    for(int i = 1;i <= MAX;i++){
            ans += x[i]*i;
    }

    for(int j = 0;j < q;j++){

        ans -= x[b[j]]*b[j];
        
        x[c[j]] += x[b[j]];

        ans += x[b[j]]*c[j];

        x[b[j]] = 0;
 
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
typedef long long ll;
const int N=2e5+5;
long long ans;
int n,L,a[N],i,j,x,aa[N];
int g[N];
V lv[N],rv[N];int mx[N];
int gfa(int x){return g[x]==x?x:g[x]=gfa(g[x]);}
inline bool cmp(int x,int y){return a[x]==a[y]?x<y:a[x]<a[y];}
long long mi;
struct atom{
	V l,r;int mx;bool full;
	inline void set(const atom&a,int mx2){
		ll z=1;int zz=max(a.l.empty()?0:a.l.back(),a.r.empty()?0:a.r[0]);
		full=0;l.clear();r.clear();
		for(mx=a.mx;mx<mx2 && z<=zz;z*=L,++mx);
		if(zz<z){mx=mx2;return;}
		full=a.full;
		for(int x:a.l)if(x>=z)l.push_back(x/z);
		for(int x:a.r)if(x>=z)r.push_back(x/z);
	}
}b[N],v[N];int xb;
int w,l,s,st[N];bool bb[N];
inline void uni(atom&zz){
	w=s=0;l=1;
	zz.full=1;zz.mx=b[1].mx;
	for(int i=1;i<=xb;++i){
		zz.full&=b[i].full;
		for(int x:b[i].l){
			for(;l<=w && st[l]+s+x>=L;++l)if(l<w && bb[l+1])s-=st[l+1];
			ans+=l-1;
		}
		if(!b[i].full)w=s=0,l=1;
		if(!b[i].r.empty()){
			if(l<=w)s+=b[i].r[0];int ow=w;
			for(int x:b[i].r)st[++w]=x,bb[w]=0;bb[ow+1]=1;
		}
	}
	zz.r.resize(w);s=0;for(int i=w;i;--i)zz.r[i-1]=st[i]+s,s+=bb[i]?st[i]:0;
	w=0;
	for(int i=xb;i;--i){
		if(!b[i].full)w=0;
		if(!b[i].l.empty()){
			int ow=w;reverse(b[i].l.begin(),b[i].l.end());
			for(int x:b[i].l)st[++w]=x,bb[w]=0;bb[ow+1]=1;
		}
	}
	zz.l.resize(w);s=0;for(int i=w;i;--i)zz.l[w-i]=st[i]+s,s+=bb[i]?st[i]:0;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>L;for(i=1;i<=n;++i)cin>>a[i],aa[i]=i,g[i]=i,v[i].l=v[i].r={1},v[i].mx=a[i],v[i].full=1;
	std::sort(aa+1,aa+n+1,cmp);
	for(i=1;i<=n;i=j){
		xb=0;
		if(aa[i]>1 && a[aa[i]-1]<a[aa[i]])b[++xb].set(v[aa[i]-1],a[aa[i]]),g[aa[i]-1]=aa[i];
		for(j=i+1,b[++xb]=v[aa[i]];j<=n && a[aa[j]]==a[aa[i]] && gfa(aa[j-1]+1)>=aa[j]-1
			 && a[aa[j-1]+1]<=a[aa[i]];++j){
			if(aa[j-1]+1<aa[j])b[++xb].set(v[aa[j]-1],a[aa[i]]),g[aa[j]-1]=aa[j];
			b[++xb]=v[aa[j]];g[aa[j-1]]=aa[j-1]+1;
		}
		if(aa[j-1]<n && a[aa[j-1]]>a[aa[j-1]+1])b[++xb].set(v[gfa(aa[j-1]+1)],a[aa[i]]),g[aa[j-1]]=aa[j-1]+1;
		uni(v[gfa(aa[i])]);
	}
	cout<<ans+n<<endl;
	return 0;
}

Measured memory_bytes: 58520
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long long N;
  cin >> N;
  
  long long num = 5;
  
  long long num2;
  
  long long num3 = 0;
  
  if(N % 2 == 1){
    cout << "0" << endl;
  }
  else{
    while(true){
      num2 = N / (num * 2);
      num3 = num2 + num3;
      num = num * 5;
      if(num2 == 0){
        break;
      }
    }
    cout << num3 << endl;
  }
}
  
  




Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int N;
  int a[100001];
  int i,tmp;
  int ans=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<N;i++){
    tmp=a[i];

    if(a[(tmp-1)]==i+1){
      // printf("%d\n",a[(tmp-1)]);
      ans++;
    }
  }
    printf("%d\n",ans/2);
    return 0;
  }


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.length() % 2 == 0) {
		for (int i = 0; i < s.length() / 2; i++) {
			cout << s[2 * i];
		}
	}
	else {
		for (int i = 0; i < s.length() / 2; i++) {
			cout << s[2 * i];
		}
		cout << s[s.length() - 1];
	}
}

Measured memory_bytes: 512
if __name__ == '__main__':
    n = int(input())
    reg = []
    for _ in range(n):
        reg.append(input())
    m = int(input())
    state = 0

    for _ in range(m):
        p = input()
        if p in reg and not state:
            print("Opened by %s" % (p))
            state = 1
        elif p in reg and state:
            print("Closed by %s" % (p))
            state = 0
        else:print("Unknown %s" % (p))

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return a/gcd(a, b) * b; }

ll f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/(lcm(c, d));
  return res;
}

int main(void){
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b, c, d) - f(a-1, c, d);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<usize>().unwrap());
    let n: usize = itr.next().unwrap();
    let k: usize = min(itr.next().unwrap(), 41);
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut a = is
        .split_whitespace()
        .map(|e| e.parse::<i64>().unwrap())
        .collect::<Vec<i64>>();

    for _ in 0..k {
        let mut b = vec![0; n + 1];
        for i in 0..n {
            let l = i.saturating_sub(a[i] as usize);
            let r = min(i + a[i] as usize + 1, n);
            b[l] += 1;
            b[r] += -1;
        }
        for i in 1..n {
            b[i] += b[i - 1];
        }

        a = b;
        a.pop();
        // if a.iter().all(|e| e == &(n as i64)) {
        //     break;
        // }
    }

    let mut flg = false;
    for e in a {
        if flg {
            print!(" ");
        }
        print!("{}", e);
        flg = true;
    }
    println!();
}


Measured memory_bytes: 6412
#include <iostream>
#define H 600
#define INF 2000000005

using namespace std;
int main() {
    int h;
    cin >> h;
    int tree[H];
    for (int i = 0; i < h; i++)
        cin >> tree[i];
    for (int i = h; i < H; i++)
        tree[i] = INF;
    for (int i = 0; i < h; i++) {
        int node = i + 1;
        cout << "node " << node << ": key = " << tree[node - 1] << ", ";
        if (i != 0)
            cout << "parent key = " << tree[node / 2 - 1] << ", ";
        if (tree[node * 2 - 1] != INF)
            cout << "left key = " << tree[node * 2 - 1] << ", ";
        if (tree[node * 2 + 1 - 1] != INF)
            cout << "right key = " << tree[node * 2 + 1 - 1] << ", ";
        cout << '\n';
    }
}


Measured memory_bytes: 3100
import collections
N=int(input())
d=list(map(int,input().split()))
dd = collections.Counter(d)
if dd[0]!=1 or d[0]!=0:
    print(0)
    exit()
count=1
for i in range(1,max(dd)+1):
    count *= pow(dd[i-1],dd[i],998244353)
print(count%998244353)



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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



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

    ll sum=0;
    ll ans;
    
    for(ll i=1;i<=x;i++){
        sum+=i;
        if(sum>=x){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll P[52][52] = {};
string A[52];
ll H, W;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  REP(i, 50) REP(j, 50) P[i][j] = llINF;
  cin >> H >> W;
  REP(i, H) cin >> A[i];
  ll ans = 0;
  REP(i, H) REP(j, W) {
    if (A[i][j] == '.')
      ans++;
  }

  queue<pll> que;
  que.push(make_pair(0, 0));
  P[0][0] = 1;
  while (!que.empty()) {
    auto pos = que.front();
    que.pop();
    ll x = pos.first;
    ll y = pos.second;
    // cout << x << "," << y << endl;
    if (x == W - 1 && y == H - 1) {
      break;
    }
    REP(i, 4) {
      if (x + dx[i] < W && x + dx[i] > -1 && y + dy[i] < H && y + dy[i] > -1 &&
          A[y + dy[i]][x + dx[i]] == '.' && P[y + dy[i]][x + dx[i]] == llINF) {
        P[y + dy[i]][x + dx[i]] = P[y][x] + 1;
        que.push(make_pair(x + dx[i], y + dy[i]));
      }
    }
  }

  if (P[H - 1][W - 1] == llINF)
    cout << -1 << endl;
  else
    cout << ans - P[H - 1][W - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0028();
	}
	class AOJ0028{
		public AOJ0028() {
			int[] data = new int[101];
			while(in.hasNext())data[in.nextInt()]++;
			int max=Integer.MIN_VALUE;
			for(int i=1;i<101;i++)max = Math.max(max, data[i]);
			for(int i=1;i<101;i++)if(max==data[i])System.out.println(i);
		}
	}

}

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

class Select{
	int *p;
	int size;
public:
	Select(int);
	Select(const Select&);
	Select& operator=(const Select&);
	~Select();
	void input();
	void narabekae();
	int get_size()const{ return size; }
};

Select::Select(int size){
	this->size = size;
	p = new int[size];
}

Select::Select(const Select& x){
	p = new int[x.get_size()];
}

Select& Select::operator=(const Select& x){
	if(&x==this) return *this;
	delete p;
	p = new int[x.get_size()];
	return *this;
}

Select::~Select(){
	delete [] p;
}

void Select::input(){
	for(int i=0;i<get_size();i++)
		cin>>p[i];
}

void Select::narabekae(){
	int count = 0;
	for(int i=0;i<get_size();i++){
		int minj = i;
		for(int j=i;j<get_size();j++){
			minj = (p[j]<p[minj])? j:minj;
		}
		int temp = p[i];
		p[i] = p[minj];
		p[minj] = temp;
		if(i!=minj) count++;
	}

	for(int i=0;i<get_size();i++){
		if(i!=get_size()-1){
			cout<<p[i]<<" ";
		}else{
			cout<<p[i]<<endl;
		}
	}
	cout<<count<<endl;
}

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

	Select test(size);
	test.input();
	test.narabekae();

	cin.get();
	cin.get();
}

Measured memory_bytes: 3092
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	double n;
	double m,d;
	cin >> n >> m >> d;
	cout.precision(17);
	double r=(n-d)/n/n*(m-1);
	if(d>0){
		r*=2;
	}
	cout << r << endl;




	return 0;
}



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

int main()
{
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;

    vector<pair<int, int>> zerSegs;

    int st;

    for(int i = 0; i < n; ++i){
        if(str[i] == '1' && i != 0 && str[i - 1] == '0'){
            zerSegs.push_back({st, i - 1});
        }else if(str[i] == '0' && (str[i - 1] == '1' || i == 0)){
            st = i;
        }
        if(str[i] == '0' && i == n - 1){
            zerSegs.push_back({st, i});
        }
    }

    int numSegs = zerSegs.size();
    if(k >= numSegs){
        cout << n << "\n";
        return 0;
    }

    int mxlen = 0;
    for(int i = 0; i + k <= numSegs; ++i){
        if(i == 0){
            mxlen = max(mxlen, zerSegs[i + k].first);
        }else if(i + k == numSegs){
            mxlen = max(mxlen, n - zerSegs[i - 1].second - 1);
        }else{
            mxlen = max(mxlen, zerSegs[i + k].first - 1 - zerSegs[i - 1].second);
        }
    }

    cout << mxlen << "\n";
    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int oddBCnt, oddWCnt, evenBCnt, evenWCnt;
	oddBCnt = oddWCnt = evenBCnt = evenWCnt = 0;
	FOR(i,0,n){
		if(i % 2 == 0){
			if(s[i] == '0'){
				oddBCnt++;
			}else{
				oddWCnt++;
			}
		}else{
			if(s[i] == '0'){
				evenBCnt++;
			}else{
				evenWCnt++;
			}
		}
	}
	ANS(min(oddBCnt + evenWCnt, oddWCnt + evenBCnt));
	return 0;
}


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

int main() {
    vector<vector<int>> v(3, vector<int>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> v[i][j];
        }
    }

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

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

int main() {
	int N,cnt=0,ans=0;
	cin >> N;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin >> a.at(i);
		if(a.at(i)==1) cnt++;
	}
	if(cnt>0){
		cnt=1;
		for(int i=0;i<N;i++){
			if(a.at(i)==cnt) cnt++;
			else ans++;
		}
		cout << ans << endl;
	}else cout << -1 << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 1e6 + 1;
bool prime[N];
ll divi[N]; 
ll cnt[N];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    memset(prime, true, sizeof(prime));
    prime[1] = false;
    prime[0] = false;
    divi[1] = 1;
    for(i = 2 ;i < N; i++){
        if(!prime[i]){
            //divi[i] = i;
            continue;
        }
        divi[i] = i;
        for(j = i + i; j < N; j+= i){
            prime[j] = false;
            divi[j] = i;
        }
    }
    
    while (T--) {
        ll n;
        cin >> n;
        ll g = 0;
        for(i =0 ; i < n; i++){
            ll x;
            cin >> x;
            g = __gcd(g, x);
            map<ll,ll> cnt2;
            while(x > 1){
                cnt2[divi[x]]++;
                x /= divi[x];
            }
            for(auto u : cnt2){
                cnt[u.ff]++;
            }
        }
        bool flag = true;
        for(i = 2; i < N; i++){
            if(cnt[i] > 1){
                //cout << i;
                flag = false;
            }
        }
        if(flag){
            cout << "pairwise coprime";
        }
        else{
            if(g== 1){
                cout << "setwise coprime";
            }
            else{
                cout << "not coprime";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 20260
#include<iostream>
#include<string>
using namespace std;
int main(){
	int alf[26] = {0};
	char c;
	string t="";
	
	while(cin>>c){
		if(c>=65&&c<=90)++alf[c-65];
		else if(c>=97&&c<=122)++alf[c-97];
	}
	for(int i=0;i<26;++i)
		cout << t+(char)(97+i) <<  " : " << alf[i] << endl;
}

Measured memory_bytes: 1188
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> V(n*2);
  for (int i=0; i<n*2; i++)
    cin >> V[i];
  sort(V.begin(), V.end());
  int res = 0;
  for (int i=0; i<n*2; i+=2)
    res += V[i];
  cout << res << endl;
}


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

int main(){
  int n, k;
  std::string s;
  std::cin >> n >> k >> s;
  
  int ans = 0;
  for(int i = 0; i < n - 1; i++)
    if(s[i] == s[i + 1])
      ans++;
  
  std::cout << (ans + 2 * k < n - 1 ? ans + 2 * k : n - 1) << '\n';
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<string>
const int maxn = 500;
using namespace std;
typedef long long LL;
#define For(a,b,c) for(int a=b;a<=c;a++)
#define For_(a,b,c) for(int a=b;a>=c;a--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define debug(x) cout<<#x<<" "<<x<<" "
int read(){
    int r=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(isdigit(c)){
        r=(r<<1)+(r<<3)+c-'0';
        c=getchar();
    }
    return r*f;
}

LL n;
void sovle(LL x){
    if(x != 0){
    int d = x%26;
    if(d == 0) sovle(x/26 -1);
    else sovle(x/26);
    if(d == 0) putchar('z');
    else putchar(d + 'a'-1);
    }
}
int main(){
    cin>>n;
    sovle(n);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3608
s = str(input())
if len(s)%2 == 1:
    u = 0
    for i in range ((len(s)-1)//2):
        if s[i] != s[len(s) -i -1]:
            u += 1
    print(u)
if len(s) % 2 == 0:
    u = 0
    for i in range(len(s)//2):
        if s[i] != s[len(s) - i -1]:
            u += 1
    print(u)

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n;
int A[25], B[25], C[25];

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

    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> A[i];
    }
    for (int i=1; i<=n; i++) {
        cin >> B[i];
    }
    for (int i=1; i<n; i++) {
        cin >> C[i];
    }

    int ans = 0;
    for (int i=1; i<=n; i++) {
        ans += B[A[i]];
        if (i > 1 && A[i-1]+1 == A[i]) {
            //cout << "D: " << i << "\n";
            ans += C[A[i-1]];
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

def check(s):
    n = len(s)
    if n%2 == 0:
        if s[:n//2] == s[n//2:]:
            return True
        else:
            return False
    else:
        # 偶数のぐう文字列は存在しない
        return False

for i in range(n):
    if i != 0 and check(s):
        break
    s = s[:-1]
    
print(len(s))

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n) ans += a[i] - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,ans=-1;
	ll a,t,h,mn=INFLL;
	cin >> n;
	cin >> t >> a;
	t *= 1000; a *= 1000;
	for(i=0; i<n; ++i){
		cin >> h;
		h = (t-6*h);
		h = abs(h-a);
		if(h<mn){
			ans = i;
			mn = h;
		}
	}
	cout << (ans+1) << endl;
	return 0;
}


Measured memory_bytes: 256
M, D = gets.split.map(&:to_i)

puts (1..M).inject(0) {|sum, i|
    (2..D).each{|d|
        d1, d10 = d%10, d/10
        sum += (d1 > 1 && d10 > 1 && i == d1*d10) ? 1 : 0 if d10.zero?.!
    }
    sum
}

Measured memory_bytes: 1788
n = int(input())
heights = list(map(int, input().split()))

maximum = max(heights)

splits = 0
for h in range(maximum, 0, -1):
    before = None
    sp = 0
    for i, _ in enumerate(heights):
        if heights[i] == h:
            if before != i - 1:
                sp += 1
            before = i
            heights[i] -= 1
    # print('height', h, ':', sp)
    splits += sp

print(splits)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		String str = scan.next();
		for(int i = str.length() - 1; i >= 0; i--){
			char ch = str.charAt(i);
			System.out.printf("%c", ch);
		}
		System.out.printf("\n");
	}
}

Measured memory_bytes: 25976
import sys
input = sys.stdin.readline

W, H, N = map(int, input().split(' '))
bound = {'l': 0, 'r': W, 'd': 0, 'u': H}
for _ in range(N):
    x, y, a = map(int, input().split(' '))
    if a == 1 and bound['l'] < x:
        bound['l'] = x
    elif a == 2 and bound['r'] > x:
        bound['r'] = x
    elif a == 3 and bound['d'] < y:
        bound['d'] = y
    elif a == 4 and bound['u'] > y:
        bound['u'] = y

w = max(0, bound['r']-bound['l'])
h = max(0, bound['u']-bound['d'])
print(w * h)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 500011
#define sigma 26
#define maxLog 21

int n, i, q, l, r;
char s[maxN];
int nxt[sigma][maxN];
int dad[maxLog][maxN];

void pre() {
    int i, j;

    for (i = 0; i < sigma; i++) nxt[i][n + 1] = n + 2;
    for (i = 0; i < sigma; i++) nxt[i][n + 2] = n + 2;

    for (i = n; i > 0; i--) {
        nxt[s[i] - 'a'][i] = i + 1;
        for (j = s[i] - 'a' + 1; j < sigma; j++)
            nxt[j][i] = nxt[j - 1][ nxt[j - 1][i] ];

        dad[0][i] = nxt[25][ nxt[25][i] ];

        for (j = 0; j < s[i] - 'a'; j++)
            nxt[j][i] = nxt[j][ dad[0][i] ];
    }

    for (i = 0; i < maxLog; i++) dad[i][n + 1] = n + 2;
    for (i = 0; i < maxLog; i++) dad[i][n + 2] = n + 2;

    for (i = 1; i < maxLog; i++)
        for (j = 1; j <= n; j++)
            dad[i][j] = dad[i - 1][ dad[i - 1][j] ];
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%s\n%d", s + 1, &q); n = strlen(s + 1);
    pre();

    for (i = 1; i <= q; i++) {
        scanf("%d%d", &l, &r);

        for (int step = maxLog - 1; step >= 0; step--)
            if (dad[step][l] <= r + 1)
                l = dad[step][l];

        if (l == r + 1)
            printf("Yes\n");
        else
            printf("No\n");
    }



    return 0;
}


Measured memory_bytes: 92928
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;



int main(){
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a.at(i);
  sort(all(a));
  ll min=a.at(0);
  ll tmp=1000000001;
  while(min<tmp){
    tmp=min;
    for(int i=1;i<n;i++){
      if(a.at(i)%min==0){
        a.at(i)=min;
      }else{
        a.at(i)=a.at(i)%min;
      }
    }

    sort(all(a));
    min=a.at(0);
  }

  cout<<min<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



long long int height[50], count_p[50];



int main(int argc, char *argv[])
{
	int n;
	vector<int> l;
	//input
	cin >> n;
	for (int i = 0; i < n; i++){
		int li;
		cin >> li;
		l.push_back(li);
	}


	//calc
	sort(l.begin(), l.end(), greater<int>());
	int max = l[0];
	int other_sum = 0;
	for (int i = 1; i < n; i++){
		other_sum += l[i];
	}


	//ans
	if (max < other_sum){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];

signed main(){
	cin>>N;
	int p=0,q=0;
	REP(i,N){
		cin>>A[i];
		q+=A[i];
	}
	int t=q;
	int m=INF;
	for(int i=0;i<N-1;i++){
		p+=A[i];
		q-=A[i];
		m=min(m,abs(p-q));
	}
	cout<<m<<endl;
	return 0;
}


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

int N;
int A[3000];

const int offset = 4000010;

int main () {
	scanf ("%d", &N);
	for (int i = 1; i <= N; ++i) scanf ("%d", &A[i]);
	std::bitset <offset * 2> bit;
	bit[offset] = 1;
	for (int i = 1; i <= N; ++i) bit = (bit << A[i]) | (bit >> A[i]);
	int sum = 0;
	for (int i = 1; i <= N; ++i) sum += A[i];
	for (int i = 0; i <= offset; ++i) {
		if (bit[offset + i] == 1 || bit[offset - i] == 1) {
			printf ("%d\n", (sum + i) / 2);
			return 0;
		}
	}
}


Measured memory_bytes: 5120
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (i % 2 == 0) {
			if (s.at(i) == 'L') {
				cout << "No";
				return 0;
			}
		}
		else {
			if (s.at(i) == 'R') {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#include<string>
using namespace std;

int main(){
    string str;
    cin >> str;
    for(int i = str.size()-1; i >=0 ; i--){
        if(str[i] =='9'){printf("Yes\n"); return 0;}
    }
    printf("No\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; 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; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];
const int MOD = 1000000007;

int main()
{
    int n, k; cin >> n >> k;
    ll ans = k;
  	while(n - 1 > 0)
    {
      ans *= k - 1;
      n--;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    string weather[3]= {"Sunny","Cloudy","Rainy"};
    string in;
    cin>>in;
    for (int i=0; i< 2; i++)
    {
        if (weather[i]== in)
        {
            cout<<weather[i+1]<<endl;
            return 0;
        }
    }
    cout<<weather[0];
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
mi = min(A)
cntA = Counter(A)
cnt_mi = cntA[mi]
if cnt_mi>2:
    print("Impossible")
    exit()
elif cnt_mi==1:
    ma = 2 * mi
else:
    ma = 2 * mi - 1
cnt = cnt_mi
for i in range(mi+1, ma+1):
    c = cntA[i]
    if c < 2:
        print("Impossible")
        exit()
    cnt += c
if cnt!=N:
    print("Impossible")
else:
    print("Possible")


Measured memory_bytes: 3316
# Aizu Problem ALDS_1_10_B: Graph
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
G = [[0 for _ in range(n)] for __ in range(n)]
for row in range(n):
    inp = [int(_) for _ in input().split()]
    a = inp[0]
    if inp[1] > 0:
        for b in inp[2:]:
            G[a-1][b-1] = 1

for row in G:
    print(' '.join([str(_) for _ in row]))

Measured memory_bytes: 7768
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* funciton */
/* main */
int main() {
    int N;
    cin >> N;
    vector<double> prob(N);
    for (int i = 0; i < N; i++) cin >> prob[i];

    // dp[i] : 表がi枚出る確率
    // 遷移)
    // 1) i枚目, 表が出る
    // dp[i+1] += dp[i] * (prob[i])
    // 2) i枚目, 裏が出る
    // dp[i] = dp[i] * (1 - prob[i])
    vector<double> dp(N+1, 0);
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j >= 0; j--) {
            dp[j+1] += dp[j] * prob[i];
            dp[j] = dp[j] * (1 - prob[i]);
        }
    }
    double ans = 0.0;
    for (int i = (N+1)/2; i <= N; i++) ans += dp[i];
    cout << fixed << setprecision(10) << ans << '\n';
}

Measured memory_bytes: 3844
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long count = 0;
        if (n * 2 > m) {
            count = m / 2;
        } else {
            count = n + ((m - (n * 2)) / 4);
        }
        System.out.println(count);
        bw.flush();
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

int main() {
	int N;cin>>N;
	vector<int>c(N);
	vector<int>cnt(N);
	vector<vector<int>>E(N);
	for (int i = 0; i < N-1; i++)
	{
		int a,b;cin>>a>>b;a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	for (int i = 0; i < N; i++)
	{
		cnt[i] = E[i].size();
	}
	for (int i = 0; i < N; i++)
	{
		cin>>c[i];
	}
	sort(c.begin(), c.end());

	vector<int>leaf;
	for (int i = 0; i < N; i++)
	{
		if(cnt[i] == 1)leaf.push_back(i);
	}

	vector<int>ans(N);
	for(int i=0;i<N;i++)
	{
		int id =  leaf.back();
		leaf.pop_back();

		ans[id] = c[i];

		for (int j = 0; j < E[id].size(); j++)
		{
			int id2 = E[id][j];
			cnt[id2]--;
			if(cnt[id2] == 1)leaf.push_back(id2);
		}
	}

	int M = 0;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < E[i].size(); j++)
		{
			int i2 = E[i][j];

			M += min(ans[i], ans[i2]);
		}
	}

	cout<<M/2<<endl;
	for (int i = 0; i < N; i++)
	{
		if(i)cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}

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

using namespace std;

int main() 
{
    int n;
    while (cin >> n, n) {
        vector<int> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }

        int mi = 999999999;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (mi > abs(s[i] - s[j])) {
                    mi = abs(s[i] - s[j]);
                }
            }
        }
        cout << mi << endl;
    }
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)IN(a[i]);
    REP(i,n){
        int c;
        cin>>c;
        a[i]-=c;
    }
    sort(ALL(a));
    ll ans=0;
    REP(i,n)ans+=max(0,a[i]);
    OUT(ans);
    return 0;
}

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

		int N = sc.nextInt();
		String S = sc.next();
		String[] alp = new String[]{"a","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
		String ans = "a";
		for( int i=0; i<S.length(); i++ ){
			char ch = S.charAt(i);
			String ss = String.valueOf(ch);
			for( int j=1; j<=26; j++ ){
				if( ss.equals(alp[j]) ){
					if( j+N>26 ){
						ans += alp[j+N-26];
						break;
					}else{
						ans += alp[j+N];
						break;
					}
				}
			}
		}
		System.out.println(ans.substring(1));     
	}
}


Measured memory_bytes: 145836