akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    a,b = LI()
    if not (a*b)%2:
        print("Even")
    else:
        print("Odd")
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = I()
    a = LI()
    f = 0
    for j in range(100000):
        for i in range(n):
            if a[i]%2:
                f = 1
                break
            a[i] //= 2
        if f:break
    print(j)
    return

#D
def D():
    a,b,c,x = IR(4)
    su = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:su += 1
    print(su)
    return

#E
def E():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    E()


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

int main() {
    int K;
    string S;

    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

void print(vector<int> v) {
	for_each(v.begin(), v.end(), [](int x) {
		cout << x << " ";
		});
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i];
	}

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

	vector<int> v(n);
	for (int i = 0;i < n;i++) {
		v[i] = i + 1;
	}

	int pn = 0, qn = 0;
	int count = 0;
	do {
		count++;
		if (v == p) {
			pn = count;
		}
		if (v == q) {
			qn = count;
		}
	} while (next_permutation(v.begin(), v.end()));
	
	cout << abs(pn - qn) << endl;
	return 0;
}


//BBBBBBBBBBBBBBBBBB
//int main() {
//	int n;
//	string s;
//	cin >> n >> s;
//
//	int ans = 0;
//	for (int i = 0;i < n - 2;i++) {
//		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
//	}
//
//	cout << ans << endl;
//
//	return 0;
//}

//AAAAAAAAAAAAAAAAA
//int main() {
//	int k, x;
//	cin >> k >> x;
//
//	if (k * 500 >= x) cout << "Yes" << endl;
//	else cout << "No" << endl;
//
//	return 0;
//}

Measured memory_bytes: 3636
n = int(input())
h = list(map(int, input().split()))

ans = 0

tmp = 0
for i in range(1,n):
    if h[i-1] >= h[i]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0

ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 14252
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(s);
        Console.WriteLine(solve(s[0], s[1], s[2]));
    }
    static int solve(int a, int b, int c) { //a < b < c
        int count = 0;
        if ((c-b)%2 == 0 && (c-a)%2 == 0) {
            count += (c-b)/2+(c-a)/2;
        }   
        else if (((c-b)%2 == 0 && (c-a)%2 == 1) || ((c-b)%2 == 1 && (c-a)%2 == 0)) {
            count += (c-b)/2 + (c-a)/2 + 2;
        }
        else {
            count += (c-b)/2 + (c-a)/2 + 1;
        }
        return count;
    }
}

Measured memory_bytes: 13396
import sys
from io import StringIO
import unittest


def resolve():
    a, b, c = map(int, input().split())
    k = int(input())
    ans = 0

    for i in range(k + 1):
        if a < b * (2 ** i) and b * (2 ** i) < c * (2 ** (k - i)):
            ans = 1
            break
    
    if ans == 1:
        print('Yes')
    else:
        print('No')


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7 2 5
3"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 4 2
3"""
        output = """No"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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


int main() {

    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size()) {
        if (s[i] == '+') ++ans;
        else if (s[i] == '-') --ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 12.08.2020 23:58:38
*/

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


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    for(int i=1; i<=b; i++){
        if(a*i%b==c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s]=0
    C[s] += 1
cmax = 0
for s in C:
    cmax = max(cmax,C[s])
A = []
for s in C:
    if C[s]==cmax:
        A.append(s)
A = sorted(A)
for i in range(len(A)):
    print(A[i])

Measured memory_bytes: 147888
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000
//aizu 200???

//??±???????????¢?´¢??§??????????????????
//???????????????????????¢?´¢??§????????????
int h, w;
int di[4] = {0, 1, 0, -1};
int dj[4] = {1, 0, -1, 0};


int main(){
    while(1){
    cin >> w >> h;
    if(w == 0) break;
    vector<vector<bool> > canGo(2*h + 2, vector<bool> (2*w + 2, true));
    for(int i = 1; i <= 2*h - 1; i++){
        for(int j = 1; j <= 2*w - 1; j++){
            canGo[i][j] = false;
        }
    }

    //??\???
    for(int i = 1; i <= 2*h - 1; i++){
        if(i % 2 == 1){
            for(int j = 2; j <= 2*w - 1; j += 2){
                bool input; cin >> input;
                canGo[i][j] = input;
            }
        }else{
            for(int j = 1; j <= 2*w - 1; j+= 2){
                bool input; cin >> input;
                canGo[i][j] = input;
            }
        }
    }


    //??\??????????????¢?´¢
    queue<pair<int, pair<int, int> > > wait;
    wait.push(make_pair(0, make_pair(1, 1)));
    canGo[1][1] = true;

    //??\???????????????
    int ans = 0;   //ans???0??§?????????

    while(!wait.empty()){    //?????\???????????????????????§
        //?????\????????????????´????????????????
        int nowcost = wait.front().first;
        int nowi = wait.front().second.first;
        int nowj = wait.front().second.second;

        //cout << nowcost << " " << nowi << " " << nowj << endl;
        wait.pop();

        //??´??????????????????????????????????????????????????????
        if(nowi == 2*h - 1 && nowj == 2*w - 1){
            ans = nowcost;
            break;
        }

        //??????????????¢?´¢
        for(int k = 0; k < 4; k++){
            int nexti = nowi + 2*di[k];
            int nextj = nowj + 2*dj[k];

            //??????????????????????????????
            if(canGo[nowi + di[k]][nowj + dj[k]] == 0 && canGo[nexti][nextj] == 0){
                //????????????????????\???????????????
                //??????????´¢???????????¨?????????????£???§?????????
                wait.push(make_pair(nowcost + 1, make_pair(nexti, nextj)));
                canGo[nexti][nextj] = true;
            }
        }
    }

    if(ans == 0) cout << ans << endl;
    else cout << ans + 1 << endl;
    }
    return 0;

}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string s;
int ans;
int main(){
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'A')ans++;
    }
    if(ans == 1 or ans == 2)printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        a: usize,
        x: [usize; n],
    }

    let mut dp = vec![vec![0; 2501]; 51];

    dp[0][0] = 1;
    for i in 0..n {
        for j in (1..n + 1).rev() {
            for k in (0..2501).rev() {
                if k >= x[i] {
                    dp[j][k] += dp[j - 1][k - x[i]];
                }
            }
        }
    }
    let mut ans = 0usize;
    for i in 1..n + 1 {
        ans += dp[i][a * i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
num = int(input())

array = []
odd_array = []

for i in range(num):
    tmp = int(input())
    array.append(tmp)
    if tmp % 2 != 0:
        odd_array.append(tmp)

odd_array.sort()
point = sum(array)

if point % 10 != 0:
    print(point)
elif len(odd_array) == 0:
    print(0)
else:
    for i in odd_array:
        if i % 10 != 0:
            print(point - i)
            break


Measured memory_bytes: 3060
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;
const ll ZERO = 0;

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

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

int N;
ll dp[100010][3];
ll a[100010][3];

void rec(int i, int pre)
{
  if (dp[i][pre] > 0)
  {
    return;
  }
  if (i == 0)
    return;

  ll res = 0;
  rep(j, 3)
  {
    rep(k, 3)
    {
      if (j == k)
        continue;
      rec(i - 1, j);
      chmax(dp[i][k], dp[i - 1][j] + a[i][k]);
    }
  }
  return;
}

int main()
{
  cin >> N;
  rep(i, N)
  {
    rep(j, 3)
    {
      cin >> a[i + 1][j];
    };
  }
  rep(i, N + 1)
  {
    rep(j, 3)
    {
      dp[i][j] = 0;
    };
  }

  rec(N, 0);
  ll res = 0;
  rep(i, 3) chmax(res, dp[N][i]);
  cout << res << endl;
}

Measured memory_bytes: 12800
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        if (500 * K >= X) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }        
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(void) {
	//食べたいカード二枚があったとき、二枚を食べれる。
	long long int N,ans;
	scanf("%lld", &N);
	ans = (N / 11)*2;
	N %= 11;
	if (N > 0) { ans++; }
	if (N > 6) { ans++; }
	printf("%lld", ans);
	return 0;
}

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

int main() {
  string a, b; cin >> a >> b;
  
  string s = a+b;
  int n = stoi(s);
  bool can = false;
  for (int i=2; i<=n/2; i++) {
    if (i == n/i && n%i == 0) can = true;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
	static int n,t,s,a,b,dp[3000+2][3000+2];
	scanf("%d%d%d",&n,&t,&s);
	dp[0][0]=0;
	for(int i=1;i<=n;i++)dp[i][0]=0;
	for(int i=1;i<=t;i++)dp[0][i]=0;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a,&b);
		for(int j=1;j<=t;j++){
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(j>=b&&!(j-b<s&&j>s))dp[i][j]=max(dp[i][j],dp[i-1][j-b]+a);
		}
	}
	printf("%d\n",dp[n][t]);
}

Measured memory_bytes: 36384
#include <stdio.h>
int func(int);
int n,q,g[100000];
int main (){
    int i,left=0,right=100000*10000,mid;
    scanf("%d %d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%d",&g[i]);
    }
    while(right-left>1){
        mid=(left+right)/2;
        if(func(mid)){
            right=mid;
        }
        else{
            left=mid;
        }
    }
    printf("%d\n",right);
    return 0;
}

int func(int mid){
    int sum,i,j=0;
    for(i=0;i<q;i++){
        sum=0;
        while(g[j]+sum<=mid){
            sum+=g[j];
            j++;
            if(j==n) return 1;
        }
    }
    return 0;
}





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

int main(){
 int a,b;
 cin >> a >> b ;
 cout << "a";
 if(a<b) cout <<" < ";
 if(a>b) cout <<" > ";
 if(a==b) cout <<" == ";
 cout << "b" << endl;
 return 0;

}


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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string a,b;
    cin>>a>>b;

    int n = (int)a.length();
    int m = (int)b.length();

    vector<vector<int> >dp(n+1,vector<int>(m+1,0));
    vector<vector<int> >ch(n+1,vector<int>(m+1,0));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i] == b[j]){
                dp[i+1][j+1] = 1+dp[i][j];
                ch[i+1][j+1] = 2;
            }
            else {
                if(dp[i][j+1] > dp[i+1][j]){
                    dp[i+1][j+1] = dp[i][j+1];
                    ch[i+1][j+1] = 0;
                }

                else{
                    dp[i+1][j+1] = dp[i+1][j];
                    ch[i+1][j+1] = 1;
                }
            }
        }
    }

    string ans = "";
    
    int i = n,j = m;

    while(i>0 && j>0){
        if(ch[i][j]==2){
            ans+=a[i-1];
            i--;
            j--;
        }
        else if(ch[i][j]==1){
            j--;
        }
        else i--;
    }

    reverse(ans.begin(),ans.end());

    cout<<ans;

    return 0;

}

Measured memory_bytes: 73624
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<climits>
#include<set>
#include<sstream>
#include<time.h>

#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define MEM(a) memset(a, 0, sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
#define endl "\n"
#define eps 1e-8
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2e5+10, maxn = 1e6+10;
void FAST(){ios::sync_with_stdio(false);cin.tie(nullptr); cout.tie(nullptr);}
const ll mod =  998244353;

int n, m, k, s;
int a[N];
ll dp[3100][3100];

void solve()
{
    scanf("%d%d", &n, &s);
    dp[0][0] = 1;
    for(int i = 1; i<= n; ++i) {
        scanf("%d", &a[i]);
        for(int j = 0;j <= s; ++j) {
            dp[i][j] = (dp[i-1][j]*2)%mod;
            if(j >= a[i]) dp[i][j] = (dp[i][j]+dp[i-1][j-a[i]])%mod;
        }
    }
    printf("%lld", dp[n][s]);
}

int main()
{
//    FAST();
//    init();
//    int _;scanf("%d", &_); while(_--)
//    while(scanf("%d", &n)&&n)
//    while(scanf("%d%d%d", &n, &m, &k)&&(n+m+k))
    solve();
    return 0;
}


Measured memory_bytes: 76504
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int W = scanner.nextInt();
        int H = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();
        
        if (x >= r && x <= W-r && y >= r && y <= H-r) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    REP(i,0,n){
        if (s[i] == 'p') cnt++;
    }

    if (cnt == n / 2) cout << 0 << endl;
    else cout << n / 2 - cnt << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(){
	char s[100],*pts,t[100],*ptt,n='\0';
	int len;
	
	memset(s,'\0',sizeof(s));
	memset(t,'\0',sizeof(t));
	
  
  
	scanf("%s",s);
	scanf("%s",t);
	len = strlen(s);
	
	pts = s;
	ptt = t;
	
	int i,j,fin=0;
	
	if(strcmp(pts,ptt)==0) fin=1;
	
   
  
	for(i=1;(i<=len&&fin==0);i++) {
		n=s[len-1];
		for(j=len-1;j>=1;j--) {
			s[j] = s[j-1];
		}
		s[0]=n;
		if(strcmp(pts,ptt)==0) fin=1;
	}
	
	if(fin==1) {
		printf("Yes");
	} else {
		printf("No");
	}
	
	return 0;
}

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

int main()
{
    string S;
    ll Q;
    cin >>  S >> Q;

    string head = "";
    string tail = "";
    int re = 0;

    for (ll i = 0; i < Q ; i++)
    {
        int command1;cin >> command1;
        if(command1==2){
            int f;char c;
            cin >> f >> c;
            if((re%2==0 && f==1)|(re%2==1 && f==2))head+=c;
            else tail+=c;
        }else{//re: number of reverse command
            re++;
        }
    }
    if(re%2==1){
        reverse(S.begin(),S.end());
        reverse(tail.begin(),tail.end());
        cout << tail + S + head;
    }else{
        reverse(head.begin(),head.end());
        cout << head + S + tail;
    }
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 1e5 + 3;
const int N = 27;
int v[T][N];
string s,t;

int main() {
    ios::sync_with_stdio(false);
    memset(v, INF, sizeof v);
    cin >> s >> t;
    int n = s.size();
    s = "#" + s;

    for(int i = 1; i <= n; i++) v[i-1][s[i]-'a'] = i;

    for(int i = 0; i < 27; i++)
        for(int j = n; j >= 0; j--)
            v[j][i] = min(v[j][i], v[j+1][i]);

    ll ans = 0;
    int at = 0;
    int as = 0;

    while(at < t.size()) {
        if(v[as][t[at]-'a'] == INF) {
            if(as == 0) { cout << -1 << endl; return 0; }
            as = 0;
            ans += n;
        } else {
            as = v[as][t[at]-'a'];
            at++;
        }
    }

    cout << ans + as << endl; 

    return 0;
}


Measured memory_bytes: 11088
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main() {
	cout << fixed << setprecision(10);
	LLI n, k;
	cin >> n >> k;
	vector<LLI> v(n);
	REP(i, n)cin >> v[i];
	SORT(v);

	LLI L = -2e18, R = 2e18;

	while (1 < R - L) {
		LLI M = (L + R) / 2;
		LLI cnt = 0;


		REP(i, n) {
			if (0 < v[i]) {
				LLI l = i, r = n;

				while (1 < r - l) {
					LLI m = (l + r) / 2;

					if (v[i] * v[m] < M) {
						l = m;
					}
					else {
						r = m;
					}
				}
				cnt += l - i;
			}
			else {
				LLI l = i, r = n;

				while (1 < r - l) {
					LLI m = (l + r) / 2;

					if (v[i] * v[m] < M) {
						r = m;
					}
					else {
						l = m;
					}
				}
				cnt += n - r;
			}
		}

		if (cnt < k) {
			L = M;
		}
		else {
			R = M;
		}
	}

	cout << L;

	return 0;
}

/*

6 10 14
15 21
35

4 1
2 3 5 7



*/

Measured memory_bytes: 1792
import sys
from heapq import heappop, heappush, heapify
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    que = [-a for a in A]

    heapify(que)

    for _ in range(M):
        maxA = -heappop(que)
        heappush(que, -(maxA // 2))

    ans = -sum(que)
    print(ans)

sol()

Measured memory_bytes: 69100
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

int mod = 1000000007;

signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int h, w;
	cin >> h >> w;
	int a[h + 1][w + 1];
	char d;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			cin >> d;
			if(d == '.') a[i][j] = 0;
			else a[i][j] = 1;
		}
	}

	int count[h + 1][w + 1];

	for(int i = 0; i <= h; i++) {
		count[i][0] = 0;
	}

	for(int i = 0; i <= w; i++) {
		count[0][i] = 0;
	}

	count[1][1] = 1;

	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			if(i == 1 and j == 1)continue;

			if(a[i][j] == 1) {
				count[i][j] = 0;
			} else {
				count[i][j] = (count[i - 1][j] + count[i][j - 1])%mod;
			}
		}
	}




	cout << count[h][w] << endl;


	return 0;
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

int main(){
    ll N; cin>>N;
    map<ll,ll> x;
    ll ans=0;
    rep(i,N){
        ll y; cin>>y;
        if(x.count(i-y)) ans+=x[i-y];
        if(x.count(i+y)) x[i+y]++;
        else x.insert(mp(i+y,1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 16100
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int N;

vector<LL> A;

int main() {
	cin >> N;
	A.clear();
	LL x;
	FOR (i, N) {
		cin >> x;
		A.pb(x);
 	}
 	LL ret = 0LL;
 	ffor (len, 1, N) {
 		sort(all(A));
 		reverse(all(A));
 		LL k = (A[len - 1] - A[len]) / (N + 1LL);
 		FOR (i, len) {
 			A[i] -= k * N;
 			A[i] += (len - 1LL) * k;
		}
		if (A[0] <= N && k) {
			FOR (i, len) {
				A[i] += N;
				A[i] -= (len - 1LL);
			}
			k--;
		}
		if (A[0] <= 2 * N && k) {
			FOR (i, len) {
				A[i] += N;
				A[i] -= (len - 1LL);
			}
			k--;
		}

		ffor (i, len, N)
			A[i] += len * k;
		ret += len * k;
		sort(all(A));
		reverse(all(A));
		while (A[0] >= N && A[0] - A[len] >= N) {
			A[0] -= N;
			ffor (i, 1, N)
				A[i]++;
			ret++;
			sort(all(A));
			reverse(all(A));
		}
	}
	LL k = max(0LL, A[0] - 2LL * N);
	FOR (i, N)
		A[i] -= k;
	ret += N * k;
	while (A[0] >= N) {
		A[0] -= N;
		ffor (i, 1, N)
			A[i]++;
		ret++;
		sort(all(A));
		reverse(all(A));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int len = 0;
	char prev = ' ';
	int n;
	string s;
	cin >> n;
	cin >> s;

	for (char c: s) {
		if (prev != c) {
			len++;
			prev = c;
		}
	}
	cout << len << endl;

	return 0;
}

Measured memory_bytes: 512
input_arr = []
length_arr = []
ingredient_sum = 0

while str = gets
	break if str == "\n"
	input_arr << str.chomp.split(" ").map!{|s| s.to_i}
end

bar_num = input_arr.shift
bar_num = bar_num * 2
length_arr = input_arr.shift

length_arr.sort!

(length_arr.length/2).times do |num|
	ingredient_sum += length_arr.shift
	length_arr.shift
end

p ingredient_sum


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;


int main(){
	int n, k;
	double x, ans = 0;
	vector<double> p, sum;
	p.push_back(0);
	sum.push_back(0);

	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> x;
		p.push_back((x+1)/2);
		sum.push_back(sum[i-1]+p[i]);
	}
	for (int i = k; i <= n; i++){
		ans = max(sum[i] - sum[i-k], ans);
	}
	cout << setprecision(10) << ans << endl;
	return 0;
}

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

void solve(int n, int w){
	int a[15] = {};
	for(int i=0; i<n; ++i){
		int v;
		cin >> v;
		++a[v/w];
	}
	int ma = 0;
	for(int i=0; i<15; ++i)
		if(a[i] > 0)
			ma = i;
//	cout << ma << "\n";
	int hst = 0;
	for(int i=0; i<15; ++i)
		hst = max(hst, a[i]);
//	cout << hst << "\n";
	double ans = 0.0;
	for(int i=0; i<15; ++i)
		ans += (1-(double)i/ma)*(double)a[i]/hst;
	printf("%.6lf\n", ans+0.01);
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, w;
		cin >> n >> w;
		if(n == 0 && w == 0) return 0;
		solve(n, w);
	}
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> A, B;
  llong ans = 0;

  cin >> N;
  A.resize(N + 1);
  B.resize(N + 1);
  B[0] = 1;
  for (int i = 0; i <= N; ++i) {
    if (i > 0) {
      B[i] = min(B[i - 1] * 2, mod * mod);
    }
    cin >> A[i];
    B[i] -= A[i];
    if (B[i] <= 0 && i < N) {
      ans = -1;
      break;
    }
  }

  if (ans == -1) {
    cout << ans << endl;
    return 0;
  }

  llong child = 0;
  ans = 0;
  for (int i = N; i >= 0; --i) {
    if (child > B[i] * 2) {
      ans = -1;
      break;
    }
    child = min(child, B[i]) + A[i];
    ans += child;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4844
fn main() {
 let v:Vec<i64>={
  let mut b=String::new();
  let s=std::io::stdin();
  s.read_line(&mut b).unwrap();
  b.split_whitespace().flat_map(str::parse).collect()
 };
 let (a,b)=(v[0],v[1]);
 println!("{} {} {:.6}",a/b,a%b,a as f64/b as f64);
}


Measured memory_bytes: 5036
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

const int mod = 2019;
int main() {
    long l,r;
    cin >> l >> r;
    if ( r - l >= mod ) {
        puts("0");
        return 0;   
    }
    r%=mod;
    l%=mod;

    int mmin = 2018;
    for(int i=l; i<=r; i++) {
        for (int j=i+1; j<=r; j++) {
            mmin = min(mmin, (i*j)%mod);
        }
    }
    cout << mmin << endl;
}

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

using namespace std;

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

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) ((n%m + m) % m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 3e5 + 5;
int w[N], e[N];
int n;
vector<ll> vec;

ll check(ll b)
{
	ll res = 0;
	rep(i, 0, n)
		res += abs(vec[i] - (b + i + 1));
	return res;
}

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

	cin >> n;
	vec.resize(n);
	rep(i, 0, n)
		cin >> vec[i];

	ll st = -2e9, en = 2e9, mid, ret = INT_MIN;

	while (st <= en)
	{
		mid = (st + en) / 2;

		if (check(mid) > check(mid + 1))
			st = mid + 1;
		else
			en = mid - 1, ret = mid;
	}

	cout << check(ret) << endl;

	return 0;
}



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

int main(void) {
  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A.at(i);
  vector<ll> sorted(A); sort(sorted.begin(), sorted.end());
  map<ll, int> index;
  for (ll i = 0; i < N; i++) index[sorted.at(i)] = i%2;

  vector<ll> l;
  for (ll i = 0; i < N; i++) {
    if (i%2 != index[A.at(i)]) {
      if (i%2) l.push_back(i);
    }
  }

  cout << l.size() << endl;

  return 0;
}


Measured memory_bytes: 8704
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  int N,count=0;
  cin >> N;
  int L[N],tri[3];

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

  sort(L,L+N);

  
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
	tri[0] = L[i];
	tri[1] = L[j];
	tri[2] = L[k];
	if(tri[2] < tri[0]+tri[1]){
	  count++;
	}
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
long long a[404], b[404], d[404][404];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i];
    for (int i = 1; i < n; i++) {
        for (int j = 1; j + i <= n; j++) {
            d[j][j + i] = 1e18;
            for (int k = j; k < j + i; k++) {
                d[j][j + i] = min(d[j][j + i], d[j][k] + d[k + 1][j + i]);
            }
            d[j][j + i] += b[j + i] - b[j - 1];
        }
    }
    cout << d[1][n] << '\n';
}

/*
 1 2 3 4 5 6
 1 23 4 5 6
 1 23 4 56
 1 234 56
 123456 d[1][3]+d[4][6]+a[1]+...+a[6]
 123456
 */


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define M 3009
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}






void test_case() {

   ll n;
   cin>>n;


   vecl arr(n);
   rep(i,n) {
       cin>>arr[i];
   }

   ll dp[n][n];

   memset(dp,0,sizeof(dp));

   ll sum =0;

   for(auto it : arr) {
       sum+= it;
   }

   for(int i=0; i+1<n; i++) {
       dp[i][i] = arr[i];
       dp[i][i+1] = max(arr[i], arr[i+1]);
   }

   dp[n-1][n-1] = arr[n-1];

   for(ll d = 0; d<n; d++) {
       for(ll i=0, j=d; j<n; i++,j++) {

           ll x = ((i+2 <= j)) ? dp[i+2][j] : 0;
           ll y = ((i+1 <= j-1)) ? dp[i+1][j-1] : 0;
           ll z = ((i <= j-2)) ? dp[i][j-2] : 0;

           dp[i][j] = max(arr[i] + min(x,y), arr[j] + min(y,z));
       }
   }

    ll ans = dp[0][n-1] - sum;
    ans+= dp[0][n-1];
   cout<<ans<<endl;

}


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

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


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 73912
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define mp make_pair
using namespace std;

using ll = long long;
using ii = pair<int, int>;
const int INF = (int)10e9;
int N, W;
ll dp[105][100005];

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i = 0; i < N; i++) {
        cin>>w[i]>>v[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if(i == 0) { if(j >= w[i]) dp[i][j] = v[i];}
            else if(j - w[i] >= 0) dp[i][j] = max(v[i] + dp[i-1][j-w[i]], dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
    }

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

    return 0;
}


Measured memory_bytes: 81660
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll N;
	cin >> N;

	ll F[101][11];
	ll P[101][11];

	repn(i, N)repn(j, 10) cin >> F[i][j];

	repn(i, N)rep(j, 11) cin >> P[i][j];

	ll ans = -INF;

	repn(i, 1023) {
		bool eigyo[11];

		ll x = i;

		repn(j, 10) {
			eigyo[j] = x % 2;
			x /= 2;
		}

		ll c[101] = {};

		repn(j, N) {
			repn(k, 10) { if (F[j][k] == 1 && eigyo[k] == 1) { c[j]++; } }
		}

		ll v = 0;

		repn(j, N) { v += P[j][c[j]]; }

		ans = max(v, ans);

		//cout << i <<" "<< v << endl;

	}

	cout << ans;
	

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int X, N;
	cin >> X >> N;
	vector<int> inputs;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		inputs.push_back(tmp);
	}
	sort(inputs.begin(), inputs.end());

	set<int> array;
	for (int i = -100; i <= 101; i++) {
		bool found = binary_search(inputs.begin(), inputs.end(), i);
		if (!found) array.insert(i-X);
	}

	for (int i = 0; i <= 100; i++) {
		if (array.count(-i) != 0) {
			cout << X - i << endl;
			return 0;
		}
		else if(array.count(i) != 0) {
			cout << X + i << endl;
			return 0;
		}
	}

	return 0;

}


Measured memory_bytes: 3636
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define MOD 10000000009

int main() {
    ll i,j,x,a,b;
    cin>>x>>a>>b;
    x-=a;
    cout<<x%b;
return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  std::string a, b;
  std::cin >> a >> b;

  if (a == b) {
    std::cout << "EQUAL" << std::endl;
  } else if (a.size() < b.size()) {
    std::cout << "LESS" << std::endl;
  } else if (a.size() > b.size()) {
    std::cout << "GREATER" << std::endl;
  } else {
    for (int i = 0; i < a.size(); i++) {
      if (a[i] < b[i]) {
        std::cout << "LESS" << std::endl;
        return 0;
      } else if (a[i] > b[i]) {
        std::cout << "GREATER" << std::endl;
        return 0;
      }
    }
  }
  return 0;
}

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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 

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

    ll k;
    cin >> k;

    ll r=0;
    //10^1000000までにはあるだろう
    rep(i, 10000000)
    {
        r=(r%k)*10+7;
        if(r%k==0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;



    return 0;

}


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

int main(){
    int H, W;
    int i, j;
    while(1){
        cin >> H >> W;
        if(H + W == 0) break;
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
				if((i + j) % 2){ cout << "."; }else{ cout << "#"; }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N,sum=0;
  cin >> N;
  int l[N+10],r[N+10];
  for(int i=0; i<N; i++){
    cin >> l[i] >> r[i];
    sum += r[i]-l[i]+1;
  }cout << sum << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

string s;
ll dp[3010][3010];
int tar[3010];

const ll mod=1000000007LL;



int main(void){
	int n,m;
	cin >> n >> m >> s;
	rep(i,n) tar[i]=i+1;
	tar[n]=n;
	
	rep(i,m){
		int l,r;
		cin >> l >> r;
		l--;
		chmax(tar[l],r);
	}

	rep(i,1,n+1) chmax(tar[i],tar[i-1]);
	
	//rep(i,n+1) cout << tar[i] << endl;

	int one=0;
	rep(i,tar[0]) one+=(s[i]=='1');
	dp[0][one]=1LL;
	
	rep(i,n){
		int add=0;
		rep(j,tar[i],tar[i+1]) add+=(s[j]=='1');
		//cout << "Len : " << tar[i]-i << endl;
		rep(c,tar[i]-i+1){
			if(c>0){
				dp[i+1][c-1+add]+=dp[i][c];
				dp[i+1][c-1+add]%=mod;
			}
			if(c<tar[i]-i){
				dp[i+1][c+add]+=dp[i][c];
				dp[i+1][c+add]%=mod;
			}
		}
	}

	//rep(i,2) cout << dp[n-1][i] << endl;
	cout << dp[n][0] << endl;

	return 0;
}

Measured memory_bytes: 12800
from numba import njit
from sys import stdin


@njit(cache=True)
def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


@njit(cache=True)
def fact(x):
    if x == 1:
        return x
    return x * fact(x - 1)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 108504
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  string S;
  while (cin >> S) {
    int N = S.size();
    S += 'R';
    vector<int> res(N, 0);
    for (int i = 1, p = 0, m = -1; i <= N; i++) {
      if (S[i - 1] == 'R' && S[i] == 'L') {
        m = i;
        continue;
      }
      if (S[i - 1] == 'L' && S[i] == 'R') {
        int R = m - p;
        int L = i - m;
        res[m - 1] += (R - R / 2) + L / 2;
        res[m] += R / 2 + (L - L / 2);
        p = i;
      }
    }
    for (int x : res) cout << x << " ";
    cout << endl;
  }
  return 0;
}


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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<8>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<int>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define M 1e9

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

int main()
{
    llint s;
    ci >> s;

    co << "0 0 ";

    llint x, y, xx, yy;
    
    llint l = 1, r = M, mid = M / 2;

    while(mid <= M) {
	if(s / mid + 1 > M) {
	    if(mid == M) break;
	    l = mid + 1;
	    mid = l + (r - l) / 2;
	} else {
	    break;
	}
    }
    
    llint tmp = s / mid;
    if(s % mid != 0) tmp++;
    x = mid;
    yy = tmp;

    xx = x * yy - s;
    y = 1;

    co << x << ' ' << y << ' ' << xx << ' ' << yy << en;

    //co << x * yy - xx * y << en;
    
    return 0;
}

// 0.5 * ((x1−x3)(y2−y3)−(y1−y3)(x2−x3))


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

int main() {
    int N;
    cin >> N;
    int res = 0;
    int ans = 1;
    for (int i = 1; i <= N; ++i) {
        int x = i,count=0;
        while(x/2>0){
            x /= 2;
            ++count;
        }
        if (count >res) {
            res = count;
            ans = i;
        };
    }
    cout << ans << endl;
}

Measured memory_bytes: 256