akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
ary = gets.split(" ").map(&:to_i)

h = Hash.new(0)
num = 1
ary.each do |a|
    h[num] = a unless num == a
    num = num + 1
end

def hikaku(hash)
    a = hash.to_a
    a[0][1] == a[1][0]
end


if h.length >= 3 #ハッシュが３つ以上
    puts "NO"
elsif h.length == 1
    puts "NO"
elsif h.empty? #ハッシュなし
    puts "YES"
elsif hikaku(h) == true
    puts "YES"
elsif hikaku(h) == false
    puts "NO"
else
    puts "NO"
end

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

int main(){
  int N,X,count=0;
  cin >> N >> X;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  vector<long long> D(N+1);
  for(int i=1;i<N+1;i++){
    D.at(i)=D.at(i-1)+L.at(i-1);
  }
  for(int i=0;i<N+1;i++){
    if(D.at(i)<=X){
      count++;
    }
  }
  cout << count << endl;
}  

Measured memory_bytes: 3632
from collections import deque

ans = []
while True:
    w, h = map(int, input().split())
    if not w and not h:
        break
    
    roadmap = []
    d = deque()
    able = [[False for i in range(w)] for j in range(h)]
    for i in range(h):
        roadmap.append(input())
        
    
    for i in range(h):
        for j in range(w):
            if roadmap[i][j] == '@':
                able[i][j] = True
                d.append([i, j])

    
    while len(d):
        y, x = d.pop()
        
        for course in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
            tmpy, tmpx = y + course[0], x + course[1]
            if tmpy < 0 or tmpy >= h or tmpx < 0 or tmpx >= w:
                continue
                
            if not able[tmpy][tmpx] and roadmap[tmpy][tmpx] == '.':
                able[tmpy][tmpx] = True
                d.append([tmpy, tmpx])

    a = 0
    for i in range(h):
        a += len(list(filter(lambda x:x, able[i])))

    ans.append(a)

[print(i) for i in ans]



Measured memory_bytes: 6072
#include <bits/stdc++.h>
using namespace std;
#define lim 999999999
#define on 100005
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR for(int i=1;i<=n;i++)
typedef long long int lo; 
typedef pair<int,int> PII;
int n,m,a[200005],cev=-lim,buy,kuc,say,k,z,x,y,mn=lim;
char c;
string s;
stack<int> st;
vector<int> v;
int main(){
	scanf("%d %d %d %d",&n,&m,&k,&z);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cev=max(cev,x);
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&y);
		mn=min(mn,y);
	}
	if(mn<=cev){
		printf("War");
		return 0;
	}
	if(mn<=min(k,z) || cev>=max(z,k)){
		printf("War");
		return 0;
	}
	printf("No War");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int gcd(int a, int b)
{
  int r, tmp;
 
  /* 自然数 a > b を確認・入替 */
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void)
{
long K, x, y, z, sum;

  scanf("%ld", &K);
  sum = 0;
  for (x = 1; x <= K; ++x) {
    for (y = 1; y <= K; ++y) {
      for (z = 1; z <= K; ++z) {
        sum += gcd(gcd(x, y), z);
      }
    }
  }
  printf("%d\n", sum);
    
  return 0;
}


Measured memory_bytes: 1736
<?php
fscanf(STDIN, "%d %d %d %d", $N, $A, $B, $C);
$arrayL = array();
for ($i = 0; $i < $N; $i ++) {
    // ${"l" . $i} = fgets(STDIN);
    // $arrayL[] = ${"l" . $i};
    $arrayL[$i] = fgets(STDIN);
}

$arrayABC = array();
$arrayA = array();
$arrayB = array();
$arrayC = array();
$minMP = 3000;
for ($i = 0; $i < 4; $i ++) {
    $arrayABC[0] = $i;
    for ($j = 0; $j < 4; $j ++) {
        $arrayABC[1] = $j;
        for ($k = 0; $k < 4; $k ++) {
            $arrayABC[2] = $k;
            for ($l = 0; $l < 4; $l ++) {
                if ($N <= 3 && $l >= 1) {
                    break;
                } else {
                    $arrayABC[3] = $l;
                }
                for ($m = 0; $m < 4; $m ++) {
                    if ($N <= 4 && $m >= 1) {
                        break;
                    } else {
                        $arrayABC[4] = $m;
                    }
                    for ($n = 0; $n < 4; $n ++) {
                        if ($N <= 5 && $n >= 1) {
                            break;
                        } else {
                            $arrayABC[5] = $n;
                        }
                        for ($o = 0; $o < 4; $o ++) {
                            if ($N <= 6 && $o >= 1) {
                                break;
                            } else {
                                $arrayABC[6] = $o;
                            }
                            for ($p = 0; $p < 4; $p ++) {
                                if ($N <= 7 && $p >= 1) {
                                    break;
                                } else {
                                    $arrayABC[7] = $p;
                                }
                                if (! in_array(1, $arrayABC) || ! in_array(2, $arrayABC) || ! in_array(3, $arrayABC)) {
                                    continue;
                                }
                                for ($z = 0; $z < $N; $z ++) {
                                    if ($arrayABC[$z] === 1) {
                                        $arrayA[] = $arrayL[$z];
                                    } elseif ($arrayABC[$z] === 2) {
                                        $arrayB[] = $arrayL[$z];
                                    } elseif ($arrayABC[$z] === 3) {
                                        $arrayC[] = $arrayL[$z];
                                    }
                                }
                                $value = abs(array_sum($arrayA) - $A) + abs(array_sum($arrayB) - $B) + abs(array_sum($arrayC) - $C);
                                $value += (count($arrayA) - 1) * 10 + (count($arrayB) - 1) * 10 + (count($arrayC) - 1) * 10;
                                if ($minMP > $value) {
                                    $minMP = $value;
                                }
                                $arrayA = array();
                                $arrayB = array();
                                $arrayC = array();
                            }
                        }
                    }
                }
            }
        }
    }
}
echo $minMP;


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    std::vector<int> a;
    
    cin>>n;
    cin>>m;
    
    int tmp = 0;
    long long int sum = 0;
    while(cin>>tmp){
        a.push_back(tmp);
        sum += tmp;
    }
    
    long long int ok_count = 0;
    for(int i=0;i<a.size();i++){
        if(a[i]>=(float)sum/(4.0*(float)m))
            ok_count++;
    }
    
    if(ok_count>=m){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
long long  mod = 1000000007;
struct rest {
	string S;
	int point;
	int num;
};
vector<rest> R;
int main()
{
	int N; cin >> N;
	string s;
	int p;
	int n;
	int e;
	for (int i = 0; i < N; i++) {
		cin >> s >> p;
		R.push_back({ s,p,i + 1 });
	}
	while (!R.empty()) {
		s = R[0].S; p = R[0].point; n = R[0].num, e = 0;
		for (int i = 0; i < R.size(); i++) {
			if (R[i].S < s) {
				s = R[i].S;
				p = R[i].point;
				n = R[i].num;
				e = i;
			}
			else if (R[i].S == s) {
				if (R[i].point > p) {
					p = R[i].point;
					n = R[i].num;
					e = i;
				}
			}
		}
		cout << n << "\n";
		R.erase(R.begin() + e);
	}
}

Measured memory_bytes: 256
// 2013/09/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if(b1==1 && b2==0 && b3==0){
		cout << "Close\n";
	}
	else if(b1==0 && b2==1 && b3==0){
		cout << "Close\n";
	}
	else if(b1==1 && b2==1 && b3==0){
		cout << "Open\n";
	}
	else if(b1==0 && b2==0 && b3==1){
		cout << "Open\n";
	}
	else if(b1==0 && b2==0 && b3==0){
		cout << "Close\n";
	}

	return 0;
}

Measured memory_bytes: 1124
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x,ans=0,mon=100;
		x = sc.nextLong();
		while(mon<x) {
			mon+=mon*0.01;
			ans++;
		}
	System.out.println(ans);
	}
}

Measured memory_bytes: 35796
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int X;
    cin>>X;
    int m=X%100;
    int f=(X/100)*5;
    cout<<(m<=f)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max 20

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while (a!=0) {a=a/10;i++;}return i;}

int main()
{
    int n, a[max], b[max], c[max], sum=0, i;
    
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    for (i=0; i<n; i++) {
        scanf("%d", &b[i]);
        sum+=b[i];
    }
    for (i=0; i<n-1; i++) {
        scanf("%d", &c[i]);
    }
    
    for (i=0; i<n-1; i++) {
        if (a[i+1]-a[i]==1) {
            sum+=c[a[i]-1];
        }
    }
    
    printf("%d", sum);
    
    return 0;
}



Measured memory_bytes: 128
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int d = int.Parse(input[1]);

        int count = 0;

        for (int i = 0; i < n; i++)
        {
            input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]);
            int y = int.Parse(input[1]);
            if (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) <= d)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


Measured memory_bytes: 40536
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int GetDigit(int num){
    return log10(num)+1;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 0; i <= n; i++) {
    if(GetDigit(i) % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int maxn = 1e5 + 5;
int h[maxn], dp[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> h[i];
	dp[n - 1] = 0;
	dp[n - 2] = abs(h[n - 1] - h[n - 2]);
	for (int i = n - 3; i >= 0; i --){
		dp[i] = min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
	}
	cout << dp[0];
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main(){
	string s, t;
	bool f = 0;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		s = s[s.size() - 1] + s;
		s.erase(s.end()-1);
		if (s == t)f = 1;
	}
	
	if (f == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main()
{
	char s[2000000], t[2000000];
	int count=0, i;

	scanf("%s", &s[0]);
	scanf("%s", &t[0]);

	for (i = 0;i <= strlen(s)-1 ;i++) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	printf("%d", count);
	return 0;
}

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

int n, m, k[11], s[11], t, p[11], ans;
bool f;

int numberOfSetBits(int i){
	if (i <= 1) return i;
	else return numberOfSetBits(i >> 1) + (i % 2);
}

int main(){
	cin >> n >> m;
	for (int i = 0; i < m; ++i){
		cin >> k[i];
		s[i] = 0;
		for (int j = 0; j < k[i]; ++j){
			cin >> t;
			s[i] += (1 << (t-1));
		}
	}
	for (int i = 0; i < m; ++i) cin >> p[i];

	ans = 0;
	for (int i = 0; i < (1 << n); ++i){
		f = true;
		for (int j = 0; j < m; ++j){
			if (numberOfSetBits(s[j] & i) % 2 != p[j]){
				f = false;
				break;
			}
		}
		if (f) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		prepareFact();

		int need = sc.nextInt();
		int winT = sc.nextInt();
		int winA = sc.nextInt();
		int draw = sc.nextInt();
		long ans = 0;
		for(int m = need; m < need * 2; m ++) {
			long drawVal = mod(m * 100 * invMod(100 - draw));
			long combi = combiMod(m - 1, need - 1);
			long winTs = mod(powerMod(winT, need) * powerMod(winA, m - need));
			long winAs = mod(powerMod(winA, need) * powerMod(winT, m - need));
			long wins = mod(mod(winTs + winAs) * invMod(powerMod(winT + winA, m)));
			long tmp = mod(mod(wins * combi) * drawVal);
			ans = mod(ans + tmp);
		}
		System.out.println(ans);
	}

	static long MOD = (long)Math.pow(10, 9) + 7;
	public static long mod(long i) {
		return i % MOD + ((i % MOD) < 0 ? MOD : 0);
	}
	
	static long powerMod(long x, long y) {
		if (y == 0) {
			return 1;
		} else if (y == 1) {
			return x;
		} else if (y % 2 == 0) {
			long tmp = powerMod(x, y / 2);
			return mod(tmp * tmp);
		} else {
			long tmp = powerMod(x, y / 2);
			return mod(mod(tmp * tmp) * x);
		}
	}
	
	static long invMod(long x) {
		return powerMod(x, MOD - 2);
	}
	
	static int MAX_FACT = 200_100;
	static long factMod[] = new long[MAX_FACT];
	static void prepareFact() {
		factMod[0] = 1;
		for(int i = 1; i < MAX_FACT; i ++) {
			factMod[i] = mod(factMod[i - 1] * i);
		}
	}

	static long combiMod(int n, int r) {
		if(n < 0 || n < r) { return 0; }
		if(r == 0 || r == n) { return 1; }
		return mod(mod(factMod[n] * invMod(factMod[r])) * invMod(factMod[n - r]));
	}
}

Measured memory_bytes: 22960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<string> ans;
    auto dfs = [&](auto&& self,int cur,int ma,vec<int>& v)->void{
        if(cur==N){
            string S = "";
            for(auto& c:v){
                char a = 'a'+c;
                S += a;
            }
            ans.push_back(S);
            return ;
        }
        for(int i=0;i<=ma+1;i++){
            v.push_back(i);
            self(self,cur+1,max(ma,i),v);
            v.pop_back();
        }
        return ;
    };
    vec<int> v;
    int ma = -1;
    dfs(dfs,0,ma,v);
    sort(ans.begin(),ans.end());
    for(auto& s:ans) cout << s << "\n";
}

Measured memory_bytes: 9716
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define lli long long int
#define REP(i, s, l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (lLL <<50)
#define MOD 1000000007

map<lli, vector<lli>> v;

int main() {
	lli n, m;
	cin >> n >> m;

	for (lli i = 0; i < n; i++) {
		lli a, b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	lli sum = 0;

	priority_queue<lli> q;

	for (lli i = 0; i <= m; i++) {
		for (lli j = 0; j < v[i].size(); j++) {
			q.push(v[i].at(j));
		}

		if (q.size() == 0) continue;
		sum += q.top(); //1日で最大、1,2日で最大、1,2,3日で最大...
		q.pop();
	}

	cout << sum << endl;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

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

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int k; cin >> k;
    vector<ll> su;
    vector<ll> ans;
    FOR(i, 1, 10) su.pb(i);
    FOR(i, 1, 10000){
        FOR(j, 1, 14){
            ll nine = pow(10, j) - 1;
            su.pb(i*pow(10, j) + nine);
        }
    }
    sort(ALL(su));
    for(int i=su.size()-2; i>=0; i--){
        if (su[i] == su[i+1]) su.erase(su.begin()+i+1);
    }

    double mindiv;

    for(int i=su.size()-1; i>=0; i--){
        int s = 0;
        ll tmp = su[i];
        while(tmp > 0){
            s += tmp % 10;
            tmp /= 10;
        }
        if (i == su.size()-1) mindiv = su[i] / double(s);
        else if (su[i] / double(s) <= mindiv){
            ans.pb(su[i]);
        }
        mindiv = min(mindiv, su[i]/double(s));
    }
    sort(ALL(ans));
    REP(i, k) cout << ans[i] << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
    int i, n, p, t, s=0;
    ll ans;
    scanf("%d%d", &n, &p);
    for(i=0; i<n; i++) {
        scanf("%d", &t);
        s|=t;
    }
    if(s&1) ans=1LL<<(n-1);
    else ans=(1LL<<n)*(1-p);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dpcost[407][407];
ll dpsize[407][407];
ll A[407],sum[407];

int main(){
  ll N;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    sum[i+1]=sum[i]+A[i];
  }
  rep(i,N){
    Rep(j,i+1,N+1){
      dpsize[i][j]=sum[j]-sum[i];
    }
  }
  rep(i,N+1){
    rep(j,N+1){
      dpcost[i][j]=LINF;
    }
  }
  Rep(j,1,N+1){
    rep(i,N){
      if(i+j>N){
        continue;
      }
      if(j==1){
        dpcost[i][i+j]=0;
      }
      else{
        Rep(k,1,j){
          dpcost[i][i+j]=min(dpcost[i][i+j],dpcost[i][i+k]+dpcost[i+k][i+j]+dpsize[i][i+j]);
        }
      }
    }
  }
  cout << dpcost[0][N] << endl;
}

Measured memory_bytes: 2816
from fractions import gcd
from functools import reduce

N, *A = map(int, open(0).read().split())

def lcm(x, y):
    return x * y // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

MOD = 10 ** 9 + 7
num = lcm_list(A)
print(sum(num * pow(v, MOD - 2, MOD) for v in A) % MOD)


Measured memory_bytes: 69720
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#define inf 0x7ffffff7
#define MAXN  100010
#define PII pair<int, int>
#define e 2.718281828459
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll dis[MAXN] = { 0 };
vector<pair<ll, ll>> G[MAXN];
bool vis[MAXN];
void dfs(ll v)
{
	vis[v] = 1;
	for (int i = 0; i < G[v].size(); i++)
	{
		ll u = G[v][i].first;
		ll w = G[v][i].second;
		if (!vis[u])
		{
			dis[u] = dis[v] + w;
			dfs(u);
		}
	}
}
int main()
{
	int n, x, y;
	ll d;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		cin >> x >> y >> d;
		G[x].push_back(pair<ll, ll>(y, d));
		G[y].push_back(pair<ll, ll>(x, d));
	}
	ll q, k;
	cin >> q >> k;
	dfs(k);
	while (q--)
	{
		cin >> x >> y;
		cout << dis[x] + dis[y] << endl;
	}
	//cin >> T;
	return 0;
}


Measured memory_bytes: 14336
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
main = do
    n <- getInt
    when (n/=0) $ do
        d <- map snd . sort . map (\(i:s) -> (sum $ map (\[m,s] -> 60*m+s) $ splitRec 2 s, i)) <$> replicateM n getInts
        print $ head d
        print $ head $ tail d
        print $ last $ init d
        main


-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
-- templete



Measured memory_bytes: 13332
n, m = map(int, input().split())
dic = {}
ab = []
for i in range(m):
  a, b = map(int, input().split())
  if a in dic.keys():
    dic[a] += [b]
  else:
    dic[a] = [b]
  if b in dic.keys():
    dic[b] += [a]
  else:
    dic[b] = [a]
  ab.append([a, b])
  
ans = 0
for pair in ab:
  a = pair[0]
  b = pair[1]
  dic[a] = [num for num in dic[a] if num != b]
  dic[b] = [num for num in dic[b] if num != a]

  serch_spot = [a]
  visited = []
  while len(serch_spot) != 0:
    spot = serch_spot.pop(0)
    visited.append(spot)
    Next_cands = dic[spot]
    for cand in Next_cands:
      if cand in visited:
        continue
      elif cand in serch_spot:
        continue
      else:
        serch_spot.append(cand)
  if len(visited) != n:
    ans += 1
  dic[a] += [b] 
  dic[b] += [a]

print(ans)

Measured memory_bytes: 39792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int m,d; cin>>m>>d;
  int ans = 0;
  reps(j,m){
    reps(i,d){
      int a,b;
      a = i/10; b = i%10;
      if(a*b==j && a>=2 && b>=2){
        ans++;
        cerr << j SP a SP b << endl;
      }

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


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
#define INF 10000
#define pp pair<int,int>
using namespace std;
vector<vector<int> > ar;
queue<pair<int,int> > q;
int n,root,k;
bool chk[2005];
int centeris(int x,int x2) {
	int i;
	for (i = 1; i <= n; i++) chk[i] = false;
	chk[x] = true; chk[x2] = true;
	q.push(pp(0, x));
	if (x2 > 0) q.push(pp(0, x2));
	int ret = 0;
	int len;
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		x = p.second; len = p.first;
		if (len > k) ret++;
		for (int next : ar[x]) {
			if (chk[next]) continue;
			chk[next] = true;
			q.push(pp(len + 1, next));
		}
	}
	return ret;
}
int main() {
	scanf("%d%d", &n,&k);
	ar.resize(n + 1);
	int i;
	for (i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ar[a].push_back(b);
		ar[b].push_back(a);
	}
	int ans = INF;
	if (k % 2 == 0) {
		k /= 2;
		for (i = 1; i <= n; i++) {
			int res = centeris(i, 0);
			if (ans > res) ans = res;
		}
	}
	else {
		k = (k - 1) / 2;
		for (i = 1; i <= n; i++) {
			for (int next : ar[i]) {
				int res = centeris(i, next);
				if (ans > res) ans = res;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 384
#include <iomanip>
#include <iostream>
#include <vector>
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
template<typename A, typename B> void cmax(A &a, const B &b) {
  if (a < b) a = b;
}
constexpr double INF = 1e9;
using namespace std;

template<typename CommutativeGroup> class RangeFold {
  using T = typename CommutativeGroup::value_type;

  CommutativeGroup g;

  std::vector<T> cache;

public:
  RangeFold(const std::vector<T> &raw) : cache(raw) {
    size_t w = cache.size();
    loop(i, 1, w) cache[i] = g(cache[i], cache[i - 1]);
  }

  T fold(const int l, const int r) { // [l, r)
    T acc = g.id();
    if (r > 0) acc = g(acc, cache[r - 1]);
    if (l > 0) acc = g(acc, g.inv(cache[l - 1]));
    return acc;
  }
};

template<typename T> struct sumGroup {
  using value_type = T;
  constexpr value_type id() { return 0; }
  constexpr value_type operator()(const value_type &a, const value_type &b) { return a + b; }
  constexpr value_type inv(const value_type &x) { return -x; }
};

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  RangeFold<sumGroup<int>> rf(a);
  vector<vector<double>> dp(n + 1, vector<double>(n + 1, -INF));
  dp[0][0] = 0;
  loop(i, 1, 1 + n) loop(j, 1, 1 + i) loop(k, 1, 1 + i) cmax(dp[i][j], dp[i - k][j - 1] + 1.0 * rf.fold(i - k, i) / k);
  cout << fixed << setprecision(32) << dp[n][m] << endl;
}



Measured memory_bytes: 5080
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
 long long a,b,c,d,e,i,j;
 cin >> a;
 long long sum=0;
 vector<long long>vec;
 while(a--)
 {
     cin >> b;
     sum+=b;
     vec.push_back(b);
 }
 long long mul=0,cnt=1;
 for(i=0;i<vec.size()-1;i++)
 {
     cnt=1;
     sum-=vec[i];
     cnt=1;
     cnt=((vec[i]%mod)*(sum%mod))%mod;
     mul=((mul%mod)+(cnt%mod))%mod;



 }
 cout << mul << endl;
}


Measured memory_bytes: 5360
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();

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

    Arrays.sort(L);

    int ans = 0;

    for (int i = 0; i < n; i++) {
      int a = L[i];
      for (int j = i+1; j < n; j++) {
        int b = L[j];
        for (int k = j+1; k < n; k++) {
          int c = L[k];
          if (a < b + c && b < c + a && c < a + b) {
            ans++;
          } else {
            break;
          }
        }
      }
    }

    System.out.println(ans);
  }
}

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

static const int N = 1000;

int lcs(string X,string Y){
    int c[N+1][N+1];    //c[i][k]???Xi??¨Yk???LCS??¨??????????????????
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X; // X[0]?????????????????\
    Y = ' ' + Y;
    for(int i=1;i<=m;i++) c[i][0] = 0;
    for(int k=1;k<=n;k++) c[0][k] = 0;
    c[0][0] = 0;

    for(int i=1;i<=m;i++){
        for(int k=1;k<=n;k++){
            if(X[i]==Y[k]){
                c[i][k] = c[i-1][k-1] + 1;
            } else {
                c[i][k] = max(c[i-1][k],c[i][k-1]);
            }
            maxl = max(maxl,c[i][k]);
        }
    }

    return maxl;
}

int main(){
    string s1,s2;
    int n; cin >> n;
    for(int i=0;i<n;i++){
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }

    return 0;
}

Measured memory_bytes: 7028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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

inline int gcd(int a, int b) { if (a%b == 0) { return b; } else { return gcd(b, a%b); } }

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = a; i <= a*b; i += a) {
        if ( i % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = list(input() for _ in range(n))
m = int(input())
b = list(input() for _ in range(m))

dict_a = {}
dict_b = {}

for i in a:
    if i in dict_a:
        dict_a[i] += 1
    else:
        dict_a[i] = 1

for i in b:
    if i in dict_b:
        dict_b[i] += 1
    else:
        dict_b[i] = 1

for c in dict_a.keys():
    if c in dict_b.keys():
        dict_a[c] -= dict_b[c]
print(max(0, max(dict_a.values())))


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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if(S == "Y") {
      cout << "Four";
      break;
    }
    else if (i == N - 1) cout << "Three";
  }
}


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

int main(void)
{
	int h, w, k, count = 0, ans = 0, s = 0;
	cin >> h >> w >> k;

	vector<string> a(h);
	for(int i = 0; i < h; i++)
		cin >> a[i];

	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
			if(a[i][j] == '#')
				s++;
	}

	for (int i = 0; i < (1<<h); ++i)
	{
		for (int j = 0; j < (1<<w); ++j)
		{
			count = 0;
			
			for (int x = 0; x < h; ++x)
			{
				for (int y = 0; y < w; ++y)
				{
					if(((i & (1<<x)) || (j & (1 << y))) && a[x][y] == '#')
						count++;
				}
			}

			//cout << count << ' ';
			if(s-count == k)
				ans++;
		}
	}

	cout << ans;
}

Measured memory_bytes: 3640
na,nb,m = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
D = [[int(x) for x in input().split()] for _ in range(m)]

best = min(A) + min(B)
for x,y,c in D:
    cand =  A[x-1] + B[y-1] - c
    if cand < best:
        best = cand
print(best)



Measured memory_bytes: 81644
i = gets.split

gets.to_i.times do
  o = gets.split.map { |e| i.index(e) }
  puts n =
  case o
  when [0, 1] then i[2]
  when [0, 2] then i[4]
  when [0, 3] then i[1]
  when [0, 4] then i[3]

  when [1, 0] then i[3]
  when [1, 3] then i[5]
  when [1, 5] then i[2]
  when [1, 2] then i[0]

  when [2, 0] then i[1]
  when [2, 1] then i[5]
  when [2, 5] then i[4]
  when [2, 4] then i[0]

  when [3, 0] then i[4]
  when [3, 4] then i[5]
  when [3, 5] then i[1]
  when [3, 1] then i[0]

  when [4, 0] then i[2]
  when [4, 2] then i[5]
  when [4, 5] then i[3]
  when [4, 3] then i[0]

  when [5, 1] then i[3]
  when [5, 3] then i[4]
  when [5, 4] then i[2]
  when [5, 2] then i[1]
  end
end

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

const int mod = 100000;
//dp[ pos&1 ][ is nice ][ is prv 'J' ][ bit ] 
int dp[2][2][2][1<<20];

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> g(h);
  rep(i,h)cin >> g[i];
  dp[0][0][0][0] = 1;

  rep(y,h)rep(x,w){
    int cur = (y*w+x)&1, nxt = 1-cur;
    rep(ok,2)rep(J,2)rep(bit,1<<(w-1))dp[nxt][ok][J][bit] = 0;

    rep(ok,2)rep(J,2){
      rep(bit,1<<(w-1)){
	if(dp[cur][ok][J][bit]==0)continue;
	//cerr << y << " " << x << " " << ok << " " << J << " " << bit << endl;
	
	int nxtbit = bit & (~(1<<x));
	if(g[y][x] == 'J' || g[y][x] == '?'){
	  if(x!=w-1){
	    (dp[nxt][ok][1][nxtbit] += dp[cur][ok][J][bit]) %= mod;
	  }else{
	    (dp[nxt][ok][0][nxtbit] += dp[cur][ok][J][bit]) %= mod;
	  }
	}
	
	if(g[y][x] == 'O' || g[y][x] == '?'){
	  if(x!=0 && J){
	    (dp[nxt][ok][0][nxtbit | 1<<(x-1)] += dp[cur][ok][J][bit]) %= mod;
	  }else{
	    (dp[nxt][ok][0][nxtbit] += dp[cur][ok][J][bit]) %= mod;
	  }
	}
	
	if(g[y][x] == 'I' || g[y][x] == '?'){
	  if( (bit>>x)&1 ){
	    (dp[nxt][1][0][nxtbit] += dp[cur][ok][J][bit]) %= mod;
	  }else{
	    (dp[nxt][ok][0][nxtbit] += dp[cur][ok][J][bit]) %= mod;
	  }
	}
      }
    }
    /*
    rep(ok,2)rep(J,2)rep(bit,1<<(w-1)){
      cout << dp[cur][ok][J][bit] << " ";
    }
    cout << endl;
    */
  }
  
  /*
  rep(ok,2)rep(J,2)rep(bit,1<<(w-1)){
    cout << dp[(h*w-1)&1][ok][J][bit] << " ";
  }
  cout << endl;
  */

  int ans = 0;
  rep(J,2)rep(bit,1<<(w-1)){
    (ans += dp[(h*w)&1][1][J][bit]) %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 33972
from operator import add
import sys
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e, operator_func=add):
        self.e = e # 単位元
        self.size = N
        self.node = [self.e] * (2*N)
        self.operator_func = operator_func # 処理(add or xor max minなど)

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size-1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        # [l, r) についてqueryを求める
        x = self.e
        l += self.size
        r += self.size

        while l<r:
            if l&1:
                x = self.operator_func(x, self.node[l-1])
                l += 1
            if r&1:
                r -= 1
                x = self.operator_func(x, self.node[r-1])
            l >>= 1
            r >>= 1
        return x


N, K = map(int, input().split())
P = list(map(int, input().split()))
tree = SegTree(N, 10**12, min)
tree_min = SegTree(N, 10**12, min)
tree_max = SegTree(N, -10**12, max)
tree_min.set_list(P)
tree_max.set_list(P)

for i in range(N):
    tree.update(i, P[i]-P[i-1] if i else P[i])

f = lambda l,r:tree.get(l+1, r)>=0

ans = N-K+1
isOrig = 0
for i in range(N-K):
    if f(i, i+K):
        ans -= 1
        isOrig = 1
    elif tree_min.get(i, i+1+K)==P[i] and tree_max.get(i, i+1+K)==P[i+K]:
        ans -= 1
if f(N-K, N):
    ans -= 1
    isOrig = 1
ans += isOrig
print(ans)

Measured memory_bytes: 104872
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  int n;
  cin >> n;
  set<string> st;
  REP(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  print(st.size());
  return 0;
}

Measured memory_bytes: 19076
if __name__ == '__main__':
    w = int(input())
    result = [i + 1 for i in range(w)]

    n = int(input())

    permutations = []
    for _ in range(n):
        permutations.append(map(lambda x: int(x) - 1, input().split(',')))

    for i, j in permutations:
        result[j], result[i] = result[i], result[j]

    print("\n".join(map(str, result)))


Measured memory_bytes: 5612
import java.util.Scanner;

class Solver{
    final String S;

    Solver(Scanner in){
        S = in.next();
    }

    void solve(){
        char[] chars = S.toCharArray();
        int counter = 0;
        int result = 0;

        for(char ch : chars){
            if(ch == 'S') counter++;
            else if(counter <= 0){
                result++;
            }else counter--;
        }

        System.out.println(result * 2);
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 26524
#!/usr/bin/env python3
import sys


def solve(N: int):
    return sum(range(1, N+1))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9092
//Author : Vipul Sharma

// LIBRARIES
#include <bits/stdc++.h>

// MACROS
#define ll long long int
#define ld long double
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rev(i,b,a) for(ll i=b-1;i>=a;i--)
#define eqrep(i,a,b) for(ll i=1;i<=b;i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define w(t) while (t--)
#define booster                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
# define INF 0x3f3f3f3f 
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << endl;
#define deb4(x, y, z, w) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << "\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

using namespace std;
long long cost = 1e18;



int main()
{
	
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    booster;
    ll n;
    cin>>n;
    cout<<pow(n,1)+pow(n,2)+pow(n,3)<<endl;
    return 0;
}

Measured memory_bytes: 4240
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

void DebugPrint(double a[], int n)
{
#ifdef DEBUG_MODE
	for (int i = 0; i < min(20, n); ++i) {
		cout << a[i] << ",";
	}
	cout << endl;
#endif
}

double dp[3001][3001];

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  

	int n;
	cin >> n;

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

	dp[0][0] = 1.0;

	for (int i = 0; i < n / 2 + 1; ++i) {
		for (int j = i; j < n; ++j) {
			dp[i][j + 1] = dp[i][j + 1] + dp[i][j] * p[j];
			dp[i + 1][j + 1] = dp[i][j] * (1.0 - p[j]);
		}
		DebugPrint(dp[i], n + 1);
	}

	double sum = 0.0;
	for (int i = 0; i < n / 2 + 1; ++i) {
		sum += dp[i][n];
	}

	cout << fixed << setprecision(10) << sum << endl;
	return 0;
}


Measured memory_bytes: 37248
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

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

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

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

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N;
    cin >> N;

    string U, D;
    cin >> U;
    cin >> D;

    llong ans = 0;
    llong now = 0;
    if(U[0] == D[0]) {
        ans = 3;
        now++;
    } else {
        ans = 6;
        now += 2;
    }

    while(now < N) {
        if(U[now] == D[now]) {
            if(U[now - 1] == D[now - 1]) {
                ans *= 2;
                ans %= MOD;
            } else {
                ans *= 1;
            }
            now++;
        } else {
            if(U[now - 1] == D[now - 1]) {
                ans *= 2;
                ans %= MOD;
            } else {
                ans *= 3;
                ans %= MOD;
            }
            now += 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<sstream>
using namespace std;
string htox(){
  
  
}

int main(){
  int num;
  cin >> num;
  for(int k=0;k<num;k++){
    string N;
    bitset<32> b;
    cin >> N;
    for(int i=0;i<8;i++){
      int n;
      if(N[i]>='a')
	n=N[i]-'a'+10;
      else
	n=N[i]-'0';
      for(int j=0;j<4;j++)
	b.set(31-(i*4+j),n&(int)pow(2,3-j));
    }
    if(b[31])
      cout << '-';
    long long int r=0;
    for(int i=7;i<31;i++)
      if(b[i])
	r+=powl(2,i-7);
    cout << r;
    r=0;
    for(int i=0;i<=6;i++)
   if(b[i])
     r+=pow(0.5,7-i)*pow(10,10);
    int j=9;
    cout << '.';
    if(r!=0)
      while(r<pow(10,j)){
	j--;
	cout << 0;
      }
    while(r%10==0 && r!=0)
      r/=10;
      cout << r;
    cout << endl;
  }
  return 0; 
}

Measured memory_bytes: 1280
def main():
    n, m = map(int, input().split())

    c, div = 1, []
    while c * c <= m:
        if not m % c:
            div.append(c)
            if m // c != c:
                div.append(m//c)
        c += 1

    div.sort(reverse=True)
    for g in div:
        if n <= m // g:
            print(g)
            exit()


if __name__ == '__main__':
    main()


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

#define N 100010
#define ll long long

int n,a[N];
ll ans;

int main(){
	ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        ans+=a[i]/2;
        a[i]%=2;
        if(i<n&&a[i]&&a[i+1]){
            ans++;
            a[i]--;
            a[i+1]--;
        }
    }
    cout<<ans;
    return 0;
}

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

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

const int MAXN = 3000;
const ll MOD = 1e9+7;
const ll two = 500000004;

int N, Q, A[MAXN+10], X[MAXN+10], Y[MAXN+10];
ll dp[MAXN+10][MAXN+10], tmp[MAXN+10][MAXN+10], ans;

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d%d", &N, &Q);
    for(i=1; i<=N; i++) scanf("%d", &A[i]);
    for(i=1; i<=Q; i++) scanf("%d%d", &X[i], &Y[i]);

    for(i=1; i<=N; i++) for(j=1; j<=N; j++) if(A[i]>A[j]) dp[i][j]=1;

    for(i=1; i<=Q; i++)
    {
        tmp[X[i]][Y[i]]=tmp[Y[i]][X[i]]=two*(dp[X[i]][Y[i]]+dp[Y[i]][X[i]])%MOD;
        for(j=1; j<=N; j++)
        {
            if(j==X[i] || j==Y[i]) continue;
            tmp[j][Y[i]]=two*(dp[j][Y[i]]+dp[j][X[i]])%MOD;
            tmp[Y[i]][j]=two*(dp[Y[i]][j]+dp[X[i]][j])%MOD;
            tmp[X[i]][j]=two*(dp[X[i]][j]+dp[Y[i]][j])%MOD;
            tmp[j][X[i]]=two*(dp[j][X[i]]+dp[j][Y[i]])%MOD;
        }

        for(j=1; j<=N; j++)
        {
            dp[j][X[i]]=tmp[j][X[i]];
            dp[X[i]][j]=tmp[X[i]][j];
            dp[j][Y[i]]=tmp[j][Y[i]];
            dp[Y[i]][j]=tmp[Y[i]][j];
        }
    }

    for(i=1; i<=N; i++) for(j=i+1; j<=N; j++) ans=(ans+dp[i][j])%MOD;
    for(i=1; i<=Q; i++) ans=(ans*2)%MOD;

    printf("%lld", ans);
    return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)

const int MOD = 1e9+7;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k,x;
    cin >> k >> x;
    if(k*500 >= x) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256