akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

#define M_PI 3.141592653589793

int main(void) {

	int i, j, k, n;
	int num;
	int b, f, r, v;
	int data[4][3][10] = { 0 };//?£?,???,??¨?±?

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		data[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				printf(" %d", data[i][j][k]);
			}printf("\n");
		}
		printf("####################\n");
	}
	for (j = 0; j < 3; j++) {
		for (k = 0; k < 10; k++) {
			printf(" %d", data[3][j][k]);
		}printf("\n");
	}


	return 0;

}

Measured memory_bytes: 2732
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#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<ll,ll> Pll;

const int MAX = 200100;
const int MOD = 1000000007;

ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i % MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i) % MOD;
        finv[i]=finv[i-1]*inv[i] % MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}

signed main(){
    COMinit();
    int n,k; cin >> n >> k;
    ll ans=0;
    for(int i=1;i<=min(n-1,k);i++){
        //無人をi部屋作る
            ans+=(COM(n,i)*COM(n-1,n-i-1))%MOD;
            ans%=MOD;
    }
    ans++;
    cout << ans%MOD << endl;
}


Measured memory_bytes: 4992
N=int(input())
p=[[int(i) for i in input().split()] for i in range(N)]
p_copy=list(p)
p_copy.sort(key=lambda x:x[0]+x[1])
length=abs(p_copy[N-1][0])+abs(p_copy[N-1][1])
if length%2==0:
  edge=[1]
  a=1
  while a<length:
    edge.append(a)
    a=2*a
  edge.reverse()
else:
  edge=[]
  a=1
  while a<length:
    edge.append(a)
    a=2*a
  edge.reverse()
if len(edge)>40 or edge[len(edge)-1]>10**12:
  print(-1)
  exit()
w=[""]*N
for n in range(N):
  x,y=p[n][0],p[n][1]
  if (x+y)%2!=length%2:
    print(-1)
    exit()
  else:
    a,b=0,0
    for e in edge:
      R=abs(x-(a+e))+abs(y-(b))
      L=abs(x-(a-e))+abs(y-(b))
      U=abs(x-(a))+abs(y-(b+e))
      D=abs(x-(a))+abs(y-(b-e))
      if min([R,L,U,D])==R:
        a+=e
        w[n]+="R"
      elif min([R,L,U,D])==L:
        a+=-e
        w[n]+="L"
      elif min([R,L,U,D])==U:
        b+=e
        w[n]+="U"
      else:
        b+=-e
        w[n]+="D"
  
print(len(edge))
map_edge=map(str,edge)
print(" ".join(map_edge))
for n in range(N):
  print(w[n])
    


Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main(){
    int n, k, q, x, a[100000]={0};
    cin>>n>>k>>q;
    for(int i=0; i<q; ++i){
        cin>>x;
        a[x]++;
    }
    if(k>q)
        for(int i=0; i<n; ++i)
            cout<<"Yes"<<endl;
    else{
        for(int i=1; i<=n; ++i){
            if(!a[i]) cout<<"No"<<endl;
            else if(q-a[i]<k) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  
  int res = 114514;
  for(int i = 1; i < N; i++) {
    int c = findSumOfDigits(i) +findSumOfDigits(N - i);
    if(c < res) {
      res = c;
    }
  }
  cout << res << endl;
    
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9+7;
int main()
{
	int n; cin>>n;
	ll  a[n], ans = 0;
	for(int i = 0;  i < n ; i++)
		cin>>a[i];
	for(int i = 0 ; i <61; i++)
	{
		int c_1 = 0;
		for(int j = 0 ; j < n ; j++)
			if((a[j]>>i)&1)
				c_1++;
		ans = (ans+ ((((n-c_1)%mod*c_1)%mod)*((1LL<<i)%mod))%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int n,a=0,b;

    cin >> n;

    a = n%100;
    b = n/100;

    if(b*5>=a) cout << 1;

    else cout << 0;




    return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
c=[0]*n
for j in range(2):
    cnt=0 #
    for i in range(n):
        if s[i]=='R':
            cnt+=1
        else:
            c[i]+=cnt//2
            c[i-1]+=-(-cnt//2)
            cnt=0
    c.reverse()
    s=s[::-1]
    s=s.replace('R', 'X').replace('L', 'R').replace('X', 'L')
print(*c)

Measured memory_bytes: 6400
n,m=map(int,input().split(" "))

l = list(map(int,input().split()))

s = sum(l)

nl=sorted(l,reverse=True)



r = s/(4*m)

count=0

for i in range(m) :
    if nl[i]>=r:
        pass
    else :
        count += 1

if count > 0:
    print("No")
else :
    print("Yes")

Measured memory_bytes: 9196
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

bool check(char c){
    if(c!='A' && c!='C' && c!='G' && c!='T')return true;
    return false;
}

signed main() {
   tezz
   
    string s;
    cin >> s;
    int c=0;
    int n=s.length();
    int mx=INT_MIN;
    for(int i=0; i<n; i++){
        if(!check(s[i])){
            c++;
        }
        else{
            mx=max(mx,c);
            c=0;
        }
    }
    mx=max(mx,c);
    cout << mx;
   
   return 0;
}

Measured memory_bytes: 256
def f():
  z =list(map(int,input().split(" ")))
  n=min(z)
  m=max(z)
  p=1000000000+7
  if m-n >1:
    print("0")
    return 0
  cnt= 1
  for i in range(1,1+m):
    cnt =( cnt*i)%p
  for i in range(1,1+n):
    cnt =(cnt*i)%p
  if m==n:
    cnt = (cnt*2)%p
  print(cnt)

f()


Measured memory_bytes: 3064
// WeirdBugsButOkay

# include <bits/stdc++.h>
 
# define ll long long
# define ld long double
# define pii pair <int,int>
# define pll pair <ll,ll>
# define mp make_pair
# define pb push_back
# define ff first
# define ss second
# define endl '\n'
 
using namespace std;

ll pow3(ll a, ll b, ll m = 1000000007)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ld pi = 3.1415926;
    ll r;
    cin >> r;
    cout << setprecision(11) <<  2.0 * pi * r;
}

 
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> q;
    for(ll i = 0; i < q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3804
#include<stdio.h>
int main()
{
    int n,flag=0;
    scanf("%d",&n);
    while(n)
    {
        if(n%10==7) flag=1;
        n /= 10;
    }
    if(flag==1) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1660
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var N int
var M int

func main() {
	N = nextInt()
	M = nextInt()
	As := nextInts(M)
	match := []int{2,5,5,4,5,6,3,7,6}
	dp := make([]string, N+10)
	for i, _  := range dp {
		dp[i] = "0"
	}
	dp[0] = ""
	for i :=0; i < N; i++ {
		if (dp[i] != "0") {
			for _, a := range As {
				dp[i+match[a-1]] = chmax(dp[i+match[a-1]], dp[i] + strconv.Itoa(a))
			}
		}
	}
	fmt.Printf("%v", dp[N])
}

func chmax(a, b string) string {
	if len(a) > len(b) {
		return a
	} else if len(b) > len(a) {
		return b
	} else {
		if a > b {
			return a
		} else {
			return b
		}
	}
}

func sum(a []int) int {
	s := 0
	for _, v := range a {
		s += v
	}
	return s
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 113348
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

int main() {

	int n;
	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<pair<char, char>> table(n);

		for (auto& temp : table) {
			cin >> temp.first >> temp.second;
		}

		int m;
		cin >> m;

		for (int i = 0; i < m; ++i) {
			char temp;
			cin >> temp;

			auto it = find_if(table.begin(), table.end(), [temp](pair<char, char> a) {return a.first == temp;});
			if (it == table.end()) {
				cout << temp;
			}
			else {
				cout << it->second;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
        a.second < b.second;
    a.first < b.first;
}
vector<string> v;

vector<pair<int, int>> vp;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);
    while (1)
    {
        bool eo = false;
        for (int i = 0; i < 8; ++i)
        {
            string s = "";
            cin >> s;
            if (s == "")
            {
                eo = true;
                break;
            }
            s = "0000" + s;
            s += "0000";
            v.push_back(s);
        }
        if (eo)
            break;
        v.push_back("0000000000000000");
        v.push_back("0000000000000000");
        v.push_back("0000000000000000");

        string ans = "";
        for (int i = 0; i < v.size(); ++i)
        {
            for (int j = 0; j < v[i].size(); ++j)
            {
                if (v[i][j] == '1')
                {
                    if (v[i][j + 1] == '1' && v[i + 1][j] == '1' && v[i + 1][j + 1] == '1')
                    {
                        ans = "A";
                    }
                    else if (v[i + 1][j] == '1' && v[i + 2][j] == '1' && v[i + 3][j] == '1')
                    {
                        ans = "B";
                    }
                    else if (v[i][j + 1] == '1' && v[i][j + 2] == '1' && v[i][j + 3] == '1')
                    {
                        ans = "C";
                    }
                    else if (v[i + 1][j] == '1' && v[i + 1][j - 1] == '1' && v[i + 2][j - 1] == '1')
                    {
                        ans = "D";
                    }
                    else if (v[i][j + 1] == '1' && v[i + 1][j + 1] == '1' && v[i + 1][j + 2] == '1')
                    {
                        ans = "E";
                    }
                    else if (v[i + 1][j] == '1' && v[i + 1][j + 1] == '1' && v[i + 2][j + 1] == '1')
                    {
                        ans = "F";
                    }
                    else if (v[i + 1][j] == '1' && v[i][j + 1] == '1' && v[i + 1][j - 1] == '1')
                    {
                        ans = "G";
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int dp[41][4010][41][4];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a));
    for (int i = 0; i <= 40; i++) {
        for (int j = 0; j <= 4000; j++) {
            for (int k = 0; k <= 40; k++) {
                for (int l = 0; l < 4; l++) {
                    dp[i][j][k][l] = -INF;
                }
            }
        }
    }
    dp[n - 1][a[n - 1]][n][1] = 0;
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j <= 4000; j++) {
            for (int k = n; k > i; k--) {
                for (int l = 0; l <= 3; l++) {
                    if (j >= a[i] && l > 0) {
                        chmax(dp[i][j][k][l], dp[i + 1][j - a[i]][k][l - 1]);
                        if (l == 3) {
                            chmax(dp[i][j][k][l], dp[i + 1][j - a[i]][k][l]);
                        }
                    }
                    if (k != n) {
                        chmax(dp[i][j][k][l], dp[i + 1][j][k][l] + 1);
                    }
                }
            }
            for (int l = 0; l <= 3; l++) {
                chmax(dp[i][j][i][l], dp[i + 1][j][n][l] + 1);
            }
        }
    }
    int res = INF;
    for (int i = 0; i <= 4000; i++) {
        if (i - a[n - 1] <= a[n - 1]) {
            continue;
        }
        for (int j = 0; j < n; j++) {
            if (dp[0][i][j][3] >= 3 && sum - i - a[j] > a[j]) {
                chmin(res, abs(i - (sum - i)));
            }
        }
    }
    if (res == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;
}

/*
dp[i][j][k][l]:i番目までにおいて、Am=Anなる多角形の長さの和がjでl個選んで、もう一つがAm=Akのときのそれの最大数
状態:40*4000*40*9,遷移O(1)
*/


Measured memory_bytes: 108468
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k,i;
	for(;cin>>n>>k,n;){
		vector<int>vec(n);
		for(i=0;i<n;i++)vec[i]=i+1;
		for(i=0;vec.size()>1;vec.erase(vec.begin()+i))if(i+=(k-1)%vec.size(),i>=vec.size())i-=vec.size();
		cout<<vec[0]<<endl;
	}
}

Measured memory_bytes: 1216
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

struct STsum{
private:
    int n;
    vector<ll> dat;
public:
    STsum(int siz){
        n = 1;
        while(n < siz)   n *= 2;
        dat.resize(2*n-1, 0);
    }

    void update(int x, ll val){
        x += (n-1);
        dat[x] += val;
        while(x > 0){
            x = (x-1)/2;
            dat[x] = dat[2*x+1]+dat[2*x+2];
        }
    }
    
    // focus on k-th node, who controls [l, r)
    ll query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)   r = n;
        if(r <= a || b <= l)    return 0;
        if(a <= l && r <= b)    return dat[k];

        ll lx = query(a, b, 2*k+1, l, (l+r)/2);
        ll rx = query(a, b, 2*k+2, (l+r)/2, r);
        return lx+rx;
    }
};

struct BIT{
    vector<int> v;
    int n;

    BIT(int _n):
        v(vector<int>(_n+1, 0)), n(_n) {}

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += v[i];
            i -= lsb(i);
        }
        return s;
    }
    
    int sum(int l, int r){
        return sum(r) - sum(l-1);
    }

    void add(int i, int x){
        while(i <= n){
            v[i] += x;
            i += lsb(i);
        }
    }

private:
    // least significant bit
    int lsb(int i){
        return i & -i;
    }
};



int main(){
    int q;
    cin >> q;
    vector<int> op(q), a(q), b(q), v;
    for(int i = 0; i < q; i++){
        cin >> op[i];
        if(op[i] == 1){
            cin >> a[i] >> b[i];
            v.push_back(a[i]);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    auto f = [&](int val)->int{
        return lower_bound(v.begin(),v.end(),val)-v.begin();
    };
    int siz = v.size();
    BIT bit(siz);
    STsum seg(siz);

    ll bsum = 0;
    int num = 0; // number of updates
    for(int i = 0; i < q; i++){
        if(op[i] == 1){
            bsum += b[i];
            int pos = f(a[i]);
            bit.add(pos+1, 1);
            seg.update(pos, a[i]);
            num++;
        }else if(op[i] == 2){
            int l = 0, r = siz; // (l, r], 1-indexed
            while(r-l > 1){
                int mid = (l+r)/2;
                int tmp = bit.sum(mid);
                if(tmp >= (num+1)/2)  r = mid;
                else                l = mid;
            }
            int low = bit.sum(r-1), high = num-bit.sum(r);
            r--; // 0-indexed
            ll ans = 0;
            ans += (ll)low*v[r]-seg.query(0, r);
            ans += seg.query(r+1, siz+1)-(ll)high*v[r];
            ans += bsum;
            cout << v[r] << " " << ans << endl;
        }
    }
    return 0;
}

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

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

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

int main(void){

    int n, m;

    scanf("%d%d", &n, &m);

    printf("%d\n", (n-1)*(m-1));

    return 0;
}

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

long long gcd(long long a, long long b) {
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	while (a != 0) {
		long long tmp = b % a;
		b = a;
		a = tmp;
	}
	return b;
}

long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}

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

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

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

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

    int jud[n];
    for (int i = 0; i < n; i++) {
        jud[i] = 0;
    }

    for (int i = 1; i <= n;) {
        for (int j = 1; j <= i;) {
            if (i % j == 0) {
                jud[i - 1]++;
            }
            j += 2;
        }
        i += 2;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (jud[i] == 8) {
            sum++;
        }
    }

    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = int(input())
mod = 10**9+7

pos = {0: 1}
neg = {0: 1}
for i in range(1, 5010):
    pos[i] = (pos[i-1]*i)%mod
    neg[i] = pow(pos[i], mod-2, mod)

ans = 0
cnt = 1
while cnt*3<=S:
    rest = S-cnt*3
    bar = cnt-1
    ans += pos[rest+bar]*neg[bar]*neg[rest]
    ans %= mod
    cnt += 1
print(ans)

Measured memory_bytes: 67872
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef vector < ll > vll;
#define s second
#define f first
int main()
{   
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while (t-- )
	{	int x,y;
		cin>>x>>y;
		bool flag=false;
		for(int i=0;i<=x;i++)
		{	if(4*i+2*(x-i)==y)
			flag=true;
		}
		if(flag)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	return 0;  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
  if(P>Q){
    swap(P,Q);
  }
  ll ans=0;
  while(P!=Q){
    next_permutation(P.begin(),P.end());
    ++ans;
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 1000000000

int n;
int s[MAX];
int linearSearch(int);

int main()
{
  int i, q, count = 0;
  int t;

  scanf("%d", &n);
  for( i = 0; i < n; i++)
    {
      scanf("%d", &s[i]);
    }
  
  scanf("%d", &q);
  for( i = 0; i < q; i++)
    {
      scanf("%d", &t);
      count += linearSearch(t);
    }
  printf("%d\n", count);

  return 0;
}
  
int linearSearch(int key)
{
  int left = 0;
  int right = n;
  int mid;

  while(left < right)
    {
      mid = (left + right) / 2;
      if(s[mid] == key)return 1;
      else if(key < s[mid])right = mid;
      else left = mid + 1;
    }
  return 0;
}



Measured memory_bytes: 2128
let (p1, p2, p3) = (257, 251, 1000000007)

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x mod p3) (n / 2) acc
    else doit (x * x mod p3) (n / 2) (acc * x mod p3) in
  doit x n 1

let make_hash v (x, y) (r, c) =
  let h1 = Array.make_matrix x y 0 in
  let c1 = pow p1 c in
  for i = 0 to x - 1 do
    let rec calc_z j acc =
      if j = c then acc
      else calc_z (j + 1) ((acc*p1 + Char.code v.(i).(j)) mod p3) in
    let rec aux j z =
      if j = y - c then h1.(i).(j) <- z
      else begin
        h1.(i).(j) <- z;
        let new_z = (z*p1 - (Char.code v.(i).(j))*c1 + Char.code v.(i).(j+c)) mod p3 in
        aux (j + 1) (if new_z < 0 then new_z + p3 else new_z)
      end in
    calc_z 0 0 |> aux 0;
  done;
  let h2 = Array.make_matrix x y 0 in
  let c2 = pow p2 r in
  for j = 0 to y - 1 do
    let rec calc_z i acc =
      if i = r then acc
      else calc_z (i + 1) ((acc*p2 + h1.(i).(j)) mod p3) in
    let rec aux i z =
      if i = x - r then h2.(i).(j) <- z
      else begin
        h2.(i).(j) <- z;
        let new_z = (z*p2 - h1.(i).(j)*c2 + h1.(i+r).(j)) mod p3 in
        aux (i + 1) (if new_z < 0 then new_z + p3 else new_z)
      end in
    calc_z 0 0 |> aux 0;
  done;
  h2

let solve (h, w) (r, c) a b =
  let s = make_hash a (h, w) (r, c) in
  let t = make_hash b (r, c) (r, c) in
  for i = 0 to h - r do
    for j = 0 to w -c do
      if s.(i).(j) = t.(0).(0) then Printf.printf "%d %d\n" i j;
    done
  done

let read_array x y =
  let a = Array.make_matrix x y '\000' in
  for i = 0 to x - 1 do
    let l = read_line () in
    for j = 0 to y - 1 do
      a.(i).(j) <- l.[j];
    done
  done;
  a

let () =
  match read_line () |> split_on_char ' ' |> List.map int_of_string with
  | [h; w] ->
    begin
      let a = read_array h w in
      match read_line () |> split_on_char ' ' |> List.map int_of_string with
      | [r; c] ->
        if h < r || w < c then ()
        else read_array r c |> solve (h, w) (r, c) a
      | _ -> assert false
    end
  | _ -> assert false

Measured memory_bytes: 42968
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;  
/*  
    time : 10 : 14    
    date : 22.01.2020
*/    
// int L,R,mid,target,idx ;
int tests() 
{   int n,k; 
    cin >> n  >> k ; 
     string S ;
     while(n){
         S.pb('0'+n%k) ;
         n /= k ; 
     }
     cout << S.size() ;
    return 0 ; 
}
int main(){
    I__O ;  
    int cases = 1 ; 
    //cin >> cases;  
    while(cases--)
      tests(); 
  return 0 ; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define endl '\n'

vector<int> sums;

int get(int l, int r) {
     if (l) {
          return sums[r] - sums[l-1];
     } else {
          return sums[r];
     }
}

signed main() {
     ios::sync_with_stdio(false);
     cin.tie();
     cout.tie();
     int n;
     cin >> n;
     vector<int> a(n);
     for (auto &el : a) {
          cin >> el;
     }
     sums.resize(n);
     sums[0] = a[0];
     for (int i = 1; i < n; ++i) {
          sums[i] = sums[i-1]+a[i];
     }
     int l = 0;
     int r = 2;
     int ans = 1e18;
     for (int mid = 1; mid < n - 2; ++mid) {
          r = max(r, mid + 1);
          
          while (l < mid - 1 && abs(get(0,l) - get(l+1, mid)) > abs(get(0, l + 1) - get(l + 2, mid))) {
               l++;
          }
          while (r < n - 1 && abs(get(mid+1, r) - get(r + 1, n - 1)) > abs(get(mid+1,r+1) - get(r + 2, n - 1))) {
               r++;
          }
          int mx = max(max(get(0, l), get(l + 1, mid)), max(get(mid+1, r), get(r + 1, n - 1)));
          int mn = min(min(get(0, l), get(l + 1, mid)), min(get(mid+1, r), get(r + 1, n - 1)));
          ans = min(ans, mx - mn);
     }
     cout << ans << endl;
     return 0;
}


Measured memory_bytes: 3456
n,k = map(int,input().split())
s = input()

if s[k-1] == "A":
    s = s[:k-1] + 'a' + s[k:]
elif s[k-1] == "B":
    s = s[:k-1] + 'b' + s[k:]
else:
    s = s[:k-1] + 'c' + s[k:]
print(s)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string T, P;

    cin >> T >> P;

    uint64_t ht = 0, hp = 0, b = 1;
    for (uint32_t i = 0; i < P.length(); i++) {
        ht = (ht << 7) + T[i];
        hp = (hp << 7) + P[i];
        b = b << 7;
    }

    for (int32_t i = 0; i <= (int32_t)(T.length() - P.length()); i++) {
        if (ht == hp) if (T.substr(i, P.length()) == P) printf("%d\n", i);
        ht = (ht << 7) + T[i+P.length()] - b * T[i];
    }

    return 0;
}

Measured memory_bytes: 4524
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll nmax=1e5+2;
#define int ll
int n, m;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>m;
    cout<<max(n+m, max(n-m, n*m));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
const ll mod=10e9+7;
ll ABS(ll a){return max(a,-a);}


int main(void){
    string S;
    cin>>S;
    ll N=S.size();
    vector<ll> ans(N,0);
    ll left=0,right,ansleft;
    rep(i,N-1){
        if(S.at(i)=='R' && S.at(i+1)=='L') ansleft=i;
        if(S.at(i)=='L' && S.at(i+1)=='R'){
            right=i+1;
            if((right-left)%2==0){
                ans.at(ansleft)=(right-left)/2;
                ans.at(ansleft+1)=(right-left)/2;
            }
            else if((right-ansleft)%2==1){
                ans.at(ansleft)=(right-left)/2+1;
                ans.at(ansleft+1)=(right-left)/2;
            }
            else {
                ans.at(ansleft)=(right-left)/2;
                ans.at(ansleft+1)=(right-left)/2+1;
            }
            left=right;
        }
        if(i==N-2){
            right=N;
            if((right-left)%2==0){
                ans.at(ansleft)=(right-left)/2;
                ans.at(ansleft+1)=(right-left)/2;
            }
            else if((right-ansleft)%2==1){
                ans.at(ansleft)=(right-left)/2+1;
                ans.at(ansleft+1)=(right-left)/2;
            }
            else {
                ans.at(ansleft)=(right-left)/2;
                ans.at(ansleft+1)=(right-left)/2+1;
            }
            left=right;
        }
    }
    rep(i,N-1) cout<<ans.at(i)<<" ";
    cout<<ans.at(N-1)<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n, m;

	std::cin >> n >> m;

	for (int i = m - n + 1; i < m + n; i++)
	{
		std::cout << i;
		if (i != m + n - 1) {
			std::cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}

ll modpow(ll x, ll n){
	ll r=1;
	while(n){
		if(n&1) r=r*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return r;
}
int main(){
  ll n,k;cin>>n>>k;
  vll a(n),b(n);
  ll sum=1;
  rep(i,0,n){cin>>a[i];}
  rep(i,k,n){
    if(a[i]<=a[i-k]){cout<<"No"<<endl;}
    else cout<<"Yes"<<endl;
    
  }
}



Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  ll n,res=0;
  cin >> n;
  ll x[n],ans[n];
  ll y[n],b[n];
  rep(i,n){
    cin >>x[i];
    y[i]=x[i];
  }

  sort(y,y+n);
  res=y[(n+1)/2];
  rep(i,n){
    if(x[i]<res)b[i]=res;
    else b[i]=y[n/2-1];
  }
  rep(i,n)cout << b[i] << endl;
}


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int a,b,c;

int main(){
    INIT;
    cin >> a >> b >> c;
    cout << std::max({a*10+b+c, a+b*10+c, a+b+c*10}) << "\n";
}

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

int main(int argc, char *argv[])
{
  string string;
  cin >> string;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (string[i] == '1') {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

#define int long long 
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pi> 
#define vvpii vector<vpii>
#define all(V) V.begin(),V.end()
#define mpii map<int,int> 
#define mpci map<char,int> 
#define fi first
#define si second
#define pb(V) push_back(V)
#define mp(a,b) make_pair(a,b)
#define mt(a,b,c) make_tuple(a,b,c)
#define forn(i,n) for (int i = 0; i < int(n); ++i)


const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	map<char,int> mp;
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.length(); ++i)
	{
		mp[s[i]]++;
	}

	if(mp.size()==2)
	{
		for(auto x:mp)
		{
			if(x.second != 2)
			{
				cout << "No";
				return 0;
			}
		}
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int num,num2,num3,num4,num5,sum,sum2;
    cin >> num >> num2 >> num3 >> num4 >> num5;
    if(num%num2!=0){
        sum=(num/num2)+1;
    }
    else{
        sum=num/num2;
    }
    sum=sum*num3;

    if(num%num4!=0){
        sum2=(num/num4)+1;
    }
    else{
        sum2=num/num4;
    }
    sum2=sum2*num5;

    if(sum>sum2){
        cout << sum2 << endl;
    }
    else if(sum<sum2){
        cout << sum << endl;
    }
    else{
        cout << sum << endl;
    }
    return 0;
}


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

int main() {
  int n , m ;cin >> n >> m;
  priority_queue<int> q;
  for(int i = 0 ;i < n; i ++ ) {
    int x ; cin >> x;
    q.push(x);
  }
  long long ans = 0;
  while(m--) {
    auto t = q.top();
    q.pop();
    t = t / 2;
    q.push(t);
  }
  while(!q.empty()) {
    auto t = q.top();
    ans += 1ll*t;
    q.pop();
  }
  cout << ans;
}


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

int main(){
    stack<int> S1, S3;
    stack<pair<int, int> > S2;

    int j, sum=0, a;
    char ch;
    for (int i=0; cin >> ch; i++) {
        if (ch == '\\') S1.push(i);
        else if (ch == '/' && !S1.empty()) {
            j = S1.top();
            S1.pop();
            a = i - j;
            sum += a;
            while (!S2.empty() && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    cout << sum << endl;

    while (!S2.empty()) {S3.push(S2.top().second); S2.pop();}
    cout << S3.size();
    while (!S3.empty()) {cout << " " << S3.top(); S3.pop();}
    cout << endl;
    return 0;
} 


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
const int MAXN = 1e6 + 50;
int A[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string S; cin >> S;
    stack<char> stac;
    for (int i=0; i<S.length(); i++){
        if (stac.empty()) stac.push(S[i]);
        else{
            if (stac.top() == '0' && S[i] == '1') stac.pop();
            else if (stac.top() == '1' && S[i] == '0') stac.pop();
            else stac.push(S[i]);
        }
    }
    cout << S.length() - stac.size();
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli x;
    cin >> x;
    lli money = 100;
    lli ans = 0;
    while(money < x){
        ans++;
        money = money + money/100;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    ll S = accumulate(arr.begin(), arr.end(), 0LL);
    ll ans = INT_MAX, acc = 0;
    for(ll val: arr) {
        acc += val;
        ans = min(ans, llabs(acc-(S-acc)));
    }
    cout << ans << endl;
    return 0;
}



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

signed main() {
  string S;
  cin >> S;
  int red = 0;
  int blue = 0;
  
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) == '0' ) red++;
    else blue++;
  }
  cout << min(red, blue)*2 << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-10;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b=10){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<ll>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

ll popHeap(vector<ll>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  ll i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n,m;
  cin>>n>>m;
  vector<pll> v;
  for(i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    v.push_back(pll(b,a));
  }
  sort(all(v));
  for(i=0;i<m;i++){
    swap(v[i].fi,v[i].se);
  }
  int x=-1;
  for(i=0;i<m;i++){
    if(v[i].fi<=x)continue;
    else{
      x=v[i].se-1;
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3444
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n;
P x[100010],y[100010];
int f[100010],s[100010];
bool C(int p)
{
	int mi=x[0].fi,mx=x[n-1].fi;
	memset(f,0,sizeof(f));
	memset(s,0,sizeof(s));
	f[x[0].sec]=2;
	for(int i=0;i<n;i++)
	{
		if(abs(mi-x[i].fi)>p&&abs(mx-x[i].fi)>p)return false;
		if(abs(mi-x[i].fi)>p)f[x[i].sec]=1;
		if(abs(mx-x[i].fi)>p)f[x[i].sec]=2;
	}
	mi=y[0].fi,mx=y[n-1].fi;
	s[y[0].sec]=2;
	for(int i=0;i<n;i++)
	{
		if(abs(mi-y[i].fi)>p&&abs(mx-y[i].fi)>p)return false;
		if(abs(mi-y[i].fi)>p)s[y[i].sec]=1;
		if(abs(mx-y[i].fi)>p)s[y[i].sec]=2;
	}
	int either=0,both=0;
	for(int i=0;i<n;i++)
	{
		if(f[i]==0||s[i]==0)both++;
		else if(f[i]!=s[i])either++;
	}
	return (either==0||both+either==n);
}
int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int tx,ty;
		cin >> tx >> ty;
		x[i]=mp(tx+ty,i);
		y[i]=mp(tx-ty,i);
	}
	sort(x,x+n);
	sort(y,y+n);
	int l=0,r=INF;
	while(r-l>1)
	{
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3516
from sys import stdin
A,B,C = [int(x) for x in stdin.readline().rstrip().split()]
 
ans = 0
 
if A == B == C:
    if A % 2 == 0:
        ans = -1
    else:
        ans = 0
else:
    for _ in range(1000):
        
        if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
            break
        ans += 1
        ta = A
        tb = B
        tc = C
        A = (tb/2) + (tc/2)
        B = (ta/2) + (tc/2)
        C = (ta/2) + (tb/2)
        
        
print(ans)

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


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


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	int x, a;
	cin >> x >> a;
	if (x < a)PRI(0);
	else PRI(10);
	return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}
 
#define MAX_K 333333
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(kaijo[0] != 1){
		kaijo[0] = 1;
		for(long long i = 1;i < MAX_K;i++)kaijo[i] = (kaijo[i-1] * i) % MOD;
	}
    long long ret = kaijo[n];
	long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
    return mod_div(ret,tmp);
}

int main(){
	
	ll h,w,k;cin >> h >> w >> k;
	ll invHW = mod_div(1, h+w);
	ll invHW1 = mod_div(1, h+w-1);
	
	ll ans = 0;
	ll AA = 0;
	ll BB = 0;
	for(int i = 1;i <= k;i++){
		ll A = ((invHW * invHW1 % MOD) * (i - 1) % MOD); 
		A = ((A * h % MOD) * w % MOD) * (k + 1 - i) % MOD;
		ll B = (invHW * (k + 1 - i) % MOD) * (h + w) % MOD;
		ans = (ans + 2 * A + B) % MOD;
		AA = (AA + A) % MOD;
		BB = (BB + B) % MOD;
	}
	ans = (ans + k) % MOD;
	
	ll A = 1;for(int i = 1;i <= h + w;i++)A = (A * i) % MOD;
	ll B = 1;for(int i = 1;i <= h + w - k;i++)B = (B * i) % MOD;
		
	cout << ans * mod_div(A, B) % MOD << endl;
	
	return 0;
}


Measured memory_bytes: 2816