akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}


vector<string> res;
int k;
string s;

void go() {
    string t = s;
    sort(t.begin(),t.end());
    char c = t[0];
    char d = t[1];
    char e = t[2];
    char f = t[3];
    char g = t[4];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == c || s[i] == d || s[i] == e || s[i] == f || s[i] == g) {
            int cnt = 0;
            for (int j = i; j < s.size(); j++) {
                if (cnt++ > 200) break;
                string ss = s.substr(i,j - i + 1);
                res.push_back(ss);
            }
        }
    }
    sort(res.begin(),res.end());
    int y = unique(res.begin(), res.end()) - res.begin();
    cout<<res[k - 1]<<endl;
}

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    init();
     cin>>s;
     cin>>k;
    if (s.size() > 50) {
        go();return 0;
    }
    for (int i = 0; i < s.size(); i++) {
        for (int j = i; j < s.size(); j++) {
            string t = s.substr(i,j - i + 1);
            res.push_back(t);
        }
    }
    sort(res.begin(),res.end());
    //for (int i = 0; i < res.size(); i++) cout<<res[i]<<' ';cout<<endl;
    int t = unique(res.begin(), res.end()) - res.begin();
    cout<<res[k - 1]<<endl;

    return 0;
}


Measured memory_bytes: 143976
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int BingoCard[3][3], N , Number[10];
    bool CheckCard[3][3] = {0}, Bingo = 0;
    long ans = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
        cin >> BingoCard[i][j];
        }
    }
    cin >> N;
    for(int k = 0; k < N; k++){
        cin >> Number[k];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                 if(BingoCard[i][j] == Number[k]){
                     CheckCard[i][j] = 1;
    		    }
    		}
    	}
    }
    
    for(int i = 0; i < 3; i++){
        if(CheckCard[i][0] && CheckCard[i][1] && CheckCard[i][2]){
            Bingo = 1;
        }
        else if(CheckCard[0][i] && CheckCard[1][i] && CheckCard[2][i]){
            Bingo = 1;
        }
    }
    if(CheckCard[0][0] && CheckCard[1][1] && CheckCard[2][2]){
        Bingo = 1;
    }
    else if(CheckCard[0][2] && CheckCard[1][1] && CheckCard[2][0]){
        Bingo = 1;
    }
    if(Bingo){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int sum[1001];

int main() {
    sum[0] = 0;
    for (int i = 1; i <= 1000; ++i) {
        sum[i] = sum[i - 1] + i;
    }

    while (1) {
        int n;
        cin >> n;

        if (n == 0) break;

        int ans = 0;
        for (int i = 1; i <= 1000; ++i) {
            for (int j = i + 1; j < 1000; ++j) {
                if (sum[j] - sum[i - 1] == n) ans++;
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b&&b < c)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int m;
int a[100], b[100];
int g, n;

int table[10010];

void print_table(){
	REP(i, 100){
		cout << table[i] << endl;
	}
}

void solve(){
	REP(i, m){
		for (int j = 10010 - 1; j >= 0; j--){
			if (table[j]){
				FOR(k, 1, b[i] + 1){
					table[j + a[i] * k] += table[j];
				}
			}
		}
	}
}


int main(){
	while (cin >> m&&m){
		fill(table, table + 10010, 0);
		table[0] = 1;
		REP(i, m){
			cin >> a[i] >> b[i];
		}
		solve();
		cin >> g;
		REP(i, g){
			cin >> n;
			cout << table[n] << endl;
		}

	}
}

Measured memory_bytes: 1200
import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    string s = readln.chomp;
    string odd, even;
    foreach (i, x; s) {
        if (i % 2) even ~= x;
        else odd ~= x;
    }
    writeln(odd.count('L') || even.count('R') ? "No" : "Yes");
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint a) const {mint res(*this); return res+=a;}
    mint operator-(const mint a) const {mint res(*this); return res-=a;}
    mint operator*(const mint a) const {mint res(*this); return res*=a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int f(string s) {
	map<char, int> m;
	m['A'] = 0;
	m['C'] = 1;
	m['G'] = 2;
	m['T'] = 3;
	int ret = 0;
	rep(i, s.size()) ret += pow(4, s.size() - i - 1) * m[s[i]];
	return ret;
}

int main() {
	int n;
	cin >> n;
	mint dp[101][64];
	rep(i, 64) dp[3][i] = 1;
	dp[3][f("AGC")] = 0;
	dp[3][f("ACG")] = 0;
	dp[3][f("GAC")] = 0;
	for(int i = 4; i <= n; i++) {
		rep(j, 64) dp[i][j] = 0;
		rep(j, 64) {	// old 3 chars
			rep(k, 4) {	// new char to be added
				if((j >> 2) == f("AG") && k == f("C")) {
					continue;	// skip for AG?C
				}
				if((j >> 4) == f("A") && (j % 4) == f("G") && k == f("C")) {
					continue;	// skip for A?GC
				}
				dp[i][(j << 2) % 64 + k] += dp[i - 1][j];
			}
		}
		dp[i][f("AGC")] = 0;
		dp[i][f("ACG")] = 0;
		dp[i][f("GAC")] = 0;
	}
	mint ans = 0;
	rep(i, 64) ans += dp[n][i];
	cout << ans.x << endl;
}


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

int main(){
  string str;
  cin >> str;
  string ans_1=(""),ans_2=("");
  int ans1 = 0, ans2=0;
  
  for(int i = 0; i< str.size();i++){
    if(i % 2 == 0){
      ans_1.push_back('0');
      ans_2.push_back('1');
    }else{
      ans_1.push_back('1');
      ans_2.push_back('0');      
    }
  }

  for(int i = 0; i< str.size();i++){
    if(str[i] != ans_1[i])ans1++;
    if(str[i] != ans_2[i])ans2++;
  }

  if(ans1 < ans2)cout << ans1 << endl;
  else cout << ans2 << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,a;
    set<int>st;
    cin>>n;
    while(cin>>a)
        st.insert(a);
    cout<<(st.size()==n?"YES":"NO")<<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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 main() {
  ll n;
  cin >> n;
  ll a, b;
  cin >> a >> b;

  ll iter = n / (a + b);
  ll ans = 0;
  ans += iter * a;

  ll amari = n % (a + b);

  if(amari >= a) {
    ans += a;
  } else {
    ans += amari;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

int main(){
    int N,K; cin >> N >> K;
    vector<ll> h(N);
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    ll mn = MM;
    for (int i = K-1; i < N; i++){
        ll tmp = h[i]-h[i-K+1];
        mn = min(mn,tmp);
    }
    cout << mn << endl;
}

Measured memory_bytes: 1024
num=input()
num_list=list(num)

for i in range(3):
    if num_list[i]=="1":
        num_list[i]="9"
    elif num_list[i]=="9":
        num_list[i]="1"
    else:
        pass
    
    




num_changed="".join(num_list)

print(int(num_changed))

Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>

using namespace std;

bool isWin( string s, char c ) {
	//縦
	bool b = false;
	for( int i = 0; i < 3; i++ )
		b |= ( s[i] == c && s[i + 3] == c && s[i + 6] == c);
	if( b ) return true;
	//横
	b = false;
	for( int i = 0; i < 3; i++ )
		b |= ( s[i*3] == c && s[i*3 + 1] == c && s[i*3 + 2] == c );
	if( b ) return true;
	//斜め
	if( s[0] == c && s[4] == c && s[8] == c ) return true;
	if( s[2] == c && s[4] == c && s[6] == c ) return true;
	return false;

}

int main(void){
	
	while( true ) {
		string str;
		if( cin.eof() ) break;
		getline( cin, str );
		if( str == "\n" || str == "" ) break;
		//oの勝利判定
		if( isWin( str, 'o' ) ) cout << "o" << endl;
		else if( isWin( str, 'x' ) ) cout << "x" << endl;
		else cout << "d" << endl;
		
	}


    return 0;
}

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

signed main(void)
{
	int n, x, t, cnt;
	cin >> n >> x >> t;
	cnt = n / x;
	if (n % x != 0)
		cnt++;
	cout << cnt * t << endl;
	return 0;
}


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

int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int  A,B,X;
	scanf("%d%d%d",&X,&A,&B);
	int c = (X-A)/B;
	
	printf("%d\n",X - A - B*c);
	
	
	
	return 0;
}

Measured memory_bytes: 128
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;}
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    ll n, k;
    cin >> n >> k;
    n %= k;
    ll ans = n;
    fr(i, 42) {
        n = abs(n-k);
        ans = min(ans, n);
    }
    cout << ans << endl;
}


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

int main(void){
  
  int A, B;
  cin >> A >> B;
  if((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
    
 return 0;
  
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i,m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    int ans = -1;
    int st = pow(10,n-1);
    if(n == 1) st = 0;
    for (int i = st;i < pow(10,n);i++){
        string num = to_string(i);
        bool f = true;
        rep(j,m){
            if(num[s[j]] != c[j]) f=false;
        }
        if(f) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
#include <stdio.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n);++i)printf(i==(n)-1?"%d\n":"%d ",(a)[i])

int bubble_sort(int *a, const int N) {
    bool flag = true;
    int head = 0;
    int cnt = 0;
    while(flag) {
        flag = false;
        for(int i = N - 1; i > head; --i) {
            if(a[i] < a[i - 1]) {
                int tmp = a[i];
                a[i] = a[i - 1];
                a[i - 1] = tmp;
                cnt++;
                flag = true;
            }
        }
        head++;
    }
    return cnt;
}

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; ++i) scanf("%d", a + i);
    int cnt = bubble_sort(a, n);
    arr_print_d0dn(a, n);
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2708
import sys
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

d=min(y)-max(x)
warFlag = False
if d<=0:
    print("War")
    sys.exit()
else:
    for i in range(1, Y - X + 1):
        Z=X+i
        if (max(x)>=Z or min(y)<Z):
          warFlag = True
        else: #max(x) < Z, max(y) >= Z
          warFlag = False
          break
if warFlag:
  print("War")
else:
  print("No War")

Measured memory_bytes: 9216
#[allow(unused_macros)]
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 ) * } };
}
#[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 ) * } };
}
#[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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        ab: [(usize1, usize1); n-1],
        cc: [u64; n]
    }

    let mut c = cc;
    c.sort();
    let mut g = vec![vec![];n];
    for i in 0..n-1 {
        let (a, b) = ab[i];
        g[a].push(b);
        g[b].push(a);
    }

    let mut m = vec![0u64;n];
    let sum = c.iter().take(n-1).fold(0, |acc, &x| acc + x);
    dfs(&g, &mut m, &mut c, None, 0);
    println!("{}", sum);
    println!("{}", join(&m, " "));
}

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

fn dfs(g: &[Vec<usize>], m: &mut Vec<u64>, c: &mut Vec<u64>, pre: Option<usize>, cur: usize) {
    m[cur] = c.pop().unwrap();
    for &v in &g[cur] {
        if pre.map(|src| src == cur).unwrap_or(false) || m[v] != 0 {
            continue;
        }
        dfs(g,m,c,Some(cur),v);
    }
}


Measured memory_bytes: 5244
K, A, B = map(int, input().split())
answer = 1
if B - A <= 2:
    #ずっと＋１する場合
    answer += K
else:
    time = A - 1 #A枚最初に手に入る
    if time + 2 > K or B - A < 2:
        answer += K
    else:
        answer += time
        q, mod = divmod(K-time, 2)
        answer += q * (B-A)
        answer += mod
print(answer)

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, a;cin >> n >> a;
    cout << n*n-a << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll N;
vll a;
vvll dp;

ll search(ll begin, ll end){
  if(dp[begin][end]<INFLL) return dp[begin][end];
  if(begin==end) return dp[begin][end] = a[begin];
  ll ans = a[begin]-search(begin+1, end);
  chmax(ans, a[end]-search(begin, end-1));
  return dp[begin][end] = ans;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(N);
  a.resize(N);
  dp.resize(N, vll(N, INFLL));
  REP(i,N) IN(a[i]);

  OUT(search(0, N-1));

  return 0;
}

Measured memory_bytes: 70912
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

using P = pair<int, int>;
P task[100000];
int N, M;
priority_queue<int> q;

signed main()
{
	cin >> N >> M;
	REP(i, N)
	{
		int a, b;
		cin >> a >> b;
		task[i] = P(a, b);
	}
	ARY_SORT(task, N);

	int ans = 0;
	int cur = 0;
	for (int i = 1; i <= M; i++)
	{
		for (int j = cur; j < N; j++)
		{
			if (task[j].first <= i)
			{
				q.push(task[j].second);
				cur = j + 1;
			}
			else
			{
				break;
			}
		}
		if (q.size() > 0)
		{
			ans += q.top();
			q.pop();
		}
	}

	cout << ans << endl;
}











Measured memory_bytes: 2936
// 未解決

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

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

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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 in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

const int MAX = 1000010;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  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;
  }
}

// 二項係数計算
long long COM(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;
}

//**********

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

  int x, y;
  cin >> x >> y;

  int ans = 0;
  if (x * 2 < y || x > y * 2 || (x + y) % 3 != 0) {
    cout << ans << endl;
    return 0;
  }

  int n = (x + y) / 3;  // 手かず
  int a = x - n;
  // debug(n);
  // debug(a);

  // nCaが答え。
  COMinit();
  ans = COM(n, a);
  cout << ans << endl;

  return 0;
};


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

bool isPalindrome(string s)
{
	int n=s.length();
	for(int i=0;i<=n/2;i++)
		if(s[i]!=s[n-1-i])
			return false;
	
	return true;
}

int main() {
	
	string a;
	cin>>a;
	int n=a.length();
	
	string b="", c="";
	for(int i=0;i<(n-1)/2;i++)
	b+=a[i];
	for(int i=(n+3)/2-1;i<n;i++)
	c+=a[i];
	
	if(isPalindrome(a) && isPalindrome(b) && isPalindrome(c))
	cout<<"Yes";
	else
	cout<<"No";
	cout<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list("abcdefghijklmnopqrstuvwxyz")
a = 1
while N > 26**a:
    N = N - 26**a
    a += 1
 
pre = []
for i in reversed(range(1,a)):
    r = (N-1) // 26**i
    pre.append(r)
    N = int(N%(26**i))
 
ans = ''
for i in pre:
    ans += L[i]
print(ans+L[N-1])

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    rep(i, n) cin >> x[i] >> u[i];

    double res = 0;
    rep(i, n)
    {
        if (u[i] == "JPY")
        {
            res += x[i];
        }
        else
        {
            res += x[i] * 380000.0;
        }
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3760
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	int i, j, h, w, g;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}

Measured memory_bytes: 3044
#include <stdio.h>
#include <math.h>

int main(){
	int i, j, N[10], temp;
	
	for(i=0; i<10; i++){
		scanf("%d", &N[i]);
	}
	for(i=0; i<10; i++){
    for(j=9; j>i; j--){
      if(N[j] < N[j-1]){
        temp = N[j];
        N[j] = N[j-1];
        N[j-1] = temp;
      }
    }
  }
   printf("%d\n%d\n%d\n", N[9], N[8], N[7]);
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)







/* comb, perm */
const ll table_size = 300005;
ll fact[table_size], finv[table_size], inv[table_size];

// 前処理
void make_table(ll mod) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < table_size; i++){
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll comb(ll n, ll r, ll mod){
    if(n < r || n < 0 || r < 0) return 0;
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}


int main(){
    make_table(MOD);
    
    ll n, k;
    cin >> n >> k;
    for(ll i = 1; i <= k; i++){
        cout << comb((n - (i - 1) - k) + (i + 1) - 1, (n - (i - 1) - k), MOD) * comb(k - 1, k - i, MOD) % MOD << endl;
    }
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define NMAX 102
#define MMAX 1005
#define INF (int)1e9

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

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

int N,M,a[MMAX],b[MMAX],c[MMAX];
vector<P > cone[NMAX];
pair <int ,set<int > > d[NMAX][NMAX];
set<int > st;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	for (int k = 0; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				if(max(d[i][k].first,d[k][j].first) == INF){
					continue;
				}
				if(d[i][j].first > d[i][k].first+d[k][j].first){
					set<int > dest1;
					set_union(d[i][k].second.begin(), d[i][k].second.end(),
						d[k][j].second.begin(), d[k][j].second.end(),
						inserter(dest1,dest1.begin()));
					d[i][j].second = dest1;
				}
				d[i][j].first = min(d[i][j].first,d[i][k].first+d[k][j].first);
			}
		}
	}
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			set<int > dest1;
			set_union(d[i][j].second.begin(), d[i][j].second.end(),
				st.begin(),st.end(),
				inserter(dest1,dest1.begin()));
			st = dest1;
			// cout << i << " " << j << " : ";
			// cout << "cost:" << d[i][j].first << " : ";
			// for(auto&& k : d[i][j].second) {
			// 	cout << k << " ";
			// }
			// cout << endl;
		}
	}
}

void debug(){

}

void answer(){
	cout << M-st.size() << "\n";
}

int main(){
	cin >> N >> M;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			d[i][j].first = INF;
		}
	}
	for (int i = 0; i < M; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
		d[a[i]-1][b[i]-1].first = c[i];
		d[b[i]-1][a[i]-1].first = c[i];
		d[a[i]-1][b[i]-1].second.insert(i);
		d[b[i]-1][a[i]-1].second.insert(i);
	}
	solve();
	answer();
	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<int> v(n, 0);
  set<int> flg;
  for(int i=0; i<m; i++){
    int s, c; cin >> s >> c;
    if(s==1 && c==0 && n!=1) {cout << "-1"; return 0;}
    if(flg.count(s)==1 && v[s-1]!=c) {cout << "-1"; return 0;}
    v[s-1]=c;
    flg.insert(s);
  }
  if(v[0]==0 && n!=1) v[0]=1;
  for(int i=0; i<n; i++){
    cout << v[i];
  }
  return 0;
}

Measured memory_bytes: 256
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True) :
   del phU[-2]
   try :
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 ph = phU + phL[1:-1]
 return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1])

Measured memory_bytes: 33228
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long int ll;

int main()
{
    for(;;){
		int n;
		cin >> n;
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			int a,b,c;
			cin >> a >> b >> c;
			if(a==100||b==100||c==100)
				printf("A\n");
			else if(b+a>=180)
				printf("A\n");
			else if(a+b+c>=240)
				printf("A\n");
			else if(a+b+c>=210)
				printf("B\n");
			else if(a+b+c>=150&&(a>=80||b>=80))
				printf("B\n");
			else printf("C\n");
		}
	}
}

Measured memory_bytes: 1116
#include <stdio.h>
int main(void){
    int x,y,a,b,r,tmp;
    double c;
    while( scanf("%d %d" , &x , &y ) != EOF ){
        a = x;
        b = y;
        if( a < b ){
            tmp = b;
            b = a;
            a = tmp;
        }

        r = a % b;
        while( r != 0 ){
            a = b;
            b = r;
            r = a % b;
        }
        
        c = (double)x / b * y;
        
        printf("%d %.0f\n" , b , c );

    }
}


Measured memory_bytes: 2068
N, M = map(int,input().split())
L = [0 for i in range(M)]
R = [0 for i in range(M)]
for i in range(M):
        L[i], R[i] = map(int, input().split())
if min(R) >= max(L):
        print(min(R) - max(L) + 1)
else:
        print(0)

Measured memory_bytes: 11536
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}

	}
}


Measured memory_bytes: 22732
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  
  vector<int> v;
  
  for (int i = 0; i < k; i++){
    v.push_back(a+i);
    if (a+i >= b-i) break;
    v.push_back(b-i);
  }
  
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  
  for(auto c:v) cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    string a, b, tmp;
    map<string, int> m;
    cin >> a >> b;
    cin >> m[a] >> m[b];
    cin >> tmp;
    m[tmp] --;
    cout << m[a] << " " << m[b] << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String sValue = sc.nextLine();
    String[] sSplitVal = sValue.split(" ");
    String s1 = sSplitVal[0];
    int i2 = Integer.parseInt(sSplitVal[1]);
    String sm = Long.toString(Long.parseLong(s1, 10), i2);
    System.out.print(sm.length());
  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
#define pb push_back
#define all(x) x.begin(),x.end()
ll mob=1000000007;
using namespace std;
int main()
{ 
int n;
cin>>n;
ll a[n];
FOR(i,n)cin>>a[i];
ll sumh[n];
ll sump[n];
map<ll,ll> g;

FOR(i,n)
{
    sumh[i]=a[i]+i;
    g[sumh[i]]++;
    
    
}
FOR(i,n)
{
    sump[i]=i-a[i];
}
ll r=0;
for(int i=n-1;i>0;i--)
{ if(sump>0)
{
    if(g.find(sump[i])!=g.end())
    {
        r+=g[sump[i]];
    }
}
    
}
cout<<r;

return 0;
}











Measured memory_bytes: 20636
from itertools import product
import numpy as np
N,M,X=map(int,input().split(' '))
Books=[np.array(list(map(int,input().split(' ')))) for i in range(N)]
A=[0]*M
maxi = sum([Books[i][0] for i in range(N)])+1
ans = maxi
for i in product([0,1],repeat=N):
    tmp = np.array([0]*M)
    t_ans = 0
    for n,j in enumerate(i):
        if j:
            tmp += Books[n][1:]
            t_ans += Books[n][0]
    if tmp.min() >=X:
        ans = min(ans,t_ans)
if ans < maxi:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27260
#define _GLIBCXX_DEBUG //提出時に消す
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool check(ll mid, ll n, ll k,vector<ll> &a) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += (a[i] - 1) / mid;
  }
  return cnt <= k;
}

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  ll sum_len = 0;
  for (int i = 0; i < n; i++) sum_len += a[i];

  ll ng = sum_len / (k + n);
  ll ok = sum_len;
  ll mid;
  while (abs(ok - ng) > 1) {
    mid = (ng + ok) / 2;
    if (check(mid, n, k, a)) ok = mid;
    else ng = mid;
  }

  cout << ok << endl;
}

Measured memory_bytes: 4788
import java.util.Scanner;
import java.util.stream.StreamSupport;

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

        while(sc.hasNext()){
            int i=0;
            String word = sc.nextLine();
            String result = "";
            for(i=0; i<word.length(); i++){
                char ch = word.charAt(i);
                if (Character.isLowerCase(ch)){
                    ch = Character.toUpperCase(ch);
                }
                else if (Character.isUpperCase(ch)){
                    ch = Character.toLowerCase(ch);
                }

                result += ch;
            }

            System.out.println(result);

        }
    }
}



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

int main(){
    ll N;cin>>N;
    ll h[N];
    rep(i,N) {
      cin>>h[i];
    }
    ll sum=accumulate(h,h+N,0);
    ll count=0;
    while(sum>0){
        rep(i,N){
            if((i==N-1) && (h[i]>0)) {
              count++;
            }
            else if((h[i]>0) && (h[i+1]==0)) {
              count++;
            }
            if(h[i]>0) {
                h[i]--;
                sum--;
            }
        }//rep_ist_fertig
    }//while_ist_fertig
    
  

  
  cout<<count<<endl;

}

 

Measured memory_bytes: 256
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    N = int(readline().rstrip())
    ans = 0
    for i in range(1, N+1):
        n = N // i
        ans += 0.5 * n * (2*i + i * (n-1))
    print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll l, r; cin >> l >> r;
    if(l / 2019 != r / 2019) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = INF;
    Rep(i, l, r) Rep(j, i+1, r+1) chmin(ans, i * j % 2019);
    cout << ans << endl;
}

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

tree_info = {}
for i in range(n):
    row = input().split()
    childs = list(map(int, row[1:]))
    tree_info[int(row[0])] = [ int(child)  for child  in childs if child != -1]


Nodes = [None] * n

class Node:
    
    def __init__(self, id, parent, sibling, depth, child):
        self.id = id
        self.parent = parent
        self.depth = depth
        self.sibling = sibling
        self.height = 0
        if (parent == -1):
            self.tree_type = "root"
        elif(len(child) == 0):
            self.tree_type = "leaf"
        else:
            self.tree_type = "internal node"
            
        self.child = child
        
        if(self.tree_type != "leaf" and len(child) > 0):
            self.make_child()
    
    def make_child(self):
        if(len(self.child) == 2):
            Nodes[self.child[0]] = Node(self.child[0], self.id, self.child[1], self.depth + 1, tree_info[self.child[0]])
            Nodes[self.child[1]] = Node(self.child[1], self.id, self.child[0], self.depth + 1, tree_info[self.child[1]])
        elif(len(self.child) == 1):
            Nodes[self.child[0]] = Node(self.child[0], self.id, -1, self.depth + 1, tree_info[self.child[0]])
        
    def backward_height(self):
        if(self.tree_type == "root"):
            return
        if(self.tree_type == "leaf"):
            self.height = 0
        Nodes[self.parent].height = max(Nodes[self.sibling].height + 1, self.height + 1) 
        Nodes[self.parent].backward_height()
    
    def __str__(self):
        return "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
            self.id, self.parent, self.sibling, len(self.child), self.depth, self.height, self.tree_type)


for i in range(n):
    if(Nodes[i] == None):
        Nodes[i] = Node(i, -1, -1, 0, tree_info[i])

for i in range(n):
    if(Nodes[i].tree_type == "leaf"):
        Nodes[i].backward_height()

for root in Nodes:
    print(root)


Measured memory_bytes: 5620
#include <stdio.h>

int main () {
	int n;
	scanf("%d", &n);
	int AC = 0, WA = 0, TLE = 0, RE = 0;
	for (int i = 0; i < n; i++) {
		char s[6];
		scanf("%s", &s);
		if (s[0] == 'A') {
			AC++;
		}
		else if (s[0] == 'W') {
			WA++;
		}
		else if (s[0] == 'T') {
			TLE++;
		}
		else if (s[0] == 'R') {
			RE++;
		}
	}
	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
	
	return 0;
}

Measured memory_bytes: 1736
import numpy as np

N = int(input())
a = np.array([list(map(int,input().split())) for _ in range(N)])
dp=np.zeros([N+1,3])

for i in range(1,N+1):
    for j in range(3):
        dp[i][j] = a[i-1][j]+np.maximum(dp[i-1][(1+j)%3],dp[i-1][(2+j)%3])
print(int(max(dp[N])))


Measured memory_bytes: 49488
import math

n = input_data = int(input().rstrip())

total = 0
while n != 0:
	total += n % 10
	n /= 10
	n = math.floor(n)

is_harshad = (input_data % total == 0)

if is_harshad == True:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 20090717
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-12;
const int N=300000+10,maxn=10000+10,inf=0x3f3f3f3f;

int a[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,n;
    cin>>k>>n;
    if(k%2==0)
    {
        cout<<k/2;
        for(int i=1;i<n;i++)cout<<" "<<k;
    }
    else if(k==1)
    {
        for(int i=1;i<=(n+1)/2;i++)cout<<1<<" ";
    }
    else
    {
        for(int i=1;i<=n;i++)a[i]=k/2+1;
        for(int i=n/2;i;i--)
        {
            int j;
            for(j=n;a[j]==0&&j;j--);
            if(--a[j++])for(int u=j;u<=n;u++)a[u]=k;
        }
        for(int i=1;i<=n;i++)
        {
            if(!a[i])break;
            cout<<a[i]<<" ";
        }
    }
    return 0;
}
/********************

********************/


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

int main() 
{
    int n, p[210], m[110][110];
    cin >> n;
    for (int i = 1; i <= n; ++i) 
    {
        cin >> p[i-1] >> p[i];
    }
    for (int i = 0; i <= n; ++i) m[i][i] = 0;
    for (int l = 2; l <= n; ++l) 
    {
        for (int i = 1; i <= n - l + 1; ++i) 
        {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++) 
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout << m[1][n] << endl;
}


Measured memory_bytes: 3112
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m, x) = (v[0] as usize, v[1] as usize, v[2]);
    let mut books = vec![];
    for i in 0..n {
        let v = read_vec::<i64>();
        books.push(v);
    }

    let mut ans = std::i64::MAX;
    for state in 0..1 << n {
        let mut understand = vec![0; m];
        let mut price = 0;
        for j in 0..n {
            if (state >> j) & 1 == 1 {
                price += books[j][0];
                for i in 0..m {
                    understand[i] += books[j][i + 1];
                }
            }
        }
        if understand.iter().all(|&u| u >= x) && price < ans {
            ans = price;
        }
    }
    if ans == std::i64::MAX {
        println!("-1");
        return;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2168