akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int T = Integer.parseInt(in.readLine());
		for (int t = 0; t < T; ++t) {
			Main ins = new Main(in);
			ins.calc();
			ins.showResult();
		}
	}

	int N;
	Tuple[] tuples;
	long result = 0L;
	Set<Tuple>[] lefts, rights;

	static class Tuple {
		int K;
		long L, R;

		Tuple(int K, long L, long R) {
			this.K = K;
			this.L = L;
			this.R = R;
		}

		int getType() {
			if (L > R) {
				return 1;
			} else if (L < R) {
				return -1;
			} else {
				return 0;
			}
		}

		long getBase() {
			return Math.min(L, R);
		}

		long getProfit() {
			return Math.abs(L - R);
		}
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		tuples = new Tuple[N];
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			int K = Integer.parseInt(tokens[0]) - 1;
			long L = Long.parseLong(tokens[1]);
			long R = Long.parseLong(tokens[2]);
			tuples[i] = new Tuple(K, L, R);
		}

		// baseを足す
		for (int i = 0; i < N; ++i) {
			result += tuples[i].getBase();
		}

		lefts = new Set[N];
		rights = new Set[N];
		for (int i = 0; i < N; ++i) {
			lefts[i] = new HashSet<Tuple>();
			rights[i] = new HashSet<Tuple>();
		}
		for (int i = 0; i < N; ++i) {
			if (tuples[i].getType() > 0) {
				// Lの方が大きい-> leftsに足す
				Tuple t = tuples[i];
				lefts[t.K].add(t);
			} else if (tuples[i].getType() < 0) {
				// Rの方が大きい
				Tuple t = tuples[i];
				if (t.K + 1 < N) {
					rights[t.K + 1].add(t);
				}
			}
		}
	}

	void calc() {
		Queue<Tuple> leftQue = new PriorityQueue<>(new Comparator<Tuple>() {
			@Override
			public int compare(Tuple o1, Tuple o2) {
				return Long.compare(o1.getProfit(), o2.getProfit());
			}
		});
		for (int i = 0; i < N; ++i) {
			leftQue.addAll(lefts[i]);
			while (leftQue.size() > i + 1) {
				leftQue.poll();
			}
		}
		Queue<Tuple> rightQue = new PriorityQueue<>(new Comparator<Tuple>() {
			@Override
			public int compare(Tuple o1, Tuple o2) {
				return Long.compare(o1.getProfit(), o2.getProfit());
			}
		});
		for (int i = N - 1; i >= 0; --i) {
			rightQue.addAll(rights[i]);
			while (rightQue.size() > N - i) {
				rightQue.poll();
			}
		}
		while (!leftQue.isEmpty()) {
			Tuple t = leftQue.poll();
			result += t.getProfit();
		}
		while (!rightQue.isEmpty()) {
			Tuple t = rightQue.poll();
			result += t.getProfit();
		}
	}

	void showResult() {
		System.out.println(result);
	}
}

Measured memory_bytes: 106756
h, w, k = (int(x) for x in input().split())
S = [input() for _ in range(h)]

ans = 10**18
for bit in range(1<<(h - 1)):
    segment = [0] * h
    seg_label = 0
    for i in range(h - 1):
        if bit & (1<<i):
            seg_label += 1
        segment[i + 1] = seg_label
    n = max(segment) + 1

    count = n - 1
    k_count = [0] * n
    for j in range(w):
        tmp_count = [0] * n
        for i in range(h):
            k_count[segment[i]] += int(S[i][j])
            tmp_count[segment[i]] += int(S[i][j])
            if k_count[segment[i]] > k:
                count += 1
                for seg in range(n):
                    k_count[seg] = tmp_count[seg]

    ans = min(ans, count)

print(ans)


Measured memory_bytes: 76076
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a=0;
  cin>>N;
  int T[N];
  for(int i=0;i<N;i++){
    cin>>T[i];
    a+=T[i];
  }
  int M,P,X;
  cin>>M;
  int A[M];
  for(int i=0;i<M;i++){
    cin>>P>>X;
    A[i]=a-T[P-1]+X;
  }
  for(int i=0;i<M;i++) cout<<A[i]<<endl;
}

Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, A);
    IN(ll, B);
    IN(ll, C);
    AIN(string, s, N);
    map<char, ll> v{{'A', A}, {'B', B}, {'C', C}};
    vector<char> ans(N);
    bool ok = true;
    REP(i, N)
    {
        ll x = v[s[i][0]];
        ll y = v[s[i][1]];
        ll j = y > x or (x == 1 and y == 1 and (i == N - 1 or s[i][0] == s[i + 1][0] or s[i][0] == s[i + 1][1]));
        --v[s[i][j]];
        ++v[s[i][1 - j]];
        ans[i] = s[i][1 - j];
        ok &= v[s[i][j]] >= 0;
    }
    YES(ok);
    if (ok)
    {
        REP(i, N)
        {
            OUT(ans[i]);
        }
    }
}

Measured memory_bytes: 6432
h,w=map(int,input().split())
n=int(input())
lis=list(map(int,input().split()))
ans=[]
cnt=0
s=""
hh=0
for i in range(n):
  for j in range(lis[i]):
    if hh==0:
      s=s+str(i+1)+" "
    else:
      s=str(i+1)+" "+s
    cnt+=1
    if cnt==w:
      ans.append(s)
      s=""
      cnt=0
      hh=(hh+1)%2
for i in range(h):
  print(ans[i])


Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
using namespace std;

int read_p,read_ca;
inline int read(){
	read_p=0;read_ca=getchar();
	while(read_ca<'0'||read_ca>'9') read_ca=getchar();
	while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
	return read_p;
}
int n,a,b;
int main(){
	n=read();a=read();b=read();
	if (n==1){
		printf("%d\n",a==b);
		return 0;
	}
	if (a>b) puts("0");else
	printf("%lld\n",1LL*(b-a)*(n-2)+1);
}

Measured memory_bytes: 128
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[52][2510];
void Solve() {
	string s;
	cin >> s;
	string s2(s.size(), ' ');
	int v = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == 'B') {
			v = max(v-1,0);
		}
		else {
			s2[v++] = s[i];
		}
	}

	for (size_t i = 0; i < v; i++)
	{
		cout << s2[i];
	}
	cout << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 256
A,B=map(int,input().split())
S=list(input())

l=set(['1','2','3','4','5','6','7','8','9','0'])

if S[A]!='-':
    print('No')
    exit()

del S[A]
for s in S:
    if s not in l:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#!/usr/bin/env python3

def main():
    n = int(input())
    li = [input() for i in range(n)]
    if len(set(li)) == n:
        res = True
        for i in range(n - 1):
            if li[i][-1] != li[i + 1][0]:
                res = False
    else:
        res = False
    print("Yes" if res else "No")

main()


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

int main()
{
	int t;
	t = 1;
	while (t--)
	{
		int n;
		cin >> n;
		int a[n + 1];

		for (int i = 1; i <= n; i++)
			cin >> a[i];

		int dp[n + 1];

		dp[1] = 0;
		dp[2] = abs(a[2] - a[1]);

		for (int i = 3; i <= n; i++)
		{
			dp[i] = min( dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]) );
		}
		int sum = 0;


		cout << dp[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  int cost = h[0];
  int k = h[0];
  for (int i = 1; i < N; i++) {
    if (k < h[i]) {
      cost += h[i] - k;
      k = h[i];
    } else if (k > h[i]) {
      k = h[i];
    }
  }
  cout << cost << "\n";
  return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
res = Array.new(n, -1)
m.times do
  s, c = gets.chomp.split.map(&:to_i)
  if res[s - 1] != -1 && res[s - 1] != c
    puts "-1"
    exit
  end
  if c == 0 && s - 1 < n - 1
    puts "-1"
    exit
  end
  res[s - 1] = c
end

n.times do |i|
  next if res[i] != -1
  if n != 1 && i == 0
    res[i] = 1
  else
    res[i] = 0
  end
end
puts res.join("")

Measured memory_bytes: 14404
#include <string>
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
	int y, m, d;
	string s;
	bool flag = false;
	scanf("%d/%d/%d", &y, &m, &d);

	if (y < 2019) flag = true;
	else if (y == 2019 && m < 4) flag = true;
	else if (y == 2019 && m == 4 && d < 31) flag = true;

	if (flag) cout << "Heisei\n";
	else cout << "TBD\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;

  vector<int>num(N,0);

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

  int ans = 0;
  while(1){
    bool exist_odd = false;
    for(int i=0;i<N;i++){
      if(num[i] % 2 != 0)
        exist_odd =true;
    }

      if(exist_odd) break;

      else{
        for(int i=0;i<N;i++){
          num[i] = num[i] / 2;
        }
        ans++;
      }
  }

  cout << ans << endl;

  return 0;
}


    
    
      

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

void trace(vector<int> a, int n, int cnt) {
	for (int i = 0;i < n;i++) {
		cout << a[i];
		if (i < n - 1)cout << " ";
		if (i == n - 1) cout << endl;
	}
	cout << cnt << endl;
}
void bubbleSort(vector<int> a, int n) {
	bool flag = true;
	int cnt = 0;
	while (flag) {
		flag = 0;
		for (int j = n - 1;j > 0;j--) {
			if (a[j] < a[j - 1]) {
				int tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
				flag = 1;
				cnt++;
			}
		}
	}
	trace(a, n, cnt);
}
int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0;i < n;i++)cin >> a[i];
	bubbleSort(a, n);
	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c || b+c==a || a+c==b) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int n;
    cin >> n;
    if (n % 2 == 1) {
        n *= 2;
    }
    cout << n << endl;
    return 0;
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int x;
	for(int i = 1;scanf("%d", &x); i++)
	{
		if(x == 0)
		{
			break;
		} 
		printf("Case %d: %d\n", i, x);
			
	}
	return 0;
 } 


Measured memory_bytes: 1976
#include <iostream>
#include <queue>
#include <algorithm>
#include <climits>
#include <stack>
#include <vector>
#include <random>
#include <string.h>
#include <stdio.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef pair<int, int> ii;
typedef pair<long double, int> id;
typedef pair<long long, long long> llp;
const int N = 3*1e3+1;
int n, m;
long long dp[N][N];
int main() {
    //freopen("ee.inp", "r", stdin);
    //freopen("ee.OUT", "w", stdout);
    fastIO;
    string s, t;
    cin>>s>>t;
    if (s.size()<t.size()) swap(s, t);
    n = s.size(), m = t.size();
    for(int i=1;i<=n;i++) {
        //cout << i << " | ";
        for(int j=1;j<=m;j++) {
            dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            if (s[i-1]==t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
            //cout << dp[i][j] << " ";
        }
        //cout << "\n";
    }
    stack<int> st;
    while(n>0&&m>0) {
        if (dp[n-1][m]==dp[n][m]) n--;
        else if (dp[n][m-1]==dp[n][m]) m--;
        else if (dp[n-1][m-1]+1==dp[n][m]) {
            n--, m--;
            st.push(n);
        }
    }
    while(!st.empty()) {
        cout << s[st.top()];
        st.pop();
    }
}


Measured memory_bytes: 73976
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if ( (x-r) < 0 || (y-r) < 0 || (x+r) > W || (y+r) > H ) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}


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

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	if (x < y && x < z && y < z) {
		cout << x << " " << y << " " << z << endl;
	}
	if (x < z && x < y && z < y) {
		cout << x << " " << z << " " << y << endl;
	}
	if (y < x && y < z && x < z) {
		cout << y << " " << x << " " << z << endl;
	}
	if (y < z && y < x && z < x) {
		cout << y << " " << z << " " << x << endl;
	}
	if (z < x && z < y && x < y) {
		cout << z << " " << x << " " << y << endl;
	}
	if (z < y && z < x && y < x) {
		cout << z << " " << y << " " << x << endl;
	}
	if (x == y && x < z && y < z) {
		cout << x << " " << y << " " << z << endl;
	}
	if (x == z && x < y && z < y) {
		cout << x << " " << z << " " << y << endl;
	}
	if (y == z && y < x && z < x) {
		cout << y << " " << z << " " << x << endl;
	}
	if (x == y && y == z) {
		cout << x << " " << y << " " << z << endl;
	}

	return 0;
}


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

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

	int a, b;
	cin >> a >> b;
	int c = b - a;
	if (b < 0 && a < 0)c = -c;
	if (b >= 0 && a <= 0)cout << "Zero";
	else if (c > 0)cout << "Positive";
	else if (c == 0){
		if (a > 0)cout << "Positive";
		if (a == 0)cout << "Zero";
		if (a < 0)cout << "Negative";
	}
	else{
		if (c % 2 == 0)cout << "Negative";
		else cout << "Positive";
	}
	cout << endl;



	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int d;
  cin>>d;
  for(;d--;)
    {
      int n;
      cin>>n;
      char output[n][n];
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  output[i][j]=' ';

      int dx[]={-1,0,1,0};
      int dy[]={0,1,0,-1};
      int move=0;
      int cnt=0;
      int x=n-1,y=0;
      for(;;)
	{
	  //	  cout<<x<<" "<<y<<endl;
	  // cout<<"next:"<<x+dx[move]<<" "<<y+dy[move]<<endl;
	  output[x][y]='#';
	  cnt++;
	  bool flag=false;
	  while(x+dx[move]<0 || 
		x+dx[move]>=n ||
		y+dy[move]<0 || 
		y+dy[move]>=n ||
		(
		 x+dx[move]*2>=0 &&
		 x+dx[move]*2<n &&
		 y+dy[move]*2>=0 &&
		 y+dy[move]*2<n &&
		 output[x+dx[move]*2][y+dy[move]*2]=='#'
		 )
		)
	    {
	      /*
		cout<<(x+dx[move]<0)<<endl; 
		cout<<(x+dx[move]>=n)<<endl; 
		cout<<(y+dy[move]<0)<<endl; 
		cout<<(y+dy[move]>=n)<<endl; 
	      */
	      move++;
	      if(move>3)
		move=0;
	      
	      if(cnt<2)
		{
		  flag=true;
		  break;
		}
	      cnt=0;
	    }
	  if(flag)
	    break;
	  x+=dx[move];
	  y+=dy[move];
	  
	}

      for(int i=0;i<n;i++,cout<<endl)
	for(int j=0;j<n;j++)
	  cout<<output[i][j];
      if(d>0)
	cout<<endl;
    }

}

Measured memory_bytes: 1160
s = str(input())
t = str(input())
d = {}
for k, v in zip(s, t):
    if d.get(k) != None and d.get(k) != v:
        print("No")
        exit()
    d[k] = v

if len(set(d.values())) == len(d):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
const int mod = 1000000007;
signed main(){
    int n,k;cin >> n >> k;
    int ans = 0;
    for(int i = k;i <= n+1;i++){
        (ans += ((2*n-i+1)*i)/2 - (i*(i-1))/2 +1)%=mod;
    }
    cout << ans%mod << endl;

    return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int A, B;
	cin >> A >> B;
	if(B % A == 0){
		cout << A + B << endl;
	}
	else{
		cout << B - A << endl;
	}
	return 0;
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;
int N, M, C;
int ix(int u, int n){
  return n*N + u;
}

using Type = pair<PII,int>;
struct gt{
  bool operator()(const Type& l, const Type& r)const{
	if(l.FF.FF != r.FF.FF)
	  return l.FF.FF > r.FF.FF;
	return l.SS > r.SS;
  };
};

int Dijkstra(const Graph& G){
  priority_queue<Type, vector<Type>, gt> pq;
  VVI d(N+1, VI(N,INF));
  d[0][0] = 0;
  // ((n, u), cost)
  pq.push(MP(MP(0,0),0));

  while(!pq.empty()){
	Type pii = pq.top(); pq.pop();
	int n = pii.FF.FF;
	int u = pii.FF.SS;
	int c = pii.SS;
	if(d[n][u] < c) continue;
	for(unsigned int i=0;i<G[u].size();++i){
	  const Edge& e = G[u][i];
	  int nc = c + e.cost;
	  if(d[n][e.to] > nc){
		d[n][e.to] = nc;
		pq.push(MP(MP(n,e.to), nc));
	  }
	  if(n+1 <= N && d[n+1][e.to] > c){
		d[n+1][e.to] = c;
		pq.push(MP(MP(n+1,e.to), c));
	  }
	}
  }

  for(int n=0;n<=N;++n)
	if(d[n][N-1] <= C)
	  return n;
  return 114514;
}

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

  while(cin>>N>>M>>C,N){
	Graph G(N);
	REP(i,M){
	  int u, v, c;
	  cin >> u >> v >> c;
	  --u;
	  --v;
	  G[u].EB(v,c);
	}
	cout << Dijkstra(G) << endl;
  }

  return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
int main(void)
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(A == B && B == C){
        printf("No");
    }else if(A != B && A != C && B != C){
        printf("No");
    }else{
        printf("Yes");
    }
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define fint register int
#define p 457834
#define h 5001
using namespace std;
int a[p];
int main()
{
	int n,k;
	cin>>n>>k;
	for(fint i=1;i<=n;i++)
	cin>>a[i];
	for(fint i=k+1;i<=n;i++)
	if(a[i]>a[i-k])
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asort(s)        sort(s.begin(), s.end())
#define dsort(s)        sort(s.rbegin(), s.rend())
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)
#define all(s)          s.begin(), s.end()

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


unordered_map <ll, ll> f;
ll a[SZ];

int main() {
    ll t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    cin >> n;
    for1(i, n) cin >> a[i];

    for1(i, n) {
        x = i-a[i];
        y = a[i]+i;
        ans += f[x];
        f[y]++;
    }
    cout << ans << "\n";

    return 0;
}



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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int ans;
	for(int i = 0; i < 5; i++) {
		int x;
		cin >> x;
		if(x == 0)
			ans = i + 1;
	}
	cout << ans;




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, cc, kk;
	cin >> nn >> cc >> kk;
	vector<int64> aa(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
	}
	sort(aa.begin(), aa.end());
	int64 tmp, old = -1, cnt, ans = 0;
	for(int64 ii = 0;ii < nn;ii++)
	{
		tmp = aa[ii];
		if(old == -1)
		{
			ans++;
			old = tmp;
			cnt = 1;
			continue;
		}
		if(old + kk < tmp)
		{
			ans++;
			old = tmp;
			cnt = 1;
			continue;
		}
		if(cnt == cc)
		{
			ans++;
			old = tmp;
			cnt = 1;
			continue;
		}
		cnt++;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    char W[11];
    char T[101];
    char EOT[12] = "END_OF_TEXT";
    int ascii_diff = 'a' - 'A';
    int count = 0;

    scanf("%s", W);
    for (;;) {
        scanf("%s", T);

        if (strcmp(T, EOT) == 0) {
            break;
        }

        int i;
        for (i = 0; i <= strlen(T); i++) {
            if (('A' <= T[i])&&(T[i] <= 'Z')) {
                    T[i] += ascii_diff;
            }
        }


        if (strcmp(T, W) == 0) {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;
}



Measured memory_bytes: 2052
#include <stdio.h>

int main(int argc, char *argv[]){
  int n,x,l[100],i,y = 0;
  scanf("%d %d",&n,&x);
  for(i=0;i < n;i++){
    scanf("%d", &l[i]);
  }
  for(i=1;i < n+1;i++){
    y += l[i-1];
    if(y > x) break;
  }
  if(i == n){
    if(y <= x) i++;
  }
  
  printf("%d",i);
  return 0;
}

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

int main(){
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x,y;
  cin >>x >>y;
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    for(size_t i = 0; i < N; i++)
    {
        cin >> s[i];
    }
    cout << (find(s.begin(), s.end(),"Y") == s.end() ? "Three" : "Four") << endl;
    
    return 0;
}

Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);

    int n,s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(s-(i+j)<=n && s-(i+j)>=0)ans++;
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3656
from collections import deque as dq
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
ab = []
c = []
inf = 2 << 31
for i in range(M):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split())))
dp = [[inf] * M for _ in range(2 ** 12)]
cc = []
for i in range(M):
  temp = 0
  for k in range(ab[i][1]):
    t = 2 ** (c[i][k] - 1)
    temp = temp | t
  cc.append(temp)
def less(a, b):
  if a > b:
    return b
  else:
    return a
#print(ab, c)
Q = dq([])
Q.append((0, 0))
vis = [[0] * M for _ in range(2 ** 12)]
while len(Q):
  q = Q.popleft()
  i, j = q[0], q[1]
  if j >= M:
    continue
  if vis[i][j] == 1:
    continue
  vis[i][j] = 1
  temp = i ^ 0
  temp2 = cc[j]
  if j > 0:
    #print(temp | temp2, j, ab[j][0])
    dp[temp | temp2][j] = less(dp[temp][j - 1] + ab[j][0], dp[temp | temp2][j])
    dp[temp][j] = less(dp[temp][j], dp[temp][j - 1])
    dp[temp2][j] = less(ab[j][0], dp[temp2][j])
    Q.append((temp | temp2, j + 1))
    Q.append((temp, j + 1))
    Q.append((temp2, j + 1))
  else:
    #print(temp | temp2, j, ab[j][0])
    dp[temp | temp2][j] = less(ab[j][0], dp[temp | temp2][j])
    Q.append((temp | temp2, j + 1))
if dp[2 ** N - 1][-1] == inf:
  print(-1)
else:
  print(dp[2 ** N - 1][-1])




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

int main()
{
    int a,b;
    cin>>a>>b;
    int count = 0;
    for(int i=a;i<=b;i++){
        int t = 0; 
        int m = i,n;
        
        for(int j=4;j>=0;j--){
            int p = 1,q = 1;
            for(int k=0;k<j;k++){
                p *= 10;
            }
            for(int k=0;k<4-j;k++){
                q *= 10;
            }
            n = m/p;
            t += n*q;
            m -= n*p;
        }
        if(t == i){
            count++;
        }
    }
    cout<<count<<endl;
}

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

int main() {

  string S ; cin >> S;
  
  //int N;
  //N = S.size();
  
  char S3,S4,S5,S6;
  bool same = 1;
  
  //3,4
    S3 = S.at(2);
    S4 = S.at(3);
    if (S3 != S4) same = 0;    

  //5,6
    S5 = S.at(4);
    S6 = S.at(5);
    if (S5 != S6) same = 0;    
  
if ( same ) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
from networkx import*
H,*S=open(0)
H,W=map(int,H.split())
g=Graph()
a=g.add_edges_from
for i in range(m:=H*W):a([[M:=m*2,h:=i//W],[M,w:=i%W+m]]*((c:=S[h][w-m])=='S')+[[h,I:=m*3],[w,I]]*(c=='T'),capacity=I),a([[h,w],[w,h]]*(c>'T'),capacity=1)
print([-1,f:=minimum_cut(g,M,I)[0]][f<I])

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
#define int long long

int a[5], b[5];
signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false);   cout.tie(0);
    FOR(i, 1, 4)    {
        int x; cin >> x;
        if(x == 1) b[1] = 1;
        if(x == 9) b[2] = 1;
        if(x == 7) b[3] = 1;
        if(x == 4) b[4] = 1;
    }
    FOR(i, 1, 4) if(!b[i])
        return cout << "NO", 0;
    return cout << "YES", 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    in(n);
    char s[70];
    ll ac = 0, wa = 0, tle = 0, re = 0;
    fw(i, 0, n)
    {
        cin >> s;
        if (s[0] == 'A')
        {
            ac++;
        }
        else if (s[0] == 'W')
        {
            wa++;
        }
        else if (s[0] == 'T')
        {
            tle++;
        }
        else if (s[0] == 'R')
        {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  int cur=0;
  rep(i,0,m){
    int a;
    cin>>a;
    cur+=a;
  }
  cout<<max(-1,n-cur)<<endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define ll long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    if(s.back() == '1') {
        cout << "-1\n";
        return 0;
    }
    if(s[0] == '0') {
        cout << "-1\n";
        return 0;
    }
    for(int i = 1; i < n; ++i) {
        if(s[i-1] != s[(n-i)-1]) {
            cout << "-1\n";
            return 0;
        }
    }
    vector<int> sizes;
    for(int i = 1; i < n; ++i) {
        if(s[i-1] == '1') {
            sizes.push_back(i);
        }
    }
    vector<pair<int, int> > edges;
    for(int i = 1; i <= (int)sizes.size(); ++i) {
        edges.push_back({i,i+1});
    }
    int nextID = sizes.size()+2;
    int ID = 2;
    for(int i = 1; i < (int)sizes.size(); ++i) {
        for(int j = 0; j < sizes[i] - sizes[i-1] - 1; ++j) {
            edges.push_back({ID, nextID++});
        }
        ID++;
    }
    for(auto &p : edges) {
        cout << p.first << ' ' << p.second << '\n';
    }
    return 0;
}
















Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  int H, W;
  cin >> H >> W;
  
  vector<string> A(H);
  rep(i, H) cin >> A.at(i);
  
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  
  rep(i, H){
    rep(j, W){
      if(A.at(i).at(j) == '#'){
        dist.at(i).at(j) = 0;
        que.push(make_pair(i,j));
      }else{
        continue;
      }
    }
  }
      
      while(!que.empty()){
        pair<int, int> v = que.front(); que.pop();
        
        for(int k = -1; k<=1; k++){
          for(int l = -1; l<=1; l++){
            if(k*l != 0) continue;
            if(v.first+k < 0 || H <= v.first+k) continue;
            if(v.second+l < 0 || W <= v.second+l) continue; //場外
            if(dist.at(v.first+k).at(v.second+l) != -1) continue;
            
            dist.at(v.first+k).at(v.second+l) = dist.at(v.first).at(v.second) + 1;
            que.push(make_pair(v.first+k, v.second+l));
          }
        }
      }

  int res = 0;
  rep(i, H){
    rep(j, W){
      if(res < dist.at(i).at(j)) res = dist.at(i).at(j);
    }
  }
  
  cout << res;
  
}

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

#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))
const double EPS = 1e-9;

typedef complex<double> P;
#define X real()
#define Y imag()
typedef pair<P, P> L;

vector<P> poly;

int N;

double dot(P a, P b) {
    return (conj(a)*b).X;
}
double cross(P a, P b) {
    return (conj(a)*b).Y;
}
double distLP(P a1, P a2, P p) {
    return abs(cross(a2-a1,p-a1))/abs(a2-a1);
}
int ccw(P a, P b, P c) {
    b -= a;	c -= a;
    //3???????????´???????????????
    if (cross(b,c) > EPS) return +1;	// counter clockwise
    if (cross(b,c) < -EPS) return -1;	// clockwise
    //3???????????´???????????????
    if (dot(b,c) < -EPS) return +2;		// c--a--b on line
    if (norm(b) < norm(c)) return -2;	// a--b--c on line or a==b
    return 0;							// a--c--b on line or a==c or b==c
}
bool isecSS(P a1, P a2, P b1, P b2) {
    return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
    ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
P crosspointLL(P a1, P a2, P b1, P b2) {
    double d1 = cross(b2-b1, b1-a1);
    double d2 = cross(b2-b1, a2-a1);
    if (EQ(d1, 0) && EQ(d2, 0)) return a1;	// same line
    return a1 + d1 / d2 * (a2-a1);
}

bool ok(double l){
    vector<L> lines(N);
    for(int i=0; i<N; i++){
        auto p1 = poly[i], p2 = poly[(i+1)%N];
        auto v = (p2 - p1)/abs(p2 - p1) * P(0, 1) * l;
        auto np1 = p1 + v, np2 = p2 + v;
        lines[i] = L(np1, np2);
    }
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            auto& a1 = lines[i].first, a2 = lines[i].second;
            auto& b1 = lines[j].first, b2 = lines[j].second;
            if(!isecSS(a1, a2, b1, b2)) continue;
            
            auto p = crosspointLL(a1, a2, b1, b2);
            bool flag = true;
            for(int k=0; k<N; k++){
                auto& p1 = poly[k], p2 = poly[(k+1)%N];
                flag &= GE(distLP(p1, p2, p), l);
            }
            if(flag)
                return true;
        }
    }
    return false;
}

void solve(){
    double lb = 0, ub = 10000;
    for(int i=0; i<100; i++){
        double m = (lb + ub)/2;
        if(ok(m))
            lb = m;
        else
            ub = m;
    }
    cout << lb << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(16);
    cout.setf(ios::fixed);

    while(cin >> N, N){
        poly.resize(N);
        for(int i=0; i<N; i++){
            int x, y; cin >> x >> y;
            poly[i] = P(x, y);
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 3332
import java.util.Scanner;

class Main
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        
        int S = scan.nextInt();
        int h = S/3600;
        int m = (S-3600*h)/60;
        int s = S%60;
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26240
// Comment
// Choose number of (A+B) first

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

int A, B, C, X, Y;
int main() {
	cin >> A >> B >> C >> X >> Y;
	ll ans = LINF;
	for(int i=0; i<=max(X, Y); i++) {
		ans = min(ans, 1ll * max(0, X-i) * A + 1ll * max(0, Y-i) * B + 1ll * 2 * i * C);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int N, M, C; cin >> N >> M >> C;
	int b[25];
	int a[25][25];
	for (int i = 0; i < M; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> a[i][j];
		}
	}
	int c = 0;
	for (int i = 0; i < N; i++) {
		int sum = C;
		for (int j = 0; j < M; j++) {
			sum += b[j] * a[i][j];
		}
		if (sum > 0)c++;
	}
	cout << c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/


ll n;
ll a[MAX];
ll f[10*MAX];
ll spf[10*MAX];

void sieve(ll N){
  for(ll i=0;i<=N;i++){
    spf[i]=i;
  }
  for(ll i=2;i*i<=N;i++){
    if(spf[i]==i){
      for(ll j=i*i;j<=N;j+=i){
        spf[j]=min(spf[j],i);
      }
    }
  }
  return;
}

int main(){FAST;
  sieve(1000000);

cin>>n;

vl v;
for(int i=1;i<=n;++i){
  cin>>a[i];
  v.pb(a[i]);
}
sort(all(v));
v.resize(distance(v.begin(),unique(all(v))));

for(int i=0;i<v.size();++i){
  ll x = v[i];
  ll p = 1;
  ll ct = 0;

  while(x!=1){
    ll cp = spf[x];
    
    if(cp!=p){
      f[p] = max(f[p],ct);
      p = cp;
      ct = 1;
    }
    else{
      ct++;
    }
    
    x/=spf[x];
  }
  f[p] = max(f[p],ct);

}

ll l = 1;
for(ll i=1;i<=1000000;++i){
  l=(l*mpow(i,f[i],MOD))%MOD;
}

ll ans = 0;
for(ll i=1;i<=n;++i){
  ans=(ans+(l*minv(a[i],MOD))%MOD)%MOD;
}

cout<<ans;
return 0;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Asum,Aprod,Aint;
int n;
string A,B;

ll nCr(int n, int r){
  if(r==0||n==r)return 1;
  ll a=1;
  for(int i=0;i<r;i++) a*=(n-i);
  for(int i=0;i<r;i++) a/=(i+1);
  return a;
}

ll Sum(string str){
  ll res=0;
  for(int i=0;i<str.size();i++)res+=str[i]-'0';
  return res;
}

ll Prod(string str){
  ll res=1;
  for(int i=0;i<str.size();i++)res*=str[i]-'0'+1;
  return res;
}

ll Int(string str){
  ll res=0;
  for(int i=0;i<str.size();i++)res=res*10+str[i]-'0';
  return res;
}

ll permutation(string str){
  ll n=str.size(),res=1;
  for(int i=0,cnt=1;i<n;i++){
    if(str[i]==str[i+1])cnt++;
    else res*=nCr(n-i+cnt-1,cnt),cnt=1;
  }
  return res;
}

ll permutation(vector<int> a){
  string str;
  for(int i=0;i<a.size();i++)while(a[i]--)str+=(char)(i+'0');
  return  permutation(str);
}

ll count(){
  ll res=0;
  vector<int>cnt(10);
  for(int i=0;i<n;i++)cnt[B[i]-'0']++;

  for(int i=0;i<n;i++){
    for(int j=0;j<A[i]-'0';j++)
      if(cnt[j])cnt[j]--,res+=permutation(cnt),cnt[j]++;
    if(!cnt[A[i]-'0'])break;
    cnt[A[i]-'0']--;
  }
  return res;
}

ll calc(){
  if(Asum!=Sum(B)) return (Sum(B)<Asum)*permutation(B);
  if(Aprod!=Prod(B))return (Prod(B)<Aprod)*permutation(B);
  return count();
}

ll dfs(int idx,int num,int sum){
  if(idx==n) return calc();
  if(num==10||idx==n) return 0;
  ll res=dfs(idx,num+1,sum);
  B[idx]=num+'0';
  return res+dfs(idx+1,num,sum+num);
}

int main(){
  cin>>A;
  n=A.size();
  Asum=Sum(A),Aprod=Prod(A),Aint=Int(A);
  B.resize(n);
  cout<<dfs(0,0,0)<<endl;
  return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

// Don't konw why this sol doesn't work for all cases
class Solution1 {
private:
public:
    int64 solve(vector<int64>& A, vector<int64>& B, int64 n, int64 m, int64 k) {
        int64 i = 0, j = 0, ret = 0;
        while(i < n && j < m) {
            int64 cur;
            if(A[i] <= B[j]) cur = A[i++];
            else cur = B[j++];
            if(k >= cur) { k -= cur; ++ret; }
            else break;
        }
        if(k > 0) {
            while(i < n && k >= A[i]) {                 
                k -= A[i++];
                ++ret; 
            }
            while(j < m && k >= B[j]) {                 
                k -= B[j++];
                ++ret; 
            }
        }
        return ret;
    }
};

class Solution {
private:
public:
    int solve(vector<int>& A, vector<int>& B, int n, int m, int k) {
        int ret = 0;
        vector<int64> preA(n + 1), preB(m + 1);
        for(int i = 0; i < n; ++i) { preA[i + 1] = preA[i] + A[i]; }
        for(int i = 0; i < m; ++i) { preB[i + 1] = preB[i] + B[i]; }
        // for(int i = 0; i <= m; ++i) cout << preB[i] << " "; cout << endl;
        for(int i = 0; i <= n; ++i) {
            if(preA[i] > k) break;
            auto it = upper_bound(preB.begin(), preB.end(), k - preA[i]);
            // cout << "search val: " << k - preA[i] << ", it val: " << *it << endl;
            int b = it - preB.begin() - 1;
            ret = max(ret, i + b);
            // cout << "i: " << i << ", ret: " << ret << endl;
        }
        return ret;
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> A(n), B(m);
    for(int i = 0; i < n; ++i) cin >> A[i];
    for(int i = 0; i < m; ++i) cin >> B[i];

    Solution sol;
    auto ret = sol.solve(A, B, n, m, k);
    cout << ret << endl;
}

Measured memory_bytes: 7968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
int main(){
    ll x, D, r;
    cin >> r >> D >> x;
    rep(_,10){
        x = r * x - D;
        cout << x << endl;
    }
}


Measured memory_bytes: 3560
# https://atcoder.jp/contests/abc132/tasks/abc132_e
# 拡張ダイクストラ

import heapq
from collections import defaultdict

INF = int(1e18)
N, M = map(int, input().split())
G = {n: [] for n in range(N)}
for _ in range(M):
    ui, vi = map(int, input().split())
    ui -= 1; vi -= 1
    G[ui].append((1, vi))
S, T = map(int, input().split()); S -= 1; T -= 1

Gp = {}
for n in G:
    for t in [0, 1, 2]:
        Gp[(n, t)] = []
for u in G:
    for c, v in G[u]:
        Gp[(u, 0)].append((c, (v, 1))) # Gp[(v, 1)].append((1, (u, 0)))
        Gp[(u, 1)].append((c, (v, 2))) # Gp[(v, 2)].append((1, (u, 1)))
        Gp[(u, 2)].append((c, (v, 0))) # Gp[(v, 0)].append((1, (u, 2)))

# dijkstra on Gp
s = (S, 0)
t = (T, 0)
d = {v: INF for v in Gp}
used = {v: True for v in Gp}
d[s] = 0
used[s] = False

edgelist = []
for e in Gp[s]:
    heapq.heappush(edgelist, e)

while len(edgelist) > 0:
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]:
        continue
    v = minedge[1]
    d[v] = minedge[0]
    used[v] = False
    for e in Gp[v]:
        if used[e[1]]:
            heapq.heappush(edgelist, (e[0] + d[v], e[1]))

if t not in d or d[t] == INF:
    print("-1")
else:
    print(d[t] // 3)

Measured memory_bytes: 161676
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.*;

public class Main {
	public static class pair implements Comparable<pair> {
		int id;
		int ans;

		pair(int x, int y) {

			id = x;
			ans = y;

		}

		public pair() {

		}

		public int compareTo(pair o) {
			// TODO Auto-generated method stub

			return this.id - o.id;
		}
	}

//	static int mod = (int) 998244353.;
	static ArrayList<Integer> gr[];
	static long ar[];
	static Scanner sc = new Scanner(System.in);
	static int pri[] = new int[(int) 1e6 + 5];
	static StringBuilder out = new StringBuilder();

	//static long dp[];

	public static void main(String[] args) throws IOException {
		int t =1;// sc.nextInt();
		
		while (t-- > 0) {

			String s1="ABC";
			String s2="ARC";
			String s=sc.next();
			if(s.equals(s1)) {
				System.out.println(s2);
			}
			else System.out.println(s1);
		}

	}
}

Measured memory_bytes: 39644