akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	char name[21];
	int length;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int main(){

	int N,cost[14][14],limit,count,tmp,ans,next_state,num_town;
	int table[14] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};
	int** dp = new int*[14];
	bool* check = new bool[16384];
	for(int i = 0; i < 14; i++){
		dp[i] = new int[16384];
	}

	Info first_info[14],info[14];
	bool FLG,part_sentence[14];

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",first_info[i].name);
			for(first_info[i].length = 0; first_info[i].name[first_info[i].length] != '\0';first_info[i].length++);
		}

		for(int i = 0; i < 14;i++)part_sentence[i] = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i != k && first_info[i].length <= first_info[k].length){
					for(int left = 0; first_info[k].length-left >= first_info[i].length;left++){
						FLG = true;

						for(int a = 0; a < first_info[i].length; a++){
							if(first_info[i].name[a] != first_info[k].name[left+a]){
								FLG = false;
								break;
							}
						}

						if(FLG){
							part_sentence[i] = true;
							break;
						}
					}

				}
			}
		}

		num_town = 0;

		for(int i = 0; i < N; i++){
			if(part_sentence[i] == false){
				strcpy(info[num_town].name,first_info[i].name);
				info[num_town].length = first_info[i].length;
				num_town++;
			}
		}

		N = num_town;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i == k)continue;

				count = 0;

				for(int left = 0; left < info[i].length;left++){
					FLG = true;
					for(int a = left; a < info[i].length && (a-left) < info[k].length;a++){
						if(info[i].name[a] != info[k].name[a-left]){
							FLG = false;
							break;
						}
					}
					if(FLG){
						count = info[i].length-left;
						break;
					}
				}

				cost[i][k] = count;
			}
		}

		limit = pow(2,N);
		for(int i = 0; i < limit;i++)check[i] = false;

		for(int i = 0; i < N;i++){
			for(int k = 0; k < limit; k++){
				dp[i][k] = BIG_NUM;
			}
		}

		for(int i = 0; i < N; i++){
			tmp = pow(2,i);
			dp[i][tmp] = info[i].length;
			check[tmp] = true;
		}

		for(int state = 0; state <= limit-2; state++){
			if(!check[state])continue;
			for(int k = 0; k < N; k++){
				if(dp[k][state] == BIG_NUM)continue;
				for(int a = 0; a < N; a++){
					if(state & (1 << a)){
						//Do nothing
					}else{
						next_state = state + table[a];
						if(dp[a][next_state] > dp[k][state] + info[a].length - cost[k][a]){
							dp[a][next_state] = dp[k][state] + info[a].length - cost[k][a];
							check[next_state] = true;
						}
					}
				}
			}
		}

		ans = BIG_NUM;
		for(int i = 0; i < N; i++){
			ans = min(ans,dp[i][limit-1]);
		}

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

	return 0;
}

Measured memory_bytes: 3656
#define TEST_MODE false

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif

#else
const bool test = false;
#define dump(x) 
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    // while (true) {
    //     solve();
    // }
    return 0;
}

// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'

int N, M;

int ans() {
    if (N < M) swap(N, M); 
    if (N - M > 1) return 0;
    if (N == M) {
        int res = 1;
        rep(loop, 2) {
            rep(i, N) {
                res *= i + 1;
                res %= mod_n;
            }
        }
        res *= 2;
        res %= mod_n;
        return res;
    }    
    if (N - M == 1) {
        int res = 1;
        rep(loop, 2) {
            int A = (loop == 0 ? N : M);
            rep(i, A) {
                res *= i + 1;
                res %= mod_n;
            }
        }
        return res;
    }
}

void solve() {
    cin >> N >> M;
    cout << ans() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

signed main() {
	int N;
	cin >> N;

	vector<int> p(N);
	rep(i, N) cin >> p[i];

	sort(all(p));

	int ret = 0;
	rep(i, N) {
		if (i == N - 1) ret += p[i] / 2;
		else ret += p[i];
	}

	cout << ret << endl;
}


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

int main(int argc, char const *argv[])
{
    int H, W;
    std::vector<int> input_H, input_W;

    while (true)
    {
        std::cin >> H >> W;
        if (H == 0 && W == 0)
        {
            break;
        }
        else
        {
            input_H.emplace_back(H);
            input_W.emplace_back(W);
        }
    }

    for (int i = 0; i < input_H.size(); i++)
    {
        for (int j = 0; j < input_H[i]; j++)
        {
            for (int k = 0; k < input_W[i]; k++)
            {
                if (j % 2 == 0)
                {
                    if (k % 2 == 0)
                    {
                        std::cout << "#";
                    }
                    else
                    {
                        std::cout << ".";
                    }
                }
                else
                {
                    if (k % 2 == 0)
                    {
                        std::cout << ".";
                    }
                    else
                    {
                        std::cout << "#";
                    }
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }

    return 0;
}



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

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

static const int MAX_N = 1e5+107;
static const int INF = 1e9+7;

int N, K;
int h[MAX_N];
int dp[MAX_N];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
  }

  fill(dp, dp+MAX_N, INF);
  dp[0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int k = 1; k <= K; ++k)
      chmin(dp[i+k], dp[i] + abs(h[i+k] - h[i]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 10000000000000;

int main() {
  int r;
  cin>>r;
  cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

int main()
{
	int N,a,b,c,d,e,ans = 0;
	scanf("%d %d %d",&N,&a,&b);
	for(int i = 1;i <= N;i++)
	{
		d = i;
		e = 0;
		while(d!=0)
		{
			c = d%10;
			e += c;
			d = d/10;
		}
		if(e >= a && e <= b) ans += i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
double dp[21][200001];
const double INF=(1LL<<50);
int a[21];
int n;
double dfs(int idx,int lastNum){
    if(idx==-1)
        return 0.0;
    if(!EQ(INF,dp[idx][lastNum]))
        return dp[idx][lastNum];
    double minCost=INF;
    if(idx==n-1)
        for(int i = 1; i <= 150000; i++)
            minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
    else{
        // lastNumðèØéÅJÚ
        for(int i = 1; i*i <= lastNum; i++){
            if(lastNum%i==0){
                minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
                minCost=min(minCost,max(dfs(idx-1,(lastNum/i)),(double)abs(a[idx]-(lastNum/i))/a[idx]));
            }
        }
    }
    return dp[idx][lastNum]=minCost;
}

int main(){
    for(int i = 0; i < 21; i++)
        for(int j = 0; j < 200001; j++)
            dp[i][j]=INF;
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i];
    double res=dfs(n-1,0);
    printf("%.9f\n",res);
    return 0;
}

Measured memory_bytes: 32000
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char** argv) {
    int r, d, x;
    cin >> r >> d >> x;
    int ans{x};
    for (int i=0; i < 10; ++i) {
        ans = r * ans - d;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from itertools import permutations
from math import sqrt,factorial

N=int(input())
X=[tuple(map(int,input().split())) for i in range(N)]

cal_dist = lambda x,y: sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

def calc_total(route):
  total=0
  for i in range(1,len(route)):
    total+=cal_dist(X[route[i]],X[route[i-1]])
  return total

SUM=0
for p in permutations(range(N)):
  SUM += calc_total(p)

print(SUM/factorial(N))

Measured memory_bytes: 9152
N,K = map(int,input().split(" "))
array = list(map(int,input().split(" ")))

minus = 0
while minus < N and array[minus]<0:
    minus += 1

first,last = max(minus-K,0),min(minus,N-K)

ans = 2*(array[N-1]- array[0])

for i in range(first,last+1):
    m_dist, p_dist = array[i], array[K-1+i]
    if m_dist*p_dist <=0:
        dist_i = min(abs(m_dist),abs(p_dist))*2+max(abs(m_dist),p_dist)
    else:
        dist_i = max(abs(m_dist),abs(p_dist))
    ans = min(ans,dist_i)

print(ans)

Measured memory_bytes: 14128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp28 {
    class Program {
        static void Main(string[] args) {
            var x = Console.ReadLine().Split(' ').Select(q => int.Parse(q)).ToArray();

            int N = x[0];
            int M = x[1];

            int[] p = new int[M];
            string[] S = new string[M];

            for (int i = 0; i < M; i++) {
                string[] st = Console.ReadLine().Split(' ').ToArray();
                p[i] = int.Parse(st[0]) - 1;
                S[i] = st[1];
            }

            //正解数
            int right = 0;

            //ペナルティ数
            int pena = 0;

            //その問題でACが出たかどうかを記録しておく配列(0が未正解)
            int[] AC_List = Enumerable.Repeat(0, N).ToArray();
            //その問題でのWAの回数を記録しておく配列
            int[] WA_List = Enumerable.Repeat(0, N).ToArray();


            for (int i = 0; i < M; i++) {
                if (AC_List[p[i]] == 0) {
                    if (S[i] == "AC") {
                        right++;
                        AC_List[p[i]] = 1;
                        pena += WA_List[p[i]];
                    } else {
                        WA_List[p[i]]++;
                    }
                }
            }


            Console.WriteLine(right + " " + pena);
        }
    }
}

Measured memory_bytes: 23752
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]

    def find(self, x):
        if self.v[x] < 0:
            return x
        else:
            self.v[x] = self.find(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:
            x, y = y, x
        self.v[x] += self.v[y]
        self.v[y] = x

    def root(self, x):
        return self.v[x] < 0

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.v[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x, y)
print(sum(1 for i in range(N) if uf.root(i)))


Measured memory_bytes: 5492
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int n,k;
int M;
int f[333][333];
int c[333][333];
int s[333][333];
int main()
{
	n=io::F(),k=io::F(),M=io::F();
	for(register int i=0;i<=n;++i)c[i][0]=c[i][i]=1;
	for(register int i=2;i<=n;++i)
		for(register int j=1;j<i;++j)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%M;
	for(register int i=0;i<=k;++i)f[0][i]=1,s[0][i]=i+1;
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=k;++j)
			for(register int x=1;x<=i;++x)
			{
				int fl=s[x-1][j-1];
				int fr=f[i-x][j];
				f[i][j]=(f[i][j]+(long long)fl*fr%M*c[i-1][x-1])%M;
				s[i][j]=(s[i][j-1]+f[i][j])%M;
			}
	printf("%d\n",f[n][k]);
	return 0;
}

Measured memory_bytes: 1408
#! python3
# coding:utf-8

def main():
	X,S,Y = input()
	X,Y = ord(X) - 55,ord(Y) - 55
	if X > Y:
		print('>')
	elif X < Y:
		print('<')
	else:
		print('=')

if __name__ == "__main__":
	main()

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] ar=new int[n];
        for(int i=0;i<n;i++){
            ar[i]=sc.nextInt();
        }
        int count=0;
        for(int i=0;i<n-1;i++){
            if(ar[i]==ar[i+1]){
                count++;
                i++;
            }
        }
        System.out.println(count);
    }  
} 

Measured memory_bytes: 22996
N = int(input())
A = sorted(list(map(int, input().split())))

if A[0] == 0:
    print(0)
    exit()

output = A[0]

for a in A[1:]:
    output = output * a
    if output > 10 ** 18:
        print(-1)
        exit()
print(output)


Measured memory_bytes: 84700
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    string s;cin>>s;
    set<char> st;
    fr(i,0,3)st.insert(s[i]);
    if(st.size()==2){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    //cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							     \
			cout.tie(0);
#define sz(arr) ll(arr.size())

using namespace std;

using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e18 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b, const ll MOD) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
ll div_floor(ll a, ll b) { return a / b - (((a ^ b) < 0) and a % b); }
ll div_ceil(ll a, ll b) { return a / b + (((a ^ b) >= 0) and a % b); }

ll f[200005];
ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

int main() {
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	fastio;
	f[0] = 1;
	for (int i = 1; i <= 200000; ++i)
		f[i] = (f[i - 1] * i) % MOD;

	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = 0;
	for (int k1 = 0; k1 <= k; ++k1) {
		ll temp = kCn(k1, n - 1);
		temp = (temp * m) % MOD;
		temp = temp * powmod(m - 1, n - 1 - k1, MOD);
		temp %= MOD;
		ans += temp;
		ans %= MOD;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 5212
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>

using namespace std;

long long zheng(long long int a, long long int b)
{
	if (a % b == 0)
		return a / b;
	return a / b + 1;
}

int main(void)
{
	long long int a, b, T, ta, tb, rate;
	scanf("%lld", &T);
	a = b = 1;
	while (T--)
	{
		scanf("%lld%lld", &ta, &tb);
		rate = 1;
		if (a >= ta)
			rate = zheng(a, ta);
		if (b >= tb)
		{
			long long t = zheng(b, tb);
			rate = rate > t ? rate : t;
		}
		a = ta * rate;
		b = tb * rate;
	}
	printf("%lld", a + b);
}

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

bool g[10][10];
bool color[10];

int dfs(int v, int n){

  bool flag = true;

  for(int i = 0; i < n; i++){
    if(color[i] == false){
      flag = false;
    }
  }
  
  if(flag) return 1;
  int res = 0;

  for(int i = 0; i < n; i++){
    if(g[v][i] == false) continue;
    if(color[i]) continue;
    color[i] = true;
    res += dfs(i, n);
    color[i] = false;
  }
  return res;
}

int main(){

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

  for(int i = 0; i < m; i++){
    int from, to;
    cin >> from >> to;
    from--; to--;
    g[from][to] = g[to][from] = true;
  }

  fill(color, color+10, false);
  color[0] = true;

  int ans = dfs(0, n);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	int n ,a,b,c ,d;
	cin >>n;
	for(int i =1; i <n+1;i++){
		int x[i];
		int a =i%3;
		int b =i %10;
        int c =i/10;
         x[i]= 0;
        while(c >2){
        	int d = c%10;
        	if (d ==3)
        	{
        		x[i]=3;/* code */
        	}
        	c =c/10;
        }
		if (a ==0 ||b ==3 ||x[i] ==3){
			cout <<" "<<i ;
		}
	}
	cout << endl;
return 0;
}



Measured memory_bytes: 3100
using System;
using System.Collections;
using System.Linq;
using System.Numerics;

class F
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long L = a[0], R = a[1];

		BigInteger c = 0;
		pow2 = new long[61];
		pow3 = new BigInteger[61];
		pow2[0] = 1;
		pow3[0] = 1;
		for (var i = 1; i <= 60; pow2[i] = 2 * pow2[i - 1], pow3[i] = 3 * pow3[i - 1], i++) ;

		for (int i = 0; i < 60; i++)
		{
			var pl = pow2[i];
			var pr = pow2[i + 1] - 1;

			if (R < pl) break;
			if (pr < L) continue;
			if (L <= pl || pr <= R) { c += SumCount(Math.Min(R, pr) - Math.Max(L, pl) + 1, i); continue; }

			for (var x = L; x <= R; x++)
				for (var y = x; y <= R; y++)
					if (y - x == (y ^ x)) c++;
		}
		Console.WriteLine(c % 1000000007);
	}

	static long[] pow2;
	static BigInteger[] pow3;

	static BigInteger SumCount(long max, int maxBit)
	{
		BigInteger c = 0;
		var b = new BitArray(new[] { (int)max, (int)(max >> 32) });
		for (int c2 = 0, i = maxBit; i >= 0; i--) if (b[i]) c += pow2[c2++] * pow3[i];
		return c;
	}
}


Measured memory_bytes: 13652
use std::io;

fn main() {
    let n = parse_line::<usize>();
    let mut v1 = parse_values(n);
    let mut v2 = parse_values(n);

    let mut diffs: Vec<i64> = Vec::new();

    let max_len = v1.len();
    let factorial_cache = [5040, 720, 120, 24, 6, 2, 1];
    let f_cache = &factorial_cache[(8 - max_len)..];
    //println!("{:?}", f_cache);
    for i in 0..max_len - 1 {
        let t = process_head(&mut v1, &mut v2);
        diffs.push(t.0);
        v1 = t.1;
        v2 = t.2;
        //println!("{:?}", v1);
    }
    //println!("{:?}", diffs);
    let mut sum = 0;
    for i in 0..diffs.len() {
        //println!("{:?}", diffs[i]);
        //println!("{:?}", f_cache[i]);
        sum += diffs[i] * f_cache[i] * (-1);
    }
    if sum > 0 {
        println!("{:?}", sum);
    } else {
        println!("{:?}", -sum);
    }
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_values<T: std::str::FromStr>(n: usize) -> Vec<T> {
    let line = parse_line::<String>();
    let mut split = line.split_whitespace();
    let mut values = Vec::with_capacity(n);
    for _ in 0..n {
        let v = split.next().unwrap().parse::<T>().ok().unwrap();
        values.push(v);
    }
    values
}

fn process_head(v1: &mut Vec<i64>, v2: &mut Vec<i64>) -> (i64, Vec<i64>, Vec<i64>) {
    let v1_head = v1[0];
    let v1_tail = &v1[1..];

    let v2_head = v2[0];
    let v2_tail = &v2[1..];
    let diff = v1[0] - v2[0];

    let v1_after: Vec<i64> = v1_tail
        .iter()
        .map(|&i| if i > v1_head { i - 1 } else { i })
        .collect();
    let v2_after: Vec<i64> = v2_tail
        .iter()
        .map(|&i| if i > v2_head { i - 1 } else { i })
        .collect();
    (diff, v1_after, v2_after)
}

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

int main() {
    multiset<string> b, r;
    set<string> w;
    int n, m;
    cin >> n;
    for (int i=0; i<n; ++i) {
        string s; cin >> s;
        b.insert(s);
        w.insert(s);
    }
    cin >> m;
    for (int i=0; i<m; ++i) {
        string s; cin >> s;
        r.insert(s);
        w.insert(s);
    }
    int ans = 0;
    for (string s: w) {
        int cnt = 0;
        for (string t: b) {
            if (s == t) cnt++;
        }
        for (string t: r) {
            if (s == t) cnt--;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a;
    scanf("%d", &a);

    int i;
    int value[a], cost[a];
    for(i=0; i<a; i++){
        scanf("%d", &value[i]);
    }
    for(i=0; i<a; i++){
        scanf("%d", &cost[i]);
    }
    int ans = 0;
    for(i=0; i<a; i++){
        if(value[i]>cost[i]){
            ans+=value[i]-cost[i];
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll Q, H, S, D, N;

int main(){
  cin >> Q >> H >> S >> D >> N;

  ll one = min(min(Q * 4, H * 2), S);
  if(one * 2 <= D) {
    cout << one * N << endl;
  } else {
    cout << D * (N / 2) + one * (N % 2) << endl;
  }

  return 0;
}



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

int main(){
	int w, n, i, tmp, a, b;
	cin>>w;
	cin>>n;
	vector<int> vw(w);
	vector<vector<int> > vn(n, vector<int>(2));
	for(i=0;i<w;i++) vw[i] = i+1;
	for(i=0;i<n;i++){
		scanf("%2d,%2d",&a, &b);
		vn[i][0] = a-1;
		vn[i][1] = b-1;
		
		tmp = vw[(vn[i][0])];
		vw[(vn[i][0])] = vw[(vn[i][1])];
		vw[(vn[i][1])] = tmp;
	}
	for(i=0;i<w;i++) cout << vw[i] << endl;
	return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
#define cpd complex<double>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
static const double pi = 3.141592653589793;

double A, B, H, M;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> A >> B >> H >> M;
    double ax = A * cos(2 * pi * (60 * H + M) / 720);
    double ay = A * sin(2 * pi * (60 * H + M) / 720);
    double bx = B * cos(2 * pi * M / 60);
    double by = B * sin(2 * pi * M / 60);
    cout << fixed << setprecision(20);
    cout << sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)) << endl;
    return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef multiset<ll> ssll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

const int INF = 1000000000;
const ll MOD = 1000000007;

int main() {FIN
	
	int k;
	cin >> k;
	string s = "";
	for (int i = 0; i < k; i++) s += "ACL";
	cout << s << "\n";
	
	return 0;
}

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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    ull ans = 0;
    if (n%k == 0) 
    {
        ans = 0;
        cout << ans << endl;
        return 0;
    }
    if (n <= abs(n-k))
    {
        ans = n;
        cout << ans << endl;
        return 0;
    }

    n = (n%k > k/2) ? k-(n%k) : n%k;
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N= 2e5 +10;

int n;
int a[N];
int tmp;
ll ans;
int ok=1;

int main() {
	cin>>n;
	REP(i, 1, n) {
		cin>>a[i];
	}
	tmp=0;
	DOWN(i, n, 1) {
		if (a[i]==tmp) {
			tmp--;
			continue;
		}
		if (a[i]<tmp) {
			ok=0;
			break;
		}
		if (a[i]>tmp) {
			ans+=a[i];
			tmp=max(tmp-1, a[i]-1);
		}
	}
	if (tmp!=-1) ok=0;
	if (!ok) cout<<-1<<endl;
	else cout<<ans<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> prev(1000);
  int sum = 0;
  for (int i=0; i<1000; i++) {
    sum += i+1;
    prev[i] = (double)sum / (i+1);
  }

  vector<double> p(n);
  int v;
  cin >> v;
  p[0] = prev[v-1];  
  for (int i=1; i<n; i++) {
    cin >> v;
    p[i] = prev[v-1] + p[i-1];
  }

  double maxP = p[k-1];
  for (int i=0; i<n-k; i++) {
    chmax(maxP, p[i+k]-p[i]);
  }
  cout << fixed << setprecision(20) << maxP <<   endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n;cin>>n;
    vector<int> v[n+1];
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int c[n];
    rep(i,0,n)cin>>c[i];
    int num;
    ll ans=0;
    rep(i,1,n+1){
        if(v[i].size()==1){
            num=i;
            break;
        }
    }
    sort(c,c+n);
    int nw=n-1;
    int d[n+1];
    queue<int> q;
    q.push(num);
    bool used[n+1];
    fill(used,used+n+1,false);
    used[num]=true;
    while(q.size()>0){
        int now=q.front();q.pop();
        d[now]=c[nw];
        nw--;
        rep(i,0,v[now].size()){
            if(used[v[now][i]])continue;
            used[v[now][i]]=true;
            q.push(v[now][i]);
            
        }
    }
    rep(i,0,n-1)ans+=c[i];
    cout<<ans<<endl;
    rep(i,1,n)cout<<d[i]<<" ";
    cout<<d[n]<<endl;
}


Measured memory_bytes: 1024
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

vector<ll> mincost;
vector<vector<vector<ll>>> Edges;
vector<bool> ncycle;
deque<ll> bfsrec;

//負閉路検出
void bfs(){
    ll s=SIZE(bfsrec);
    REP(i,s){
        ll now=*bfsrec.begin();
        bfsrec.pop_front();
        REP(i,SIZE(Edges[now])){
            if(ncycle[Edges[now][i][0]]==false){
                ncycle[Edges[now][i][0]]=true;
                bfsrec.PB(Edges[now][i][0]);
            }
        }
    }
    if(s)bfs();
}

bool bellmanford(ll n){
    //(l1-1)(普通のbellman)+1(検出)
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(mincost[j]!=INF){
                for(const auto& edge:Edges[j]){
                    ll new_mincost=mincost[j]+edge[1];
                    if(mincost[edge[0]]>new_mincost){
                        mincost[edge[0]]=new_mincost;
                        if(i==n-1){
                            ncycle[edge[0]]=true;//負の閉路があればtrue
                            bfsrec.PB(edge[0]);
                        }
                    }
                }
            }
        }
    }
    bfs();
    if(ncycle[n-1]==true)return true;
    return false;//Nを含む負の閉路がなければfalse
}


signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,m,p;cin>>n>>m>>p;
    mincost.resize(n);mincost[0]=0;
    FOR(i,1,n-1)mincost[i]=INF;
    Edges.resize(n);
    ncycle.resize(n);
    REP(i,n)ncycle[i]=false;
    //コストをpでマイナスしてそれを符号逆に
    REP(i,m){
        ll a,b,c;cin>>a>>b>>c;
        Edges[a-1].PB({b-1,p-c});
        //cout<<p-c<<endl;
    }
    //このもとでの最小を考える
    bool check=bellmanford(n);
    if(check or mincost[n-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<max(-mincost[n-1],ll(0))<<endl;
    }
}

Measured memory_bytes: 3988
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
double dmax(double a,double b){
    return a>b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
#define N 100000
int rank[N],p[N];

void initialize(int n){
    int i;
    rep(i,n){
        p[i]=i;
        rank[i]=0;
    }
}

int find_set(int x){
    if(x!=p[x])
        p[x]=find_set(p[x]);
    return p[x];
}

void link(int x,int y){
    if(rank[x]>rank[y])
        p[y]=x;
    else{
        p[x]=y;
        if(rank[x]==rank[y])
            rank[y]++;
    }
}
void unite(int x,int y){
    link(find_set(x),find_set(y));
}

int same(int x,int y){
    return find_set(x)==find_set(y);
}

int main(void){
    int n=in(),m=in(),i,a[N],x,y,ans=0;
    initialize(n);
    rep(i,n)a[i]=in();
    rep(i,m){
        x=in(),y=in();
        unite(x,y);
    }
    rep(i,n)ans+=same(i+1,a[i]);
    print(ans);
    return 0;
}

Measured memory_bytes: 1280
N = input()

if N =="SUN":
  print(7)
elif N =="MON":
  print(6)
elif N =="TUE":
  print(5)
elif N =="WED":
  print(4)
elif N =="THU":
  print(3)
elif N =="FRI":
  print(2)
elif N =="SAT":
  print(1)
  
  

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

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

#############
# Main Code #
#############

K = inputI()

l = [[gcd(i,j) for i in range(1,K+1)] for j in range(1,K+1)]

dic = [0 for i in range(1,K+2)]

for item in l:
  for i in item:
    dic[i] += 1
    
#print(dic)

res = 0
for a in range(1,K+1):
  for d in range(1,K+1):
    res += dic[a] * l[a-1][d-1]
      
print(res)


Measured memory_bytes: 75636
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int n;cin >> n;
     vector<int>a(n);
     for(int i = 0;i<n;i++) cin >> a[i];
     int cnt = 0;
     for(int i = 0;i<n;i++){
        if(a[i]!=i+1) cnt++;
     }
     if(cnt<=2) cout <<"YES";
     else cout <<"NO";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3588
import numpy as np
H,W=map(int, input().split())
A=[]

for h in range(H):
    a=list(input())
    A.append(a)

A=np.array(A)
hs=[]
ws=[]

for i in range(H):
    if (A[i,:]=="#").sum()==0:
        hs.append(i)
for i in range(W):
    if (A[:,i]=="#").sum()==0:
        ws.append(i)

for h in range(H):
    if h not in hs:
        L=[]
        for w in range(W):
            if w not in ws:
                L.append(A[h,w])
        print("".join(L))




Measured memory_bytes: 12496
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<priority_queue<int>> s(n);
  int q, t, x;
  cin >> q;
  while (cin >> q >> t) {
    if (q == 0) {
      cin >> x;
      s[t].push(x);
    } else if (q == 1) {
      if (!s[t].empty())
        cout << s[t].top() << endl;
    } else {
      if (!s[t].empty())
        s[t].pop();
    }
  }
}


Measured memory_bytes: 4080
/*
 *	Argorithms and Data Structures
 *	Lectuire 5 
 *	Merge Sort
 */

#include <stdio.h>
#include <limits.h>

#define INFTY INT_MAX
#define N 500000

int count = 0;

void merge(int A[], int left, int mid, int right){
	int i, j, k;
	int L[N], R[N];
	int L_elements = mid - left;
	int R_elements = right - mid;

	for(i=0; i<L_elements; i++)
		L[i] = A[left + i];
	L[i] = INFTY;

	for(i=0; i<R_elements; i++)
		R[i] = A[mid + i];
	R[i] = INFTY;


	i = j = k = 0;
	for(k=left; k<right; k++){
		if( L[i] <= R[j] )
			A[k] = L[i++];
		else
			A[k] = R[j++];
	}
	count += i + j;
}	

void mergeSort(int A[], int left, int right){
	int mid;
	if( left+1 < right ){
		mid = ( left + 1 + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main(void){
	int A[N], n, i;

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

	mergeSort(A, 0, n);

	for(i=0; i<n-1; i++)
		printf("%d ", A[i]);
	printf("%d\n%d\n", A[i], count);

	return 0;
}

Measured memory_bytes: 5580
a,b,c,k=map(int,input().split())
if a >= k:
    print(k)
elif (a+b)>= k:
    print(a)
elif (a+b) < k < (a+b+c):
    print(a-(k-(a+b)))
elif (c+b+a) <= k:
    print(a-c)

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

typedef long long lint;
typedef long double louble;

#define lf '\n'

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int tc()
	{
		int c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		return c;
	}
}
using ae86::ty;
using ae86::tc;

const int _ = 200007;

vector<int> e[_];

int n,m,val[_]={0},cnt[_][2]={0},fail[_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty(),m=ty();
	for(int i=1;i<=n;i++)val[i]=tc()=='A';
	for(int i=1;i<=m;i++)
	{
		int a=ty(),b=ty();
		e[a].emplace_back(b),e[b].emplace_back(a);
		cnt[a][val[b]]++,cnt[b][val[a]]++;
	}

	queue<int> q;
	for(int i=1;i<=n;i++)if(cnt[i][0]<=0 || cnt[i][1]<=0)fail[i]=1,q.emplace(i);
	while(!q.empty())
	{
		int a=q.front();
		q.pop();
		for(auto b:e[a])
		{
			cnt[b][val[a]]--;
			if(!fail[b] && (cnt[b][0]<=0 || cnt[b][1]<=0))fail[b]=1,q.emplace(b);
		}
	}
	for(int i=1;i<=n;i++)if(!fail[i]){puts("Yes");return 0;}
	puts("No");
	
	return 0;
}


Measured memory_bytes: 13824
from sys import stdin
import numpy as np
 
n,k,q = [int(x) for x in stdin.readline().rstrip().split()]
p_lst = [k] * n
p_t_lst = [0] * n

for i in range(q):
  a = int(stdin.readline().rstrip())
  p_t_lst[a-1] += 1

p_lst = np.array(p_lst) + np.array(p_t_lst) - q

for p in p_lst:
  if p <= 0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 21152
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define MOD 1000000007
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int N;
    cin >> N;
    ll ans = 1;
    rep(i,N){
        ans *= i+1;
        ans = ans%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    H = LIST()

    tmp = 1
    for i in range(N):
        if tmp < H[i]:
            tmp = H[i] - 1
        elif tmp > H[i]:
            No()
            exit()
    Yes()
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]

ans = 0
cnt = 0
for i in range(n):
  ans = c
  for j in range(m):
    ans += a[i][j]*b[j]
  if ans >0:
    cnt +=1
print(cnt)

Measured memory_bytes: 3064