akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
      	int n = sc.nextInt();
      	int num[] = new int[n];
      
      	for(int i = 0; i < n; i++){
        	num[i] = sc.nextInt();
        }
      	
      	double sum = 0.0;
      	for(int i = 0; i < n; i++){
         	 sum = sum + ((double)1 / num[i]);          		
        }	
    	
      	System.out.println(1 / sum);
      	
	}
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    int ans = INF;
    REPF(a, 1, N) {
        int b = N - a;
        string A = to_string(a);
        string B = to_string(b);
        int s = 0;
        FORE(x, A) s += x - '0';
        FORE(x, B) s += x - '0';
        chmin(ans, s);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import itertools
n, k = map(int, input().split())
d = list(map(int, input().split()))
ls = []
for i in range(10):
    if i not in d:
        ls.append(i)
mp = 10 ** 9
for j in range(len(str(n)), 7):
    for i in itertools.product(ls, repeat=j):
        m = int("".join(map(str, i)))
        if m >= n:
            mp = min(mp, m)
print(mp)


Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int ans = 0;
	for (int i = 0; i < n; i++) {
		while (n > 0) {
			if (a[i] % 2 == 0) {
				ans++;
				a[i] /= 2;
			}
			else
				break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int N,K;
int main(void){
  cin>>N>>K;
  double p=0;
  for(int i=1;i<=N;i++){
    if(i>=K){
      p+=1.0;
      continue;
    }
    int n=ceil(log2((double)K/(double)i));
    p+=pow(0.5,n);
  }
  cout<<setprecision(12)<<p/(double)N<<endl;
  return 0;
}


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

int main()
{
    int h = 0, w = 0;
 
    while(1)
    {
        cin >> h >> w;
        if(((h>0) && (h<=300)) ||
           ((w>0) && (w<=300)))
        {
               for(int i = 0; i<h ;i++)
               {
                   for(int j = 0; j < w; j++)
                   {
                       if((i == 0) || (i == h-1) || (j == 0)|| (j == w-1))
                       {
                            cout << "#";
                       }
                       else
                       {
                            cout << ".";
                       }
                   }
                   cout << endl;
               }
               cout << endl;
        }
        else if((h == 0) && (w == 0))
        {
            break;
        }      
    }
    return 0;
}


Measured memory_bytes: 3052
class RootedTree
  def solve
    n  = gets.chomp.to_i
    nd = Array.new

    n.times do
      i = gets.split(/\s/).map(&:to_i)
      if i[1] == 0
        unless nd[i[0]]
          nd[i[0]] = [nil, nil]
        end
      else
        if(nd[i[0]])
          nd[i[0]][1] = i[2,i[1]]
        else
          nd[i[0]] = [nil, i[2,i[1]]]
        end
        (1..i[1]).each do |x|
          if(nd[i[x+1]])
            nd[i[x+1]][0] = i[0]
          else
            nd[i[x+1]] = [i[0], nil]
          end
        end
      end
    end

    (0...n).each do |i|
      depth = 0
      prt = nd[i][0]
      while (prt)
        depth += 1
        prt = nd[prt][0]
      end
      print "node #{i}: parent = #{nd[i][0] ? nd[i][0] : -1}, depth = #{depth}, #{nd[i][0] ? (nd[i][1] ? "internal node" : "leaf") : "root"}, "
      print "["
      if nd[i][1]
        print "#{nd[i][1].join(", ")}"
      end
      puts "]"
    end
  end
end

if $0 == __FILE__
  RootedTree.new.solve
end

Measured memory_bytes: 26336
s = int(input())
query = [s]
tmp = s
count = 1
ans = -1
while tmp != 0:
 count += 1
    
 if tmp%2 == 0:
  tmp = tmp//2
  if tmp in query:
    break
  query.append(tmp)
 else:
  tmp = tmp*3 +1
  if tmp in query:
   break
  query.append(tmp)

print(count) 


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <valarray>
#include <utility>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP2(i,m,n) for(int i=m+1;i<=(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<=(int)(n);i++)
#define INF 2000000000
#define INFLL 9000000000000000000
#define MOD 1000000007

typedef long long int ll;

int main() {
    // a 0x61 z 0x7a
    const int AZ = 0x7a - 0x61 + 1;

    int n;
    cin >> n;

    string s[n];

    rep(i, n) {
        cin >> s[i];
    }

    int alphabet[n][AZ] = {};

    rep(i, n) {

        rep(j, s[i].length()) {
            alphabet[i][(int) s[i][j] - 0x61]++;
        }
    }

    rep(j, AZ) {
        int Min = 50;

        rep(i, n) {
            Min = min(Min, alphabet[i][j]);
        }

        rep(i, Min) {
            cout << (char) (j + 0x61);
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#define SIZE 1005

using namespace std;

char str[SIZE];
int n;

bool check()
{
	bool A=false,B=false,C=false,D=false;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='S') A=true;
		else if(str[i]=='N') B=true;
		else if(str[i]=='W') C=true;
		else D=true;
	}
	if(A&&!B) return false;
	if(!A&&B) return false;
	if(C&&!D) return false;
	if(!C&&D) return false;
	return true;
}
int main()
{
	scanf("%s",&str);
	n=strlen(str);
	if(check()) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 128
s = input(); n = len(s); INF=1<<32
dp = [ [0,INF] for i in range(n+1) ]
for i in range(n):
  d = int(s[i])
  dp[i+1][0] = min(dp[i][0], dp[i][1])+d
  dp[i+1][1] = min(dp[i][0], dp[i][1]-2)+11-d
print(min(dp[n][0],dp[n][1]))

Measured memory_bytes: 137952
N = int(input())
A = list(map(int , input().split()))
B = list(map(int , input().split()))

count = 0

hero_old = 0

for i in range(N + 1):
    enemy_now = A[i]
    if i == N:
        hero_now = 0
    else:
        hero_now = B[i]
    count += min([enemy_now, hero_old])
    enemy_now = max([0, enemy_now - hero_old])
    count += min([enemy_now, hero_now])
    hero_old = max([0, hero_now - enemy_now])

print(count)


Measured memory_bytes: 18624
x,k,d = map(int, input().split())

if x == 0:
    if k % 2 == 0:
        print(0)
    else:
        print(d)
else :
    if abs(x) > k * d:
        if x > 0:
            print(x - k * d)
        else:
            print(abs(x + k * d))
    else:
        if x > 0:
            aaa = x // d
            a = x - aaa * d
            b = x - (aaa + 1) * d
            if abs(a) >= abs(b):
                if (k - (aaa + 1))%2 == 0:
                    print(abs(b))
                else:
                    print(abs(a))
            else:
                if (k - aaa)%2 == 0:
                    print(abs(a))
                else:
                    print(abs(b))
                
        else:
            aaa = abs(x) // d
            a = x + aaa * d
            b = x + (aaa + 1) * d
            if abs(a) >= abs(b):
                if (k - (aaa + 1))%2 == 0:
                    print(abs(b))
                else:
                    print(abs(a))
            else:
                if (k - aaa)%2 == 0:
                    print(abs(a))
                else:
                    print(abs(b)) 

Measured memory_bytes: 9216
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

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

	int mm1 = n/100;
	int mm2 = n%100;	

	if(mm2<=12 and mm2 > 0 and mm1<=12 and mm1 >0){
		cout<<"AMBIGUOUS"<<endl;
	}else if(mm2<=12 and mm2 >0){
		cout<<"YYMM"<<endl;
	}else if(mm1<=12 and mm1>0){
		cout<<"MMYY"<<endl;
	}
	else{
		cout<<"NA"<<endl;
	}

	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <numeric>

using namespace std;

int main() {
  char *line = NULL;
  size_t buffer_size = 0;
  while (getline(&line, &buffer_size, stdin) > 0) {
    int ls[10];
    int v1, v2;
    sscanf(line, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
           ls, ls+1, ls+2, ls+3, ls+4, ls+5, ls+6, ls+7, ls+8, ls+9,
           &v1, &v2);
    int total_len = accumulate(ls, ls + 10, 0);
    double x1 = v1 * static_cast<double>(total_len) / (v1 + v2);
    for (int i = 0, acc = 0; i < 10; ++i) {
      acc += ls[i];
      if (x1 <= acc) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
  free(line);

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   
    cin>>n;
    vi a(n+1,2);
    a[1]=1;
    for(i=2;i<=n;i++)
    {
        for(j=i*2;j<=n;j+=i)a[j]++;
    }
    c=0;
    fo1(i,n)c+=i*a[i];
    
    
    cout<< c <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 81312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
///................function.....................///
#define siz(s) (int)(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mod 1000000007
int main()
{
    FIO;
    ///freopen("in.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    if(s.back()=='s')
        s+="es";
    else s+="s";
    cout<<s<<endl;
}


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

struct Point {
  double x;
  double y;
};

void kock(int n, Point p1, Point p2) {
  if (n == 0) return;
  Point s, t, u;
  double r = 60.0 * M_PI / 180.0;
  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = (t.x - s.x) * cos(r) - (t.y - s.y) * sin(r) + s.x;
  u.y = (t.x - s.x) * sin(r) + (t.y - s.y) * cos(r) + s.y;
  kock(n -1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);
  kock(n -1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  kock(n -1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  kock(n -1, t, p2);
}

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

  int n;
  cin >> n;

  Point p1, p2;
  p1.x = 0.0;
  p1.y = 0.0;
  p2.x = 100.0;
  p2.y = 0.0;
  printf("%.8f %.8f\n", p1.x, p1.y);
  kock(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

  cout << ((n / 10) % 111 == 0 || (n % 1000) % 111 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, c;
    cin >> n >> m >> c;
    int k = max(n, m);
    cout << (c + k - 1) / k;
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int a, b, m;
            ReadInt(out a, out b, out m);
            var A = ReadIntArray();
            var B = ReadIntArray();

            int ans = A.Min() + B.Min();

            for (int i = 0; i < m; i++)
            {
                int x, y, c;
                ReadInt(out x, out y, out c);
                x--;
                y--;

                ans = Min(ans, A[x] + B[y] - c);
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 36444
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> a(3*N);
    rep(i,3*N)cin >> a[i];
    sort(All(a));
    ll res = 0;
    rep(i,N){
        res+=a[3*N-(2*(i+1))];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int gcd(int a,int b){
  if(a<b){
    int64 tmp=a; a=b; b=tmp;
  }
  int64 r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n){
    cin>>a[i];
  }
  if(n==2){
    cout<<max(a[0],a[1]);
  }else{
    int left[n-1],right[n-1];
    left[0]=a[0]; right[0]=a[n-1];
    rep1(i,n-1){
      left[i]=gcd(left[i-1],a[i]);
      right[i]=gcd(right[i-1],a[n-1-i]);
    }
    int ans=max(left[n-2],right[n-2]);
    rep(i,n-2){
      ans=max(ans,gcd(left[i],right[n-3-i]));
    }
    cout<<ans;
  }
}


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

using namespace std;

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0)
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;


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


void inm_to(int &a, int b) { a = (ll) a * b % Mod; }
int inm(int a, int b) { return (ll) a * b % Mod; }
void add_to(int &a, int b) { a += b; if(a >= Mod) a -= Mod; }

int power(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b&1) inm_to(ans, a);
        inm_to(a, a); b >>= 1;
    }
    return ans;
}

int inv(int a)
{
    return power(a, Mod-2);
}

/////////////////////////////////////////////////////////

int N, M, cnt, pos[50], where[50], comp;
map<int,int> id;
pair<int,int> R[50];
int coef[1<<16], dp[1<<16], dp2[1<<16];


void dfs(int node, int comp)
{
    if(where[node]) return;

    where[node] = comp;
    int i;
    for(i=1; i<=M; ++i)
        if(R[i].first == pos[node])
            dfs(id[R[i].second], comp);

    for(i=1; i<=M; ++i)
        if(R[i].second == pos[node])
            dfs(id[R[i].first], comp);
}

void calc_subsets()
{
    int i, j, k;
    for(i=0; i<(1<<comp); ++i)
    {
        coef[i] = 1;

        for(j=0; j+1<cnt; ++j)
            if((i & (1<<where[j])) && (i & (1<<where[j+1])))
                inm_to(coef[i], 1 + inm(9, inv(power(10, pos[j+1] - pos[j]) - 1)));
    }
}

void do_dp()
{
    int i, j;
    for(i=0; i<(1<<comp); ++i)
    {
        for(j=i; j; j = (j-1) & i)
            add_to(dp2[i], inm(dp[j], coef[i ^ j]));
        add_to(dp2[i], inm(dp[0], coef[i]));
    }
}

void solve()
{
    int i, j;
    dp[0] = 1;

    for(i=0; i<9; ++i)
    {
        do_dp();
        for(j=0; j<(1<<comp); ++j)
            dp[j] = dp2[j], dp2[j] = 0;
    }

    int ans = dp[(1<<comp) - 1];

    inm_to(ans, power(10, pos[0]));
    inm_to(ans, power(10, N - pos[cnt - 1]));

    for(i=0; i+1 < cnt; ++i)
        inm_to(ans, inm( power(10, pos[i+1] - pos[i]) - 1, inv(9) ));
    cout << inm(ans, inv(9)) << '\n';
}

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

    cin >> N >> M;

    int i, x, y;
    for(i=1; i<=M; ++i)
    {
        cin >> x >> y; --x;
        R[i] = {x, y};
        id[x] = 1; id[y] = 1;
    }

    cnt = 0;
    for(auto &it : id)
    {
        it.second = cnt;
        pos[cnt] = it.first;
        cnt++;
    }

    comp = 0;
    for(i=0; i<cnt; ++i)
        if(!where[i])
        {
            ++comp;
            dfs(i, comp);
        }

    for(i=0; i<cnt; ++i) where[i] --;

    calc_subsets();
    solve();

    return 0;
}


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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A * N, B) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

int nowPlace(int in[], int now, int miFlag){
	int p = 0, m = 0, ptr = 0;
	if (miFlag == 0){
		while (p <= now){
			p += in[ptr];
			ptr++;
		}
		return ptr;
	}
	else{
		ptr = 9;
		while (m <= now){
			m += in[ptr];
			ptr--;
		}
		ptr += 2;
		return ptr;
	}
}

int solve(int in[]){
	cout << "nowSolve" << endl;
	int plusV = in[10];
	int miV = in[11];
	int minFlag = 0,  SA = plusV - miV;
	if (SA < 0)	minFlag = 1;
	// 現在位置
	int nowPlus = 0, nowMi = 0;
	for (int i = 0; i < 10; i++)	in[i] *= 1000;
	while (1){
		nowPlus++;
		nowMi++;
		if (minFlag)	nowMi += -SA;
		else			nowPlus += SA;
		cout << "nowPlus = " << nowPlus << " , nowMi = " << nowMi << endl;
		cout << "nowPlace plus = " << nowPlace(in, nowPlus, 0) << " , nowPlace mi = " << nowPlace(in, nowMi, 1) << endl;
		if (nowPlace(in, nowPlus, 0) >= nowPlace(in, nowMi, 1))
			return nowPlace(in, nowPlus, 0);
	}

}

int solve2(int in[]){
	int longSum = 0, v1 = in[10], v2 = in[11];
	int ptr = 0;
	double temp = 0;
	for (int i = 0; i < 10; i++)	longSum += in[i];
	// (左端0としたときの)すれちがう位置
	temp = (double)(longSum * v1) / (v1 + v2);
	while (temp > 0){
		temp -= in[ptr];
		ptr++;
	}
	return ptr;
}

int main(){
	int in[13];
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
		&in[0], &in[1], &in[2], &in[3], &in[4], &in[5], &in[6], &in[7], &in[8], &in[9], &in[10], &in[11])
		!= EOF){
		cout << solve2(in) << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
N,M,X,Y=list(map(int,input().split(" ")))
x=list(map(int,input().split(" ")))
y=list(map(int,input().split(" ")))

if max(X,sorted(x)[-1])<min(Y,sorted(y)[0]): # 戦争が起こらない場合
    print("No War")
else: # 戦争が起こる場合
    print("War")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  long double a, b, c;
  cin >> a >> b >> c;
  if (a + b + 2 * sqrt(a * b) < c)
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    bool v[2000010];
    memset(v, 1, sizeof v);
    for(int i = 3; i < 2000010; i += 3)
        v[i] = 0;
    for(int i = 5; i < 2000010; i += 5)
        v[i] = 0;
    ll n; cin >> n;
    ll cnt = 1, ans = 0;
    for(int i = 1; i <= n; i += 1){
        if(v[i]){
            ans += i;
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<ll> p(k, 0);
	rep2(i, 1, n+1)p.at(i%k)++;

	ll ans = 0;
	rep(a, k){
		int b = (k - a) % k;
		int c = (k - a) % k;
		if((b+c) % k != 0) continue;
		ans += p.at(a) * p.at(b) * p.at(c);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
import math


def main():
    N, K = map(int, input().split())
    accum = 0
    for i in range(1, len(bin(K)) - 2 + 1):
        cur = max(0, N - (math.ceil(K * 0.5 ** i)) + 1) * 0.5 ** i
        pre = max(0, N - (math.ceil(K * 0.5 ** (i - 1))) + 1) * 0.5 ** i
        accum += cur - pre
    print((max(0, N - K + 1) + accum) / N)
    return


main()


Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void) {
     
    int i, j, n, s, minj, count = 0;
    int a[100];
     
    scanf("%d", &n);
    for( i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
     
   
            for( i = 0; i < n-1; i++){
                minj = i;
                for( j = i; j < n; j++){
                	if( a[j] < a[minj]){
                		minj = j;
                	}
                }
                if(i!= minj){
                		s = a[i];
                		a[i] = a[minj];
                		a[minj] = s;
                    count = count + 1;
                }
}
       
     
    for(i = 0; i < n-1; i++){
        printf("%d ", a[i]);
    }
        printf("%d\n",a[n-1]);
        printf("%d\n", count);
         
    return 0;
     
}

Measured memory_bytes: 1792
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    if N == M:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61748
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n,a,b; cin>>n>>a>>b;
  if(n%(a+b)==0){
    cout<<(n/(a+b))*a;
    return ;
  }
  ll x = n/(a+b);
  if(x*(a+b)<n){
    ll ans=x*a;
    ll r=n%(a+b);
    ans+=min(r,a);
    cout<<ans;
  }
  else{
    ll ans=x*a;
    ans+=min(a,n%(a+b));
    cout<<ans;
  }
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define MAXN 205
#define mod 1000000007
using namespace std;

struct VectorImg {
    vector<long long> v;
    long long remOp;
};

struct Comp {
    bool operator()(const vector<long long> &v1, const vector<long long> &v2) const {
        for (int i = 0; i < (int) v1.size(); ++i)
            if (v1[i] != v2[i])
                return v1[i] < v2[i];
        return 0;
    }
};

int n;
long long k, a[MAXN];
map<vector<long long>, vector<pair<long long, long long>>, Comp> difVals;
map<vector<long long>, bool, Comp> uz;

void addToDifVals(const VectorImg &vi) {
    vector<long long> v;

    for (int i = 1; i < (int) vi.v.size(); ++i)
        v.push_back(vi.v[i] - vi.v[i - 1]);

    if (!difVals.count(v))
        difVals[v] = vector<pair<long long, long long>>();
    
    difVals[v].push_back(make_pair(max(vi.v[0] - vi.remOp, 0LL), vi.v[0]));
}

VectorImg shift(const VectorImg &vi) {
    VectorImg ans;

    ans.remOp = vi.remOp - 1;
    for (auto x: vi.v)
        ans.v.push_back(x >> 1);

    return ans;
}

VectorImg decrementAndShift(const VectorImg &vi) {
    VectorImg ans;

    ans.remOp = vi.remOp - 2;
    for (auto x: vi.v)
        ans.v.push_back((x - 1) >> 1);

    return ans;
}

void bkt(const VectorImg &vi) {
    if (uz[vi.v])
        return;

    uz[vi.v] = 1;
    addToDifVals(vi);

    if (vi.v.back() > 0 && vi.remOp >= 1) {
        VectorImg newVi = shift(vi);
        bkt(newVi);
    }
    if (vi.v.front() > 0 && vi.v.back() >= 2 && vi.remOp >= 2) {
        VectorImg newVi = decrementAndShift(vi);
        bkt(newVi);
    }
}

long long getIntervalSpan(vector<pair<long long, long long>> &v) {
    sort(v.begin(), v.end());

    long long ans = 0;
    long long left = 0, right = -1;

    for (auto &x: v) {
        if (x.first > right) {
            ans += right - left + 1;
            left = x.first;
            right = x.second;
        }
        else
            right = max(right, x.second);
    }

    ans += right - left + 1;
    return ans;
}

int main() {
    ios::sync_with_stdio(0);

    cin >> n >> k;
    VectorImg vi;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        vi.v.push_back(a[i]);
    }

    sort(vi.v.begin(), vi.v.end());
    vi.remOp = k;

    bkt(vi);

    long long sol = 0;
    for (auto &x: difVals)
        sol = (sol + getIntervalSpan(x.second)) % mod;

    cout << sol << "\n";

    return 0;
}

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


using namespace std;

#define re return
#define sz(a) (int)a.size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 0; i < int(n); i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long double ld;

int n, a, b;
int main() {
	iostream::sync_with_stdio(0), cin.tie(0);
	//freopen("a.in", "r", stdin);
	cin >> n >> a >> b;
	if (a % 2 == b % 2) cout << "Alice\n";
	else
		cout << "Borys\n";
	re 0;

}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
const ll MOD = 1'000'000'007; // 998'244'353;

// #include <atcoder/all>
// using namespace atcoder;

int main() {
	// 0-ind
	prec(2);
	int N; cin >> N;
	vi t(N); rep(i, N) cin >> t[i];
	vi v(N); rep(i, N) cin >> v[i];

	int T = accumulate(all(t), 0);
	vi V(T); // V[i]:時刻i~i+1に出すことのできる速度
	int cur = 0;
	rep(i, N) {
		rep0(t[i]) {
			V[cur] = v[i];
			cur++;
		}
	}
	// dbl(V);
	vi M(T + 1, INF); // M[i]:時刻T[i]において出すことのできる最大の速度
	cur = 0;
	rep(i, N) {
		chmin(M[cur], v[i]);
		rep0(t[i]) {
			cur++;
			chmin(M[cur], v[i]);
		}
	}
	// dbl(M);
	M[0] = 0;
	rep2(cur, 1, T) chmin(M[cur], M[cur - 1] + 1);
	M[T] = 0;
	rep3(cur, T - 1, 0) chmin(M[cur], M[cur + 1] + 1);
	// dbl(M);

	float ans = 0.0;
	rep(cur, T) {
		if (M[cur] != M[cur + 1]) {
			ans += (M[cur] + M[cur + 1]) / 2.0f;
		} else {
			if (M[cur] < V[cur]) {
				ans += M[cur] + 0.25f;
			} else {
				ans += M[cur];
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	int count4 = 0;
	int count2 = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		if (tmp % 4 == 0)
			count4++;
		else if (tmp % 2 == 0)
			count2++;
	}

	if (count2 + count4 == 0)
	{
		cout << "No" << endl;
		return;
	}
	count2 = max(count2, 1);

	if (N <= count2 + count4 * 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int change(char x) {
  if (x == '1') return 1;
  if (x == '2') return 2;
  if (x == '3') return 3;
  if (x == '4') return 4;
  if (x == '5') return 5;
  if (x == '6') return 6;
  if (x == '7') return 7;
  if (x == '8') return 8;
  if (x == '9') return 9;
}
int main() {
  string S;
  cin >> S;
  vector<int> vec(S.size() - 2), vec2(S.size() - 2);
  int a, b, c;
  for (int i = 0; i < S.size() - 2; i++) {
    a = change(S.at(i));
    b = change(S.at(i + 1));
    c = change(S.at(i + 2));
    vec.at(i) = a * 100 + b * 10 + c;
  }
  for (int i = 0; i < S.size() - 2; i++) {
    if (vec.at(i) > 753) vec2.at(i) = vec.at(i) - 753;
    else vec2.at(i) = 753 - vec.at(i);
  }
  sort(vec2.begin(), vec2.end());
  cout << vec2.at(0) << endl;
}

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

int main(){
    int n; cin>>n;
    int ans=111;
    for(int i=1;i<10;i++){
        if(i*111<n and n<=(i+1)*111){
            ans=(i+1)*111;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
  int n; cin>>n;
  vector<vector<int>> num(9,vector<int>(9));
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      num[i][j]=(i+1)*(j+1);
    }
  }
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      if(num[i][j]==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

struct edge{
    int from,to,cost;
};

int n,q,k;
queue<int> que;

int main(void){
    cin >> n;
    vector<int> a(n-1);
    vector<int> b(n-1);
    vector<int> c(n-1);
    REP(i,n-1){
        cin >> a[i] >> b[i] >> c[i];
    }
    cin >> q >> k;
    vector<int> x(q);
    vector<int> y(q);
    REP(i,q){
        cin >> x[i] >> y[i];
    }
    vector<vector<edge>> e(n);
    vector<ll> d(n,LLONG_MAX);
    REP(i,n-1){
        edge edg1 = {a[i]-1,b[i]-1,c[i]};
        e[a[i]-1].push_back(edg1);
        edge edg2 = {b[i]-1,a[i]-1,c[i]};
        e[b[i]-1].push_back(edg2);
    }
    que.push(k-1);
    d[k-1] = 0;
    while(que.size()){
        int i = que.front();que.pop();
        
        REP(j,e[i].size()){
            int ni = e[i][j].to;
            if(d[ni]==LLONG_MAX){
                que.push(ni);
                d[ni] = d[i]+e[i][j].cost;
            }
        }
    }
    vector<ll> res(q);
    REP(i,q){
        res[i] = d[x[i]-1] + d[y[i]-1];
    }
    REP(i,q){
        put(res[i]);
    }
    return 0;
}


Measured memory_bytes: 11956
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		int n;
		while(sc.hasNextInt()){
			n = sc.nextInt();
			
			if(n >= 512){
				n -= 512;
				list.add(512);
			}
			if(n >= 256){
				n -= 256;
				list.add(256);
			}
			if(n >= 128){
				n -= 128;
				list.add(128);
			}
			if(n >= 64){
				n -= 64;
				list.add(64);
			}
			if(n >= 32){
				n -= 32;
				list.add(32);
			}
			if(n >= 16){
				n -= 16;
				list.add(16);
			}
			if(n >= 8){
				n -= 8;
				list.add(8);
			}
			if(n >= 4){
				n -= 4;
				list.add(4);
			}
			if(n >= 2){
				n -= 2;
				list.add(2);
			}
			if(n >= 1){
				n -= 1;
				list.add(1);
			}
			for(int i = 0; i < list.size(); i++){
				if(i != list.size() - 1)
					System.out.print(list.get(list.size() - i - 1) + " ");
				else
					System.out.println(list.get(0));
			}
			list.clear();
		}
		sc.close();
	}
}

Measured memory_bytes: 17224
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}

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

int main(){
    int n,r;
    cin >> n >> r;
    if(n<10){
        cout << r + (100 * (10 - n));
    }
    else cout << r;
    return 0;
}

Measured memory_bytes: 256
class segTreeMin:
  # 区間最小値を求めるセグメント木
  inf = 10**10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.inf = num
    s.T = [s.inf] * (2 * s.N)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i + 1, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, x):
    return s.T[x + s.N - 1]
  def getArea(s, l, r):
    L = l + s.N
    R = r + s.N
    p = s.inf
    while L < R:
      if R & 1:
        R -= 1
        p = s.do(p, s.T[R - 1])
      if L & 1:
        p = s.do(p, s.T[L - 1])
        L += 1
      L >>= 1
      R >>= 1
    return p

class segTreeMax:
  # 区間最大値を求めるセグメント木
  inf = -1
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N)
  def do(s, l, r):
    #最大値
    return max(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i + 1, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, x):
    return s.T[x + s.N - 1]
  def getArea(s, l, r):
    L = l + s.N
    R = r + s.N
    p = s.inf
    while L < R:
      if R & 1:
        R -= 1
        p = s.do(p, s.T[R - 1])
      if L & 1:
        p = s.do(p, s.T[L - 1])
        L += 1
      L >>= 1
      R >>= 1
    return p

N = int(input())
a = list(map(int, input().split()))

segMax = segTreeMax(N)
segMin = segTreeMin(N)

D = [[0] * 2 for _ in range(N)]
L = [0] * N

for i in range(N):
  t = a[i] - 1
  L[t] = i
  
ans = 0
for i in range(N):
  l = segMax.getArea(0, L[i] + 1)
  r = segMin.getArea(L[i], N)
  ans += (i + 1) * (L[i] - l) * (r - L[i])
  segMax.update(L[i], L[i])
  segMin.update(L[i], L[i])

print(ans)

Measured memory_bytes: 123044
class SegmentTree:
	def __init__(self, orig, func, unit):
		_len = len(orig)
		self.func = func
		self.size = 1 << (_len - 1).bit_length()
		self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
		self.unit = unit

		for i in range(self.size - 1, 0, -1):
			self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])

	def update(self, i, v):
		i += self.size
		self.tree[i] = v
		while i:
			i //= 2
			self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def find(self, l, r):
		l += self.size
		r += self.size
		ret = self.unit
		while l < r:
			if l & 1:
				ret = self.func(ret, self.tree[l])
				l += 1
			if r & 1:
				r -= 1
				ret = self.func(ret, self.tree[r])
			l //= 2
			r //= 2
		return ret

import sys
input = sys.stdin.readline
from operator import or_

def main():
	input()
	seg = SegmentTree([1 << ord(x) - 97 for x in input()[:-1]], or_, 0)
	ans = []
	for _ in range(int(input())):
		f, x, y = input().split()
		if f == "1":
			seg.update(int(x) - 1, 1 << ord(y) - 97)
		else:
			ans.append(bin(seg.find(int(x) - 1, int(y))).count("1"))
	print(*ans)

if __name__=="__main__":
	main()

Measured memory_bytes: 48076
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

const int A_MAX = 1000000;
const int A_MIX = 1000;

void primeset(vector<bool> &prime){
  prime.at(0) = false; prime.at(1) = false;
  int i=1;
  while (i <= A_MIX){
    if (!prime.at(i)){ i++; continue;}
    int tmp = i*2;
    while (tmp <= A_MIX){
      prime.at(tmp) = false; tmp += i;
    }
    i++;
  }
}

int main() {
  int n; cin >>n;
  vector<ll> a(n);
  rep(i, n) cin >>a.at(i);
  /* aの全要素の最小公倍数をXと置くと、b[i] = X / a[i].
     これらの和をMODで割った余りが欲しい。従ってX / a[i] (mod MOD)を足し合わせていけばよい。
     乃ちa[i]の逆元をinversea[i]と置くとX *inversea[i] (mod MOD)を足し合わせていけばよい。
     従ってY = X (mod MOD)と置くとY * inversea[i] (mod MOD)を足し合わせて行けばよい。
     inversea[i]はパパっと計算するとして、a[i]の全要素の最小公倍数Xの情報は求めておく必要がある。
  */

  vector<bool> prime(A_MIX + 1,true);
  primeset(prime);
  vector<ll> primes;
  rep(i, A_MIX + 1) if (prime.at(i)) primes.push_back(i);
  // primesには10^3までの素数が順番に格納されている

  vector<ll> Aprime(A_MIX + 1,0); // 素因数分解
  set<int> primes2; //10^3より大きい素数を格納する。指数は高々1

  for (int i=0; i<n; i++){
    // 各a[i]について素因数分解を行い、指数が大きいものがあれば反映する
    map<int,int> tmpvec;
    ll buf = a.at(i);
    for (int j=0; j<primes.size(); j++){
      ll tmp2 = primes.at(j);
      while (buf % tmp2 == 0){
        buf /= tmp2; tmpvec[tmp2] += 1;
      }
      if (buf == 1) break;
    }
    if (buf != 1) primes2.insert(buf);
    for (auto x : tmpvec){
      auto k = x.first; auto v = x.second;
      if (Aprime.at(k) < v) Aprime.at(k) = v;
    }
  }

  ll y = 1;
  for (int i=2; i<Aprime.size(); i++){
    if (Aprime.at(i) != 0){
      y = y * powerM((ll)i, Aprime.at(i)) % MOD;
    }
    if (i % 2 == 1) i++;
  }
  for (auto x : primes2){
    y = y * x % MOD;
  }

  ll ans = 0;
  rep(i, n){
    ll gyakugen = powerM(a.at(i), MOD-2);
    ans = ans + y * gyakugen % MOD;
    ans %= MOD;
  }

  cout <<ans <<endl;
}

Measured memory_bytes: 768