akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

bool btest(int i, int j) {
  return (i & (1 << j));
}

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> sw(M);
  vector<int> p(M);
  for (int i = 0; i < M; ++i) {
    int k; cin >> k;
    vector<int> s(k); cin >> s;
    sw[i] = s;
  }
  cin >> p;

  int total = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int cnt = 0;
      for (int x : sw[j]) {
        if (btest(i, x-1)) ++cnt;
      }
      if (cnt % 2 != p[j]) {
        ok = false;
        break;
      }
    }
    if (ok) ++total;
  }
  cout << total << endl;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  auto b = a;
  if(prev_permutation(b.begin(), b.end())) {
    for(int i = 0; i < n; ++i) cout << b[i] << " \n"[i==n-1];
  }
  for(int i = 0; i < n; ++i) cout << a[i] << " \n"[i==n-1];
  auto c = a;
  if(next_permutation(c.begin(), c.end())) {
    for(int i = 0; i < n; ++i) cout << c[i] << " \n"[i==n-1];
  }
  return 0;
}



Measured memory_bytes: 3140
import sys

N = int(input())

x = []
y = []
h = []

for _ in range(N):
    t_x, t_y, t_h = map(int, input().split())
    x.append(t_x)
    y.append(t_y)
    h.append(t_h)

for i in range(101):
    for j in range(101):

        H = -1
        # 初期化
        for index, t_h in enumerate(h):
            if t_h != 0:
                H = abs(i - x[index]) + abs(j - y[index]) + t_h
                break

        for t_x, t_y, t_h in zip(x, y, h):
            if t_h == 0:
                if H > abs(i - t_x) + abs(j - t_y):
                    break
            elif H != abs(i - t_x) + abs(j - t_y) + t_h:
                break
        else:
            print(i, j, H)
            sys.exit(0)


Measured memory_bytes: 42736
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int n1,n2;
			String s,result;
			s = sc.next();
			sc.close();
			
			n1=Integer.parseInt(s.substring(0,2));
			n2=Integer.parseInt(s.substring(2,4));
			if(n1>0 && n1<13) {
				if(n2>0 && n2<13){
					result="AMBIGUOUS";
				}
				else{
					result="MMYY";
				}
			}
			else if(n2>0 && n2<13) {
				result="YYMM";
			}
			else {
				result="NA";
			}

			// 出力
			System.out.println(result);
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8
int main(){
  int M;
  cin >> M;
  cout << 48-M << endl;
}

Measured memory_bytes: 256
n,m,l = [int(x) for x in raw_input().split()]

A = []
for idx in range(0,n):
    A.append([int(x) for x in raw_input().split()])

B = []
for idx in range(0,m):
    B.append([int(x) for x in raw_input().split()])

for line in range(0, n):
    result_list = []
    for idx1 in range(0, l):
        sum = 0
        for idx2 in range(0, m):
            sum += A[line][idx2] * B[idx2][idx1]
        result_list.append(sum)
    
    result_str = ""
    for result in result_list:
        result_str += str(result) + " "
    print result_str.rstrip()

Measured memory_bytes: 4744
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(s;stdin.byLine())
    {
        int[] a;
        foreach(c;s) a~=c-'0';
        foreach_reverse(i;1..a.length)
            foreach(j;0..i) a[j]=(a[j]+a[j+1])%10;
        writeln(a[0]);
    }
}

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

int N, K;
vector<int> A;

int main() {
  while (cin >> N >> K) {
	A.resize(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	int res = 0;
	int right = 0;
	while (true) {
	  if (res == 0) right += K;
	  else right += K-1;
	  ++res;

	  if (right >= N) break;
	}
	cout << res << endl;
  }
}



























Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define SORT(A) sort(A.begin(), A.end())
#define SORTG(A) sort(A.begin(), A.end(), greater<int>())
using namespace std;
typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> table;
    string tmp;
    bool flg;
    rep(y, H)
    {
        cin >> tmp;
        for (char c : tmp)
        {
            if (c == '#')
            {
                table.push_back(tmp);
                break;
            }
        }
    }
    vector<bool> dlt(W, true);
    rep(x, W)
    {
        rep(y, table.size())
        {
            if (table.at(y).at(x) == '#')
            {
                dlt.at(x) = false;
                break;
            }
        }
    }
    for (string y : table)
    {
        rep(x, W)
        {
            if (dlt.at(x) == false) cout << y.at(x);
        }
        cout << endl;
    }

    return 0;
}

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

static const int N = 100;

int main() {
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i - 1] >> p[i];
	}

	for (int i = 1; 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: 3104
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

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


int n, d;

int main(){
	cin >> n >> d;
	
	d += d + 1;
	
	cout << n / d + !!(n%d) << endl;
	
	return 0;
}

Measured memory_bytes: 256
use itertools::Itertools as _;
use proconio::input;
use std::ops::BitXor;

fn main() {
    input! {
        n: usize,
        r#as: [u64; n],
    }

    let xor = r#as.iter().fold(0, BitXor::bitxor);

    println!("{}", r#as.iter().map(|a| a ^ xor).format(" "));
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  char A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool X = false;
  for (int i = 0; i < N; i++) {
    if (A[i] == 'Y') {
      X = true;
      break;
    }
  }
  if (X) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

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

using namespace std;

int n, k;
long long h[200005], total;

int main() {
  cin >> n >> k;
  for(int ana = 0; ana < n; ana++) {
    cin >> h[ana];
  }
  sort(h, h + n);
  for(int ani = 0; ani < n - k; ani++) {
    total += h[ani];
  }
  cout << total << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int n, a[200005];
int b[200005];

bool trial(int v){
	for(int i=0; i<2*n-1; i++) b[i] = (a[i] >= v);
	if(b[n-2] != b[n-1] && b[n-1] != b[n]){
		int w = n-2, e = n;
		while(w > 0 && b[w-1] != b[w]) w--;
		while(e+1 < 2*n-1 && b[e+1] != b[e]) e++;
		if(e - w + 1 == 2*n-1) return b[w];
		if((e - w + 1) % 2 == 1) return b[w];
		if(abs(n-1-w) < abs(n-1-e)) return b[w];
		return b[e];
	}
	return b[n-1];
}


int main(){
	cin >> n;
	for(int i=0; i<2*n-1; i++){
		cin >> a[i];
	}
	int s = 1, e = 2*n-1;
	while(s != e){
		int m = (s+e+1)/2;
//		printf("%d %d\n", m, trial(m));
		if(trial(m)) s = m;
		else e = m-1;
	}
	cout << s;
}


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

int main(){
    int W,H,N;
    cin >> W >> H >>N;
    int x[N];
    int y[N];
    int a[N];
    for(int i=0;i<N;i++) cin >> x[i] >> y[i] >>a[i];
    int maxX=W,minX=0,maxY=H,minY=0;

    for(int i=0;i<N;i++){
        if(a[i]==1) minX = max(minX,x[i]);
        if(a[i]==2) maxX = min(maxX,x[i]);
        if(a[i]==3) minY = max(minY,y[i]);
        if(a[i]==4) maxY = min(maxY,y[i]);
    }
    int ans;
    if((minX<=maxX)&&(minY<=maxY)) ans =(maxX-minX)*(maxY-minY);
    else ans =0;

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rep1(i,n) for(int i=1; (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
  int main(){
  int a, b; cin >> a >> b;
  int ans = a - 2*b;
  if(ans < 0) ans = 0;
  cout << ans;
  
  return 0;
  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <string>
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() {
	int n; cin >> n;
	vector<string> s(n);
	vector<int> p(n);
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> s.at(i) >> p.at(i);
		a.at(i) = i + 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (s.at(i).compare(s.at(j))>0) {
				swap(s.at(i), s.at(j));
				swap(a.at(i), a.at(j));
				swap(p.at(i), p.at(j));
			}
		}
	}
	for (int i = 0; i < n; i++) {
		int j = i + 1;
		while (j < n and s.at(i) == s.at(j)) {
			if (p.at(i) < p.at(j)) {
				swap(p.at(i), p.at(j));
				swap(a.at(i), a.at(j));
			}
			j++;
		}
	}

	for (int i = 0; i < n; i++) {
		cout << a.at(i) << endl;
	}
	return 0;
}

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

typedef long long ll;

ll P = 999999999989LL;
ll M = 1000003LL;

ll mod_mul(ll a,ll b){
  return ((a*(b/M)%P)*M + (a*(b%M))%P)%P;
}

ll power(ll x,ll p){
  ll res = 1;
  while(p>0){
    if(p&1)res = mod_mul(res,x);
    x = mod_mul(x,x);
    p >>= 1;
  }
  return res;
}

int main(){
  ll x,y;
  int n,o;

  cin >> n;
  x = 0;
  for(int i=0;i<n;i++){
    cin >> o >> y;
    if(o == 1)x += y;
    else if(o == 2)x -= y;
    else if(o == 3)x = mod_mul(x,y);
    else if(o == 4)x = mod_mul(x,power(y,P-2));
    x = (x+P)%P;
  }
  if(x<(1LL<<31))cout << x << endl;
  else cout << x-P << endl;
}

Measured memory_bytes: 1168
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define LOCAL
#ifdef LOCAL
#define debug(a) cerr<<#a<<" "<<a<<endl;
#else
#define debug(a)
#endif
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	if(n>=30)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int r;
	cin >> r;
	cout << 2*PI*r << endl;
	return 0;
}


Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int a[3][3];
    bool c[3][3];
    rep(i,3){
        rep(j, 3){
            cin >> a[i][j];
            c[i][j]=false;
            }
    }

    int n; cin >> n;
    int b[n+1];

    rep(i, n) cin >> b[i];
    rep(k, n){
        rep(i, 3){
            rep(j, 3){
                if(b[k]==a[i][j]) c[i][j]=true;
            }
        }
    }

    rep(i,3){
        if(c[i][0]==1&&c[i][1]==1&&c[i][2]==1){out("Yes");return 0;}
        else if(c[0][i]==1&&c[1][i]==1&&c[2][i]==1){out("Yes"); return 0;}
    }
    if(c[0][0]==1&&c[1][1]==1&&c[2][2]==1){out("Yes"); return 0;}
    if(c[0][2]==1&&c[1][1]==1&&c[2][0]==1){out("Yes"); return 0;}

    out("No");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())

lst = [0]*N

for i in range(N):
    X = list(set(list(S[0:i])))
    Y = list(set(list(S[i:N])))
    ans = 0
    for j in range(len(X)):
        if X[j] in Y:
            ans += 1
    lst[i] = ans

print(max(lst))


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i, n) cin>>a[i];

  ll ans = 0;
  rep(i, n) {
    ll t = a[i];
    while (t%2 == 0) {
      t/=2;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3688
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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(){
    string s,t;
    cin>>s>>t;
    cout<<t<<s;
}

Measured memory_bytes: 256
n = $stdin.gets.chomp.to_i

f = Array.new
n.times do |num|
  f << $stdin.gets.split.map(&:to_i)
end

p = Array.new
n.times do |num|
  p << $stdin.gets.split.map(&:to_i)
end

answers = []
[0, 1].repeated_permutation(10) do |perm|
  next if perm == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  score = 0
  f.each_with_index do |ary, index|
    count = 0
    ary.each_with_index do |i, idx|
      if perm[idx] == 1 && ary[idx] == 1
        count += 1
      end
    end
    score += p[index][count]
  end
  answers << score
end

puts answers.max


Measured memory_bytes: 3836
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define mod 1000000007
using namespace std;
typedef long long int LL;

int main() {
    int n;
    LL y;
    cin >> n >> y;

    rep(a, n + 1) {
        rep(b, n + 1) {
            LL c = n - a - b;
            if (c >= 0
                and 10000LL * a + 5000LL * b + 1000L * c == y) {
                printf("%d %d %d\n", a, b, c);
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Here your code !

import math

def minmax_n(n):
    return sum(i for i in range(0,n)), sum(i for i in range(9,9-n,-1))

def saiki(n, s, ls):
    ans = 0
    if n==1:
        if s in ls:
            return 1
        else:
            return 0
    if s < minmax_n(n)[0] or s > minmax_n(n)[1]:
        return 0
    for l in ls:
        ls_ = ls[:]
        ls_.remove(l)
        ans += saiki(n-1, s-l, ls_)
    return ans

while(1):
    str = raw_input()
    n, s = map(int, str.split(' '))
    
    if n==0 and s==0:
        break
    if s < minmax_n(n)[0] or s > minmax_n(n)[1]:
        print 0
    else:
        print saiki(n, s, range(10))/math.factorial(n)

Measured memory_bytes: 6396
def chmin(a, b)
    a > b ? b : a
  end
n = gets.to_i
sum = 10000000000000
(1..Math.sqrt(n)).each do |i|
    if n % i == 0
        k = n / i
        sum = chmin(sum, (i - 1) + (k - 1))
    end
end
puts sum


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int A[110] = {};
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    A[a]++;    
  }

  int cost1 = 0, cost2 = 0;
  for (int i = 1; i < X; i++) {
    if (A[i] > 0) cost1++;
  }
  for (int i = X + 1; i < N; i++) {
    if (A[i] > 0) cost2++;
  }

  cout << min(cost1, cost2) << endl;
}

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

public class Main {

	public static void main(String[] args) {
		FastReader s = new FastReader();
	
		int n = s.nextInt();
		int[] inp = new int[n];
		
		Set<Integer> set = new HashSet<>();
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i=0;i<n;++i)
		{
			inp[i] = s.nextInt();
			map.put(inp[i], map.getOrDefault(inp[i], 0)+1);
			set.add(inp[i]);
		}
		int ans = 0;
		for(int i=0;i<n;++i)
		{
			for(int j=1;j<=Math.sqrt(inp[i]);++j)
			{
				if(inp[i]%j == 0)
				{
					if(j==1)
					{
						if(map.get(inp[i]) > 1)
						{
							ans++;
							break;
						}
						
						if(set.contains(j) && inp[i]!=1)
						{
							ans++;
							break;
						}
							
					}
					else
					{
						if(set.contains(j))
						{
							ans++;
							break;
						}
						if(set.contains(inp[i]/j))
						{
							ans++;
							break;
						}
					}
				}
			}
		}
		
		System.out.println(n-ans);
	}
	
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
	}

}


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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int tmp = 0;
		int p = i;
		while (p >= 10) {
			tmp +=(p % 10);
			p /= 10;
		}
		tmp += p;
		if (tmp >= a && tmp <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}


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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

#define testcase(t) \
    while (t--)     \
        solve();

void solve()
{
}

int32_t main()
{
    FIO;
    //OJ;

    int n, x, t;
    cin >> n >> x >> t;

    if (n % x == 0)
    {
        cout << (n / x) * t << endl;
    }
    else
    {
        cout << ((n / x) + 1) * t << endl;
    }

    return 0;
}

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

public class Main {

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

		int n = sc.nextInt();
		ArrayList<List<Integer>> A = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> B = new ArrayList<>();
			A.add(B);
		}
		int q = sc.nextInt();

		for (int i = 0; i < q; i++) {
			int x = sc.nextInt();
			if (x == 0) {
				int y = sc.nextInt();
				int z = sc.nextInt();
				A.get(y).add(z);

			} else if (x == 1) {
				int y = sc.nextInt();
				if (A.get(y).size() != 0) {
					System.out.println(A.get(y).get(0));
				}

			} else if (x == 2) {
				int y = sc.nextInt();
				if (A.get(y).size() != 0) {
					A.get(y).remove(0);
				}
			}
		}
		sc.close();
//A.get(y).size() - 1
	}

}



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

int main(){
  int a,c,d,e=0;
  cin>>a;
  vector<int>b(a);
  rep(i,a){
    cin>>c;
    b.at(i)=c;
  }
  sort(b.begin(), b.end());
  rep(i,a){
    d=0;
    for(int o=i;o<a;o++){
      d++;
      if(b[o]!=b[o+1])break;
      i++;
    }
    if(b[i]>d)e+=d;
    else e+=d-b[i];
  }
  cout<<e;
}

Measured memory_bytes: 768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int A = in.nextInt(), B = in.nextInt(), C = in.nextInt(), K = in.nextInt();
            int ans = 0;
            if (A >= K) {
                ans = K;
            } else {
                ans = A;
                K -= A;
                K -= B;
                if (K > 0) {
                    ans -= K;
                }
            }
            out.printLine(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}



Measured memory_bytes: 32896
#include <cstdio>
#include <map>

using namespace std;

const int MAXN=2e5+10;

int A[MAXN];
bool ok[MAXN];
int N;


int main(){
    map<int,int> m;
    scanf("%d",&N);

    for(int i=1;i<=N;i++) {
        int temp;
        scanf("%d",&temp);
        m[temp]++;
    }

    auto ans=0;
    auto maxele=(*m.rbegin()).first;
    for(auto i:m){
        for(int k=2;i.first*k<=maxele;k++){
            int temp=i.first*k;
            auto multiple=m.find(temp);
            if (multiple==m.end()) continue;
            m.erase(multiple);
        }
        if (i.second>1) continue;
        ans++;
    }

    printf("%d\n",ans);

    return 0;
}

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

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

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

    cin >> n;
    n %= 10;
    if (n == 3) cout << "bon\n";
    else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon\n";
    else cout << "hon\n";
}


Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    print(max(len(set(S[:i]) & set(S[i:])) for i in range(1, N)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int s,w;
  cin >> s >> w;
  if(w>=s) cout << "unsafe" << endl;
  else cout << "safe" << endl;


  return 0;
}


Measured memory_bytes: 3676
import sys
readline = sys.stdin.readline
from collections import Counter


def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    counter = Counter(A)
    res = sum(A)

    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().rstrip().split())
        res = res - b * counter[b] + c * counter[b]
        counter.setdefault(c, 0)
        counter[c] += counter[b]
        counter.setdefault(b, 0)
        counter[b] = 0

        print(res)
        

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  int n;
  cin >> n;
  bool is_valid = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0)  is_valid = false;
    }
  }
  if (is_valid) puts("APPROVED");
  else puts("DENIED");
  return 0;
}



Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;
	int mx = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x >= mx) {
			ans++;
			mx = x;
		}
	}

	cout << ans;


	return 0;
}


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

int n, k, a[100010];
long long dp[110][100010], mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=0; i<n; ++i) cin >> a[i+1];
	dp[0][0] = 1;
	for(int i=1; i<=n; ++i){
		for(int j=0; j<=k; ++j){
			dp[i][j] = dp[i-1][j-min(a[i], j)] - dp[i-1][j+1];
			dp[i][j] %= mod;
			if(dp[i][j] < 0) dp[i][j] += mod;
		}
		for(int j=k-1; j>=0; --j){
			dp[i][j] += dp[i][j+1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][k] << "\n";
}

Measured memory_bytes: 81408
n=int(input())
A=[]
B=[]
C=[]
for i in range(n):
    
    a,b,c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    
dp = [[0,0,0] for i in range(n)]

dp[0] =[A[0],B[0],C[0]]

for i in range(1,n):
    
    a = max(dp[i-1][1], dp[i-1][2]) + A[i]
    b = max(dp[i-1][2], dp[i-1][0]) + B[i]
    c = max(dp[i-1][0], dp[i-1][1]) + C[i]
    
    dp[i] = [a,b,c]
    
print(max(dp[-1]))


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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int A, B, M;
vector<int> v1, v2;
int ans = 0;

int main(){
	scanf("%d%d", &A, &B);
	scanf("%d", &M);
	int mn = INF;
	v1.pb(0); v2.pb(0);
	for(int i=1; i<=A; i++){
		int x; scanf("%d", &x); v1.pb(x);
		mn = min(mn, x);
	}
	ans+=mn;
	mn = INF;
	for(int i=1; i<=B; i++){
		int x; scanf("%d", &x); v2.pb(x);
		mn = min(mn, x);
	}
	ans+=mn;
	for(int i=1; i<=M; i++){
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		ans = min(ans, v1[a]+v2[b]-c);
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		short A = sc.nextShort();
		short B = sc.nextShort();
		short C = sc.nextShort();
		
		if( A <= C && C <= B ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
		sc.close();
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,k,x,y;
    cin>>a>>b;
    if(a!=b)
    {
        k=(a+b)/2;
        if(k==(int)k)
        {
            x=a-k;
            x=abs(x);
            y=b-k;
            y=abs(y);
            if(x==y)
            {
                cout<<k<<endl;
            }
            else
                cout<<"IMPOSSIBLE"<<endl;

        }
        else
        {
            cout<<"IMPOSSIBLE"<<endl;
        }

    }
}


Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-23 16:27:12
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    if (a >= b) {
        cout << "delicious" << endl;
    } else if (b-a <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long ll;
int n;
ll a[N];
unordered_map<ll,int>vis;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=vis[i-a[i]];
        vis[i+a[i]]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 20100
# -*- coding: utf-8 -*-

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    N = int(input())

    return N


def sum_digits(n: int) -> int:
    """
    各桁の和を取得する.

    Args:\n
        n (int): 整数

    Returns:\n
        int: 各桁の和
    """
    return sum(list(map(int, str(N))))


def main(N: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数(0 <= N <= 10**200000)
    """
    # 求解処理
    ans = str()
    if sum_digits(N) % 9 == 0:
        ans = "Yes"
    else:
        ans = "No"

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N = get_input()

    # メイン処理
    main(N)


Measured memory_bytes: 11268
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	string str;
	cin >> str;
	str[5] = ' ';
	str[13] = ' ';

	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n,m,cnt=0;
int head[410000],nxt[410000],to[410000],val[410000];
int ma=0,mi=0;
int q[1000000],dis[100100],f[100100],vis[100100];
void addedge(int x,int y,int z)
{
    cnt++;
    nxt[cnt]=head[x];
    head[x]=cnt;
    to[cnt]=y;
    val[cnt]=z;
}
bool spfa(int x)
{
    int l=0,r=1;
    q[1]=x;vis[x]=1;dis[x]=0;
    while(l<r)
    {
        int u=q[++l];
        for(int i=head[u];i!=-1;i=nxt[i])
        {
            int v=to[i];
            if(dis[v]==12345678987654321)
            {
                dis[v]=dis[u]+val[i];
                ma=max(ma,dis[v]);
                mi=min(mi,dis[v]);
                if(ma-mi>1e9) return 0;
                vis[v]=1;
                if(!f[v]) q[++r]=v,f[v]=1;
            }
            else if(dis[v]!=dis[u]+val[i]) return 0;
        }
        f[u]=0;
    }
    return 1;
}
signed main()
{
    memset(head,-1,sizeof(head));
    for(int i=1;i<=100000;i++)
        dis[i]=12345678987654321;
    scanf("%lld%lld",&n,&m);
    if(!m) {printf("Yes");return 0;}
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        addedge(x,y,z);
        addedge(y,x,-z);
    }
    for(int i=1;i<=n;i++)
        if(!vis[i]) {if(!spfa(i)) {printf("No");return 0;}}
    printf("Yes");
    return 0;
}

Measured memory_bytes: 19200
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,a,b;
	cin >> n;
	vector<vector<int>> G(n);
	vector<pair<int,int>> vp;
	for(int i = 0; i < n -1; i++) {
		cin >> a >> b;
		G[a - 1].emplace_back(b - 1);
		G[b - 1].emplace_back(a - 1);
		vp.emplace_back(a-1,b-1);
	}
	int K = 0;//木の大きさ
	map<pair<int,int>,int> I;
	vector<int> cs(n,0);//頂点の色
	
	vector<int> used(n,0);//使用済みの頂点
	queue<int> que;
	used[0] = 1;
	que.emplace(0);
	while(!que.empty()){//bfs
		int v = que.front();
		que.pop();
		if(K <(int)G[v].size()){//その頂点からでる辺の数が最大のものが色の数
			K = G[v].size();
		}
		int cur = 1;
		//使ってない色の中で最小のものをみつける

		for(int u:G[v]){//G[v]の中身をループ
			if(used[u]){
				continue;
			}
			if(cur == cs[v]){
				cur++;
			}
			cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
			used[u] = 1;
			que.emplace(u);//子を追加
		}

	}

	cout<<K<<endl;
  	for(auto p:vp) cout<<I[p]<<endl;//この表現便利
	return 0;
}

Measured memory_bytes: 20084
#include "bits/stdc++.h"
using namespace std;

int main()
{
    string s;
    cin >> s;
    long long q;
    cin >> q;

    s.reserve(q);
    // 読み捨て
    string command;
    getline(cin, command);

    bool isreverse = false;
    for (auto i = 0; i < q; i++)
    {
        string command;
        getline(cin, command);

        if (command.length() == 1)
        {
            int n = atoi(&(command.at(0)));
            isreverse = !isreverse;
        }
        else
        {
            char f = command[2];
            char c = command[4];
            if (f == '1')
            {
                if (isreverse)
                {
                    s.push_back(c);
                }
                else
                {
                    s.insert(s.begin(), c);
                }
            }
            else
            {
                if (isreverse)
                {
                    s.insert(s.begin(), c);
                }
                else
                {
                    s.push_back(c);
                }
            }
        }
    }

    if (isreverse == true)
    {
        reverse(s.begin(), s.end());
    }

    std::cout << s << endl;
}


Measured memory_bytes: 924
import java.util.*;

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

    String S = sc.next();
    long K = sc.nextLong();

    int one_length = 0;
    String next_string = "1";

    for (int i = 0; i < S.length(); i++) {
      if (S.charAt(i) != '1') {
        one_length = i;
        next_string = String.valueOf(S.charAt(i));
        break;
      }
    }

    String ans = "";

    if (K <= (long)one_length) {
      ans = "1";
    } else {
      ans = next_string;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21204
function Main(s){
  s = s.split("\n");
  s[0] = s[0].split(" ").map(a => parseInt(a));
  const n = s[0][0];
  var a = s[1].split(" ").map(a => parseInt(a));
  var min = a[0];
  var now = 0;
  var ans = 0;
  for(var i = 1; i < n; i++){
    tmp = a[i] - min;
    if(tmp > now){
      now = tmp;
      ans = 1;
    }else if(tmp === now) ans++;
    else if(min > a[i]) min = a[i];
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17612
//＊最初に、入力のNを1/2倍しておく。以降では1≦N≦6*10^5として考える。
//AB, BA -> AA, BBと置き換えて良い. （偶数番目のAをBに, BをAにした文字列Tを考えると分かる）
//置き換え後、A,BだけならAB,BAを消せるので、AとBが同数が必要条件。
//逆にAとBが同数(1個以上)なら, AB, BAがどこかに存在するので、帰納的に十分性が成立。
//Cは(AまたはB)として使えるので、長さ2NのABC列であって「A,BがN個以下」を数えれば良い。
//否定を取ると「AがN+1個以上」または「BがN+1個以上」となりこれは排反かつ対称な条件なので嬉しい。
//「AがN+1個以上」はAの個数を全探索すれば容易に計算可能。
//1～Nのmod P (P=998244353)での逆元の計算にO(NlogP)かけると厳しいが、これはO(N)にできるので大丈夫。

#include <iostream>
#define int long long
using namespace std;

const int MAX = 10000010;
const int mod = 998244353;
int fact[MAX], finv[MAX], inv[MAX];
int pow2[MAX];

int comb(int n, int k) {
	if (k > n) return 0;
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

int n;

signed main() {
	int i;
	
	cin >> n;
	n /= 2;
	
	//参考：http://drken1215.hatenablog.com/entry/2018/06/08/210000
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (i = 2; i < MAX; 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;
	}
	
	pow2[0] = 1;
	for (i = 1; i < MAX; i++) {
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
	
	int ngCnt = 0;
	for (i = n + 1; i <= 2 * n; i++) {
		ngCnt += comb(2 * n, i) * pow2[2 * n - i] % mod;
		ngCnt %= mod;
	}
	
	int all = 1;
	for (i = 0; i < 2 * n; i++) (all *= 3) %= mod;
	
	int ans = (all - 2 * ngCnt + 2 * mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 312704
// https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// dp[i][j] : コインをi枚使い、j枚が表である確率
// double dp[3001][3001];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	// 入力、DP後、DP前
	vector<double> p(n), dpA(n + 1, 0), dpB(n + 1, 0);
	vector<double>& p_dpa = dpA;
	vector<double>& p_dpb = dpB;

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	p_dpb[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			// i-1回目で表の枚数がj-1で、i回目が表
			// i-1回目で表の枚数がjで、i回目が裏
			p_dpa[j] = p_dpb[j - 1] * p[i - 1] + p_dpb[j] * (1.0 - p[i - 1]);
		}
		swap(p_dpb, p_dpa);
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += p_dpb[i];
	}
	printf("%0.10f\n", ans);

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b='.';
    //int i=1;
    cin>>a>>b>>c>>d;
    if(a+b>c+d) cout<<"Left";
    else if(a+b==c+d) cout<<"Balanced";
    else cout<<"Right";
    return 0;
}



Measured memory_bytes: 256
def solve():
    # mini = (k - 1) * k // 2
    # maxi = k * (n - k + 1) + mini
    total_comb = 0
    for i in range(k, n+2):
        total_comb = (total_comb + i * (n - i + 1) + 1) % (10**9 + 7)
    print(total_comb)
    return



n, k = [int(i) for i in input().split(" ")]
solve()

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

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define INF 100000000

int D, G;
vi P, C;

int main()
{
	cin >> D >> G;
	P.assign(D, 0), C.assign(D, 0);

	for (int d = 0; d < D; d++)
		cin >> P[d] >> C[d];

	int best = INT_MAX;
	for (int i = 0; i < (1 << D); i++)
	{
		int temp = G;
		int count = 0;
		for (int d = 0; d < D; d++)
			if ((i >> d) & 1 == 1)
				temp -= C[d], temp -= P[d]*((d+1)*100), count += P[d];

		if (temp <= 0)
		{
			best = min(best, count);
			continue;
		}

		for (int d = D-1; d >= 0; d--)
		{
			if ((i >> d) & 1 == 1) 
				continue;
			int worth = (d+1) * 100;
			int target = (temp % worth == 0) ? temp / worth : temp / worth + 1;
			int used = min(target, P[d]);
			count += used;
			temp -= used * worth;
			if (temp <= 0)
				break;
		}
		best = min(best, count);
	}
	cout << best << endl;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, n;
  priority_queue<ll, vector<ll>,  greater<ll> > pq_fw;
  priority_queue<ll> pq_bw;
  ll sum_fw = 0, sum_bw = 0;
  cin >> N;
  n = 3 * N;
  vector<ll> a(n), tots_fw(N+1), tots_bw(N+1);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    if(i<N) {
      pq_fw.push(a[i]);
      sum_fw += a[i];
    }
    if(i>=2*N) {
      pq_bw.push(a[i]);
      sum_bw += a[i];
    }
  }
  ll ans = sum_fw - sum_bw;

  tots_fw[0] = sum_fw;
  tots_bw[N] = sum_bw;
  for(int i=N;i<2*N;i++) {
    sum_fw += a[i];
    pq_fw.push(a[i]);
    sum_fw -= pq_fw.top();
    pq_fw.pop();
    tots_fw[i-N+1] = sum_fw;
    //cout << "tots_fw : "<< tots_fw[i-N] << endl;
  }

  for(int i=2*N-1;i>=N;i--) {
    sum_bw += a[i];
    pq_bw.push(a[i]);
    sum_bw -= pq_bw.top();
    pq_bw.pop();
    tots_bw[i-N] = sum_bw;
    //cout << "tots_bw : "<< tots_bw[i-N] << endl;
  }


  for(int i=0;i<=N;i++) {
    ans = max<ll>(ans, tots_fw[i]-tots_bw[i]);
  }
  cout << ans << endl;


}


Measured memory_bytes: 6516
#include<stdio.h>

main(){


int a,b,c,x,y,z;


scanf("%d %d %d",&a,&b,&c);


if(a>b){


x=a;


a=b;


b=x;


}


if(b>c){


y=b;


b=c;


c=y;


}


if(a>b){


z=a;


a=b;


b=z;


}


printf("%d %d %d\n",a,b,c);


return 0;


}

Measured memory_bytes: 596
n, k = map(int, input().split())

li = [int(input()) for _ in range(n)]
li.sort()
ans = li[-1]
for i in range(n-k+1):

    if ans > li[i+k-1] - li[i]:
        ans = li[i+k-1] - li[i]

print(ans)


Measured memory_bytes: 7384