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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
const int PrimeMax = 10000100;
int is_prime[PrimeMax];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    is_prime[i] = 1;
  }
  is_prime[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(is_prime[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Eratosthenes(PrimeMax);
  vary(int,v,0,0);
  REP(i,13,10000000){
    if(is_prime[i] && is_prime[i-2] && is_prime[i-6] && is_prime[i-8]){
      v.pb(i);
    }
  }
  ll n;
  while(cin >> n&&n){
    for(int i = v.size()-1; i >= 0;--i){
      if(n >= v[i]){
        cout << v[i]<<endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 42180
#include <iostream>
#include <string>
 
using namespace std;
 
void func149b()
{
    long long a, b, k;
    cin >> a >> b >> k;
    if (k <= a) cout << a - k << ' ' << b << endl;
    else if (k <= a + b) cout << 0 << ' ' << b - (k - a) << endl;
    else cout << 0 << ' ' << 0 << endl;
}
 
int main()
{
  func149b();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)
		swap(a,b);
	if(c>=a&&c<=b)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ps(n);
    for(int i = 0; i < n; i++){
        cin >> ps[i];
        ps[i]--;
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        if(ps[i] == i){
            swap(ps[i], ps[i + 1]);
            ans++;
        }
    }
    if(ps[n - 1] == n - 1){
        ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#define N 100

int bubble(int *, int);

int main(){

  int i, n, a[N], cnt;
  
  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

  cnt=bubble(a, n);

  printf("%d",a[0]);
  for(i=1;i<n;i++)
    printf(" %d",a[i]);
  printf("\n%d\n",cnt);
  return 0;
}
int bubble(int *a, int n){
  int i, j, tmp, cnt=0;

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j]<a[j-1]){
	tmp=a[j-1];
	a[j-1]=a[j];
	a[j]=tmp;
	cnt++;
      }}}
  return cnt;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    rep(i,0,n){
        cin>>a.at(i);
        a.at(i)%=m;
    }
    
    vector<int> r(n+1,0);
    rep(i,0,n) r.at(i+1)=(r.at(i)+a.at(i))%m;
    
    map<int,int> mp;
    rep(i,0,n+1) mp[r.at(i)]++;
    
    ll ans=0;
    for(auto p:mp){
        int x=p.second;
        ans+=(ll)x*(x-1)/2;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3968
/*input
3
1
4
3
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE

#ifdef TEMPLATE
	typedef long long ll;
	typedef long double ld;
	typedef complex<ld> cd;

	typedef pair<int, int> pi;
	typedef pair<ll,ll> pl;
	typedef pair<ld,ld> pd;

	typedef vector<int> vi;
	typedef vector<vi> vii;
	typedef vector<ld> vd;
	typedef vector<ll> vl;
	typedef vector<vl> vll;
	typedef vector<pi> vpi;
	typedef vector<vpi> vpii;
	typedef vector<pl> vpl;
	typedef vector<cd> vcd;
	typedef vector<pd> vpd;
	typedef vector<bool> vb;
	typedef vector<vb> vbb;
	typedef std::string str;
	typedef std::vector<str> vs;

	#define x first
	#define y second
	#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

	const int MOD = 1000000007;
	const ll INF = std::numeric_limits<ll>::max();
	const int MX = 100101;
	const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;

	template<typename T>
	pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
	template<typename T>
	pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
	template<typename T>
	T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
	template<typename T>
	T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

	template<typename T>
	void print(vector<T> vec, string name = ""){
		cout << name;
		for(auto u: vec)
			cout << u << ' ';
		cout << '\n';
	}

#endif

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N;
	cin >> N;
	vi sk(N);
	int did = 0;
	int ant = 0;
	int a;
	for (int i = 0; i < N; ++i)
	{
		cin >> a;
		sk[i] = a;
		if(a >= did){
			ant = did;
			did = a;
		}
		else if(a > ant)
			ant = a;
	}
	for (int i = 0; i < N; ++i)
	{
		if(sk[i] == did)
			printf("%d\n", ant);
		else
			printf("%d\n", did);
	}
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* array bounds
*/
	

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln << "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
struct edge {
	int to,cost;
	edge(int t, int c):to(t),cost(c) {}
};

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int n, W;
	cin >> n >> W;
	int v[n], w[n];
	int dp[2][W+1];
	fill(dp[0], dp[0]+W+1, 0);
	repst(i,1,n) cin >> v[i] >> w[i];
	
	repst(i,1,n) {
		fill(dp[i&1], dp[i&1]+W+1, 0);
		rept(j,W) {
			if (j<w[i]) dp[i&1][j] = dp[~i&1][j];
			else dp[i&1][j] = max(dp[~i&1][j], dp[~i&1][j-w[i]]+v[i]);
		}
	}
	cout << dp[n&1][W] ln;
}

Measured memory_bytes: 3272
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
	char W[201],Wbuf[201];
	int h;
	int n,i,j,k;
	
	while(1)
	{
		scanf("%s\n%d",W,&n);
		if(W[0]=='-') break;
		for(i=0;i<n;i++) 
		{
			scanf("%d",&h);
			for(j=h;W[j]!='\0';j++) Wbuf[j-h]=W[j];
			for(k=0;k<h;k++) Wbuf[j-h+k]=W[k];
			for(j=0;W[j]!='\0';j++) W[j]=Wbuf[j];
		}
		printf("%s\n",W);
	}
  return 0;
}


Measured memory_bytes: 2700
while True:
	a,b=map(int,input().split())
	if a==0 and b==0:
	   break
	for i in range(a):
		if i==0 or i==a-1:
			for n in range(b):
				print('#',end='')
		else:
			print('#',end='')
			for g in range(b-2):
				print('.',end='')
			print('#',end='')
		print()
	print()


Measured memory_bytes: 7004
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut a: Vec<i32> = (0..n + 1)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let mut b: Vec<i32> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let mut ans: i64 = 0;

    for i in 0..n {
        let c = std::cmp::min(a[i], b[i]);
        a[i] -= c;
        b[i] -= c;
        ans += c as i64;
        let c = std::cmp::min(a[i + 1], b[i]);
        a[i + 1] -= c;
        b[i] -= c;
        ans += c as i64;
    }

    println!("{}", ans);
}


Measured memory_bytes: 10232
#include <iostream>
#include <vector>

#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif // INPUT_FROM_FILE
	int m = 0;
	int f = 0;
	int r = 0;
	int mpf = 0;

#if INPUT_FROM_FILE
	while(ifs >> m >> f >> r, (m != -1 || f != -1 || r != -1)){
#else
	while(std::cin >> m >> f >> r, (m != -1 || f != -1 || r != -1)){
#endif // INPUT_FROM_FILE
		if(m < 0 || f < 0){
			std::cout << "F" << std::endl;
			continue;
		}
		mpf = m + f;

		if(mpf >= 80){
			std::cout << "A" << std::endl;
		}
		else if(mpf >= 65){
			std::cout << "B" << std::endl;
		}
		else if(mpf >= 50){
			std::cout << "C" << std::endl;
		}
		else if(mpf >= 30){
			if(r >= 50){
				std::cout << "C" << std::endl;
			}
			else{
				std::cout << "D" << std::endl;
			}
		}
		else{
			std::cout << "F" << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <cstdio>
#include <fstream>

using namespace std;

struct P{double x,y;};

void output(double x,double y)
{
	printf("%.6lf %.6lf\n",x,y);
}

int main(){

//	cut here before submit 
//	freopen ("testcase.sp", "r", stdin );

	string str = "";

	while (getline(cin,str) ){

		while (str.find(',') != string::npos ){
			str = str.replace (str.find(','), 1, " " );
		} // end while
		P a,b,q;
		stringstream ss (str );
		ss >> a.x >> a.y >> b.x >> b.y >> q.x >> q.y;
		
		double x , y , X = a.x-b.x , Y = a.y-b.y;
		if (X == 0 ){
			output(2*a.x-q.x,q.y );
		}else if (Y == 0 ){
			output(q.x,2*a.y-q.y );
		}else{
			x = ( q.y -a.y + (Y/X)*a.x + (X/Y)*q.x ) / ( (X*X+Y*Y)/(X*Y) );
			y = (Y/X)*(x-a.x) + a.y;
			output(2*x-q.x,2*y-q.y );
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int n; cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,n)
    {
        cin>>a[i];
        sum+=a[i];
        if(i>0)a[i]+=a[i-1];
    }
    rep(i,n)
    {
        a[i]=sum-2*a[i];
    }
    ll ans=LONG_LONG_MAX;
    rep(i,n-1)ans=min(ans,abs(a[i]));

    cout<<ans<<endl;

}

Measured memory_bytes: 1792
a,b=map(int,input().split())
c=(b-1000*a)//1000
f=True
for i in range(a+1):
    d=c-9*i
    if d>=0 and d%4==0 and i+d//4<=a:
        print(i,d//4,a-i-d//4)
        f=False
        break
if f:print("-1 -1 -1")


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int a, b;
  while(cin >> a >> b, a | b){
    if(a < b)swap(a, b);
    int cnt = 0;
    while(b){
      a %= b;
      swap(a, b);
      cnt ++;
    }
    cout << a << " " << cnt << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
#define MOD 1000000007

template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

struct MComb {
	vector<mint> fact;
	vector<mint> inversed;
	MComb(int n) { // O(n+log(mod))
		fact = std::vector<mint>(n+1,1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
		inversed = std::vector<mint>(n+1);
		inversed[n] = fact[n] ^ (MOD-2);
		for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
	}
	mint ncr(int n, int r) {
		return (fact[n] * inversed[r] * inversed[n-r]);
	}
	mint npr(int n, int r) {
		return (fact[n] * inversed[n-r]);
	}
	mint nhr(int n, int r) {
		assert(n+r-1 < (int)fact.size());
		return ncr(n+r-1, r);
	}
};

mint ncr(int n, int r) {
	mint res = 1;
	for (int i = n - r + 1; i <= n; i++) res *= i;
	for (int i = 1; i <= r; i++) res /= i;
	return res;
}

int main()
{
	int x, y, n;
	cin >> x >> y;
	if((x + y) % 3){
		cout << 0 << endl;
		return 0;
	}
	n = (x + y) / 3;
	x -= n, y -= n;
	if(x < 0 || y < 0){
		cout << 0 << endl;
		return 0;
	}
	//cerr << x << " " << y << endl;
	cout << ncr(x + y, x) << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>
#include<iomanip>
#include <unordered_map> 
#include <queue>

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

#define MOD 1000000007


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

  unordered_map<string, int> mp;
  mp["SUN"] = 7;
  mp["MON"] = 6;
  mp["TUE"] = 5;
  mp["WED"] = 4;
  mp["THU"] = 3;
  mp["FRI"] = 2;
  mp["SAT"] = 1;

  cout << mp[S];

  //for float, double precision
  //cout << std::fixed << setprecision(15);
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	ll n,k;
	std::cin >> n>>k;
	if(k>(n+1)/2){
		std::cout << -1 << std::endl;
		exit(0);
	}
	if(n%2==0){
		for (ll i = 1; i <=n/2; i++) {
			/* code */
			std::cout << k+2*(i-1)<< " "<<k+2*n-i <<" " << k+2*n+i+n/2-1<< std::endl;
		}
		for (ll i = 1; i <=n/2; i++) {
			/* code */
			std::cout << k+1+2*(i-1)<<" " << k+2*n-i-n/2 <<" " << k+2*n+i-1<< std::endl;
		}
	}else{
		for (ll i = 1; i <=n/2+1; i++) {
			/* code */
			std::cout << k+2*(i-1)<< " "<<k+2*n-i <<" " << k+2*n+i+n/2-1<< std::endl;
		}
		for (ll i = 1; i <=n/2; i++) {
			/* code */
			std::cout << k+1+2*(i-1)<<" " << k+2*n-i-n/2-1 <<" " << k+2*n+i-1<< std::endl;
		}
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<pair<int,int>>> pre(n);
	vector<pair<int,string>> ans;
	for (int i = 0; i < m; i++) {
		pair<int,int> py;
		int p;
		cin >> p >> py.first;
		py.second = i;
		pre[p - 1].push_back(py);
	}
	for (int i = 0; i < n; i++) {
		if (pre[i].empty() == 0) {
			string a = to_string(i + 1);
			while (a.length() < 6)a = "0" + a;
			sort(pre[i].begin(), pre[i].end());
			int k = pre[i].size();
			for (int j = 0; j < k; j++) {
				string b = to_string(j + 1);
				while (b.length() < 6)b = "0" + b;
				ans.push_back(make_pair(pre[i][j].second, a + b));
			}
		}
	}
	
	sort(ans.begin(), ans.end());
	for (int i = 0; i < m; i++)cout << ans[i].second << endl;


	return 0;
}

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

using namespace std;

int main(){
    int h,w;
    cin>>h>>w;

    char c[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>c[i][j];
        }
    }

    for(int i=0; i<2*h;i++){
        for(int j=0; j<w; j++){
            cout<<c[(i/2)][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n,a,b,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n , count = 0;
  scanf("%d",&n);
  
  for(int i = 0;4*i <=n;i ++){
    for(int j = 0;7*j <=n;j ++){
      if(4*i+7*j==n){
        count ++;
      }
    }
  }
  if(count!=0){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

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

using namespace std;

typedef long long int lli;

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

    string s, t;
    cin >> s >> t;
    int slen = s.size(), tlen = t.size();
    vector<vector<int>> table(slen, vector<int>(26, -1));

    // make table
    for (int alp=0; alp<26; alp++) {
        int cont = -1000000000;
        for (int i=0; i<slen; i++) {
            int idx = slen - i - 1;
            if (s[idx]-'a' == alp) {
                cont = 0;
            }
            table[idx][alp] = cont++;
        }

        for (int i=0; i<slen; i++) {
            int idx = slen - i - 1;
            if (cont < 0 || table[idx][alp] > -1) break;
            table[idx][alp] = cont++;
        }
    }

/*
    for (int i=0; i<3; i++) {
        for (int j=0; j<slen; j++) {
            cout << table[j][i] << " ";
        }
        cout << endl;
    }
*/

    // solve
    lli ans = 0;
    int idx = 0;
    for (int i=0; i<tlen; i++) {
        if (table[idx][t[i]-'a'] < 0) {
            cout << -1 << endl;
            return 0;
        }

        ans += (lli)table[idx][t[i]-'a'] + 1LL;
        idx = (idx + table[idx][t[i]-'a'] + 1) % slen;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13776
n = int(input())
a_ls = []
for i in range(n):
    a_ls.append(int(input()))
a_ls.sort()
flg = n % 2 == 1
if flg:
    first = a_ls[:n//2]
    center = a_ls[n//2]
    second = a_ls[n//2 + 1:] + [center]
    best = 0
    for ind in range(n//2):
        best += abs(second[ind] - first[ind]) + abs(second[ind + 1] - first[ind])
    center = a_ls[n // 2]
    first = [center] + a_ls[:n // 2]
    second = a_ls[n // 2 + 1:]
    score = 0
    for ind in range(n // 2):
        score += abs(second[ind] - first[ind]) + abs(second[ind] - first[ind+1])
    if best < score:
        best = score
else:
    first = a_ls[:n // 2]
    second = a_ls[n // 2:]
    best = 0
    for ind, (i, j) in enumerate(zip(first, second)):
        if ind > 0:
            best += abs(j - last_i)
        best += abs(j - i)
        last_i = i
print(best)

Measured memory_bytes: 53848
#include<stdio.h>
int main()
{
	int A, B, m;
	scanf("%d %d %d", &A, &B, &m);
	int i, j;
	int a[100005], b[100005];
	for (i = 0; i < A; i++)
		scanf("%d", &a[i]);
	for (i = 0; i < B; i++)
		scanf("%d", &b[i]);
	int ans;
	j = 0;
	for (i = 0; i < A; i++)
		if (a[j] > a[i])
			j = i;
	ans = a[j];
	j = 0;
	for (i = 0; i < B; i++)
		if (b[j] > b[i])
			j = i;
	ans += b[j];
	int x, y, c;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d %d", &x, &y, &c);
		if (ans > a[x - 1] + b[y - 1] - c)
			ans = a[x - 1] + b[y - 1] - c;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import Text.Printf

readInt = ( readLn :: IO Int )
getInts = map ( read :: String -> Int ) . words <$> getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- getInts
	print $ ( 2 ^ m ) * ( m * 1900 + ( n - m ) * 100 )


Measured memory_bytes: 508
/**

F(i,W) = max( include ith item , exclude ith item )

Here ,
include ith item = F(i-1,W-w[i]) + v[i]
exclude ith item = F(i-1,W)

Base case:

F(i,W<0)     = INT_MIN
F(i<=0,W==0) = 0

**/

/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 1e2+7;
const int nmax2 = 1e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

LL w[nmax];
LL v[nmax];

LL dp[nmax][nmax2];

LL solve(int pos,int W)
{
    if(W<0) return INT_MIN;
    if(W==0) return 0;

    if(pos<0)return INT_MIN;
    if(pos==0 && W>0) return 0;

    LL &ret = dp[pos][W];
    if(ret!=-1) return ret;

    LL inc = solve(pos-1,W-w[pos]) + v[pos];
    LL exc = solve(pos-1,W);

    return ret = max(inc,exc);
}

int main()
{
    optimizeIO();

    int n,W;
    cin>>n>>W;

    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];

    memset(dp,-1,sizeof dp);

    cout<<solve(n,W)<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 83840
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998244353

N, S, *A = map(int, read().split())

U = 3010

f = np.zeros(U+1, np.int64)
f[0] = 1
for a in A:
    ff = 2 * f
    ff[a:] += f[:-a]
    ff %= MOD
    f = ff

print(f[S])

Measured memory_bytes: 27476
l = [1 for i in range(10 ** 6 + 1)]
l[0] = l[1] = 0
for i in range(10 ** 6 + 1):
  if l[i] == 1:
    for j in range(i * 2, 10 ** 6 + 1, i):
      l[j] = 0
while 0 == 0:
  try:
    n = int(input())
    c = 0
    for i in range(n + 1):
      c += l[i]
    print(c)
  except EOFError:
    break



Measured memory_bytes: 13508
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
    long long x;
    cin >> x;
    if((x-1)%11 > 5)
        cout << ((x-1)/11)*2+2;
    else
        cout << ((x-1)/11)*2+1;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j == i:
            continue
        uf.union(AB[j][0], AB[j][1])
    for k in range(N):
        uf.find(k+1)
    if len(set(uf.par)) != 2:
        ans += 1

print(ans)



Measured memory_bytes: 3064
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        teles: [Usize1; n],
    }

    let mut visited = vec![false; n];
    let mut before_pattern = Vec::new();
    let mut enter_pattern = Vec::new();
    let mut next = 0;

    for _ in 0..n {
        if visited[next] {
            break;
        }
        visited[next] = true;
        before_pattern.push(next);
        next = teles[next];
    }
    let mut visited = vec![false; n];
    for _ in 0..n {
        if visited[next] {
            break;
        }
        visited[next] = true;
        enter_pattern.push(next);
        next = teles[next];
    }

    if before_pattern.len() >= k+1 {
        println!("{}", before_pattern[k] + 1);
        return;
    }

    let k = k - before_pattern.len();
    let k = k % enter_pattern.len();
    println!("{}", enter_pattern[k] + 1);

}


Measured memory_bytes: 8108
N = int(input())
A = [-1] + [int(a) for a in input().split()]
B = [-1] + [int(b) for b in input().split()]
C = [-1] + [int(c) for c in input().split()]

satisfaction = 0
for n in range(1, N):
    satisfaction += B[A[n]]
    if A[n+1] == A[n] + 1:
        satisfaction += C[A[n]]
satisfaction += B[A[-1]]
print(satisfaction)

Measured memory_bytes: 3064
N, Q = map(int, input().split())
S = input()
  
ac_sum = [0]*N
for i in range(N):
  if S[max(i-1,0):i+1] == "AC":
    ac_sum[i] = ac_sum[max(i-1,0)] + 1
  else:
    ac_sum[i] = ac_sum[max(i-1,0)]

for _ in range(Q):
  l, r = map(int, input().split())
  print(ac_sum[r-1] - ac_sum[l-1])



Measured memory_bytes: 6140
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;

int tbl[6][6] = {
	{-1, 1, 1, -1, -1, -1},
	{-1, -1, -1, -1, -1, -1},
	{-1, -1, -1, -1, -1, -1},
	{0, 0, -1, -1, -1, 0},
	{2, -1, -1, -1, -1, 2},
	{-1, 1, 1, -1, -1, -1},
};

int cnt[500][500][6];
int dat[500][500][6];
int lft[500][500][6];
int rgt[500][500][6];
vector<string> name;


void tostr(int i, int j, int t, bool space, string &res){
	if(cnt[i][j][t] != 1){ throw 0; }

	int k = dat[i][j][t];
	int x = lft[i][j][t];
	int y = rgt[i][j][t];

	if(t == 0){
		tostr(i, k, x, false, res);
		if(space){ res += ' '; }
		res += '(';
		tostr(k, j, y, false, res);
		res += ')';
	}
	else if(t == 1 || t == 2){
		tostr(i, k, x, space, res);
		tostr(k, j, y, true, res);
	}
	else if(t == 5){
		if(space){ res += ' '; }
		res += name[k];
	}
}


string solve(const string &s){
	memset(cnt, 0, sizeof cnt);
	name.clear();

	int n = 0;
	char buf[32] = {};
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'l'){
			cnt[n][n+1][3] = 1;
			++n;
		}
		else if(s[i] == 'n'){
			cnt[n][n+1][4] = 1;
			++n;
		}
		else if(isupper(s[i])){
			sscanf(s.c_str() + i, "%[A-Z]", buf);
			cnt[n][n+1][5] = 1;
			dat[n][n+1][5] = name.size();
			name.push_back(buf);
			i += name.back().size() - 1;
			++n;
		}
	}

	for(int len = 2; len <= n; ++len){
		for(int i = 0; i + len <= n; ++i){
			int j = i + len;
			for(int k = i; k < i + len; ++k){
				for(int x = 0; x < 6; ++x){
					if(cnt[i][k][x] == 0){ continue; }
					for(int y = 0; y < 6; ++y){
						int t = tbl[x][y];
						if(cnt[k][j][y] == 0 || t == -1){ continue; }
						if(++cnt[i][j][t] == 1){
							dat[i][j][t] = k;
							lft[i][j][t] = x;
							rgt[i][j][t] = y;
						}
					}
				}
			}
		}
	}

	if(cnt[0][n][0] == 1){
		try{
			string ans;
			tostr(0, n, 0, false, ans);
			return ans;
		}catch(...){}
	}

	return "AMBIGUOUS";
}


int main(){
	name.reserve(500);

	int n;
	cin >> n;
	cin.get();
	string s;
	for(int i = 0; i < n; ++i){
		getline(cin, s);
		cout << solve(s) << '\n';
	}
}

Measured memory_bytes: 24416
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  double p[3010];
  for (int i = 1; i <= N; i++) cin >> p[i];

  double dp[3010][3010];
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= N; j++) dp[i][j] = 0.0;
  }

  dp[0][0] = 1.0;

  for (int i = 0; i <= N - 1; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] += dp[i][j] * p[i + 1];
      dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]);
    }
  }
  double res = 0;
  for (int i = N / 2 + 1; i <= N; i++) res += dp[N][i];
  cout << fixed << setprecision(15) << res << endl;
  return 0;
}

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

int main() {
    string s; cin >> s;
    vector<string> v;
    string t;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        t += s[i];
        if (v.size() == 0 || v[v.size() - 1] != t) {
            v.push_back(t);
            t = "";
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
    int N;string S;
    cin>>N>>S;
    long long r =0,g=0,b=0;
    for(auto c:S){
        if (c=='R') r++;
        else if(c=='G') g++;
        else b++;
    }
    long long all= r*g*b;
    long long sub = 0;
    for(int i=0;i<N;i++){
        for (int j =i+1;j<N;j++){
            if(S[i]==S[j]) continue;
            int k = j*2-i;
            if (k>=N or S[k]==S[i] or S[k]==S[j]) continue;
            ++ sub;
        }
    }
    cout<<(all-sub)<<endl;

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 100001;

map<string,int> ans, ways;
int N;

int ad(int a, int b) { return (a+b)%MOD; }
int mul(int a, int b) { return (ll)a*b%MOD; }

string getAnd(string a, string b) {
    if (sz(a) == 0) return b;
    F0R(i,sz(b)) if (b[i] == '0') a[i] = '0';
    return a;
}

int getAns(string s);

int getWays(string s) {
    if (ways.count(s)) return ways[s];
    if (sz(s) == 1) {
        // cout << s << " " << 1 << "\n";
        if (s == "0") return ways[s] = 1;
        return ways[s] = 2;
    }
    
    int z = 0;
    FOR(i,2,sz(s)+1) if (sz(s) % i == 0) {
        string t;
        for (int j = 0; j < sz(s); j += sz(s)/i) t = getAnd(t,s.substr(j,sz(s)/i));
        // cout << s << " " << i << " " << t << "\n";
        z = ad(z,getAns(t));
    }
    
    // cout << s << " " << z << "\n";
    return ways[s] = z;
}

int getAns(string s) {
    //cout << "OH " << s << "\n";
    if (ans.count(s)) return ans[s];
    if (s == "") return ans[s] = 1;
    int z = 0;
    FOR(i,1,sz(s)+1) {
        //cout << "TT " << s << " " << s.substr(0,i) << "\n";
        z = ad(z,mul(getWays(s.substr(0,i)),getAns(s.substr(i,sz(s)-i))));
    }
    return ans[s] = z;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // string s; F0R(i,100) s += char('0'+(rand()&1)); cout << s; 
    string s; cin >> s; 
    cout << getAns(s);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 12928
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int left = 0;
        int right = 0;
        int[] a = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = 0; i < m; i++) {
            if (x < a[i])
                right++;
            else
                left++;
        }
        System.out.println(Math.min(right, left));
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

#define maxN 310
#define maxM 310

int N, M;
int L[maxM], R[maxM], X[maxM];
bool forbid[maxN][maxN][maxN];
int dp[maxN][maxN][maxN];
const int mod = (int) 1e9 + 7; 

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> L[i] >> R[i] >> X[i];
	}
	
	for(int k=0;k<M;k++){
		int r = R[k];
		int l = L[k];
		int x = X[k];
		for(int i=0;i<r;i++){
			for(int j=0;j<r;j++){
				int cnt = 1;
				if(l <= i) cnt++;
				if(l <= j) cnt++;
				if(cnt != x){
					forbid[r][i][j] = true;
					forbid[r][j][i] = true;
					forbid[i][r][j] = true;
					forbid[i][j][r] = true;
					forbid[j][i][r] = true;
					forbid[j][r][i] = true;
				}
			}
		}
	}
	
	dp[0][0][0] = 1;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=N;k++){
				
				if(forbid[i][j][k]) dp[i][j][k] = 0;
				int nxt = 1 + max(max(i, j), k);
				if(nxt > N) continue;
				dp[nxt][j][k] += dp[i][j][k]; if(dp[nxt][j][k] >= mod) dp[nxt][j][k] -= mod;
				dp[i][nxt][k] += dp[i][j][k]; if(dp[i][nxt][k] >= mod) dp[i][nxt][k] -= mod;
				dp[i][j][nxt] += dp[i][j][k]; if(dp[i][j][nxt] >= mod) dp[i][j][nxt] -= mod;
			}
		}
	}
	
	int tot = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			tot += dp[i][j][N]; if(tot >= mod) tot -= mod;
			tot += dp[i][N][j]; if(tot >= mod) tot -= mod;
			tot += dp[N][i][j]; if(tot >= mod) tot -= mod;
		}
	}
	cout << tot << endl;


	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


signed main(){
    ll H;
    cin >> H;
    ll sum = 0, num = 1;
    while(H > 0){
        sum += num;
        H /= 2;
        num *= 2;
    }
    PRINT(sum);
    return 0;

}

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

int main(){
    
int n;
cin >> n;
if(n%2==0){
    cout << 0.50 << endl;
}
else{
    printf("%.10f",double(double((n/2+1))/double(n)));
}
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

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

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

ll pow(ll b, ll e) {
    ll res = 1;
    while (e) {
        if (e&1) res *= b;
        b *= b;
        b %= MOD;
        res %= MOD;
        e >>= 1;
    }
    return res;
}

vector<ll> fact(2000010,0), factinv(2000010,0);
void init(void) {
    fact[0] = 1, fact[1] = 1;
    for (int i=2;i<=2000000;i++) fact[i] = fact[i-1]*i % MOD;
    factinv[0] = 1, factinv[1] = 1;
    for (int i=2;i<=2000000;i++) factinv[i] = pow(fact[i],MOD-2);
}

int main(void) {
    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    init();
    ll res = 0;
    ll tot = fact[r1+c1] * factinv[r1] % MOD * factinv[c1] % MOD;
    ll fl = (r1==r2)?-1:1, fr = (c1==c2)?-1:1;
    ll l = fact[r1+c1] * factinv[r1+1] % MOD * factinv[c1-1] % MOD;
    if (fl<0) l = tot;
    ll r = fact[r1+c1] * factinv[r1-1] % MOD * factinv[c1+1] % MOD;
    if (fr<0) r = tot;
    res = (res + tot) % MOD;
    // printf("%5lld %5lld %5lld %5lld %5lld\n",tot,l,r,fl,fr);
    for (int i=r1+c1+1;i<=r2+c2;i++) {
        tot = (tot*2 + fl*l + fr*r) % MOD;
        if (i-c1 == r2) fl = -fl;
        if (i-r1 == c2) fr = -fr;
        if (fl>0) l = fact[i] * factinv[i-c1+1] % MOD * factinv[c1-1] % MOD;
        else l = fact[i] * factinv[r2] % MOD * factinv[i-r2] % MOD;
        if (fr>0) r = fact[i] * factinv[r1-1] % MOD * factinv[i-r1+1] % MOD;
        else r = fact[i] * factinv[i-c2] % MOD * factinv[c2] % MOD;
        res = (res + tot) % MOD;
        // printf("%5lld %5lld %5lld %5lld %5lld\n",tot,l,r,fl,fr);
    }
    cout << (res+MOD)%MOD << endl;

    return 0;
}


Measured memory_bytes: 31488
import java.util.Arrays;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        double[] v = new double[N];

        for (int i = 0 ; i < N ; i++) {
            v[i] = scanner.nextDouble();
        }

        Arrays.sort(v);

        for (int i = 0 ; i < N - 1 ; i++) {
            v[i + 1] = (v[i] + v[i + 1]) / 2.0;
        }

        System.out.println(v[N - 1]);
    }
}


Measured memory_bytes: 37488
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

x = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int main()
{
	fast
	ll N, K;
	cin>>N>>K;
	ll arr[K];
	for(ll i=0; i<K; i++)
	{
		cin>>arr[i];
	}
	if(K==2)
	{
		cout<<min(abs(arr[0]-arr[1]),N-abs(arr[0]-arr[1]));
		return 0;
	}
	sort(arr,arr+K);
	ll min=INT_MAX;
	for(ll i=0; i<K-1; i++)
	{
		if(N-(arr[i+1]-arr[i])<min)
		{
			min=N-(arr[i+1]-arr[i]);
		}
	}
	//cout<<min<<endl<<(N-abs(N-arr[K-1]-arr[0]))<<endl;
	if(arr[K-1]>(N/2))
	{
		if(arr[0]<=(N/2))
		{
			if(N-abs(N-arr[K-1]+arr[0])<min)
				min=N-abs(N-arr[K-1]+arr[0]);
		}
		else
		{
			if(N-abs(arr[K-1]-arr[0])<min)
				min=N-abs(arr[K-1]-arr[0]);	
		}
	}
	else if(N-(arr[K-1]-arr[0])<min)
	{
		min=N-(arr[K-1]-arr[0]);
	}
	cout<<min<<endl;
}

Measured memory_bytes: 1792
import Data.Char
import Control.Monad

parseInputLine :: String -> String -> [Int]
parseInputLine val [] = [read val]
parseInputLine val (' ':xs) = [read val] ++ parseInputLine "" xs
parseInputLine val (x:xs) = parseInputLine (val ++ [x]) xs

solve :: String -> [[Int]] -> Int
solve str []
  | length str >= 2 && c == '0' = read ('1':drop 1 str)
  | read str == 0 = 0
  | otherwise = read str
  where c = head str
solve str (sc:scs)
  | length str >= 2 && s == 0 && c == 0 = -1
  | r `elem` ['0', chr (ord '0' + c)] = solve new_str scs
  | otherwise = -1
  where s = sc!!0 - 1
        c = sc!!1
        r = str!!s
        new_str = (take s str) ++ (show c) ++ (drop (s+1) str)

main :: IO ()
main = do
  inNM <- getLine
  let nm = parseInputLine "" inNM
      n = nm!!0
      m = nm!!1
  inScs <- replicateM m getLine
  let scs = map (parseInputLine "") inScs
      initStr = take n (repeat '0')
      output = solve initStr scs

  putStrLn (show output)


Measured memory_bytes: 508
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
state = [[int(a) for a in list(input().rstrip())] for _ in range(N)]
Query = [list(map(int, input().split())) for _ in range(Q)]
updown = [[0]*(M+1) for _ in range(N)]
for h in range(N-1):
    st = 0
    for w in range(M):
        if state[h][w] and state[h+1][w]:
            st += 1
        updown[h+1][w+1] = st

rileft = [[0]*M for _ in range(N+1)]
for w in range(M-1):
    st = 0
    for h in range(N):
        if state[h][w] and state[h][w+1]:
            st += 1
        rileft[h+1][w+1] = st

dp = [[0]*(M+1) for _ in range(N+1)]
for h in range(N):
    have = False
    connected = 0
    for w in range(M):
        if state[h][w]:
            if not have:
                connected += 1
                have = True
        else:
            if have:
                have = False
        dp[h+1][w+1] = dp[h][w+1] + connected - updown[h][w+1]

for n1, m1, n2, m2 in Query:
    midcon = dp[n2][m2] - dp[n1-1][m2] + updown[n1-1][m2]
    lecon = dp[n2][m1-1] - dp[n1-1][m1-1] + updown[n1-1][m1-1]
    ans = midcon - lecon + (rileft[n2][m1-1] - rileft[n1-1][m1-1])
    print(ans)

Measured memory_bytes: 195788
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, k;
	scanf("%d%d", &n, &k);
	int ans=0;
	while(n>0){
		n/=k;
		ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
s = input()
t = input()
chancenum = []

for i in range(0,len(s) - len(t)+1):
    if s[i] == t[0] or s[i] == "?":
        n = 1
        while n < len(t) and (s[i+n] == t[n] or s[i+n] == "?"):
            n += 1
        if n == len(t):
            chancenum.append(i)

if chancenum == []:
    print("UNRESTORABLE")
else:
    tright = max(chancenum)
    for i in range(0,len(t)):
        s = s[:tright] + t + s[tright+len(t):]
    print(s.replace('?', 'a'))

Measured memory_bytes: 3188
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val A = readLine().split(" ").map(_.toInt)

  def solve(): String = {
    A.foldLeft(Map.empty[Int, Int]) { (acc, num) =>
      acc.get(num) match {
        case Some(_) => return "NO"
        case None => acc.updated(num, 1)
      }
    }
    "YES"
  }

  println(solve())

}



Measured memory_bytes: 80464
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010,P=1e9+7;
int n,ans,x[MAXN],inv[MAXN];
int qpow (int a,int b) {
	int res=1;
	while (b) {
		if (b&1) {res=(1ll*res*a)%P;}
		a=(1ll*a*a)%P,b>>=1;
	}
	return res;
}
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {scanf("%d",&x[i]);}
	for (int i=1;i<=n;i++) {inv[i]=qpow(i,P-2);}
	for (int i=1;i<=n-1;i++) {ans=(ans+(1ll*(x[n]-x[i])*inv[n-i])%P)%P;}
	int tmp=0;
	for (int i=2;i<=n-1;i++) {
		tmp=(tmp+(1ll*inv[i]*inv[i-1])%P)%P;
		ans=(ans+(1ll*x[i]*tmp)%P)%P;
	}
	tmp=0;
	for (int i=n-2;i>=1;i--) {
		tmp=(tmp+(1ll*inv[n-1-i]*inv[n-1-i+1])%P)%P;
		ans=(ans-(1ll*x[i]*tmp)%P+P)%P;
	}
	for (int i=1;i<=n-1;i++) {ans=(1ll*ans*i)%P;}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{   
    vector<string> s;
    int ans=0;
    int H,W,K;
    cin >> H >> W >> K;
    s.resize(H);
    for(int i=0;i<H;i++){
        cin >> s.at(i);
    }
    for(int line_bit=0;line_bit<(1<<H);line_bit++){
        for(int row_bit=0;row_bit<(1<<W);row_bit++){
            int count=0;
            for(int l=0;l<H;l++){
                for(int r=0;r<W;r++){
                    if((line_bit&1<<l)&&(row_bit&1<<r)&&(s[l][r]=='#')){
                        count++;
                    }
                }
            }
            if(count==K){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(b <= c || d <= a){
    cout << "0" << endl;
  }
  else{
    cout << (min(b, d) - max(a, c)) << endl;
  }

  return 0;
}

Measured memory_bytes: 256