akhauriyash/Code-Regression huggingface dataset:
L=[]
for h in range(1,150):
    for	w in range(h+1,151):
	L.append((h*h+w*w,h,w))
L.sort()
while True:
    h,w=map(int,raw_input().split())
    if h==w==0:break
    d=h*h+w*w
    for dd,dh,dw in L:
	if dd==d and dh>h:
            print dh,dw
            break
	elif dd>d:
            print dh,dw
            break

Measured memory_bytes: 5476
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
    char step[101];
    int i;

    scanf("%s", step);
    for (i=0; i<strlen(step); i++) {
        if (i%2==1) {
            if (step[i]!='L' && step[i]!='U' && step[i]!='D') {
                printf("No\n");
                return 0;
            }
        }
        else {
            if (step[i]!='R' && step[i]!='U' && step[i]!='D') {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
    int c[3][3], dYoko[3][2], dTate[2][3];
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            cin >> c[i][j];
        }
    }
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            if (j != 0) dYoko[i][j-1] = c[i][j] - c[i][j-1];
            if (i != 0) dTate[i-1][j] = c[i][j] - c[i-1][j];
        }
    }
    string result = "Yes";
    for (int i=0; i<2; i++) {
        if (dYoko[0][i] != dYoko[1][i] || dYoko[1][i] != dYoko[2][i]
            || dTate[i][0] != dTate[i][1] || dTate[i][1] != dTate[i][2]) {
            result = "No";
            break;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    string s;
    cin, k, s;
    if (s.size() > k) {
        s = s.substr(0, k) + "...";
    }
    print(s);

    return 0;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	VI a(3);
	rep(i, 3)cin >> a[i];
	SORT(a);
	int ans = a[0] == a[1] ? a[2] : a[0];
	cout << ans << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
const int N=200001;
int n,l,t,dir;
struct node{
	int pos,id,dir;
}a[N];
node b[N];
int ans[N],rk[N];

bool cmp(node x,node y)
{
	if(x.pos==y.pos) return x.id<y.id;
	return x.pos<y.pos;
}

int main()
{
	scanf("%d%d%d",&n,&l,&t);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d%d",&a[i].pos,&a[i].dir);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	rk[1]=1; int tmp=a[1].pos;
	for(int i=1;i<=n;i++)
	{
		int tmp=t;
		if(a[i].dir==1)
		{
			if(tmp>=l-a[i].pos)
			{
				rk[1]=(rk[1]+1)%n;
				tmp-=(l-a[i].pos);
			}
			rk[1]=(rk[1]+tmp/l)%n;
		}
		else
		{
			if(tmp>=a[i].pos+1)
			{
				rk[1]=(rk[1]-1+n)%n;
				tmp-=(a[i].pos+1);
			}
			rk[1]=((rk[1]-tmp/l)%n+n)%n;
		}
	}
	if(rk[1]==0) rk[1]=n;
	//cout<<rk[1]<<endl;
	for(int i=2;i<=n;i++) 
	{
		rk[i]=rk[i-1]+1;
		if(rk[i]>n) rk[i]-=n;
	}
	for(int i=1;i<=n;i++) 
	{
		if(a[i].dir==1) a[i].pos=(a[i].pos+t)%l;
		else a[i].pos=((a[i].pos-t)%l+l)%l;
		b[i]=a[i];
	}
	sort(a+1,a+n+1,cmp);
//	for(int i=1;i<=n;i++)
//	{
//		cout<<a[i].pos<<" "<<a[i].id<<endl;
//	}
	for(int i=1;i<=n;i++)
	{
		ans[b[i].id]=a[rk[i]].pos;
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

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

#define fst first
#define snd second
typedef long long ll;
typedef pair<ll, ll> pii;
const int MAXN = 500010;
int X, Y, Z, n;
pii p[MAXN];
ll q[MAXN], cnt;
ll ans, pre[MAXN], suf[MAXN], Ans;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

inline void chkmax(ll &cur, ll val) {
	if(val > cur) cur = val;
}

bool cmp(const pii &a, const pii &b) {
	return a.fst-a.snd > b.fst-b.snd;
}

int main() {
	int i;
	X = read(), Y = read(), Z = read();
	n = X+Y+Z;
	for(i = 1; i <= n; i++) {
		ll x = read(), y = read(), z = read();
		ans += x, p[i].fst = y-x, p[i].snd = z-x;
	}
	sort(p+1, p+n+1, cmp);
	for(i = 1; i <= Y; i++) {
		q[++cnt] = -p[i].fst;
		pre[Y] += p[i].fst;
	}
	make_heap(q+1, q+cnt+1);
	for(i = Y+1; i <= n-Z; i++) {
		q[++cnt] = -p[i].fst;
		push_heap(q+1, q+cnt+1);
		pop_heap(q+1, q+cnt+1);
		ll val = -q[cnt];
		cnt--;
		pre[i] = pre[i-1]+p[i].fst-val;
	}
	cnt = 0;
	for(i = n; i > n-Z; i--) {
		q[++cnt] = -p[i].snd;
		suf[n-Z+1] += p[i].snd;
	}
	make_heap(q+1, q+cnt+1);
	for(i = n-Z; i > Y; i--) {
		q[++cnt] = -p[i].snd;
		push_heap(q+1, q+cnt+1);
		pop_heap(q+1, q+cnt+1);
		ll val = -q[cnt--];
		suf[i] = suf[i+1]+p[i].snd-val;
	}
	Ans = pre[Y]+suf[Y+1];
	for(i = Y+1; i <= n-Z; i++) 
		Ans = max(Ans, pre[i]+suf[i+1]);
	printf("%lld\n", Ans+ans);
	return 0;
}


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

const int MAXN = 1e5 + 10, MAXM = 2e5 + 10;
vector<pair<int, int> > vc[MAXN];
vector<pair<int, pair<int, int> > > e;
long long d[MAXN], n, m;
bool se[MAXN];

void dfs(int v, long long dis) {
	d[v] = dis;
	se[v] = 1;
	for (int i = 0; i < vc[v].size(); i++)
		if (!se[vc[v][i].first])
			dfs(vc[v][i].first, dis + vc[v][i].second);
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int li, ri, di;
		cin >> li >> ri >> di;
		vc[li].push_back({ri, di});
		vc[ri].push_back({li, -di});
		e.push_back({di, {li, ri}});
	}
	for (int i = 1; i <= n; i++)
		if (!se[i])
			dfs(i, 0);
	for (int i = 0; i < m; i++)
		if (d[e[i].second.second] - d[e[i].second.first] != e[i].first)
			return cout << "No", 0;
	cout << "Yes";
}

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

int main(void){
    string O, E;
    cin >> O >> E;
    for(int i=0;i<O.length()+E.length();i++){
        if(i%2==0) cout << O[i/2];
        else cout << E[i/2];
    }
    cout << endl;
    return 0;
}

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

#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define int long long 

using namespace std;

const int MAXN = 1001 * 1001 , MOD = 1e9 + 7 ; 

int dp[MAXN][3] ; 

int solve(vector<int> v)
{

	int n = v.size() ; 
	if(n==1) return 0 ; 
	dp[n][0] = dp[n][1] = dp[n][2] = 0 ; 
	dp[n-1][0] = dp[n-1][1] = dp[n-1][2] = 0 ; 
	for(int i = n - 2 ; i > -1 ; i -- ) 
	{
		dp[i][0] = max({dp[i+1][1]+v[i],dp[i+2][0]+v[i+1],dp[i+1][2]+v[i+1]-1}) ; 
		if(v[i]>1) dp[i][1] = max({dp[i+1][1]+v[i]-1,dp[i+2][0]+v[i+1],dp[i+1][2]+v[i+1]-1}) ; 
		else dp[i][1] = dp[i+1][0] ;
		int x = v[i] ;
		v[i] = 1 ; 
		dp[i][2] = max({dp[i+1][1]+v[i],dp[i+2][0]+v[i+1],dp[i+1][2]+v[i+1]-1}) ; 
		v[i] = x ; 
	}
	return dp[0][0] ; 
}

int32_t main() 
{
	ios::sync_with_stdio(0) ; 
	cin.tie(0) ;
	string s ; 
	cin >> s >> s ; 
	int n = s.size() ; 
	vector<int> v ; 
	int i = 0 ; 
	while(i<n&&s[i]=='0') i ++ ; 
	if(i==n) return cout << 0 << endl , 0 ; 
	int t = i ; 
	int ans = 0 ; 
	for(int i = t ; i < n ; i ++ ) 
	{
		int j = i ; 
		while(j<n&&s[j]=='1') j ++ ; 
		v.pb(j-i) ; 
		if(j>=n-1||s[j+1]=='0') ans += solve(v) , v.clear() ; 
		while(j<n&&s[j]=='0') j ++ ;
		i = j - 1 ; 
	}
	cout << ans << endl ; 
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  ll N,D,A;
  cin >> N >> D >> A;
  vector<P> B(N);
  REP(i,N){
    cin >> B[i].first >> B[i].second;
  }
  sort(ALL(B));

  vector<ll> vec(N);
  ll right=0;
  REP(left,N){
    while(B[right].first-B[left].first<=2*D&&right<N){
      right++;
    }
    if(right==left){
      right++;
    }
    vec[left]=right;
  }

  vector<ll> imos(N+1,0);
  ll cnt = 0;
  REP(i,N){
    B[i].se-=A*imos[i];
    if(B[i].se<0){
      imos[i+1]+=imos[i];
      continue;
    }
    ll attack;
    if(B[i].se%A==0){
      attack=B[i].se/A;
    }else{
      attack=B[i].se/A+1;
    }
    imos[i]+=attack;
    imos[vec[i]]-=attack;
    imos[i+1]+=imos[i];
    cnt+=attack;
  }

  cout << cnt << endl;
}

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

int main(){
    int h,w;
    char data[55][55]={};
    cin >>h>>w;
    bool ans=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>data[i][j];
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(data[i][j]=='#'){
                ans=false;
                if(data[i][j]==data[i+1][j]){
                   ans=true;
                }

                if(data[i][j]==data[i][j+1]){
                   ans=true;
                }
                if(j!=0){
                    if (data[i][j] == data[i][j -1]){
                        ans = true;
                    }
                }

                if(i!=0){
                    if (data[i][j] == data[i-1][j]){
                        ans = true;
                    }
                }
                if(ans==false){
                    cout<<"No";
                    return 0;
                }
            }
        }
    }
    cout<<"Yes";
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int counter = 0;
  
  for (int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if(500*i+100*j+50*k == X){
          counter++;
        }
      }
    }
  }
    
    cout << counter << endl;
    return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int M,N;

  map <string,int> name;

  cin >> M >> N;

  string tmp;
  for(int i = 0 ; i < N; i++){
      tmp += to_string(M);
  }

  name[tmp];  
  tmp = "";
  for(int i = 0 ; i < M; i++){
      tmp += to_string(N);
  }
  
  name[tmp];
  for (auto i = name.begin(); i != name.end(); ++i) {
    cout << i->first << endl;
    break;
  }

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
multiset<int> S;
int P[101010];
vector<pair<int,int>> V;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	S.insert(0);
	S.insert(0);
	S.insert(N+1);
	S.insert(N+1);
	
	FOR(i,N) {
		cin>>P[i+1];
		V.push_back({P[i+1],i+1});
	}
	sort(ALL(V));
	reverse(ALL(V));
	ll ret=0;
	FORR(v,V) {
		ll num=v.first;
		int id=v.second;
		auto it=S.lower_bound(id);
		int R1=*it++;
		int R2=*it--;
		it--;
		int L1=*it--;
		int L2=*it;
		ret+=num*(R2-R1)*(id-L1);
		ret+=num*(L1-L2)*(R1-id);
		S.insert(id);
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6132
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;
int main(void)
{
	double r, m = 0, e = 0;//,p=M_PI;
	scanf("%lf", &r);
	m = M_PI * r * r ;
	e = M_PI * 2 * r ;
	printf("%.6lf %.6lf\n", m, e);
	return 0;
}


Measured memory_bytes: 3192
s = input()
ok = ['KIHBR', 'KIHBRA', 'KIHBAR', 'KIHBARA', 'KIHABR','KIHABRA', 'KIHABAR', 'KIHABARA', 'AKIHBR', 'AKIHBRA', 'AKIHBAR', 'AKIHBARA', 'AKIHABR', 'AKIHABRA', 'AKIHABAR', 'AKIHABARA']
print('YES') if s in ok else print('NO')

Measured memory_bytes: 61852
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = input.split('\n');
let str = '';

arr.forEach((elm) => {
  const item = elm.split(' ').map(Number);
  const m = item[0];
  const f = item[1];
  const r = item[2];
  const sum = m + f;
  if(m === -1 && f === -1 && r === -1) return;
  if(m === -1 || f === -1 || sum < 30) {
    str += 'F\n';
    return;
  }
  if(sum >= 80) str += 'A\n';
  if(sum >= 65 && sum < 80) str += 'B\n';
  if(sum >= 50 && sum < 65) str += 'C\n';
  if(sum >= 30 && sum < 50) {
    if(r >= 50) {
      str += 'C\n';
    } else if(r < 50) {
      str += 'D\n';
    }
  }
})

console.log(str.trim());


Measured memory_bytes: 15140
#include<iostream>
#include<string>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const bool Upstairs = true;
const bool Downstairs  = false;

int main() {
  int n;
  while (cin >> n and n) {
    int steps = 0;
    bool left = Downstairs, right = Downstairs, direction = true;
    REP(i, n) {
      string move;
      cin >> move;
      if (move == "lu" and left == Downstairs) {
        left = Upstairs;
      } else if (move == "ru" and right == Downstairs) {
        right = Upstairs;
      } else if (move == "ld" and left == Upstairs) {
        left = Downstairs;
      } else if (move == "rd" and right == Upstairs) {
        right  = Downstairs;
      }
      
      if (direction and left == Upstairs and right == Upstairs) {
        steps++;
        direction = false;
      } else if (!direction and 
          left == Downstairs and right == Downstairs) {
        steps++;
        direction = true;
      }
    }
    cout << steps << endl;
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    REP(i, n){
        cin >> a[n-1-i];
    }
    REP(i, n-1) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    return 0;
}

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

vector<vector<int>> E;
vector<int> V;

void dfs(int x, int y) {
  for (int e : E.at(x)) {
    if (y == e) continue;
    V.at(e) += V.at(x);
    dfs(e, x);
  }
}

int main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  E.resize(N + 1);
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    E.at(a).push_back(b), E.at(b).push_back(a);
  }
  V.resize(N + 1);
  for (int i = 1; i <= Q; i++) {
    int p, x;
    cin >> p >> x;
    V.at(p) += x;
  }

  dfs(1, 0);

  for (int i = 1; i <= N; i++) {
    cout << V.at(i) << "\n";
  }
}

Measured memory_bytes: 26624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ara[101],bara[101];
    cin>>n;
    int j=0;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
        if(ara[i]%2==0)
        {
            bara[j]=ara[i];
            j++;
        }
    }
    bool ok=true;
    for(int i=0;i<j;i++)
    {
        if(bara[i]%3!=0&&bara[i]%5!=0)
        {
            ok=false;
            break;
        }
    }
    if(ok)
    {
        cout<<"APPROVED"<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
    }

}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;

#define rep(i,n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x;}

const int mod = 1000000007;

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for (ll i = 2; i*i <= n; ++i) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    vector<pair<ll, int>> f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
}

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

using i64 = int64_t;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v;
    for(int i=0;i<n;++i){
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    sort(v.begin(), v.end());
    priority_queue<int> que;
    int ans = 0, idx = 0;
    for(int i=1;i<=m;++i){
        while(idx<n && i >= v[idx].first){
            que.push(v[idx].second);
            ++idx;
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
        //cerr << idx << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1908
import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val sb = StringBuilder()
    val n = br.readInt()
    val k = br.readInt()
    val a = IntArray(n) { br.readInt() }
    for (x in k until n) {
        if (a[x] > a[x - k]) {
            sb.append("Yes\n")
        } else {
            sb.append("No\n")
        }
    }
    print(sb)
}


private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}

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

int l[111111], r[111111], a[111111];
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
		l[i] = s[i] == 'L' ? l[i - 1] : i;
	for (int i = s.length(); i--;)
		r[i] = s[i] == 'L' ? i : r[i + 1];
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != 'L') a[r[i] - i & 1 ? r[i] - 1 : r[i]]++;
		else a[i - l[i] & 1 ? l[i] + 1 : l[i]]++;
	}
	for (int i = 0; i < s.length(); i++)
		cout << a[i] << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  ll n, i=2; cin >> n;
  map<int,int> mp;
  for (; i * i <= n; i++) {
    if (n % i == 0) {
      int exp = 0;
      while (n % i == 0) {
        exp++; n/=i;
      }
      mp[i] = exp;
    }
  }
  if (n != 1) mp[n]++; // y tho?
  ll res = 0;
  for (auto p : mp) {
    int exp = p.second;
    int sub = 1;
    while (exp - sub >= 0) {
      exp -= sub;
      sub++; 
      res++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3644
n, q = gets.strip.split.map(&:to_i)
s = gets.strip

t = Array.new(n + 1){0}

n.times do |i|
  ct = s[i, 2].eql?('AC') ? 1 : 0
  t[i + 1] = t[i] + ct 
end

d = q.times.map { gets.strip.split.map(&:to_i) }
d.each do |l, r|
  puts t[r-1] - t[l-1]
end


Measured memory_bytes: 11004
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int in()
{
  int x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int main()
{
  ll a = in() , b = in() , c = in() , k = in() ;
  ll ans = 0 , res = 0  ;
  if(a <= k) k -= a , res += a ;
  else  res += k , k = 0 ;
  if(b <= k) k -= b ;
  else k = 0 ;
  if(c <= k) k -= c , res -= c ;
  else res -= k , k = 0 ;
  cout << res << endl ;
  return 0 ;
}
/*
*/


Measured memory_bytes: 3160
import java.io.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;

class Main {
   final static PrintWriter out = new PrintWriter( System.out );

   final static BufferedReader in =
         new BufferedReader( new InputStreamReader( System.in ) );

   static int lcs(char[] a, char[] b){
      final int alen = a.length;
      final int blen = b.length;
      int dp[][] = new int[alen+1][blen+1];

      for(int i=0; i<alen; ++i){
         for(int j=0; j<blen; ++j){

            if(a[i] == b[j])
               dp[i+1][j+1] = dp[i][j] + 1;
            else
               dp[i+1][j+1] = max( dp[i][j+1], dp[i+1][j] );
         }
      }
      return( dp[alen][blen] );
   }

   public static void main(String[] args) throws IOException {
      final int N = parseInt( in.readLine() );
      for(int i=0; i<N; ++i){
         char[] a = in.readLine().toCharArray();
         char[] b = in.readLine().toCharArray();
         out.println( lcs(a,b) );
      }
      out.flush();
   }
}




Measured memory_bytes: 63176
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;
const double EPS = 1e-9;
void solve(){
	int n;
	cin >> n;
	vector<pair<int, int>> v(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i].first >> v[i].second;
	}
	bool pr = false;
	int cnt = 0;
	for(int i = 0; i < n; ++i){
		if(v[i].first == v[i].second)cnt++;
		else cnt = 0;
		if(cnt >= 3){
			pr = true;
			break;
		}
	}
	if(pr)cout << "Yes\n";
	else cout << "No\n";
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3656
a, b = map(int, input().split())
# print(f"{a} {b}")

ans = 0
for i in range(a, b + 1):
    if str(i) == str(i)[::-1]:
        # print(f"{str(i)} {str(i)[::-1]}")
        ans += 1

# i = a
# print(str(i))
# print(str(i)[::-1])

print(ans)

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

ll GCD (ll x, ll y){
  ll a = max(x,y);
  ll b = min(x,y);
  if(a%b == 0) return b;
  return GCD(b,a%b);
}

int main(){
  ll a, b;
  cin >> a >> b;
  ll c = GCD(a,b);
  cout << a*b/c << endl;
}


Measured memory_bytes: 256
import sys
n, x = [int(i) for i in sys.stdin.readline().split()]
cur = 1
p = 1
ls = [cur]
p_ls = [p]
for i in range(50):
    cur = cur * 2 + 3
    p = p * 2 + 1
    ls.append(cur)
    p_ls.append(p)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    if x == 1:
        return 0
    elif x <= 1 + ls[n-1]:
        return f(n-1, x-1)
    elif x == ls[n-1] + 2:
        return 1 + p_ls[n-1]
    elif x < ls[n]:
        return 1 + p_ls[n-1] + f(n-1, x - ls[n-1] - 2)
    else:
        return p_ls[n]
res = f(n, x)
print(res)

Measured memory_bytes: 3064
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100*1000+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  string s;
  cin>>s;
  int ans1=s.size(),ans2=s.size();
  for(int  i=0 ;i<s.size();i++){
    if(s[i]=='1'){
      ans1=min(ans1,max(i,(int)s.size()-i-1));
    }
  }
  for(int  i=0 ;i<s.size();i++){
    if(s[i]=='0'){
      ans2=min(ans2,max(i,(int)s.size()-i-1));
    }
  }
  cout<<max(ans1,ans2) ;
}



Measured memory_bytes: 512
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int i=Integer.parseInt(line);
        if(i<1200)
        System.out.println("ABC");
        else if(i<2800)
        System.out.println("ARC");
        else
        System.out.println("AGC");
    }
}

Measured memory_bytes: 22868
# coding: utf-8
# Your code here!
import itertools

N = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

M = 0
for i in range(N):
    S = sum(a1[:i+1]) + sum(a2[i:])
#    print(S)
    M = max(M,S)

print(M)    
    




Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int D;
	cin >> D;
	if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	if (D == 25) {
		cout << "Christmas" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    nt = set(range(n))
    kt = set(range(1, k + 1))
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in nt:
        for j in kt:
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 27548
#include<iostream>

using namespace std;

char tb[55][55];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int H,W;
int main () {
    cin >> H >> W;
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
            cin >> tb[i][j];

    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            if( tb[i][j] == '#') {
                bool flag = false;
                for(int k=0; k<4; k++) {
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if( tb[ny][nx] == '#' ) flag = true;
                }
                if(!flag) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

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

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

Measured memory_bytes: 26268
n, m = map(int, input().split())
S = [list(map(int, input().split()[1:])) for _ in range(m)]
P = list(map(int, input().split()))

count = 0
for i in range(2 ** n):

    # switch state
    switches = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            switches[j] = 1
    
    # light state
    lights = [0] * m
    for k in range(m):
        on_num = sum(map(lambda x: switches[x-1], S[k]))
        if on_num % 2 == P[k]:
            lights[k] = 1
    
    # are all lights on?
    if all(light == 1 for light in lights):
        count += 1

print(count)

Measured memory_bytes: 44296
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    output(s.substr(0, 4) + " " + s.substr(4, 8));
    
    return 0;
}

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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const LL N = 205;
const LL M = 205;
const LL INF = 0x3f3f3f3f;
const double Pi = acos(-1);
const LL MOD = 1e9+7;
const double eps = 1e-8;
LL n,m;
LL s[N];
LL S,T;
struct edge
{
    LL to,cap,rev;
};
vector <edge> G[N];
LL level[N],iter[N];
LL vis[N];
inline void add_edge(LL from,LL to,LL cap)
{
    // cout<<"ADD "<<from<<" "<<to<<" "<<cap<<endl;
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
inline void bfs (LL s)
{
    memset(level,-1,sizeof(level));
    queue <int> que;
    level[s]=0;
    que.push(s);
    while (!que.empty())
    {
        LL v=que.front();
        que.pop();
        for (LL i=0;i<G[v].size();i++)
        {
            edge &e= G[v][i];
            if (e.cap>0&&level[e.to]<0)
            {
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}
inline LL dfs(LL v,LL t,LL f)
{
    if (v==t)
        return f;
    for (LL &i=iter[v];i<G[v].size();i++)
    {
        edge &e=G[v][i];
        if (e.cap>0&&level[v]<level[e.to])
        {
            LL d=dfs(e.to,t,min(f,e.cap));
            if (d>0)
            {
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
inline LL max_flow(LL s,LL t)
{
    LL flow=0;
    for (;;)
    {
        bfs(s);
        if (level[t]<0)
            return flow;
        memset(iter,0,sizeof(iter));
        LL f;
        while ((f=dfs(s,t,INF))>0)
            flow+=f;
    }
}

inline void ini()
{
    S=0,T=n+1;
    for (LL i=0;i<=n+1;i++)
        G[i].clear();
}
int main()
{
    while (~scanf("%lld",&n))
    {
        ini();
        LL ans = 0;
        LL sum=0;
        for (LL i=1;i<=n;i++)
        {
            scanf("%lld",&s[i]);
            sum += s[i];
            if (s[i]<0)
                ans -= s[i];
            if (s[i]<0)
                add_edge(i,T,-s[i]);
            else
                add_edge(S,i,s[i]);
        }
        for (LL i=1;i<=n;i++)
            for (LL j=i+i;j<=n;j+=i)
                add_edge(j,i,INF);
        LL tmp = max_flow(S,T);
        // cout<<"bug "<<ans<<" "<<tmp<<endl;
        printf("%lld\n",sum+(ans-tmp));
    }
    return 0;
}

/*

6
1 2 -6 4 5 3

6
100 -100 -100 -100 100 -100

5
-1 -2 -3 -4 -5

2
-1000 100000

*/

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int i,flag=0;
    long double n,ans,a[100010]={};
    scanf("%llf",&n);
    for(i=0; i<n-0.1; i++){
        scanf("%llf",&a[i]);
        if(a[i]==0){
            printf("0");
            return 0;
        }
    }
    ans=1;
    for(i=0; i<n-0.1; i++){
        ans*=a[i];
        if(ans>1000000000000000000){
            printf("-1");
            return 0;
        }
    }
    printf("%0.llf",ans);
    return 0;
}

Measured memory_bytes: 3316
a,b,k = map(int,input().split())

for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        c = a // 2
        a -= c
        b += c
    else:
        if b % 2 == 1:
            b -= 1
        c = b // 2
        b -= c
        a += c
print(a,b)


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>

int main(void){

double a,b,C,c,rad;
double S,L,h;
double PI = acos(-1);
	
	scanf("%lf %lf %lf",&a,&b,&C);
	
	rad = C * PI / 180;
	
	S = 0.5*a*b*sin(rad);
	
	c = (a*a) + (b*b) - 2*a*b*cos(rad);
	L = a+b+sqrt(c);
	
	h = S/(0.5*a);
	
	printf("%lf\n%lf\n%lf\n",S,L,h);
	

return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int sum=0;
  int N;
  cin >> N;
  vector<int> d(N);
  REP(i,N) cin >> d[i];
  REP(i,N-1) {
     FOR(j,i+1,N) {
      sum += d[i]*d[j];
     }
  }
  cout << sum << endl;
}

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

using namespace std;

int main(){
    long long int N,Q,ans=0;
    cin >> N;
    vector<long long int> A(N);
    map<long long int,long long int> mp;
    for(int i=0;i<N;i++){
        cin >> A[i];
        ans += A[i];
        mp[A[i]]++;
    }

    cin >> Q;

    for(int i=0;i<Q;i++){
        long long int B,C;
        cin >> B >> C;
        ans += mp[B]*(C-B);
        mp[C] += mp[B];
        mp[B] = 0;
        cout << ans << endl;
    }
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int a,b,k;

int main(){
  cin >> k;
  cin >> a >> b;
  for(int i=a;i<=b;++i){
    if(i%k==0){cout << "OK";return 0;}
  }
  cout << "NG";
  return 0;
}


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

#define MAXN (100010)

int n, l, t;
int x[MAXN];

int main(){
	scanf("%d%d%d", &n, &l, &t);
	long long cnt = 0;
	for (int i = 0, w; i < n; ++ i){
		scanf("%d%d", &x[i], &w);
		if(w == 1){
			x[i] += t;
			cnt += x[i] / l;
			x[i] %= l;
		}
		else{
			x[i] -= t;
			cnt += x[i] / l;
			x[i] %= l;
			if(x[i] < 0){
				x[i] += l;
				-- cnt;
			}
		}
	}
	std::sort(x, x + n);
	cnt %= n;
	cnt = (cnt + n) % n;
	for(int i = 0; i < n; ++ i){
		printf("%d\n", x[(i + cnt) % n]);
	}
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ss second
#define ff first 
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0)return (power((x*x)%M,n/2))%M;else return ((x%M)*power(x,n-1)%M);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
    for (ll i = 1; i <= n; i++){ 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll ncrmod(ll n, ll r, ll p){ 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
   return (ncrmod(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p;  
} 
ll modInverse(ll a,ll m) 
{ 
   ll m0 = m; 
   ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
       ll q = a / m; 
       ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
const int m=1000001;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str,ptr;
cin>>str>>ptr;
int l1=str.length();
int l2=ptr.length();
int g=0,ans=l2;
for(int i=0; i<l1; i++){
int f=0;
int k=i;
if(l1-k>=l2){
for(int j=0; j<l2; j++){
if(str[k]!=ptr[j]){
f+=1;
}
k+=1;
}
if(f==0){
g+=1;
cout<<"0";
break;
}else{
ans=min(ans,f);
}
}
}
if(g==0)
cout<<ans;
return 0;
}

Measured memory_bytes: 3684
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

      
 public static void main(String[] args) {
    
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
    int W = in.nextInt();
    long[][] dp = new long[N+1][W+1];
    
    for (int i = 1 ; i <= N; ++i) {
        int wi = in.nextInt();
        int vi = in.nextInt();
        for(int w = 0; w <= W; w++) {
            if(w >= wi) {
                dp[i][w] = Math.max(dp[i-1][w], vi+dp[i-1][w-wi]);
            }
            else {
                dp[i][w] = dp[i-1][w];
            }
        }
    }
    
    System.out.println(dp[N][W]);
  }
  
}

Measured memory_bytes: 126164
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int N, vector<double> const &probs) {
  vector<vector<double>> dp(N+1, vector<double>(N+1, 0));
  dp[0][0] = 1;
  REP(i, N) FOR(k, 0, i) {
    dp[i+1][k+1] += dp[i][k] * probs[i];
    dp[i+1][k]   += dp[i][k] * (1-probs[i]);
  }
  double ans = 0;
  FOR(i, (N+2)/2, N) {
    ans += dp[N][i];
  }
  cout << ans << endl;
}

int main() {
  cout << fixed << setprecision(10);
  int N; cin >> N;
  vector<double> probs;
  REP(i, N) {
    double P;
    cin >> P;
    probs.push_back(P);
  }
  solve(N, probs);
  return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

char buf[32];
int cnt = 0;

void insertionSort(int *a, int n, int g)
{
  int i, j, v;
  for (i=g; i < n; i++) {
    v = a[i];
    j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j+g] = a[j];
      j -= g;
      cnt++;
    }
    a[j+g] = v;
  }
}


void shellSort(int *a, int n)
{
  int i, j, g, m=0;
  m = (int)(log(2*n+1)/log(3));
  int G[m];
  for (i=m; i>0; i--) {
    G[m-i]= (pow(3,i)-1)/2;
  }
  for (i=0; i<m; i++) {
    g = G[i];
    insertionSort(a, n, g);
  }

  buf[31]=0;
  buf[30]='\n';
  i=30;
  int d = m;
  if (d>0)  for (; d>0; buf[--i]='0'+d%10,d/=10);
  else  buf[--i] = '0';
  fputs(buf+i, stdout);

  buf[30]=' ';
  for (i=0; i<m-1; i++) {
    for (j=30; G[i]>0; buf[--j]='0'+G[i]%10,G[i]/=10);
    fputs(buf+j, stdout);
  }
  buf[30]='\n';
  for (j=30; G[i]>0; buf[--j]='0'+G[i]%10,G[i]/=10);
  fputs(buf+j, stdout);

  j=30;
  if (cnt>0)
    for (; cnt>0; buf[--j]='0'+cnt%10,cnt/=10);
  else  buf[--j] = '0';
  fputs(buf+j, stdout);
  
  for (i=0; i<n; i++) {
    j=30;
    if (a[i]>0)
      for (; a[i]>0; buf[--j]='0'+a[i]%10,a[i]/=10);
    else  buf[--j] = '0';
    fputs(buf+j, stdout);
  }
}

int main()
{
 int i, n;
 char *p;
 fgets(buf, 32, stdin);
 for (n=0, p=buf; *p!='\n'; p++)  n = n * 10 + *p - '0';
 int *a = (int *)malloc(sizeof(int)*n);

 for (i=0; i<n; i++) {
   fgets(buf, 32, stdin);
   for (a[i]=0, p=buf; *p!='\n'; p++)  a[i] = a[i] * 10 + *p - '0';
 }
 shellSort(a, n);
	 
 return 0;
}



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

int main(){
	int n,A[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<n;i++){
		if(i>0) cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	for(int i=1;i<n;i++){
		int v=A[i];
		int j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		for(int k=0;k<n;k++){
			if(k>0) cout<<" ";
				cout<<A[k];
		}
		cout<<endl;
	}
		return 0;
}

Measured memory_bytes: 3104
import java.util.HashMap;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long A=stdIn.nextLong();
		long B=stdIn.nextLong();
		long a=0,b=0,k=2;
		int ans=0;
		while(true){
			if(A%B!=0){
				a=A%B;
				A=B;B=a;
			}
			else
				break;
		}a=B;b=a/2+1;
		HashMap<Long,Boolean> c=new HashMap<Long,Boolean>();
		while(true){
			while(k<=Math.sqrt(a)){
				if(a%k!=0)
					k+=2;
				else
					break;
				if(k==4)
					k=3;
			}
			if(a%k!=0){
				if(a!=1)
					ans++;
				break;
			}
			b=a/k;
			if(c.containsKey(a/b)==false){
				ans++;
				c.put(a/b,true);
				while(true){
					if(b%k!=0)
						break;
					b/=k;
				}
			}
			if(b==1)
				break;
			a=b;k+=2;
			if(k==4)
				k=3;
		}
		ans++;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (a[i] > i + 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	vint ans(n);
	int cnt = n;
	int tmp;
	drep(i, n) {
		tmp = cnt;
		drep(j, n) {
			if (a[j] == tmp) {
				ans[i] = tmp;
				a[j] = -1;
				break;
			}
			if (a[j] != -1) {
				tmp--;
			}
		}
		cnt--;
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  string output="";
  for (int i = 0; i < w+2; ++i) {
    output+="#";
  }
  output+="\n";
  for (int i = 0; i < h; ++i) {
    string line;
    cin >> line;
    output+="#"+line+"#\n";
  }
  for (int i = 0; i < w+2; ++i) {
    output+="#";
  }
  cout << output << endl;
  return 0;
}


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

Measured memory_bytes: 256
H, W, K = map(int, input().split())
mod = 10 ** 9 + 7
F = [1, 1, 2, 3, 5, 8, 13, 21, 34]
inv_F = pow(F[W], mod - 2, mod)
P = [[0 for w in range(W + 2)] for h in range(H + 1)]
P[0][1] = 1

for h in range(1, H + 1):
    for w in range(1, W + 1):
        P[h][w] = (P[h - 1][w - 1] * F[w - 2] * F[W - w] % mod
                   + P[h - 1][w] * F[w - 1] * F[W - w] % mod
                   + P[h - 1][w + 1] * F[w - 1] * F[W - w - 1] % mod) * inv_F % mod

print(P[H][K] * pow(F[W], H, mod) % mod)


Measured memory_bytes: 3064