akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    ll index;
    rep(i,n){
        if (a[i] == 1) index = i;
    }
    ll m = n-1;
    PRINT((m%(k-1) ? m/(k-1)+1 : m/(k-1)));
}



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

#define int long long
#define vc vector<char>
#define vi vector<int>
#define vs vector<string>
#define si set<int>
#define pii pair<int,int>
#define SORT(c) sort(c.begin(),c.end())
#define SORTC(c, cmp) sort(c.begin(),c.end(),cmp)
#define mapii map<int,int>
#define pb push_back
#define F first
#define S second
#define rep(i, j, k) for (int i=j;i<k;i++)
#define repb(i, j, k) for (int i=j;i>=k;i--)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ar array

using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0)


void solve() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a;
}


int32_t main() {
    fast;

    int tt{1};
//    cin >> tt;
    while (tt--) {
        solve();
        cout << endl;
    }
    return 0;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t,f,ans;
double a[200001];
map<pair<int,int>,int> m;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		int b=round(a[i]*1000000000);
		t=f=-9;
		while(b%2==0)
		{
			b/=2;
			t++;
		}
		while(b%5==0)
		{
			b/=5;
			f++;
		}
		m[make_pair(t,f)]++;
	}
	for(auto i:m)
		for(auto l:m)
			if(i.first.first+l.first.first>=0&&i.first.second+l.first.second>=0)
			{
				if(i==l)
					ans+=i.second*(i.second-1)/2;
				if(i<l)
					ans+=i.second*l.second;
			}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5332
// I read the submission #8087563.
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int min(int X, int Y) {
    return X < Y ? X : Y;
}

int main() {
    int n, m, l; cin >> n >> m >> l;
    int d[n][n];
    REP(0, i, n) {
        REP(0, j, n) {
            d[i][j] = 1000000007;
        }
        d[i][i] = 0;
    }
    int a[m], b[m], c[m];
    REP(0, i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
        d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
    }
    REP(0, k, n) {
        REP(0, i, n) {
            REP(0, j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    REP(0, i, n) {
        REP(0, j, n) {
            if (d[i][j] == 0) d[i][j] = 0;
            else if (d[i][j] <= l) d[i][j] = 1;
            else d[i][j] = 1000000007;
        }
    }
    REP(0, k, n) {
        REP(0, i, n) {
            REP(0, j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int q; cin >> q;
    REP(0, i, q) {
        int s, t; cin >> s >> t; s--; t--;
        if (d[s][t] == 1000000007) cout << "-1" << endl;
        else cout << d[s][t] - 1 << endl;
    }
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int tb = 0;
	int xb = 0;
	int yb = 0;
	int t, x, y;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		if (abs(x - xb) + abs(y - yb) > t-tb || (t - tb - abs(x - xb) - abs(y - yb)) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
		tb = t;
		xb = x;
		yb = y;
	}
	cout << "Yes" << endl;
}

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

int main(void){
    int n,k;
    int p[1001];
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>p[i];
    }
    int ans=0;
    sort(p,p+n);
    for(int i=0;i<k;i++){
        ans+=p[i];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#define MAX 101

int main(){
	int n, u, k, v, A[MAX][MAX] = {};
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>u>>k;
		for(int j = 0; j < k; j++){
			cin>>v;
			A[u][v] = 1;
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout<<(j==1?"":" ")<<A[i][j];
		}cout<<endl;
	}
	return 0;
}


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

// --------------------------------------------------------------------------------
#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define fset(arr,n,val) for(int i=0;i<n;++i) arr[i] = val
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b) for(int i=a;i<=b;i++)
#define frepj(a,b) for(int j=a;j<=b;j++)
// --------------------------------------------------------------------------------

void solve_main()
{
    int a;cin>>a;
    cout<<a*a + a*a*a + a;
}

int main()
{

	// #ifndef ONLINE_JUDGE
	//	freopen("/home/suryakant/input.txt","r",stdin);
	//	freopen("/home/suryakant/output.txt","w",stdout);
	// #endif

    int t=1;
    // cin>>t;
    while(t--)
    {
    	solve_main();
    }
    //for(int caset=1;caset<=t;++caset)
    //{
    //    solve_main();
    //}
    
}

Measured memory_bytes: 3556
a = int(input())
b = input().split()
b[0] = int(b[0])
b[1] = int(b[1])
A = b[0] / a
B = b[1] / a
C = B - A
if a == 1:
    print('OK')
elif b[1]%a == 0:
    print('OK')
elif b[0]%a == 0:
    print('OK')
elif C >= 1:
    print('OK')
elif (b[1]//a)*a >= b[0]:
    print('OK')
else:
    print('NG')

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int32 cur = n;
    vector<int32> ans;
    while(cur > 0){
        FORR(i,m,0){
            if(i == 0){
                cout << -1 << endl;
                return 0;
            }
            if(cur - i < 0)continue;
            if(s[cur - i] == '0'){
                ans.pb(i);
                cur -= i;
                break;
            }
        }
    }
    reverse(ALL(ans));
    REP(i,ans.size())cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1480
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {
	ll n;
	cin >> n;

	ll ans = 0;
	// 次の値で割り続ける
	Rep(i, 1, n) {
		ans += i;
	}

	cout << ans << endl;

	return 0;
}

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


int main(){
    string s;
    cin >> s;
    vector<int> chars(26, 0);
    for(int i = 0; i < int(s.size()); i++){
        chars[s[i] - 'a']++;
    }
    for(int i = 0; i < 26; i++){
        if(chars[i] == 0){
            cout << char('a' + i) << endl;
            return 0;
        }
    }
    cout << "None\n";
}



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

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

template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll g = 0;
    for (ll x : A) g = gcd(g, x);
    ll mx = *max_element(A.begin(), A.end());
    bool res = K % g == 0 && K <= mx;
    cout << (res ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long double LD;
#define N 600 + 5

int n, m, Go[N][N];
LD ans, PreP[N], Pre[N], Suf[N];

void DP()
{
	PreP[1] = 1, Pre[1] = 0;
	for (int i = 1; i < n; i ++)
	{
		LD tp = PreP[i] / Go[i][0], tpl = (Pre[i] + PreP[i]) / Go[i][0];
		for (int j = 1; j <= Go[i][0]; j ++)
		{
			int d = Go[i][j];
			PreP[d] += tp;
			Pre[d] += tpl;
		}
	}
	Suf[n] = 0;
	for (int i = n - 1; i; i --)
	{
		for (int j = 1; j <= Go[i][0]; j ++)
			Suf[i] += Suf[Go[i][j]] + 1;
		Suf[i] /= Go[i][0];
	}
	ans = Suf[1];
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1, u, v; i <= m; i ++)
	{
		scanf("%d%d", &u, &v);
		Go[u][++ Go[u][0]] = v;
	}
	DP();
	for (int i = 1; i <= n; i ++)
		if (Go[i][0] > 1)
		{
			LD retpl = Pre[n] - PreP[i] * Suf[i];
			for (int j = 1; j <= Go[i][0]; j ++)
			{
				LD npl = retpl + PreP[i] * (Suf[i] * Go[i][0] - (Suf[Go[i][j]] + 1)) / (Go[i][0] - 1);
				ans = min(ans, npl);
			}
		}
	printf("%.9Lf\n", ans);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
char ans[10];
int c=0;
string a;
int i=0;
int main(){
  cin >> a;
  for(int i=0;i<a.size();i++){
  //cin >> a[i];
  //while(a[i]=='0'|| a[i]=='1' || a[i]=='B'){
  if(a[i]=='0'|| a[i]=='1'){
    ans[c]=a[i];
    c++;
  }
    if(i>0 && c>0){
      if(a[i]=='B'){
        c=c-1;
      }
    }
  //  c++;
  }
  for(int k=0;k<c;k++){
    cout << ans[k];
  }
  cout << endl;
  //cout <<a.size();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	long long a,b,ans,bns;
	char c;
	cin>>a>>c>>b;
	if(c=='+')
	{
		ans=a+b;
	    cout<<ans<<endl;
	}
	else
	{
		bns=a-b;
		cout<<bns<<endl;
	}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int dy[4] = {-1,0,0,1};
int dx[4] = {0,-1,1,0};
int w,h;
int a[21][21];
pii s,g;

bool contain(int y, int x) {
  return IN(y,0,h-1) && IN(x,0,w-1);
}

int dfs(int y, int x, int lev) {
  if (lev > 10) return INF;
  int res = INF;
  for (int i = 0; i < 4; i++) {
    int cy = y, cx = x;
    if (a[cy+dy[i]][cx+dx[i]] == 1) continue;
    while (contain(cy+dy[i],cx+dx[i]) && a[cy+dy[i]][cx+dx[i]] == 0) {
      cy += dy[i];
      cx += dx[i];
    }
    if (!contain(cy+dy[i],cx+dx[i])) continue;
    if (a[cy+dy[i]][cx+dx[i]] == 1) {
      a[cy+dy[i]][cx+dx[i]] = 0;
      CHMIN(res,dfs(cy,cx,lev+1));
      a[cy+dy[i]][cx+dx[i]] = 1;
    } else {
      return lev;
    }
  }
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> w >> h, w) {
    REP(i,h) REP(j,w) {
      cin >> a[i][j];
      if (a[i][j] == 2) s = pii(i,j), a[i][j] = 0;
      if (a[i][j] == 3) g = pii(i,j);
    }
    int ans = dfs(s.first,s.second,1);
    cout << (ans == INF ? -1 : ans) << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define maxn 30
#define u32d unsigned int
#define LL   long long
#define INF  0x7FFFFFFF
using namespace std;

bool vis[26]; 
int main(){
	string s;
	cin >> s;
	LL a = 0;
	memset(vis, 0, sizeof vis);
	for(int i = 0; i < 4; ++i){
		if(1 & (a >> (s[i] - 'A'))){
			if(vis[s[i] - 'A']){
				continue;
			}
			vis[s[i] - 'A'] = 1;
			a = a - (1 << (s[i] - 'A'));
		}
		else{
			a = a + (1 << (s[i] - 'A')); 
		}
	}
	if(a){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
} 

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

using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)

#define MAX_W 10000

int sw;
int dp[MAX_W + 1];

vector<std::string> split(const string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}

inline bool isRange(const int i)
{
    return 0 <= i && i <= sw;
}

int main()
{
    string nw;
    getline(cin, nw);
    auto nws = split(nw, ' ');
    int n = stoi(nws[0]);
    sw = stoi(nws[1]);

    vector<int> v(n), w(n);
    REP(i, n)
    {
        string vw;
        getline(cin, vw);
        auto vws = split(vw, ' ');
        v[i] = stoi(vws[0]);
        w[i] = stoi(vws[1]);
    }

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    int ans = INT_MIN;
    REP(i, n)
    {
        RREP(j, sw + 1)
        {
            if (dp[j] >= 0 && isRange(w[i] + j))
            {
                dp[w[i] + j] = max(dp[j] + v[i], dp[w[i] + j]);
                ans = max(dp[w[i] + j], ans);
            }
        }
    }

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

    return 0;
}



Measured memory_bytes: 3388
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::collections::VecDeque;

fn main() {
    let k = get!(u64);
    let mut q = VecDeque::<u64>::from(vec!(1, 2, 3, 4, 5, 6, 7, 8, 9));

    let mut x = 0;
    for _ in 1..k+1 {
        x = q.pop_front().unwrap();
        let m = x % 10;
        if m != 0 {
            q.push_back(10 * x + m - 1);
        }
        q.push_back(10 * x + m);
        if m != 9 {
            q.push_back(10 * x + m + 1);
        }
    }
    println!("{}", x);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;
 
const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
 
ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}
 
ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}
 
ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}
 
ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}
 
ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}
 
int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}
 
int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}
 
/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/
 
const int N = 100+5;
const int W = 100000+5;
const ll inf = 1LL<<60;
 
int n;
int C;
int w[N];
int v[N];
ll memo[N][W];
 
int main(){
	ri2(n,C);
	for(int i=1; i<=n; i++){
		ri2(w[i],v[i]);
	}
	// Inicializar en -inf 
	// excepto el peso 0, que
	// trivialmente cumple con ser 0
	// el valor maximo que puede dar
	for(int i=0; i<=C; i++) memo[0][i] = -inf;
	memo[0][0] = 0;
	for(int i=1; i<=n; i++){
		for(int c = 0; c <= C; c++){
			memo[i][c] = memo[i-1][c];
			if(c >= w[i]){
				memo[i][c] = max(memo[i][c],memo[i-1][c-w[i]]+v[i]);
			}
		}
	}
	ll ans = 0;
	for(int i=0; i<=C; i++){
		ans = max(ans,memo[n][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 82548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, x;
  cin >> n >> x;
  vi m(n);
  rep(i,n){
    cin >> m[i];
    x -= m[i];
  }
  sort(all(m));
  ll count = n;
  while(x-m[0]>=0){
    x -= m[0];
    count++;
  }
  print(count);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;

int main() {
	cin >> s;
	rep(i, 26) {
		rep(j, s.size()) {
			if (s[j] == 'a' + i)break;
			if (j == s.size() - 1) {
				cout << (char)('a' + i) << endl;
				return 0;
			}
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
from collections import Counter

N,A = map(int,input().split())
X = list(map(int, input().split()))

X = [X[i] - A for i in range(N)]

sums = Counter([0, X[0]])

for x in X[1:]:
    c = Counter()
    for k,v in sums.items():
        c[x+k] = v
    sums += c
    
print(sums[0]-1)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=50+5, mod=1e9+7;
ll n,k;
struct mat {
    ll val[maxn][maxn];
    mat(){ memset(val, 0, sizeof(val)); }
    ll* operator[] (ll i) {return val[i];}
} ady;
void mat_mul(mat &a, mat &b) {
    mat c;
    rep(i,0,n)
        rep(j,0,n)
            rep(k,0,n)
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
    memcpy(&a,&c,sizeof a);
}
void mat_exp(mat &a, ll x) {
    mat b; rep(i,0,n) b[i][i]=1;
    for(;x;x/=2,mat_mul(a,a)) if(x&1) mat_mul(b,a);
    memcpy(&a,&b,sizeof a);
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    rep(i,0,n) rep(j,0,n) cin>>ady[i][j];
    mat_exp(ady, k);
    ll ans=0; rep(i,0,n) rep(j,0,n) ans=(ans+ady[i][j])%mod;
    cout<<ans<<"\n";
}


Measured memory_bytes: 384
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    ans = [0]*N
    for a in A:
        ans[a-1]+=1
    print(*ans,sep="\n")
if __name__ == '__main__':
    main()

Measured memory_bytes: 102032
#include <stdio.h>

using namespace std;

int main()
{
	const static int INVALID = -1;
	int front = 0, back = 0;
	int *allocate_array;

	int n, size = 1000020;
	scanf("%d", &n);
	if (n < 1000020) size = n;

	allocate_array = new int[size];
	char command[12];
	int x;

	for (int i = 0; i < n; i++) {
		scanf("%s", command);
		if (command[0] == 'i') { // insert x
			scanf("%d", &x);
			allocate_array[front] = x;
			front++;
			size++;
		}
		else { // delete???
			switch (command[6]) {
			case '\0': // delete x
				scanf("%d", &x);
				for (int i = front - 1; i >= back; i--) {
					if (allocate_array[i] == x) {
						allocate_array[i] = INVALID;
						if (i == front - 1)
							front--;
						if (i == back)
							back++;
						break;
					}
				}
				break;
			case 'F': // deleteFirst
				if (size > 0) {
					front--;
					size--;
				}
				break;
			case 'L': // deleteLast
				if (size > 0) {
					back++;
					size--;
				}
				break;
			}
		}
	}
	int i = front - 1;
	while (i >= back && allocate_array[i] == INVALID) i--;
	printf("%d", allocate_array[i]);
	i--;
	for (; i >= back; i--) {
		if (allocate_array[i] != INVALID)
			printf(" %d", allocate_array[i]);
	}
	putchar('\n');

	delete[] allocate_array;
	return 0;
}

Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string s1;
	cin>>s1;
	int count=0,f1=1;
	if(s1=="SUN")count=7;
	else
	    for(int i=1;;i++){
		if(s[i]==s1)f1=0;
		if(s[i]=="SUN")break;
		if(f1==0)count++;
		if(i==6)i=-1;
	    }
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Map.Strict as M
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Maybe (M.Map Int [Int])
solve !n = flip fmap mayGetGroupNum $ \k ->
  foldl' (\(!mp) (!i, (!x, !y)) -> M.adjust (i :) x $ M.adjust (i :) y mp)
         (M.fromList $ zip [1 .. k] $ repeat [])
    $ zip [1 ..] [ (x, y) | x <- [1 .. k], y <- [x + 1 .. k] ]
 where
  getMaySquare n =
    let sn = floor (sqrt $ fromIntegral n)
    in  if sn ^ 2 == n then Just sn else Nothing

  mayGetGroupNum = fmap (\s -> (1 + s) `div` 2) $ getMaySquare (1 + 8 * n)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  let ma = solve n
  case ma of
    Nothing -> putStrLn "No"
    Just mp -> do
      putStrLn "Yes"
      print $ M.size mp
      forM_ (M.toList mp) $ \(_, xs) -> do
        putStr $ show $ length xs
        mapM_ (putStr . (' ' :) . show) xs
        putStrLn ""


Measured memory_bytes: 10620
def solve():
  N, K = [int(i) for i in input().split()]
  h = [int(i) for i in input().split()]

  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i - K, 0), i))

  print(dp[N - 1])

solve()


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<double, ll> pdl;

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

int main() {
    // input, ready, resolve
    int N;
    cin >> N;
    double bunbo=0;
    for (int i=0; i<N; i++) {
        double a;
        cin >> a;
        bunbo += (1/a);
    }

    printf("%8.8lf", (1/bunbo));

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = 1;
        int total = 0;
        ArrayList<Integer> li = new ArrayList<Integer>();
        while(n > total){
            total += i;
            li.add(i);
            i++;
        }
        if(total - n != 0){
            li.remove(total-n-1);
        }
        for(int a : li){
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 23380
N, M = map(int, input().split())

tower = list(map(int, input().split()))
result = [0]*N
ans = 0

for i in range(M):
  A, B = map(int, input().split())
  #print(A, B)
  
  if tower[A-1] < tower[B-1]:
    result[A-1] += 1
  elif tower[A-1] > tower[B-1]:
    result[B-1] += 1
  else:
    result[A-1] += 1
    result[B-1] += 1

for i in result:
  if i == 0:
    ans += 1

print(ans)

Measured memory_bytes: 20048
import sys
readline = sys.stdin.readline

def main():
    H, W = map(int, readline().rstrip().split())
    mat = []
    for _ in range(H):
        inp = readline().rstrip()
        if '#' not in inp:
            continue
        mat.append(list(inp))
    
    ws = []
    for w in range(W):
        flg = False
        for h in range(len(mat)):
            if mat[h][w] == '#':
                flg = True
                break
        if flg:
            ws.append(w)
    
    ans = [''.join([l[j] for j in range(len(l)) if j in ws]) for l in mat]
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <climits>

#define el '\n'
typedef long long ll;
using namespace std;

void sol(){
	int n,k;
	cin >>n>>k;
	vector<int> h(n);
	for (int &i: h) cin >>i;
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 1; i < n; i++){
		for (int j = 1; j <= min(k, i); j++)
		dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
	}
	cout << dp[n - 1]<<el;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t= 1;
	while(t--){
	//	cout << t<<el;
		sol();
	}
}

Measured memory_bytes: 3632
import sys, math, bisect


if(__name__ == "__main__"):
    """
    N = int( input().strip() )
    Length = list( map(int, input().strip().split() ) )
    """
    X, K, D = map(int, input().strip().split() )


    if(X<0):
        X *= -1
    moved = X//D

    if(moved >= K):
        x_end = X-D*K
        print(x_end)
    else:
        x_0 = X-D*moved
        if(x_0 > D/2):
            moved += 1
            x_0 -= D
        move_remain = K-moved
        if(move_remain>0):
            if(move_remain%2!=0):
                if(x_0>=0):
                    x_0 -= D
                else:
                    x_0 += D

        print( abs(x_0) )


Measured memory_bytes: 9216
#[doc = " Ported from [bluss/permutohedron](https://github.com/bluss/permutohedron)"]
pub trait LexicalPermutation {
#[doc = " Return \'true\' if the slice was permuted, \'false\' if it is already "]
#[doc = " at the last ordered permutation."]
    fn next_permutation(&mut self) -> bool;
#[doc = " Return \'true\' if the slice was permuted, \'false\' if it is already "]
#[doc = " at the first ordered permutation."]
    fn prev_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
#[doc = " Original author in Rust: Thomas Backman <serenity@exscape.org>"]
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }
#[doc = " Original author in Rust: Thomas Backman <serenity@exscape.org>"]
    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}

fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get_line().parse::<usize>().unwrap();
    let p = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<usize>>();
    let q = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<usize>>();

    let mut v = (1..n + 1).collect::<Vec<usize>>();
    let (mut a, mut b): (i64, i64) = (0, 0);
    let mut count = 0;
    loop {
        if &v == &p { a = count; }
        if &v == &q { b = count; }
        if !v.next_permutation() { break; }
        count += 1;
    }
    println!("{}", (a - b).abs());
}


Measured memory_bytes: 4352
#include<stdio.h>
struct _data{
	int rank;
	int p;
	int num;
}typedef data;
data d[100000];
void sort(int n){
	int i,j,t;
	for(i=1;i<=n;i++){
		for(j=i;j<=n;j++){
			if(d[i].p<d[j].p){
				t=d[i].p;
				d[i].p=d[j].p;
				d[j].p=t;
				t=d[i].num;
				d[i].num=d[j].num;
				d[j].num=t;
			}
		}
	}
}
int main(){
	int i,n,r,p;
	int c=0;
	int rank=1;
	for(i=1;scanf("%d,%d",&n,&p)&&(n||p);i++){
		d[n].p=p;
		d[n].num=n;
		c++;
	}
	sort(c);
	for(i=1;i<=c;i++){
		if(i>1&&d[i-1].p!=d[i].p)rank++;
		d[i].rank=rank;
	}
	for(;scanf("%d",&r)!=EOF;){
		for(i=1;i<=c;i++){
			if(d[i].num==r)printf("%d\n",d[i].rank);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int maxn = (int)1e5 + 5;
const int mod = (int)1e9 + 7;
const int inf = 0x3f3f3f3f;
using namespace std;

vector<string> v;

int main(){
	string s; int k; cin >> s >> k;
	for(int i = 0; i < s.size(); i++){
		for(int j = 1; j <= 5; j++){
			v.push_back(s.substr(i, j));
		}
	}
	sort(v.begin(), v.end());
	unique(v.begin(), v.end());
	cout << v[k-1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  LL a,b;
  cin >> a >> b;
  // a, a+1, .. , l(4*x), ... , r(4*y), r+1, ..b;
  //              ^^^^^^^^^^^^^ <--- XOR is 0
  LL l = (a/4+1)*4;
  LL r = b/4*4;
  LL answer = 0ll;
  for(LL i = a; i<l; ++i) answer ^= i;
  for(LL i = r; i<=b; ++i) answer ^= i;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int H, N;
int ng[10101][4];
int dp[10101][1 << 4];
//---------------------------------------------------------------------------------------------------
int check(int y, int msk) {
    rep(x, 0, 4) if (ng[y][x]) if (!(msk & (1 << x))) return 0;
    return 1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> N;
    rep(i, 0, N) {
        int x, y; cin >> x >> y;
        ng[y][x] = 1;
    }

    rep(y, 0, H - 1) rep(msk, 0, 1 << 4) if(check(y, msk)) {
        rep(msk2, 0, 1 << 4) if (check(y + 1, msk2)) {
            // 1個置く
            rep(x, 0, 3) {
                if (msk & (1 << x)) continue;
                if (msk & (1 << (x+1))) continue;
                if (msk2 & (1 << x)) continue;
                if (msk2 & (1 << (x + 1))) continue;

                chmax(dp[y + 1][msk2 + (1 << x) + (1 << (x + 1))], dp[y][msk] + 1);
            }
            // 2個置く
            if (msk == 0 and msk2 == 0) chmax(dp[y + 1][(1 << 4) - 1], dp[y][0] + 2);
            chmax(dp[y + 1][msk2], dp[y][msk]);
        }
    }

    int ans = 0;
    rep(msk, 0, 1 << 4) if (check(H - 1, msk)) chmax(ans, dp[H - 1][msk]);
    cout << ans << endl;
}


Measured memory_bytes: 3948
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val n = readInt
  val A = readLine.split(" ").map(_.toInt)
  val p = partition(A, 0, n - 1)
  println(A.zipWithIndex.map{ case(e, i) => { if (i == p) s"[$e]" else e }}.mkString(" "))

  def partition(A: Array[Int], p: Int, r: Int): Int = {
    val x = A(r)
    var i = p - 1
    for (j <- p to r - 1) {
      if (A(j) <= x) {
        i += 1
        swap(A, i, j)
      }
    }
    swap(A, i + 1, r)
    i + 1
  }

  def swap(A: Array[Int], i: Int, j: Int): Unit = {
    if (i == j) {
      return
    }
    A(i) = A(i) ^ A(j)
    A(j) = A(i) ^ A(j)
    A(i) = A(i) ^ A(j)
  }
}



Measured memory_bytes: 75996
module P = Map.Make(struct type t = int let compare = (-) end)
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.fold_left (fun ((c, mp), z) x ->
    let s = try P.find ((c + x) mod m) mp with Not_found -> 0 in
    ((c + x) mod m, P.add ((c + x) mod m) (s+1) mp), z+s
  ) ((0, P.singleton 0 1), 0) a |> snd |> Printf.printf "%d\n"

Measured memory_bytes: 9600
#include <string.h>
#include <stdio.h>
int main()
{char s[12];
int i,cnt=0,len;
    scanf("%s",s);
    len=strlen(s);
    if(s[0]=='A'){
        for(i=2;i<= len - 2;i++){
            if(s[i]=='C'){
                cnt++;
            }
        }
        if(cnt==1){
            cnt=0;
            for(i=1;i<=len;i++){
            if((s[i]>='A')&&(s[i]<='Z')){
                cnt++;
            }    
            }
            if(cnt==1){
                printf("AC");
            }else{
                printf("WA");
            }
        }else{printf("WA");}
        }else {
        printf("WA");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int n;
vector<int> g[200005];

int d[200005];

void dfs(int u, int dist) {
    d[u] = dist;
    for (int v : g[u]) {
        if (d[v] == -1) {
            dfs(v, dist + 1);
        }
    }
}

int diameter() {
    memset(d + 1, -1, sizeof(int) * n);
    dfs(1, 0);
    int v = 1;
    for (int u = 2; u <= n; ++u)
        if (d[u] > d[v]) v = u;
    memset(d + 1, -1, sizeof(int) * n);
    dfs(v, 0);
    int dia = 0;
    for (int u = 1; u <= n; ++u) dia = max(dia, d[u]);
    return dia;
}

int main() {
    // freopen("data.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int d = diameter();
    if (d % 3 == 1) {
        printf("Second\n");
    } else {
        printf("First\n");
    }
}

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

using namespace std;

const int MaxN = 1e5 + 15;

int a[MaxN];

int n, k;

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    int mx = 0;
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
        if(i)
            a[i] = __gcd(a[i - 1], a[i]);
    }
    if(k % a[n] || k > mx)
        cout << "IMPOSSIBLE\n";
    else
        cout << "POSSIBLE\n";
    return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int n, a[100009], c[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i], c[a[i]]++;
	int r = 0;
	for (int i = 0; i <= 100000; i++) r += max(c[i] - 1, 0);
	cout << n - (r + 1) / 2 * 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const A = input[0];
  const B = input[1];
  const C = input[2];
  console.log(Math.max(C - (A - B), 0));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; 
	int A[2010] = {}, B[2010] = {};
	long long int C[2010] = {}; 
	long long int D[1010] = {}; 
	long long int INF = 1e15; 
	cin >> N >> M; 
	for(int i = 0; i < M; i++){
		cin >> A[i] >> B[i] >> C[i]; 
		C[i] *= -1; 
	}
	for(int i = 2; i <= N; i++){
		D[i] = INF; 
	}
	long long int x, y; 
	for(int i = 0; i < N * 2; i++){
		for(int j = 0; j < M; j++){
			if(D[A[j]] != INF && D[B[j]] > D[A[j]] + C[j]){
				D[B[j]] = D[A[j]] + C[j];
			}
		}
		if(i == N - 1) x = D[N]; 
		if(i == N * 2 - 1) y = D[N]; 
	}
	if(x != y) cout << "inf" << endl; 
	else cout << - y << endl; 
}

Measured memory_bytes: 256
s = input()

g = []
g.append(1)
g.append(2 if s[0] != s[1] else 1)
g.extend([0]*(len(s)-2))

for i in range(2, len(s)):
    g[i] = g[i-1] + 1 if s[i] != s[i-1] else g[i-3] + 2

print(g[-1])


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;


    vector<lint> ax(5);

    rep0(i,5)
    {
        cin >> ax[i];
    }

    rep0(i,5)
    {
        if(ax[i] == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

struct HBar{
	int r,c,li,ri,lp,rp;
	bool operator<(const HBar& hb)const{return r!=hb.r?r<hb.r:c<hb.c;}
	bool operator>(const HBar& hb)const{return r!=hb.r?r>hb.r:c>hb.c;}
};

int main()
{
	for(int n,m,h,k;cin>>n>>m>>h>>k,n|m|h|k;){
		vector<int> ps(n);
		for(int i=0;i<n;i++)
			cin>>ps[i];
		
		vector<HBar> hbs(m);
		for(int i=0;i<m;i++)
			cin>>hbs[i].c>>hbs[i].r;
		
		vector<int> is(n);
		for(int i=0;i<n;i++)
			is[i]=i;
		
		sort(hbs.begin(),hbs.end());
		for(int i=0;i<m;i++){
			hbs[i].li=is[hbs[i].c-1];
			hbs[i].ri=is[hbs[i].c];
			swap(is[hbs[i].c-1],is[hbs[i].c]);
		}
		for(int i=m;i--;){
			hbs[i].lp=ps[hbs[i].c-1];
			hbs[i].rp=ps[hbs[i].c];
			swap(ps[hbs[i].c-1],ps[hbs[i].c]);
		}
		
		int sum=accumulate(ps.begin(),ps.begin()+k,0);
		int sub=0;
		for(int i=0;i<m;i++){
			if(hbs[i].li<k && hbs[i].ri>=k)
				sub=max(sub,hbs[i].rp-hbs[i].lp);
			if(hbs[i].li>=k && hbs[i].ri<k)
				sub=max(sub,hbs[i].lp-hbs[i].rp);
		}
		
		cout<<sum-sub<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
  int sum,sum9,i,a;

  while(scanf("%d",&sum),sum){
    for(i=sum9=0;i<9;i++){
      scanf("%d",&a);
      sum9+=a;
    }
    printf("%d\n",sum-sum9);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long ans;
  if (a < 0 && b < 0 && c < 0 && d < 0) {
    ans = a * c;
  }
  else if (a < 0 && b < 0 && c < 0 && d >= 0) {
    ans = a * c;
  }
  else if (a < 0 && b < 0 && c >= 0 && d >= 0) {
    ans = b * c;
  }
  else if (a < 0 && b >= 0 && c < 0 && d < 0) {
    ans = a * c;
  }
  else if (a < 0 && b >= 0 && c < 0 && d >= 0) {
    ans = max(a * c, b * d);
  }
  else if (a < 0 && b >= 0 && c >= 0 && d >= 0) {
    ans = b * d;
  }
  else if (a >= 0 && b >= 0 && c < 0 && d < 0) {
    ans = a * d;
  }
  else if (a >= 0 && b >= 0 && c < 0 && d >= 0) {
    ans = b * d;
  }
  else if (a >= 0 && b >= 0 && c >= 0 && d >= 0) {
    ans = b * d;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st= new StringTokenizer(br.readLine());
        int th = Integer.parseInt(st.nextToken());
        int ts = Integer.parseInt(st.nextToken());
        int ah = Integer.parseInt(st.nextToken());
        int as = Integer.parseInt(st.nextToken());

        int tnum = ah%ts==0?ah/ts:(ah/ts) +1;
        int anum = th%as==0?th/as:(th/as) +1;
        String ans = tnum>anum? "No":"Yes";
        System.out.println(ans);
        

    }
}

Measured memory_bytes: 32804
N = int(input())
S = input()
i = 0
l = []
while i < N:
    if i + 1 < N:
        if S[i] == S[i + 1]:
            i += 2
            l.append(2)
            continue
    i += 1
    l.append(1)

if l[0] == 1:
    ans = 3
else:
    ans = 6
for i in range(1, len(l)):
    if l[i] == 1:
        if l[i - 1] == 1:
            ans *= 2
    else:
        if l[i - 1] == 1:
            ans *= 2
        else:
            ans *= 3
print(ans % 1000000007)


Measured memory_bytes: 3064
'use strict'
function main(inp) {
  inp = inp.trim()
  let L = []
  let R = []
  let ans = []
  let temp = 0

  for (let i = 0; i < inp.length; i++) {
    R[i] = 0
    if (inp[i] === 'R') {
      temp++
    } else if (temp > 0) {
      R[i] = Math.floor(temp / 2)
      R[i - 1] = temp - R[i]
      temp = 0
    }
  }
  temp = 0

  for (let i = inp.length - 1; i >= 0; i--) {
    L[i] = 0
    if (inp[i] === 'L') {
      temp++
    } else if (temp > 0) {
      L[i] = Math.floor(temp / 2)
      L[i + 1] = temp - L[i]
      temp = 0
    }
  }

  for (let i = 0; i < inp.length; i++) {
    ans[i] = R[i] + L[i]
  }
  console.log(ans.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 16844