akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int N; 
cin >> N; 
int F[150][15], P[150][15]; 
for(int i = 0; i < N; i++){
 for(int j = 0; j < 10; j++){
cin >> F[i][j];
 }
}
for(int i = 0; i < N; i++){
 for(int j = 0; j <= 10; j++){
cin >> P[i][j];
 }
}

int y = -1000000000; 
for (int bit = 1; bit < (1<<10); ++bit){
    int benefit = 0; 
for(int i = 0; i < N; i++){
  int count = 0; 
 for (int j = 0; j < 10; j++) {
if ((bit / (1<<j)) % 2 == 1) {count += F[i][9-j];
                             }
 }
   benefit += P[i][count]; 
}
   y = max(y, benefit); 
}
cout << y << endl; 
return 0;
}


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

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int arr[][]=new int[N][M];
		int n=M;
		int m=N;
		int l=0,k=0,i;
		int size=sc.nextInt();
		List<Integer> li=new ArrayList<>();
		for (int j = 0; j < size; j++) {
			li.add(sc.nextInt());
		}
		List<Integer> ele=new ArrayList<>();
		int u=1;
		for(Integer p:li)
		{
			
			while(p-->0)
			{
				ele.add(u);
			}u++;
		}
		Iterator<Integer> itr=ele.iterator();
		while(l<n&&k<m)
		{
			for( i=l;i<n;i++)
			{
				
				arr[k][i]=itr.next();
			}
			k++;
			for( i=k;i<m;i++)
			{
				 arr[i][n-1]=itr.next();
			}
			n--;
			if(k<m)
			{
				 for (i = n-1; i >= l; --i)
		            {
					  arr[m-1][i]=itr.next();
		            }
		            m--;
			}
			
			if(l<n)
			{
				 for (i = m-1; i >= k; --i)
		            {
		               arr[i][l]=itr.next();
		            }
		            l++;  
			}
		}
		for ( i = 0; i < N; i++) {
			for (int j = 0; j <M; j++) {
				System.out.print(arr[i][j]+" ");
			}
			System.out.println();
		}
	}

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll W,H,X,Y;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W>>H>>X>>Y;
	
	if(2*X==W && 2*Y==H) {
		cout<<W*H/2.0<<" "<<1<<endl;
	}
	else {
		cout<<W*H/2.0<<" "<<0<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8");

function Main(input) {
  input = input.split('\n').map(Number);
  const N = input[0]
  const A = input[1]  
  console.log(N%500 <= A?'Yes':'No');
}

// Don't edit this line!
Main(input);


Measured memory_bytes: 21064
#include <stdio.h>

int main(){
  int key, i, j, len, a[101];
  scanf("%d", &len);
  for(i = 0;i < len;i++) scanf("%d", a + i);

  for(j = 1;j < len;j++){
    for(i = 0;i < len;i++) printf(i != 0 ? " %d":"%d", a[i]);
    puts("");
    key = a[j];
    for(i = j - 1;i >= 0 && a[i] > key;i--) a[i + 1] = a[i];
    a[i + 1] = key;
  }

  for(i = 0;i < len;i++) printf(i != 0 ? " %d": "%d", a[i]);
  puts("");
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define maxn 200001

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[maxn],h[maxn];
long long tree[4*maxn],ma=0;

void update(int x,long long k)
{
    for (;x<=n;x+=(x&-x))
        tree[x]=max(tree[x],k);
}

long long _get(int x)
{
    long long kq=0;
    for (;x>0;x-=(x&-x))
        kq=max(kq,tree[x]);
    return kq;
}

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&h[i]);
    }
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
    }
}

void process()
{
    for (int i=1;i<=n;++i)
    {
        update(h[i],_get(h[i]-1)+a[i]);
        ma=max(ma,_get(h[i]-1)+a[i]);
    }
    cout<<ma;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 3328
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll prime[1000005]; 
unordered_map<ll, ll> max_map; 
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < 1000005; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < 1000005; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
void solve()
{
    int n;
    cin>>n;
    ll ar[n];
    rep0(i,n) cin>>ar[i];
    for (int i = 0; i < n; i++) { 
        ll num = ar[i]; 
        unordered_map<ll, ll> temp; 
        while (num > 1) { 
            ll factor = prime[num]; 
            temp[factor]++; 
            num /= factor; 
        } 
        for (auto it : temp) { 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
    ll lc = 1; 
    for (auto it : max_map) {  
        lc = (lc * power(it.f, it.s)) % mod; 
    } 
    ll an=0;
    rep0(i,n){
        an=(an+(lc*power(ar[i],mod-2))%mod)%mod;
    }
    pr(an);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    sieve(); 
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 8576
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    for (L in M / N downTo 1) {
        val D = M - N * L
        if (D % L == 0) {
            println(L)
            return
        }
    }
}

Measured memory_bytes: 36572
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    scanf("%d", &i);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    scanf("%lld", &i);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

constexpr char BR = '\n';


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

int main()
{
    int N, M, K;
    io >> N >> M >> K;
    vll A(N+1), B(M+1);
    A[0] = B[0] = 0;
    for (int i = 0; i < N; i++)
    {
        int a;
        io >> a;
        A[i+1] = A[i] + a;
    }
    for (int i = 0; i < M; i++)
    {
        int b;
        io >> b;
        B[i+1] = B[i] + b;
    }

    int ans = 0;
    for (int i = 0; i <= N; i++)
    {
        if (A[i] > K) break;
        ll rest = K - A[i];
        auto it = upper_bound(begin(B), end(B), rest);
        int bi = it - begin(B) - 1;
        ans = max(ans, i + bi);
    }
    io << ans << BR;
}


Measured memory_bytes: 6456
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int N, M;
	cin >> N >> M;
	int a[M], b[M];
	for (int i = 0; i < M; ++i) cin >> a[i] >> b[i];
 
    // 解法
    // 仕事をソートするためのpairの配列
    point itv[M];
 
    // pairは辞書順で比較される
	for (int i = 0; i < M; ++i){
		if (a[i]<b[i]){
			itv[i].first = a[i];
			itv[i].second = b[i];
		}
		else{
			itv[i].first = b[i];
			itv[i].second = a[i];
		}
	}
	sort(itv, itv + M);
	// for (int i = 0; i < M; ++i){
	// 	printf("(%d, %d)\n", itv[i].first, itv[i].second); 
	// }
	// tは最後に選んだ仕事の終了時間
	int most_left = N;
	int ans = 1;
	for (int i = 0; i < M; ++i){
		// printf("(%d, %d most:%d)\n", itv[i].first, itv[i].second, most_left); 
		if (most_left<=itv[i].first){
			ans++;
			most_left = itv[i].second;
			// cout << "cut" << endl;
		}
		if (itv[i].second<most_left) most_left = itv[i].second;
	}
	
	//出力
	printf("%lld\n", ans); 
}
 


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<pii, int> piipi;
piipi p[100005];
int l[100005], r[100005], c[100005];

LL st[400005];
void build(int n, int s, int e){
    if(s == e) st[n] = 1e18;
    else{
        int mid = (s+e)/2;
        build(n+n, s, mid);
        build(n+n+1, mid+1, e);
        st[n] = min(st[n+n], st[n+n+1]);
    }
}
void update(int n, int s, int e, int idx, LL v){
    if(s == e){
        st[n] = min(st[n], v);
        return;
    }
    int mid = (s+e)/2;
    if(idx <= mid) update(n+n, s, mid, idx, v);
    else update(n+n+1, mid+1, e, idx, v);
    st[n] = min(st[n+n], st[n+n+1]);
}
LL query(int n, int s, int e, int l, int r){
    if(s > r || l > e) return 1e18;
    if(l <= s && e <= r) return st[n];
    int mid = (s+e)/2;
    return min(query(n+n, s, mid, l, r), query(n+n+1, mid+1, e, l, r));
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    build(1, 1, n);
    update(1, 1, n, 1, 0);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d", &l[i], &r[i], &c[i]);
        p[i] = piipi(pii(r[i], l[i]), c[i]);
    }   
    sort(p+1, p+1+m);
    for(int i=1;i<=m;i++){
        r[i] = p[i].first.first;
        l[i] = p[i].first.second;
        c[i] = p[i].second; 

        LL q = query(1, 1, n, l[i], r[i]);

        if(q != 1e18) update(1, 1, n, r[i], q+c[i]);
    }
    LL ans = query(1, 1, n, n, n);
    if(ans == 1e18) ans = -1;
    printf("%lld\n", ans);
}

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

typedef long long ll;
typedef int keytype;

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

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

ll ans(ll h){
    if(h == 1){
        return 1;
    }else{
        return 2 * ans(h / 2) + 1;
    }
}

int main(){
    ll h;

    scanf("%lld", &h);

    
    ll sum = 1;
    for(ll i = 2; (h /= 2) >= 1; i*=2){
        sum += i;
    }
    
    //ll sum = ans(h);

    printf("%lld\n", sum);

    return 0;
}


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

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    	std::string s(a,'0');
    	std::string t(w-a,'1');
        std::string ans=s+t;
  		std::string S(a,'1');
  		std::string T(w-a,'0');
  		std::string Ans=S+T;
  for(int i=0;i<h;++i){
    if(i<b){
    	printf("%s\n",ans.c_str());
    }
    else{
    	printf("%s\n",Ans.c_str());
    }
  }
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}
 
const int N=2e6+3,M=5e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;
 
int n,m,k,tc,ans,a[N];
 
int main(){
    int A,B,C;
    scanf("%d %d %d %d",&A,&B,&C,&k);
    while(k && B <= A) 
        B <<= 1, k--;
    while(k && C <= B)
        C <<= 1, k--;
    if (B > A && C > B)
        printf("Yes\n");
    else
        printf("No\n");

}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=1;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a,b,c,x;
int main(){
	a=read();b=read();c=read();
	x=max(a,b);x=max(x,c);
	if(x==a)printf("%d\n",x*10+b+c);
	else if(x==b)printf("%d\n",x*10+a+c);
	else printf("%d\n",x*10+b+a);
	return 0;
}

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

using namespace std;

int main() {

	int n,k;
	cin >> n >> k;

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

	sort(h.begin(), h.end());

	int minh = 1000000000;
	for (int i = 0; i < n-k+1; i++) {
		if (h[i + k-1] - h[i] < minh) {
			minh = h[i + k-1] - h[i];
		}
	}

	cout << minh << endl;

}

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

typedef long long int ll;
ll pts[400005][2] = { 0 };

ll mnht(ll pt[400005][2], int kth, int idx, int d)
{
	ll dist = 0;

	for (int i = 0; i < d; i++)
	{
		dist += abs(pt[kth][i] - pt[idx][i]);
	}

	return dist;
}
ll max_cmb(ll cmbn[2], ll pt[400005][2], int n, int d)
{
	ll pk = 0; ll idx = 0;

	for (int i = 0; i < n; i++)
	{
		ll val = 0;

		for (int j = 0; j < d; j++)
		{
			val += (1 - 2 * cmbn[j])*pt[i][j];
		}

		if (val > pk)
		{
			pk = val;
			idx = i;
		}
	}

	return idx;
}

int main()
{
	int n, d;
	cin >> n;
	d = 2;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
			cin >> pts[i][j];
	}

	ll pk[2 << d];

	for (int j = 0; j < 1 << (d); j++)
	{
		ll cmbn[2] = { 0 };
		for (int dig = 0; dig < d; dig++)
		{
			if (j & 1 << dig)
				cmbn[dig] = 1;
		}
		
		pk[j] = max_cmb(cmbn, pts, n, d);
	}

	ll maxd = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 1 << (d); j++)
			maxd = max(maxd, mnht(pts, i, pk[j], d));
	}

	cout << maxd << endl;
	return 0;
}


Measured memory_bytes: 6724
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7 ;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}





int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;

    ll n;
    cin>>n;
    ll res=n*n-n;
    res/=2;
    cout<<res<<endl;
    return 0;
    }


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


using namespace std;


constexpr auto BASE = 1000000007;





int N, K;


long long mypow(int a, int b);

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

	auto k = vector<long long >(K+1,0);
	long long ans = 0;

	for (int i = K; i > 0; i--) {
		int n = K / i;

		long long b = mypow(n,N);

		int j = 2;
		while (i*j<=K) {
			b = b - k[i*j];
			while (b < 0) {
				b += BASE;
			}

			j++;
		}

		k[i] = b;

		ans = (ans + (b*i)%BASE) % BASE;

	}





	cout << ans << endl;

	return 0;
}


long long mypow(int a,int b)
{
	int i = 0;
	long long r = 1;
	long long d = a;

	vector<long long> ary;

	do {
		ary.push_back(d);
		r*=2;
		i++;

		d = (d*d)%BASE;
	} while (r <= b);

	i--;
	r /= 2;

	long long ans = 1;

	while (i>=0 && b>0) {

		long long  bb = b / r;

		if (bb > 0) {
			b -= bb * r;
			ans = ((ary[i] * bb) % BASE * ans) % BASE;
		}
		i--;
		r /= 2;

	}

	return ans;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl p(n+1);
  rep2(i, n) cin >> p[i];
  
  ll ans=0;
  rep2(i, n) {
    if(p[i]==i) {
      ans++;
      if(i<n) p[i+1]=0;
    }
  }
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3868
import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([K-1])
    dist = [-1]*N
    dist[K-1] = 0
    
    while q:
        v = q.popleft()
        
        for nv, w in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+w
                q.append(nv)
    
    return dist

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a-1].append((b-1, c))
    G[b-1].append((a-1, c))

Q, K = map(int, input().split())
dist = bfs()

for _ in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])

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

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, 0, N) cin >> L.at(i);
    int count = 0;
    rep(i, 0, N - 2){
        rep(j, i + 1, N - 1){
            rep(k, j + 1, N){
                
                vector<int> X = {L.at(i), L.at(j), L.at(k)};
                sort(all(X));
                int x = X.at(0), y = X.at(1), z = X.at(2);
                if((x == y) || (y == z) || (x == z)) continue;
                if((x + y <= z)) continue;
                //cout << i << " " << j << " " << k << endl;
                //cout << "L " << x << " " << y << " " << z << endl;
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(int argc, char *argv[])
{
	int n,a[7]={1,2,4,8,16,32,64};
	while(scanf("%d",&n)!=EOF)
	{
		int s=0,i;
		for(i=6;i>=0;i--)
		{
			if(a[i]<=n){printf("%d\n",a[i]);break;}
		}
		
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

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


int main()
{
  string s;
  cin >> s;
  if(s[0] != 'A')
  {
    cout << "WA" << endl;
    return 0;
  }
  s = s.substr(1);
  string tmp = s.substr(1, int(s.size()) - 2);
  int count = 0;
  for (int i = 0; i < int(tmp.size()); i++)
  {
    count += (tmp[i] == 'C');
    if(tmp[i] == 'C') tmp.erase(tmp.begin()+i);
  }
  if(count != 1)
  {
    cout << "WA" << endl;
    return 0;
  }
  s = s[0] + tmp + s[s.size()-1];

  for (int i = 0; i < int(s.size()); i++)
  {
    if(isupper(s[i])){
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;

}

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

using namespace std;

class XorBase {
public:
    explicit XorBase(){}
    long long reduce(long long t) const {
        for(auto& b : base) t = min(t, t^b);
        return t;
    }
    bool add(long long t){
        t = reduce(t);
        if(!t) return false;
        base.push_back(t);
        for(int i=base.size()-2;i>=0;i--) if(base[i] < base[i+1]) swap(base[i], base[i+1]);
        return true;
    }
    long long getMax() const {
        long long res = 0;
        for(auto& b : base) res = max(res, res^b);
        return res;
    }
    bool represent(long long t) const { return reduce(t) == 0; }
private:
    vector<long long> base;
};

int main(){
    int N; cin >> N;
    long long all = 0;
    XorBase xb;
    vector<long long> a(N);
    for(auto& t : a){
        cin >> t;
        all ^= t;
    }
    for(auto& t : a) xb.add(t&~all);
    cout << 2*xb.getMax()+all << endl;
}

Measured memory_bytes: 1024
/***********************************************
#
#      Filename: d.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-05-20 20:43:42
***********************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3 * 100000 + 10;
int N;
int x[maxn];
ll d1[maxn];
ll d2[maxn];
multiset<int> st;

void findpre() {
    ll sum = 0;
    st.clear();
    for (int i = 1; i <= N; ++ i) {
        sum += x[i] * 1LL;
        st.insert(x[i]);
    }
    d1[N] = sum;
    for (int i = N+1; i <= 2*N; ++ i) {
        int cur = x[i];
        if (cur <= *st.begin()) {
            d1[i] = d1[i-1]; // make as large as possible
            continue;
        }
        int r = *st.begin();
        st.erase(st.begin());

        st.insert(x[i]);
        d1[i] = d1[i-1] - r * 1LL + cur * 1LL;
    }
}

void findsuf() {
    ll sum = 0;
    st.clear();
    for (int i = 3*N; i >= 2*N+1; -- i) {
        sum += x[i] * 1LL;
        st.insert(x[i]);
    }
    d2[2*N+1] = sum;
    for (int i = 2*N; i >= N+1; -- i) {
        int cur = x[i];
        if (cur >= *st.rbegin()) { // max value in st
            d2[i] = d2[i+1];
            continue;
        }
        int r = *st.rbegin();
        // st.erase(r); 会把r全部删除！！！
        st.erase( st.find(r) ); // 只删除一个
        st.insert(x[i]);
        d2[i] = d2[i+1] - r * 1LL + cur * 1LL;
    }
}

int main()
{
    cin >> N;
    for (int i = 1; i <= 3*N; ++ i) {
        cin >> x[i];
    }
    findpre();
    findsuf();
    ll ans = - ( 1LL << 60 );
    for (int i = N; i <= 2*N; ++ i) {
        ll tmp = d1[i] - d2[i+1];
        if (tmp > ans)
            ans = tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
char s[100005][5];
char ans[100005];
int main()
{
	ll n,a,b,c,i,j,cnt=0,flag=0;
	cin>>n>>a>>b>>c;
	for(i=0;i<n;i++)
	{
		cin>>s[i][0]>>s[i][1];
	}
	for(i=0;i<n;i++)
	{
		if((s[i][0]=='A'&&s[i][1]=='B')||(s[i][0]=='B'&&s[i][1]=='A'))
		{
			if(a<b)
			{
				a++;
				b--;
				ans[cnt++]='A';
			}
			else if(a>b)
			{
				a--;
				b++;
				ans[cnt++]='B';
			}
			else
			{
				if(s[i+1][0]=='A'||s[i+1][1]=='A'||a==0)
				{
					a++;
					b--;
					ans[cnt++]='A';
				}
				else
				{
					a--;
				    b++;
				    ans[cnt++]='B';
				}
			}
		}
		else if((s[i][0]=='A'&&s[i][1]=='C')||(s[i][0]=='C'&&s[i][1]=='A'))
		{
			if(a<c)
			{
				a++;
				c--;
				ans[cnt++]='A';
			}
			else if(a>c)
			{
				a--;
				c++;
				ans[cnt++]='C';
			}
			else
			{
				if(s[i+1][0]=='A'||s[i+1][1]=='A'||a==0)
				{
					a++;
					c--;
					ans[cnt++]='A';
				}
				else
				{
					a--;
				    c++;
				    ans[cnt++]='C';
				}
			}
		}
		else
		{
			if(c<b)
			{
				c++;
				b--;
				ans[cnt++]='C';
			}
			else if(c>b)
			{
				c--;
				b++;
				ans[cnt++]='B';
			}
			else
			{
				if(s[i+1][0]=='C'||s[i+1][1]=='C'||c==0)
				{
					c++;
					b--;
					ans[cnt++]='C';
				}
				else
				{
					c--;
				    b++;
				    ans[cnt++]='B';
				}
			}
		}
		if(a<0||b<0||c<0)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	cout<<"No";
	else
	{
		cout<<"Yes"<<endl;
		for(i=0;i<cnt;i++)
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4224
n, m = map(int, input().split())
a = list(map(int, input().split()))

def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1:
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res
 

li = []
a.sort()
for aa in a:
  li = insertHeap(li, aa)

for i in range(m):
  val = desertHeap(li)
  li = insertHeap(li, val//2)

print(sum(li))
  

Measured memory_bytes: 14480
X,K,D = (int(x) for x in input().split())

ans = 0

X = abs(X)
amari = X % D
sho = X // D
if sho > K:
    ans = X - K * D
else:
    if sho % 2 == K % 2:
        ans = amari
    else:
        ans = abs( amari - D )

print(ans)

Measured memory_bytes: 9188
#include "bits/stdc++.h"
using namespace std;
 
long long int n, q;
 
void solve(){
    cin >> n;
    long long int sum = 0;
    vector<long long int> freq(100069, 0);
    for(long long int i = 0, inp; i < n; ++i){
        cin >> inp;
        freq[inp]++;
        sum += inp;
    }
    cin >> q;
    while(q--){
       long long int b, c;
        cin >> b >> c;
        sum -= freq[b]*b;
        sum += freq[b]*c;
        freq[c] += freq[b];
        freq[b] = 0;
        cout << sum << endl;
    }
}
 
int32_t main(){
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    // int t; cin >> t;
    // while(t--)
        solve();
    return 0;
}

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

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

  if (n == 1) cout << "Hello World" << endl;
  else {
    cin >> a >> b;
    cout << a+b << endl;
  }
}


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

using namespace std;

int main() {
    int n,ans = 0;
    cin >> n;
    int p[n] = {0};
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    for (int i=0;i<n-2;i++){
        if ((p[i] < p[i+1] && p[i+1] < p[i+2] )|| (p[i+2] < p[i+1] && p[i+1] < p[i])){
            ans++;
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
while True :
    x=int(input())
    if x==0 : break
    i=1
    a=1
    b=0
    while i<=x :
        a=a*i
        i=i+1
        
    while True :
        if a%10==0 :
            b=b+1
            a=a//10
        else : break
    print(b)


Measured memory_bytes: 5632
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a >= 13)
		printf("%d\n", b);
	else if (a >= 6)
		printf("%d\n", b / 2);
	else
		printf("0\n");
	return 0;
}

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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e = a*b;
	int f = c*d;
	if (e > f){
		cout << e;
	} else {
		cout << f;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int head[N],cnt=0,siz[N],n;
ll inv[N],pp[N];
ll dp[N];
ll ans[N];
struct edge{
    int next,to;
}e[N<<1];
void add(int u,int v){
    e[++cnt].next=head[u];
    e[cnt].to=v;
    head[u]=cnt;
}
ll pow(ll a, ll n, ll p)
{
    ll ans = 1;
    while(n)
    {
        if(n & 1) ans = ans * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return ans;
}
void init(){
    inv[1]=inv[0]=1;
    for(int i=2;i<=2e5;i++)inv[i]=inv[i-1]*pow(i,mod-2,mod)%mod;
    pp[0]=pp[1]=1;
    for(int i=2;i<=2e5;i++)pp[i]=pp[i-1]*i%mod;

}
ll cal(int n,int m){
    return pp[m]*inv[n]%mod*inv[m-n]%mod;
}
void dfs(int u,int fa){
    siz[u]=1;
    dp[u]=1;
    for(int i=head[u];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        dfs(v,u);
        dp[u]=dp[u]*dp[v]%mod*cal(siz[v],siz[u]+siz[v]-1)%mod;
        siz[u]+=siz[v];
    }
}
void dfs1(int u,int fa){
    for(int i=head[u];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        dp[v]=dp[u]*pow(cal(siz[v],siz[u]-1),mod-2,mod)%mod*cal(siz[u]-siz[v],siz[u]-1)%mod;
        siz[v]=n;
        dfs1(v,u);
    }
}
int main()
{
    init();
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        add(a,b);add(b,a);
    }
    dfs(1,0);
    dfs1(1,0);
    for(int i=1;i<=n;i++)printf("%lld\n",dp[i]);
    return 0;
}


Measured memory_bytes: 13312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String st = sc.next();
		
		char[] c = s.toCharArray();
		char[] ch =st.toCharArray();
		
		int count = 0;
		
		if(c[0] == ch[0]){
			count++;
		} 
		if(c[1] == ch[1]){
			count++;
		}
		
		if(c[2] == ch[2]){
			count++;
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 21972
#!/usr/bin/env pypy

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    for _ in range(min(K,50)):
        B = [0]*N
        for i in range(N):
            l = max(0,i-A[i])
            r = min(N-1,i+A[i])
            B[l] += 1
            if r+1 < N:
                B[r+1] -= 1
        for i in range(N-1):
            B[i+1] += B[i]
        A = B

    print(*B)

if __name__ == "__main__":
    main()

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

int main() {
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	cout.precision(5);
	cout << fixed << sqrt(pow(x2-x1, 2)+pow(y2-y1, 2)) << endl;

	return 0;
}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,h,nh=0,ans1=0,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h;
        if(nh>=h){
            ans1++;
            nh=h;
        }
        else{
            ans=max(ans,ans1);
            ans1=0;
            nh=h;
        }
    }
    ans=max(ans,ans1);
    cout<<ans<<endl;
    return(0);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+9;

int n, ai, c0, c1, c2;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> ai;
        if (ai % 4 == 0) c2++;
        else 
            if (ai % 2 == 0) c1++;
            else c0++;
    }
    bool flag = true;
    if (c2 + 1 < c0) flag = false;
    if (c2 + 1 == c0 && c1 % 2 == 1) flag = false;
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

print(min(dp[H:]))


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

const ll MOD=1e9+7;
const ll MAX=1e9;
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x;
  cin>>x;
  
  int n=1;
  while(1){
    if(n*x%360==0) break;
    n++;
  }
  
  cout<<n<<endl;
  
  return 0;
}

Measured memory_bytes: 3648
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)
    elif op=='?':
        break


Measured memory_bytes: 5596
#include <iostream>

int f(std::string s) {

    int result = INT_MAX;
    for (int i = 0; i < s.size() - 2; i++) {
        int tmp = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        if (result > std::abs(753 - tmp)) {
            result = std::abs(753 - tmp);
        }
    }

    return result;
}

int main() {

    std::string s;
    std::cin >> s;

    int result = f(s);
    std::cout << result << std::endl;

    return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

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

    ll s1=0,s2=0;
    vector<int> w(N);
    REP(i,N){
        cin >> w[i];
        s1 += w[i];
    }

    ll ans=abs(s1-s2);
    REP(i,N){
        s1 -= w[i];
        s2 += w[i];
        chmin(ans,abs(s1-s2));
    }

    pl(ans)

    return 0;
}

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

int main(){
    string a;
    cin >> a;
    int c;
    c = a.length();
    if(a.at(c-1)=='s'){
        cout <<  a<<"es"<<endl;
    }else{
        cout << a<<"s"<<endl;
    }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, C, A[404], B[404];
i64 dp[404][404];
i64 psum[404][404];

i64 mpow(int a, int b)
{
	i64 ret = 1;
	while (b--) ret = ret * a % MOD;
	return ret;
}

int main()
{
	scanf("%d%d", &N, &C);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);
	for (int i = 0; i < N; ++i) scanf("%d", B + i);

	for (int i = 0; i <= 400; ++i) {
		i64 tmp = 0;
		for (int j = 0; j <= 400; ++j) {
			ADD(tmp, mpow(j, i));
			psum[i][j] = tmp;
//			if (i < 10 && j < 10) printf("%d %d %lld\n", i, j, psum[i][j]);
		}
	}

	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int w = 0; w <= C; ++w) {
			dp[i + 1][w] = 0;
			for (int j = 0; j <= w; ++j) {
			//	printf("%d %d %d\n", i, w, j);
				ADD(dp[i + 1][w], dp[i][w - j] * (MOD + psum[j][B[i]] - psum[j][A[i] - 1]) % MOD);
			}
		}
	}

	printf("%lld\n", dp[N][C]);
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef pair<long,long>P;
P solve(P p){
  long x=p.first,y=p.second;
  if(x%y==1)return P(1,-(x/y));
  if(y==-1)return P(1,x-1);//x -1  * 1 x-1
  P r_=solve(P(y,x%y));
  long a_=r_.first,b_=r_.second;
  P r(b_,a_-b_*(x/y));
  return r;
}

int main(){
  long N;cin>>N;long n=2*N;
  map<long,long>p;
  for(long i=2;i*i<=n;i++){
    while(n%i==0){
      if(p[i]==0)p[i]=i;
      else p[i]*=i;
      n/=i;
    }
  }
  if(n!=1)p[n]=n;
    
  long ans=1000000000000000;
  vector<long>keys;
  for(auto [key,value]:p)keys.push_back(key);
  for(long i=0;i<(1<<keys.size());i++){
    long x=1,y=1;
    bitset<20>bit(i);
    for(long j=0;j<keys.size();j++){
      if(bit.test(j)) x*=p[keys[j]];
      else y*=p[keys[j]];
    }
    
    
    //if(x!=1&&y!=1)
    P p=solve(P(x,-y));
    long r=max((-p.first+y-1)/y,(-p.second+x-1)/x);
    long b=p.second+x*r;
    if(b*y>0)ans=min(ans,b*y);
    //cout<<b*y<<endl;
  }
  cout<<ans;
}
/*
k+1 k=2Nr


2N=x*y
k+1=ax
k=byとして

1=xa+(-y)b
このようなa,bの一般解を求めたとして, a>0,b>0を満たす最小のa,bを求めればいい

a=a0+yr
b=b0+xr
a>0,b>0となるような最小のrを探す
a0+yr>0 && b0+xr>0
r>-a0/y, -b0/x

2 -1*  =1
2の場合
1 2 3

1の場合1
*/

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   int n;
   cin >> n;
   vector<P> v;
   v.push_back(make_pair(0, 0));
   rep(i, n) { 
       int t, x, y;
       cin >> t >> x >> y;
       v.push_back(make_pair(t, x + y));
   }
   bool flag = true;
   rep(i, n) {
       int time = v[i + 1].first - v[i].first;
       int dist = abs(v[i + 1].second - v[i].second);
       if(time == dist)
           continue;
       else if(time > dist) {
           if(dist == 0) {
               time = time - 4;
           } else {
               time = time - dist;
           }
           if(time % 2 != 0) {
               flag = false;
               break;
           }
       }else{
           flag = false;
           break;
       }
   }
   if(flag)
       cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int n,l;
    cin >> n >> l;
    vs s(n);
    rp(i,n){
        cin >> s.at(i);
    }
    sort(all(s));
    rp(i,n){
        cout << s.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())  # nは入力回数
num_list = list(map(int, input().split()))
count = 0

if n%2 == 0:
  for i in range(n//2):
    if (num_list[2*i]%2) == 1:
      count += 1
else:
  for i in range((n//2) + 1):
    if (num_list[2*i]%2) == 1:
      count += 1
      
print(count)

Measured memory_bytes: 9116
#include<stdio.h>
#include<stdint.h>
#define a 97
#define A 65

int main(){
  char S[3][101];
  uint8_t *P[3],x;

  P[0]=&S[0][0];
  P[1]=&S[1][0];
  P[2]=&S[2][0];

  scanf("%s%s%s",&S[0],&S[1],&S[2]);

  while(*P[x])
    x=*P[x]++-a;

  printf("%c\n",x+A);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    int A,B;
    int a,b,c,Ans;

    scanf("%d %d",&A,&B);

    a = A + B;
    b = A - B;
    c = A * B;

    if(a > b)
        Ans=a;
        else
        Ans=b;

    if(Ans>c)
        Ans = Ans;
        else 
        Ans=c;

    printf("%d\n",Ans);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
ll N,D;
  cin>>N>>D;
ll X[N],Y[N];
ll L;
  ll ans=0;
D=D*D;
for(ll i=0;i<N;i++){
cin>>X[i]>>Y[i];
L=X[i]*X[i]+Y[i]*Y[i];
  if(L<=D){ans++;}
  //cout<<L<<","<<D<<endl;
}

  
  
     cout<<ans<<endl;
  
}


Measured memory_bytes: 6712
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 110
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

int lowerBound(vector<int> &v, int target) {
	int l = 0, r = v.size() - 1;
	while(l <= r) {
		int m = l + (r - l) / 2;
		if(v[m] < target) l = m + 1;
		else if(v[m] > target) r = m - 1;
		else r = m - 1;
	}
	return l;
}
int main() {
	int n, num, a; cin >> num >> n;
	set<int> is;
	fore(i, 0, n) {
		cin >> a;
		is.insert(a);
	}
	vector<int> v;
	fori(i, 0, MAX) {
		if(!is.count(i)) v.pb(i);
	}
	int ind = lowerBound(v, num), size = v.size();
	int best = 10000, ans, ini = std::max(0, ind-5), end = std::min(size, ind+5);
	fore(i, ini, end) {
		int dif = abs(v[i] - num);
		if(dif < best) {
			best = dif;
			ans = v[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s ;
   cin >> s ;
  
  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
    cout << "Bad" << endl ;
  else
    cout << "Good" << endl ;
  
     
    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 105;
int n, k, d, cn[MX], res;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	while (k--) {
		cin >> d;
		while (d--) {
			int x;
			cin >> x;
			cn[x]++;
		}
	}

	for (int i = 1; i <= n; i++)
		if (!cn[i])
			res++;

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 18;

int N;
int A[1 << MAX_N];
int memo[2][1 << MAX_N];
ll memo2[1 << MAX_N];

int main(){
	cin >> N;
	for(int i = 0; i < (1 << N); i++) cin >> memo[0][i];
	fill(memo2, memo2 + (1 << N), 0LL);

	for(int i = 0; i < N; i++){
		for(int j = 0; j < (1 << N); j++){
			if(j & (1 << i)) continue;
			int next = j | (1 << i);
			for(int k = 0; k < 2; k++){
				memo[1][next] = max(memo[1][next], memo[k][j]);
				if(memo[0][next] < memo[1][next]) swap(memo[0][next], memo[1][next]);
			}
		}
	}

	for(int i = 0; i < (1 << N); i++) memo2[i] = (ll)memo[0][i] + (ll)memo[1][i];
	for(int i = 0; i < (1 << N); i++){
		if(i == 0) continue;
		memo2[i] = max(memo2[i], memo2[i - 1]);
	}

	for(int i = 1; i < (1 << N); i++) cout << memo2[i] << endl;
	return 0;
}


Measured memory_bytes: 7168