akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)1e5+5)
#define MOD ((int)1e9+7)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll n;
string s;

ll dp[MAXN][13];

ll conv(char c){return c - '0';}

ll remain(ll rem,ll x)
{
	ll res = ((rem%13)*10 + x)%13;
	return res;
}

ll rec(ll idx,ll rem)
{
	if(dp[idx][rem] != -1) return dp[idx][rem];

	if(s[idx] != '?')
		return dp[idx][rem] = rec(idx+1,remain(rem,conv(s[idx])))%MOD;

	ll res = 0;

	for (int i = 0; i < 10; ++i)
	{
		res = (res+rec(idx+1,remain(rem,i)))%MOD;
	}
	return dp[idx][rem] = res;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> s;
	n = s.size();
	CLEAR(dp,-1);

	for (int i = 0; i < 13; ++i)
		dp[n][i] = 0;
	dp[n][5] = 1;
	ll ans = rec(0,0);

	cout << fixed << ans << endl;
}

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

const int N = 1e4 + 10;
typedef long long ll;
ll h, n, a[N], b[N];
ll f[N << 1];

int main() {
    cin >> h >> n;
    rep(i, 1, n) scanf("%lld%lld", &a[i], &b[i]);

    memset(f, 0x3f, sizeof(f));
    f[h + N] = 0;
    rep(i, 1, n) {
        for (int j = h; j >= 1; j--) {
            // if (f[j - a[i] + N] > f[j + N] + b[i]) {
                f[j - a[i] + N] = min(f[j - a[i] + N], f[j + N] + b[i]);
                // if (!f[j - a[i] + N]) printf("%d ! %lld %lld\n", j - a[i], f[j + N], b[i]);
            // }
        }
    }
    ll ans = (ll)0x3f3f3f3f;
    rep(i, -N, 0) ans = min(ans, f[i + N]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/*
 * If true, return not 0. If false, return 0.
 */
int isPrime(int num){
    if(num == 2) return 1;
    if(num == 3) return 1;
    if(num == 4) return 0;
    if(num == 5) return 1;
    
    for (int i = 2; i*i <= num; i++) {
        if (num % i == 0) {
            return 0;
        }
    }
    return 1;
}

int main(int argc, const char * argv[]) {
    //Input
    int n, value, maximum, ans;
    maximum = 0;
    scanf("%d", &n);
    
    int *array = NULL;
    array = (int*)malloc(sizeof(int) * n);
    int * flag = NULL;
    flag = (int*)malloc(sizeof(int) * n);
    memset(flag, 0x00, sizeof(int) * n);
    
    REP(i, n){
        scanf("%d", &value);
        maximum = maximum > value ? maximum : value;
        array[i] = value;
    }
    ans = 0;
    for(int i = 0; i < n; i++){
        if(isPrime(array[i])){
            ans += 1;
        }
    }
    
    printf("%d\n", ans);
    
    
    
    return 0;
}

Measured memory_bytes: 1104
def resolve():
	N, M = map(int, input().split())
	H = [int(i) for i in input().split()]
	adj = [[] for i in range(N)]
	for i in range(M):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = 0
	for i in range(N):
		if all(H[i] > H[neighbor] for neighbor in adj[i]):
			ans += 1
	print(ans)
resolve()

Measured memory_bytes: 29376
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	long long n,k;
	cin>>n>>k;
	n%=k;
	cout<<min(n,k-n);
	return 0;
}


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

int main()
{
    string S, T;
    cin >> S;
    cin >> T;

    int count = 0;

    for (int i = 0; i < 3; i++) {
        if (S.at(i) == T.at(i)) {
            count++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#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 <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N, as = 0, b;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    cin >> B.at(i);
  }
  as = B[0];
  for (int i = 1; i < N - 1; i++)
  {
    as += min(B[i - 1], B[i]);
  }
  as += B[N - 2];
  cout << as << endl;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n,m;
    cin >> n >> m;
    int a[35][35];
    vector<int> k(n);
    rep(i,n) {
        cin >> k[i];
        rep(j,k[i]) {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for(int l = 1;l<=m;l++) {
        int cnt = 0;
        rep(i,n) {
            rep(j,k[i]) {
                if(l == a[i][j]) {
                    cnt++;
                }
            }
        }

        if(cnt == n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<P> v(n);
    ll cnt[100][100];
    rep(i,100)rep(j,100)cnt[i][j]=0;
    rep(i,n){
        long double in; cin >> in;
        in*=1e9;
        in+=0.1;
        ll d=in;
        int num1=0,num2=0;
        while(d%2==0){
            d/=2;
            num1++;
        }
        while(d%5==0){
            d/=5;
            num2++;
        }
        v[i]={num1,num2};
        cnt[num1][num2]++;
    }
    rrep(i,100){
        rrep(j,100){
            if(i+1<100)cnt[i][j]+=cnt[i+1][j];
            if(j+1<100)cnt[i][j]+=cnt[i][j+1];
            if(i<99&&j<99)cnt[i][j]-=cnt[i+1][j+1];
        }
    }
    ll ans=0;
    rep(i,n){
        int x=18-v[i].fi,y=18-v[i].se;
        chmax(x,0);chmax(y,0);
        
        ans+=cnt[x][y];
        if(v[i].fi>=9&&v[i].se>=9) ans--;
    }
    cout << ans/2 << endl;
}



Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x;
  cin>>x>>a>>b;
  if(b-a>=x+1)
  cout << "dangerous" <<endl;
  else if(0<b-a&&b-a<=x) cout<<"safe"<<endl;
  else if(b-a<=0) cout << "delicious"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct edg
{
    int x, i;
};

vector<edg> arr[1010];

int dis[1010];
stack<int> stk;
int tim;

int low[1010];
int num[1010];
vector<int> scc[1010];
int siz;

void f(int x)
{
    dis[x] = ++tim;
    low[x] = dis[x];
    stk.push(x);

    for(edg &e : arr[x])
    {
        if(!dis[e.x])
        {
            f(e.x);
            low[x] = min(low[x], low[e.x]);
        }
        else if(!num[e.x])
            low[x] = min(low[x], dis[e.x]);
    }

    if(low[x] == dis[x])
    {
        siz++;
        while(1)
        {
            int t = stk.top();
            stk.pop();

            num[t] = siz;
            scc[siz].push_back(t);
            if(t == x)
                break;
        }
    }
}

bool chk[1010];
bool res[200010];

void dfs(int x)
{
    chk[x] = 1;
    for(edg &e : arr[x])
        if(!chk[e.x])
            dfs(e.x);
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, m, i;
    scanf("%d%d", &n, &m);
    for(i = 0; i < m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        arr[x].push_back({ y, i });
    }

    for(i = 1; i <= n; i++)
        if(!dis[i])
            f(i);

    for(i = 1; i <= n; i++)
    {
        for(edg &e : arr[i])
            if(num[i] == num[e.x])
                res[e.i] = 1;

        memset(chk, 0, sizeof chk);
        chk[i] = 1;
        for(edg &e : arr[i])
        {
            if(num[i] == num[e.x] && chk[e.x])
                res[e.i] = 0;
            else if(num[i] != num[e.x] && chk[e.x])
                res[e.i] = 1;
            dfs(e.x);
        }

        reverse(arr[i].begin(), arr[i].end());

        memset(chk, 0, sizeof chk);
        chk[i] = 1;
        for(edg &e : arr[i])
        {
            if(num[i] == num[e.x] && chk[e.x])
                res[e.i] = 0;
            else if(num[i] != num[e.x] && chk[e.x])
                res[e.i] = 1;
            dfs(e.x);
        }
    }

    for(i = 0; i < m; i++)
    {
        if(res[i])
            printf("diff\n");
        else
            printf("same\n");
    }
    return 0;
}

Measured memory_bytes: 4608
#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;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ld l;

void solve(){
    cin >> l;
    l/=3;
    cout << l*l*l << endl;
}

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

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define ll long long
#define M 1000000007
#define mod 998244353
#define fs first
#define sc second

int main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll int n,k,i,j,c=0;
  cin>>n;
  vector<pair<ll int,ll int>>v;
  for(i=0;i<n;i++)
   {
      cin>>c;
      v.pb(mp(c-1,i+1));
   } 
   sort(v.begin(),v.end());
   for(i=0;i<v.size();i++)
    cout<<v[i].sc<<" ";
  return 0;
}

Measured memory_bytes: 2544
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>a;
	while(n>0)
	{
	    b++;
	    n-=a;
	}
	cout<<b;
	
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]
if N==1:
    for i in range(10):
        flg = 0
        for j in range(M):
            s,c = A[j]
            if str(i)[s-1]==str(c):
                continue
            else:
                flg = 1
                break
        if flg==0:
            print(i)
            break
    if flg==1:
        print(-1)
else:
    for i in range(10**(N-1),10**N):
        flg = 0
        for j in range(M):
            s,c = A[j]
            if str(i)[s-1]==str(c):
                continue
            else:
                flg = 1
                break
        if flg==0:
            print(i)
            break
    if flg==1:
        print(-1)

Measured memory_bytes: 38384
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math

pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)

LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
    for i in range(2,LIMIT+1):
        if minPrime[i] == 0:
            minPrime[i] = i
            #print(i)
            for j in range(i+i,LIMIT+1,i):
                #print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i
make()
def factrial(N):
     ret = []
     while minPrime[N] != N:
         ret.append(minPrime[N])
         N = N//minPrime[N]
     if N != 1:
         ret.append(N)
     return ret
# def factrial(N):
#     ret = set()
#     while 1 != N:
#         ret.add(minPrime[N])
#         N = N//minPrime[N]
#     if N != 1:
#         ret.add(N)
#     return ret

#sofe = Sieve_of_Eratosthenes(M)
judge = set([])

for i in a:
    if not pc:
        break
    #asf = sofe.factorization(i)
    asf = set(factrial(i))

    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")
# import sys,collections

# N = int(sys.stdin.readline())
# #a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = list(map(int,input().split()))

# import math

# # def factrial(N):
# #     ret = []
# #     while minPrime[N] != N:
# #         ret.append(minPrime[N])
# #         N = N//minPrime[N]
# #     if N != 1:
# #         ret.append(N)
# #     return ret

# def factrial(N):
#     ret = set()
#     while 1 != N:
#         ret.add(minPrime[N])
#         N = N//minPrime[N]
#     if N != 1:
#         ret.add(N)
#     return ret

# for i in range(N):
#     acc = math.gcd(acc,a[i])
# if acc != 1:
#     print("not coprime")
#     exit()

# pairwise = True
# p = set() #all prime
# for e in a:
#     if not pairwise:
#         break
#     f = factrial(e)
#     if p & f != set():
#         pairwise = False
#         print("setwise coprime")
#         exit(0)
#     p = p | f

# if pairwise:
#     print("pairwise coprime")
# else:
#     print("setwise coprime")


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

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

  for (int i=0;i<N;i++){
    string s;
    cin >>s;
    if (s=="Y"){
      cout <<"Four"<<endl;
      break;}
    else if (i==N-1 && s != "Y"){
      cout <<"Three"<<endl;}
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

int M[101][101]={};

signed main(){
  int V,E;
  cin>>V>>E;
  REP(i,V)REP(j,V)M[i][j]=i==j?0:INF;
  REP(i,E){
    int s,d,c;
    cin>>s>>d>>c;
    M[s][d]=c;
  }
  REP(k,V)REP(i,V)REP(j,V){
    if(M[i][k]!=INF&&M[k][j]!=INF){
      M[i][j]=min(M[i][j],M[i][k]+M[k][j]);
    }
  }
  bool nega=false;
  REP(i,V)if(M[i][i]<0)nega=true;
  if(nega){
    cout<<"NEGATIVE CYCLE"<<endl;
  }else{
    REP(i,V){
      REP(j,V){
        if(j)cout<<' ';
        if(M[i][j]==INF)cout<<"INF";
        else cout<<M[i][j];
      }
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
using namespace std;


int main()
{
	string first;
	queue<string> body;
	map<string, int> second;
	bool aligned = true;
	char changecolor;
	string tmp;

	while (1)
	{
		cin >> first;
		if (first[0] == '0') return 0;

		body.push(first);
		second[first] = 0;

		while (!body.empty())
		{
			aligned = true;

			for (int i = 0; i < body.front().size() - 1; ++i)
			{
				tmp = body.front();

				if (tmp[i] == 'r' && tmp[i + 1] == 'g') changecolor = 'b';
				if (tmp[i] == 'r' && tmp[i + 1] == 'b') changecolor = 'g';
				if (tmp[i] == 'g' && tmp[i + 1] == 'r') changecolor = 'b';
				if (tmp[i] == 'g' && tmp[i + 1] == 'b') changecolor = 'r';
				if (tmp[i] == 'b' && tmp[i + 1] == 'r') changecolor = 'g';
				if (tmp[i] == 'b' && tmp[i + 1] == 'g') changecolor = 'r';

				if (tmp[i] != tmp[i + 1])
				{
					aligned = false;
					tmp[i] = changecolor;
					tmp[i + 1] = changecolor;
				}

				if (second.count(tmp) == 0)
				{
					second[tmp] = second[body.front()] + 1;
					body.push(tmp);
				}
			}

			if (aligned)
			{
				cout << second[body.front()] << endl;
				break;
			}

			body.pop();
		}

		if(body.empty()) cout << "NA" << endl;

		first.clear();
		second.clear();
		while (!body.empty()) body.pop();
	}

	return 0;
}

Measured memory_bytes: 2852
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    string s;cin >>s;
    sort(all(s));
    bool flg=true;
    if(s[0]!=s[1]||s[1]==s[2]||s[2]!=s[3])flg=false;
    if(flg)puts("Yes");
    else puts("No");
}


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


#define repl(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double D;

typedef vector<D> vec;
typedef vector<vec> mat;

mat operator*(const mat& a,const mat& b){
	ll sz=a.size();
	mat res=mat(sz,vec(sz,0));
	rep(i,sz)rep(j,sz)rep(k,sz){
		res[i][j]+=a[i][k]*b[k][j];
	}
	return res;
}

mat mpow(mat a,ll n){
	ll sz=a.size();
	mat res=mat(sz,vec(sz,0));
	rep(i,sz)res[i][i]=1;
	while(n>0){
		if(n&1)res=res*a;
		a=a*a;
		n>>=1LL;
	}
	return res;
}

ll n;
ll m;
D p[21][121];

int main(){
    while(1){
    	cin>>n>>m;
        if(n==0&&m==0)break;
        rep(i,n+1)rep(j,121)p[i][j]=0;
        p[0][0]=1;
        rep(i,n)rep(j,121){
        	repl(k,1,6+1){
        		if(j+k<=120)p[i+1][j+k]+=p[i][j]*(1.0/6.0);
        	}
        }
        D crtE=(n+6*n)/2.0;
        ll crtX=0;
        crtX=(ll)floor(crtE);
		m--;
        while(m>0){
        	mat crtm(2,vec(2,0));
        	D a=1;
        	D b=0;
        	repl(i,crtX+1,6*n+1){
        		b+=i*p[n][i];
        		a-=p[n][i];
        	}
        	crtm[0][0]=a; crtm[0][1]=b;
        	crtm[1][0]=0; crtm[1][1]=1;
        	ll lb=0,ub=m;
        	while(ub-lb>1){
        		ll mid=(lb+ub)/2;
        		mat r=mpow(crtm,mid);
        		D tmp=r[0][0]*crtE+r[0][1];
        		if(crtX+1<tmp)ub=mid;
        		else lb=mid;
        	}

			mat r=mpow(crtm,ub);
			crtE=r[0][0]*crtE+r[0][1];

        	m-=ub;
        	crtX=(ll)floor(crtE);
        }
		printf("%.10Lf\n",crtE);
    }
}



Measured memory_bytes: 3336
#include<stdio.h>

int main(void)
{
  int a,b;
  char op;
 

  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op == '?')
      break;
    if(op == '+'){
      printf("%d\n",a+b);
    }
    else if(op == '-'){
      printf("%d\n",a-b);
    }
    else if(op == '*'){
      printf("%d\n",a*b);
    }
    else if(op == '/'){
      printf("%d\n",a/b);
    }
      }
  return 0;
}

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

typedef pair<int, int> Zahyo;
struct edge { int from, to, cost; };


template<typename T>
class UnionFind {
  public:
    vector<T> parent;

    UnionFind(T n) {
      parent = vector<T>(n, -1);
    }

    T root(T a) {
      if (parent[a] < 0) return a;
      else return parent[a] = root(parent[a]);
    }

    T size(T a) {
      return -parent[root(a)];
    }

    bool connect(T a, T b) {
      a = root(a);
      b = root(b);
      if (a == b) {
        return false;
      }

      if (size(a) < size(b)) swap(a, b);

      parent[a] += parent[b];
      parent[b] = a;
      return true;
    }
};

void Main() {
  int N;
  cin >> N;

  Zahyo x[N], y[N];
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    x[i] = Zahyo(X, i);
    y[i] = Zahyo(Y, i);
  }

  sort(x, x + N);
  sort(y, y + N);

  vector<edge> e;
  for (int i = 1; i < N; i++) {
    e.push_back({x[i - 1].second, x[i].second, abs(x[i].first - x[i - 1].first)});
    e.push_back({y[i - 1].second, y[i].second, abs(y[i].first - y[i - 1].first)});
  }

  sort(e.begin(), e.end(), [&](const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
  });

  long long ans = 0;
  UnionFind<int> u = UnionFind<int>(e.size());
  for (auto edge: e) {
    if (u.root(edge.from) != u.root(edge.to)) {
      u.connect(edge.from, edge.to);
      ans += edge.cost;
    }
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 6388
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
char func(char cur, char nbr, char info) {
  if (cur == 'S') {
    if (info == 'o') {
      return nbr;
    } else {
      return 'W' + 'S' - nbr;
    }
  } else {
    if (info == 'o') {
      return 'W' + 'S' - nbr;
    } else {
      return nbr;
    }
  }
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  string s, t = "SW";
  cin >> s;
  for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
      vector<char> test(n + 1);
      test[0] = t[x];
      test[1] = t[y];
      for (int i = 1; i < n; i++) {
        test[i + 1] = func(test[i], test[i - 1], s[i]);
      }
      if (func(test[0], test[1], s[0]) != test[n - 1] || test[n] != test[0]) continue;
      for (int i = 0; i < n; i++) {
        cout << test[i];
      }
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;	
}

Measured memory_bytes: 640
from itertools import permutations


def check(queen):
    for r1, c1 in queen:
        if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2)
                   for r2, c2 in queen):
            return False
    return True


N = int(input())
row, col = list(range(8)), list(range(8))
queen = []
for _ in range(N):
    r, c = map(int, input().split())
    queen.append((r, c))
    row.remove(r)
    col.remove(c)

for l in permutations(col):
    queen_tmp = queen[:]
    for r, c in zip(row, l):
        queen_tmp.append((r, c))
    if check(queen_tmp):
        board = [''.join('Q' if (r, c) in queen_tmp else '.' for c in range(8)) for r in range(8)]
        print(*board, sep='\n')
        break


Measured memory_bytes: 5668
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    int n, a, b;
    string str;
    int pass = 0, foregn = 0;
    cin >> n >> a >> b >> str;
    rep(i,str.size()){
        if(str[i] == 'a'){
            if(pass < a + b){
                cout << "Yes" << endl;
                pass++;
            }else{
                cout << "No" << endl;
            }
        }else if(str[i] == 'b'){
            foregn++;
            if(pass < a + b &&  foregn <= b){
                cout << "Yes" << endl;
                pass++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 896
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
ABC=n3(n)
ABC

dp=[[0,0,0] for _ in range(n)]
dp[0]=ABC[0]
for i in range(1,n):
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+ABC[i][0]
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+ABC[i][1]
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+ABC[i][2]

print(max(dp[-1]))

Measured memory_bytes: 76760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
 
using namespace std;
#define MAXN 2000000
#define MOD 1000000007
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
int fac[MAXN+5], e[MAXN+5]; int X1, Y1, X2, Y2, X3, Y3, X4, Y4, X5, Y5, X6, Y6, ans, MX;
inline int fastpow(int s, int n){int a = 1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;}
inline int C(int n, int k){if(n<0||k<0||n<k) return 0; if(!k||n==k) return 1; return 1ll*fac[n]*e[k]%MOD*e[n-k]%MOD;}
#define f(sx,sy,tx,ty) (C(abs((sx)-(tx))+abs((sy)-(ty)),abs((sy)-(ty))))
inline int F(int sx, int sy, int tx1, int ty1, int tx2, int ty2, bool dir)
{
	return (dir ? 0ll+f(sx,sy,tx1,ty1)+f(sx,sy,tx2+1,ty2+1)+MOD-f(sx,sy,tx1,ty2+1)+MOD-f(sx,sy,tx2+1,ty1)
				: 0ll+f(sx,sy,tx2,ty2)+f(sx,sy,tx1-1,ty1-1)+MOD-f(sx,sy,tx2,ty1-1)+MOD-f(sx,sy,tx1-1,ty2)) % MOD;
}
int main()
{
	X1 = read(), X2 = read(), X3 = read(), X4 = read(), X5 = read(), X6 = read(), Y1 = read(), Y2 = read(), Y3 = read(), Y4 = read(), Y5 = read(), Y6 = read(), MX = max(Y6-Y1,X6-X1)<<1;
	fac[0] = 1; for(rint i = 1; i <= MX; fac[i] = 1ll*fac[i-1]*i%MOD, i++); e[MX] = fastpow(fac[MX],MOD-2); for(rint i = MX; i; e[i-1] = 1ll*e[i]*i%MOD, i--);
	for(rint x = X3, y = Y4; x <= X4; ans += 	1ll*F(x,y,X1,Y1,X2,Y2,0)*F(x,y+1,X5,Y5,X6,Y6,1)%MOD*(x+y  )%MOD, ans<MOD?:ans-=MOD, x++);
	for(rint x = X3, y = Y3; x <= X4; ans +=MOD-1ll*F(x,y-1,X1,Y1,X2,Y2,0)*F(x,y,X5,Y5,X6,Y6,1)%MOD*(x+y-1)%MOD, ans<MOD?:ans-=MOD, x++);
	for(rint x = X4, y = Y3; y <= Y4; ans += 	1ll*F(x,y,X1,Y1,X2,Y2,0)*F(x+1,y,X5,Y5,X6,Y6,1)%MOD*(x+y  )%MOD, ans<MOD?:ans-=MOD, y++);
	for(rint x = X3, y = Y3; y <= Y4; ans +=MOD-1ll*F(x-1,y,X1,Y1,X2,Y2,0)*F(x,y,X5,Y5,X6,Y6,1)%MOD*(x+y-1)%MOD, ans<MOD?:ans-=MOD, y++); printf("%d\n",ans); return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
using namespace std;
#define MAP_SIZE 10

class Pos {
  public:
    Pos(int x, int y) : x(x), y(y) {}
    int x, y;
    bool alive(Pos p) { return p.x - 1 <= this->x && this->x <= p.x + 1 && p.y - 1 <= this->y && this->y <= p.y + 1; }
};

int dx[12] = {-2, -2, -2, 2, 2, 2, -1, 0, 1, -1, 0, 1};
int dy[12] = {-1, 0, 1, -1, 0, 1, -2, -2, -2, 2, 2, 2};
bool move(Pos p, vector<Pos> sc, int n) { 
  if (p.x < 0 || MAP_SIZE <= p.x || p.y < 0 || MAP_SIZE <= p.y) return false;
  if (n == -1) return true;
  if (!p.alive(sc[n--])) return false;
  sc.pop_back();
  bool result = false;
  for (int i = 0; i < 12; i++) {
    if (move(Pos(p.x + dx[i], p.y + dy[i]), sc, n)) result = true;
    if (result) break;
  }
  return result;
}

int main() {
  int x, y, n;
  while (cin >> x >> y) { 
    if (x == 0 && y == 0) break;
    Pos p = Pos(x, y);
  
    cin >> n;
    vector<Pos> sc = { p };
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      sc.insert(sc.begin(), Pos(x, y));
    }
    cout << (move(p, sc, n) ? "OK" : "NA") << endl;
  }
  return 0;
}

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

int main()
{
    ll n, p;
    string s;
    cin >> n >> p >> s;
    ll ans = 0;
    if (p ==  2 || p == 5) {
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0')%p == 0) ans += i + 1;
        }
    }
    else {
        map<ll,ll> cnt;
        cnt[0]++;
        ll num = 0, ten = 1;
        for (int i = n - 1; i >= 0; i--) {
            num = num + (s[i] - '0') * ten;
            ten *= 10;
            ten %= p;
            num %= p;
            cnt[num]++;
        }
        for (auto x:cnt) {
            ans += x.second * (x.second - 1) / 2;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1028
import sys
sys.setrecursionlimit(10**7)

class Node:
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right

def get_depth(T:dict,u:int):
    d = 0
    while T[u] != -1:
        u = T[u].parent
        d += 1

D = {}

def get_all_depth(T:dict,u:int,p:int):
    D[u] = p
    if T[u].left != -1:
        get_all_depth(T,T[u].left,p+1)
    if T[u].right != -1:
        get_all_depth(T,T[u].right,p+1)

H = {}

def get_all_height(T:dict,u:int):
    h1 = 0
    h2 = 0
    if T[u].right != -1:
        h1 = get_all_height(T,T[u].right)+1
    if T[u].left != -1:
        h2 = get_all_height(T,T[u].left)+1
    H[u] = max(h1,h2)
    return H[u]

def get_sibling(T:dict,u:int):
    if T[u].parent == -1:
        return -1
    if T[T[u].parent].left != u and T[T[u].parent].left != -1:
        return T[T[u].parent].left
    if T[T[u].parent].right != u and T[T[u].parent].right != -1:
        return T[T[u].parent].right
    return -1

def PRINT(T:dict,node:int,D:dict,H:dict):
    dig = (T[node].right!=-1)+(T[node].left!=-1)
    if (T[node].left==-1) and (T[node].right==-1):
        node_type = "leaf"
    else:
        node_type = "internal node"
    if T[node].parent == -1:
        node_type = "root"
    print(f"node {node}: parent = {T[node].parent}, sibling = {get_sibling(T,node)}, degree = {dig}, depth = {D[node]}, height = {H[node]}, {node_type}")

n = int(input())
T = {k: Node(-1,-1,-1) for k in range(n)}
    
for _ in range(n):
    a,b,c = map(int,input().split())
    T[a].left = b
    T[a].right = c
    if b != -1:
        T[b].parent = a
    if c != -1:
        T[c].parent = a
for node in range(n):
    if T[node].parent == -1:
        get_all_depth(T,node,0)
        get_all_height(T,node)
        break
for node in range(n):
    PRINT(T,node,D,H)


Measured memory_bytes: 5656
def d_powerful_discount_tickets():
    import heapq
    N, M = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    # 参考: https://juppy.hatenablog.com/entry/2019/04/05/蟻本_Python_プライオリティキュー_2_heapq_競技プログラミン
    def _heappush_max(heap, item):
        heap.append(item)
        heapq._siftdown_max(heap, 0, len(heap) - 1)

    def _heappop_max(heap):
        """Maxheap version of a heappop."""
        lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
        if heap:
            returnitem = heap[0]
            heap[0] = lastelt
            heapq._siftup_max(heap, 0)
            return returnitem
        return lastelt

    heapq._heapify_max(A)
    for _ in range(M):
        _heappush_max(A, _heappop_max(A) // 2)
    return sum(A)

print(d_powerful_discount_tickets())

Measured memory_bytes: 14180
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  long n;
  cin >> n;
  unsigned long long result = 0;
  for (long i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      result += i;
    }
  }
  cout << result;
  return 0;
}


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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<long long> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int bound = lower_bound(v.begin(), v.end(), 0) - v.begin();
	vector<long long> minus(bound + 1), plus(n - bound + 1);
	for (int i = 0; i < bound; i++) {
		minus[i] = v[i];
	}
	minus[bound] = 0;
	reverse(minus.begin(), minus.end());
	for (int i = 1; i <= n - bound; i++) {
		plus[i] = v[i - 1 + bound];
	}
	plus[0] = 0;
	int first_p = min(n - bound, k);
	long long m = 1000000000;
	for (int i = first_p; i >= 0; i--) {
		m = min(min(m, plus[i] - 2 * minus[k - i]), 2 * plus[i] - minus[k - i]);
		if (k - i == bound) {
			break;
		}
	}
	cout << m << endl;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
        var n int
        fmt.Scan(&n)

        var a int
        cnt4 := 0
        cnt2 := 0
        for i := 0; i < n; i++ {
                fmt.Scan(&a)
                if a%4 == 0 {
                        cnt4 = cnt4 + 1
                } else if a%2 == 0 {
                        cnt2 = cnt2 + 1
                }
        }

        answer := "No"
        if n/2 <= (cnt4 + cnt2/2) {
                answer = "Yes"
        }

        fmt.Printf("%s\n", answer)
}


Measured memory_bytes: 5504
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    set<string> used;
    cout << "?aaaaa" << endl;

    int i = 0;
    for(;;){
        string s;
        cin >> s;
        if(s[0] != 'a' || used.find(s) != used.end()){
            cout << "!OUT" << endl;
            return 0;
        }
        used.insert(s);

        s = s[s.size()-1];
        if(i == 26)
            s += "aa";
        else
            s += 'a' + i;
        s += 'a';
        ++ i;

        cout << '?' << s << endl;
    }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
int main() {
	int N;
	cin>>N;
	if(N==1){
		cout<<1<<endl;
		return 0;
	}
	vint X,Y;
	map<pint, int> pam;
	for(int i=0;i<N;i++){
		int x,y;
		cin>>x>>y;
		X.pb(x);
		Y.pb(y);
		pam[mp(x,y)]=1;
	}
	int ans=INF;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==j)
				continue;
			int p=X[i]-X[j],q=Y[i]-Y[j];
			//cout<<p<<" "<<q<<" : ";
			int temp=0;
			for(int k=0;k<N;k++){
				int x=X[k], y=Y[k];
				if(pam.find(mp(x+p, y+q))==pam.end())
					temp++;
			}
			ans=min(ans, temp);
			//cout<<temp<<endl;
		}
	}
	//cout<<ans<<endl;
	cout<<max(ans,1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int N; cin >> N;
  ll A[N];
  rep(i, N) cin >> A[i];
  ll S = 0;
  rep(i, N) S += A[i];
  ll sunuke = A[0];
  ll ans = abs(sunuke - (S - sunuke));
  for(int i = 1; i < N - 1; i++){
    sunuke += A[i];
    ans = min(ans, abs(sunuke - (S - sunuke)));
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    int d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

/*
*/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}


#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;


int main()
{
	ll H, W;
	cin >> H >> W;
	vector<string> C(H);
	REP(i, H) {
		cin >> C[i];
	}

	REP(i,H){
		cout<<C[i]<<endl<<C[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a_count =0
b_count =0
ab_count =0
ab_alt =0
flag =0
for i in range(N):
    test = str(input())
    if test[0] == "B":
        b_count +=1
        flag =1
    if test[-1] == "A":
        a_count += 1
        if flag == 1:
            flag =0
            ab_alt +=1
    ab_count += test.count("AB")
if ab_alt != 0:
    if ab_alt == b_count:
        if ab_alt == a_count:
            a_count += -1
print(ab_count+min(a_count,b_count))


Measured memory_bytes: 3064
#B
import sys,math
s = list(input())
# print(s)
for i in range(len(s)):
    # print(s[i],s[len(s)-i-1])
    if s[i] != s[len(s)-i-1]:
        print('No')
        sys.exit()
n = (len(s) - 1) // 2
# print(n)
for i in range(n):
    # print(s[i], s[n - 1 - i])
    if s[i] != s[n - 1 - i]:
        print('No')
        sys.exit()
start = math.ceil((len(s) + 3) / 2)-1
# print(start)
for i in range(start, len(s)):
    # print(s[i], s[n - i])
    if s[i] != s[n - i]:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[11][10][10];
int row[10];
int col[10];
int dx[]={-2,-2,-2,-1,-1,0,0,1,1,2,2,2};
int dy[]={-1,0,1,-2,2,-2,2,-2,2,-1,0,1};
int ABS(int a){
	return a<0?-a:a;
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		int c;
		scanf("%d",&c);
		for(int i=0;i<11;i++)
			for(int j=0;j<10;j++)
				for(int k=0;k<10;k++)
					dp[i][j][k]=0;
		for(int i=0;i<c;i++){
			scanf("%d%d",row+i,col+i);
		}
		dp[0][a][b]=1;
		for(int i=0;i<c;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					if(dp[i][j][k]){
						for(int l=0;l<12;l++){
							if(0<=j+dx[l]&&j+dx[l]<10&&0<=k+dy[l]&&k+dy[l]<10&&max(ABS(row[i]-j-dx[l]),ABS(col[i]-k-dy[l]))<=1)dp[i+1][j+dx[l]][k+dy[l]]=1;
						}
					}
				}
			}
		}
		bool ok=false;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(dp[c][i][j])ok=true;
		if(ok)printf("OK\n");
		else printf("NA\n");
	}
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int one = 100*(n-m) + 1900*m;
	int ans = one*pow(2, m);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
//ISU
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    long long X,Y,Z;
    cin >> X >> Y >> Z;
    long long YZ = Y+Z;
    X -= Y+2*Z;
    long long ans = X/YZ + 1;
    cout << ans << endl;
    return 0;
}

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

int main() {
   int D,T,S;
   cin >> D  >> T >> S;
   int t=D/T;
   if (D%T!=0) t++;
   if (t<=S) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#undef strstr
using namespace std;
char s[110];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<=len;j++)
			if(s[j]=='F')
			return printf("Yes\n")&0;
			return printf("No\n")&0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
array = readlines.map{|n| n.chomp.to_i}

m_1 = array.max
m_1_count = array.count(m_1)
arr = array.dup
arr.delete(m_1)
m_2 = arr.max

N.times do |i|
  if array[i] == m_1
    if m_1_count == 1
      puts m_2
    else
      puts m_1
    end
  else
    puts m_1
  end
end


Measured memory_bytes: 22420
#include <bits/stdc++.h>
using namespace std;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e, f;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
    a *= 100; b *= 100;

    std::set<int> x, y;
    int water=0, sugar=0;
    for(int i=0; a * i <= f; i++)
    {
        for(int j=0; b * j <= f; j++)
        {
            water = a * i + b * j;
            if(water<=f && water!=0) x.insert(water);
        }
    }
    
    for(int i=0; c * i<=f; i++)
    {
        for(int j=0; d * j <= f; j++)
        {
            sugar = c * i + d * j;
            if(sugar<f) y.insert(sugar);
        }
    }
    double mx = -100;
    int ans_mass = -100, ans_sugar = -100;
    
    for(auto itr=x.begin(); itr!=x.end(); itr++)
    {
        for(auto jtr=y.begin(); jtr!=y.end(); jtr++)
        {
            // water : *itr, sugar : *jtr
            double mass = *itr + *jtr;
            if(mass > f) continue;
            double conc = (double)*jtr / mass;
            int solub = *itr * e / 100;
            if(solub < *jtr) continue;
            // printf("concentration : %lf ", conc);
            // printf("water : %d ", *itr);
            // printf("sugar : %d\n", *jtr);
            if(max(conc, mx)==conc)
            {
                ans_mass = mass;
                ans_sugar = *jtr;
                mx = conc;
            }
        }
    }
    printf("%d %d\n", ans_mass, ans_sugar);
    return 0;
}

Measured memory_bytes: 384