akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int gcd(int x, int y){
    if(x<y) swap(x,y);
    
    if(y == 0) return x;
    
    return gcd(y,x%y);
}

int main(){
    int n; cin >> n;
    
    vi x(n+1);
    rep(i,n+1) cin >> x[i];
    
    
    if(n == 1) {
        cout << abs(x[0]-x[1]) << endl;
        return 0;
    }
    
    
    Sort(x);
    
    int d[n+1];
    rep(i,n){
        d[i] = x[i+1]-x[i];
    }
    
    int ans = d[0];
    rep(i,n-1){
        ans =gcd(ans,d[i+1]);
    }
    

    
    cout << ans << endl;
}






Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import heapq as hq
n, m = map(int, input().split())

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

acc = []
for i in a:
    hq.heappush(acc, [-i, i, 0])

for _ in range(m):
    price, org, disnum = hq.heappop(acc)
    if price == 0:
        break

    new_disnum = disnum + 1
    new_price = org // (2 ** new_disnum)

    hq.heappush(acc, [-new_price, org, new_disnum])

total = 0
for price, _, _ in acc:
    total -= price

print(total)


Measured memory_bytes: 22884
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<vector<char>> C(H,vector<char> (W));
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      cin >> C.at(i).at(j);
    }
  }
  int ans = 0;
  int count =0;
  for (int bith = 0; bith < (1<<H); ++bith) {
    for (int bitw = 0; bitw < (1<<W); ++bitw) {
      count = 0;
        for (int i = 0; i < H; ++i){
          for (int j = 0; j < W; ++j){
            if(!((bith & (1<<i))|| (bitw & (1<<j)))){
                if(C.at(i).at(j)=='#'){
                  count++;
                }
            }
          }
        }

        if(count==K){
          ans++;
        }
    }
  }
  
  cout << ans << endl;
}




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

int main() {
  int N,X,T;
  cin >> N >> X >> T;
  
  int A;
  A = N / X;
  
  int B;
  B = N % X;

  if (B != 0) {
  cout << (A + 1)*T << endl;
  }
  
  else {
  cout << A*T << endl;
  }
}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
#define ll long long

ll mod=1e9+7;
ll pad(ll a,ll b)
{
    ll k=1;
    a%=mod;
    while(b!=0)
    {
        if(b%2==1)
        {
            k=(k*a)%mod;
        }
        a=(a*a)%mod;
        b/=2;
    }
    return k;
}
ll ra(ll x)
{
    return pad(x,mod-2);
}
ll ncr(ll n,ll r)
{
    ll m=max(n-r,r);
    ll s=1,p=1;
    for(ll i=m+1; i<=n; i++)
    {
        s=(s*i)%mod;
    }
    m=min(n-r,r);
    for(ll i=1; i<=m; i++)
    {
        p*=ra(i);
        p%=mod;
    }
    return s*p;
}
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll x=pad(2,n)-1;
    ll y=ncr(n,a) ;
    ll z=ncr(n,b);
    ll c=(x-((y+z)%mod))%mod;
    if(c<0) c=c+mod;
    cout<<c<<"\n";
    return 0;
}


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


long long int knapSack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   long long int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 

int main() {
	// your code goes here
	int n,w;
	cin>>n>>w;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>b[i]>>a[i];
	}
	
	cout<<knapSack(w,b,a,n)<<endl;
	
	return 0;
}

Measured memory_bytes: 79104
s = list(input())
t = list(input())
s.sort()
t.sort()
A = []
B = []
for i in s:
    A.append(ord(i))
for j in t:
    B.append(ord(j))
count=0
if(min(A)<max(B)):
    print("Yes")
    count+=1
else:
    for i in range(min(len(A), len(B))):
        if(min(A)> max(B)):
            print("No")
            count+=1
            break
if(len(set(A)) == len(set(B)) and len(A)<len(B) and count==0):
    print("Yes")
    count+=1
if(count==0):
    print("No")

Measured memory_bytes: 3064
# coding: utf-8
n = int(input())
a = input().split()
stop=0
for i in range(n):
  a[i] = int(a[i])
m = int(min(a)/2)
b=0
for j in range(m):
  for i in range(n):
    if a[i]%2 == 0:
      a[i] = a[i]/2
    else:
      stop = 1
  if stop==1:
    break
  b = b+1
print(b)


Measured memory_bytes: 3060
s = str(input())
l = len(s)
s = s[::-1]
i = 0
while i < l:
    if s[i] == "r":
        if (s[i:min(l,i+7)] == "remaerd"):
            i += 7
        elif (s[i:min(l,i+6)] == "resare"):
            i += 6
        else:
            print('NO')
            break
    
    elif s[i] == "m":
        if (s[i:min(l,i+5)] == "maerd"):
            i += 5
        else:
            print('NO')
            break
            
    elif s[i] == "e":
        if (s[i:min(l,i+5)] == "esare"):
            i += 5
        else:
            print('NO')
            break
            
    else:
        print('NO')
        break
        
    
else:
    print('YES')

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

int main(){
	int a; double b,c;
	while(~scanf("%d,%lf,%lf",&a,&b,&c)) if(b >= 25 * c * c) printf("%d\n",a);

    return 0;
}

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

using namespace std;
map<string,long long> mmp;
set<string> st;
string s;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		mmp[s]++;
		st.insert(s);
	}
	long long ans=0;
	for(auto v:st){
		ans+=(mmp[v]*(mmp[v]-1)/2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define R register int
#define ll long long 
using namespace std;
const int mod=1000000007;
const int N=100001;
int n,w[N],res[N],vis[N];
int le,ri,z,y;ll ans;
vector<int>G[N];
int gi(){
    R x=0,k=1;char c=getchar();
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    if(c=='-')k=-1,c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();	
    return x*k;
}
void work(R k){
	puts("Yes");
	printf("%d\n",k);
	R tot=0;
	for(R i=1;i<=k;++i)
		for(R j=i+1;j<=k;++j)
			tot++,G[i].push_back(tot),G[j].push_back(tot);
	for(R i=1;i<=k;++i){
		printf("%d ",k-1);
		for(R j=0;j<k-1;++j)
			printf("%d ",G[i][j]);
		puts("");
	}
	exit(0);
}
int main(){
	cin>>n;
	if(n==1){
		puts("Yes");
		puts("2");
		cout<<1<<' '<<1<<endl;
		cout<<1<<' '<<1<<endl;
		return 0;
	}
	for(R k=1;k<=n;++k)
		if(k*(k-1)/2==n)
			work(k);
	puts("No");
    return 0;
}


Measured memory_bytes: 4608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int q[] = new int[N];
        for(int i = 0; i < N; i++) {
            int x = sc.nextInt() - 1;
            q[x] = i;
        }
        
        UnionFind nf = new UnionFind(N);
        
        for(int i = 0; i < M; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            nf.unite(x, y);
        }
        
        int ans = 0;
        for(int i = 0; i < N; i++) {
            if( nf.isSame(q[i], i) ) {
                ans++;
            }
        }
        
        System.out.println(ans);
    }
}

class UnionFind {
    int[] parent;
    int[] size;
    int N;
    
    public UnionFind( int N ) {
        parent = new int[N];
        size = new int[N];
        this.N = N;
        for(int i = 0; i < N; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }
    
    public int root(int x) {
        if( parent[x] == x ) return x;
        return parent[x] = root(parent[x]);
    }
    
    public int getSize(int x) {
        return size[root(x)];
    }
    
    public boolean isSame(int x, int y) {
        return root(x) == root(y);
    }
    
    public void unite( int x, int y ) {
        if( isSame(x, y) ) return;
        size[root(y)] += size[root(x)];
        parent[root(x)] = root(y);
    }
    
}


Measured memory_bytes: 59328
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1 << 30
#define LINF (ll)1 << 62
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    set<ll> se;
    rep(i,n){
        ll a; cin >> a;
        if(se.find(a) != se.end()) se.erase(a);
        else se.insert(a);
    }
    cout << se.size() << endl;
}


Measured memory_bytes: 4864
#include <iostream>
#include <stdio.h>
#include <vector>
#include <bitset> 
 
using namespace std;
 
#define daymax ( 30 + 1 )
 
int main(void){
  
    int n;
 
    while ( true ) {
        scanf("%d", &n);
        if( !n ) break;
        vector< bitset< 50 > > schedule( daymax );
        vector< vector< bitset< 50 > > > dp( daymax, vector< bitset< 50 > >( n ) );
        for( int i = 0; i < daymax; i++ )
            schedule[i].reset();
        for( int i = 0; i < n; i++ ) {
            int num;
            scanf("%d",&num);
            for( int j = 0; j < num; j++ ) {
                int tmp;
                scanf("%d",&tmp);
                schedule[tmp].set( i );
            }
        }
 
        for( int i = 0; i < dp.size(); i++ )
            for( int j = 0; j < dp[i].size(); j++ ) {
                dp[i][j].reset();
                dp[i][j].set(j);
            }
 
        int ans = -1;
        for( int i = 1; i < daymax && ans < 0 ; i++ )
            for( int j = 0; j < n && ans < 0; j++ )
                for( int k = 0; k < n && ans < 0 ; k++ ) {
                    if( j == k || ( ( schedule[i].test(j) && schedule[i].test(k) ) ) ) {
                        dp[i][j] |= dp[i-1][k];
                    }
                    if( dp[i][j].count() == n ) {
                        ans = i;
                    }
                }
        cout << ans << endl;
 
    }
    return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b,a % b);}
struct cmp
{
	bool operator()(const pii & a, const pii & b)
	{
		return a.second > b.second;
	}
};
const ll mod = 23333333333333333;
const int maxn = 1e5+5;

int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for (int  i= a; i <= b; i ++ )
	{
		if(i % n == 0)
		{
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
}

Measured memory_bytes: 3164
#include<iostream>

using namespace std;

int main(){
    long long int S;
    cin >> S;
    long long int x1,x2,x3,y1,y2,y3,I;
    I = 1000000000;
    x1=0;
    y1=0;
    x2=I;
    y2=1;
    if((I-S%I)==0){
        I/=0;
    }
    x3 = (I-S%I)%I;
    y3 = (S+x3)/I;
    printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
}


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

		String[] table = new String[h];
		for(int i = 0; i < h; i++) {
			table[i] = sc.next();
		}

		// 確認
		String ans = "Yes";
		boolean flg = false;
		for(int i = 0; i < h; i++) {

			boolean befflg = false;
			for(int j = 0; j < w; j++) {
				if(table[i].charAt(j) == '.') {
					befflg = false;
					continue;
				}

				if(befflg == true) {
					continue;
				}

				flg = false;
				if(i != 0 && table[i-1].charAt(j) == '#') {
					flg = true;
				}
				if(i != h-1 && table[i+1].charAt(j) == '#') {
					flg = true;
				}
				if(j != 0 && table[i].charAt(j-1) == '#') {
					flg = true;
				}
				if(j != w-1 && table[i].charAt(j+1) == '#') {
					flg = true;
				}

				if(flg == false) {
					ans = "No";
					break;
				}
			}
			if(flg == false) {
				break;
			}
		}

		System.out.println(ans);

	}
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<int> cnt(200000, 0);
    rep(i, N) ++cnt[A[i]];
    int ans = 0;
    REP(i, 150000) ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

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);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int n;
	LL k;
	cin>>n>>k;
	int a[200005];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	int town[200005];
	int cur=1;
	int cnt=0;
	for(int i=1;i<=n;i++){
		town[i]=-1;
	}
	while(1){
		cur=a[cur];
		k--;
		cnt++;
		if(town[cur]!=-1){
			k%=(cnt-town[cur]);
			break;
		}
		if(k==0)break;
		town[cur]=cnt;
	}
	while(k>0){
		cur=a[cur];
		k--;
	}
	cout<<cur<<endl;
	return 0;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
#define forn(i,l,r) for(int i=l;i<n;i++)

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long long l[n];
    forn(i,0,n)
        cin>>l[i];
    int ans=0;
    forn(i,0,n)
    {
        forn(j,i+1,n)
        {
            forn(k,j+1,n)
            {
                if(l[i]!=l[j] && l[i]!=l[k] &&l[j]!=l[k] )
                {
                    if((l[i]+l[j])>l[k] && (l[i]+l[k])>l[j] && (l[k]+l[j])>l[i])
                    {
                        //cout<<l[i]<<" "<<l[j]<<" "<<l[k]<<endl;
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int array[6] = {}, sum = 0;

  for(int i=A;i<=B;i++) {
    int num = i;
    for(int j=0; j<5; j++){
      array[j] = num % 10;
      num /= 10;
    }
    if(array[0]==array[4] && array[1]==array[3])
        sum++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
x = int(input())
if x < 7:
    print(1)
elif 6 < x < 12:
    print(2)
else:
    if x%11 == 0:
        print((x//11)*2)
    elif x%11 < 7:
        print((x//11)*2 + 1)
    else:
        print((x//11)*2 + 2)

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

int main(){
    int n,m;
    cin>>n>>m;
    int hyo[n];
    int sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>hyo[i];
        sum+=hyo[i];
    }
    int giri=sum/(4*m);
    sort(hyo,hyo+n);
    for (int j = 0; j < m; ++j) {
        if(sum%(4*m)!=0 && hyo[n-1-j]<=giri){
            cout<<"No"<<endl;
            return 0;
        }
        if(sum%(4*m)==0 && hyo[n-1-j]<giri){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();
    int vectorx = x2 - x1;
    int vectory = y2 - y1;
    int x3 = x2 - vectory;
    int y3 = y2 + vectorx;
    int x4 = x3 - vectorx;
    int y4 = y3 - vectory;
    System.out.println(String.format("%d %d %d %d", x3, y3, x4, y4));
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int n;
int main() {
  //  freopen("test.txt","r",stdin);
    int n,k;
    int a[maxn];
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n-k;i++) {
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
def f(s, k):
    n = len(s)
    if len(set(s)) == 1:
        return n * k // 2
    ans = 0

    c = [1]
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            c[-1] += 1
        else:
            ans += (c[-1] // 2) * k
            if len(c) > 1:
                c.pop()
            c.append(1)
    ans += (c[-1] // 2) * k

    if s[0] == s[n - 1]:
        if c[0] % 2 == 1 and c[-1] % 2 == 1:
            ans += (k - 1)
    return ans

assert f("aba", 1) == 0
assert f("aba", 2) == 1 # aba_ba
assert f("aba", 4) == 3 # aba _ba _ba _ba
assert f("aaa", 4) == 6 # a_a _a_ a_a _a_
assert f("aaa", 3) == 4 # a_a_a_a_a
assert f("aaa", 5) == 7 # a_a_a_a_a_a_a_a
assert f("aa", 1) == 1 # a_
assert f("aa", 2) == 2 # a_a_
assert f("aa", 3) == 3 # a_a_a_
assert f("aa", 4) == 4 # a_a_a_a_
assert f("aaa", 1) == 1 # a_a
assert f("aaa", 2) == 3 # a_a_a_
assert f("aaaa", 1) == 2 # a_a_
assert f("aaaa", 2) == 4 # a_a_a_a_
assert f("aaaa", 3) == 6 # a_a_a_a_a_a_
assert f("qq", 81) == 81
assert f("cooooooooonteeeeeeeeeest", 999993333) == 8999939997
assert f("issii", 2) == 4 # is_i_is_i_

s = input()
k = int(input())
ans = f(s, k)
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int debug_num=0;
#define debug cout<<"debug "<<++debug_num<<" :"

const int maxn=2e5+10;
ll a[maxn];
ll pre[maxn];

map<ll,ll> mp;

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    pre[0]=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    ll ans=0;
    mp[0]++;
    for(int i=1;i<=n;++i){
        ans+=mp[pre[i]];
        mp[pre[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}



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

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  cout << (N + (X - 1)) / X * T << endl;

  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

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

	int arr[n];
	for (int i=0; i<n;i++) {
		scanf("%d", &arr[i]);
	}

	c = 0;
	for (int i=0; i<n; i++) {
		for (int j=n-1; j>i;j--) {
			if (arr[j] < arr[j-1]) {
				c++;
				int tmp = arr[j];
				arr[j] = arr[j-1];
				arr[j-1] = tmp;
			}
		}
	}

	printf("%d", arr[0]);
	for (int i=1; i<n; i++) {
		printf(" %d", arr[i]);
	}
	printf("\n%d\n", c);
}



Measured memory_bytes: 2744
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);

  int h,w,n;cin>>h>>w>>n;

  if(h<w)swap(h,w);

  cout<<(n+h-1)/h<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

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

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x;
	cin >> x;
	cout << (x / 500) * 1000 + (x % 500 / 5) * 5;
	
	return 0;
}












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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    ll cnt = 0;
    bool f = true;
    int n = s.size();
    for(int i = 1; i < n; i++){
        if(s[i - 1] != s[i]){
            f = false;
            break;
        }
    }
    ll ans = 0;
    if(f){
        ans = n * k / 2;
    }else{
        if(s[0] == s.back()){
            ll a = 1, b = 1;
            while(s[a - 1] == s[a]){ a++;};
            while(s[n - b] == s[n - b - 1]){ b++;};
            for(int i = a + 1; i < n - b; i++){
                if(s[i - 1] == s[i]){
                    ans++;
                    s[i] = '0';
                }
            }
            ans = ans * k + (ll)(a / 2) + (ll)(b / 2) + (ll)((a + b) / 2) * (k - 1);
        }else{
            for(int i = 1; i < n; i++){
                if(s[i - 1] == s[i]){
                    s[i] = '0';
                    ans++;
                }
            }
            ans *= k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    sort(a.rbegin(),a.rend());

     if(n==1){
        cout << 0 << endl;
        return 0;
    }
    if(n==2){
        cout << a[0] <<endl;
        return 0;
    }

    ll ans=0;
    int kaisu = (n-1)/2;
    
    for(int i=0; i<=kaisu; i++){
        if(i==0){
            ans+= a[0];
            
            }
         else if(n%2 ==1 && i == kaisu){
            ans += a[i];
           
        }
        else{
            ans += a[i]*2;
           
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4772
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			long n = in.nextLong();
			long m = in.nextLong();
			long l = 0;
			long r = n + m + 1;
			while (r - l > 1) {
				long x = l + (r - l) / 2;
				long additionalS = Math.max(0L, x - n);
				long needC = 2 * x + 2 * additionalS;
				if (needC <= m) {
					l = x;
				} else {
					r = x;
				}
			}
			out.println(l);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}



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

long long GetResult(int n, long long ga, long long sa, long long ba,
              long long gb, long long sb, long long bb) {
  std::vector<long long> f(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + 1;
    if (i >= ba) {
      f[i] = max(f[i], f[i - ba] + bb);
    }
  }
  std::vector<long long> g(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    g[i] = max(f[i - 1] + 1, g[i - 1] + 1);
    if (i >= sa) {
      g[i] = max(g[i], f[i - sa] + sb);
      g[i] = max(g[i], g[i - sa] + sb);
    }
    g[i] = max(g[i], f[i]);
  }
  long long g_num = 0, ans = n, g_b_num = 0;
  while (g_num <= n) {
    ans = max(ans, g_b_num + g[n - g_num]);
    g_num += ga;
    g_b_num += gb;
  }
  return ans;
}

int main() {
  long long n, ga, sa, ba, gb, sb, bb;
  cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;
  n = GetResult(n, ga, sa, ba, gb, sb, bb);
  n = GetResult(n, gb, sb, bb, ga, sa, ba);
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 390912
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


#include <set>
void solve() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> B(m);
  loop(i,0,m) cin >> B[i];
  int ans = 0;
  loop(i,0,n) {
    vector<int> A(m);
    loop(j,0,m) cin >> A[j];
    int x = c;
    loop(j,0,m) x += A[j] * B[j];
    ans += (x > 0);
  }
  cout << ans << endl;
}


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

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

	int64_t max = sqrt(n);
	int64_t sum;
	for (int64_t i = 1; i <= max; i++) {
		if (n % i == 0) {
			sum = i + n / i;
		}
	}

	int64_t ans = sum - 2;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int a, b;

int main(){

    cin >> a >> b;

    for(int i = 1; i < 4; i++){
        if((a*b*i) %2 != 0){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];

    vector<pair<int,int>> flag(20, make_pair(-1,-1));
    ll ans = 0;

    REP(i, n){
        int d = i + 1;
        REP(j, 20){
            if((v[i] >> j) & 1){
                flag[j].second = flag[j].first;
                flag[j].first = i;
            }
            d = min(d, i - flag[j].second);
        }
        ans += d;
    }

    cout << ans << endl;

    return 0;
}

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

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

    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,i,j,buf,m=0;
  cin>>n;
  vector<int> a(n);
  vector<int> ans(n);
  for(i=0;i<n;i++) cin>>a[i];
  vector<int> pos;
  for(i=n-1;i>=0;i--){
    j=(i+1)*2;
    buf=0;
    while(j<=n){
      buf+=ans[j-1];
      j+=i+1;
    }
    buf=buf%2;
    ans[i]=(a[i]+buf)%2;
    if(ans[i]){
      pos.push_back(i+1);
      m++;
    }
  }

  cout<<m<<endl;
  if(m==0) return 0;
  cout<<pos[0];
  for(i=1;i<m;i++) cout<<" "<<pos[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var v = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);

        Array.Sort(v);

        var ans = v[0];
        for (int i = 1; i < n; i++)
        {
            ans = (ans + v[i]) / 2;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
using System;
using System.Linq;

class p{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    string ans = "";
    while (N != 0) {
      if (N % 2 != 0) {
        ans = "1" + ans;
        N = (N - 1) / -2;
      }else{
        ans = "0" + ans;
        N /= -2;
      }
    }
    Console.WriteLine(ans == "" ? "0" : ans);
  }
}

Measured memory_bytes: 11092
class Tree:
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right


def preparse(u):
    if u == -1: return
    print(" ", end="")
    print(u, end="")
    preparse(trees[u].left)
    preparse(trees[u].right)


def inparse(u):
    if u == -1: return
    #???????????????????§????
    inparse(trees[u].left)
    #??¨???
    print(" ", end="")
    print(u, end="")
    #??????????§????
    inparse(trees[u].right)
    

def postparse(u):
    if u == -1: return
    #???????????????????§????
    postparse(trees[u].left)
    #??????????§????
    postparse(trees[u].right)
    #??¨???
    print(" ", end="")
    print(u, end="")


N = int(input())
# ?????????
trees = [Tree(-1,-1,-1) for i in range(N)]
for i in range(N):
    l = list(map(int, input().split()))
    no = l[0]
    left = l[1]
    right = l[2]
    trees[no].left = left
    trees[no].right = right
    if left != -1: trees[left].parent = no
    if right != -1: trees[right].parent = no

r = 0
for i in range(N):
    if trees[i].parent == -1:
        r = i

print("Preorder")
preparse(r)
print("")
print("Inorder")
inparse(r)
print("")
print("Postorder")
postparse(r)
print("")

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

int main(){
    int H, W, M;
    cin >> H >> W >> M;
    set<pair<int, int>> st;
    vector<int> x(300010, 0), y(300010, 0);
    for (int i = 0; i < M; i++) {
        int h, w;
        cin >> h >> w;
        x[h]++;
        y[w]++;
        st.insert({h, w});
    }
    
    int xmax = 0, ymax = 0;
    for (int i = 0; i < 300010; i++) {
        xmax = max(xmax, x[i]);
        ymax = max(ymax, y[i]);
    }
    vector<int> argxmax, argymax;
    for (int i = 0; i < 300010; i++) {
        if (x[i] == xmax) argxmax.push_back(i);
        if (y[i] == ymax) argymax.push_back(i);
    }
    if ((ll)argxmax.size()*(ll)argymax.size() > M) {
        cout << xmax+ymax << endl;
        return 0;
    }else {
        int cand = xmax+ymax-1;
        for (int n : argxmax) {
            for (int m : argymax) {
                auto it = st.find({n, m});
                if (it == st.end()) {
                    cout << xmax+ymax << endl;
                    return 0;
                }else {
                    st.erase(it);
                }
            }
        }
        cout << cand << endl;
        return 0;
    }
	return 0;
}


Measured memory_bytes: 22836
package main

import "fmt"

func main() {
	var a, b string
	fmt.Scan(&a, &b)
	var r string
	switch {
	case a > b:
		r = ">"
	case a == b:
		r = "="
	case a < b:
		r = "<"
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

vector<ll> L;
ll a[100100];

int main()
{
    ll n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    ll length=0;
    L.push_back(a[0]);
    for(ll i=1;i<n;i++){
        if(L[length]<a[i]){
            L.push_back(a[i]);
            length++;
        }
        else{
            *lower_bound(L.begin(),L.end(),a[i])=a[i];
        }
    }
    cout << length+1 << endl;
    return 0;
} 


Measured memory_bytes: 4592
import sys

h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h): #すべての行の塗りつぶし方を2進数で列挙する
 for paint_w in range(2**w): #すべての列の塗りつぶし方を2進数で列挙する
   cnt=0
   for i in range(h): #すべてのi行目j列目の要素についてみる
     for j in range(w):
       if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
         if board[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
           cnt+=1
   if cnt==k: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
     ans+=1
print(ans)


Measured memory_bytes: 9188
def main
  n = ARGF.gets.to_i

  chars = ARGF.gets.chars.to_a

  w_nums = 0
  s1 = chars.map.with_index do |c, i|
    if i == 0
      next 0

    elsif chars[i-1] == "W"
      w_nums += 1
    end
    w_nums
  end

  min_cnt = n-1
  e_nums = 0
  chars.each_with_index.reverse_each do |c, i|
    if i == n-1
      if s1[i] < min_cnt
        min_cnt = s1[i]
      end

    elsif chars[i+1] == "E"
      e_nums += 1
    end
    if s1[i] + e_nums < min_cnt
      min_cnt = s1[i] + e_nums
    end
  end
  puts min_cnt
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 47244
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// using namespace std;

// using ll=long long;
// template<class T> using V = vector<T>;
// template<class T, class U> using P = pair<T, U>;
// using vll = V<ll>;
// using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;

long long powmod(int m, int p) {
    if (p == 0) return 1;
    long long tmp = powmod(m, p / 2);
    if (p & 1) return (tmp * tmp % MOD) * m % MOD;
    else return tmp * tmp % MOD;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];

    std::map<int, int> prime;
    for (int i = 0; i < n; i++) {
        int tmpa = a[i];
        for (int j = 2; j * j <= tmpa; j++) {
            if (tmpa % j == 0) {
                int cnt = 0;
                while (tmpa % j == 0) cnt++, tmpa /= j;
                prime[j] = std::max(prime[j], cnt);
            }
        }
        if (tmpa > 1) prime[tmpa] = std::max(prime[tmpa], 1);
    }

    long long lcm = 1;
    for (std::pair<int, int> p: prime) {
        lcm *= powmod(p.first, p.second);
        lcm %= MOD;
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (lcm * powmod(a[i], MOD - 2)) % MOD;
        if (ans >= MOD) ans -= MOD;
    }
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int h[1502], w[1502];

int main(){

    while(true){
        int N, M;
        cin >> N >> M;
        if(N == 0) break;

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

        map<int, int> h_count;
        for(int i=0;i<N;i++){
            int h_sum = 0;
            for(int j=i;j<N;j++){
                h_sum += h[j];
                h_count[h_sum]++;
            }
        }

        int ans = 0;
        for(int i=0;i<M;i++){
            int w_sum = 0;
            for(int j=i;j<M;j++){
                w_sum += w[j];
                ans += h_count[w_sum];
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 20924
#include <bits/stdc++.h>
#define Pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 7;
inline int R()
{
    int rt = 0; char ch = getchar(); bool isn = false;
    for ( ; ch < '0' || ch > '9'; ch = getchar() ) isn = ch == '-' ? true : isn;
    for ( ; ch >= '0' && ch <= '9'; ch = getchar() ) rt = rt * 10 + ch - '0';
    return isn ? -rt : rt;
}

int n, m;
struct Iv { int l, r; }a[MAXN];
inline bool Cmp ( Iv t1, Iv t2 ) { return t1.r - t1.l < t2.r - t2.l; }

int t[MAXN], ans[MAXN];
void Add ( int pos, int val )
{
	for ( ; pos <= m; pos += ( pos & -pos ) )
		t[pos] += val;
}

int Query ( int pos )
{
	int rt = 0;
	for ( ; pos; pos -= ( pos & -pos ) )
		rt += t[pos];
	return rt;
}

int main()
{
	n = R(), m = R();
	for ( int i = 1; i <= n; ++i )
		a[i].l = R(), a[i].r = R(), ++ans[a[i].r - a[i].l + 1];
	sort ( a + 1, a + n + 1, Cmp );
	int na = 1;
	for ( int i = m; i; --i )
		ans[i] += ans[i + 1];
	for ( int i = 1; i <= m; ++i )
	{
		for ( ; na <= n && a[na].r - a[na].l + 1 < i; ++na )
			Add ( a[na].l, 1 ), Add ( a[na].r + 1, -1 );
		for ( int j = 0; j <= m; j += i )
			ans[i] += Query ( j );
		printf ( "%d\n", ans[i] );
	}
	return 0;
}

Measured memory_bytes: 4352
n = int(input())
dp = [10**9]*30000000
dp[0] = 0
pow6 = [6**i for i in range(10) if 6**i <= n]
pow9 = [9**i for i in range(10) if 9**i <= n]

for i in range(n):
    for p6 in pow6:
        dp[i+p6] = min(dp[i+p6], dp[i]+1)
    for p9 in pow9:
        dp[i+p9] = min(dp[i+p9], dp[i]+1)
print(dp[n])

Measured memory_bytes: 237428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int K, A, B;
    cin >> K >> A >> B;

    if (K <= B && A <= K * (B / K))
    {
        cout << "OK" << endl;
    }
    else
    {
        cout << "NG" << endl;
    }
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int a[7],b[7];
	int i;
	for(i=0;i<7;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for (i=0;i<7;i++){
		printf("%d\n",a[i]-b[i]);
	}
	return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>
int main(){
    char S[101];
    scanf("%s",S);
    int n,x=0;
    for(int i=0;i<101;i++){
        if(S[i]==0){
            n=i;
            i=101;
        }
    }
    for(int i=0;i<n/2;i++){
        if(S[i]!=S[n-1-i]){
            x++;
        }
    }
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
int n;
while (cin >> n){
	REP(i, 10){
		if (n % (1 << (i+1))){
			cout << (1<<i);
			n -= 1 << i;
			if (n==0)
			break;
			cout << " ";
		}
		
	}
	cout << endl;
}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
ll a[MAX] = {};
ll sumn[MAX] = {};

int main(){
   
    ll n,l;
    cin >> n >> l;
    for (ll i=1;i<=n;i++){
        cin >> a[i];
    }
    ll maxv = 0;
    ll maxidx = 0;
    for (ll i=1;i<n;i++){
        sumn[i] = a[i] + a[i+1];
        if(maxv < sumn[i]){
            maxv = sumn[i];
            maxidx = i;
        }
    }
    if(maxv < l){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        for(ll i=1;i<maxidx;i++){
            cout << i << endl;
        }
        for (ll i=n-1;i>maxidx;i--){
            cout << i << endl;
        }
        cout << maxidx << endl;
    }

}

Measured memory_bytes: 2432