akhauriyash/Code-Regression huggingface dataset:
//ABC125 A - 
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    float tt;
    cin>>a>>b>>tt;
    tt+=0.5;
    int t=a;
    int ans=0;
    //int cnt=1;
	while((float)t < tt) {
		ans += b;
		t += a;
        //++cnt;
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;

long long int fact(long long int k) {
	long long int sum = 1;
	for (long long int i = 2; i <= k; i++)
	{
		sum *= i;
	}
	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}


int main()
{
	long long int n;

	cin >> n;

	if(n % 2 == 0)
		cout << n / 2 - 1 << endl;
	else
		cout << n / 2 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class BIT {
    int n;
    vi data0, data1;

    void add(vi& data, int i, i64 x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }

    i64 sum(vi& data, int i) {
        i64 s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

public:
    BIT(int n) : n(n) {
        data0 = vi(n + 1);
        data1 = vi(n + 1);
    }

    // [l, r)
    void add(int l, int r, i64 x) {
        l++;
        r++;
        add(data0, l, -x * (l - 1));
        add(data1, l, x);
        add(data0, r, x * (r - 1));
        add(data1, r, -x);
    }

    // [l, r)
    i64 sum(int l, int r) {
        i64 s = 0;
        s += sum(data0, r) + sum(data1, r) * r;
        s -= sum(data0, l) + sum(data1, l) * l;
        return s;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    BIT bit(m);
    vector<int> as;
    i64 sum[101010] = {};
    {
        int a;
        cin >> a;
        a--;
        as.push_back(a);
        
        for (int i = 0; i < n - 1; i++) {
            int b;
            cin >> b;
            b--;
            as.push_back(b);
            sum[b] += (b + m - a) % m - 1;
            if (a < b) {
                bit.add(a + 1, b, 1);
            } else {
                bit.add(a + 1, m, 1);
                bit.add(0, b, 1);
            }
            a = b;
        }
    }

    i64 ans = 1e18, cur = 0;
    for (int i = 1; i < n; i++) {
        int a = as[i - 1], b = as[i];
        cur += min(1 + (b + m - 0) % m, (b + m - a) % m);
    }

    ans = cur;
    for (int i = 1; i < m; i++) {
        cur += sum[i - 1];
        cur -= bit.sum(i - 1, i);
        ans = min(ans, cur);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3196
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final long K = sc.nextLong();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		if (K == 0) {
			System.out.println(f(0, A));
			return;
		}
		long k = K;
		int numBit = 0;
		while (k > 0) {
			numBit++;
			k = k / 2;
		}

		long n = 0;
		for (int b = numBit - 1; b >= 0; b--) {
			long mask = 1L << b;
			if (n + mask > K) {
				continue;
			}
			int cnt = 0;
			for (int i = 0; i < N; i++) {
				if ((A[i] & mask) > 0) {
					cnt++;
				}
			}
			if (cnt < (N - cnt)) {
				n += mask;
			}
		}
		
		System.out.println(f(n, A));

		sc.close();
	}

	private long f(long x, long[] a) {
		long res = 0;
		for (int i = 0; i < a.length; i++) {
			res += (x ^ a[i]);
		}
		return res;
	}
}

Measured memory_bytes: 61620
#include <stdio.h>
int main(void){
 int a,b,c,d,e,f,g;
 scanf("%d %d %d %d",&a,&b,&c,&d);
 e=a-c;
 if(e<0){
  e=e-2*e;
 }
 f=a-b;
 if(f<0){
  f=f-2*f;
 }
 g=b-c;
 if(g<0){
  g=g-2*g;
 }
 if(d>=e||(d>=f&&d>=g)){
  printf("Yes");
 }else{
  printf("No");
 }
 return 0;
}

Measured memory_bytes: 128
import math

n, d = map(int, input().split())

li_p = []

for i in range(n):
    li_p.append(tuple(map(int, input().split())))

answer = 0
for x, y in li_p:
    if math.sqrt(x ** 2 + y ** 2) <= d:
        answer += 1
print(answer)


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

using namespace std;

int main() {
  int mod = 1e9 + 7;
  int n;
  cin >> n;
  long long a[n];
  for (auto &x: a) {
    cin >> x;
  }
  long long ans = 0;
  long long bit = 1;
  for (auto i = 0; i < 60; ++i) {
    long long one = 0;
    for (auto x: a) {
      if (x & bit) one++;
    }
    ans += bit % mod * one % mod * (n - one) % mod;
    ans %= mod;
    bit <<= 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
N,M = map(int,input().split())

St = [list(map(int,input().split()))for _ in range(N)]
Pt = [list(map(int,input().split()))for _ in range(M)]

for a,b in St:
    dis = [abs(a-c)+abs(b-d)for c,d in Pt]
    print(dis.index(min(dis))+1)

Measured memory_bytes: 9040
IDENTIFICATION DIVISION.
PROGRAM-ID. 149B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP PIC X(100).
01 A   PIC 9(13).
01 B   PIC 9(13).
01 K   PIC 9(13).
01 W-A PIC Z(12)9.
01 W-B PIC Z(12)9.

PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B K.
*>
  PERFORM UNTIL K <= 0
    EVALUATE TRUE
      WHEN A > K
        COMPUTE A = A - K
        MOVE 0  TO K
      WHEN A > 0 
        COMPUTE K = K - A
        MOVE 0  TO A
      WHEN B > 0 AND B > K
        COMPUTE B = B - K
        MOVE 0  TO K
      WHEN B > 0    
        COMPUTE K = K - B
        MOVE 0  TO B
      WHEN OTHER
        MOVE 0  TO K
    END-EVALUATE
  END-PERFORM.
*>
  MOVE A TO W-A
  MOVE B TO W-B
  DISPLAY FUNCTION TRIM(W-A) ' ' FUNCTION TRIM(W-B).
*>
  STOP RUN.


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

int main() {
	double l;
	cin >> l;

	double t = l / 3;
	double s = t * t * t;
	cout << fixed << setprecision(16);
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  ll count=0;
  FOR(i,0,n){
    ll a;
    	ci(a);
    if(a!=(i+1)){
      count++;
    }
  }
  if(count>2){
    co("NO")
  }
  else{
    co("YES")
  }
}

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

using namespace std;

typedef long long ll;
const ll mod=1000000007;

#define rep(i,m,n) for(ll i=m;i<n;i++)

const ll nmax=200005;

ll fac[nmax],finv[nmax],inv[nmax];

void comint(){
 fac[0]=fac[1]=1;
 finv[0]=finv[1]=1;
 inv[1]=1;
 for(long i=2;i<nmax;i++){
  fac[i]=fac[i-1]*i%mod;
  inv[i]=mod-inv[mod%i]*(mod/i)%mod;
  finv[i]=finv[i-1]*inv[i]%mod;
}
}

auto com(auto n, auto k){
 if(n<k||n<0||k<0) return 0;
 return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  comint();
  ll res=com(n*m-2,k-2);
  ll x=0,y=0;
   rep(d,1,n)(x+=(d*(n-d))%mod)%=mod;
   (x*=m)%=mod;
   (x*=m)%=mod;
   rep(d,1,m)(y+=(d*(m-d))%mod)%=mod;
   (y*=n)%=mod;
   (y*=n)%=mod;
   (res*=(x+y))%=mod;

    
  
  
  cout << res << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  ll a,b,c,d;cin>>a>>b>>c>>d;
  ll ans = a*c;
  chmax(ans,a*c);
  chmax(ans,a*d);
  chmax(ans,b*c);
  chmax(ans,b*d);

  

  print(ans);
  return 0;
}

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

int main(void){
    int cnt=0;
    string s;
    cin >> s;
    if(s[0]=='1') ++cnt;
    if(s[1]=='1') ++cnt;
    if(s[2]=='1') ++cnt;
    cout << cnt << endl;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        char[] chars = str.toCharArray();
//        preMode[i][j]表示i*10^j%2019
        ArrayList<ArrayList<Integer>> preMode = new ArrayList<>();
        preMode.add(new ArrayList<>());
//        preMode[i]的循环节
        int[] modeLoop = new int[10];
        for (int i = 1; i <= 9; i++) {
            boolean[] used = new boolean[2019];
            int mod = i;
            preMode.add(new ArrayList<>());
            while (!used[mod]) {
                preMode.get(i).add(mod);
                used[mod] = true;
                mod = mod * 10 % 2019;
                modeLoop[i] += 1;
            }
        }

        int[] modiToN = new int[str.length()];
        modiToN[chars.length - 1] = chars[chars.length - 1] - '0';
        for (int i = str.length() - 2; i >= 0; i--) {
            int numi = chars[i] - '0';
            int exp = (str.length() - i - 1) % modeLoop[numi];
            modiToN[i] = (preMode.get(numi).get(exp)+modiToN[i+1])%2019;
        }

        long[] count=new long[2019];
        for (int i:modiToN){
            count[i]+=1;
        }

        long result=0L;
        for (long i:count){
            result+=i*(i-1)/2;
        }
        result+=count[0];

        System.out.println(result);
    }
}


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

using namespace std;



int main()
{
  
  
     int a,b,c,x,cnt=0;
     scanf("%d%d%d%d",&a,&b,&c,&x);
     int i,j,k;
     for(i=0;i<=a;++i)
      {
          for(j=0;j<=b;++j)
          {
              for(k=0;k<=c;++k)
                {
                    if((i*500 + j*100 + k*50)==x)
                       cnt++;
                       
                    if((i*500 + j*100 + k*50)>x)
                        break;
                }
                 
          }
           
      }
      
      printf("%d",cnt);
    
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        int digit =0;//2進数表示したときの桁数
        long tmp = b;
        while(tmp > 0){
            digit++;
            tmp/=2;
        }
        long res = 0;
        for(int i=digit;i>=1;i--){
            long l = 1L << i;
            long amod = a%l;
            long bmod = b%l;
            long count;
            if(bmod > amod){
                count = Math.max(bmod - l/2 +1 ,0) - Math.max(amod - l/2 ,0);
            }else{
                count = l/2 - Math.max(amod -l/2,0) + Math.max(bmod-l/2+1, 0);
            }
            if(l==2){
                long mod = (b-a+1)%4;
                if(a%2==0){
                    if(mod <=1 ){
                        count = 0;
                    }else {
                        count = 1;
                    }
                }else{
                    if(mod==1 || mod == 2){
                        count = 1;
                    }else {
                        count = 0;
                    }
                }
            }

            if(count%2==0){
                res*=2;
            }else {
                res = res*2 + 1;
            }

        }
        System.out.println(res);
        sc.close();
    }
}

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

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

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

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

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        t: usize,
        mut ab: [(usize, usize); n],
    }
    ab.sort_by_key(|x| x.0);
    let mut dp = vec![0; t+3001];

    for &(a, b) in ab.iter() {
        for i in (0..t).rev() {
            dp[i + a] = max(dp[i + a], dp[i] + b);
        }
    }

    println!("{}", dp.into_iter().max().unwrap());
}


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

int main() {
  int n;
  cin>>n;
  for (int i=1; i<=9; i++) {
    for (int j=1; j<=9; j++) {
      if (i * j == n) {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
def func(n):
    if n==1:
        return 1
    return n*func(n-1)
n=int(input())
L=[0 for i in range(n)]
for i in range(n):
    L[i]=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        length=(L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2
        length=length**0.5
        ans+=length*func(n-1)*2
print(ans/func(n))

Measured memory_bytes: 9468
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

ll n, m;
int main() {
	scanf("%lld", &n);
	m = n;
	int r = 0;
	for (ll p = 2; p * p <= n; p++) {
		int count = 0;
		while (m % p == 0)
			m /= p, count++;
		if (count <= 0)
			continue;
		for (int j = 1; j <= count; j++)
			r++, count -= j;
	}
	r += m != 1;
	printf("%d\n", r);
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int m,n,i;

		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		int[][] students = new int[n][2], coordinates= new int[m][2];
		for(i=0;i<n;i++){
			students[i][0] = scanner.nextInt();
			students[i][1] = scanner.nextInt();
		}
		for(i=0;i<m;i++){
			coordinates[i][0] = scanner.nextInt();
			coordinates[i][1] = scanner.nextInt();
		}
		scanner.close();
		int distance;
		int minDis;
		int[] result = new int[n];
		for(i=0;i<n;i++){
			minDis = Integer.MAX_VALUE;
			for(int j=0;j<m;j++){
				distance = Math.abs(students[i][0] - coordinates[j][0]) + 
						Math.abs(students[i][1] - coordinates[j][1]);
				if(distance < minDis){
					result[i] = j;
					minDis = distance;
				}
			}
		}

		for(i=0;i<n;i++){
			System.out.println(result[i] + 1);
		}
	}

}

Measured memory_bytes: 21716
n = int(input())

a = [int(i)-j for i,j in zip(input().split(),range(n))]

l = -10 ** 10

r = 10 ** 10

def f(x):
  return sum(map(lambda y: abs(y - x), a))

while r - l > 3:
  l_r = (r - l) // 3
  l_i = l + l_r
  i_r = r - l_r
  if f(l_i) > f(i_r):
    l = l_i
  else:
    r = i_r
print(min(f(l),f(l+1),f(l+2),f(l+3)))
  



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

int main(){
    int n, k, h, cnt = 0;
    scanf("%d %d", &n, &k);
    for(int i=0; i<n; i++){
        scanf("%d", &h);
        if(h >= k) cnt++;}
    printf("%d\n", cnt);

    return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

int main(){
	DRIII(n,m,q);
	vector<VI> nbt(n+1,VI(n+1));  // nbt[a][b] = nb trains starting in a finishing at b
	vector<VI> nbbt(n+1,VI(n+1));  // nbt[a][b] = nb trains starting in a finishing before b
	REP(i,m){	
		DRII(l,r);
		nbt[l][r]++;
	}
	REPP(i,1,n+1){
		nbbt[i][i]=nbt[i][i];
		REPP(j,i+1,n+1){
			nbbt[i][j]=nbbt[i][j-1]+nbt[i][j];
		}
	}
	
	REP(i,q){
		DRII(p,q);
		int res=0;
		REPP(i,p,q+1){
			res+=nbbt[i][q];
		}
		printf("%d\n",res);
	}
}


Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {

	void doIt() {
		Scanner stdIn = new Scanner(System.in);

		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int[] data = new int[10];
			for(int r = 0; r < n; r++) {
				int input = stdIn.nextInt();
				data[input]++;
			}
			for(int r = 0; r < 10; r++) {
				if(data[r] != 0) {
					for(int c = 0; c < data[r]; c++) {
						System.out.print('*');
					}
					System.out.println();
				} else {
					System.out.println('-');
				}
			}
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}

}

Measured memory_bytes: 56064
#include <stdio.h>

#define MAX_NAME_LENGTH 10+1    // name????????§
#define MAX_PROCESS 100000      // ?????§??????????????°

//?????\????????????????????????????§???????
typedef struct{
    char name[MAX_NAME_LENGTH];
    int time;
}Process;

Process Q[MAX_PROCESS];
int head=0,tail=0;

//?????\??????????´?x?????????????????¢??°
void enqueue(Process x){
    Q[tail]=x;
    if(tail+1 == MAX_PROCESS){//????????°?????????????????¨??????
        tail=0;
    }else{
        tail++;
    }
}

//?????\??????????????????????´??????????????????¢??°
Process dequeue(){
    Process x = Q[head];
    if(head+1 == MAX_PROCESS){//????????°?????????????????¨??????
        head=0;
    }else{
        head++;
    }
    return x;
}

int main(){
    int n,q,i,count=0;
    Process x;
    scanf("%d %d",&n,&q);   //??????????????°n??¨???????????????n?????\???
    
    for(i=0;i<n;i++){
        scanf("%s %d",x.name,&x.time);
        enqueue(x);         //?????\??????????´?x???????????????
    }
    
    while(1){
        x=dequeue();    //?????\????????????????´????????????????
        if(x.time<=q){  //???????????????????????????????????????????????\????????£?????´???
            count+=x.time;
            printf("%s %d\n",x.name,count);
        }else {         //?????????????????????????????????????????????????????§????????£?????´???
            count+=q;
            x.time-=q;
            enqueue(x); //???????????\?????´???
        }
        if(tail==head)break;//?????\??????head??¨tail????????´??????????????\??????????????????????????£????????´???break
    }
}

Measured memory_bytes: 3264
n, k = map(int,input().split())
b = []
a = list(map(int,input().split()))
for i in range(k):
    if k-1 == i:
        b.append(n-a[i] + a[0])
    else:
        b.append(a[i+1]-a[i])

print(sum(b)-max(b))

Measured memory_bytes: 26420
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int sum = 0;
    vector<int>f(a);
    for (int i = 0; i < a; i++)
    {
        cin >> f[i];
    }
    sort(f.begin(), f.end());
    for (int i = 0; i < b; i++)
    {
        sum = sum + f[i];
        
    }

    cout << sum;
    return 0;

}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 3588
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s<< endl;
    else cout << "red" << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();
    vvi dbl(n, vi(100, 0));
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            dbl[i][0] = i + 1;
        else
            dbl[i][0] = i - 1;
    }
    for (int j = 1; j < 100; ++j) {
        for (int i = 0; i < n; ++i) {
            dbl[i][j] = dbl[dbl[i][j - 1]][j - 1];
        }
    }
    vi ret(n, 0);
    for (int i = 0; i < n; ++i) {
        ret[dbl[i][99]]++;
    }
    print(ret);
    return 0;
}

Measured memory_bytes: 43904
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);

    console.log(180 * (N - 3) + 180)
});

Measured memory_bytes: 21320
h,w,k = map(int,input().split())
y1,x1,y2,x2 = map(int,input().split())
grid = []
grid.append(['@']*(w+2))
for i in range(h):
    grid.append(['@']+list(input())+['@'])
grid.append(['@']*(w+2))

q = set()
next_q = set()
next_q.add((y1,x1))
ans = 0
while True:
    if not next_q:
        print(-1)
        exit()
    for y,x in next_q:
        grid[y][x] = '@'
    q = next_q
    next_q = set()
    while q:
        y,x = q.pop()
        if (y,x) == (y2,x2):
            print(ans)
            exit()
        for i in range(1,k+1):
            if grid[y+i][x] == '@':
                break
            next_q.add((y+i,x))
        for i in range(1,k+1):
            if grid[y-i][x] == '@':
                break
            next_q.add((y-i,x))
        for i in range(1,k+1):
            if grid[y][x+i] == '@':
                break
            next_q.add((y,x+i))
        for i in range(1,k+1):
            if grid[y][x-i] == '@':
                break
            next_q.add((y,x-i))
    ans += 1

Measured memory_bytes: 35068
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include <iomanip>
#include<string.h>
using namespace std;
const int  N = 1e4+5;
int arr[N]={0};



int main()
{
    int n;
    cin>>n;
    int x,y,z;
    for(x=1;x<=100;x++)
    {
        for(y=1;y<=100;y++)
        {
            for(z=1;z<=100;z++)
            {
                int temp = x*x+y*y+z*z+x*y+z*x+y*z;
                if(temp > 1e4)
                    break;
                arr[temp]++;
            }
        }
    }
    for(int i =1;i<=n;i++)
        cout<<arr[i]<<endl;
   
}


Measured memory_bytes: 3640
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val k = sc.nextLong()
    val a = (0 until n).map { sc.next().toLong() }
    val b = (0 until m).map { sc.next().toLong() }
    println(problem172c(n, m, k, a, b))
}

fun problem172c(
    n: Int,
    m: Int,
    k: Long,
    a: List<Long>,
    b: List<Long>
): Int {
    /**
     * 二分探索を使いkeyに一番近いkey未満のindex + 1を返す
     */
    fun lowerBound(list: List<Long>, key: Long): Int {
        var ng = -1
        var ok = list.size

        while (ok - ng > 1) {
            val mid = (ok + ng) / 2
            if (list[mid] >= key) ok = mid else ng = mid
        }
        return ok
    }

    val aS = mutableListOf<Long>()
    aS.add(0)
    for (i in 0 until n) {
        aS.add(aS[i] + a[i])
    }
    val bS = mutableListOf<Long>()
    bS.add(0)
    for (i in 0 until m) {
        bS.add(bS[i] + b[i])
    }
    var max = 0
    for (i in 0 until aS.size) {
        val aC = k - aS[i]
        if (aC < 0) break
        val se = bS.binarySearch(aC)
        var j = if (se > 0 && se < bS.size) {
            se
        } else {
            Math.abs(lowerBound(bS, aC)) - 1
        }
        if (j == -1) j = 0
        if (aS[i] + bS[j] > k) continue
        max = Math.max(max, i + j)

    }
    return max
}

Measured memory_bytes: 84320
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n-1; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define maxn 110
#define maxk 100010

using namespace std;

int n, k, A[maxn];
bool F[maxk];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
    FOR(i, 1, n) cin >> A[i];
    memset(F, false, sizeof(F));
    FOR(i, 1, k) {
        FOR(j, 1, n)
            if (i-A[j] >= 0 && !F[i-A[j]])
                F[i] = true;
    }
    if (F[k])
        cout << "First";
    else
        cout << "Second";
	return 0;
}


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

int main() {
	string s1;
	string s2;
	cin >> s1 >> s2;
	reverse(s2.begin(), s2.end());
	if (s1 == s2) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    using P = pair<double, double>;
    vector<vector<P>> v(n, vector<P>(m+1, {0,0}));
    for (int i = 0; i < n; ++i) {
        double p, t, k;
        cin >> p >> t >> k;
        p /= 100; k = l/k;
        vector<vector<double>> dp(m+1, vector<double>(m+1, 0));
        dp[0][0] = 1.0;
        for (int j = 0; j < m; ++j) {
            for (int jj = 0; jj <= j; ++jj) {
                dp[j+1][jj] += dp[j][jj]*(1-p);
                dp[j+1][jj+1] += dp[j][jj]*p;
            }
        }
        for (int j = 0; j <= m; ++j) {
            v[i][m-j] = make_pair(-k-t*j, dp[m][j]);
        }
        for (int j = 0; j <= m; ++j) {
            if(j) v[i][j].second += v[i][j-1].second;
        }
    }
    for (int i = 0; i < n; ++i) {
        double ans = 0;
        for (int j = 0; j <= m; ++j) {
            double x = v[i][j].second;
            if(j) x -= v[i][j-1].second;
            for (int k = 0; k < n; ++k) {
                if(i == k) continue;
                auto cur = lower_bound(v[k].begin(),v[k].end(), make_pair(v[i][j].first, 0.0));
                if(cur == v[k].begin()) x *= 0;
                else {
                    cur--;
                    x *= cur->second;
                }
            }
            ans += x;
        }
        printf("%.10lf\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3348
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//	freopen("palindrome.in", "r", stdin);

	//freopen("palindrome.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
}
char grid[400][400]; int n, m;
bool vis[400][400];
ll cnt1, cnt2;
void dfs(int x, int y)
{
	if (x < 0 || y < 0 || x == n || y == m || vis[x][y])return;
	vis[x][y] = 1;
	cnt1 += (grid[x][y] == '.' ? 1LL : 0LL);
	cnt2 += (grid[x][y] == '#' ? 1LL : 0LL);
	for (int i = 0; i < 4; i++)
	{
		int u = x + dx[i], v = y + dy[i];
		if (grid[x][y] != grid[u][v])
			dfs(u, v);
	}
}
int main()
{
	Mohammed_Atef_Hassan
		cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> grid[i][j];
	ll res = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (grid[i][j] == '#')
			{
				cnt1 = 0, cnt2 = 0;
				dfs(i, j);
				res += cnt1 * cnt2;
			}
		}
	}
	cout << res << finl;
}

Measured memory_bytes: 8064
N = gets.to_i
A = 0.0
i = 0
while i < N
    eveG = gets.split(" ")
    if eveG[1] == "JPY"
        d1 = eveG[0].to_f
        A += d1
    elsif eveG[1] == "BTC"
        d2 =  eveG[0].to_f * 380000.0
        A += d2
    end
    i += 1
end
puts A

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 19;
const int MAXS = ( 1 << 16 ) + 7;
const int MOD = SC ( int, 1e9 + 7 );

int n, m;
int a[MAXN];
int dp[MAXN][MAXS];
LL frac[MAXS], rf[MAXS];
int mC[MAXS];

void init ();
void input ();
void work ();



int add ( int x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
	return x;
}

void addv ( int &x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
}

int dec ( int x, int y )
{
	x -= y;
	if ( x < 0 ) x += MOD;
	return x;
}

void decv ( int &x, int y )
{
	x -= y;
	if ( x < 0 ) x += MOD;
}

int qpow ( int a, int b )
{
	LL base = a, ans = 1;
	while ( b ){
		if ( b & 1 ) ( ans *= base ) %= MOD;
		( base *= base ) %= MOD;
		b >>= 1;
	}
	return SC ( int, ans );
}

int C ( int n, int m )
{
	return ( ( m >= 0 && m <= n ) ? ( frac[n] * rf[m] % MOD * rf[n-m] % MOD ) : 0 );
}



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
	
	frac[0] = 1;
	lp ( i, 1, MAXS ) frac[i] = frac[i-1] * i % MOD;
	rf[MAXS-1] = qpow ( frac[MAXS-1], MOD-2 );
	lpdi ( i, MAXS-2, 0 ) rf[i] = rf[i+1] * ( i + 1 ) % MOD;
	
	mC[0] = 1;
	lp ( i, 0, MAXS ) mC[i] = SC ( LL, mC[i^(i&-i)] ) * C ( i, i&-i ) % MOD;
}

void input ()
{
	// input method
	
	scanf ( "%d%d", &n, &m );
	lpi ( i, 1, m ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work
	
	int ms = 1 << n;
	
	dp[m+1][0] = 1;
	lpd ( i, m, 0 ){
		lp ( j, 0, ms ){
			lp ( k, 0, n ){
				if ( ! ( j >> k & 1 ) ){
//					cerr << i << " " << j << " " << k << " " << C ( ms - a[i] - j, ( 1 << k ) - 1 ) << endl;
					addv ( dp[i][j|(1<<k)], SC ( LL, dp[i+1][j] ) * C ( ms-a[i]-j, ( 1 << k ) - 1 ) % MOD );
				}
			}
			addv ( dp[i][j], dp[i+1][j] );
		}
	}
	
//	lpi ( i, 1, m ){ lp ( j, 0, ms ) cerr << dp[i][j] << " "; cerr << endl; }
	
	int ans = 0, cv;
	lp ( i, 0, ms ){
		cv = SC ( LL, dp[1][i] ) * mC[(ms-1)^i] % MOD;
		if ( __builtin_popcount ( i ) & 1 ) decv ( ans, cv );
		else addv ( ans, cv );
	}
	
	lp ( i, 0, n ) ans = SC ( LL, ans ) * frac[1<<i] % MOD;
	ans = SC ( LL, ans ) * ( 1 << n ) % MOD;
	
	cout << ans << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi l_,r_;

int main(){
	cin>>n;
	l_=r_=vi(n);
	ll res=0,t=0;
	multiset<P> st1,st2;
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		st1.insert({-l,r});
		st2.insert({r,l});
		l_[i]=l,r_[i]=r;
	}
	while(!st1.empty()){
		bool B=0;
		auto it=st2.begin();
		ll L=it->second,R=it->first;
		if(R<=t){
			st2.erase(it);
			st1.erase(st1.find({-L,R}));
			t=R;
			B=1;
		}
		it=st1.begin();
		L=-(it->first);
		R=it->second;
		if(st1.empty()) break;
		if(t<=L){
			st1.erase(it);
			st2.erase(st2.find({R,L}));
			res+=L-t;
			t=L;
			B=1;
		}
		if(!B) break;
	}
	if(t<0) res-=t;
	st1.clear();
	st2.clear();
	ll M=res;
	res=0;
	for(int i=0;i<n;i++){
		st1.insert({-l_[i],r_[i]});
		st2.insert({r_[i],l_[i]});
	}
	t=0;
	while(!st1.empty()){
		bool B=0;
		auto it=st1.begin();
		ll L=-(it->first),R=it->second;
		if(t<=L){
			st1.erase(it);
			st2.erase(st2.find({R,L}));
			res+=L-t;
			t=L;
			B=1;
		}
		if(st1.empty()) break;
		it=st2.begin();
		L=it->second;
		R=it->first;
		if(R<=t){
			st2.erase(it);
			st1.erase(st1.find({-L,R}));
			t=R;
			B=1;
		}
		if(!B) break;
	}
	if(t<0) res-=t;
	M=max(res,M);
	cout<<2*M<<endl;
}

Measured memory_bytes: 10368
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BNotFound {
public:
    void solve(istream& cin, ostream& cout) {
        string s;
        cin >> s;
        vector<int> h(26, 0);
        for(auto k: s) h[k-'a']++;
        int i;
        for(i=0; i<26; i++) {
            if(h[i] == 0) break;
        }
        if(i == 26) cout << "None\n";
        else cout << (char)('a' + i) << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BNotFound solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n; cin >> n;
  int d=1;
  int res=0;
  rep(i,n){
    int temp; cin >> temp;
    if(temp==d){
      d++;
    }else{
      res++;
    }
  }
  if(d==1){
    cout << -1 << endl;
    return 0;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll dp[3010][3010];
constexpr ll mod = 998244353;

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

	int n, s;
	cin >> n >> s;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 3010) {
			dp[i + 1][j] += dp[i][j] * 2;
			dp[i + 1][j] %= mod;
			if (j >= a[i]) {
				dp[i + 1][j] += dp[i][j - a[i]];
				dp[i + 1][j] %= mod;
			}
		}
	}
	cout << dp[n][s] << '\n';
}

Measured memory_bytes: 74220
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s.at(i);
    }
    vector<vector<int>> l(h, vector<int>(w, 0)), r(h, vector<int>(w, 0)), u(h, vector<int>(w, 0)), d(h, vector<int>(w, 0));
    
    for (int i = 0; i < h; i++) {
        if (s.at(i).at(0) == '.') l.at(i).at(0) = 1;
        for (int j = 1; j < w; j++) {
            if (s.at(i).at(j) == '.') l.at(i).at(j) = l.at(i).at(j - 1) + 1;
        }
    }
    for (int i = 0; i < h; i++) {
        if (s.at(i).at(w - 1) == '.') r.at(i).at(w - 1) = 1;
        for (int j = w - 2; j >= 0; j--) {
            if (s.at(i).at(j) == '.') r.at(i).at(j) = r.at(i).at(j + 1) + 1;
        }
    }
    for (int j = 0; j < w; j++) {
        if (s.at(0).at(j) == '.') u.at(0).at(j) = 1;
        for (int i = 1; i < h; i++) {
            if (s.at(i).at(j) == '.') u.at(i).at(j) = u.at(i - 1).at(j) + 1;
        }
    }
    for (int j = 0; j < w; j++) {
        if (s.at(h - 1).at(j) == '.') d.at(h - 1).at(j) = 1;
        for (int i = h - 2; i >= 0; i--) {
            if (s.at(i).at(j) == '.') d.at(i).at(j) = d.at(i + 1).at(j) + 1;
        }
    }
    
    int ans = 0;
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans, l.at(i).at(j) + r.at(i).at(j) + u.at(i).at(j) + d.at(i).at(j) - 3);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 67328
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = STR()
n = len(s)
pcnt = 0
gcnt = 0
ans = 0
for i in range(n):
    pcnt += 1
    if pcnt <= gcnt and s[i] == 'g':
        ans += 1
    elif pcnt <= gcnt and s[i] == 'p':
        continue
    elif pcnt > gcnt and s[i] == 'p':
        pcnt -= 1
        gcnt += 1
        ans -= 1
    elif pcnt > gcnt and s[i] == 'g':
        pcnt -= 1
        gcnt += 1
print(ans)

Measured memory_bytes: 61164