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

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;

vi V;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	ll ans = 0;
	ll x; cin >> x;
	ll y = x/500;
	x -= (y*500);
	ans += 	y*1000;
	ll z = x/5;
	ans += z*5;
	cout << ans << '\n';
		
	return 0;
}


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


int main()
{
    char st1[100] = {};
    cin >> st1;
    set<char>st;
    for(int i = 0; i < strlen(st1); i++)
    {
        st.insert(st1[i]);
    }
    if(st.size() == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		for(int i = 0; i < n; i++) {
			children[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				if(children[i] > children[j]) {
					int tmp = children[i];
					children[i] = children[j];
					children[j] = tmp;
				}
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			if((x = x - children[i]) >= 0) {
				count++;
			}else {
				break;
			}
			if(i == n-1) {
				if(x > 0) {
					count--;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A;
  cin >> B;
  if((B-1)%(A-1) == 0)
    cout << (B-1)/(A-1) << endl;
  else
    cout << (B-1)/(A-1) + 1 << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

bool solve() {
	ll n, m;
	cin >> n >> m;
	
	vvl adj(n);
	while (m--) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	FOR(i,0,n) if (sz(adj[i]) % 2 != 0) return false;

	map<ll,ll> deg_cnt;
	FOR(i,0,n) deg_cnt[min(6LL,sz(adj[i]))]++;

	if (deg_cnt[6] >= 1) return true;
	if (deg_cnt[4] <= 1) return false;
	if (deg_cnt[4] >= 3) return true;
	
	ll i = 0;
	while (sz(adj[i]) == 2) i++;
	
	for (ll j: adj[i]) {
		ll a = i, b = j;
		while (sz(adj[b]) == 2) {
			a ^= adj[b][0] ^ adj[b][1];
			swap(a,b);
		}
		if (b == i) return true;
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << (solve() ? "Yes" : "No") << endl;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, m;

void solve(){
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int ans = -1;
    rep(i, n)For(j, i + 1, n){
        if(a[i] + a[j] <= m) chmax(ans, a[i] + a[j]);
    }
    if(ans < 0) puts("NONE");
    else printf("%d\n", ans);
}

int main(){
    while(scanf("%d%d", &n, &m) && n){
        solve();
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long X, long long Y, long long Z) {
  // solver code
  swap(X, Y);
  swap(X, Z);

  cout << X << " " << Y << " " << Z << endl;
}

int main() {
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  long long Z;
  scanf("%lld", &Z);
  solve(X, Y, Z);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;


public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = sc.nextInt();
        String[] S = new String[N];
        for(int i=0;i<N;i++){
            S[i] = sc.next();
        }

    Arrays.sort(S);
    TreeSet<String> s = new TreeSet<>();
    int c = 1;
    int M = 1;
    for(int i=0;i<N-1;i++){
        if(S[i].equals(S[i+1])){
            c++;
        }
        else{
            if(c>M){
                s.clear();
                s.add(S[i]);
                M = c;
            }
            else if(c==M){
                s.add(S[i]);
                M = c;
            }
            c = 1;
        }
    }

    if(c>M){
        s.clear();
        s.add(S[N-1]);
    }
    else if(c==M){
        s.add(S[N-1]);
    }

    for(String a :s){
        out.println(a);
    }


        out.flush();
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 61440
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)

ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int mod=1e9+7;
const int maxn=3050;
int n,k;
ll f[maxn][maxn];
ll fac[maxn*maxn],inv[maxn*maxn];

inline int C(int x,int y){
	if(x<y) return 0;
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	n=read(),k=read();
	if(k==1){
		puts("1");
		return 0;
	}
	fac[0]=1;
	rep(i,1,3000*3000) fac[i]=fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	rep(i,2,3000*3000) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	rep(i,1,3000*3000) inv[i]=inv[i]*inv[i-1]%mod;
	f[0][0]=1;
	rep(i,1,n){
		rrep(j,i,0){
			f[i][j]=f[i][j+1]%mod;
			if(j){
				f[i][j]+=f[i-1][j-1]*C(i*k-j-1,k-2)%mod;
				f[i][j]%=mod;
			}
		}
	}
	cout<<f[n][0]*fac[n]%mod;
	return 0;
}


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

int main()
{
    int n; string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        int cnt = 0;

        for (char c = 'a'; c <= 'z'; c++)
        {
            bool left = false, right = false;

            for (int j = 0; j < i; j++)
                if (s[j] == c)
                    left = true;

            for (int j = i; j < n; j++)
                if (s[j] == c)
                    right = true;

            if (left && right)
                cnt++;
        }

        if (ans < cnt)
            ans = cnt;
    }

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

Measured memory_bytes: 256
using System;

namespace abc107_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = Convert.ToInt32(input[0]);
            int i = Convert.ToInt32(input[1]);
            Console.WriteLine(N - i + 1);
        }
    }
}


Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

				final int a0 = sc.nextInt();
				final int L = sc.nextInt();

				if (a0 == 0 && L == 0) {
					break;
				}

				Map<Integer, Integer> map = new HashMap<Integer, Integer>();
				map.put(a0, 0);

				int value = a0;
				for (int count = 1;; count++) {
					String value_str = value + "";
					for(int i = value_str.length(); i < L; i++){
						value_str = "0" + value_str;
					}
					char[] value_array = value_str.toCharArray();
					
					Arrays.sort(value_array);
					
					

					StringBuilder max = new StringBuilder(), min = new StringBuilder();
					for (int i = 0; i < value_array.length; i++) {
						max.append(value_array[value_array.length - i - 1]);
						min.append(value_array[i]);
					}

					final int min_value = Integer.parseInt(min.toString());
					final int max_value = Integer.parseInt(max.toString());
					final int next_value = max_value - min_value;

					//System.out.println(value + " " + next_value + " " + count + " " + min_value + " " + max_value);
					
					if (map.containsKey(next_value)) {
						System.out.println(map.get(next_value) + " " + next_value + " " + (count - map.get(next_value)));
						break;
					} else {
						map.put(next_value, count);
					}
					
					value = next_value;
				}
			
		}
	}
}

Measured memory_bytes: 21196
N = int(input())


def basem2(n, ans):
    if n == 0:
        if not ans:
            ans.append(0)
        return ans
    if n > 0:
        p, a, k = 1, 1, 0
        while n > a:
            p *= 4
            a += p
            k += 2
        # print(f"n={n} +{p} bit:{k} => {n-p}")
    else:
        assert n < 0
        p, a, k = -2, -2, 1
        while n < a:
            p *= 4
            a += p
            k += 2
        # print(f"n={n} {p} bit:{k} => {n-p}")
    while len(ans) < k + 1:
        ans.append(0)
    ans[k] = 1
    return basem2(n - p, ans)


print("".join([str(x) for x in reversed(basem2(N, []))]))


Measured memory_bytes: 3064
import java.util.*;

public class Main {

  static Scanner scan = new Scanner(System.in);

  public static void main(String[] args) {
    int n = scan.nextInt();
    int m = scan.nextInt();
    int[] H = new int[n + 1];

    for (int i = 1; i <= n; i++) {
      H[i] = scan.nextInt();
    }

    Map<Integer, List<Integer>> graph = new HashMap<>();

    for (int i = 0; i < m; i++) {
      int d1 = scan.nextInt();
      int d2 = scan.nextInt();
      add(graph, d1, d2);
      add(graph, d2, d1);
    }

    int numGood = 0;
    for (int node = 1; node <= n; node++) {
      boolean good = true;
      if (graph.containsKey(node)) {
        for (int neighbor: graph.get(node)) {
          if (H[neighbor] >= H[node]) {
            good = false;
            break;
          }
        }
      }

      if (good) {
        numGood++;
        // System.out.println(node);
      }
    }

    // System.out.println(graph.get(1));
    System.out.println(numGood);
  }

  private static void add(Map<Integer, List<Integer>> graph, int d1, int d2) {
    if (graph.containsKey(d1)) {
      graph.get(d1).add(d2);
    }
    else {
      List<Integer> newList = new ArrayList<>();
      newList.add(d2);
      graph.put(d1, newList);
      // System.out.println("herte" + d1 + " " + d2 + " " + graph.get(d1));
    }

  }
}

Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

set<ll> all_divisor(ll n){
	set<ll> res;
	for(ll i = 1; i*i<= n; i++){
		if(n%i==0){res.insert(i);res.insert(n/i);}
	}
	return res;
}

int main(){
    ll n;
    cin >> n;
    int ans = 0;
    auto s = all_divisor(n-1);
    ans += s.size() - 1;
    auto ss = all_divisor(n);
    for(auto p : ss) {
        if(p == 1) continue;
        ll nn = n;
        while(nn%p == 0) {
            nn /= p;
        }
        if((nn-1)%p==0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3760
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

vl H;
vl M;
ll K;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    H = vl(2);
    M = vl(2);
    for(int i = 0; i < 2; ++i){
        cin >> H[i];
        cin >> M[i];
    }
    cin >> K;
    solve();
}

// 0 < H_1, H_2 < 23
// 0 < M_1, M_2 < 59
// H_1 時 M_1 分は H_2 時 M_2 分より前の時刻である
// K > 1
// 高橋君が起きている時間の長さは K 分以上である
// 入力は全て整数である

// vl H, vl M, ll K
// 答えを整数として出力せよ。
void solve(){
    ll t=H[1]*60+M[1]-(H[0]*60+M[0]);
    cout<<t-K<<endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

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

    if (!isKaibun(s)) {
      System.out.println("No");
      return;
    }

    int middle = (s.length() + 1) / 2;
    if (!isKaibun(s.substring(0, middle - 1)) || !isKaibun(s.substring(middle))) {
      System.out.println("No");
      return;
    }

    System.out.println("Yes");
    return;
  }

  static boolean isKaibun(String s) {
    int h = 0;
    int e = s.length() - 1;

    while (h < e) {
      if (!(s.substring(h, h + 1).equals(s.substring(e, e + 1)))) {
        return false;
      }
      h++;
      e--;
    }

    return true;
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define vi(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
}

bool isAllsame(string s){
    for(ll i=1;s[i];i++){
        if(s[i]!=s[i-1]){
            return false;
        }
    }
    return true;
}


int main() {

    IO; 

    ll n,t;
    cin>>n>>t;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    
    ll dp1[n];
    dp1[0]=a[0];
    for(ll i=1;i<n;i++){
        dp1[i]=max(dp1[i-1],a[i]);
    }
    ll dp2[n];
    dp2[n-1]=a[n-1];
    for(ll i=n-2;i>=0;i--){
        dp2[i]=max(dp2[i+1],a[i]);
    }
    if(t%2){
        t=t-1;
        t/=2;
    }
    else{
        t/=2;
    }
    // Now , we have calculated all the maximum for left and right part respectively
    ll score_opp=0;
    for(ll i=0;i<n-1;i++){
        score_opp=max(score_opp,(-a[i]+dp2[i+1])*t);
    }


    ll cnt=0;
    for(ll i=0;i<n-1;i++){
        if((-(a[i]-dp2[i+1])*t) == score_opp){
            cnt++;
        }
    }

    cout<<cnt<<endl;

}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

///Rectangular Stamps
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n], w = new int[n];
		for(int i=0;i<n;i++){
			h[i] = sc.nextInt(); w[i] = sc.nextInt();
		}
		int[][] a = new int[4][4];
		for(int i=0;i<4;i++){
			char[] c = sc.next().toCharArray();
			for(int j=0;j<4;j++)a[i][j] = c[j]=='R'?0:c[j]=='G'?1:2;
		}
		int[] d = new int[1<<16];
		int INF = 1<<29;
		Arrays.fill(d, INF);
		d[65535] = 0;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(65535);
		while(!q.isEmpty()){
			int S = q.poll();
			if(S==0){
				System.out.println(d[S]); break;
			}
			for(int k=0;k<n;k++){
				for(int i=-3;i<=3;i++)for(int j=-3;j<=3;j++){
					int cov = 0, app = 0;
					for(int y=0;y<h[k];y++)for(int x=0;x<w[k];x++){
						if(0<=i+y&&i+y<4&&0<=j+x&&j+x<4){
							int p = (i+y)*4+j+x;
							if(((S>>p)&1)==0)continue;
							app|=1<<a[i+y][j+x];
							cov+=1<<p;
						}
					}
					if(app==1||app==2||app==4){
						int ns = S&~cov;
						if(d[ns]==INF){
							d[ns] = d[S]+1; q.add(ns);
						}
					}
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
N = int(input())
kabu = [int(i) for i in input().split()]
money = 1000
hoji = 0

for i in range(N-1):
    if kabu[i] < kabu[i+1] and not hoji:
        hoji = money//kabu[i]
        money = money - hoji*kabu[i]
    if kabu[i] > kabu[i+1] and hoji:
        money = money + hoji*kabu[i]
        hoji = 0
if hoji:
    money = money + hoji*kabu[i+1]
print(money)

Measured memory_bytes: 9164
// 2017-04-23
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> p;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			p.push_back(a[i] * a[j]);
		}
	}
	int m = -1;
	for (auto i = begin(p); i != end(p); i++) {
		int v = *i;
		int d = v % 10;
		v /= 10;
		while (v > 0) {
			if (v % 10 != d - 1) {
				break;
			}
			d = v % 10;
			v /= 10;
		}
		if (v == 0) {
			m = max(m, *i);
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 4964
s = list(input())
m = {}
for c in s:
    if c in m:
        m[c] += 1
    else:
        m[c] = 1

ans = True
if len(m) != 2:
    ans = False
else:
    for v in m.values():
        if v != 2:
            ans = False

if ans:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 38256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    unordered_map<int, int> mp1, mp2;
    int v;
    for (int i = 0; i < n; i++) {
        cin >> v;
        if (i % 2 == 0) {
            if (mp1.find(v) == mp1.end()) {
                mp1[v] = 1;
            } else {
                mp1[v]++;
            }
        } else {
            if (mp2.find(v) == mp2.end()) {
                mp2[v] = 1;
            } else {
                mp2[v]++;
            }
        }
    }

    vector<pair<int, int>> p1 = {{0, 0}, {0, 0}};
    for (auto& x : mp1) {
        if (x.second >= p1[0].second) {
            p1[1] = p1[0];
            p1[0] = x;
        }
        if (x.second < p1[0].second && x.second > p1[1].second) { p1[1] = x; }
    }

    vector<pair<int, int>> p2 = {{0, 0}, {0, 0}};
    for (auto& x : mp2) {
        if (x.second >= p2[0].second) {
            p2[1] = p2[0];
            p2[0] = x;
        }
        if (x.second < p2[0].second && x.second > p2[1].second) { p2[1] = x; }
    }

    int ans;
    if (p1[0].first != p2[0].first) {
        ans = n - p1[0].second - p2[0].second;
    } else {
        ans = min(n - p1[1].second - p2[0].second,
                  n - p1[0].second - p2[1].second);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4200
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
long long inv(long long now) {
	long long ans = 1;
	long long te = MAX_MOD - 2LL;
	while (te != 0) {
		if (te % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		te /= 2;
		now *= now;
		now %= MAX_MOD;
	}
	return ans;
}
int main(){
	long long n;
	cin >> n;
	vector<long long> solve;
	solve.push_back(1);
	n--;
	for (long long i = 1;n != 0; ++i) {
		for (long long q = i; q >= 0; --q) {
			if (q < 50 && (1LL << (long long)q) <= n) {
				n -= (1LL << (long long)q);
				solve.insert(solve.begin() + q, i + 1);
				break;
			}
		}
	}
	cout << solve.size() + 100 << endl;
	REP(i, solve.size()) {
		cout << solve[i] << " ";
	}
	for (int i = 1; i <= 100; ++i) {
		cout << i << " ";
	}
	cout << endl;
}

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

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things. 
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

#define MAXN 100001
ll tot[MAXN];

int main(){
	
	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;

    ll arr[n];
    for(int i=0;i<n;i++){
    	cin>>arr[i];
    }

    ll curr=0;

    for(int i=0;i<n;i++){
    	curr^=arr[i];
    }

    for(int i=0;i<n;i++){
    	cout<<(curr^arr[i])<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 5220
k,n = map(int, input().split())
a = list(map(int, input().split()))

max = 0

for i in range(n):
    if i == n - 1:
        t = k - a[i] + a[0]
    else:
        t = a[i+1] - a[i]

    if t > max:
        max = t

print(k-max)

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

int point(int x,int y,int w,int h){
  int s;
  s= y*w+x;
  return s;
}

int point_x(int x,int w){
  int s;
  s=x%w;
  return s;
}

int point_y(int x,int w){
  int s;
  s=x/w;
  return s;
}

int main(){
  int w,h;
  cin>>w>>h;
  while(w!=0){
    int a[21][21]={};
    int sx,sy;
    for(int j=0;j<h;j++){
      for(int i=0;i<w;i++){
	char s;
	cin>>s;
	if(s=='.'){
	  a[i][j]=1;
	}else if(s=='#'){
	  a[i][j]=-1;
	}else{
	  a[i][j]=2;
	  sx=i;
	  sy=j;
	}
      }
    }

    int d[21][21];
    for(int i=0;i<21;i++){
      for(int j=0;j<21;j++){
	d[i][j]=-1;
      }
    }
    queue<int>q;
    d[sx][sy]=0;
    int str;
    str=point(sx,sy,w,h);
    q.push(str);
    while(! q.empty()){
      int cur =q.front();
      q.pop();
      int x,y;
      x=point_x(cur,w);
      y=point_y(cur,w);
      if(x>=1){
	if(a[x-1][y]==1&&d[x-1][y]==-1){
	  d[x-1][y]=0;
	  q.push(point(x-1,y,w,h));
	}
      }
      if(x<=w-2){
	if(a[x+1][y]==1&&d[x+1][y]==-1){
	  d[x+1][y]=0;
	  q.push(point(x+1,y,w,h));
	}
      }
      if(y>=1){
	if(a[x][y-1]==1&&d[x][y-1]==-1){
	  d[x][y-1]=0;
	  q.push(point(x,y-1,w,h));
	}
      }
      if(y<=h-2){
	if(a[x][y+1]==1&&d[x][y+1]==-1){
	  d[x][y+1]=0;
	  q.push(point(x,y+1,w,h));
	}
      }
    }

    int t=0;
    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	if(d[i][j]==0){
	  t+=1;
	}
      }
    }
    cout <<t<< endl;
    cin>>w>>h;
  }
}
    
    

Measured memory_bytes: 3080
import java.io.*;
import java.util.*;

public class Main{
	public static void solve(String str){
    	HashSet<String> ptn= new HashSet<String>();
    	ptn.add(str);
    	for(int i=1;i<str.length();i++){
    		String str_frt= str.substring(0,i);
    		String str_bck= str.substring(i);
//            StringBuilder sb_frt_inv= new StringBuilder();
//            StringBuilder sb_bck_inv= new StringBuilder();
//            for(int j=str_frt.length()-1;j>=0;j--){
//                sb_frt_inv= sb_frt_inv.append(str_frt.charAt(j));
//            }
//            for(int j=str_bck.length()-1;j>=0;j--){
//                sb_bck_inv= sb_bck_inv.append(str_bck.charAt(j));
//            }
//            String str_frt_inv= sb_frt_inv.toString();
//            String str_bck_inv= sb_bck_inv.toString();
    		String str_frt_inv= new StringBuilder(str_frt).reverse().toString();
    		String str_bck_inv= new StringBuilder(str_bck).reverse().toString();
    		
    		ptn.add(str_frt+str_bck_inv);
    		ptn.add(str_frt_inv+str_bck);
    		ptn.add(str_frt_inv+str_bck_inv);
    		ptn.add(str_bck+str_frt);
    		ptn.add(str_bck+str_frt_inv);
    		ptn.add(str_bck_inv+str_frt);
    		ptn.add(str_bck_inv+str_frt_inv);
    	}
    	
    	System.out.println(ptn.size());
	}
    public static void main(String args[]) throws Exception{
    	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    	int rep= Integer.valueOf(br.readLine());
    	for(int i=0;i<rep;i++){
        	solve(br.readLine());
    	}
    }
}

Measured memory_bytes: 54036
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
 
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main() {
  int n;
  cin >> n;
 
  int64_t ans=0;
  rep(i, n+1){
    if(!(i%3==0 || i%5==0)) ans+=i;
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int mod=998244353;
int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    int dp[n+1]={};
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=abs(arr[i]-arr[i-1])+dp[i-1];
        for(int j=2;j<=k;j++)
        {
            if((i-j)==0)
                break;
            dp[i]=min(abs(arr[i]-arr[i-j])+dp[i-j],dp[i]);
        }
    }
    cout<<dp[n]<<endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/04  Problem: ABC 099 D / Link: http://abc099.contest.atcoder.jp/tasks/abc099_d  ----- */


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

	LL N, C; cin >> N >> C;
	vector<vector<LL>> cost(C, vector<LL>(C));
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j < C; ++j) {
			cin >> cost[i][j];
		}
	}

	vector<vector<LL>> a(N, vector<LL>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	VVL b(3);
	FOR(i, 0, N) {
		FOR(j, 0, N) {
			b[(i + j) % 3].push_back(a[i][j]);
		}
	}

	// pre
	VVL bcost(3, VL(C));
	{
		FOR(bb, 0, 3) {
			FOR(c, 0, C) {
				for (auto it : b[bb]) {
					bcost[bb][c] += cost[it][c];
				}
			}
		}
	}
	// 各bに対して重複無いCを割り振って，そのコスト
	LL ans = LINF;
	FOR(i, 0, C) {
		FOR(j, 0, C) {
			FOR(k, 0, C) {
				if (i == k || i == j || j == k)continue;
				ans = min(ans, bcost[0][i] + bcost[1][j] + bcost[2][k]);
			}
		}
	}

	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 4400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
vi used;
int out;
vvp area;
bool h;
void dfs(int a,int prev,int b,int c){
	if(b==0){
		h=true;
		int t=0;
		rep(i,area[a].size())if(area[a][i].first!=prev&&used[area[a][i].first]){
			t=area[a][i].second;
		}
		out=max(out,c+t);
		return ;
	}
	rep(i,area[a].size())if(used[area[a][i].first]==0){
		used[area[a][i].first]=true;
		c+=area[a][i].second;
		dfs(area[a][i].first,a,b-1,c);
		c-=area[a][i].second;
		used[area[a][i].first]=false;
	}
}
int main(){
	int n,m,s;
	while(cin>>n>>m>>s,n+m+s){
		vvi in(n,vi(3));
		rep(i,n)rep(j,3)cin>>in[i][j];
		area=vvp(n);
		rep(i,n)rep(j,n)if(i!=j){
			int x=min(in[i][0],in[j][0])+s-max(in[i][0],in[j][0]);
			int y=min(in[i][1],in[j][1])+s-max(in[i][1],in[j][1]);
			int z=min(in[i][2],in[j][2])+s-max(in[i][2],in[j][2]);
			if(x>0&&y>0&&z>0)area[i].pb(pii(j,2*(x*y+y*z+z*x)));
		}
		h=out=0;
		rep(i,n){
			used=vi(n);
			used[i]=true;
			dfs(i,-1,m-1,0);
		}
		if(!h)cout<<-1<<endl;
		else cout<<m*6*s*s-out<<endl;
	}
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int s;
  cin>>s;
  mint a[2009];
  a[0]=0;
  a[1]=0;
  a[2]=0;
  a[3]=1;
  Rep(i,4,2001){
    a[i]=a[i-1]+a[i-3];
  }
  
  cout<<a[s].x<<endl;
}
  



Measured memory_bytes: 3644
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		input := strings.Split(scanner.Text(), ",")
		cards := make([]int, 5)
		for i :=range input {
			cards[i], _ = strconv.Atoi(input[i])
		}
		sort.Sort(sort.IntSlice(cards))
		if cards[0] == cards[1] && cards[2] == cards[3] && cards[2] == cards[1] {
			fmt.Println("four card")
		} else if cards[1] == cards[2] && cards[3] == cards[4] && cards[3] == cards[2]{
			fmt.Println("four card")
		} else if cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4] {
			fmt.Println("full house")
		} else if cards[0] == cards[1] && cards[2] == cards[3] && cards[3] == cards[4] {
			fmt.Println("full house")
		} else if cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13 {
			fmt.Println("straight")
		} else if cards[0]+1 == cards[1] && cards[1]+1 == cards[2] && cards[2]+1 == cards[3] && cards[3]+1 == cards[4] {
			fmt.Println("straight")
		} else if (cards[0] == cards[1] && cards[1] == cards[2]) || (cards[1] == cards[2] && cards[2] == cards[3]) || (cards[2] == cards[3] && cards[3] == cards[4]) {
			fmt.Println("three card")
		} else if ((cards[0] == cards[1]) && ((cards[2] == cards[3]) || (cards[3] == cards[4]))) || ((cards[1] == cards[2]) && (cards[3] == cards[4])) {
			fmt.Println("two pair")
		} else if cards[0] == cards[1] || cards[1] == cards[2] || cards[2] == cards[3] || cards[3] == cards[4] {
			fmt.Println("one pair")
		} else {
			fmt.Println("null")
		}
	}
}


Measured memory_bytes: 1084
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i prev acc =
        if i = n then acc else
            if s.[i] = prev then loop (i + 1) prev acc else
                loop (i + 1) s.[i] (acc + 1)
    in
    loop 1 s.[0] 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int a,b,c;
  string s,t;
  int x,y;
  int an = 0;
  string ans;
  cin >> s >> t;
  cout << t+s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

const llong mod = (llong)1e9 + 7;
llong pow_mod(llong n, llong m) {
    llong res = 1;
    while (m) {
        if (m & 1) {
            res *= n;
            res %= mod;
        }
        n *= n;
        n %= mod;
        m >>= 1;
    }

    return res;
}

llong n;
llong a[10005];
llong tmp[10005];
llong cnt[1000005];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        tmp[i] = a[i];
    }

    for (int i = 0; i < n; i++) {
        for (llong j = 2; j * j <= a[i] && tmp[i] > 1; j++) {
            llong c = 0;
            while (tmp[i] % j == 0 && tmp[i] > 1) {
                tmp[i] /= j;
                c++;
            }
            cnt[j] = max(cnt[j], c);
        }
        cnt[tmp[i]] = max(cnt[tmp[i]], 1ll);
    }

    llong lcm = 1;
    for (int i = 1; i <= 1000000; i++) {
        lcm *= pow_mod(i, cnt[i]);
        lcm %= mod;
    }

    llong ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (lcm * pow_mod(a[i], mod - 2)) % mod;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
// #include "lib.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define MAXN 1000006
#define MAXK 26
#define MAXX 15000006
#define ll long long
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define forit(it, A) for(set<ll>::iterator it = A.begin(); it != A.end(); it++)
#define bg(ms) *ms.begin()
#define ed(ms) *prev(ms.end(), 1)
#define addedge(a, b, c) v[a].pb(pi(b, c)); v[b].pb(pi(a, c))
#define ph push
#define all(x) x.begin(), x.end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll n, m, l;
int main()
{
	cin >> n >> m;
	l = m/n+1;
	for(ll i = l; i >= 1; i--)
	{
		if(m%i == 0 && m/i >= n)
		{
			cout << i << "\n";
			return 0;
		}
	}
}


Measured memory_bytes: 256
N = int(raw_input())
a = map(int, raw_input().split())
b = []
cnt = 0
for i in range(0, N):
    if a[i] / 400 >= 8:
        cnt += 1
    else:
        b.append(a[i]/400)
b = set(b)

flag = 1
for x in a:
    if x >= 3200:
        flag = 0
    else:
        flag = 1
        break
if flag:
    print len(b)
else:
    print 1
print len(b) + cnt


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 100000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (60) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;



void solve()
{
	int n, k;
	cin >> n >> k;
	if(k == 1)
		cout << 0 << '\n';
	else
		cout << (n-k) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(6);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
while(True):
   
    n,x=map(int,input().split())
    sum=0
    if(n==0 and x==0):break
    for i in range(1,n-1):
        for j in range(i+1,n):
            if(x-i-j>j and n>=x-i-j):
                sum+=1
                #print(i,j,x-i-j)
    print(sum)
    


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	if (K < 10) {
		cout << K << endl;
		return 0;
	}

	vector<Int> curr;
	for (int i = 1; i < 10; ++i) { curr.emplace_back(i); }

	int cnt = 9;
	while (cnt < K) {
		vector<Int> nxt;
		for (auto v : curr) {
			Int x = v % 10;
			for (int i = -1; i <= 1; ++i) {
				Int y = x + i;
				if (y >= 0 && y < 10) {
					nxt.emplace_back(v * 10 + y);
					++cnt;
					if (cnt >= K) {
						cout << nxt.back() << endl;
						return 0;
					}
				}
			}
		}
		curr = nxt;
	}

	return 0;
}


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

int main(){
	ll N,Z,W;
	cin >> N >> Z >> W;
	vector<ll> a(N);
	for(auto &x:a){
		cin >> x;
	}
	if(N==1){
		cout << abs(W-a[0]) << endl;
		return 0;
	}
	ll ans = max(abs(a[N-2]-a[N-1]),abs(W-a[N-1]));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string a,b,c;
    cin>>a>>b>>c;
    int A=0,B=0,C=0;
    char res='a';
    while(1){
        if(res=='a'){
            if(A==a.size()){cout<<'A'<<endl;return 0;}
            res=a[A];
            A++;
        }
        else if(res=='b'){
            if(B==b.size()){cout<<'B'<<endl;return 0;}
            res=b[B];
            B++;
        }
        else if(res=='c'){
            if(C==c.size()){cout<<'C'<<endl;return 0;}
            res=c[C];
            C++;
        }
    }
}


Measured memory_bytes: 256
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Monday July 27, 2020
 */

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  tuple<int, int, int>
#define pll   pair<ll, ll>
#define plll  tuple<ll, ll, ll>

#define X  first
#define Y  second

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(const pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

// add templates here

template <typename T>
string to_string(const vector<T> &v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}

const int MOD = int(1e9+7);
const ll oo  = (ll)(1e9+20);
const ll lloo  = (ll)(1e18)+40;

class Task {
public:
    ll N;

    string solve(istream &i, ostream &o) {
        i >> N;
        for(ll i = 9; i > 0; i--) {
            if(N%i==0 && N/i <= 9) return "Yes";
        }
        return "No"; 
    }
    
    void run(istream &i, ostream &o) {
        int t;
        i >> t;
        while(t--) {
            o << solve(i, o) << endl;
        }
    }
};
    
auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    cout << solver.solve(in, out) << endl;
    //solver.run(in, out);
    return 0;
}



Measured memory_bytes: 3640