akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
*A, = map(int, input().split())
p = 10**9 + 7
A.sort()
ans = 1
# 全部0以下の場合かつkが奇数の場合はトップk個の積
if A[n - 1] <= 0 and k % 2 == 1:
    for i in range(k):
        ans *= A[n - 1 - i]
        ans %= p
    print(ans)
    exit()

i = 0
j = n - 1
# kが奇数なら最大は絶対使う
if k % 2 == 1:
    ans *= A[j]
    ans %= p
    j -= 1
    k -= 1
    n -= 1
# 以下A[n-1]を除いてkを偶数として考える
k //= 2
for _ in range(min(k, n // 2)):
    # 2個ずつのペアを作って採用するかを決めていく
    left = A[i] * A[i + 1]
    right = A[j] * A[j - 1]
    if (left > right):
        ans *= left
        ans %= p
        i += 2
    else:
        ans *= right
        ans %= p
        j -= 2
print(ans)


Measured memory_bytes: 100096
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e6+7,mod=1000000007;
int n,m,ans,f[N],s[N];
int main()
{
	scanf("%d",&n);
	f[1]=1;
	for(int i=1;i<=n;i++)
	{
		if(i>=3)f[i]=(f[i]+s[i-3])%mod;
		f[i]=(f[i]+f[i-1])%mod;
		s[i]=(s[i-1]+f[i])%mod;
	}
	ans=1ll*f[n]*n%mod;
	for(int i=1;i<n;i++)ans=(ans+1ll*f[i]*(n-1)%mod*(n-1)+1ll*f[i]*min(i+1,n-1))%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 7936
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
    }
    let mut max_n = 0;
    for i in 0..(n-2)+1 {
        max_n += i;
    }
    if k > max_n {
        println!("-1");
        return;
    } else {
        let mut g = vec![];
        for i in 1..n {
            g.push((1, 1+i));
        }
        let mut l = 2;
        let mut r = 3;
        for _ in 0..max_n - k {
            if r > n {
                l += 1;
                r = l + 1;
            }
            g.push((l, r));
            r += 1;
        }
        println!("{}", g.len());
        for (l, r) in g {
            println!("{} {}", l, r);
        }
    }
}


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

int main(){
	int n;
  	string s, t;
  	cin >> n >> s >> t;
  	
  	string ans;
  	rep(i, n){
    	ans.push_back(s[i]);
      	ans.push_back(t[i]);
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    /*
    int a, b, c;
    cin >> a >> b >> c ;
    //*/

    //*
    //vector<int> vec(3);
    //cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    string vec;
    cin >> vec;
    
    //sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( vec.at(0) == vec.at(1) || vec.at(1) == vec.at(2) || vec.at(2) == vec.at(3) ){
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
    //*/
    
    //cout << min(a * b, c ) << endl;

    return 0; 
}


Measured memory_bytes: 3544
#include <iostream>
#include <stack>
#include <sstream>
#include <vector>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  stack<double> num;
  vector<double> result;
  while (getline(cin, s)) {
    stringstream ss(s);
    while (ss >> s) {
      double a, b;
      if (s == "+") {
        a = num.top();
        num.pop();
        b = num.top();
        num.pop();
        num.push(a + b);
      } else if (s == "-") {
        a = num.top();
        num.pop();
        b = num.top();
        num.pop();
        num.push(b - a);
      } else if (s == "*") {
        a = num.top();
        num.pop();
        b = num.top();
        num.pop();
        num.push(a * b);
      } else if (s == "/") {
        a = num.top();
        num.pop();
        b = num.top();
        num.pop();
        num.push(b / a);
      } else {
        stringstream hoge(s);
        hoge >> a;
        num.push(a);
      }
    }
    result.push_back(num.top());
  }

  for (int i = 0; i < result.size(); i++)
    printf("%.6lf\n", result[i]);
  return 0;
}

Measured memory_bytes: 1312
#include "bits/stdc++.h"

using namespace std;

//-------------------------------- Libraries --------------------------------//

//-------------------------------- Type Names --------------------------------//

using i64 = int_fast64_t;

using seika = string;
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//-------------------------------- Solver --------------------------------//

void solve()
{
    int n;
    cin >> n;
    i64 ans = 0, lo = 0;
    for (int i = 0; i < n; i++)
    {
        i64 a;
        cin >> a;
        i64 k = (a - 1) / (lo + 1);
        ans += k;
        if (a == lo + 1 || i == 0)
            lo++;
        //cout << i << ' ' << k << ' ' << lo << endl;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
/**
*    created: 30.06.2020 16:25:08
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x;
    cin >> x;
    vector<int> v(1001);
    rep2(i,2,1001) {
        int tmp = i * i;
        while(tmp <= 1000) {
            v[tmp]++;
            tmp *= i;
        }
    }
    v[1]++;
    
    for (int i = x; i >= 0; i--) {
        if (v[i] > 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int a[100005],l=0,r=1e9+7;
long long n,ac;
struct BIT{
	int d[(1<<18)+1] = {};
	void ope(int x){
		for(int y=x;y;y-=y&-y) ac -= d[y];
		for(;x<=1<<18;x+=x&-x) d[x]++;
	}
};
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", a+i);
	while(l+1<r){
		int m=(l+r)/2, s=n+1;
		BIT bt;bt.ope(s);
		rep(i,n) bt.ope(s+=a[i]<m?-1:1);
		(ac+n*(n+1)/2<=n*(n+1)/4?l:r)=m;ac=0;
	}
	printf("%d\n", l);
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 100

int FLAG[N],d[N],f[N],time,n;

int G[N][N];


void DFS_visit(int u){
  FLAG[u] = 1;
  d[u] = time++;
  for(int i = 0; i < n;i++){
    if(G[u][i] == 1 && FLAG[i] == 0) {
      DFS_visit(i);
    }
  }
  FLAG[u] = 2;
  f[u] = time++;
}

void DFS(void){
  int i;
  for(i = 0; i < n;i++) FLAG[i] = 0;
  time = 1;

  for(i = 0; i < n;i++){
    if(FLAG[i] == 0) DFS_visit(i);
  }
  for(i = 0; i  < n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}
    

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n;j++){
      G[i][j] = 0;
    }
  }
  
  for(i = 0; i < n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k;j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }
  DFS();
  return 0;
}



Measured memory_bytes: 2084
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <chrono>
#include <ctime>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <iomanip>
#include <assert.h>
#include <stdio.h>
#include <cstring>
#include <random>

using namespace std;
#define int long long
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define try tr
#define pii pair<int, int>
#define ti tuple <int, int, int>
#define vi vector <int>
#define vpi vector <pii>
#define umap unordered_map
#define uset unordered_set
#define left left11
#define right right11
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define fs first
#define sc second

ld TL = 0.25;
bool is_tl = 0;
int CALLS = 0;

inline bool IS() {
    if (++CALLS == 1000) {
        CALLS = 0;
        is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
    }
    return is_tl;
}

template<typename T1, typename T2>
inline void amin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void amax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
    os << p.first << ' ' << p.second << endl;
    return os;
}

template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
    for (auto &u : v) os << u << ' ';
    os << endl;
    return os;
}

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 1e18 + 7, SM = 1e2 + 7;
const ld eps = 1e-9;
int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4];
int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];

void solve() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    int l = -1, r = n - 1, m;
    while(r - l > 1) {
        m = (l + r) / 2;
        int sum = 0;
        for (int i = 0; i <= m; i++)
            sum += a[i];
        bool f = 1;
        for (int i = m + 1; i < n; i++) {
            if(a[i] > sum * 2)
                f = 0;
            else
                sum += a[i];
        }
        if(f)
            r = m;
        else
            l= m;
    }
    cout << n - r;
}

signed main() {
    fast
    solve();
}


Measured memory_bytes: 4040
n,m=gets.split.map &:to_i;
a=n.times.map{gets.split.map &:to_i}
b=m.times.map{gets.split.map &:to_i}
a.map{|x,y|
s=1e9;j=i=0;b.map{|z,w|i+=1;n=(x-z).abs+(y-w).abs;n<s&&(s,j=n,i)}
p j}


Measured memory_bytes: 1788
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	int H;
	int W;
	int K;

	cin >> H >> W;
	cin >> K;

	vector<vector<int>> table(H, vector<int>(W));

	int ichigoDaisuke = 1;
	vector<pair<int, int>> ichigo;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			char c;
			cin >> c;
			if (c == '#') {
				ichigoDaisuke++;
				ichigo.push_back(make_pair(i, j));
			}
		}
	}


	int x = 0, y = 0;
	ichigoDaisuke = 1;

	for (int i = 0; i < ichigo.size(); ++i) {
		if (i != 0 && ichigo[i].first != ichigo[i - 1].first) {
			x = 0;
			y = ichigo[i].first;
		}
		for (int j = y; j <= ichigo[i].first; ++j) {
			for (int k = x; k <= ichigo[i].second; ++k) {
				table[j][k] = (ichigoDaisuke);
			}
		}
		ichigoDaisuke++;
		x = ichigo[i].second + 1;
	}

	for (int i = 0; i < H; ++i) {
		bool zero = 1;
		for (int j = 0; j < W; ++j) {
			if (table[i][j] != 0 && zero) {
				zero = 0;
			}
			else if (table[i][j] == 0 && !zero) {
				table[i][j] = table[i][j - 1];
			}
		}
		for (int j = 0; j < W; ++j) {
			if (zero) {
				table[i][j] = table[i - 1][j];
			}
		}
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << table[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1908
import heapq
N = int(input())
UVW = [list(map(int,input().split())) for _ in [0]*(N-1)]

E = [{} for _ in [0]*N]
for u,v,c in UVW:
    E[u-1][v-1] = c
    E[v-1][u-1] = c

def Dijkstra(N,E,start):
    d = [-1]*N
    q = [(0,start)]
    while q:
        ci,i = heapq.heappop(q)
        if d[i]!= -1:continue
        d[i] = ci
        for j,cj in E[i].items():
            if d[j]!=-1:continue
            heapq.heappush(q,(ci+cj,j))
    return d

d = Dijkstra(N,E,0)
print(*[l%2 for l in d],sep="\n")

Measured memory_bytes: 75524
import java.util.Scanner; // ?????¨?????????????????????

public class Main {
    public static void main(String[] args) {
        // ?????????????????\?????????????????¨?????? sc ??????????????? (???????????????????????????????????????????????°???????????????).
        Scanner sc = new Scanner(System.in);

        // ????????? sc ??? int ?????¨?????? 1 ?????\???????????????.
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        // ??????????????¢??????????????????????????????.
        if (x - r >= 0 && x + r <=  W && y - r >= 0 && y + r <= H) { System.out.println("Yes"); }
        else { System.out.println("No"); }
    }
}

Measured memory_bytes: 26208
import numpy as np
N = int(raw_input())
P = np.empty([N,2], dtype=float)
for i in xrange(N):
    P[i] = map(float, raw_input().split())

Distance_matrix = np.empty([N,N], dtype=float)
for i in xrange(N):
    for j in xrange(i+1,N):
        temp = np.sqrt((P[i,0] - P[j,0])**2 + (P[i,1] - P[j,1]) ** 2)
        Distance_matrix[i,j] = Distance_matrix[j,i] = temp

from itertools import permutations
path = permutations(range(N), N)

length = []
for p in path:
    sum = 0
    for i in xrange(N-1):
        sum += Distance_matrix[p[i], p[i+1]]
    length.append(sum)

print "{:12.10f}".format(np.mean(length))


Measured memory_bytes: 12592
N = int(input())
n = round(N ** 0.5)
m = 12
for i in range(1, n + 1):
    if N % i == 0:
        j = N // i
        #print('{0} , {1}'.format(i,j))
        m = min(max(len(str(i)),len(str(j))),m)
print(m)

Measured memory_bytes: 3060
#include <stdio.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&b!=c)||(b==c&&a!=c))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
S = input()
M = 2019

cnt = [0] * M
cnt[0] = 1
N = 0
ans = 0
for i, n in enumerate(map(int, S[::-1])):
    N = (N + n * pow(10, i, M)) % M
    ans += cnt[N]
    cnt[N] += 1
print(ans)


Measured memory_bytes: 9368
#include<iostream>
#include<string>
using namespace std;
int main(){
	for(;;){
		string word;
		int hand = 0, sum = 0;
		getline(cin,word);
		if(word == "#"){break;}
		for(int i=0; i<word.size(); i++){
			int flag = 2;
			if(word[i] == 'q'){flag = 1;}
			if(word[i] == 'w'){flag = 1;}
			if(word[i] == 'e'){flag = 1;}
			if(word[i] == 'r'){flag = 1;}
			if(word[i] == 't'){flag = 1;}
			if(word[i] == 'a'){flag = 1;}
			if(word[i] == 's'){flag = 1;}
			if(word[i] == 'd'){flag = 1;}
			if(word[i] == 'f'){flag = 1;}
			if(word[i] == 'g'){flag = 1;}
			if(word[i] == 'z'){flag = 1;}
			if(word[i] == 'x'){flag = 1;}
			if(word[i] == 'c'){flag = 1;}
			if(word[i] == 'v'){flag = 1;}
			if(word[i] == 'b'){flag = 1;}
			if(!hand){hand = flag;}
			else if(hand != flag){hand = flag; sum++;}
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
S=input()
T=input()
if len(S)<len(T):
  print('UNRESTORABLE')
  exit()
else:
  list=[]
  for i in range(len(S)-len(T)+1):
    count=0
    for j in range(len(T)):
      if S[i+j]==T[j] or S[i+j]=='?':
        count+=1
    if count==len(T):
      SS=S[:i]+T+S[i+len(T):]
      for m in range(len(S)):
        if SS[m]=='?':
          SS=SS[:m]+'a'+SS[m+1:]
      list.append(SS)
list.sort()
if list==[]:
  print('UNRESTORABLE')
else:
  print(list[0])

Measured memory_bytes: 64540
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	int n;
	cin >> n;
	int a[n+1], s[n+1], minn=99999999;
	s[0]=0;
	for (int i=1; i<=n; i++)
	{
		cin >> a[i];
		s[i]=s[i-1]+a[i];
	}
	for (int i=1; i<=n; i++)
		minn=min(abs(s[n]-s[i-1]-s[i-1]),minn);
	cout << minn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define maxn 120
using namespace std ;
priority_queue<double,vector<double>,greater<double> >q ;
double a[maxn] ,  ans ;
int n ;

int main () {
	cin >> n ;
	for(int i = 1 ; i <= n ; i ++) {
		cin >> a[i] ;
		q.push(a[i]) ;
	}
	for(int i = 1 ; i < n ; i ++) {
		double x = q.top() ;
		q.pop() ;
		double y = q.top() ;
		q.pop() ;
		double c = (x+y)/2 ;
		q.push(c) ;
	}
	cout << q.top() <<endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int f[50];
signed main(){
	ic(n) 
	f[0]=1;
	f[1]=1;
	rep(2,i,45)f[i]=f[i-1]+f[i-2];	
	c(f[n])
}


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

int main() {
  int n=1,y=1,x,z=0;
cin>>n>>y>>x;
for(int i=1;i<=x;i++){
if ((x%i==0)and((i>=n)and(i<=y))){z++;};

};cout<<z<<endl;return 0;}


Measured memory_bytes: 3084
#include<stdio.h>
#include<limits.h>
#define NIL -1

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, v, sum, u , minV, A[MAX];
  
  int M[MAX][MAX], key[MAX], p[MAX];
   
  scanf("%d", &n);
   
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

   for(i = 0; i < n; i++){
    key[i] = INT_MAX;
    p[i] = NIL;
    A[i] = NIL;
  }
   
  key[0]=0;
   
  while(1){
     
    u = NIL;
     
    minV = INT_MAX;
     
    for(i = 0;  i < n; i++){
       
      if(key[i] < minV && A[i] == NIL){
     
    u = i;
     
    minV = key[i];
     
      }
       
    }  

    if(u == NIL)break;
     
    A[u] = u; 
     
    for(v = 0; v < n; v++){
      if(M[u][v] < key[v] && A[v] == NIL){
    key[v] = M[u][v];
    p[v] = u;
      }
    }
  }
   
  sum = 0;
   
  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum +=M[p[i]][i];
  }
   
  printf("%d\n", sum);
   
   
  return 0;
}

Measured memory_bytes: 804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ul sum ;
    ul n;cin >> n;
    sum = n-1;
    ul m = (ul)(sqrt(n)+0.9999999999);
    if(n<3){cout<<0<<endl;return 0;}
    for(int i = 2;i < m;i++){
        if(n%i==0){
            if(n/i-1>i)sum+=n/i-1;
        }
    }
    //cout << sizeof(ul) << sizeof(ll)<< endl;
    cout << sum << endl;
    return 0;
}


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


L = 2019
S = input().rstrip()


A = {0 : 1}
ans = 0
tmp = 0
c = 1
for s in S[::-1]:
    n = int(s)
    tmp = (tmp + c*n) % L
    c = c * 10 % L
    if tmp in A:
        A[tmp] += 1
    else:
        A[tmp] = 1

for v in A.values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 74492
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    string S;
    void input() { cin >> S; }
    void output() {
        if (S.back() != 's') {
            S += 's';
        } else {
            S += "es";
        }
        cout << S << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll n,r;

ll keta(ll i){
    ll a=0;
    while(i>0){
        a++;
        i/=r;
    }
    return a;
}

int main(){
    cin>>n>>r;
    cout<<keta(n)<<endl;
    
    return 0;
}



Measured memory_bytes: 256
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        N = self.N
        edges = self.edges
        start = [0]*(N+1)
        elist = [0]*len(edges)
        for e in edges:
            start[e[0]+1] += 1
        for i in range(1,N+1):
            start[i] += start[i-1] 
        counter = start[:]
        for e in edges:
            elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1        
        now_ord = group_num = 0
        visited = []
        low = [0]*N
        order = [-1]*N
        ids = [0]*N
        parent = [-1]*N
        stack = []
        for i in range(N):
            if order[i] == -1:
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(start[v],start[v+1]):
                            to = elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))


Measured memory_bytes: 213280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n)){
		int flag=0;
		while(n--){
			int t,x,y;
			scanf("%d%d%d",&t,&x,&y);
			if((t-(x+y))%2||t<(x+y)){
				flag=1;
			}
		}
		if(flag){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
		
		
	}
	return 0;
}

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

int main()
{
	ll a;
	double b;
	scanf("%lld %lf",&a,&b);
	b=b+1e-7;
	ll c=b*100;
	ll d=c*a/100;
	printf("%lld",d);
	return 0;
}

Measured memory_bytes: 3820
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

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

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int n;
string t;

inline void addcom(string& a, char c){
	if(c == 'R')a += c;
	else{
		if(!a.empty() && a.back() == c)a.pop_back();
		else a += c;
	}
}

const int N = 1e6 + 5;
string com[N];
int v[N];
int num[N];

int ans[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n>>t;
    com[0] = t;

    int idx = 0;
    int mul = 1;
    FOR(i,n){
    	// process bit i
    	int m = 1;
    	REP(j,0,i)m *= 3;

    	int cbit = 0;
    	FOR(j,m){
    		idx++;
    		int par = (idx-1)/3;
    		// printf("bit %d, num %d, idx = %d\n",i,j,idx);
    		// printf("par %d\n",par);
    		v[idx] = cbit;
    		// printf("command: %s\n",com[par].c_str());
    		for(auto k : com[par]){
    			if(k == 'R'){
    				v[idx]++;
    				if(v[idx] == 3){
    					v[idx] = 0;
    					addcom(com[idx], 'R');
    				}
    			}else{
    				if(v[idx] == 1)v[idx] = 2;
    				else if(v[idx] == 2)v[idx] = 1;
    				addcom(com[idx], 'S');
    			}
    		}
    		v[idx] = v[idx] * mul + v[par];
    		num[idx] = cbit * mul + num[par];

    		if(i == n-1)ans[num[idx]] = v[idx];

    		cbit = (cbit+1)%3;
    	}
    	mul *= 3;
    }

    int m = 1;
    FOR(j,n)m *= 3;

    FOR(j,m)cout << ans[j] << " ";
    cout << endl;

    return 0;
}


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

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


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define print(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pdd pair<ld,ld> 
#define ld double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int x = 864197532, N = 50000;
const long long mod = 9223372036854775807;
const double eps = 1e-6, Pi = 3.1415926535;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector <int> a(n), b(n);
	fop (i,0,n) cin >> a[i] >> b[i];
	sort(all(a));
	sort(all(b));
	if (n % 2 == 0) {
		int k1 = n / 2 - 1, k2 = n / 2;
		cout << (b[k2] + b[k1]) - (a[k2] + a[k1]) + 1 << endl;
	} else {
		int k1 = (n - 1) / 2;
		cout << b[k1] - a[k1] + 1 << endl;
	}
}

Measured memory_bytes: 4776
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int h, w, n;
    cin >> h >> w >> n;
    int x, y;
    cin >> x >> y;

    string s, t;
    cin >> s;
    cin >> t;

    int l1 = 1, r1 = h, l2 = 1, r2 = w;

    for (int i = n - 1; i >= 0; --i) {
        if (t[i] == 'L') {
            r2 = min(w, r2 + 1); 
        } else if (t[i] == 'R') {
            l2 = max(1, l2 - 1);
        } else if (t[i] == 'U') {
            r1 = min(h, r1 + 1);
        } else if (t[i] == 'D') {
            l1 = max(1, l1 - 1);
        }

        if (s[i] == 'L') {
            ++l2;
        } else if (s[i] == 'R') {
            --r2;
        } else if (s[i] == 'U') {
            ++l1;
        } else {
            --r1;
        }

        // cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl;

        if (r1 < l1 || r2 < l2) {
            cout << "NO" << endl;
            return 0;
        } 
    }   

    if (l1 <= x && x <= r1 && l2 <= y && y <= r2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


}  


Measured memory_bytes: 920
n,k=gets.split(" ").map(&:to_i)
r,s,pa=gets.split(" ").map(&:to_i)
t=gets.chomp.to_s
te=[]
scr=0

(0..k-1).each do |x|
    if t[x]=="r"
        scr+=pa
        te[x]=pa
    elsif t[x]=="s"
        scr+=r
        te[x]=r
    else
        scr+=s
        te[x]=s
    end
end

(k..n-1).each do |x|
    if t[x]=="r"
        if t[x-k]=="r"
            if te[x-k]<pa
                scr+=(pa-te[x-k])
                te[x]=pa
            else
                te[x]=0
            end
        else
            scr+=pa
            te[x]=pa
        end
    elsif t[x]=="s"
        if t[x-k]=="s"
            if te[x-k]<r
                scr+=(r-te[x-k])
                te[x]=r
            else
                te[x]=0
            end
        else
            scr+=r
            te[x]=r
        end
    else
        if t[x-k]=="p"
            if te[x-k]<s
                scr+=(s-te[x-k])
                te[x]=s
            else
                te[x]=0
            end
        else
            scr+=s
            te[x]=s
        end
    end
end
p scr

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
main()
{
	string s;
	cin>>s;
	int n=s.size();
	bool b=0;
	for(int i=0;i<=n/2;i++)
	{
		if(s[i]!=s[n-1-i])
		{
			b=1;
			break;	
		}
	}
	if(b==1)
	{
		cout<<"No\n";
		return 0;	
	}
	for(int i=0;i<=(n-3)/4;i++)
	{
		if(s[i]!=s[(n-3)/2-i])
		{
			b=1;
			break;
		}
	}
	if(b==1)
	{
		cout<<"No\n";
		return 0;	
	}
	for(int i=(n+1)/2;i<n;i++)
	{
		if(s[i]!=s[(3*n-1)/2-i])
		{
			b=1;
			break;
		}
	}
	if(b==1)
	{
		cout<<"No\n";
		return 0;	
	}
	cout<<"Yes\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define MOD 998244353

//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll f;}sayouso;
typedef struct atai{ll n0,n1,s;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM;

//↓ここから変える
sayouso sid={0};
atai aid={0,0,0};
atai xx(atai x,atai y){
	atai ret;
	ret.n0=x.n0+y.n0;
	ret.n1=x.n1+y.n1;
	ret.s=x.s+y.s+x.n1*y.n0;
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	if(T.f){
		ret.n0=x.n1;
		ret.n1=x.n0;
		ret.s=x.n0*x.n1-x.s;
	}else{
		ret=x;
	}
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.f=S.f^T.f;
	return ret;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	rep(i,0,lsegNUM){
		lseg[i].x=aid;
		lseg[i].T=sid;
	}
	for(int i=lsegNUM-1;i>0;i--){
		lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(int i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm);
	lsegupdatesub(l,r,T,2*i+1,cm,cr);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(lsegN[2*i].T,lsegN[2*i].x),Tx(lsegN[2*i+1].T,lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(lsegN[i].T,lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(lsegN[i].T,lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm),lsegcalcsub(l,r,2*i+1,cm,cr));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM);}
//遅延セグ木ここまで
//*/

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	lseguse(1<<18);
	rep(i,1,n+1){
		int t;
		scanf("%d",&t);
		if(t)lseg[i].x.n1=1;
		else lseg[i].x.n0=1;
	}
	lseginit();
	while(q--){
		int t,l,r;
		scanf("%d%d%d",&t,&l,&r);
		if(t==1){
			sayouso T={1};
			lsegupdate(l,r+1,T);
		}else{
			printf("%lld\n",lsegcalc(l,r+1).s);
		}
	}
}

Measured memory_bytes: 18104
#include<iostream> 
#include<algorithm> 
#include<cstdio> 
#include<string>
#include<cstring>
using namespace std; 
int main() 
{ 
 	int H,W;
 	int a[105][105],b[105][105];
 	memset(b,0,sizeof(b));
	 cin>>H>>W; 
	 int i,j;
	 char ch;
	 for(i=1;i<=H;i++)
	 	for(j=1;j<=W;j++)
	 	{
	 		cin>>ch;
	 		if(ch=='.')
	 		a[i][j]=0;
	 		else if(ch=='#')
	 		a[i][j]=1;
		 }
	for(i=1;i<=H;i++)
	{
		int sum=0;
		for(j=1;j<=W;j++)
		sum+=a[i][j];
		if(sum==0)
		for(j=1;j<=W;j++)
		b[i][j]=-1;
	}
	for(j=1;j<=W;j++)
	{
		int sum=0;
		for(i=1;i<=H;i++)
		sum+=a[i][j];
		if(sum==0)
		for(i=1;i<=H;i++)
		b[i][j]=-1;
	}
	for(i=1;i<=H;i++)
	{
		int sign=0;
		for(j=1;j<=W;j++)
	 	{
	 		if(a[i][j]==0&&b[i][j]==0)
	 		{
	 			printf(".");
	 			sign=1;
			 }
	 		else if(a[i][j]==1&&b[i][j]==0)
	 		{
	 			printf("#");
	 			sign=1;
			 }
		 }
		 if(sign)
		 printf("\n");
	}
	return 0; 
}


Measured memory_bytes: 384
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      	int y = sc.nextInt();
        for(int i = 0 ; i <= n ; i++){
          for(int j = 0 ; j <= n - i ; j++){
          	 int k = n - i - j ;
            if (10000*i + 5000 * j + 1000 * k == y){
            	System.out.println(i + " " + j + " " + k );
              return;
            }
          }
        }
      System.out.println("-1 -1 -1");
    }
}


Measured memory_bytes: 39600
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int i;
        int[] test = new int[3];
        
        int x;
        int y;
        while (true) {
            for (i = 0; i < 3; i++) {
                test[i] = sc.nextInt();
            }
            if(test[0] == -1 && test[1] == -1 && test[2] == -1) break;
            if(test[0] == -1 || test[1] == -1){
                System.out.println("F");
            }else if(test[0]+test[1] >= 80){
                System.out.println("A");
            }else if(test[0]+test[1] >= 65 && test[0]+test[1] < 80){
                System.out.println("B");
            }else if(test[0]+test[1] >= 50 && test[0]+test[1] <65){
                System.out.println("C");
            }else if(test[0]+test[1] >= 30 && test[0]+test[1] <50 && test[2] >=50){
                System.out.println("C");
            }else if(test[0]+test[1] >= 30 && test[0]+test[1] <50){
                System.out.println("D");                
            }else{
                System.out.println("F");
            }              
        }
        sc.close();
    }
}


Measured memory_bytes: 26236
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;
int a[10001];
int main()
{     int m,n;
      cin>>m>>n;
      for(int i=1;i<=n;i++)
	  {  int c,b;
	     cin>>c>>b;
		 a[c]++;a[b]++;}
	  for(int i=1;i<=m;i++)cout<<a[i]<<endl; 
	  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const int N=2e5+3;
ll M=1e9+7;
ll a[N];
int main()
{
    ft
    ll i,j,n,k,l,r,s=1;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(k%2==1)
    {
        if(a[n-1]==0)
        {
            cout<<"0\n";
            return 0;
        }
        else if(a[n-1]<0)
        {
            for(i=n-1;i>=(n-k);i--)
            {
                s=(s*(a[i]+M))%M;
            }
            cout<<s<<"\n";
            return 0;
        }
        else
        {
            s=(s*(a[n-1]+M))%M;
            n--,k--;
        }
    }
    l=0,r=n-1;
    while(k>0)
    {
        if((a[l]*a[l+1])>(a[r]*a[r-1]))
        {
            s=(s*(a[l]+M))%M;
            s=(s*(a[l+1]+M))%M;
            l+=2;
        }
        else
        {
            s=(s*(a[r]+M))%M;
            s=(s*(a[r-1]+M))%M;
            r-=2;
        }
        k-=2;
    }
    cout<<s<<"\n";
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    switch (n % 10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

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

Measured memory_bytes: 3612
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#define LL long long
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int a,b;
	while(cin>>a>>b){
		cout<<(a*b+1-a-b)<<endl;
	} 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int h, w, k, ans = 0;
	cin >> h >> w >> k;
	vector<string> a(h);
	for (int i = 0; i < h; ++i)
	{
		cin >> a[i];
	}
	for (int i = 0; i < (1 << h); ++i)
	{
		for (int j = 0; j < (1 << w); ++j)
		{
			int cnt = 0;
			for (int r = 0; r < h; ++r)
			{
				for (int c = 0; c < w; ++c)
				{
					int sl = 0;
					if (a[r][c] == '#')
						cnt ++;
					if ((1 << r) & i)
						sl = 1;
					if ((1 << c) & j)
						sl = 1;
					if (sl && a[r][c] == '#')
						cnt --;
				}
			}
			
			ans += (cnt == k);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3612