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

using namespace std;
typedef long long ll;
ll n;
ll a,b,c,d;
bool exist;
int main() {
  cin >> n >> a >> b >> c >> d;
  ll ans = abs(a - b);

  exist = false;

  for(ll i = 0; i < n; i++) {
    ll x = n - 1 - i;
    ll y = i;
    if(d * x - y * c >= ans && c * x - y * d <= ans) exist = true;
  }

  if(exist) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
int a[105];
int rsq[105];
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N;
	cin>>N;
	int sum=0;
	rsq[0]=0;
	for(int i=1;i<=N;i++){
		cin>>a[i];
		sum+=a[i];
		rsq[i]=rsq[i-1]+a[i];
	}
	int ans=1e9;
	for(int i=1;i<=N;i++){
		ans=min(ans,abs(sum-2*rsq[i]));
	}
	cout<<ans;
}

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

int main(){
    string S;
    cin >> S;
    vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    map<string, int> dict;
    for(int i=0;i<7;i++) dict[days[i]] = 7-i;
    cout << dict[S] << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for j in range(int(input())):
        x,y=map(int,input().split())
        B[x-1]=str(y)
    A.append("".join(B))

ans=0
for i in range(2**n):
    num=format(i, "b").zfill(n)
    flag,cnt=1,0
    for j,k in enumerate(num):
        result=re.fullmatch(r"".join(A[j]),num)
        if result is not None and k=="1":
            cnt +=1
        elif (result is not None and k=="0") or (result is None and k=="1"):
            flag=0
            break
    if flag:ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
ll rest=998244353;
int main(){
  ll n;
  cin>>n;
  vector<ll> d(n);
  rep(i,n)cin>>d[i];
  ll ans=1;
  vector<ll> k(n,0);
  if(d[0]!=0)ans=0;
  sort(d.begin(),d.end());
  k[0]=1;
  int count=1;
  rep1(i,n-1){
    if(d[i]==0)break;
    k[d[i]]++;
    ans=ans*k[d[i]-1];
    ans=ans%rest;
    }
  if(d[1]==0)ans=0;
  if(d[0]!=0)ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import static java.lang.System.*;
import static java.lang.Math.*;

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

    int[] A = new int[n];
    int[] L = new int[n];

    for (int i = 0; i < n; i++) {
      A[i] = sc.nextInt();
    }
    sc.close();

    L[0] = A[0];
    int length = 1;

    for (int i = 1; i < n; i++) {
      if(L[length-1] < A[i]){
        L[length++] = A[i];
      }else{
        int index = ~Arrays.binarySearch(L, 0, length, A[i]);
        if (index < 0) index = ~index;
        L[index] = A[i];
      }
    }

    out.println(length);
	}
}


Measured memory_bytes: 69856
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define equals(a,b) fabs((a) - (b)) < EPS

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

struct Point3D {
	double x, y, z;

	Point3D() : x(0), y(0), z(0) {}

	Point3D(double x, double y, double z) : x(x), y(y), z(z) {}

	Point3D operator+(const Point3D &o) const { return Point3D(x+o.x, y+o.y, z+o.z); }

	Point3D operator-(const Point3D &o) const { return Point3D(x-o.x, y-o.y, z-o.z); }

	Point3D operator*(const double m) const { return Point3D(x*m, y*m, z*m); }

	Point3D operator/(const double d) const { return Point3D(x/d, y/d, z/d); }

	bool operator==(const Point3D &o) const { return fabs(x-o.x) < EPS && fabs(y-o.y) < EPS; }
};

ostream& operator << (ostream& os, const Point3D& p) {
	os << "(" << p.x << ", " << p.y << ", " << p.z << ")";
	return os;
}

double dot(Point3D a, Point3D b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
Point3D cross(Point3D a, Point3D b) { return Point3D(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); }

double norm(Point3D p) { return dot(p, p); }
double abs(Point3D p) { return sqrt(norm(p)); }

struct Line {
	Point3D a, b;

	Line() : a(Point3D(0, 0, 0)), b(Point3D(0, 0, 0)) {}

	Line(Point3D a, Point3D b) : a(a), b(b) {}
};

ostream& operator << (ostream& os, const Line& l) {
	os << "(" << l.a.x << ", " << l.a.y << ", " << l.a.z <<  ")-(" << l.b.x << "," << l.b.y << ", " << l.b.z <<  ")";
	return os;
}

Point3D project(Line l, Point3D p) {
	Point3D base = l.b - l.a;
	double t = dot(base, p-l.a) / dot(base, base);
	return l.a + base * t;
}

struct Ball {
	Point3D p;
	double r;

	Ball() : p(Point3D(0, 0, 0)), r(0.0) {}

	Ball(Point3D p, double r) : p(p), r(r) {}
};

ostream& operator << (ostream& os, const Ball& b) {
	os << "(" << b.p.z << ", " << b.p.y << ", " << b.p.z << " :" << b.r << ")";
	return os;
}

int main() {
	int n, q;
	cin >> n >> q;

	vector<Ball> v(n);
	vector<ll> cost(n);
	rep(i, n) {
		cin >> v[i].p.x >> v[i].p.y >> v[i].p.z >> v[i].r >> cost[i];
	}

	rep(i, q) {
		ll ans = 0;
		Point3D s, t;
		cin >> s.x >> s.y >> s.z >> t.x >> t.y >> t.z;

		Line line(s, t);

		rep(j, n) {
			Point3D proj = project(line, v[j].p);

			if(abs(line.b - line.a) >= abs(proj - line.a) && abs(line.a - line.b) >= abs(proj - line.b)) {
				if(abs(proj - v[j].p) <= v[j].r + EPS) {
					ans += cost[j];
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
//
// Created by Ryuta Kremer on 2018-12-08.
//

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> h;

int main()
{
    int k, n;
    ll ans = 1e10;
    cin>>n>>k;

    REP(i,n) {
        ll tmp;
        cin>>tmp;
        h.push_back(tmp);
    }
    SORT(h);

    REP(i,n-k+1) {
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1400
//
// Created by Tetsuya Shiota on 2019-04-13.
//

#include<iostream>
#include<vector>


using namespace std;

class Solver{
public:
    vector<vector<bool>> edge;
    int N, M;
    Solver(){
        cin >> N >> M;

        for(int i = 0; i<N; i++){
            edge.push_back(vector<bool>(N));
            for(int j=0;j<N;j++){
                edge[i][j] = false;
            }
        }

        for(int i =0; i<M; i++){
            int a, b;
            cin >> a >> b;
            a--;b--;
            edge[a][b] = edge[b][a] = true;
        }
    }

    int solve(int now, int cnt, vector<bool> &visited){
        if(cnt == N)return 1;

        int ret = 0;
        visited[now] = true;
        for(int i = 0; i<N; i++){
            if(visited[i])continue;
            if(!edge[now][i])continue;
            ret += solve(i, cnt+1, visited);
        }
        visited[now] = false;

        return ret;
    }

    int solve(){
        int now = 0;
        vector<bool> visited(N);
        return solve(now, 1, visited);
    }
};


int main(){
    auto solver = Solver();
    cout << solver.solve() <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 65;

int l, r;
int dp[N][2][2][2];

int solve(int idx, bool equal_L, bool equal_R, bool start){
   if(idx < 0){
      return start == 1;
   }

   int &ans = dp[idx][equal_L][equal_R][start];
   if(~ans)
      return ans;

   ans = 0;

   bool nf1 = equal_R, nf2 = equal_L;
   int bit_R = (r & (1LL << idx)) > 0;
   int bit_L = (l & (1LL << idx)) > 0;

   for (int i = 0; i < 2; ++i)
   {
      for (int j = 0; j < 2; ++j)
      {
         if(j > i)
            continue;
         bool tnf1 = nf1, tnf2 = nf2;
         if(nf1 == 1 and i > bit_R){
            continue;
         }
         else if(nf1 == 1 and i < bit_R){
            tnf1 = 0;
         }

         if(nf2 == 1 and j < bit_L){
            continue;
         }
         else if(nf2 == 1 and j > bit_L){
            tnf2 = 0;
         }

         if(start == 0){
            if(i != j)
               continue;
         }
         bool nstart = start;
         nstart |= (i > 0 && j > 0);
         ans += solve(idx-1, tnf2, tnf1, nstart);
         ans %= mod;
      }
   }

   return ans;
}

int32_t main(){_

   cin >> l >> r;
   memset(dp, -1, sizeof dp);

   cout<<solve(63, 1, 1, 0);

   return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc128/tasks/abc128_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N, M = map(int, input().split())

    S = []
    for _ in range(M):
        ks = list(map(int, input().split()))
        S.append(ks[1:])

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

    # print(S)
    # print(P)

    ans = 0
    # Bit 全探索
    pattern = 1 << N
    for i in range(pattern):
        scope = []
        for j in range(N):
            if (i >> j) & 1:
                scope.append(j + 1)

        if len(scope) > 0:
            turn_on = True
            for j in range(len(S)):
                switches = S[j]
                c = 0
                for states in scope:
                    if states in switches:
                        c += 1
                if c % 2 != P[j]:
                    turn_on = False
                if not turn_on:
                    break
            if turn_on:
                # print('ok = {}'.format(scope))
                ans += 1
        else:
            turn_on = True
            for j in range(len(S)):
                if P[j] != 0:
                    turn_on = False
            if turn_on:
                ans += 1


    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41456
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	// mahakal();fast;

	ll n , m ;
	cin>>n>>m;
	if(n>=m){
		for(ll i=0;i<n;i++)cout<<m;
	}
	else for(ll i=0;i<m;i++)cout<<n;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int check(const char* str) {
	static const char* aidu="AIDUNYAN";
	int count[26]={};
	int i;
	for(i=0;aidu[i];i++)count[aidu[i]-'A']++;
	for(i=0;str[i] && i<8;i++)count[str[i]-'A']--;
	for(i=0;i<26;i++) {
		if(count[i]!=0)return 0;
	}
	return 1;
}

void put(char* str) {
	static const char* aizu="AIZUNYAN";
	int i;
	for(i=0;aizu[i];i++)str[i]=aizu[i];
}

int main(void) {
	char str[1024];
	int i;
	scanf("%s",str);
	for(i=0;str[i];i++) {
		if(check(&str[i])) {
			put(&str[i]);
			i+=7;
		}
	}
	puts(str);
	return 0;
}

Measured memory_bytes: 524
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        HashSet<Integer> hs = new HashSet<>();
        int n = Integer.parseInt(br.readLine());

        boolean dis = true;
        st = new StringTokenizer(br.readLine());
        for(int i=0 ; i<n ; i++) {
            int x = Integer.parseInt(st.nextToken());
            if(hs.contains(x)) {
                dis = false;
                break;
            }
            else {
                hs.add(x);
            }
        }

        if(dis) pw.println("YES");
        else pw.println("NO");
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 55032
#include <stdio.h>
int main(void)
{
int n,S[10000],i,j,q,T[500],t,C;
	scanf("%d",&n);
	for(i=0;i!=n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(j=0;j!=q;j++){
		scanf("%d",&T[j]);
	}
	C=0;
	for(i=0;i!=q;i++){
		for(t=0;t!=n;t++){
			if(T[i]==S[t]){
				C=C+1;
				break;
			}
		}
	}
	printf("%d\n",C);
	return 0;
}

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

#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define N 1000001


int32_t main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, k; cin >> n >> k;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec[i];
	vector<int> dp(n, INT_MAX); // dp[i] the cost to reach ith height....
	dp[0] = 0; 		// the initial height on which the frog is present initially.
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			int m = i - j;
			if (m < 0)
				break;
			else
				dp[i] = min( dp[i], dp[i - j] + abs(vec[i - j] - vec[i]));

		}
	}
	cout << dp[n - 1] << endl;

}







Measured memory_bytes: 4776
import math

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

total = a**2*b

if x >= total / 2:
    print(math.degrees(math.atan( (total-x) / (0.5*a**3 ))))
else:
    print(90-math.degrees(math.atan( (x) / (0.5*a*b**2 ))))




Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

long long mmax(long long x, long long y) {
	if (x > y) return x;
	else return y;
}


int main() {
	int n;
	cin >> n;
	Graph abc(n);
	rep(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		abc[i].push_back(a);
		abc[i].push_back(b);
		abc[i].push_back(c);
	}

	long long dp[100009][3];
	rep(i, 100009) rep(j, 3) dp[i][j] = 0;
	dp[0][0] = abc[0][0];
	dp[0][1] = abc[0][1];
	dp[0][2] = abc[0][2];
	rep(i, n - 1) {
		rep(j, 3) {
			long long x = dp[i][(j + 1) % 3];
			long long y = dp[i][(j + 2) % 3];
			dp[i + 1][j] = mmax(x, y) + abc[i + 1][j];
		}
	}
	//rep(i, n) rep(j, 3)
	//	cout << i << j << ":" << dp[i][j] << endl;

	long long ans = 0;
	rep(i, 3) ans = mmax(ans, dp[n - 1][i]);
	cout << ans << endl;
}

Measured memory_bytes: 8064
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int n,k; cin >> n >> k;
    vector<int> a(n);
    vector<ll> s(n+1);
    s[0] = 0;
    REP(i, n) {
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    REP(i, n+1) {
        s[i] = (s[i] - i) % k;
    }
    map<int, int> mp;
    ll ans = 0;
    REP(i, n+1) {
        if (i >= k) mp[s[i - k]]--;
        ans += mp[s[i]];
        mp[s[i]]++;
    }
    cout << ans << endl;
    return 0;
}

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

bool isOP(string s) {
    return s[0] == '+' || s[0] == '-' || s[0] == '*';
}

long long calc(stack<string>& st) {
    long long res = 0;
    if (isOP(st.top())) {
        string s = st.top();
        st.pop();

        long long a = calc(st);
        long long b = calc(st);
 
        switch (s[0]) {
            case '+':
                res = b + a;
                break;
            case '-':
                res = b - a;
                break;
            case '*':
                res = b * a;
                break;
            default:
                break;
        }
    } else {
        res = stoi(st.top());
        st.pop();
    }
    return res;
}

int main() {
    stack<string> st;
    
    string in;
    while (cin >> in) {
        st.push(in);
    }
    
    cout << calc(st) << endl;
}



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

const int divisor = 1000000007;

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

	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		int* word = new int[N];
		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
			}
			else {
				bubblenum = bubblehist.rbegin()->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(--it, p);
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}

		delete[] word;
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << "\n";
	}

	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6868
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 21972
// Aizu Vol-10 1023: Amazing Graze
// 2017.8.20 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MAX 100000
typedef struct { int x, y, e; } T; 
T a[MAX+5];
int AN, BN, R;

int cmp(T *a, T *b) { return a->x - b->x; }

int bsch(int x)
{
	int m, l = 0, r = AN;
    while (l < r) {
        m = (l + r) >> 1;
        if (a[m].x <= x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int x, y;
	int i, j, k, r, t;

	while (scanf("%d%d%d", &AN, &BN, &R) && AN) {
		for (i = 0; i < AN; i++) scanf("%d%d", &a[i].x, &a[i].y), a[i].e = 0;
		qsort(a, AN, sizeof(T), cmp);
		r = (R*R) << 4;
		for (i = 0; i < BN; i++) {
			scanf("%d%d", &x, &y);
			j = bsch(x);
			while (j >= 0 && (a[j].x-x)*(a[j].x-x) <= r) j--;
			for (j++, k = 0; j < AN && ((t = (a[j].x-x)*(a[j].x-x)) <= r || k < 3); k++, j++) {
				if (t + (a[j].y-y)*(a[j].y-y) <= r) a[j].e++;
			}
		}
		for (t = i = 0; i < AN; i++) t += a[i].e;
		printf("%d\n", t);
	}
	return 0;
}

Measured memory_bytes: 3388
// ABC067B - Snake Toy

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

int main() {
	int N, K;
	cin >> N >> K;

	vector<int> l(N);
	for (int i = 0; i < N; i++) {
		cin >> l.at(i);
	}

	sort(l.begin(), l.end(), greater<int>());

	int sum = 0;
	for (int i = 0; i < K; i++) {
		sum += l.at(i);
	}

	cout << sum << endl;

	return 0;
}


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

ll ary[1000005]={0};
void solve1();
void solve()
{
    int t;cin>>t;
    while(t--)
    {
        solve1();
    }
}
int main()
{
    solve1();
    return 0;
}
void solve1()
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<0<<endl;
        return;
    }
    if(n==2)
    {
        cout<<1<<endl;return;
    }
    ll arr[101]={0};
    arr[0]=1;arr[1]=1;
    for(int i=2;i<101;i++)
    {
        arr[i]=arr[i-1]+i;
    }
    ll b=2;
    while(b<=((ll)sqrt(n)))
    {
        if(n%b==0)
        {
            ary[b]++;
            n/=b;
        }
        else
        {
            b++;
        }
    }
    ll ans=0;
    if(n<1000000)
    {ary[n]++;}
    else
    {
        ans++;
    }
    for(int i=2;i<1000005;i++)
    {
        if(ary[i]>0)
        {
            ll j=1;
           // cout<<i<<endl;
            while(ary[i]>=arr[j+1])
            {
                j++;
            }
            ans+=j;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define alpha_size 26


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
    
    map<string, int> m;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
      string s;
      cin >> s;
      m[s]++;
    } 
    cout << m.size() << endl;
}


Measured memory_bytes: 19284
// B - Ringo's Favorite Numbers
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int D,N; cin>>D>>N;
	int s = 1; rp(i, 0, D) s*=100;
	int ans = s*N;
	if(ans%(s*100)==0) ans += s;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
H = read_ints()

# https://atcoder.jp/contests/dp/tasks/dp_a
# 全探索ではナンセンス(というより処理が終わらない)
# i+1 or i+2のうち小さい方を選びつづければいいということにすぐに気がつく
# こういったように、今の状態から次の状態が決まるときはDPが使えることがおおい(この問題はgreedy気味にも捉えることができるが。)
# 途中までの状態が決まれば、最善手を選ぶことで次の状態が決定できるのを実装する。
# 今回の場合だったらhまでの最善の状態というのはmin(2つ前までの最善の状態+差, 1つ前までの最善の状態+差)なのでこれでdpテーブルを埋めていくことができる。

import numpy as np
dp = np.full((N), np.inf, dtype='int64')
dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(H[i - 1] - H[i]),
                dp[i - 2] + abs(H[i] - H[i - 2]))

print(dp[-1])


Measured memory_bytes: 17196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,count=0,times=100000;

  cin >> N;

  vector<int> A(N);
  
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }//入力終了

/*
   for(int x : A){
    cout << x <<" ";
  }//入力確認
*/

  for(int x : A){
    int div=0;
    while(x%2 == 0){
      div++;
      x/=2;
    }
    if(times>div) times=div; 
  }


  cout << times << endl;
 
  return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  int ans = 0;
  function<void(int, vector<int> &)> dfs = [&](int n, vector<int> &A) {
    if (n == N) {
      int pts = 0;
      for (int j = 0; j < Q; j++) {
        if (A[b[j]] - A[a[j]] == c[j]) pts += d[j];
      }
      // dmp(A);
      chmax(ans, pts);
      return;
    }
    int lb = (n == 0) ? 1 : A.back();
    for (int i = lb; i <= M; i++) {
      A.push_back(i);
      dfs(n + 1, A);
      A.pop_back();
    }
  };
  vector<int> AA;
  dfs(0, AA);
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


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

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

	if(s == "Sunny"){
		cout<<"Cloudy"<<endl;
	}else if (s == "Cloudy"){
		cout << "Rainy"<<endl;
	}else if (s == "Rainy"){
		cout << "Sunny" <<endl;
	}else{
		return 0;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

struct edge{
	int l, r;
	ll c;
};

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


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

	int n, m;
	cin >> n >> m;

	vector<edge> edges;
	rep(i, m){
		int l, r;
		ll c;
		cin >> l >> r >> c;
		l--; r--;
		edges.push_back((edge){l, r, c});
	}

	sort(edges.begin(), edges.end(), [](edge e1, edge e2){
		return e1.r < e2.r;
	});

	ll INF = LLONG_MAX / 2;
	SegmentTree<ll> seg(n, [](ll a, ll b) { return min(a, b); }, INF);
	seg.update(0, 0);
	for(edge e : edges){
		ll mn = seg.query(e.l, e.r);
		ll val = seg.query(e.r, e.r+1);
		seg.update(e.r, min({val, mn + e.c, INF}));
	}

	ll ans = seg.query(n - 1, n);
	if(ans == INF){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}

}


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

using namespace std;
typedef long long ll;
string s;
int N,P;
ll c[10005];

int main(){
    cin>>N>>P>>s;
    if(P==5||P==2){
        ll ans=0;
        for(ll i=0;i<N;i++)if((s[i]-'0')%P==0)ans+=i+1LL;
        cout<<ans;
        return 0;
    }
    c[0]=1LL;
    ll ans=0;
    int num=0;
    int pot=1;
    for(int i=N-1;i>=0;i--){
        num=(num+pot*(s[i]-'0'))%P;
        pot=(pot*10)%P;
        ans+=c[num];
        c[num]++;
    }
    cout<<ans;
}

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

using namespace std;

typedef long long ll;

ll get(ll n, ll x) {
	if (!(n % x))
		return (n / x * 2 - 1) * x;
	return get(x, n % x) + n / x * x * 2;
}

ll n, x;

int main(){
	cin >> n >> x;
	cout << get(max(n - x, x), min(x, n - x)) + n << '\n';
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	ps := ReadInts(N)

	s := make([]float64, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + e(ps[i])
	}

	ans := 0.0
	for i := 0; i < N-(K-1); i++ {
		partialSum := s[i+K] - s[i]
		ans = Max(ans, partialSum)
	}
	fmt.Println(ans)
}

func e(p int) float64 {
	return (1 + float64(p)) / 2.0
}

func Max(xs ...float64) float64 {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 5952
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

bool decending(const pair<int,int> & m1, const pair<int,int> & m2) {
    return m1.second>m2.second;
}

int main(){
    int N;
    cin>>N;
    int a[N];
    int count;
    map<int,int> map_odd;
    map<int,int> map_even;
    for(int i = 0;i<N;i+=1){
        int temp;
        cin>>temp;
        if(i%2==0) {
            std::map<int,int>::iterator it;
            it = map_odd.find(temp);
            if(it==map_odd.end())
                map_odd.insert(pair<int,int>(temp,1));
            else
                it->second+=1;
        }
        else {
            std::map<int,int>::iterator it;
            it = map_even.find(temp);
            if(it==map_even.end())
                map_even.insert(pair<int,int>(temp,1));
            else
                it->second+=1;
        }
    }
    vector<pair<int,int>> vector_odd(map_odd.begin(),map_odd.end());
    vector<pair<int,int>> vector_even(map_even.begin(),map_even.end());
    sort(vector_odd.begin(),vector_odd.end(),decending);
    sort(vector_even.begin(),vector_even.end(),decending);
    if(vector_odd[0].first==vector_even[0].first){
        if(vector_even.size()==1)
            count = vector_even[0].second;
        else{
            if(vector_even[1].second>vector_odd[1].second)
                count = N-vector_odd[0].second-vector_even[1].second;
            else
                count = N-vector_even[0].second-vector_odd[1].second;
        }

    }else{
        count = N-vector_odd[0].second-vector_even[0].second;
    }
    cout<<count<<endl;
};


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

int main()
{
  int H, W;

  while (true) {
    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }
    for (int i = 0; i < H; i ++) {
      for (int j = 0; j < W; j ++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define inf 100000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector <int> A(a),B(b),C(c);
    for(int i=0;i<a;i++)
        cin>>A[i];
    for(int i=0;i<b;i++)
        cin>>B[i];
    for(int i=0;i<c;i++)
        cin>>C[i];
    sort(begin(A),end(A));
    sort(begin(B),end(B));
    sort(begin(C),end(C));
    int ans=0;
    priority_queue <int, vector <int> , greater <int> > pq1,pq2;
    priority_queue <int> pq3;
    for(int i=a-x;i<a;i++)
        pq1.push(A[i]);
    for(int i=b-y;i<b;i++)
        pq2.push(B[i]);
    for(int x:C)
        pq3.push(x);
    while(!pq3.empty()){
        int v=pq3.top();
        pq3.pop();
        if(v<pq1.top()&&v<pq2.top())
            break;
        if(pq1.top()>pq2.top()){
            pq2.pop();
            pq2.push(v);
        }
        else{
            pq1.pop();
            pq1.push(v);
        }
    }
    while(!pq1.empty()||!pq2.empty()){
        if(!pq1.empty()){
            ans+=pq1.top();
            pq1.pop();
        }
        if(!pq2.empty()){
            ans+=pq2.top();
            pq2.pop();
        }
    }
    cout<<ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  ll N; cin >> N;
  vector<ll> dp(1000010, 0);
  dp.at(0) = 0;
  FOR(i, 1, N) {
    if (i % 3 == 0 || i % 5 == 0) dp.at(i) = dp.at(i - 1);
    else dp.at(i) = dp.at(i - 1) + i;
  }
  cout << dp.at(N) << endl;
  return 0;
}


Measured memory_bytes: 11184
#include <iostream>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll INF = 100100100100100100;

ll N;
ll A[200200];
ll rui[200200];
ll ans = INF;

void init_rui() {
  rep(i,N) {
    rui[i+1] = A[i] + rui[i];
  }
}

ll get_rui(ll left, ll right) {
  return rui[right + 1] - rui[left];
}

int main() {
  cin >> N;
  rep(i,N) {
    cin >> A[i];
  }
  init_rui();
  
  ll left_center = 0;
  ll right_center = 0;
  
  
  rep(i,N + 1) {
    if (i < 2 || i >= N - 1) continue;
    //cerr << "itr " << i << endl;
    
    ll left_max  = -INF;
    ll left_min  = INF;
    ll right_max = -INF;
    ll right_min = INF;
    
    ll left_diffmin = INF;
    ll right_diffmin = INF;
    while(1) {
      while (left_center < 1) left_center++;
      if (left_center > i-1) {
        left_center--;
        break;
      }
      //cerr << "in left_center: " << left_center << endl;
      ll ll_sum = get_rui(0, left_center-1);
      ll lr_sum = get_rui(left_center, i-1);
      //cerr << "ll_sum : " << ll_sum << " , lr_sum : " << lr_sum << endl;
      if (abs(ll_sum - lr_sum) < left_diffmin) {
        left_max = max(ll_sum, lr_sum);
        left_min = min(ll_sum, lr_sum);
        left_diffmin = abs(ll_sum - lr_sum);
      }
      if (ll_sum >= lr_sum) {
        left_center--;
        break;
      }
      left_center++;
    }
    
    while(1) {
      while (right_center < i+1) right_center++;
      if (right_center > N-1) {
        right_center--;
        break;
      }
      //cerr << "in right_center: " << right_center << endl;
      ll rl_sum = get_rui(i, right_center-1);
      ll rr_sum = get_rui(right_center, N-1);
      //cerr << "rl_sum : " << rl_sum << " , rr_sum : " << rr_sum << endl;
      if (abs(rl_sum - rr_sum) < right_diffmin) {
        right_max = max(rl_sum, rr_sum);
        right_min = min(rl_sum, rr_sum);
        right_diffmin = abs(rl_sum - rr_sum);
      }
      if (rl_sum >= rr_sum) {
        right_center--;
        break;
      }
      right_center++;
    }
    //cerr << "left_max : " << left_max << " right_max : " << right_max << endl;
    //cerr << "left_min : " << left_min << " right_min : " << right_min << endl;
    ans = min(ans, max(left_max, right_max) - min(left_min, right_min));
    //cerr << "ans: " << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define CK(n,a,b) (a) <= (n) && (n) < (b)
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll H, W;
ll A[100][100], B[100][100];
bool dp[85][85][6401];
ll ans;
int main(){
	cin >> H >> W;
	REP(i,0,H){
		REP(j,0,W){
			cin >> A[i][j];
		}
	}
	REP(i,0,H){
		REP(j,0,W){
			cin >> B[i][j];
		}
	}
	dp[0][0][0] = true;
	REP(i,0,H){
		REP(j,0,W){
			REP(now, 0, 6401){
				if(abs(A[i][j] - B[i][j] + now) < 6401){
					dp[i+1][j][abs(A[i][j] - B[i][j] + now)] |= dp[i][j][now];
					dp[i][j+1][abs(A[i][j] - B[i][j] + now)] |= dp[i][j][now];
				}
				if(abs(B[i][j] - A[i][j] + now) < 6401){
					dp[i+1][j][abs(B[i][j] - A[i][j] + now)] |= dp[i][j][now];
					dp[i][j+1][abs(B[i][j] - A[i][j] + now)] |= dp[i][j][now];
				}
				if(abs(now - (A[i][j] - B[i][j]) < 6401)){
					dp[i+1][j][abs(now - (A[i][j] - B[i][j]))] |= dp[i][j][now];
					dp[i][j+1][abs(now - (A[i][j] - B[i][j]))] |= dp[i][j][now];
				}
				if(abs(now - (B[i][j] - A[i][j]) < 6401)){
					dp[i+1][j][abs(now - (B[i][j] - A[i][j]))] |= dp[i][j][now];
					dp[i][j+1][abs(now - (B[i][j] - A[i][j]))] |= dp[i][j][now];
				}
			}
		}
	}
	REP(num,0,6401){
		if(dp[H][W-1][num] || dp[H-1][W][num]){
			ans = num;
			break;
		}
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 45312
#include <stdio.h>

int yakusuu(int a,int b);

int main(void){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		printf("%d %d\n",yakusuu(a,b),(a/yakusuu(a,b)*b));
	}
	return 0;
}

int yakusuu(int a,int b){
	int n=2,c=1;
	while(n<=a && n<=b){
		if(a%n==0 && b%n==0){
			a/=n;
			b/=n;
			c*=n;
		}
		else{
			n++;
		}
	}
	return c;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MAX_N 100000

vector<vector<pair<int,int>>> p;
vector<pair<int,int>> xy;
vector<ll> d;

void solver(int a, int b, ll c){
  for(pair<int, int> q : p[a]) {
    if(q.first != b){
      d[q.first] = c + q.second;
      solver(q.first, a, d[q.first]);
    }
  }
}

int main(){
  ll n, q, k;
  cin >> n;

  p.resize(n);
  REP(i,n-1){
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    p[a].push_back(make_pair(b,c));
    p[b].push_back(make_pair(a,c));
  }

  cin >> q >> k;
  k--;

  REP(i,q){
    int x, y;
    cin >> x >> y;
    xy.push_back(make_pair(x-1,y-1));
  }

  d.resize(n);
  solver(k, -1, 0);

  REP(i,q){
    cout << d[xy[i].first] + d[xy[i].second] << endl;
  }

  return 0;
}

Measured memory_bytes: 13684
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;

int main(void){
    int a,b,h,m;
    double d;
    double angle;
    double PI = 3.14159265358979323846;
    cin >> a>>b>>h>>m;
    angle = (h+(double)m/60)/12-(double)m/60;
    d = sqrt(a*a+b*b-(double)2*a*b*(double)cos(angle*2*PI));
    printf("%.9f\n", d);


    return 0;
}

Measured memory_bytes: 4104
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,i,u,v,ans=0,sum=0;
int main()
{
	scanf("%lld",&n);
	ans=-1;
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld",&u,&v);
		sum+=u*v;
		ans+=v;
	}
	ans+=(sum-1)/9;
	printf("%lld\n",ans);
	return 0;	
} 

Measured memory_bytes: 128
using System;

namespace noteCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] input = Console.ReadLine().Split(char.Parse(" "));
                int x = int.Parse(input[0]);
                int y = int.Parse(input[1]);
                if (x == 0 & y == 0)
                {
                    return;
                }
                if (y < x)
                {
                    Console.WriteLine(y + " " + x);
                }
                else
                {
                    Console.WriteLine(x + " " + y);
                }
            }
        }
    }
}



Measured memory_bytes: 13812
#include<iostream>
using namespace std;
int gcd2(int a,int b){
  while(1){
    if(a>b){
      a=a%b;
      if(a==0) return b;
    }
    else{
      b=b%a;
      if(b==0) return a;
    }
  }
}
int main(){
  int n,i,max,buf;
  cin>>n;
  int a[n],r[n],l[n];
  for(i=0;i<n;i++) cin>>a[i];
  l[0]=a[0];
  r[0]=a[n-1];

  for(i=1;i<n;i++){
    l[i]=gcd2(l[i-1],a[i]);
    r[i]=gcd2(r[i-1],a[n-1-i]);
  }

  max=r[n-2];
  for(i=1;i<n-1;i++){
    buf=gcd2(l[i-1],r[n-2-i]);
    if(buf>max) max=buf;
  }
  buf=l[n-2];
  if(buf>max) max=buf;
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    scanf("%d",&k);
    int n = (1<<k);
    vector<int> v;
    multiset<int> s;
    for (int i = 0; i < n; i++){
        int x;
        scanf("%d",&x);
        s.insert(-x);
    }
    v.push_back(*s.begin());
    s.erase(s.begin());
    for (int i = 0; i < k; i++){
        vector<int> nv;
        for (auto x : v){
            multiset<int>::iterator it = s.upper_bound(x);
            if (it == s.end()){
                printf("No");
                return 0;
            }
            else{
                nv.push_back(*it);
                s.erase(it);
            }
        }
        for (auto x : nv) v.push_back(x);
    }
    printf("Yes");
}


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

using namespace std;

typedef long long ll;
const int Mod = 1e9 + 7;

int n, m, i, A[4][4], x, x0;

void inm(int a[4][4], int b[4][4])
{
    ll c[4][4];
    memset(c, 0, sizeof(c));

    int i, j, k;
    for(i=0; i<4; ++i)
        for(j=0; j<4; ++j)
            for(k=0; k<4; ++k)
                c[i][j] += (ll) a[i][k] * b[k][j];

    for(i=0; i<4; ++i)
        for(j=0; j<4; ++j)
            a[i][j] = c[i][j] % Mod;
}

void res(int ans[4][4], int x)
{
    int i;
    int a[4][4]
    {
        1, 1, 1, 1,
        0, 1, 0, 1,
        0, 0, 1, 1,
        1, 1, 1, 2,
    };

    for(i=0; x; ++i)
    {
        if(x&(1<<i))
        {
            x ^= (1<<i);
            inm(ans, a);
        }

        inm(a, a);
    }
}

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m;

    x0  = 0;
    A[0][0] = 1; A[0][1] = A[0][2] = A[0][3] = 0;

    for(i=1; i<=m; ++i)
    {
        cin >> x;
        res(A, x - x0);

        x0 = x + 1;
        A[0][3] = ((ll) A[0][0] + A[0][1] + A[0][2] + A[0][3]) % Mod;
        A[0][2] = (A[0][0] + A[0][2]) % Mod;
        A[0][1] = (A[0][0] + A[0][1]) % Mod;
    }

    res(A, n - x0);
    cout << A[0][3] << '\n';

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(M):
    p,S=input().split()
    data[int(p)].append(S)

ACcount=0
WAcount=0
for h in data:
    for i in range(len(h)):
        if h[i]=="WA":
            continue
        else:
            ACcount+=1
            WAcount+=i
            break
print(ACcount,WAcount)

Measured memory_bytes: 58272
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline

import itertools as it

N=one_int()

A=many_int()

A=sorted(A)
sums_A=list(it.accumulate(A))

for i in range(N-1, -1, -1):
    if 2*sums_A[i-1] < A[i]: 
        break

print(N-i)

Measured memory_bytes: 64616
#include <iostream>

using namespace std;

int main() {
  char b;
  cin >> b;
  if (b == 'A') b = 'T';
  else if (b == 'T') b = 'A';
  else if (b == 'C') b = 'G';
  else b = 'C';
  cout << b << endl;
  return 0;
}


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

using namespace std;

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

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T    In(T& x){ cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  fast_io();
  
  int n, k;
  while (cin >> n >> k, k){
    vector<int> card;
    inpt(card, k);
    sort(card);
    vector<duo> ranges;
    for (int i = 0; i < k; i++){
      if (card[i] == 0) continue;
      int s, e;
      s = e = i;
      while (e + 1 < k && card[e] + 1 == card[e + 1]) e++;
      ranges.push_back(duo(card[s], card[e]));
      i = e;
    }
    bool exist_white = card[0] == 0;
    int maxi = ranges[0].second - ranges[0].first + 1;
    for (int i = 0; i < ranges.size(); i++){
      maxi = max(maxi, ranges[i].second - ranges[i].first + 1);
    }
    if (exist_white){
      maxi++;
      for (int i = 0; i < ranges.size() - 1; i++){
        if (ranges[i].second + 2 == ranges[i + 1].first){
          maxi = max(maxi, ranges[i + 1].second - ranges[i].first + 1);
        }
      }
    }
    cout << maxi << "\n";
  }
  return (0);
}

Measured memory_bytes: 1732