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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=15;
const int mod=1e9+7;
const int inv2=(mod+1)/2;
int n,m,ans,cnt;
bool e[maxn][maxn];
int tmp_dp[maxn],edge[maxn],tmp_tmp_dp[maxn];
pii tmp_sg[maxn];
class State{
public:
	int sg[maxn];
	ll gethash(){
		ll h=0;
		rep(i,n)h=1LL*h*(n+1)+(sg[i]+1);
		return h;
	}
	void work(int x){
		cnt=0;
		for(int i=x+1;i<n;i++)if(sg[i]>=0&&e[x][i])tmp_sg[cnt++]=mp(sg[i],i);
		sort(tmp_sg,tmp_sg+cnt);
		rep(i,n)tmp_dp[i]=0;
		tmp_dp[0]=1;
		rep(i,cnt){
			int now=tmp_sg[i].fst;
			tmp_dp[now+1]+=1LL*tmp_dp[now]*inv2%mod;
			if(tmp_dp[now+1]>=mod)tmp_dp[now+1]-=mod;
			tmp_dp[now]=1LL*tmp_dp[now]*inv2%mod;
		}
		rep(i,n)tmp_dp[i]=1LL*tmp_dp[i]*(1<<cnt)%mod;
	}
	void relax(int x){
		int ccnt=0;
		for(int i=x;i<n;i++)if((edge[i]&((1<<x)-1))==edge[x])
			tmp_sg[ccnt++]=mp(sg[i],i);
		sort(tmp_sg,tmp_sg+ccnt);
		ccnt=0;
		for(int i=x;i<n;i++)if((edge[i]&((1<<x)-1))==edge[x])
			sg[i]=tmp_sg[ccnt++].fst;
	}
}ini,cur,cur2;
map<ll,int>dp;
queue<State>q;

int main(){
	scanf("%d%d",&n,&m);
	ans=1;
	rep(i,m)ans=2LL*ans%mod;
	rep(i,m){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;v--;
		e[u][v]=true;
		edge[v]|=(1<<u);
	}
	rep(i,n)ini.sg[i]=-1;
	dp[ini.gethash()]=1;
	q.push(ini);
	while(!q.empty()){
		cur=q.front();q.pop();
		ll h=cur.gethash();
		int x=0;
		while(cur.sg[x]<0)x++;
		x--;
		int base=dp[h];
		if(x==1){
			cur.work(0);
			rep(i,n)tmp_tmp_dp[i]=tmp_dp[i];
			cur.work(1);
			rep(i,n){
				ans-=1LL*base*tmp_tmp_dp[i]%mod*tmp_dp[i]%mod;
				if(ans<0)ans+=mod;
			}
			continue;
		}
		cur.work(x);
		rep(i,n)if(tmp_dp[i]){
			cur2=cur;
			cur2.sg[x]=i;
			cur2.relax(x);
			ll h2=cur2.gethash();
			if(!dp.count(h2))q.push(cur2);
			dp[h2]+=1LL*base*tmp_dp[i]%mod;
			if(dp[h2]>=mod)dp[h2]-=mod; 
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 27664
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;



// void solve(){

// string s;
// cin>>s;


// }
 


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      
     int n;
     cin>>n;
     vector<int> a(100004);
     ll s= 0;
     for (int i = 0;i<n;i++) {int k; cin>>k; a[k]++; s+=k;}
    int q;
  

  cin>>q;
  while(q--){
    int b,c;
    cin>>b>>c;
    ll change = 0;
    int cnt = a[b];
    a[b] = 0;
    a[c]+=cnt;
    change = (c-b)*cnt;
    s+=change;
    cout<<s<<"\n";

  }

}



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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> C(H);
  for(int i=0; i<H; i++){
    cin >> C.at(i);
    cout << C.at(i) << endl << C.at(i) << endl;
  }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

int n;
pair <int, int> a[100005];

int main() {		
	scanf ("%d", &n);
	rep(i, 1, n) {
		scanf ("%d", &a[i].fi);
		a[i].se = i;
	}
	sort(a + 1, a + n + 1);
	int ans = 0;
	rep(i, 1, n) if (i % 2 != a[i].se % 2) ans++;
	printf ("%d\n", ans / 2);
	return 0;
}


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

int main() {
	string S;
	cin >> S;
	size_t ans = 0;
	for (int i = 0; i < S.size(); ++i) {
		string tmp;
		for (int j = i; j < S.size(); ++j) {
			tmp += S[j];
			//cout << tmp << endl;
			int k;
			for (k = 0; k < tmp.size(); ++k) {
				if (tmp[k] != 'A' && tmp[k] != 'C' && tmp[k] != 'G' && tmp[k] != 'T') break;
			}
			if (k == tmp.size()) ans = max(ans, tmp.size());
		}
	}
	/*for (int i = 0; i < S.size(); ++i) {
		for (int j = 0; j < S.size() - i; ++j) {
			bool tmp = true;
			for (int k = j; k < i + j + 1; ++k) {
				if (S[k] != 'A' && S[k] != 'C' && S[k] != 'G' && S[k] != 'T') tmp = false;
			}
			if (tmp = true) ans = i + 1;
		}
	}*/
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M;
	cin >> N >> M;
	
	vector<pii> ba;
	PQ Q;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		ba.push_back(make_pair(a,b));
	}

	SORT(ba);

	int ans = 0;
	int j = 0;
	for (int i = 1; i <= M;i++) {
		while (j != N && ba[j].first <= i) {
			Q.push(ba[j].second);
			j++;
		}
		if (!Q.empty()) {
			ans += Q.top();
			Q.pop();
		}
		
	}
	cout << ans << endl;
	return 0;
}



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

int R;

int main(){
   cin >> R;
  if(R < 1200){
  cout << "ABC" <<endl;
  } 
  else if(1200 <= R && R < 2800){
  cout <<"ARC" << endl;
  }
  else if(2800 <= R && R <= 4208){
  cout << "AGC" << endl;
 }
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

ll b[5000][200];
ll le[5001][5001];


void solve() {
	int n, m; cin >> n >> m;
	vector<ll> a(n);
	rep(i, n - 1) {
		cin >> a[i];
	}
	rep(i, n) {
		rep(j, m) {
			cin >> b[i][j];
		}
	}
	rep(i, m) {
		//cout << i << endl;
		set<int> st;
		st.insert(-1);
		st.insert(n);
		priority_queue<LP> q;
		rep(j, n) {
			q.push({ b[j][i],j });
		}
		while (!q.empty()) {
			int id = q.top().second; q.pop();
			st.insert(id);
			auto itr = st.find(id);
			itr--;
			int l = *itr;
			itr++; itr++;
			int r = *itr;
			if (id - l > r - id) {
				for (int j = id; j < r; j++) {
					le[l + 1][j] += b[id][i];
					le[id + 1][j] -= b[id][i];
					le[l + 1][j + 1] -= b[id][i];
					le[id + 1][j + 1] += b[id][i];
				}
			}
			else {
				//cout << "hello " << id << l << r << endl;
				for (int j = l + 1; j <= id; j++) {
					//cout << j << " " << id << " add " << b[j][i] << endl;
					le[j][id] += b[id][i];
					le[j][r] -= b[id][i];
					le[j + 1][id] -= b[id][i];
					le[j + 1][r] += b[id][i];
				}
			}
		}
	}
	rep(i, n) {
		rep(j, n) {
			le[i][j + 1] += le[i][j];
		}
	}
	rep(i, n) {
		rep(j, n) {
			le[j+1][i] += le[j][i];
		}
	}
	/*rep(i, n) {
		rep(j, n) {
			cout << i << " " << j << " " << le[i][j] << endl;
		}
	}*/
	ll ans = 0;
	rep(i, n) {
		ans = max(ans, le[i][i]);
		ll sum = 0;
		Rep(j,i+1, n) {
			sum -= a[j - 1];
			//cout << i << " " << j <<" "<<le[i][j]<<" "<<ri[i][j]<< endl;
			//cout << sum + le[i][j] + ri[i][j] << endl;
			ans = max(ans, sum+le[i][j]);
		}
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 203928
N, K = map(int, input().split())
X = [int(x) for x in input().split()]
ans = 1e9
for l in range(N-K+1):
    r = l+K-1
    a = min(
        abs(X[l]) + abs(X[r]-X[l]),
        abs(X[r]) + abs(X[l]-X[r])
    )
    if a < ans:
        ans = a
print(ans)

Measured memory_bytes: 14384
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

ll res[2002][2002],res2[2002][2002];
signed main() {
    SS(int,N)
    vector<int> a(N + 1);
    rep(i,N)cin >> a[i+1];
    
    vector<int> ans;
    vector<int> b(N + 1, 0);
    for (int i = N; i >= 1; i--) {
        int sum = 0;
        for (int j = i; j <= N; j += i) sum += b[j];
        
        if ((sum + a[i]) % 2 == 1) {
            b[i]++;
            ans.push_back(i);
        }
    }

    reverse(all(ans));
    cout << ans.size() << endl;
    for(auto x: ans) cout << x << " ";
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    ll N;
  	cin>>N;
    map<ll,ll> m;
    rep(i,N) {
        ll x;
        cin>>x;
        m[x]++;
    };
    ll cnt = 0LL;
    for(auto x:m){
        cnt+=x.first*x.second;
    }
    int Q;
    cin>>Q;
    rep(i,Q){
        ll B,C;
        cin>>B>>C;
        cnt = cnt-B*m[B]+C*m[B];
        m[C]+=m[B];
        m[B]=0;
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 9416
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b, q;
  cin >> a >> b >> q;
  vector<long long> s, t;
  s.push_back(-(1LL << 60));
  t.push_back(-(1LL << 60));
  for (int i = 0; i < a; i++) {
    long long ss;
    cin >> ss;
    s.push_back(ss);
  }
  for (int i = 0; i < b; i++) {
    long long tt;
    cin >> tt;
    t.push_back(tt);
  }
  s.push_back(1LL << 60);
  t.push_back(1LL << 60);
  while (q--) {
    long long x;
    cin >> x;
    auto itr_s = lower_bound(s.begin(), s.end(), x);
    auto itr_t = lower_bound(t.begin(), t.end(), x);
    long long ss[] = {*(itr_s--), *itr_s};
    long long tt[] = {*(itr_t--), *itr_t};
    long long ans = 1LL << 60;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        ans = min(ans, abs(ss[i] - tt[j]) + min(abs(x - ss[i]), abs(x - tt[j])));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
const int MAXN = 305;
const int S = 3;
double dp[MAXN][MAXN][MAXN]{ };
int cnt[S]{ };
int A, N;

void init() {
  int a = cnt[0];
  int b = cnt[1];
  int c = cnt[2];
  for (int i = a+b+c; i >= 0; --i) {
    for (int j = b+c; j >= 0; --j) {
      for (int k = c; k >= 0; --k) {
        dp[i][j][k] = -1.0;
      }
    }
  }
  dp[0][0][0] = 0.0;
}

double dfs(int i, int j, int k) {
  if (dp[i][j][k] >= 0.0) {
    return dp[i][j][k];
  }
  int sum = i + j + k;
  bool one = (i == sum) || (j == sum) || (k == sum);
  double p = 0.0;
  if (one) {
    if (k) p = dfs(i, j+1, k-1) + 1.0 * N / k;
    if (j) p = dfs(i+1, j-1, k) + 1.0 * N / j;
    if (i) p = dfs(i-1, j, k) + 1.0 * N / i;
  } else if (sum) {
    if (k) p += 1.0 * k / sum * dfs(i, j+1, k-1);
    if (j) p += 1.0 * j / sum * dfs(i+1, j-1, k);
    if (i) p += 1.0 * i / sum * dfs(i-1, j, k);
    p += 1.0 * N / sum;
  }
  return dp[i][j][k] = p;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < S; ++i) {
    cnt[i] = 0;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A);
    ++cnt[A-1];
  }
  init();
  printf("%.12f\n", dfs(cnt[0], cnt[1], cnt[2]));
  return 0;
}

Measured memory_bytes: 219392
//
//  main.cpp
//  atcoder - coins
//
//  Created by r on 6/1/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

double p[3010];
int N;
double dp[3010][3010];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i<N; i++) {
        cin >> p[i];
    }
    dp[N][0] = 1;
    for (int i = N-1; i>=0; i--) {
        dp[i][0] = (1-p[i])*dp[i+1][0];
        for (int j = 1; j<=N-i; j++) {
            dp[i][j]+=p[i]*dp[i+1][j-1];
            if (j != N-i) {
                dp[i][j]+=(1-p[i])*dp[i+1][j];
            }
        }
    }
    double sum = 0;
    int highest = N/2 + 1;
    for (int i = highest; i<=N; i++) {
        sum+=dp[0][i];
    }
    cout << fixed;
    cout << setprecision(10);
    cout << sum << endl;
    return 0;
}





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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
int p[N];
int cnt=0;
rep(i,N){
    cin>>p[i];
    if(p[i]!=i+1){cnt++;}
}
if(cnt<=2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
//system("pause");
return 0;
}

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

int main(void){
  int N, A, B; cin >> N >> A >> B;

  int low, med, high; low = med = high = 0;
  for(int i = 0; i < N; i++){
    int v; cin >> v;
    if(v <= A) low++;
    else if(A+1 <= v && v <= B) med++;
    else high++;
  }

  cout << min(low, min(med, high)) << endl;
}


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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int n, c, k, t[kN];

int main() {
	rd(n, c, k);
	for(int i = 1; i <= n; ++i) rd(t[i]);
	std::sort(t + 1, t + n + 1);
	int ptr = 1, ans = 0;
	for(; ptr <= n; ++ptr) {
		int st = t[ptr] + k; ++ans;
		for(int j = 1; ptr < n && j < c && t[ptr + 1] <= st; ++ptr, ++j);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const long long mod = 998244353;
int n;
int a[500];
long long dp[500000], dp0[500000];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    dp[0] = 1, dp0[0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 100000; j >= a[i]; j--)
        {
            dp[j] = (dp[j - a[i]] * 2 + dp[j]) % mod;
            dp0[j] = (dp0[j - a[i]] + dp0[j]) % mod;
        }
    }
    long long ans = 1, s = 0;
    for (int i = 0; i < n; i++) ans = 3 * ans % mod, s += a[i];
    for (int i = 0; 2 * i <= s; i++)
    {
        ans = (ans + 3 * mod - 3 * dp[i]) % mod;
    }
    if (s % 2 == 0) ans = (ans + 3 * dp0[s / 2]) % mod;
    cout << ans;
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

struct UF {
    static const int MAX_N = 100000;
    int p[MAX_N];
    int r[MAX_N];

    void init(int n) {
        REP(i, n) {
            p[i] = i;
            r[i] = 0;
        }
    }
    int find(int x) {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y);
        if (r[x] == r[y]) r[x]++;
        p[y] = x;
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

int n, d[100];
vector<P> g[100];

void dijkstra(int s) {
    fill(d, d + n, 99999999);
    d[s] = 0;
    priority_queue<P> que;
    que.push({0, s});
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int u = p.second;
        if (p.first > d[u]) continue;
        REP(i, g[u].size()) {
            int v = g[u][i].first, cost = g[u][i].second;
            if (d[v] > d[u] + cost) {
                d[v] = d[u] + cost;
                que.push({d[v], v});
            }
        }
    }
}

int main() {
    cin >> n;
    REP(i, n) {
        int from, k;
        cin >> from >> k;
        REP(j, k) {
            int to, c;
            cin >> to >> c;
            g[from].push_back({to, c});
        }
    }
    dijkstra(0);
    REP(i, n) { cout << i << " " << d[i] << endl; }
    return 0;
}


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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int n,ans=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n-2;++i){
		if(s[i]== 'A' &&s[i+1]=='B' && s[i+2] == 'C')
			++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a, b=map(int,input().split())
if (a < 0 and 0 < b) or (a == 0 or b ==0):
  print("Zero")
  exit()
elif 0 < a:
  print("Positive")
  exit()
if (b -a+1) % 2 == 0:
  print("Positive")
else:
  print("Negative")

Measured memory_bytes: 9104
import sys
sys.setrecursionlimit(10**7)
N = int(input())

Graph = [[] for _ in range(N+10)]
dist  = [10000000000000]*(N+10)

for i in range(N-1):
	u,v,w = map(int,input().split())
	u-=1
	v-=1
	Graph[u].append((v,w))
	Graph[v].append((u,w))

dist[0] = 0

def func(fromE,now,length):
	if fromE != -1:
		dist[now] = dist[fromE]+length
	for i in range(len(Graph[now])):
		target = Graph[now][i][0]
		lengt  = Graph[now][i][1]

		if target == fromE:
			continue

		func(now,target,lengt)

func(-1,0,0)

for i in range(N):
	if dist[i]%2 == 0:
		print(0)
	else:
		print(1)

Measured memory_bytes: 86692
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int dx[]={-1,-1,0,0,1,1};
int dy[]={0,-1,1,-1,1,0};
const int inf=1000000010;
string s;
int t;
vi f(){
	vvi in;
	string w="";
	while(t<s.size()){
		if(s[t]=='('){
			t++;
			in.pb(f());
			t++;
		}else{
			int a=0;
			while(t<s.size()&&isdigit(s[t])){
				a*=10;
				a+=s[t]-'0';
				t++;
			}
			in.pb({a});
		}
		if(s.size()==t)break;
		if(s[t]==')')break;
		w+=s[t];
		t++;
	}
	vi out;
	vi per(w.size());
	rep(i,w.size())per[i]=i;
	do{
		vvi tmp=in;
		vi used(w.size()+1);
		rep(i,w.size()){
			int l=per[i],r=per[i]+1;
			while(used[l])l--;
			while(used[r])r++;
			vi nt;

			rep(j,tmp[l].size())rep(k,tmp[r].size()){
				if(w[per[i]]=='+')nt.pb(tmp[l][j]+tmp[r][k]);
				if(w[per[i]]=='-')nt.pb(tmp[l][j]-tmp[r][k]);
				if(w[per[i]]=='*')nt.pb(tmp[l][j]*tmp[r][k]);
				if(tmp[r][k]&&w[per[i]]=='/')nt.pb(tmp[l][j]/tmp[r][k]);
			}
			used[l]=true;
			tmp[l]=vi(0);
			tmp[r]=nt;
		}
		rep(j,tmp.size()){rep(i,tmp[j].size())out.pb(tmp[j][i]);}
	}while(next_permutation(all(per)));
	sort(all(out));
	out.erase(unique(all(out)),out.end());

	return out;
}
int main(){
	while(cin>>s,s!="#"){
		t=0;
		cout<<f().size()<<endl;
	}
}









Measured memory_bytes: 6212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n,i,j,k;
    int mat[100][100] = {};
    int vec[100] = {};
    int ans[100] = {};
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>mat[i][j];
        }
    }
    for(i=0;i<m;i++)
    {
        cin>>vec[i];
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            ans[i]+=mat[i][j]*vec[j];
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    long long arr[n + 1];
    for(ll i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    ll possible = n - k;
    ll sum  = 0;
    for(ll i = 0; i < possible; i++)
    {
        sum = sum + arr[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  for i in range(50000):
    a = int(i*1.08)
    if a == N:
      print(i)
      break
    else:
      continue
  else:
    print(':(')
  
  
  
if __name__ == '__main__':
  main()

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

int main() {

    int N, R;
    cin >> N >> R;

    int I = 0;
    if(N>=10){
        I=R;
    } else {
        I = R + 100 * (10-N);
    }

    cout << I << endl;


    return 0;
}


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

const int N=2100,mod=924844033;
int n,K,cnt[N];
LL fac[N<<1],inv[N<<1],f[2][N],Ans;

LL qpow(LL x,int y)
{
	LL ret=1;
	while(y)
	{
		if(y&1) ret=ret*x%mod;
		x=x*x%mod, y>>=1;
	}
	return ret;
}

LL C(int x,int y)
{
	if(y>x) return 0;
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main()
{
	scanf("%d%d",&n,&K);
	fac[0]=1;
	for(int i=1;i<=n<<1;++i) fac[i]=fac[i-1]*i%mod;
	inv[n<<1]=qpow(fac[n<<1],mod-2);
	for(int i=(n<<1)-1;i>=0;--i) inv[i]=inv[i+1]*(i+1)%mod;
	if(K*2>=n)
	{
		Ans=fac[n];
		for(int i=1;i<=(n-K)*2;++i)
			if(i&1) (Ans-=fac[n-i]*C((n-K)*2,i))%=mod;
			else (Ans+=fac[n-i]*C((n-K)*2,i))%=mod;
		(Ans+=mod)%=mod;
		printf("%lld",Ans); return 0;
	}
	for(int i=1;i<=K;++i) cnt[i]=(n-i-K)/(2*K)+1 + (n-i)/(2*K);
	f[0][0]=1;
	for(int i=1;i<=K;++i)
	{
		for(int j=0;j<=n;++j) f[1][j]=f[0][j];
		for(int j=0;j<=n;++j)
			for(int k=1;k<=min(j,cnt[i]);++k)
				(f[1][j]+=f[0][j-k]*C(cnt[i]-k+1,k)%mod)%=mod;
		for(int j=0;j<=n;++j) f[0][j]=f[1][j];
		for(int j=0;j<=n;++j)
			for(int k=1;k<=min(j,cnt[i]);++k)
				(f[0][j]+=f[1][j-k]*C(cnt[i]-k+1,k)%mod)%=mod;
	}
	Ans=fac[n];
	for(int i=1;i<=n;++i)
		if(i&1) (Ans-=f[0][i]*fac[n-i]%mod)%=mod;
		else (Ans+=f[0][i]*fac[n-i]%mod)%=mod;
	Ans=(Ans+mod)%mod;
	printf("%lld",Ans);
	return 0;
}


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

#define ll long long

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll ans = 1e18;

    //ll c = min(k, x / d);
    ll c = x / d;

    if (k <= c)
    {
        cout << x - (k * d) << "\n";
    }
    else
    {
        ans = x - (c * d);
        k -= c;
        k %= 2;
        if (k) ans = min(ans - k * d, ans + k * d);
        cout << abs(ans) << "\n";
    }
    




    // x -= c * d;
    // k -= c;
    // ans = abs(x);
    
    // if (k)
    // {
    //     if (k%2) //odd
    //     {
    //         ans = min(abs(x + d), abs(x - d));
    //     }
    //     else
    //     {
    //         ans = min(ans, abs(x - d));
    //     }
    // }

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

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=(int)1e9+7,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
    char c=gc; x=0; int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
    while(isdigit(c)) x=x*10+c-'0',c=gc;
    x*=f;
}
template<class o> void qw(o x) {
    if(x/10) qw(x/10);
    putchar(x%10+'0');
}
template<class o> void pr1(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar('\n');
}

int n;
ll ans;

ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}

void ad(ll &x,ll y) {x=(x+y)%mod;}

struct rec {
	int x,y;
	bool operator <(rec b) const {return x<b.x;}
} a[N];

struct BIT {
	ll c[N];
	BIT() {memset(c,-63,sizeof c);}
	void add(int x,ll y) {for( ;x<=n;x+=x&-x) c[x]=max(c[x],y);}
	ll ask(int x) {ll y=c[0]; for( ;x;x-=x&-x) y=max(y,c[x]);return y; }
} u,v;

int y[N];
int find(int x) {return lower_bound(y+1,y+n+1,x)-y;}

int main() {
	qr(n);
	for(int i=1;i<=n;i++) {
		qr(a[i].x); qr(a[i].y);
		y[i]=a[i].y;
	}
	sort(y+1,y+n+1); 
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) {
		int x=a[i].x,y=a[i].y,id=find(y);
		ans=max(ans,u.ask(id)+y+x);
		ans=max(ans,v.ask(n-id+1)-y+x);
		u.add(id,-x-y);
		v.add(n-id+1,-x+y);
	}
	pr2(ans);
	return 0;
}

Measured memory_bytes: 9104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine();
		}
		String t = br.readLine();
		br.close();

		String[] a = new String[n];
		String[] z = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = s[i].replaceAll("\\?", "a");
			z[i] = s[i].replaceAll("\\?", "z");
		}
		Arrays.parallelSort(a);
		Arrays.parallelSort(z);

		int start = n + 1;
		int end = 1;
		for (int i = 0; i < n; i++) {
			if (start == n + 1 && z[i].compareTo(t) >= 0) {
				start = i + 1;
			}
			if (a[i].compareTo(t) <= 0) {
				end = i + 2;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = start; i <= end; i++) {
			sb.append(i).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 44968
while ((a,op,b = gets.split(" ")).select{|i| i == "?"}.length == 0) do
  case op
  when "+" then
    puts [a,b].map(&:to_i).inject(:+)
  when "-" then
    puts [a,b].map(&:to_i).inject(:-)
  when "*" then
    puts [a,b].map(&:to_i).inject(:*)
  when "/" then
    puts [a,b].map(&:to_i).inject(:/)
  end
end

Measured memory_bytes: 8536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char s[h+2][w+2];
	for(int i=1;i<h+1;i++)
	{
		for(int j=1;j<w+1;j++)
		{
			cin>>s[i][j];
		}
	}
	for(int i=0;i<h+2;i++)
	{
		for(int j=0;j<w+2;j++)
		{
			if(i==h+1||j==0)
				cout<<"#";
			else if(j==w+1||(j==w+1&&i==0))
				cout<<"#"<<endl;
				else if(i==0)
				cout<<"#";
			else
				cout<<s[i][j];
		}
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String crlf = System.getProperty("line.separator");
    int m, f, r;
    
    while(in.hasNext()) {
      m = in.nextInt();
      f = in.nextInt();
      r = in.nextInt();
      if (m == -1 && f == -1 && r == -1) return;
      int sum = m + f;
      
      if      ((m == -1 || f == -1) || (sum < 30)) System.out.println("F");
      else if (sum >= 80)                          System.out.println("A");
      else if (sum >= 65 && sum < 80)              System.out.println("B");
      else if (sum >= 50 && sum < 65)              System.out.println("C");
      else if (r >= 50)                            System.out.println("C");
      else                                         System.out.println("D");
    }
  }
}

Measured memory_bytes: 19508
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	M := nextInt(sc)
	X := make([]int, M)
	for i := 0; i < M; i++ {
		X[i] = nextInt(sc)
	}
	sort.Ints(X)
	// fmt.Println("N", N, "M", M, "X", X)
	ans := 0
	if N < M { // N >= Mであれば全ての座標にコマをおけるため
		L := make([]int, M-1) // 区間の数はM-1
		for i := 0; i+1 < M; i++ {
			L[i] = X[i+1] - X[i]
		}
		sort.Sort(sort.Reverse(sort.IntSlice(L)))
		ans = X[len(X)-1] - X[0]
		for i := 0; i < N-1; i++ {
			ans -= L[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int DP[N], h[N], n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> h[i];
  Fill(DP, IINF);
  DP[0] = 0;
  DP[1] = abs(h[1]-h[0]);
  FOR(i, 2, n){
    mins(DP[i], DP[i-1] + abs(h[i]-h[i-1]));
    mins(DP[i], DP[i-2] + abs(h[i]-h[i-2]));
  }
  cout << DP[n-1] << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

int d[15][15];
int N;
int g[305][305];
VI vy, vx;

int check[15][15];

int main () {
	make2(A, B);
	FOR(i,0,A) FOR(j,0,B) {
		make(x); d[i+1][j+1] = x;
	}
	vector<pair<PII, int > > v;
	FOR(a,0,101) FOR(b,0,101) {
		int c = -1000;
		FOR(x,1,A+1) FOR(y,1,B+1) {
			c = max(c, d[x][y]-a*x-b*y);
		}
		if (c < 0) continue;
		v.pb(mp(mp(a,b),c));
	}
	N = 2;
	FOR(i,0,305) FOR(j,0,305) g[i][j] = -3;
	int maxa = 0;
	int maxb = 0;
	FORE(i, v) maxa = max(maxa, i->st.st);
	FORE(i, v) maxb = max(maxb, i->st.nd);
	int S = 0; vx.pb(S);
	int T = 1; vy.pb(T);
	int act = 2;
	FOR(i,0,maxa) {
		g[vx.back()][act] = -1;
		vx.pb(act); 
		act++;
	}
	FOR(i,0,maxb) {
		g[act][vy.back()] = -2;
		vy.pb(act); 
		act++;
	}
	bool ok = true;
	FORE(i,v) {
		int a = i->st.st;
		int b = i->st.nd;
		int c = i->nd;
		g[vx[a]][vy[b]] = c;
		FOR(ii,1,A+1) FOR(jj,1,B+1) {
			if (ii*a +jj*b + c == d[ii][jj]) check[ii][jj] = 1; 
			if (ii*a +jj*b + c < d[ii][jj]) ok = false;
		}
	}
	FOR(i,1,A+1) FOR(j,1,B+1) {
		if (check[i][j] != 1 || !ok) {
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	int m = 0;
	FOR(i,0,act) FOR(j,0,act) {
		if (g[i][j] != -3) m++;
	}
	printf("%d %d\n", act, m);
	FOR(i,0,act) FOR(j,0,act) {
		if (g[i][j] == -1) {
			printf("%d %d X\n", i+1, j+1);
		}
		else if (g[i][j] == -2) {
			printf("%d %d Y\n", i+1, j+1);
		} else if (g[i][j] >= 0) {
			printf("%d %d %d\n", i+1, j+1, g[i][j]);
		}
	}
	printf("1 2\n");
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
using namespace std;
 
int gcd(int x, int y){
	if(y == 0) return x;
	else return gcd(y, x % y);
}
 
int main() {
	int a, b;
	cin >> a; cin >> b;
	cout << gcd(max(a,b), min(a,b)) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

void reset(vector<int> &v) {
  rep(i, v.size()) { v[i] = 0; }
}

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<bool>> s(h, vector<bool>(w, false));
  rep(i, h) {
    string tmp;
    cin >> tmp;
    rep(j, w) {
      if (tmp[j] == '1') s[i][j] = true;
    }
  }
  int ans = h + w;
  rep(c, 1 << (h - 1)) {
    bitset<9> b(c);
    int cut = b.count();
    vector<int> blocks(cut + 1, 0);
    int wc = 0;
    int hc = 0;
    int bc = 0;
    bool cutted = false;
    while (1) {
      blocks[bc] += s[hc][wc];
      if (blocks[bc] > k) {
        if (cutted) {
          cut = h + w;
          break;
        }
        cut++;
        cutted = true;
        bc = 0;
        hc = 0;
        reset(blocks);
        continue;
      }
      if(hc <h-1){
      if (b.test(hc)) {
        bc++;
      }
      }
      hc++;
      if (hc == h) {
        bc = 0;
        hc = 0;
        wc++;
        cutted = false;
        if (wc == w) break;
      }
    }
    ans = min(ans, cut);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    return (a * b) // gcd(a, b)

N = int(input())
T = [int(input()) for i in range(N)]

ans = T[0]

for t in T[1:]:
    ans = lcm(ans, t)

print(ans)

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

// Start of template
//
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define ROF(i, a, b) for (int i = (b); i > (a); i--)
    #define REP(a) for (int i = 0; i < (a); i++)
    #define pb push_back

    typedef long long ll;
    typedef vector<int> vi;

    const int MOD = 1e9 + 7;

    // to_string methods
    string ts(int n) { return to_string(n); }
    string ts(double n) { return to_string(n); }
    string ts(long double n) { return to_string(n); }
    string ts(long long n) { return to_string(n); }
    string ts(char c) { return to_string(c); }
    string ts(bool b) { return b ? "true" : "false"; }
    string ts(string s) { return s; }

    template <typename T, typename V>
    string ts(pair<T,V> p) {
        return "{" + ts(p.first) + ", " + ts(p.second) + "}";
    }

    template <typename T>
    string ts(T arr[], int len) {
        ostringstream oss;
        oss << "[";
        string delim = "";
        for (int i = 0; i < len; i++) {
            oss << delim << ts(arr[i]);
            delim = ", ";
        }
        oss << "]";
        return oss.str();
    }

    template<typename Container>
    string ts(const Container &v) {
        ostringstream oss;
        oss << "[";
        string delim = "";
        for (const auto &x : v) {
            oss << delim << ts(x);
            delim = ", ";
        }
        oss << "]";
        return oss.str(); 
    }

    template <typename T, typename V>
    string ts(map<T,V> m) {
        ostringstream oss;
        oss << "[";
        string delim = "";
        for (auto&& [first, second] : m) {
            oss << delim;
            oss << "{" << first << ": " << second << "}";
            delim = ", ";
        }
        oss << "]";
        return oss.str(); 
    }

    // IO stuff
    void setI(string s) {
        freopen(s.c_str(), "r", stdin);
    }

    void setO(string s) {
        freopen(s.c_str(), "w", stdout);
    }

    void setIO(string s1, string s2) {
        setI(s1); setO(s2);
    }

    void setUsacoIO(string s) {
        setIO(s + ".in", s + ".out");
    }


// End of template

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

    int n, m;
    ll k;
    cin >> n >> m >> k;

    vi a(n);
    vi b(m);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    vector<ll> bSums(m + 1);
    bSums[1] = b[0];
    for (int i = 2; i <= m; i++) {
        bSums[i] = bSums[i - 1] + (ll) b[i - 1];
    }

    int numBooks = 0;
    ll aTime = 0;
    for (int i = 0; i < n + 1; i++) {
        if (aTime > k) {
            break;
        }

        if (aTime == k) {
            numBooks = max(numBooks, i);
            break;
        }

        int j = 0;
        for (int add = n; add >= 1; add /= 2) {
            while (j + add <= m && aTime + bSums[j + add] <= k) {
                j += add;
            }
        }

        numBooks = max(numBooks, i + j);
        aTime += a[i];
    }

    cout << numBooks << endl;

    return 0;
}

Measured memory_bytes: 6416
package main

import "fmt"

func main() {

	// mainA()
	mainB()

}

func mainA() {
	var a, b, res int64
	fmt.Scan(&a, &b)
	res = solveA(a, b)
	fmt.Println(res)
}

func solveA(a int64, b int64) int64 {
	var res int64
	if b%a == 0 {
		res = a + b
	} else {
		res = b - a
	}

	return res
}

func mainB() {
	var n, m int
	fmt.Scan(&n, &m)

	var kA []int
	var aA [][]int

	kA = make([]int, n)
	aA = make([][]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&kA[i])
		aA[i] = make([]int, 0)
		for j := 0; j < kA[i]; j++ {
			var b int
			fmt.Scan(&b)
			aA[i] = append(aA[i], b)
		}
	}

	var res = solveB(n, m, kA, aA)

	fmt.Println(res)
}

func solveB(n int, m int, kA []int, aA [][]int) int {
	var mA = make([]int, m)
	for i := 0; i < n; i++ {
		for j := 0; j < kA[i]; j++ {
			var num = aA[i][j]
			mA[num-1]++
		}
	}
	var res = 0
	for i := 0; i < m; i++ {
		if mA[i] >= n {
			res++
		}
	}
	return res
}


Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, read().split())

flg = 0

for i in range(101):
    c = c - b
    if c <= 0:
        flg = 0
        break
    
    a = a - d
    if a <= 0:
        flg = 1
        break

if flg == 0:
    print("Yes")
else:
    print("No")


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

using namespace std;

using ll = long long;

mt19937 mt(736);

const int mod = 998244353;


int powmod10(int n)
{
	static vector<int> dp = {1};

	while (n >= dp.size())
		dp.push_back((10ll * dp.back()) % mod);

	return dp[n];
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	array<vector<vector<int>>, 3> xyz;

	for (auto &gr : xyz)
	{
		gr.resize(n);

		int m;

		cin >> m;

		for (int i = 0; i < m; i++)
		{
			int a, b;

			cin >> a >> b;
			a--;
			b--;

			gr[a].push_back(b);
			gr[b].push_back(a);
		}
	}

	array<vector<int>, 3> mex;

	array<ll, 3> wm{}, bm{};

	for (int i = 0; i < 3; i++)
	{
		mex[i].resize(n, -1);

		for (int j = n - 1; j >= 0; j--)
		{
			unordered_set<int> neigh;

			for (auto it : xyz[i][j])
				neigh.insert(mex[i][it]);

			for (mex[i][j] = 0; neigh.count(mex[i][j]); mex[i][j]++);
		}
	}

	array<vector<ll>, 3> grundy;

	for (int i = 0; i < 3; i++)
	{
		grundy[i].resize(*max_element(mex[i].begin(), mex[i].end()) + 1);

		for (int j = 0; j < n; j++)
			grundy[i][mex[i][j]] += powmod10(18 * (j + 1));

		for (auto &it : grundy[i])
			it %= mod;
	}

	ll ans = 0;

	for (int x = 0; x < grundy[0].size(); x++)
		for (int y = 0; y < grundy[1].size(); y++)
		{
			auto z = x ^y;

			if (z < grundy[2].size())
				ans += grundy[0][x] * grundy[1][y] % mod * grundy[2][z] % mod;
		}

	cout << ans % mod << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 26736
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
const int MX = 100000+5;
vector<int> white(MX);
vector<bool> visited(MX);
vector<pair<int, ll>> G[MX];

void dfs(int node, ll prev) {
    visited[node] = true;
    if(prev&1) white[node] = 1;
    for(auto &[a,b]: G[node]) {
        if(!visited[a]) dfs(a, (prev+b)%2);
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n; cin >> n;
    FOR(i,0,n-2) {
        int u,v; cin >> u >> v;
        u--; v--;
        ll w; cin >> w;
        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
    }

    dfs(0, 0);

    FOR(i,0,n-1) {
        cout << white[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string abc = "abc";
    string str;

    cin >> str;

    sort(str.begin(), str.end());
    if (str == abc)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end
# S = gets_s

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

s = gets_s
puts s.gsub("?","D")


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

int main()
{
    map <string, int> mp;
    map <string, int>::iterator it;
    int t,mx=0;
    cin >>t;

while(t--)
{
    string s;
    cin >> s;
    mp[s]++;
    if(mp[s] > mx)
    mx = mp[s];
}
for(it = mp.begin(); it!=mp.end(); it++)
{
    if(it ->second == mx)
        cout << it->first << endl;
}

return 0;
}

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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(0); cin.tie(0) ; cout.tie(0);
#define err(x) cerr << #x << " is : " << x << endl
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v)       v.begin() , v.end()
#define pb           push_back
#define ff           first
#define ss           second

int32_t main()
{
      tie();
      double x;
      cin >> x;
      cout << fixed << setprecision(10);
      x /= 3;
      x = x * x * x;
      cout << x << endl;
      return 0;
}


Measured memory_bytes: 256