akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, sub

sys.setrecursionlimit(10000)

mod = 10**9 + 7


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y//2)**2 % mod
    else:
        return power(x, y//2)**2 * x % mod


def div(a, b):
    return mul(a, power(b, mod-2))


@mt
def slv(N, A):

    def perm(n):
        p = 1
        for i in range(1, n+1):
            p = mul(p, i)
        return p

    pn = perm(N)
    sp = [0]
    for i in range(1, N+1):
        sp.append((sp[-1] + div(pn, i)) % mod)

    ans = mul(sp[-1], A[0])
    for i in range(1, N):
        ans += mul(sp[i+1] - sp[1], A[i])
        ans %= mod
        ans += mul(sp[N-i] - sp[0], A[i])
        ans %= mod
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17332
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Chicken or the Egg
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		String s = sc.next().replace("egg", "E").replace("chicken", "C");
		List<String> l = new ArrayList<String>();
		int p = 0;
		for(int i=0;i+1<s.length();i++){
			if(s.charAt(i)==s.charAt(i+1)){
				l.add(s.substring(p, i+1));
				p = i+1;
			}
		}
		l.add(s.substring(p, s.length()));
		String res = "";
		int m = 0;
		for(String t:l){
			if(m<t.length()){
				m = t.length(); res = t.charAt(m-1)=='E'?"egg":"chicken";
			}
		}
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int main() {
  long long int A,B,K;
  cin >> A >> B >> K;
  if(A>K)
    cout << A-K << " " << B;
  else{
    cout << "0 ";
    if(K-A > B)
      cout << "0\n";
    else
      cout << B-(K-A);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(b<a)a=b
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
constexpr int dx[] = {1, 0, -1,  0};
constexpr int dy[] = {0, 1,  0, -1};
constexpr char dir[4] = {'r', 'u', 'l', 'd'};
#define N 4
#define N2 16
#define LIMIT 100
vv(int, MDT, N2, N2, 0);
struct Puzzle {
	int f[N2];
	int space, MD;
};
Puzzle state;
int limit;
vi path(LIMIT, 0);
int getAllMD(Puzzle pz) {
	int sum = 0;
	rep(i, 0, N2) {
		if(pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}
bool isSolved() {
	rep(i, 0, N2) if(state.f[i] != i + 1) return false;
	return true;
}
bool dfs(int depth, int prev) {
	if(state.MD == 0) return true;
	if(depth + state.MD > limit) return false;
	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;
	int tx, ty;
	rep(r, 0, 4) {
		tx = sx + dx[r];
		ty = sy + dy[r];
		if(tx < 0 || tx >= N || ty < 0 || ty >= N) continue;
		if(max(prev, r) - min(prev, r) == 2) continue;
		tmp = state;
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if(dfs(depth + 1, r)) { path[depth] = r; return true; }
		state = tmp;
	}
	return false;
}
string iterative_deepening(Puzzle in) {
	in.MD = getAllMD(in);
	string ans = "";
	for(limit = in.MD; limit <= LIMIT; ++limit) {
		state = in;
		if(dfs(0, -100)) {
			ans = "";
			rep(i, 0, limit) ans += dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}
int main() {
	rep(i, 0, N2) {
		rep(j, 0, N2) {
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}
	Puzzle in;
	rep(i, 0, N2) {
		cin >> in.f[i];
		if(in.f[i] == 0) {
			in.f[i] = N2;
			in.space = i;
		}
	}
	P(len(iterative_deepening(in)));
	return 0;
}

Measured memory_bytes: 3204
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
 
int main()
{
	int sx, sy, tx, ty, i;

	cin >> sx >> sy >> tx >> ty;

	for(i = sx; i < tx; i++){
		cout << 'R';
	}
	for(i = sy; i < ty; i++){
		cout << 'U';
	}
	for(i = tx; i > sx; i--){
		cout << "L";
	}
	for(i = ty; i > sy - 1; i--){
		cout << "D";
	}
	for(i = sx; i < tx + 1; i++){
		cout << "R";
	}
	for(i = sy - 1; i < ty; i++){
		cout << "U";
	}
	cout << "LU";
	for(i = tx; i > sx - 1; i--){
		cout << "L";
	}
	for(i = ty + 1; i > sy; i--){
		cout << "D";
	}
	cout << "R" << endl;
}

Measured memory_bytes: 256
#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;

typedef long long ll;
using pii = pair<int, int>;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;


//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//
    
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2 == 1){
        cout << "1" <<endl;

    }
    else{
        cout << "0" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int mod=1e9+7;
const int N=(1<<16)+5;
int dp[N],to[16],from[16],Log[N],ok[N];int pow[300];int num[N];

inline int lowbit(int x){return x&(-x);}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	register int i,S,x,y,cnt;
	int totS;int n,m;
	scanf("%d%d",&n,&m);totS=(1<<n)-1;
	rep(i,0,n)	Log[1<<i]=i;
	rep(i,1,totS)	ok[i]=((i&1)+(i>>1&1))&1,ok[i]^=1,dp[i]=ok[i];
	pow[0]=1;rep(i,1,m)	pow[i]=1ll*pow[i-1]*2%mod;
	rep(i,1,totS)	num[i]=num[i>>1]+(i&1);
	rep(i,1,m){
		scanf("%d%d",&x,&y);x--;y--;
		to[x]|=(1<<y);from[y]|=1<<x;
	}
	//rep(i,1,totS)	cerr<<ok[i]<<' ';cerr<<endl;
	rep(i,1,totS) if(ok[i]){
		dp[i]=1;
		for(S=(i-1)&i;S;S=(S-1)&i) if(ok[S]){
			x=i^S;cnt=dp[x];
			while(x){
				y=lowbit(x);
				cnt=1ll*cnt*(pow[num[to[Log[y]]&S]]-1)%mod;cnt=1ll*cnt*pow[num[from[Log[y]]&S]]%mod;
				x-=y;
			}
			dp[i]=(dp[i]+cnt)%mod;
		}
	}
	//rep(i,1,totS)	cerr<<dp[i]<<' ';cerr<<endl;
	//rep(i,1,totS)	cerr<<f[i]<<' ';cerr<<endl;
	printf("%d\n",(pow[m]-dp[totS]+mod)%mod);
}
		
	

Measured memory_bytes: 768
//#pragma GCC optimize("O3") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define TASK "triangle"
#define pb push_back
#define fi first
#define se second
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) (void)42
#endif

// every true-boy doesn't read statement!

typedef long long ll;
typedef vector < ll > vi;
typedef pair < ll, ll > pll;
typedef long double ld;

const int MAXN = (int)4e5 + 22;

int X;
set < int > st;
	
bool check(int val) {
	st.clear();
	int x = X, d;
	while (x) {
		while (val) {
			d = min(val, x);
			val--;
			if (!st.count(d)) {
				x -= d;
				st.insert(d);
				break;
			}
		}
		if (val <= 0)
			break;
	}
	return x == 0;
}

void solve() {
	cin >> X;
	int l = 0, r = min((int)1e9, X), mid;
	while (r - l > 1) {
		mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid;
	}
	cout << r;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	assert(freopen("xxx.in", "r", stdin));
	assert(freopen("xxx.out", "w", stdout));
#else
	//assert(freopen(TASK".in", "r", stdin));
	//assert(freopen(TASK".out", "w", stdout));
#endif
	solve();
	return 0;
}


Measured memory_bytes: 2304
import numpy as np

N = int(input())
A = list(map(int, input().split()))

A = np.array(A)
A_cumsum = np.cumsum(A)

solver = []
for i in range(N-1):
  snuke = A_cumsum[i]
  racoon = A_cumsum[-1] - A_cumsum[i]
  solver.append(np.abs(snuke - racoon))
  
print(min(solver))
  

Measured memory_bytes: 33056
//29
#include<iostream>

using namespace std;

int main(){
  int ans[4][2]={};
  for(double e[2];cin>>e[0]>>e[1];){
    for(int i=0;i<2;i++){
      if(e[i]>=1.1){
	ans[0][i]++;
      }else if(e[i]>=0.6){
	ans[1][i]++;
      }else if(e[i]>=0.2){
	ans[2][i]++;
      }else{
	ans[3][i]++;
      }
    }
  }
  for(int i=0;i<4;i++){
    cout<<ans[i][0]<<' '<<ans[i][1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
#define all(v) ((v).begin()),((v).end())
#define clr(v,val) memset(v,val,sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main(){


	//Run();
	
	ll n;
	cin >> n;
	ll cur = 100;
	ll i = 0;
	for (i = 0; cur<n; i++) {
		cur += (cur/100);
	}
	cout << i << endl;
	
}


Measured memory_bytes: 3620
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	int a, b;
	cin >>a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h,w;
    cin>>h>>w;
    if(h == 1 or w == 1){
        cout << 1 << endl;
        return 0;
    }
    ll ret = 0ll;
    bool on = true;
    for(int i=0;i<h;++i){
        if(on)ret += 1ll*(w+1)/2,on=false;
        else ret += 1ll*w/2,on=true;
    }
    cout << ret << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int x, n,p;
    int ans = 0;
    cin >> x >> n;
    vector<bool>sq(102, true);
    rep(i, n) {
        cin >> p;
        p;
        sq[p] = false;
    }
    int minx = 200;
    rep(i, 102) {
        if (sq[i]) {
            if (minx > abs(x - i)) {
                minx = abs(x - i);
                ans = i;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;

int main(){
    int n, count =0;
    cin >> n;
    rep(i,n) {
        int x;
        cin >> x;
        if(x %2 == 0 ) {
            if(x % 3 == 0 || x %5 == 0) {

            } else {
                cout << "DENIED";
                return 0;

            }
        }
    }
    cout << "APPROVED";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0;i < N; i++) {
            String s = scan.next();
            set.add(s);
        }
        System.out.println(set.size());
    }
}


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

bool a[11];
int main(){
	int n;
	for (int i=0; i<4 ;i++){
		cin >> n;
		a[n]= true;
	}
	if(a[1]&&a[4]&&a[7]&&a[9])cout<<"YES";
	else cout << "NO";
	return 0;
}


Measured memory_bytes: 256
n,c,k=map(int,input().split())
t=sorted([int(input()) for _ in range(n)])
bc=[1]
bt=[t[0]+k]
for i in range(1,n):
  if bc[-1]<c and t[i]<=bt[-1]<=t[i]+k:bc[-1]+=1
  else:
    bc+=[1]
    bt+=[t[i]+k]
print(len(bt))

Measured memory_bytes: 18708
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



string s;
ll K;

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

  ll m = min(100LL, K);
  
  Rep(i, m) {
    if (s[i] != '1') {
      cout << s[i] << "\n";
      return 0;
    }
  }
  cout << s[m-1] << "\n";
}


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

#pragma GCC optimize ("O2")

const int maxn = 3010;
#define double long double
 
double p[maxn];
double ans;
int n;

double dp[maxn][maxn];

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr);
	
	cin >> n;
 
	for(int i = 0; i < n; i++) cin >> p[i];
 
	dp[0][0] = 1.0;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j <= n; j++)
		{
			dp[i + 1][j] += dp[i][j]*(1 - p[i]);
			if(j) dp[i + 1][j] += dp[i][j - 1]*p[i];
		}
	}

	for(int i = n/2 + 1; i <= n; i++)
	{
		ans += dp[n][i];
	}

	cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 141568
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e3+ 2;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


ll up[Max][Max],down[Max][Max],Left[Max][Max]
,Right[Max][Max];

ll n,m;

char ara[Max][Max];





void cum()
{

    ll i,j;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(ara[i][j]=='#')
                Left[i][j]=0;

            else Left[i][j]=Left[i][j-1]+1;
        }
    }

    for(i=1; i<=m; i++)
    {
        for(j=1; j<=n; j++)
        {
            if(ara[j][i]=='#')
                up[j][i]=0;

            else up[j][i]=up[j-1][i]+1;
        }
    }

    for(j=m; j>=1; j--)
    {
        for(i=n; i>=1; i--)
        {
            if(ara[i][j]=='#')
                down[i][j]=0;

            else down[i][j]=down[i+1][j]+1;
        }
    }
    for(i=n; i>=1; i--)
    {
        for(j=m; j>=1; j--)
        {
            if(ara[i][j]=='#')
                Right[i][j]=0;

            else Right[i][j]=Right[i][j+1]+1;
        }
    }

}

int main()
{

    fastread();

    ll i,j,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

    bool flag=false;



    cin>>n>>m;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
            cin>>ara[i][j];
    }

    cum();

    ans=0;


     for(i=1; i<=n; i++)
     {
         for(j=1; j<=m; j++)
         {
             if(ara[i][j]!='#')
             {
            ans=max(ans,up[i][j]+down[i][j]+Left[i][j]+Right[i][j]-3);
             }

         }
     }

     cout<<ans<<endl;












}



Measured memory_bytes: 132704
/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment
{
    using Func = function<Monoid(Monoid,Monoid )>;

    vector<Monoid> node;
    Monoid ide;
    int n = 1;

    Func bin_f;
    Func update_f;

    Segment(const vector<Monoid> &init, Monoid ide_, Func f_,Func u_f) : bin_f(f_),ide(ide_),update_f(u_f)
    {
        int sz = init.size();
        while (n < sz)
            n *= 2;
        node.assign(n * 2 - 1, ide);
        for (int i = 0; i < sz; i++)
            node[i + n - 1] = init[i];
        for (int i = n - 2; i >= 0; i--)
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void update(int i, Monoid x)
    {
        i += n - 1;
        node[i] = update_f(node[i],x);
        while (i)
        {
            i = (i - 1) / 2;
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = n;
        if (a <= l && r <= b)
            return node[k];
        if (r <= a || b <= l)
            return ide;

        Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
        Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
        return bin_f(lm, rm);
    }
};

#include <iostream>

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

    typedef long long i64;

    Segment<i64> seg(vector<i64>(n + 1, 0), 0,
                     [](i64 a,i64 b) {
                         return a + b;
                     },
                     [](i64 a,i64 b){
                         return a + b;
                     });
   for(int i = 0;i < q;i++)
   {
       int query;
       cin >> query;
       if(query == 0)
       {
           int x,y;
           cin >> x >> y;
           seg.update(x,y);
       }
       else
       {
           int x,y;
           cin >> x >> y;
           cout << seg.get_inter(x,y + 1) << endl;
       }
   } 
}


Measured memory_bytes: 5756
N=io.read("n")
A={}
for i=1,N do
  A[i]=io.read("n")
end
local count=0
local t=A[#A]
local sign=0
while true do
  for i=1,N do
    if A[i]%2==1 then
      sign=1
      break
    end
    A[i]=A[i]//2
  end
  if A[#A]==t//2 then
    count=count+1
    t=A[#A]
  end
  if sign==1 then
    break
  end
end
print(count)
  

Measured memory_bytes: 256
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  int a[n];
  rep(i, n) { a[i] = l + i; }

  int m = 1 << 21;
  rep(i, n) { m = (abs(m) < abs(a[i])) ? m : a[i]; }

  int ans = 0;
  rep(i, n) { ans += a[i]; }
  ans -= m;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
bool is(string str)
{
    string res=str;
    reverse(res.begin(),res.end());
    if(res==str)
    {
        return 1;
    }
    return false;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin>>str;
int n=str.size();
if(is(str))
{string res="";
for(int i=0;i<(n-1)/2;i++)
    res+=str[i];

     
    if(is(res))
    {res="";
       for(int i=(n+3)/2-1;i<n;i++)
       res+=str[i];

       
        if(is(res))
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
}
else
{
    cout<<"No"<<endl;
}
    return 0;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, x;
    cin >> a >> b >> x;

    // 処理
    // 出力
    if (a <= x && a + b >= x) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl            "\n"
#define ll				long long int
#define all(v)          v.begin(),v.end()
#define f(n) 			for(int i=0;i<n;i++)
#define fo(n)			for(int j=0;j<n;j++)
#define p(x) 			cout<<x<<"\n"
#define ff 				first
#define ss 				second
#define pb 				push_back
#define mp 				make_pair
#define pii 			pair<int,int>
#define vi 				vector<int>
#define vp 				vector<pii>
#define mii				map<int,int>
#define test            int tt; cin>>tt; while(tt--)
#define mod 			1000000007
#define deb(x)			cout<<#x <<" "<<x<<"\n"
void fastio()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("ain.txt", "r", stdin);
	freopen("aout.txt", "w", stdout);
#endif
}

int main()
{
	fastio();
	int n, k;
	cin >> n >> k;
	int a[n];
	f(n)cin >> a[i];
	int dp[n];
	dp[0] = 0;
	for (int i = 1; i < n; i++)
	{
		int mini = 1e9;
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)mini = min(dp[i - j] + abs(a[i] - a[i - j]), mini);
			else mini = min(mini, abs(a[i] - a[0]));
		}
		dp[i] = mini;

	}
	cout << dp[n - 1];
}



Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; 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 = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> l;
    cout<<setprecision(10)<<double(l*l*l)/27<<endl;
}

Measured memory_bytes: 256
//======================================================================
// Contents    : AOJ ITP1_8_A
//               与えられた文字列の小文字と大文字を入れ替える
// Input       : 文字列を1行に与える
// Output      : 与えられた文字列の小文字と大文字を入れ替えた文字列
// Constraints : 入力される文字列の長さ < 1200
//               アルファベット以外の文字はそのまま出力
// Author      : 廣部智也
// LastUpdate  : 2020/07/23
// Since       : 2020/07/13
//======================================================================

#include <stdio.h>

void Upper_lower_change( char str );

int main(){

    char str = 'A';

    while(1){
        scanf("%c", &str );

        if ( str == '\n' ){
            break;
        }
        
        Upper_lower_change( str );
        
    }

    printf("\n");
    
    return 0;
}



void Upper_lower_change( char str ){
    
    if( str >= 'a' && str <= 'z' ){
        str = str - ('a' - 'A');
    }
    else if( str >= 'A' && str <= 'Z' ){
        str = str + ('a' - 'A');
    }

    printf("%c", str );
    
    return;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, cnt = 0;
    string s;
    cin >> n >> s;
    fore(i,0,n-2) {
        if (s.substr(i, 3) == "ABC") cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	ret = 1
	while pow_num > 0:
		if pow_num % 2:
			ret *= num
			ret %= MOD
		num *= num
		num %= MOD
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb %= MOD
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans

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

using namespace std;

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

	int n; cin >> n;
    string s; cin >> s;

	int e1[300005],w1[300005];
	int e2[300005],w2[300005];

	e1[0] = 0; e2[0] = 0; w1[0] = 0; w2[0] = 0;

	for (int i = 1;i <= n;i++){
		if(s[i-1] == 'W') {
			w1[i] = w1[i-1]+1;
			e1[i] = e1[i-1];
		}else{
			w1[i] = w1[i-1];
			e1[i] = e1[i-1] + 1;
		}
	}

	for (int i = 1;i <= n;i++){
		if(s[n-i] == 'W') {
			w2[i] = w2[i-1]+1;
			e2[i] = e2[i-1];
		}else{
			w2[i] = w2[i-1];
			e2[i] = e2[i-1] + 1;
		}
	}

	int ans = 1000000000;
	int a;

	for (int i = 0;i < n;i++){
		a = w1[i] + e2[n - i -1];
		//cout << a << endl;
		ans = min(a,ans);
	}	

	cout << ans << endl;

	return 0;

}


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

int main(void){
    int n;
    string s;
    int i;
    int x = 0;
    int ans = 0;
    
    cin >> n;
    cin >> s;
    
    for(i = 0; i < n; i++){
        if(s[i] == 'I')     x++;
        else                x--;
        ans = max(ans, x);
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n],b[n],c[n-1];
    for(int i=0;i<n;i++)    cin >> a[i];
    for(int i=0;i<n;i++)    cin >> b[i];
    for(int i=0;i<(n-1);i++)    cin >> c[i];
    int sm=0;
    for(int i=0;i<n;i++)    sm+=b[i];
    //cout << sm << " ";
    for(int i=0;i<(n-1);i++)
    {
        if(a[i]!=n)
        {
            if((a[i]+1)==a[i+1])
            {
                sm+=c[a[i]-1];
            }
        }
    }
    cout << sm;
    return 0;
}

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

int main(void){
    int h,w,ans=0;
    scanf("%d%d",&h,&w);
    int c[10][10];
    for (int i=0; i<10; i++){
        for (int j=0; j<10; j++){
            scanf("%d",&c[i][j]);
        }
    }
    for (int k=0; k<10; k++){
        for (int i=0; i<10; i++){
            for (int j=0; j<10; j++){
                if (c[i][j]>c[i][k]+c[k][j]){
                    c[i][j]=c[i][k]+c[k][j];
                }
            }
        }
    }
    for (int i=0; i<h; i++){
        for (int i=0; i<w; i++){
            int a;
            scanf("%d",&a);
            if (a!=-1){
                ans+=c[a][1];
            }
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef std::pair<int, int> int_pair;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int a, b;
	cin >> a >> b;
	if (b % a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}

}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	double R;
  	cin >> R;
  	cout << 3.141592*R*2 <<endl;

    
  	return 0;
}







Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
    int N, M;
    vector<int> X;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int x;
        cin >> x;
        X.push_back(x);
    }

    sort(X.begin(), X.end(), greater<int>());

    vector<int> D;
    for (int i = 1; i < M; i++)
    {
        D.push_back(X[i - 1] - X[i]);
    }

    sort(D.begin(), D.end(), greater<int>());

    int ans = X[0] - X[M - 1];
    for (int i = 0; i < min(M - 1, N - 1); i++)
    {
        ans -= D[i];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=3e3+5;
const int mod=998244353;
const ll inf=1e18+7;
string s,t;int dp[N][N];bool used[N];pii last[N][N];
int main()
{
    cin>>s>>t;
    s="0"+s;
    t="0"+t;
    forn(i,1,s.length()-1){
        forn(j,1,t.length()-1){
            dp[i][j]=dp[i-1][j];
            if(dp[i][j-1]>dp[i][j]){
                dp[i][j]=dp[i][j-1];
            }
            if(s[i]==t[j]){
                if(dp[i-1][j-1]+1>dp[i][j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }
            }
            //printf("dp[%d][%d]:%d\n",i,j,dp[i][j]);
           // printf("last:[%d][%d]\n",last[i][j].f,last[i][j].s);
        }
    }
    int i=s.length()-1,j=t.length()-1;
    string str;
    while(i>=1&&j>=1){
        if(s[i]==t[j]){
            str=s[i]+str;
            i--;
            j--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    cout<<str<<endl;
    return 0;
}

Measured memory_bytes: 36480
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    n = pow(n, 0.5);
    cout << n * n << endl;
}




Measured memory_bytes: 3932
# 入力
# スペース区切りの整数の入力(定数)
n, l = map(int, input().split())

#Class-B 行ごとの入力(n行)
input_list = []
for i in range(n) :
    a = input()
    input_list.append(a)
    
# 計算と出力
input_list.sort(reverse=False)
print("".join(input_list))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    double a, b;
    cin >> a >> b;
    double ans = 0;
    for (size_t i = 1; i <= a; i++)
    {
        int counter = 0;
        int j = i;
        while(j<b){
            j *= 2;
            counter ++;
        }
        ans += 1.0/a * pow(0.5, counter);
    }
    printf("%.12f", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll INF = 1001001001001001001;
const double pi = acos(-1);

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    //左からi個取り出す
    //右からj個取り出す
    ll ans = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (i + j > k || i + j > n)
            {
                break;
            }
            ll tmp = 0;
            priority_queue<int, vector<int>, greater<int>> que;
            for (int l = 0; l < i; l++)
            {
                tmp += v[l];
                que.push(v[l]);
            }
            for (int l = 0; l < j; l++)
            {
                tmp += v[n - 1 - l];
                que.push(v[n - 1 - l]);
            }
            for (int l = 0; l < k - i - j; l++)
            {
                if (que.empty())
                {
                    break;
                }
                int x = que.top();
                if (x >= 0)
                {
                    break;
                }
                que.pop();
                tmp -= x;
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := intScanner(), intScanner()
	if n%k == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}


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

int main(){
  int N,A,B,C,D;
  cin >> N;
  cin >> A >> B >> C;
  vector<int> T(N);
  for(int i=0;i<N;i++)
    cin >> T.at(i);
  int ff = pow(4,N);
  vector<int> answ(ff,10000);
  for(int i=0;i<ff;i++){
    int I=i;
    vector<int> S(4,0);
    vector<int> Cou = {-10,-10,-10,0};
    for(int j=0;j<N;j++){
      S.at(I%4)+=T.at(j);
      Cou.at(I%4)+=10;
      I/=4;
    }
    if(Cou.at(0)==-10||Cou.at(1)==-10||Cou.at(2)==-10)
      continue;
    answ.at(i)=abs(A-S.at(0))+abs(B-S.at(1))+abs(C-S.at(2))+Cou.at(0)+Cou.at(1)+Cou.at(2);
  }
  sort(answ.begin(),answ.end());
  cout << answ.at(0);
}

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

const int M = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> t(n);
    vector<int> a(n);
    vector<int> just(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    if (n == 1) {
        if (t[0] == a[0]) {
            cout << "1\n";
        }
        else {
            cout << "0\n";
        }
        return 0;
    }
    if (t[n - 1] != a[0]) {
        cout << "0\n";
        return 0;
    }
    int hst = a[0];
    for (int i = 0; i < n - 1; ++i) {
        if (max(t[i], a[i + 1]) < hst) {
            cout << "0\n";
            return 0;
        }
    }
    just[0] = t[0];
    just[n - 1] = a[n - 1];
    for (int i = 1; i < n; ++i) {
        if (t[i] > t[i - 1]) {
            just[i] = t[i];
        }
    }
    for (int i = n - 2; i >= 0; --i) {
        if (a[i] > a[i + 1]) {
            if (just[i] && just[i] != a[i]) {
                cout << "0\n";
                return 0;
            }
            just[i] = a[i];
        }
    }
    long long ans = 1;
    for (int i = 0; i < n; ++i) {
        if (!just[i]) {
            ans = ans * min(t[i], a[i]) % M;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1408
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (map read .words) >>= print

solve :: [Integer] -> Integer
solve [n, m]
  | 2 * n <= m = n + (m - 2 * n) `div` 4
  | otherwise = m `div` 2

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define maxn 109
#define maxm 1009
using namespace std;
struct Edge
{
	int v,w,next;
}edge[maxm];
int n,m,tot,head[maxn];
int d[maxn][maxm],inq[maxn][maxm];
inline void addedge(int u,int v,int w)
{
	edge[tot].v=v;
	edge[tot].w=w;
	edge[tot].next=head[u];
	head[u]=tot++;
}
queue<pair<int,int> >Q;
void spfa()
{
	memset(d,0x3f,sizeof(d));
	d[1][0]=0;
	Q.push(make_pair(1,0));
	pair<int,int>tmp;
	while(!Q.empty())
	{
		tmp=Q.front();
		Q.pop();
		int x=tmp.first;
		int y=tmp.second;
		inq[x][y]=0;
		for(int e=head[x];e!=-1;e=edge[e].next)
		{
			int v=edge[e].v;
			if(y<m&&d[v][y+1]>d[x][y])
			{
				d[v][y+1]=d[x][y];
				if(!inq[v][y+1])
				{
					inq[v][y+1]=1;
					Q.push(make_pair(v,y+1));
				}
			}
			if(d[v][y]>d[x][y]+edge[e].w)
			{
				d[v][y]=d[x][y]+edge[e].w;
				if(!inq[v][y])
				{
					inq[v][y]=1;
					Q.push(make_pair(v,y));
				}
			}
		}
	}
}
int main()
{
	int u,v,w,c;
	while(scanf("%d%d%d",&n,&m,&c),n+m+c)
	{
		memset(head,-1,sizeof(head));
		tot=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d%d",&u,&v,&w);
			addedge(u,v,w);
		}
		spfa();
		int ans=m;
		for(int i=0;i<=m;i++)
		{
			if(d[n][i]<=c)
			{
				ans=i;
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX_K = 1000005;

bool used[MAX_K];

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int k; cin >> k;
	int currMod = 0;
	for (int i = 1;; i++)
	{
		currMod = (currMod * 10 + 7) % k;
		if (used[currMod])
		{
			cout << "-1\n";
			return 0;
		}
		used[currMod] = true;
		if (currMod == 0)
		{
			cout << i << '\n';
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 4576
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		int c= in.nextInt();
		System.out.println(Math.max(c+b-a,0));
	}
}
	

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

int soma(int *a, int b, int c, int d) {
    int n = d, *soma = malloc(sizeof(int));
    *soma = 0;
    for (int i=0; i<n; ++i) {
        if (i==b-1) {
            *soma += c;
        } else {
            *soma += a[i];
        }
    }
    return *soma;
}

int main() {
	int *n = malloc(sizeof(int)), *m = malloc(sizeof(int));
	scanf("%d", n);
	int *sec = malloc(*n * sizeof(int));
	for(int i=0; i<*n; ++i)
	    scanf("%d", &sec[i]);
	scanf("%d", m);
	int *is = malloc(*m * sizeof(int)), *drink = malloc(*m * sizeof(int));
	for (int i=0; i<*m; ++i)
	    scanf("%d %d", &is[i], &drink[i]);
	    
	for (int i=0; i<*m; ++i)
	    printf("%d\n", soma(sec, is[i], drink[i], *n));
	return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=1000000000
for i in range(n-k+1):
  ans=min(ans,abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i+k-1]-x[i]))
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字stepIndexでループするfor文に置換します
#define FOR_RANGE(stepIndex, beg, end)     for (ll stepIndex = beg; stepIndex < N; ++stepIndex)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

struct st{
    int numofCards;
    ll score;
};

int main() {
    int N, M;
    ll A[(int)1e5];
    st BC[(int)1e5];

    cin >> N >> M;
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < M; ++i) {
        int b;
        ll c;
        cin >> b >> c;
        BC[i].numofCards = b;
        BC[i].score = c;
    };

    std::sort(A, A+N); // 昇順
    std::sort(BC, BC + M, [](st l, st r) { return l.score > r.score; }); // 降順

    ll sum = 0;
    int stepIndex = 0, cardIndex = 0;
    for (stepIndex = 0; stepIndex < M; ++stepIndex) {
        if (cardIndex >= N) break;

        int numofUses = BC[stepIndex].numofCards;
        if (cardIndex + numofUses >= N) numofUses = N - cardIndex;

        if (BC[stepIndex].score < A[cardIndex + numofUses - 1]) {
            // 順番に比較
            int i;
            for (i = 0; i <= BC[stepIndex].numofCards; ++i) {
                if (A[cardIndex + i] >= BC[stepIndex].score) {
                    break;
                }
            }
            cardIndex += i;
            sum += BC[stepIndex].score * i;
            break; 
        }

        sum += BC[stepIndex].score * numofUses;
        cardIndex += numofUses;
    }

    for (int i = cardIndex; i < N; i++) sum += A[i];

    cout << sum;

    return 0;
}



Measured memory_bytes: 2560
n = int(input())
a_list = list(map(int, input().split()))


def count(num):
    _num = num
    count = 0
    while _num / 2 >= 1 and _num % 2 == 0:
        _num = _num // 2
        count += 1
    return count


cnt_list = [count(a) for a in a_list]
cnt = sum(cnt_list)

print(cnt)

Measured memory_bytes: 4148
// c_abc098.cpp
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(i = a; i < b; ++i)
#define REP(i,n)   for(i = 0; i < n; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ull powmod(ull a, ull b, ull mod) {ull res = 1; for(; b; b >>= 1){if (b & 1) {res = res * a % mod;} a = a * a % mod;} return res;}

void printVec(vector<ull> A, int N){
    for (int i = 0; i < N; i ++){
        if(i == N - 1){
            cout << A[i] << "\n";
        }else{
            cout << A[i] << " ";
        }
    }
}

ull count(string str, char c)
{
    ull cnt = 0;
    ull i;
    REP(i, str.length()){
        if(str[i] == c){
            ++cnt;
        }
    }
    return cnt;
}

int main()
{
    string s;
    ull i, tmp, n, res;
    vector<ull> r, l, cnt;
    r.push_back(0);
    l.push_back(0);

    cin >> n; cin.ignore();
    getline(cin, s);

    REP(i, n-1) {
        if (s[i] == 'W') {
            tmp = l[i] + 1;
        } else {
            tmp = l[i];
        }
        l.push_back(tmp);

        if (s[n - i - 1] == 'E') {
            tmp = r[i] + 1;
        } else {
            tmp = r[i];
        }
        r.push_back(tmp);

    }

    REP(i, n){
        cnt.push_back(r[n - i - 1] + l[i]);
    }

    // printVec(r, r.size());
    // printVec(l, l.size());
    // printVec(cnt, cnt.size());

    res = *min_element(cnt.begin(), cnt.end());
    cout << res << "\n";
}


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

int n, q; 
string s; 
const int nm = 1e5+10;
int r[nm];

void init(){
    r[1] = 0;
    for(int i=2; i<=n; i++){
        r[i] = r[i-1];
        if(s[i-1]=='A' && s[i]=='C'){
            r[i]++;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>q;
    cin>>s; s= " "+s;
    init();
    vector<int> ans;
    rep(i, q){
        int ll, rr; cin>>ll >>rr;
        ans.push_back(r[rr] - r[ll]);
    }
    rep(i, q){
        cout << ans[i] <<endl;
    }
}

Measured memory_bytes: 1896