akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll N, W;
    cin >> N >> W;

    vector<int> v;
    vector<ll> w;

    int sum = 0;
    for(int i = 0; i < N; i++)
    {
        ll val, weight;
        cin >> weight >> val;
        v.push_back(val);
        w.push_back(weight);

        sum += val;
    }

    //dp[i][v] - min weight using i items get value v
    //dp[i][v] = min(dp[i-1][v], dp[i-1][v-v[i]] + w[i])
//    vector<vector<ll>> dp(N+1, vector<ll>(sum+1, INT_MAX));
//    dp[0][0] = 0;

//    for(int i = 1; i <= N; i++)
//    {
//        for(int j = 0; j <= sum; j++)
//        {
//            if(j - v[i-1] >= 0)
//                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
//            else
//                dp[i][j] = dp[i-1][j];
//        }
//    }

//    for(int i = N; i >= 1; i--)
//    {
//        for(int j = sum; j >= 0; j--)
//        {
//            if(dp[i][j] <= W)
//            {
//                cout << j << endl;
//                return 0;
//            }
//        }
//    }


    // dp[i][v] - min weight using items UP TO i to get value v
    vector<vector<ll>> dp(N, vector<ll>(sum+1, INT_MAX));
    dp[0][0] = 0;

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= sum; j++)
        {
            if(i == 0)
            {
                if(j == v[i])
                    dp[i][j] = w[i];
            }
            else {
                if(j - v[i] >= 0)
                    dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
                else
                    dp[i][j] = dp[i-1][j];
            }
        }
    }

    for(int i = N-1; i >= 0; i--)
    {
        for(int j = sum; j >= 0; j--)
        {
            if(dp[i][j] <= W)
            {
                cout << j << endl;
                return 0;
            }
        }
    }


    return 0;
}



Measured memory_bytes: 79488
e_1,e_2,e_3,e_4 = map(int,input().split())
if e_1 == e_2 and e_3 == e_4:
    print('yes')
elif e_1 == e_3 and e_2 == e_4:
    print('yes')
elif e_1 == e_4 and e_2 ==e_3:
    print('yes')
elif e_1 == e_2 == e_3 ==e_4:
    print('yes')
else:
    print('no')


Measured memory_bytes: 5596
#include <iostream>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC75(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC71();
}

void ABC71(void){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(a-x)<abs(b-x))cout<<'A'<<endl;
    else cout<<'B'<<endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n)cin >> a[i];
  vector<vector<int>> v(n+1,vector<int>(3,0));
  for(int i = 1;i <= n;i++){
    REP(j,3){
      if(a[i-1] != v[i-1][j])continue;
      v[i][j] = v[i-1][j]+1;
      REP(k,3)if(j != k)v[i][k] = v[i-1][k];
      break;
    }
  }
  ll res = 1;
  REP(i,n){
    ll sum = 0;
    REP(j,3)if(a[i] == v[i][j])sum++;
    res = res*sum%MOD;
  }
  cout << res << endl;




  return 0;
}

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

int a, b, c, x;

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

  cin >> a >> b >> c >> x;
  int ans = 0;

  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
	if (i*500 + j*100 + k*50 == x) ans++;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    ll ct = 0;
    for (int r = 0; r < n; ++r)
    {
        int right = -1;
        int left = -1;
        if (h[r] > 0)
        {
            right = r;
            left = r;

            for (int l = r; l < n; ++l)
            {
                if (h[l] == 0)
                {
                    left = l;
                    break;
                }
                left = l + 1;
            }

            if (left != -1 && right != -1)
            {
                ++ct;
                for (int j = right; j < left; ++j)
                {
                    h[j]--;
                }
                r = -1;
            }
        }
    }
    cout << ct << endl;
}


Measured memory_bytes: 3612
n = int(input())

def dfs(val, A):
	if val > n:
		return

	A.append(val)

	for v in [3, 5, 7]:
		dfs(10 * val + v, A)


A = []
for v in [3, 5, 7]:
	dfs(v, A)

cnt = 0
for v in A:
	if '3' in str(v) and '5' in str(v) and '7' in str(v):
		cnt += 1

print(cnt)

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll d;
    cin >> n >> d;
    int res=0;
    while(n--)
    {
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d*d) res++;
    }
    cout << res << "\n";
    return 0;
}


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

int main() {
    int N, K;
    int INF = INT_MAX;
    cin >> N >> K;
    vector<int> H(N);
    vector<int> dp(N, INF);
    for(int i=0; i<N; i++) cin >> H.at(i);

    dp.at(0) = 0;
    for(int i=1; i<N; i++) {
        for (int j=1; j<min(K, i)+1; j++) {
            dp.at(i) = min(dp.at(i), dp.at(i-j) + abs(H.at(i) - H.at(i-j)));
        }
    }
    cout << dp.at(N - 1) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
#define LM 55555
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

int A,B,C,X,Y,N, M[LM],num,v[55555],ch,ans;
string s, t;
bool a, b, c;
int main() {
	cin >> N;
	cin >> s;
	a = false;
	ch = 0;
	ans = 0;
	num = 0;
	for (int l = 0; l < N-1; l++) {
		t.clear();
		num = 0;
		for (int i = 0; i <= l; i++) {
			a = true;
			
			for (int k = 0; k < num; k++) {
				if (t[k] == s[i]) {
					a = false;
				}
			}
			if(a){
				for (int j = l+1; j < N; j++) {
					if (s[i] == s[j]) {
						t.push_back(s[i]);
						num++;
						ch++;
						break;
					}
				}
			}
		}
		ans = max(ch, ans);
		ch = 0;
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); ++itr)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;
set<int> edges[100005];
int color[100005];
int degree[100005];
int removed[100005];
int main(void)
{
	int n;
	scanf("%d", &n);
	FOR(i, 0, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--;
		v--;
		edges[u].insert(v);
		edges[v].insert(u);
		degree[u]++;
		degree[v]++;
	}
	queue<int> q;
	FOR(i, 0, n) {
		int cnt = 0;
		for (int j : edges[i]) {
			if (edges[j].size() == 1) {
				cnt++;
			}
		}
		if (cnt > 1) {
			cout << "First" << endl;
			return 0;
		}
		if (edges[i].size() == 1) {
			q.push(i);
		}
	}
	while (!q.empty()) {
		int i = q.front();
		q.pop();
		if (removed[i]) {
			continue;
		}
		int p = -1;
		for (int j : edges[i]) {
			if (color[j] == 0) {
				p = j;
				break;
			}
		}
		if (p == -1) {
			continue;
		}
		removed[p] = true;
		removed[i] = true;
		color[p] = 1;
		color[i] = 2;
		for (int j : edges[p]) {
			if (removed[j]) {
				continue;
			}
			degree[j]--;
			if (degree[j] == 1){
				q.push(j);
			}
		}
	}
	FOR(i, 0, n) {
		bool win = true;
		if (color[i] == 2) {
			continue;
		}
		for (int j : edges[i]) {
			if (color[j] == 2) {
				win = false;
				break;
			}
		}
		if (win) {
			cout << "First" << endl;
			return 0;
		}
	}
	cout << "Second" << endl;
}
/*
5
1 2
1 3
2 4
3 5
*/

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

using lint = long long int;
using pii = std::pair<int, int>;
using pll = std::pair<lint, lint>;
const double PI = 2.0 * acos(0.0);

using std::vector;
lint x1, x2, yy, y2;
int N;
vector<pll> ve;

bool range(lint t1, lint t2) {
	bool ret = ((std::min(x1, x2) <= t1 && t1 <= std::max(x1, x2)) && (std::min(yy, y2) <= t2 && t2 <= std::max(yy, y2)));
	return ret;
}
int main(void) {
	scanf("%lld %lld %lld %lld", &x1, &yy, &x2, &y2);
	if (x2 < x1) {
		std::swap(x1, x2); std::swap(yy, y2);
	}
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		lint t1, t2;
		scanf("%lld %lld", &t1, &t2);
		if (range(t1, t2)) {
			if (yy < y2) {
				ve.push_back(pll(t1, t2));
			}
			else {
				ve.push_back(pll(t1, -t2));
			}
		}
	}
	
	sort(ve.begin(), ve.end());
	double ans = 0;
	if (x1 == x2 || yy == y2) {
		ans += (std::max(x1, x2) - std::min(x1, x2) + std::max(yy, y2) - std::min(yy, y2)) * 100;
		if (ve.size() != 0) {
			ans -= 20;
			ans += (PI * 10);
		}
	}
	else {
		vector<lint> dp_v;
		for (int i = 0; i < ve.size(); i++) {
			if (dp_v.empty()) {
				dp_v.push_back(ve[i].second);
			}
			else {
				auto iter = std::lower_bound(dp_v.begin(), dp_v.end(), ve[i].second);
				if (iter == dp_v.end()) {
					dp_v.push_back(ve[i].second);
				}
				else {
					*iter = ve[i].second;
				}
			}
		}
		ans = (std::max(x1, x2) - std::min(x1, x2) + std::max(yy, y2) - std::min(yy, y2)) * 100;
		if (std::min(std::max(x1, x2) - std::min(x1, x2), std::max(yy, y2) - std::min(yy, y2)) + 1 == dp_v.size()) {
			ans -= dp_v.size() * 20;
			ans += (dp_v.size() - 1) * 5 * PI;
			ans += 10 * PI;
		}
		else {
			ans -= dp_v.size() * 20;
			ans += dp_v.size() * 5 * PI;
		}
	}
	printf("%.15lf", ans);

	return 0;
}

Measured memory_bytes: 7916
N = int(input())
A = list(input())
B = list(input())
C = list(input())


cnt = 0
i = 0
while True:
    if i >= N:
        i = 0
    if A == B and B == C:
        break
    if  A[i] != B[i] and B[i] != C[i]:
        B[i] = A[i]
        # C[i] = A[i]
        cnt += 1
    elif A[i] == B[i] and B[i] != C[i]:
       C[i] = B[i]
       cnt += 1
    elif A[i] != B[i] and B[i] == C[i]:
        A[i] = B[i]
        cnt += 1
    elif A[i] != B[i] and A[i] == C[i]:
        B[i] = A[i]
        cnt += 1
    i += 1

print(cnt)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  rep(i, 4001) rep(j, i+1) {
    c[i+1][j] += c[i][j];
    c[i+1][j+1] += c[i][j];
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
mint f2(int n, int k) {
  return comb(n+k-1,k-1);
}
mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  if (k < 1) return 0;
  return f2(n-k,k);
}

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

  int n, k; std::cin >> n >> k;
  init();
  rrep(i, k) {
    mint blue = f(k, i);
    mint red = f2(n-k-(i-1), i+1);
    mint ans = blue * red;
    printf("%lld\n", ans.x);
  }
}


Measured memory_bytes: 125568
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("in.txt","r",stdin)
#define     fwrite    freopen("o.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))

int main()
{
    __
    //fopen;
    //fwrite;

	ll n,m,g;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	g=__gcd(n,m);
	ll ans=(n*m)/g;
	for(int i=0,j=0; i<n; i+=n/g, j+=m/g )
    {
        if(s[i]!=t[j])
        {
            puts("-1");
            exit(0);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) (((a) >> (b)) & 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;

signed main() {
  cin >> N;

  int tmp = N, sum = 0, cont = 0;
  while (tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
    cont++;
  }

  int ans = N / pow(10, cont - 1);
  ans += (cont - 1) * 9 - 1;

  chmax(ans, sum);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M = list(map(int,input().split()))
inflows = [0]*(N+1)
edges = [[] for i in range(N+1)]
for i in range(M):
    x,y = list(map(int,input().split()))
    edges[x].append(y)
    inflows[y] += 1

queue = deque([i for i in range(1,N+1) if inflows[i] == 0])
DP = [0]*(N+1)
while queue:
    x = queue.popleft()
    for y in edges[x]:
        inflows[y] -= 1
        DP[y] = max(DP[y],DP[x]+1)
        if inflows[y] == 0:
            queue.append(y)

print(max(DP))


Measured memory_bytes: 60832
import numpy as np
dic = dict()
mod = 10 ** 9 + 7
p = 0

def reg(a, b):
	if a < 0 or (a == 0 and b < 0):
		a, b = -a, -b
	if b > 0:
		return 0, a, b
	else:
		return 1, -b, a

n = int(input())
for _ in range(n):
	a, b = map(int, input().split())
	if a == 0 and b == 0:
		p += 1
		continue
	ab = np.gcd(a, b)
	a, b = a//ab, b//ab
	idx, a, b = reg(a, b)
	k = (a, b)
	if k not in dic.keys():
		dic[k] = [0, 0]
	dic[k][idx] += 1

not_p = 1
for k in dic.keys():
	a, b = k
	pp, pm = dic[k]
	not_p *= (pow(2, pp, mod) + pow(2, pm, mod) - 1) % mod
	not_p %= mod

print((p + not_p -1) % mod)

Measured memory_bytes: 78084
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

count = 0

for n in range(N - 1, -1, -1):
    count += min(A[n + 1], B[n])
    if B[n] - A[n + 1] >= 0:
        if A[n] >= B[n] - A[n + 1]:
            A[n] -= (B[n] - A[n + 1])
            count += B[n] - A[n + 1]
        else:
            count += A[n]
            A[n] = 0
    else:
        B[n] = 0
        A[n + 1] -= B[n]
        

print(count)

Measured memory_bytes: 19648
def inpl(): return [int(i) for i in input().split()]
import numpy as np

N = int(input())
A = np.sort(np.array(inpl()))
B = np.cumsum(A)

ans = 0
for i in range(N-1):
    ans += 1
    if B[i]*2 < A[i+1]:
        ans = 0

print(ans+1)

Measured memory_bytes: 31332
//<<???????¨????????????????>>?¬¬??????????¢?
//DFS
#include <iostream>
#include <stdio.h>
#define MAX_W 101
#define MAX_H 101
using namespace std;
int w,h;
int res;
int dx[4]={0,-1,1,0};
int dy[4]={-1,0,0,1};
char loc[MAX_H][MAX_W];

void DFS(int a,int b,char c)
{
    loc[a][b]='o';
    for(int i=0;i<4;i++)
    {
        int x=a+dx[i],y=b+dy[i];
        if(x<h&&y<w&&x>=0&&y>=0&&loc[x][y]==c) DFS(x,y,c);
    }
    return;
}

int main()
{
    int a1,b1;
    int a2,b2;
    while(true)
    {
        cin>>h>>w;
        if(w==0&&h==0) break;
        res=0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                cin>>loc[i][j];
            }
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(loc[i][j]!='o')
                {
                    DFS(i,j,loc[i][j]);
                    res++;
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <inttypes.h>

int ok(uint64_t s_num, uint64_t c_num, uint64_t target_num) {
	uint64_t s_tarinai;
	uint64_t c_as_c, c_as_s;
	if (s_num < target_num) {
		s_tarinai = target_num - s_num;
	} else {
		s_tarinai = 0;
	}
	c_as_c = target_num * 2;
	c_as_s = s_tarinai * 2;
	return c_as_c + c_as_s <= c_num;
}

int main(void) {
	uint64_t N, M;
	uint64_t left, right, mid;
	uint64_t answer = 0;
	if (scanf("%"SCNu64"%"SCNu64, &N, &M) != 2) return 1;
	left = 0;
	right = N + M;
	while (left <= right) {
		mid = (left + right) / 2;
		if (ok(N, M, mid)) {
			if (mid > answer) answer = mid;
			left = mid + 1;
		} else {
			right = mid - 1;
		}
	}
	printf("%"PRIu64"\n", answer);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N=105;
const int INF=0x3f3f3f3f;
char s[N][N];
int f[N][N][2];
int main() {
    //freopen("in.txt","r",stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) {
        scanf("%s",s[i]+1);
    }
    memset(f,INF,sizeof f);
    f[1][1][0]=f[1][1][1]=(s[1][1]=='#');
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(i==1&&j==1) continue;
            f[i][j][0]=min(f[i][j-1][1]+(s[i][j]=='#'),f[i][j-1][0]+(s[i][j-1]=='.'&&s[i][j]=='#'));
            f[i][j][1]=min(f[i-1][j][0]+(s[i][j]=='#'),f[i-1][j][1]+(s[i-1][j]=='.'&&s[i][j]=='#'));
            if(s[i][j]=='#') {
                if(s[i][j-1]=='#') f[i][j][0]=min(f[i][j][0],min(f[i][j-1][0],f[i][j-1][1]));
                if(s[i-1][j]=='#') f[i][j][1]=min(f[i][j][0],min(f[i-1][j][0],f[i-1][j][1]));
            }
        }
    }
    printf("%d\n",min(f[n][m][0],f[n][m][1]));
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String st = in.readLine();
		String S = in.readLine();


		String[] stSplit = st.split(" ");
		int N = Integer.parseInt(stSplit[0]);
		int A = Integer.parseInt(stSplit[1])-1;
		int B = Integer.parseInt(stSplit[2])-1;
		int C = Integer.parseInt(stSplit[3])-1;
		int D = Integer.parseInt(stSplit[4])-1;

		char[] sChar = S.toCharArray();

		boolean nothreeSpace = true;
		boolean wRock = false;
		int bigger = C;
		int i=B-1;
		if(D < C){
			while(i<sChar.length-2 && i < D){
				if(sChar[i+2]=='#'){
					i+=3;
				}else if(sChar[i+1]=='#'){
					i+=2;
				}else if(sChar[i]=='#'){
					i+=1;
				}else{
					//最初に見つかった...の中にDが存在する場合、#D..または..D#の場合はAがBを追い越せない
//					if(i==D && sChar[D-1]=='#'){
//						break;
//					}else if(i+2==D && sChar[D+1]=='#'){
//						break;
//					}
					nothreeSpace = false;
					break;
				}
			}
			bigger = C;
		}else{
			bigger = D;
		}

		i=A;
		while(i < bigger && i < sChar.length -1 ){
			if(sChar[i+1] == '#'){
				if(sChar[i] == '#'){
					wRock = true;
					break;
				}else{
					i+=1;
				}
			}else{
				i+=2;
			}
		}

		String ans = "Yes";
		if(wRock == true){
			ans = "No";
		}else{
			if(D < C){
				if(nothreeSpace == true){
					ans = "No";
				}
			}
		}

		System.out.println(ans);
	}
}

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

int main() {
  int A;
  cin >> A;
  if (A>194) {cout << 5 << endl;}
  else if (A>188) {cout << 4 << endl;}
  else if (A>164) {cout << 3 << endl;}
  else if (A>134) {cout << 2 << endl;}
  else if (A>104) {cout << 1 << endl;}
  else {cout << 0 << endl;}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		ma m = new ma();
		long x = sc.nextLong();
		long count = 0;
		long v = 100;
		while(v < x) {
			v = m.next(v);
			count++;
		}
		System.out.println(count);
	}
	
	static class ma {
		public long value;
		public long next(long x) {
			long re = (long)Math.floor(x*1.01);
			return re;
		}
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32800
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

dx = [-1,0,1,0]
dy = [0,-1,0,1]

def readInts():
  return list(map(int,input().split()))
def search(S,y,x,h,w):
    #全探索で間に合うべ
    cnt = 0
    #print(y,x)
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        #print('nya',ny,nx)
        if 0 <= nx < w and 0 <= ny < h:
            #print('here',nx,ny)
            if S[ny][nx] == '#':
                cnt += 1
    #print(cnt)
    if cnt == 0:#隣接する#が一つもない
        return False
    else:
        return True

def main():
    h,w = readInts()
    S = [input() for _ in range(h)]
    #print(S)
    for i in range(h):
        for j in range(w):
            if S[i][j] == '#':
                #print(i,j)
                if search(S,i,j,h,w):
                    pass
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int dp[N][3];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (i == 0) {
            dp[0][0] = a, dp[i][1] = b, dp[i][2] = c;
        }
        else {
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b;
            dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c;
        }
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}


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

void Main()
{
    int h, n;
    cin >> h >> n;
    long d = 0;
    for (int i = 0; i < n; i++)
    {
        long a;
        cin >> a;
        d += a;
        if(d >= h) {
            cout << "Yes" << endl;
            return;
        }
    }
    
    cout << "No" << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int n, sum = 0, m;
		cin >> m >> n ;
		int a[n];
		for(int i = 0 ; i < n ; i++){
			cin >> a[i];
			sum += a[i];	
		}
		int ans = max(m - sum, -1ll);
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<string> VS;
//template
template<class T> inline bool chmin(T &a, T b) {if (a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) {if (a < b){a = b; return true;} return false;}
//repetition
#define FOR(i,a,b) for(int i=int(a); i<int(b); ++i)
#define FORD(i,a,b) for(int i=int(a); i<int(b); --i)
#define REP(i,N) for(int i=0; i<int(N); ++i)
#define REPS(i,N) for(int i=0; i<=int(N); ++i)
#define REPD(i,N) for(int i=0; i<int(N); --i)
//container util
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//constant
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //配列の最大のrenge
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void my_prime_factorize(ll n, map<ll,ll> &prime) {
    if(n<=1) return;
    ll l=sqrt(n);
    FOR(i,2,l+1){
        if(n%i==0){
        my_prime_factorize(i,prime);my_prime_factorize(ll(n/i),prime);return;
        }
    }

    prime[n]++;return;
}

int main() {
    ll N; cin >> N;
    ll res = 1;

    FOR(j,1,N-1) {
        map<ll,ll> prime;
        ll tmp = N - j;
        ll tmp2 = 1;

        my_prime_factorize(tmp,prime);
        for (auto dt : prime) {
            tmp2 *= (dt.second + 1);
        }
        res += tmp2;
    }

    cout << res << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

	i64 ans = std::max({a * c, a * d, b * c, b * d});
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3812
#include<stdio.h>
#include<stdlib.h>

int main(void){
  
  long int a,b;
  
  scanf("%ld %ld",&a,&b);
  
  if(a <= 0 && b >= 0){
    printf("Zero");
  }else if(a > 0 && b > 0){
    printf("Positive");
  }else{
    if(abs(a - b) % 2 ==0){
      printf("Negative");
    }else{
      printf("Positive");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,q;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;
    int k[q];
    rep(i,q){
        cin >> k[i];
    }
    rep(i,q){
        ll d = 0, m = 0, dm = 0;
        ll ans = 0;
        for(int j = 0; j < n; j++){
            if(s[j] == 'D'){
                d++;
            }else if(s[j] == 'M'){
                m++;
                dm += d;
            }else if(s[j] == 'C'){
                ans += dm;
            }
            if(j - (k[i] - 1) < 0) continue;
            if(s[j - (k[i] - 1)] == 'D'){
                d--;
                dm -= m;
            }else if(s[j - (k[i] - 1)] == 'M'){
                m--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(void){
    string s;
    cin >> s;
    if(s[0] == s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>

int main()
{
		int d, n;
		std::cin >> d >> n;

		if( n == 100 ) {
			n = n + 1;
		}
		int a = pow( 100, d ) * n;
		std::cout << a << std::endl;
		return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    Fr(i,9) Fr(j,9){
        if(n==i*j){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function abmp(a,b,p);if b==0;1;elseif b%2==0;k=abmp(a,div(b,2),p);(k*k)%p;else;(a*abmp(a,b-1,p))%p;end;end
function binarr(n,p);z=1;for i in 1:n;z=z*i%p;end;fac=zeros(Int,n+1);inv=zeros(Int,n+1);inv[n+1]=abmp(z,p-2,p)
for i in 0:n-1;inv[n-i]=(inv[n+1-i]*(n-i))%p;end;for i in 0:n;fac[i+1]=(((z*inv[i+1])%p)*inv[n+1-i])%p;end;fac;end
const p = 998244353

function main()
	n,m,k = readline() |> split |> parseMap
	ans = 0
	bin = binarr(n-1,p)
	now = m
	for i in 2:n-k
		now=now*(m-1)%p
	end
	for i in k:-1:0
		ans = (ans+(bin[n-i]*now)%p)%p
		now=now*(m-1)%p
	end
	println(ans)
end

main()

Measured memory_bytes: 173800
#include <iostream>
using namespace std;
long long w[103],v[103],f[103][100005];
int main()
{
    long long N,W;
    cin>>N>>W;
    for (long long i=1;i<=N;++i)
    {
        cin>>w[i]>>v[i];
    }
    for (long long i=1;i<=N;++i)
    {
        for (long long j=0;j<=W;++j)
        {
            if (j>=w[i])
            {
                f[i][j]=max(f[i-1][j-w[i]]+v[i],f[i-1][j]);
            } else f[i][j]=f[i-1][j];
        }
    }
    cout<<f[N][W];
    return 0;
}


Measured memory_bytes: 81716
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N, M = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

L=0
R=N
for i in range(M):
	l, r = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

	L=max(L,l)
	R=min(R,r)
	
	p("l,r,L,R",l,r,L,R)

ans = max(0, R-L+1)

print(ans)

p("l,r,L,R",l,r,L,R)
p(ans)



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

int BubbleSort(int A[],int N){
	int sw=0;
	bool flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=N-1;i+1<=j;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				sw++;
				flag=1;
			}
		}
	}
	return sw;
}

int main(){
	int A[100],N,sw;
	cin>>N;
	for(int t=0;t<N;t++)cin>>A[t];

	sw=BubbleSort(A,N);

	for(int t=0;t<N;t++){
		if(t) cout<<" ";
		cout<<A[t];
	}
	cout<<"\n";
	cout<<sw<<"\n";
	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define FOR(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define MOD 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll dp[105][N],pref[105][N];
int main()
{
 ll n,k;cin>>n>>k;
 ll a[n+1];
 for(int i=1;i<=n;i++)
        cin>>a[i];

  for(int i=0;i<=n;i++)dp[i][0] = pref[i][0]=1;
  for(int i=0;i<=k;i++)pref[0][i]=1; 

    for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=k;j++)
      {
        ll last = pref[i-1][j];

        ll first = (j-a[i]-1 >=0)?pref[i-1][j-a[i]-1]:0;
         dp[i][j] += (MOD+last-first)%MOD;
            pref[i][j] = (pref[i][j - 1]+dp[i][j])%MOD;
      }
    }
    cout<<dp[n][k]%MOD;
}

Measured memory_bytes: 160128
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(input())
gcd_sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            gcd_sum+=gcd(a,b,c)

print(gcd_sum)

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

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




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,k;
  cin>>n>>k;
  vector<int>h(n);
  rep(i,n) cin>>h[i];
  ll ans=0;
  sort(h.rbegin(),h.rend());
  if(n>k){
  rep(i,k){
    h[i]=0;
  }
  rep(i,n){
    ans+=h[i];
  }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
/// Template by Zayed ///

///************************************************************///
/// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>

#include <string>
#include <cstring>
#include <sstream>

#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
//#include<unordered_map>
#include <set>
//#include<unordered_set>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
///************************************************************///
using namespace std;
int caseno = 1;
///************************************************************///
#define NL '\n'
#define SF scanf
#define PF printf
#define PC() printf("Case %d: ", caseno++)//NOTES:printf
//#define PC cout << "Case "//NOTES:cout
//#define CN cout << caseno++ << ": "//NOTES:cout
#define CLR(ar) memset(ar, 0, sizeof(ar))
#define SET(ar) memset(ar, -1, sizeof(ar))
#define READ() freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST std::ios_base::sync_with_stdio(0);
///************************************************************///
typedef long long LL;//NOTES:"%lld"
typedef unsigned long long ULL;//NOTES:"%llu"
///************************************************************///
#define INF (1 << 31) - 1
#define MOD 1000000007
#define PRIME 999998727899999 			// (largest prime below 10^16)
#define PB push_back
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define pLL pair<LL, LL>
#define pis pair<int, string>
#define psi pair<string, int>
#define pss pair<string, string>
#define PI 2 * acos(0.0)
#define EPS 1e-11
///************************************************************///
// Numeric Functions
template < class T > inline void SWAP(T &a, T &b) { T t = a; a = b; b = t; }
inline LL POW(LL base, LL power){
	LL res = base; if (power == 0) return 1;
	for (int I = 0; I < power - 1; I++) res *= base; return res;
}
// Translator Functions
int ToInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToInt(
double ToDouble(string s) { double r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToDouble(
string ToString(int n) { string s; stringstream convert; convert << n; s = convert.str(); return s; }//NOTES:ToString(
///************************************************************///

/*
*******4 Direction Array*******
int dx[] = {0, 0, - 1, 1}, dy[] = {-1, 1, 0, 0};
*******8 Direction Array*******
int dx[] = {0, 0, -1, +1, -1, -1, +1, +1}, dy[] = {-1, +1, 0, 0, -1, +1, -1, +1};
********Knight Moves********
int dx[] = {-2, -2, -1, -1, +1, +1, +2, +2}, dy[] = {-1, +1, -2, +2, -2, +2, -1, +1};
*/

const LL SIZE = 2e5 + 10;
int ar[SIZE];



int main()
{
	BOOST
	///READ();
	///WRITE();
	int T, I, J, K, N, n, m, cnt = 0, len;

	cin >> n;

	LL x = 0, y = 0;

	for(I = 0; I < n; I++)
	{
		cin >> ar[I];
		y += ar[I];
	}

	LL mn = 1e18, k;

	for(I = 0; I < n - 1; I++)
	{
        x += ar[I];
        y -= ar[I];

		k = abs(x - y);
		mn = min(mn, k);
	}

	cout << mn << NL;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;




int main(){
  long long int n,m;
  cin >> n >> m;
  long long int ans;
  if(n>2 && m > 2){
    ans = (n-2)*(m-2);
  }
  else if(n==2 || m == 2){
    ans = 0;
  }
  else{
    if(n*m >= 3){
      ans = n*m-2;
    }
    else if(n*m==2){
      ans = 0;
    }
    else{
      ans = 1;
    }
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n; ll k;
    cin >> n >> k;
    vector<ll> v(n+1);
    rep(i, 1, n+1)
        cin >> v[i];
    vector<bool> a(n+1, false);
    ll i = 1;
    a[i] = true;
    vector<ll> chain;
    chain.push_back(1);
    ll next;
    while(true)
    {
        next = v[i];
        if (a[next] == true)
            break;
        i = next;
        a[next] = true;
        chain.push_back(next);
    }
    vector<ll> chain2;
    bool y = false;
    rep(i, 0, chain.size())
    {
        if (chain[i] == next)
            y = true;
        if (y == true)
            chain2.push_back(chain[i]);
    }
    if (k < chain.size())
        cout << chain[k];
    else 
    {
        ll rem = chain.size() - chain2.size();
        k = k - rem;
        ll index = k%chain2.size();
        cout << chain2[index];
    }
    return 0;
}

Measured memory_bytes: 9296
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

#define ll long long
#define PII pair<ll,pair<ll,ll>>
#define print(arr,s,n) for (int i = s; i < n; ++i) cout<<arr[i]<<" "; cout<<endl;
#define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

using namespace std;
using namespace __gnu_pbds;

void solve()
{
	int n;
	cin>>n;	
	int k = n;
	int ans = 1;
	while((k%360))
	{
		k+=n;
		ans++;
	}
	cout<<ans<<endl;
}

int main()
{ 

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

	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>

int cnt[256];

int main(void) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        char str[16];
        scanf("%s", str);
        ++cnt[(int)str[0]];
    }

    int A[5] = {cnt['M'], cnt['A'], cnt['R'], cnt['C'], cnt['H']};

    long long result = 0;
    for (int i = 0; i < 5; ++i)
        for (int j = i + 1; j < 5; ++j)
            for (int k = j + 1; k < 5; ++k)
                result += (long long)A[i] * (long long)A[j] * A[k];
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    private static final int SIZE = 1000000;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            System.out.println(primeCount(sc.nextInt()));
        }
        sc.close();
    }

    static int primeCount(int n) {
        ArrayList<Integer> primeList = new ArrayList<Integer>(SIZE);
        primeList.add(2);
        primeList.add(3);
        int count = 2;
        if(n<4) {
            return n-1;
        }
        for (int i = 5; i <= n; i += 2) { //対象は奇数のみ
            boolean wflag = false; //割り切れたかどうか
            for (int j = 1; primeList.get(j) * primeList.get(j) <= i; j++) {
                // 対象の数の平方根以下の全ての素数で除算する
                if (0 == i % primeList.get(j)) { //割り切れたら素数ではない
                    wflag = true;
                    break;
                }
            }
            if (!wflag) { //最後まで割り切れなかったら
                primeList.add(i); //素数として新たに登録
                count++;
            }
        }
        return count;
    }
}


Measured memory_bytes: 90052
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
#include<cctype>
using namespace std;

int main() {
    string s;
    cin>>s;
    for(int bit=0; bit<(1<<3); bit++){
        int ans=s[0]-'0';
        string sen;
        sen+=s[0];
        for(int i=0; i<3; i++){
            if(bit&1<<i){
                ans+=s[i+1]-'0';
                sen+="+";
                sen+=s[i+1];
            }else {
                ans-=s[i+1]-'0';
                sen+="-";
                sen+=s[i+1];
            }
        }
        if(ans==7){
            cout<<sen<<"=7"<<endl;
            break;
        }
    }
}


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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
  int k;
  cin >> k;
  
  int sum = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        sum += gcd(gcd(i, j), l);
      }
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3632