akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int MINF = -10000;
  int dp1[N+1][T+1]; //i番目の料理でt分までに食べ切れ価値の最大値
  int dp2[N+1][T+1];
  for(int i=0; i<N+1; i++){
    for(int j=0; j<T+1; j++){
      dp1[i][j] = 0;
      dp2[i][j] = 0;
    }
  }
  
  for(int i=0; i<N; i++){
    int a = vec.at(i).at(0);
    int b = vec.at(i).at(1);
    for(int j=0; j<T+1; j++){
      int x = MINF;
      if(j - a >= 0){
        x = dp1[i][j-a];
      }
      dp1[i+1][j] = max({dp1[i+1][j], dp1[i][j], x + b});
    }
  }
  
  
  for(int i=0; i<N; i++){
    int a = vec.at(N-i-1).at(0);
    int b = vec.at(N-i-1).at(1);
    for(int j=0; j<T+1; j++){
      int x = MINF;
      if(j - a >= 0){
        x = dp2[i][j-a];
      }
      dp2[i+1][j] = max({dp2[i+1][j], dp2[i][j], x + b});
    }
  }
  
  /*for(int i=0; i<N+1; i++){
    for(int j=0; j<T+1; j++){
      cout << dp1[i][j] << " ";
    }
    cout << endl;
  }*/
  
  
  int ans = 0;
  for(int i=0; i<N; i++){
    for(int j=0; j<T; j++){
      ans = max(ans,dp1[i][j] + dp2[N-i-1][T-j-1] + vec.at(i).at(1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<int>>data(h,vector<int>(w));
    int bcnt = 0;
    rep(i,h){
        rep(j,w){
            char c;
            cin >> c;
            if(c == '.')data[i][j]=0;
            else {
                data[i][j]=1;
                bcnt++;
            }
        }
    }
    int l = bcnt-k;
    int ans = 0;
    for(int i = 0;i < 1<<h;i++){
        for(int j = 0;j < 1<<w;j++){
            int cnt = 0;
            rep(a,h){
                rep(b,w){
                    if(i>>a & 1 || j >> b & 1){
                        
                            if(data[a][b]==1)cnt++;
                        
                    }
                }
            }
            if(cnt == l)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#![allow(unused_imports)]
#![allow(dead_code)]

use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let ma: usize = sc.read();
    let mb: usize = sc.read();
    let abc: Vec<(usize, usize, i32)> = (0..n).map(|_| (sc.read(), sc.read(), sc.read())).collect();
    let inf = 10000000;
    let init: Vec<Vec<i32>> = (0..401)
        .map(|i| {
            (0..401)
                .map(|j| if i == 0 && j == 0 { 0 } else { inf })
                .collect()
        })
        .collect();
    let dp = abc.iter().fold(init, |acc, &v| {
        let (a, b, c) = v;
        (0..401)
            .map(|i| {
                (0..401)
                    .map(|j| {
                        let res = acc[i][j];
                        if i >= a && j >= b {
                            std::cmp::min(res, acc[i - a][j - b] + c)
                        } else {
                            res
                        }
                    })
                    .collect()
            })
            .collect()
    });
    let cand = (1..)
        .take_while(|x| x * ma <= 400 && x * mb <= 400)
        .map(|y| dp[y * ma][y * mb])
        .min()
        .unwrap();
    let ans = if cand == inf { -1 } else { cand };
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

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


int main() {
    
    int a, b;
    int p[4] = { 4,6,9,11 };
    cin >> a >> b;
    if (a == b)cout << "Yes" << endl;
    else if (a == 2 || b == 2)cout << "No" << endl;
    else {
        for (int i = 0; i < 4; i++) {
            if (p[i] == a)a = 0;
            if (p[i] == b)b = 0;
        }
        if ((!a&&b)||(a&&!b))cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
    
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

template<class T> inline void chmax(T &x, const T &y) {if (x < y) x = y;}

int N, W;

long long dp[100100];

int main()
{
  cin >> N >> W;
  while (N--) {
    int w, v; cin >> w >> v;
    for (int i = W; i >= 0; --i)
      if (i + w <= W) chmax(dp[i+w],dp[i] + v);
  }
  
  cout << dp[W] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,m,a[100005],s=0;
vector<int> g[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	while(m--){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y),g[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		int flag=0;
		for(int y:g[i]){
			if(a[y]>=a[i])flag=1;
		}
		s+=!flag;
	}
	cout<<s;
}


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    int ans=-1;
    for(int i=0; i<=1000; i++)
    {
    	int var1=i*8/100;
    	int var2=i*10/100;
    	if(var1==a && var2==b)
    	{
    		ans=i;
    		break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
#include<functional>
#define MM 1000000007
using namespace std;

int main(void)
{
	int n,i,j,al[26],s1[100000],t1[100000],w;
	char s[100001],t[100001];
	scanf("%d",&n);
	scanf("%s %s",s,t);
	for(i=0;i<26;i++)	al[i]=0;
	for(i=0;i<n;i++)	{
		s1[i]=s[i]-'a';	t1[i]=t[i]-'a';
	}
	al[s1[0]]=1;
	for(i=1;i<n-1;i++)	{
		al[s1[i]]+=al[t1[i]];
		al[s1[i]]%=MM;
	}
	printf("%d\n",al[t1[n-1]]);
	return 0;
}


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

#define int int64_t

/*global*/



signed main()
{
    int n; cin >> n;
	int sum{};
	if(n > 2){
		for(int i = 1; i < n; ++i)
		{
			sum += i;
		}
	}
	else sum = n-1;
	cout << sum << '\n';
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    string S,T;
    cin >> S;
    T = "Yes";
    if (N % 2 == 1) {
        T = "No";
    }
    if (N % 2 == 0) {
        for (int i = 0; i < N / 2; i++) {
            if (S.at(i) != S.at(i+ (N/2))) {
                T = "No";
                break;
            }
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 256
#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 n, W;
int w[105], v[105];
ll dp[105][100100];

ll solve(int i, int j){
  	if(dp[i][j] != -1) return dp[i][j];
  
	ll res;
  	if(i == n) res = 0;
  	else if(j < w[i]){
      	res = solve(i + 1, j);
    } else {
    	res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
    }

  	return dp[i][j] = res;
}

int main(){
  	cin >> n >> W;
  	rep(i, n) cin >> w[i] >> v[i];
  	memset(dp, -1, sizeof(dp));

  	cout << solve(0, W) << endl;
}	

Measured memory_bytes: 82304
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;

/*===========================================*/

ll gcd( ll a, ll b){
  if(b == 0){
    return a;
  }
  return gcd(b, a % b);
}

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

/*===========================================*/

int N;
ll T[105];

int main(){
  cin>>N;
  REP(i,0,N){
    cin>>T[i];
  }

  ll ans = T[0];
  REP(i,1,N){
    ans = lcm(ans, T[i]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.math.BigInteger;

public class Main {

    // input
    static int n;
    static List<Long> a;

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new ArrayList<Long>();
        for (int i=0;i<n;i++){
            a.add((Long)(sc.nextLong()));
        }
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){

        Long ans = new Long(0);

        int countZero = 0;
        int countNegative = 0;

        for (Long l: a) {
            if (l == 0) {
                countZero ++;
            } else if (l < 0) {
                countNegative ++;
            }
        }

        if (countZero > 0 || countNegative % 2 == 0) {
            for (Long l: a) {
                ans += Math.abs(l);
            }
        } else {
            Long tmp = Long.MAX_VALUE;
            for (Long l: a) {
                Long _l = Math.abs(l);
                ans += _l;
                tmp = (tmp < _l) ? tmp : _l;
            }
            ans -= 2 * tmp;
        }

        System.out.println(ans);

    }

    public static void main(String args[]) {

        input();
        solve();
    }
}


Measured memory_bytes: 60684
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=1000005;
int n;char s[N];
bool chk(int mid){
	rep(_,0,1){
		int k1=_,k2=mid;
		if((k2&1)!=(k1&1))--k2;
		rep(i,1,n){
			if(s[i]=='0')--k1,--k2;else
			if(s[i]=='1')++k1,++k2;else
				--k1,++k2;
			if(k1<0)k1+=2;
			if(k2>mid)k2-=2;
			if(k1>k2)goto gg;
		}
		return 1;
		gg:;
	}
	return 0;
}
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	if(n==1){puts("1");return 0;}
	int l=0,r=1e6,ans=1e6;
	while(l<=r){
		int mid=(l+r)>>1;
		if(chk(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4792
a=[2,1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571,5778,9349,15127,24476,39603,64079,103682,167761,271443,439204,710647,1149851,1860498,3010349,4870847,7881196,12752043,20633239,33385282,54018521,87403803,141422324,228826127,370248451,599074578,969323029,1568397607,2537720636,4106118243,6643838879,10749957122,17393796001,28143753123,45537549124,73681302247,119218851371,192900153618,312119004989,505019158607,817138163596,1322157322203,2139295485799,3461452808002,5600748293801,9062201101803,14662949395604,23725150497407,38388099893011,62113250390418,100501350283429,162614600673847,263115950957276,425730551631123,688846502588399,1114577054219522,1803423556807921,2918000611027443,4721424167835364,7639424778862807,12360848946698171,20000273725560978,32361122672259149,52361396397820127,84722519070079276,137083915467899403,221806434537978679,358890350005878082,580696784543856761,939587134549734843]
print(a[int(input())])


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

int kitaeri(const void* x, const void* y) {
	char* a = *(char* const*)x, *b = *(char* const*)y;
	return strcmp(a, b);
}

const char* separator = ":,.";

int n;
char data[128][1024];

int nameCount[128];
char* names[128][1024];
int visited[128];

int memberCount;
char* members[128 * 1024];

void mizuhasu(int idx) {
	int i;
	if (visited[idx]++) return;
	for (i = 1; i < nameCount[idx]; i++) {
		int j;
		int hit = -1;
		for (j = 0; j < n; j++) {
			if (strcmp(names[idx][i], names[j][0]) == 0) {
				hit = j;
				break;
			}
		}
		if (hit >= 0) mizuhasu(hit); else members[memberCount++] = names[idx][i];
	}
}

int main(void) {
	while (scanf("%d", &n) == 1 && n > 0) {
		int i;
		int ayaneru;
		for (i = 0; i < n; i++) {
			if (scanf("%1023s", data[i]) != 1) return 1;
			names[i][0] = strtok(data[i], separator);
			nameCount[i] = 1;
			while ((names[i][nameCount[i]] = strtok(NULL, separator)) != NULL) nameCount[i]++;
			visited[i] = 0;
		}
		memberCount = 0;
		mizuhasu(0);
		qsort(members, memberCount, sizeof(*members), kitaeri);
		ayaneru = 1;
		for (i = 1; i < memberCount; i++) {
			if (strcmp(members[ayaneru - 1], members[i]) != 0) {
				members[ayaneru++] = members[i];
			}
		}
		printf("%d\n", ayaneru);
	}
	return 0;
}



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

import static java.lang.Integer.parseInt;

/**
 * Pencils
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());

		int N, A, B, C, D;
		N = parseInt(st.nextToken());
		A = parseInt(st.nextToken());
		B = parseInt(st.nextToken());
		C = parseInt(st.nextToken());
		D = parseInt(st.nextToken());

		int AB, CD;
		AB = (N / A) * B;
		if (N % A > 0) AB += B;
		CD = (N / C) * D;
		if (N % C > 0) CD += D;

		System.out.println(AB < CD ? AB : CD);
	}
}


Measured memory_bytes: 24252
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static int partition(int[] a, int p, int r) {
		int tmp = 0;

		int x = a[r];
		int i = p - 1;

			for(int j = 0; j < r; j++) {
				if (a[j] <= x) {
					i = i + 1;
					tmp =a[i];
					a[i] = a[j];
					a[j] = tmp;
				}
			}

		tmp = a[i + 1];
		a[i + 1] = a[r];
		a[r] = tmp;

		return i + 1;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(new InputStreamReader(System.in));

		int matrixLength = scan.nextInt();

		int[] a = new int[matrixLength];

		for(int i = 0; i < matrixLength; i++) {
			a[i] = scan.nextInt();
		}

		int targetIndex = partition(a, 0, matrixLength - 1);

		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < a.length; i++) {
			if(i == targetIndex){
				sb.append("[");
				sb.append(a[i]);
				sb.append("]");
			} else {
				sb.append(a[i]);
			}

			if(i == a.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
		scan.close();
	}
}

Measured memory_bytes: 68384
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#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 ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p)
{ cout << "(" << p.first << ", " << p.second << ")"; return os; }
template <class T, class S> istream& operator>>(istream& os,  pair<T, S>& p)
{ os >> p.first >> p.second; return os; }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v)
{ for (auto &e : v){cout << e << " ";}cout << endl;return os; }


ll dp[100010][110];


void solve() {
    ll n,k;
    cin>>n>>k;
    vector<pair<ll,pll> > v;
    for(ll i = 1;i*i<=n;i++){
        ll a = n/i;
        v.pb(make_pair(i, pll(n/i, -1)));
        if(a != i){
            v.pb(make_pair(a, pll(i, -1)));
        }
    }
    sort(all(v));
    ll V = v.size();
    v[0].sc.sc = 1;
    rep2(i,1,V){
        v[i].sc.sc = v[i].fi - v[i-1].fi;
    }
    rep(i,V){
        dp[i][0] = v[i].sc.sc % MOD;
    }
    rep2(j,1,k) {
        ll sum = 0;
        ll now = 0;
        repr(i,V) {
            while( v[now].sc.fi >= v[i].fi ){
                sum += dp[now][j-1];
                sum %= MOD;
                now++;
            }
            dp[i][j] = sum * v[i].sc.sc % MOD;
        }
    }
    // rep(j,k){
    //     rep(i,V){
    //         cout<<dp[i][j]<<", ";
    //     }
    //     cout<<endl;
    // }
    
    ll ans = 0;
    rep(i,V){
        ans += dp[i][k-1];
        ans %= MOD;
    }
    cout<<ans<<endl;



}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    
    // cin>>t;

    rep(i,t){
        solve(); 
    }

    return 0;
}


Measured memory_bytes: 58908
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    constexpr int T = 0xff;
    constexpr ll S = T | (ll)T << 32, X = (unsigned long long)-1 / T;
    ll p[32] = {};
    ll r = 0;

    for (int i0 = 0; i0 < n; i0 += T) {
        ll p0 = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0;
        int i1 = min(T, n - i0);
        for (int i = 0; i < i1; i++) {
            ll a;
            cin >> a;

            p0 += a & X; a >>= 1;
            p1 += a & X; a >>= 1;
            p2 += a & X; a >>= 1;
            p3 += a & X; a >>= 1;
            p4 += a & X; a >>= 1;
            p5 += a & X; a >>= 1;
            p6 += a & X; a >>= 1;
            p7 += a & X;
        }

#define F(K) \
for (int h = 0; h < 4; h++) {\
    p[8 * h + K] += p##K & S;\
    p##K >>= 8;\
}
        F(0);
        F(1);
        F(2);
        F(3);
        F(4);
        F(5);
        F(6);
        F(7);
    }

    for (int k = 0; k < 32; k++) {
        ll c = p[k];
        for (int h = 0; h < 2; h++) {
            ll t = c & ((1LL << 32) - 1);
            c >>= 32;
            r += (1LL << (32 * h + k)) % P * t % P * (n - t) % P;
        }
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		char[][] frame = new char[h + 2][w + 2];
		for(int i = 0; i < frame.length; i++) {
			Arrays.fill(frame[i], '#');
		}
		char[][] picture = new char[h][w];
		for(int i = 0; i < h; i++) {
			picture[i] = sc.next().toCharArray();
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				frame[i + 1][j + 1] = picture[i][j];
			}
		}
		for(int i = 0; i < frame.length; i++) {
			System.out.println(frame[i]);
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N = 1e2+5;
const ld eps = 1e-10;

struct P{
	ld x,y;
	P(){x = 0;y = 0;}
	P(ld _x,ld _y){x = _x;y = _y;}
	ld dis(){return sqrt(x*x+y*y);}
	P norm(){ld t = (*this).dis();return P(x/t,y/t);}
	P rot(){return P(-y,x);}
//	P add(P t){return P(x+t.x,y+t.y);}
//	P sub(P t){return P(x-t.x,y-t.y);}
//	P mul(ld t){return P(x*t,y*t);}
	P operator + (const P& t){return P(this -> x+t.x,this -> y+t.y);}
	P operator - (const P& t){return P(this -> x-t.x,this -> y-t.y);}
	P operator * (const ld& t){return P(this -> x*t,this -> y*t);}
	
} p[N];
ld c[N],r[N];
int n,k;

inline bool OK(P now){
	int res = 0;
	for(int i = 0;i < n;++i)
		if((now-p[i]).dis() < r[i]+eps) res++;
	return res >= k;
}

inline bool get_P(P &p1,P &p2,int i,int j){
	ld dv = (p[i]-p[j]).dis();
    if (dv-abs(r[i]-r[j]) < eps) return 0;
    if (r[i]+r[j]-dv < eps) return 0;
 
    ld nv = r[i]*r[i]-r[j]*r[j];
    ld pv = nv/dv;
    ld av = (dv+pv)/2;
 
    P dir = (p[j]-p[i]).norm();
    P pg = (p[i]+dir*av);
 
    ld ov = sqrt(r[i]*r[i]-av*av);
    p1 = (pg+dir.rot()*ov);
    p2 = (pg+dir.rot()*(-ov));
	return 1;
}

inline bool check(ld T){
	for(int i = 0;i < n;++i) r[i] = T/c[i];
	for(int i = 0;i < n;++i)
		if(OK(p[i])) return 1;
	
	P p1,p2;
	for(int i = 0;i < n;++i){
		for(int j = i+1;j < n;++j){
			if(get_P(p1,p2,i,j)){
				if(OK(p1) || OK(p2)) return 1;
			}
		}
	}
	return 0;
}

inline ld bin_search(ld l,ld r){
	if(k == 1) return 0.0;
	for(int i = 0;i < 100;++i){
		ld m = (l+r)/2.0;
		if(check(m)) r = m;
		else l = m;
	}
	return l;
}

int main()
{
	std::ios::sync_with_stdio(0);cin.tie(0);
	
	cin >> n >> k;
	for(int i = 0;i < n;++i){
		cin >> p[i].x >> p[i].y >> c[i];
	}
	printf("%.8Lf\n",bin_search(0,1e6));
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication58
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            for (int d = 1; d <=a; d++)
            { int b = d;
                if (b % 3 == 0) { Console.Write(" " + d);continue; }
                while (b!=0)
                {
                    if (b % 10 == 3) { Console.Write(" "+d); break; }
                    b /= 10;
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9320
S = input() #4桁

YM1_s = S[:2]
YM2_s = S[2:]

YM1 = int(YM1_s)
YM2 = int(YM2_s)

if 1 <= YM1 <= 12 and 1 <= YM2 <= 12:
    print('AMBIGUOUS')
elif 1 <= YM1 <=12:
    print('MMYY')
elif 1 <= YM2 <=12:
    print('YYMM')
else :print('NA')

Measured memory_bytes: 3060
def gets_nums; gets.split(' ').map(&:to_i) end
until (n, m, a = gets_nums) == [0, 0, 0]
  puts m.times
    .lazy
    .map { gets_nums }
    .sort_by {|(h, *_)| -h }
    .reduce(a) {|current, (h, *pq)|
      i = pq.index(current)
      i.nil? ? current : pq[i - 1]
    }
end

Measured memory_bytes: 6140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

    int h, w;
    cin >> h >> w;
    ll a[h][w], b[h][w];
    rep(i, h) rep(j, w) {
            cin >> a[i][j];
        }

    rep(i, h) rep(j, w) {
            cin >> b[i][j];
        }

    bool dp[h+1][w+1][16010];
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    rep(y, h) rep(x, w) {
            if (y == 0 && x == 0) continue;
            auto preX = x - 1;
            auto preY = y - 1;
            auto A = a[y][x];
            auto B = b[y][x];
            auto AB = abs(A - B);

            if (preX >= 0) {
                rep(i, 16010) {
                    if (dp[y][preX][i]) {
                        dp[y][x][abs(i + AB)] = true;
                        dp[y][x][abs(i - AB)] = true;
                    }
                }
            }

            if (preY >= 0) {
                rep(i, 16010) {
                    if (dp[preY][x][i]) {
                        dp[y][x][abs(i + AB)] = true;
                        dp[y][x][abs(i - AB)] = true;
                    }
                }
            }
        }

    int mmin = 10000000;
    rep(i, 16010)
        if (dp[h-1][w-1][i]) {
            mmin = i;
            break;
        }


    cout << mmin << endl;
}

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

int main(){
  int N;
	cin >> N;
	string S;
	int acount=0,bcount=0,abcount=0,outcount=0;
	for(int j=0;j<N;j++){
		cin >> S;
		if(S.at(0) == 'B' || S.at(S.size() - 1) == 'A'){
			if(S.at(0) == 'B' && S.at(S.size() - 1) == 'A'){
				outcount++;
			}
			else if(S.at(0) == 'B'){
				bcount++;
			}
			else{
				acount++;
			}
		}
		for (int i=1;i<S.size();i++){
			if(S.at(i) == 'B' && S.at(i-1) == 'A'){
				abcount++;
			}
		}
	}
	if(acount <= bcount){
		abcount += acount;
	}
	else{
		abcount += bcount;
	}
	if(acount == 0 && bcount ==0 && outcount != 0){
		abcount = abcount + outcount - 1;
	}
	else{
		abcount += outcount;
	}
	cout << abcount << endl;
}

Measured memory_bytes: 256
// finish date: 2019/07/20

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    ll S;
    cin >> S;
    ll x1 = (ll) 1000000000;
    ll y2 = (S - 1) / x1 + 1;
    ll s = x1 * y2 - S;
    ll x2 = s;
    ll y1 = 1;

    cout << x1 << " " << y1 << " " << x2 << " " << y2 <<" "<< 0 << " " << 0;

    return 0;
}


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

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int cnt = 1;
        List<Integer> list = new ArrayList<>();
        while (true) {
            int i = a * cnt % b;
            if (i == c) {
                System.out.println("YES");
                System.exit(0);
            } else if (list.contains(i)) {
                System.out.println("NO");
                System.exit(0);
            } else {
                list.add(i);
                cnt++;
            }
        }
    }
}

Measured memory_bytes: 25300
#include<iostream>
#define M 1000000000LL
using namespace std;
long long S;
int main(){
    cin>>S;
    cout<<0<<" "<<0<<" "<<M<<" "<<M-(S%M?S%M:M)<<" "<<1<<" "<<(S+M-1)/M<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000+10;
int rock[MAXN];
int dp[MAXN];
int n;
int main(){
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>rock[i];
	}
	dp[0]=0;
	dp[1]=abs(rock[1]-rock[0]);
	for(int i=2;i<n;++i){
		dp[i]=min(dp[i-2]+abs(rock[i-2]-rock[i]),dp[i-1]+abs(rock[i-1]-rock[i]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
template <typename T> using vec = vector<T>;
typedef vec<int> vi;
typedef vec<ll> vl;


template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

const int MAX_N = 100;
int n;
int b[MAX_N-1];
int a[MAX_N];

int main()
{
  cin >> n;
  forn(i,n-1) cin >> b[i];

  fill_n(a,n,INT_MAX);
  forn(i,n-1) {
    chmin(a[i],b[i]);
    chmin(a[i+1],b[i]);
  }

  int total = accumulate(a,a+n,0);

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int answer = 0;
    if (n >= 1) answer += min(9, n);
    if (n >= 100) answer += min(900, n - 100 + 1);
    if (n >= 10000) answer += min(90000, n - 10000 + 1);
    cout << answer << endl;
}


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

typedef vector<int> vi;
int n,k;
vi v;
int memo[55][55][105];
int dp[55][55][105];

int remove(int l, int r, int k) {
    vector<int> sel;
    for (int i = 0; i < l; i++) {
        sel.push_back(v[i]);
    }
    for (int i = r+1; i < n; i++) {
        sel.push_back(v[i]);
    }
    sort(sel.begin(), sel.end());
    int sum = 0, cont = 0;
    for (int x : sel) {
        if (k > 0 && x < 0) {
            sum += -x;
            k--;
        }
    }
    return sum;
}

int solve(int l, int r, int k) {
    if (k <= 0) return 0;
    if (l > r) return remove(l,r,k);
    if (memo[l][r][k]) return dp[l][r][k];
    int ans = remove(l,r,k);
    ans = max(ans, v[l] + solve(l+1,r,k-1));
    ans = max(ans, v[r] + solve(l,r-1,k-1));
    memo[l][r][k] = 1;
    return dp[l][r][k] = ans;
}

int main() {
    while (cin >> n >> k) {
        v = vi(n);
        for (int i = 0; i < n; i++) {
            cin >> v[i];
        }
        memset(memo, 0, sizeof memo);
        cout << solve(0,n-1,k) << '\n';
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    double debt = 100.0;

    cin >> n;
    
    for (int i = 0; i < n; ++i) {
        debt = ceil(debt * 1.05);
    }
    cout << static_cast<int>(debt * 1000) << endl;

    return 0;
}

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


const int INF = 1000000000;

// 入力

int N;

long long h[100010];

// DP テーブル

long long dp[100010];

int main() {
  int N; 
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件

    dp[0] = 0;

    // ループ

    for (int i = 1; i < N; ++i) {
      if(dp[i]>(dp[i - 1] + abs(h[i] - h[i - 1]))){
        dp[i]=(dp[i - 1] + abs(h[i] - h[i - 1]));
      }
      if (i > 1){
        if(dp[i]>dp[i - 2] + abs(h[i] - h[i - 2])){
          dp[i]= dp[i - 2] + abs(h[i] - h[i - 2]);
        }
      }
    }

    // 答え

    cout << dp[N-1] << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int n, m, s, t;
vector<long> dist1(100005);
vector<long> dist2(100005);
vector<long> u(100005);
vector<long> v(100005);
vector<long> a(100005);
vector<long> b(100005);
vector<vector<pair<long, long>>> graph(100005);

void dijkstra(long s, vector<long> &dist, bool isYen) {
  priority_queue<pair<long,long>, vector<pair<long, long>>, greater<>> queue;
  queue.push(make_pair(0, s));
  while (!queue.empty()) {
    pair<long, long> p = queue.top();
    queue.pop();
    long start = p.second;
    long d = p.first;
    if (d > dist.at(start)) {
      continue;
    }
    for (auto e : graph.at(start)) {
      long end = e.first;
      long train = e.second;
      long cost = isYen ? a.at(train) : b.at(train);
      if (dist.at(end) > d + cost) {
        dist.at(end) = d + cost;
        queue.push(make_pair(dist.at(end), end));
      }
    }
  }
}

int main() {
  cin >> n >> m >> s >> t;
  for (int i=1; i<=m; i++) {
    cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i);
  }

  for (int i=1; i<=m; i++) {
    graph.at(u.at(i)).push_back(make_pair(v.at(i), i));
    graph.at(v.at(i)).push_back(make_pair(u.at(i), i));
  }

  for (int i=1; i<=n; i++) {
    dist1.at(i) = LONG_MAX;
    dist2.at(i) = LONG_MAX;
  }
  dist1.at(s) = 0;
  dist2.at(t) = 0;

  dijkstra(s, dist1, true);
  dijkstra(t, dist2, false);

  vector<long> dvec(n+1);
  for (int i=1; i<=n; i++) {
    dvec.at(i) = dist1.at(i) + dist2.at(i);
  }
  for (int i=n-1; i>=1; i--) {
    dvec.at(i) = min(dvec.at(i), dvec.at(i+1));
  }
  long init = 1;
  for (int i=1; i<=15; i++) {
    init *= 10;
  }
  for (int i=1; i<=n; i++) {
    cout << init-dvec.at(i) << endl;
  }
}


Measured memory_bytes: 14848
#include <algorithm>
#include <cstdio>
using namespace std;
int n;
struct node{
	int sum,rank;
}	pool[200005];
bool cmp1(const node &a,const node &b){
	return a.sum<b.sum;
}
bool cmp2(const node &a,const node &b){
	return a.rank<b.rank;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		pool[i].rank=i;
		pool[i].sum=t;
	}
	sort(pool+1,pool+1+n,cmp1);
	int book=pool[n].rank,maxx=pool[n-1].sum;
	sort(pool+1,pool+1+n,cmp2);
	for(int i=1;i<=n;i++){
		if(i!=book)	printf("%d\n",pool[book].sum);
		else	printf("%d\n",maxx);
	}
	return 0;
}

Measured memory_bytes: 3072
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	x := scanInts(m)

	if n >= m {
		fmt.Fprintln(wr, 0)
		return
	}

	sort.Ints(x)
	y := m-n
	arr := make([]int, m-1)
	for i := 0; i < m-1; i++ {
		arr[i] = x[i+1] - x[i]
	}

	sort.Ints(arr)

	ans := 0
	for i := 0; i < y; i++ {
		ans += arr[i]
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 2944
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type Line struct {
	l, r int
}

type Byl []Line

func (a Byl) Len() int           { return len(a) }
func (a Byl) Less(i, j int) bool { return a[i].l < a[j].l }
func (a Byl) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M, Q := sc.nextInt(), sc.nextInt(), sc.nextInt()
	lines := make([]Line, M)
	for i := 0; i < M; i++ {
		lines[i] = Line{sc.nextInt() - 1, sc.nextInt() - 1}
	}
	sort.Sort(Byl(lines))
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int, N)
	}
	for i := 0; i < M; i++ {
		l, r := lines[i].l, lines[i].r
		A[l][r]++
	}
	S := make([][]int, N)
	for i := 0; i < N; i++ {
		S[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		for j := 1; j <= N; j++ {
			S[i][j] += S[i][j-1] + A[i][j-1]
		}
	}
	for i := 0; i < Q; i++ {
		ans := 0
		p, q := sc.nextInt()-1, sc.nextInt()-1
		for j := p; j <= q; j++ {
			ans += S[j][q+1]
		}
		fmt.Fprintln(wtr, ans)
	}
}


Measured memory_bytes: 8320
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String ans = "Yes";
    for(int i = 0; i < N; i++){
      String[] s = sc.nextLine().split(" ");
      int t = Integer.parseInt(s[0]);
      int x = Integer.parseInt(s[1]);
      int y = Integer.parseInt(s[2]);
      
      if(t < x+y || t%2 != (x+y)%2 ){
        ans = "No";
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 110396
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
bit_len = len(format(k, 'b'))
for i in range(n):
    bit_len = max(bit_len, len(format(a[i],'b')))
bit_count = [0 for i in range(bit_len)]
for i in range(n):
    bit = format(a[i], 'b').zfill(bit_len)
    for j in range(bit_len):
        if bit[j] == '1':
            bit_count[j] += 1
ans = 0
now_num = 0
for i in range(bit_len):
    if bit_count[i] < n - bit_count[i]:
        if now_num + 2 ** (bit_len - i - 1) <= k:
            now_num += 2 ** (bit_len - i - 1)
            ans += (n - bit_count[i]) * (2 ** (bit_len - i - 1))
            continue
    ans += bit_count[i] * (2 ** (bit_len - i - 1))
print(ans)

Measured memory_bytes: 69264
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main(){

	int n;
	int l[11];
	int total=0;
	int x=0;

	cin>>n;
	rep(i,n){
		cin>>l[i];
		x=max(x,l[i]);
		total+=l[i];
	}
	if(total-x>x)cout<<"Yes"<<endl;
	if(total-x<=x)cout<<"No"<<endl;
	return 0;
}


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#pragma endregion

int main(){
    int x, y;
    cin >> x >> y;
    string ans = "No";
    REPS(i, x) {
        if (2*i+4*(x-i)==y) {
            ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll n;
    cin >> n;

    vector<ll> v(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    
    ll distMin = 100 * 100 * 100;
    ll ans = -1;
    for (ll x = 1; x <= 100; x++){
        ll d = 0;
        for (size_t i = 0; i < n; i++){
            d += ( x - v[i] ) * ( x - v[i] );
        }
        if( d <= distMin ){
            distMin = d;
            ans = x;
        }
    }
    
    cout << distMin << endl;


}

Measured memory_bytes: 256
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X = int(read())
A = np.array([pow(i, 5) for i in range(7000)])

for i, B_f in enumerate(A):
    for sig in [1, -1]:
        diff = A - (sig * B_f)
        if (diff == X).any():
            A_f = X + (sig * B_f)
            AA = A.tolist().index(A_f)
            B = A.tolist().index(B_f)
            print(AA, sig * B)
            sys.exit()


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
int n;in n;int m;in m;
int arr[m];
int s=0;
rep(i,m){
    in arr[i];
    s+=arr[i];
}
int ans=n-s;
if(ans<0) out -1;
else out ans;
    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 3680