akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	static int n, k, a[];
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		n = fs.nextInt(); k = fs.nextInt();
		a = fs.nextIntArray(n);
		
		int sum = 0;
		for(int i=0;i<n;i++)sum += a[i];
		
		List<Integer> ls = new ArrayList<>();
		for(int i=1;i*i<=sum;i++) {
			if(sum%i==0) {
				ls.add(i);
				ls.add(sum/i);
			}
		}
		ls.add(sum);
		
		int ans = 0;
		for(int t:ls) {
			if(check(t))ans=Math.max(ans, t);
		}
		
		System.out.println(ans);
	}
	static boolean check(long x) {
		int b[] = new int[n];
		for(int i=0;i<n;i++) {
			b[i] = (int)(a[i] % x);
		}
		Arrays.sort(b);
		int sum[] = new int[n+1];
		for(int i=0;i<n;i++)sum[i+1] = sum[i] + b[i];
		for(int i=0;i<n;i++) {
			long minus = sum[i+1];
			long plus = x * (n-i-1) - (sum[n] - sum[i+1]);
			if(minus == plus) {
				if(minus<=k)return true;
				else return false;
			}
		}
		return false;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 26668
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i=0;i<ty-sy;i++)
    cout << 'U';
  for(int i=0;i<tx-sx;i++)
    cout << 'R';
  for(int i=0;i<ty-sy;i++)
    cout << 'D';
  for(int i=0;i<tx-sx+1;i++)
    cout << 'L';
  for(int i=0;i<ty-sy+1;i++)
    cout << 'U';
  for(int i=0;i<tx-sx+1;i++)
    cout << 'R';
  cout << "DR";
  for(int i=0;i<ty-sy+1;i++)
    cout << 'D';
  for(int i=0;i<tx-sx+1;i++)
    cout << 'L';
  cout << 'U' << endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
K = gets.chomp.to_i
x = gets.chomp.split.map(&:to_i)

ans = 0

N.times do |i|
  if (2 * (K - x[i]) < 2 * x[i])
    ans += 2 * (K - x[i])
  else
    ans += 2 * x[i]
  end
end

puts ans

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

bool solve() {
    ll X, Y;
    cin >> X >> Y;
    for ( int i = 0; i <= 100; i++ ) {
        for ( int j = 0; j <= 100; j++ ) {
            if ( i + j == X && 2*i+4*j==Y ) return true;
        }
    }
    return false;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624
words = lambda t : list(map(t, input().split()))
h,w = words(int)
mat = []
for _ in range(h):
    mat.append(words(int))
ans = []

for i in range(h-1):
    for j in range(w):
        if mat[i][j] % 2 != 0:
            mat[i][j] -= 1
            mat[i+1][j] += 1
            ans.append([i+1,j+1,i+2,j+1])
for i in range(w-1):
    if mat[-1][i] % 2 != 0:
        mat[-1][i] -= 1
        mat[-1][i+1] += 1
        ans.append([h,i+1,h,i+2])

print(len(ans))
for a in ans:
    print(" ".join(map(str,a)))


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

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

int main() {
  ll n, ans = 0;
  cin >> n;
  map<string, ll> mp;
  string s;
  string sample[4] = {"AC", "WA", "TLE", "RE"};
  rep(i, n) cin >> s, mp[s]++;

  rep(i, 4) cout << sample[i] << " x " << mp[sample[i]] << endl;

  return 0;
}


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

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

    ll k;
    cin >> k;

    for (int i = 0; i < k; i++) {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (k--)
	{
		if (b <= a)
		{
			b *= 2;
		}
		else if (c <= b)
		{
			c *= 2;
		}
	}
	if (c > b && b > a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <queue>
#include <cmath>
#include <cfloat>
#include <set>
#include <map>

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n, i);
	OUT(n-i+1)BR;
	
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  if(a+b==c+d){
    cout << "Balanced" << endl;
    return 0;
  }

  cout << (a+b>c+d?"Left":"Right") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector<int> W(N);
  int sum = 0, ans = 1<<30;
  REP(i,N) {
    cin>>W[i];
    sum += W[i];
  }
  int left = 0;
  REP(i,N-1) {
    left += W[i];
    int right = sum - left;
    ans = min(ans, abs(right - left));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        ll tmp = 0;
        for(ll x = i;x;x /= 10)tmp++;
        if(tmp%2)ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    while(1){
    int H,W;
    scanf("%d %d", &H, &W);
        if(H == 0 && W == 0)break;
        else{
            for(int j=0; j<H; j++){
                for(int i=0; i<W; i++){
                    printf("#");
                }
                printf("\n");
            }
        }
    printf("\n");
    }
}

Measured memory_bytes: 1744
#include <iostream>
#include <vector>
#include <algorithm>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define loop_from_to(from, to, i) for(int i=from;i<=to;i++)
#define repeat(n) for(int i__=0;i__<n;i__++)
#define multi_cin(n, array) loop(n,i){cin>>array[i];}
#define assign_if_smaller(var, val) if(var>val)var=val;
#define assign_if_larger(var, val) if(var<val)var=val;
#define each(itr, c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define r_each(itr, c) for(__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); itr++)

using namespace std;

bool check(int n, int k, int *s) {
  bool res = true;
  repeat(n) loop(k, i) {
    int b; cin>>b;
    s[i] -= b;
    if (s[i]<0) res = false;
  }

  return res;
}

int main(int argc, char const* argv[])
{
  while(1)
  {
    int n,k; cin>>n>>k;
    int s[k];
    if (n==0&&k==0) break;

    loop(k, i) cin>>s[i];

    if(check(n,k,s))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }

  return 0;
}

Measured memory_bytes: 1152
countMod0Num :: Int -> [Int] -> Int
countMod0Num n = length . filter ((==) 0) . map (flip mod n)

canSolveN :: Int -> Int -> Int -> Bool
canSolveN num4 num2 numOther
    | numOther == 0 = True
    | numOther <= num4 = True
    | (numOther + num2) <= (num4 + 1) = True
    | numOther <= (num4 + 1) && (num2 `mod` 2) == 0 = True
    | otherwise = False
    where
        num4Remain = num4 - numOther

canSolve :: [Int] -> Bool
canSolve arr = canSolveN num4 num2 numOther
    where
        num4 = countMod0Num 4 arr
        num2 = (countMod0Num 2 arr) - num4
        numOther = (length arr) - num2 - num4

toYesNo :: Bool -> String
toYesNo True = "Yes"
toYesNo False = "No"

solve :: [Int] -> String
solve = toYesNo . canSolve

main :: IO()
main = do
    n <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    putStrLn $ solve a 


Measured memory_bytes: 75132
#include<bits/stdc++.h>
using namespace std;
long long i,n;
string s;
int main()
{
	cin>>s;
	for (i=0;i<s.size();i++)
	  if (s[i]==67) n++;else
	    if (s[i]==70&&n>0) {cout<<"Yes";return 0;}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
  ll n,m; cin>>n>>m;
  Graph G(n);
  vector<ll>a(m),b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  ll ans=0;
  rep(i,m){
    queue<ll>q;
    q.push(0);
    vector<bool>seen(n,false);
    seen[0]=true;
    while(!q.empty()){
      ll v=q.front();
      q.pop();
      for(auto nv:G[v]){
        if(v==a[i]&&nv==b[i])continue;
        else if(v==b[i]&&nv==a[i])continue;
        else if(seen[nv])continue;
        q.push(nv);
        seen[nv]=true;
      }
    }
    rep(i,n){
      if(seen[i]==false){
        ans++;
        break;
      }
    }
 }
 cout<<ans<<endl;
}








Measured memory_bytes: 3636
import scala.io.StdIn

object Main extends App {
  val Array(n, m, x) = StdIn.readLine().split(' ').map(_.toInt)
  val costs = StdIn.readLine().split(' ').map(_.toInt)
  val c1 = costs.count(p => p < x)
  println(scala.math.min(c1, m - c1))

}

Measured memory_bytes: 27080
#include<cstdio>

int main(){
    long long a,b,k;
    scanf("%lld%lld%lld",&a,&b,&k);
    long long minus = a>k?k:a;
    a -= minus;
    k -= minus;
    minus = b>k?k:b;
    b -= minus;
    printf("%lld %lld\n",a,b);
    return 0;
}


Measured memory_bytes: 128
h, w, k = map(int, input().split())

c = [list(input()) for _ in range(h)]

ans = 0

#make binary numbers ranging from 0 to 2**h -1 or 2**w -1
for row in range(2**h):
    for column in range(2**w):
        count = 0
        # Neither ith digit of row nor jth digit of column is 1 and c[i][j] is black.
        for i in range(h):
            for j in range(w):
                if ((row >> i)&1) == 0 and ((column >> j)&1) == 0 and c[i][j] == '#':
                    count += 1
        if count == k:
            ans += 1

print(ans)

Measured memory_bytes: 9136
#include "stdio.h"

int main(int argc, char const *argv[])
{
    int n;
    int num;
    int keta = 1;
    int counter = 0;

    scanf("%d",&n);
    for (size_t i = 1; i <= n; i++){
        //printf("i:%d",i);
        keta = 1;
        num = i;
        while (num / 10  != 0){
            keta++;
            num = num / 10; 
        }
        
        
        if (keta % 2 == 1){
            counter++;
        }
        
    }
    printf("%d",counter);
    return 0;
}


Measured memory_bytes: 128
var binarySearch = function(key, n, a) {
  var left = 0;
  var right = n;
  while (left < right) {
    var mid = Math.floor((left + right) / 2);
    if (a[mid] == key) {
      return true;
    } else if (key < a[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  return false;
};

(function(stdin) {
  var arr = (stdin.trim()).split('\n');
  var s = arr[1].split(" ").map(Number);
  var t = arr[3].split(" ").map(Number);
 
  var ans = 0;
  for (var i = 0; i < t.length; i++) {
    ans += binarySearch(t[i], s.length, s);
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30692
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     pii             pair<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n, x)     (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     nshow(x,n)      for(int zz=0;zz<n;++zz)cout<<x[zz]<<" ";cout<<"\n";
#define     show2(x)        for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,k;
    cin>>n>>k;

    n%=k;
    int ans=min(n,k-n);
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,q; cin >> n >> q;
    vector<tuple<ll,ll,ll>> v;
    multiset<ll> st;
    rep(i,n){
        ll s,t,x;
        cin >> s >> t >> x;
        v.emplace_back(s-x, x, 1);
        v.emplace_back(t-x, x, -1);
    }
    v.emplace_back(INFL, 0, 0);
    sort(all(v));

    vector<pll> Q;
    rep(i,q){
        ll d; cin >> d;
        Q.emplace_back(d, i);
    }
    sort(all(Q));

    int now = 0;
    vl ans(q, -1);
    rep(i,q){
        ll d = Q[i].fi;
        ll idx = Q[i].se;
        while(d >= get<0>(v[now])){
            ll x = get<1>(v[now]);
            ll flg = get<2>(v[now]);
            if(flg == 1) st.insert(x);
            else st.erase(st.find(x));
            now++;
        }
        if(st.size() == 0) ans[idx] = -1;
        else ans[idx] = *st.begin();
    }
    for(auto d : ans){
        cout << d << endl;
    }
    return 0;
}

Measured memory_bytes: 26724
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char A[110];
char B[110];
char C[110];

int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	printf("%d %d\n",min(b,c),max(0,b+c-a));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char c;
	int w=1;
	while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
	int ans=c-'0';
	while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
	return ans*w;
}
int n;
int m;
int sum[1000005];
int main(){
	n=read();
	m=read();
	for(int i=1;i<=m;i++)
	{
		int a,b;
		a=read();
		b=read();
		sum[a]++;
		sum[b+1]--;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		sum[i]+=sum[i-1];
		if(sum[i]==m)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int num = 0;
    int max = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I'){
            num ++;
            if(num > max){
                max = num;
            }
        }else{
            num --;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------

string s;
int a[MAX_N*5];

int main() {

  int n, i, j, k;
  ll sum = 0;
  cin >> s;
  n = s.length();

  for(i=0; i<n; ++i) {
    if(s[i]=='<') {
      a[i+1] = a[i]+1;
    }else if(s[i]=='>') {
      j = 0;
      while(s[i+j]=='>'&&i+j<n) {
        ++j;
      }

      if(a[i]<j) {
        a[i] = j;
        a[i+1] = a[i] - 1;
      }else if(a[i]>=j) {
        a[i+1] = j-1;
      }

      for(k = 1; k<j; ++k) {
        a[i+1+k] = a[i+k]-1;
      }
      i += j-1;
    }
  }


  for(i=0; i<n+1; ++i) {
    sum += a[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(c,b/a)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int N = 100100;

int gcd(int a, int b) {
  if(a) return gcd(b % a, a);
  return b;
}

int arr[N];

int main() {
  int n; cin >> n;
  for(int i = 0; i < n + 1; i++) cin >> arr[i];
  sort(arr, arr + n + 1);
  int g = -1;
  for(int i = 1; i <= n; i++) {
    int diff = arr[i] - arr[i - 1];
    if(g == -1) g = diff;
    else g = gcd(g, diff);
  }
  cout << g << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var r = ReadLine().Split().Select(int.Parse).ToArray();
        int N = r[0];
        double D = r[1];
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            var t = ReadLine().Split().Select(double.Parse).ToArray();
            double leng = Sqrt(t[0] * t[0] + t[1] * t[1]);
            if (leng <= D) ans++;
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 41400
s = input().strip()
ans = 0
rep = 0
for c in s:
    if c == 'A' or c == 'C' or c == 'G' or c == 'T':
        rep += 1
    else:
        ans = max(ans, rep)
        rep = 0
ans = max(ans, rep)
print(ans)


Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>

int gcd(int x, int y){
  if(y==0)return x;
  else return gcd(y,x%y);
}

int main(void) {
 int val1, val2; 

scanf("%d %d",&val1, &val2);
int ans;
if (val1>val2){
ans = gcd(val1,val2);
}
else
ans = gcd(val2,val1);
printf("%d\n", ans);
  return 0;
}


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

int main() {
  vector<int> a = {1, 3, 5, 7, 8, 10, 12};
  vector<int> b = {4, 6, 9, 11};
  vector<int> c = {2};
  
  int x, y;
  cin >> x >> y;
  
  int c_a=0, c_b = 0, c_c = 0;
  for (int i:a){
    if(i == x || i==y) c_a++;
  }
  for (int i:b){
    if(i == x || i==y) c_b++;
  }
  for (int i:c){
    if(i == x || i==y) c_c++;
  }
  
  if (max(max(c_a, c_b), c_c) == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,H,W,D,L,R,Q;
  cin >> H >> W >> D;
  int dp[H*W+1],x[H*W+1],y[H*W+1];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> A;
      x[A] = i;
      y[A] = j;
    }
  }
  for (int i = 1; i <= D; i++) {
    dp[i] = 0;
  }
  for (int i = D+1; i <= H*W; i++) {
    dp[i] = dp[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
  }
  for (cin >> Q; Q; Q--) {
    cin >> L >> R;
    cout << dp[R]-dp[L] << endl;
  }
}

Measured memory_bytes: 4700
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define fre freopen("C:\\in.txt", "r", stdin)
#define _for(i,a,b) for(int i=a; i< b; i++)
#define _rep(i,a,b) for(int i=a; i<=b; i++)
#define lowbit(a) ((a)&-(a))
#define inf 0x3f3f3f3f
#define endl "\n"
using namespace std;
typedef long long ll;
template <class T>
void read(T &x)
{
    char c; bool op=0;
    while(c=getchar(), c<'0'||c>'9') if(c=='-') op=1;
    x=c-'0';
    while(c=getchar(), c>='0'&&c<='9') x=x*10+c-'0';
    if(op) x=-x;
}

const int maxn=2e5+5;
int n, u[maxn], v[maxn];

int main()
{
    read(n);
    _rep(i, 1, n-1) read(u[i]), read(v[i]);
    _rep(i, 1, n) if(u[i]>v[i]) swap(u[i], v[i]);
    ll ans=0;
    _rep(i, 1, n) ans+=1ll*i*(n-i+1);
    _rep(i, 1, n) ans-=1ll*u[i]*(n-v[i]+1);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5340
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 2000;
const long long INF = 1000000000LL * N;

int main() {
	int n;
	long long x;
	scanf("%d %lld", &n, &x);
	
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	
	vector<long long> current(n, INF);
	vector<long long> previous(n);
	long long res = INF;
	
	for (int i = 0; i < n; i++) {
		swap(current, previous);
		
		long long now = i * x;
		for (int j = 0; j < n; j++) {
			current[j] = min(a[j], previous[(j - 1 + n) % n]);
			now += current[j];
		}
		
		res = min(now, res);
	}
	
	printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=400000+10;
int head[maxn];
bool vis[maxn];
int num[maxn];
int node[maxn];
int que[maxn];
int nod[maxn];
struct Edge {
	int u,v;
	int next;
} edge[maxn];
int n,m;
int tol;
int cnt;
int ans;
int S,T;
bool flag;
void init() {
	memset(head,-1,sizeof(head));
	memset(node,0,sizeof(node));
	memset(num,0,sizeof(num));
	tol=0;
	cnt=0;
	ans=1;
	flag=true;
}
void add(int u,int v) {
	edge[tol].u=u;
	edge[tol].v=v;
	edge[tol].next=head[u];
	head[u]=tol++;
}
int bfs(int s) {
	int l=0,r=0;
	memset(vis,0,sizeof(vis));
	memset(que,0,sizeof(que));
	que[r++]=s;
	vis[s]=1;
	while(l<=r) {
		s=que[l++];
		for(int i=head[s]; i!=-1; i=edge[i].next) {
			int v=edge[i].v;
			if(vis[v]==0) {
				vis[v]=1;
				que[r++]=v;
			}
		}
	}
	return que[r-1];
}
void dfs(int u) {
	if(!flag)
		return;
	int top=0;
	vis[u]=1;
	for(int i=head[u]; i!=-1; i=edge[i].next) {
		int v=edge[i].v;
		if(vis[v]==0) {
			dfs(v);
			node[u]=max(node[u],node[v]);
			if(node[v]>1) top++;
			if(v!=T&&node[v]==1)
				num[u]++;
		}
	}
	node[u]++;
	if(top>=2) {
		printf("-1\n");
		exit(0);
		flag=false;
		return;
	}
	if(u!=S&&u!=T&&node[u]>=2)
		nod[cnt++]=num[u];
}
void printf_(int u) {
	int t=ans;
	vis[u]=1;
	if(num[u]>0) {
		for(int i=1; i<=num[u]; i++) {
			printf("%d ",++ans);
		}
	}
	printf("%d%c",t,u==T?'\n':' ');
	ans++;
	for(int i=head[u]; i!=-1; i=edge[i].next) {
		int v=edge[i].v;
		if(v==T||v==S||node[v]>1) {
			if(!vis[v])
				printf_(v);
		}
	}
}
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) {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main() {
	while(~scanf("%d",&n)) {
		init();
		m=n-1;
		int u,v;
		for(int i=0; i<m; i++) {
			//scanf("%d %d",&u,&v);
			u=read();
			v=read();
			add(u,v);
			add(v,u);
		}
		T=bfs(1);
		S=bfs(T);
		memset(vis,0,sizeof(vis));
		dfs(S);
		/*cout<<S<<" "<<T<<endl;
		cout<<cnt<<endl;
		for(int i=1; i<=n; i++)
			printf("%d%c",node[i],i==n?'\n':' ');
		for(int i=1; i<=n; i++)
			printf("%d%c",num[i],i==n?'\n':' ');
		for(int i=0; i<cnt; i++)
			printf("%d%c",nod[i],i==cnt-1?'\n':' ');
		*/
		reverse(nod,nod+cnt);
		for(int i=0; i<cnt; i++) {
			if(nod[i]<nod[cnt-i-1])
				break;
			else if(nod[i]>nod[cnt-i-1]) {
				swap(S,T);
				break;
			}
		}
		memset(vis,0,sizeof(vis));
		if(!flag)
			printf("-1\n");
		else
			printf_(S);
	}
}

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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;

  x = abs(x);
  ll ans;

  // 0に向かって移動する際、0 到達回数より k が小さい場合
  // 最小値は k 回 -d 側に移動した座標となる
  if (k < x/d) {
    ans = x - d*k;
  // 0に向かって移動する際、0 到達回数より k が大きい場合
  } else {
    // 0付近到達までの移動回数
    ll e = x/d;
    k = k - e;
    x = x - (d*e);

    // 残り回数が偶数の場合は、ループするので、そのまま
    // 残り回数が奇数の場合は、1回移動する
    if (k % 2 == 1) { x = abs(x-d); }
    ans = x;
  }

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


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define N 400009
#define inf 1000000000
using namespace std;

int n,m,p,q,a[N],h[N],num[N];
bool ok(int lim){
	int i,j,x,sum=0; bool flag1=0,flag2=0;
	memset(num,0,sizeof(num));
	for (i=j=2; i<=m; i++){
		for (; j<=m && a[h[j]]-a[h[i]]<=lim; j++){
			x=h[j];
			if ((x>>1)!=(p>>1) && (x>>1)!=(q>>1)){
				if (!num[x>>1]) sum++; num[x>>1]++;
			}
			if (x==(p^1)) flag1=1;
			if (x==(q^1)) flag2=1;
		}
		if (flag1 && flag2 && sum==n-2) return 1;
		x=h[i];
		if ((x>>1)!=(p>>1) && (x>>1)!=(q>>1)){
			num[x>>1]--; if (!num[x>>1]) sum--;
		}
		if (x==(p^1)) flag1=0;
		if (x==(q^1)) flag2=0;
		
	}
	return 0;
}
bool cmp(int x,int y){ return a[x]<a[y]; }
int main(){
	scanf("%d",&n); m=n<<1|1;
	int i;
	for (i=p=q=2; i<=m; i++){
		scanf("%d",&a[i]);
		if (a[i]<a[p]) p=i; if (a[i]>a[q]) q=i;
	}
	if (p==q){ puts("0"); return 0; }
	int x=-inf,y=inf;
	for (i=1; i<=n; i++) if (i!=(p>>1) && i!=(q>>1)){
		if (a[i<<1]>a[i<<1|1]) swap(a[i<<1],a[i<<1|1]);
		x=max(x,a[i<<1]); y=min(y,a[i<<1|1]);
	}
	if ((p^q)!=1){
		x=max(x,a[q^1]); y=min(y,a[p^1]);
	}
	ll ans=(ll)(x-a[p])*(a[q]-y);
	if ((p^q)!=1){
		for (i=2; i<=m; i++) h[i]=i;
		sort(h+2,h+m+1,cmp);
		int l=0,r=a[q]-a[p],mid;
		while (l<r){
			mid=l+r>>1;
			if (ok(mid)) r=mid; else l=mid+1;
		}
		ans=min(ans,(ll)(a[q]-a[p])*l);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
n, m = map(int, input().split())
a = [[False]*n for i in range(n)]
hen_m = []
for i in range(m):
    x1, x2 = map(int, input().split())
    x1 -= 1
    x2 -= 1
    hen_m.append([x1, x2])
    a[x1][x2] = True
    a[x2][x1] = True
for i in range(n):
    a[i][i] = True

#ワーシャルフロイド
def warshall(n, c):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                c[j][k] = c[j][k] or (c[j][i] and c[i][k])

ans = 0
# Mの辺を消して、わ～シャルフロイド
for i in range(m):
    b = [i[::] for i in a]
    x1 , x2 = hen_m[i]
    b[x1][x2] = False
    b[x2][x1] = False
    warshall(n, b)
    flag = 0
    for j in range(n - 1):
        for k in range(j + 1,n):
            if not b[j][k]:
                flag = 1
                break
        if flag == 1:
            break
    #print(i, flag)
    ans += flag
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int n,m,str[10001],i,sum=0;
    scanf("%d %d",&m,&n);
    for(i=0;i<n;i++){
    scanf("%d",&str[i]);
    sum=sum+str[i];
    }
    if(sum<=m) printf("%d", m-sum);
    else printf("-1");
    
    
    return 0;
}

Measured memory_bytes: 1772
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	string t;
	cin>>t;
	for(auto i:t) {
		if(i!='?') cout<<i;
		else cout<<"D";
	}cout<<"\n";
	return 0;
}


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

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

	long long X;
	scanf("%lld", &X);
	long long m = 100;

	for (int i = 1; true; i++) {
		m = m * 1.01;
		if (m >= X) {
			printf("%d", i);
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

typedef long long LL;

LL a[100];
LL f=-100000000,z=1000000000,wf,wz;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(f<a[i])
        {
            f=a[i];
            wf=i;
        }
        if(z>a[i])
        {
            z=a[i];
            wz=i;
        }
    }
    cout<<n*2-1<<endl;
    LL now;
    if(abs(f)>abs(z))
    {
        for(int i=1;i<=n;i++)
            cout<<wf<<' '<<i<<endl;
        if(f<=0)
        {
            for(int i=n;i>=2;i--)
            cout<<i<<' '<<i-1<<endl;
        }
        else
            for(int i=1;i<n;i++)
            cout<<i<<' '<<i+1<<endl;
    }
    else
    {
        for(int i=1;i<=n;i++)
            cout<<wz<<' '<<i<<endl;
        if(z<=0)
        {
            for(int i=n;i>=2;i--)
            cout<<i<<' '<<i-1<<endl;
        }
        else
            for(int i=1;i<n;i++)
            cout<<i<<' '<<i+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi acos(-1)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
long double dist(double x, double  y,double  xx ,double  yy){
	double ans ;
	ans = ( (x-xx)*(x-xx) + (y-yy)*(y-yy));
	ans = abs(ans);
	ans = sqrt(ans);
	return ans;
}
signed main(){
 	// #ifndef ONLINE_JUDGE
 	// freopen("input.txt","r",stdin);
 	// freopen("out2.txt","w",stdout);
 	// #endif
	SaveTime;
	int T=1;
	// cin >> T;
	dp[1]=1;
	dp[2]=2;
	for(int i =2;i<=10;i++)dp[i]=dp[i-1]*i;
	while(T--){
		int n;
		cin >> n;
		vector<pair<int,int>>v;
		vector<int>yo;
		for(int i =0 ;i < n ;i++){
			yo.pb(i);
			int x , y;
			cin >> x >>y ;
			v.pb({x,y});
		}
		// sort(all(v));
		sort(all(yo));
		double  ans=0;
		do{
			for(int i =1;i < n;i++){
				long double g = dist(v[yo[i]].fi,v[yo[i]].se,v[yo[i-1]].fi,v[yo[i-1]].se);
				// cout << g <<endl;
				ans+=g;
			}
			// cout<<"h\n";
		}while(next_permutation(all(yo)));
		// ans/=2;
		cout<<fixed<<setprecision(7) << ans/dp[n]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int N = 303, INF = 1e9 + 100;

int n, m, l, dp[N][N];
ll d[N][N];

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); 
    fill((int*) d, (int*) d + N * N, INF);
    fill((int*) dp, (int*) dp + N * N, INF);
    for(int i = 0; i < N; ++i) d[i][i] = 0, dp[i][i] = 0;
    cin >> n >> m >> l;
    for(int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        if(c <= l) d[a][b] = d[b][a] = c;
    }

    for(int k = 1; k <= n; ++k) {
        for(int u = 1; u <= n; ++u) {
            for(int v = 1; v <= n; ++v) {
                d[u][v] = min(d[u][k] + d[k][v], d[u][v]);
            }
        }
    }
    for(int u = 2; u <= n; ++u) {
        for(int v = 1; v < u; ++v) {
            if(d[u][v] <= l) {
                dp[u][v] = dp[v][u] = 1;
            }
        }
    }
    
    for(int k = 1; k <= n; ++k) {
        for(int u = 1; u <= n; ++u) {
            for(int v = 1; v <= n; ++v) {
                dp[u][v] = min(dp[u][k] + dp[k][v], dp[u][v]);
            }
        }
    }

    int Q;
    cin >> Q;
    while(Q--) {
        int s, t;
        cin >> s >> t;
        int ans = dp[s][t];
        cout << (ans == INF ? -1 : ans - 1) << '\n';
    }
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const long long MAX=1e18;
const int IMAX=2e9;
long long N, D[61][41][31][2];
int a, b, c, d;

long long solve(int x, int y, int z, int w)
{
	if(D[x][y][z][w]!=-1) return D[x][y][z][w];
	long long v=N, &ret=D[x][y][z][w];
	ret=MAX;
	for(int i=0;i<x;i++) v/=2;
	for(int i=0;i<y;i++) v/=3;
	for(int i=0;i<z;i++) v/=5;
	if(v+w<=IMAX) ret=min(ret,d*(v+w));
	if(v+w==1) return ret;
	for(int i=-4;i<=4;i++) if(v+w+i>0) {
		if((v+w+i)%2==0) {
			if((v+w+i)/2==v/2) ret=min(ret,solve(x+1,y,z,0)+1LL*abs(i)*d+a);
			if((v+w+i)/2==v/2+1) ret=min(ret,solve(x+1,y,z,1)+1LL*abs(i)*d+a);
		}
		if((v+w+i)%3==0) {
			if((v+w+i)/3==v/3) ret=min(ret,solve(x,y+1,z,0)+1LL*abs(i)*d+b);
			if((v+w+i)/3==v/3+1) ret=min(ret,solve(x,y+1,z,1)+1LL*abs(i)*d+b);
		}
		if((v+w+i)%5==0) {
			if((v+w+i)/5==v/5) ret=min(ret,solve(x,y,z+1,0)+1LL*abs(i)*d+c);
			if((v+w+i)/5==v/5+1) ret=min(ret,solve(x,y,z+1,1)+1LL*abs(i)*d+c);
		}
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int T;
	for(cin>>T;T--;) {
		cin>>N>>a>>b>>c>>d;
		memset(D,-1,sizeof(D));
		cout<<solve(0,0,0,0)<<'\n';
	}
	return 0;
}

Measured memory_bytes: 4796
N = int(input())
N0 = N
B = list(map(int,input().split()))
ans = []
i = N-1
while i >= 0:
    if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        N -= 1
        i = N-1
    else:
        i -= 1
if len(ans) == N0:
    for a in reversed(ans):
        print(a)
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

int n;
vector<int> a;
vector<ll> sum;

bool check(const int& c, const int& k){
    int pos = lower_bound(a.begin(), a.end(), c) - a.begin();
    ll res = (ll)c * (n - pos) + sum[pos];
    return res >= (ll)c * k;
}

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

    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        ++a[--x];
    }
    sort(a.begin(), a.end());
    sum.resize(n + 1);
    sum[0] = 0;
    for(int i = 0; i < n; ++i)  sum[i + 1] = sum[i] + a[i];
    
    for(int k = 1; k <= n; ++k){
        int lb = 0, ub = n / k + 1;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            if(check(mid, k))   lb = mid;
            else    ub = mid;
        }
        cout << lb << endl;
    }
}

Measured memory_bytes: 4352
def cal_algae(r, d, x, i):
    if i < 2010:
        x = r * x - d
        print(x)
        cal_algae(r, d, x, i + 1)


algae = list(map(int, input().split()))

r = int(algae[0])
d = int(algae[1])
x = int(algae[2])

i = 2000

cal_algae(r, d, x, i)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)


int main() {
	int a; 
	string s;
	cin >> a >> s;

	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}
}

 

Measured memory_bytes: 256
# https://img.atcoder.jp/abc144/editorial.pdf

def main():
    from math import pi, tan, radians

    a, b, x = map(int, input().split())

    def volume(theta: float):
        """傾けた直方体に存在できる水の体積
        水面を地面に対し平行にした図を描き
        tanを用いると計算できる"""
        theta = radians(theta)
        if a * tan(theta) <= b:  # 台形
            return a * a * b - a * a * a * tan(theta) / 2
        else:  # 三角形
            return a * b * b * tan(pi / 2 - theta) / 2

    def is_ok(theta):
        return volume(theta) >= x

    def binary_search():
        small, large = 0, 90
        for _ in range(30):
            mid = (small + large) / 2
            if is_ok(mid):
                small = mid
            else:
                large = mid
        return small

    ret = binary_search()
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
  if((C - B) % 2 == 0){
    cout << "Alice" << endl;
  }
  
  else{
    cout << "Borys" << endl;
  }
}

Measured memory_bytes: 3628
package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
    n, k := ScanInt64(), ScanInt64()
	s := strconv.FormatInt(n, int(k))
	fmt.Println(len(s))
}

/*********************** I/O ***********************/

var in *bufio.Scanner

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer writer.Flush()
	}()
}

func ScanWord() string {in.Scan(); return in.Text() }
func ScanInt() int {i, _ := strconv.Atoi(ScanWord()); return i}
func ScanInt64() int64 {i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i}


Measured memory_bytes: 640
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,i,j,k,l,m,a[200000];
        cin>>n;
        vi ne,p,v;
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            ans+=abs(a[i]);
            v.pb(a[i]);
            if(a[i]<=0)
                ne.pb(-a[i]);
            else
                p.pb(a[i]);
        }
        sort(all(p));
        sort(all(ne));
        if(ne.size()==0)
        {
            sort(all(p));
            k=p[0];
            cout<<ans-2*k<<endl;
            for(i=1;i<n-1;i++)
            {
                cout<<k<<" "<<p[i]<<endl;
                k=k-p[i];
            }
            cout<<p[n-1]<<" "<<k<<endl;
            return 0;
        }
        if(p.size()==0)
        {
            sort(all(ne));
            k=-ne[0];
            cout<<ans+2*k<<endl;
            for(i=1;i<n;i++)
            {
                cout<<k<<" "<<-ne[i]<<endl;
                k=k+ne[i];
            }
            return 0;
        }
        cout<<ans<<endl;
        k=p[0];
        for(i=0;i<ne.size()-1;i++)
        {
            cout<<k<<" "<<-ne[i]<<endl;
            k=k+ne[i];
        }
        p.pb(k);
        sort(all(p));
        k=-ne[ne.size()-1];
        for(i=1;i<p.size()-1;i++)
        {
            cout<<k<<" "<<p[i]<<endl;
            k=k-p[i];
        }
        cout<<p.back()<<" "<<k;
    }
    return 0;
}

Measured memory_bytes: 4460
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
#    N = int(input())
    H, W = map(int,input().split())
#    S = input()
    G = [input().split() for k in range(H)]
    S = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for k in range(H):
        for l in range(W):
            if G[k][l] == "snuke":
                print(S[l]+str(k+1))
                exit(0)
if __name__ == '__main__':
    main()


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

vector<int>vec[201000];
int n,m,x,y,ans,t;
priority_queue<int>q;

int main(){
  cin.tie(0);
  cin>>n>>m;
  for (int i=n;i--;) cin>>x>>y, vec[x].push_back(y);
  for (int i=m;~i;--i){
    for (auto o:vec[i]) q.push(o);
    if (i&&!q.empty())
      q.pop(), ++t;
  }
  ans=t; y=m;
  for (;!q.empty();){
    x=q.top(); q.pop();
    if (x<=y&&y>t) ++ans, --y;
  }
  cout<<n-ans<<endl;
}


Measured memory_bytes: 8960