akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  ll N;
  cin >>N;
  vector<ll> T(N);
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
    cin >> T[i];
  for (ll i = 0; i<N; i++)
    cin >> A[i];
  ll pattern = 1;
  if (T[0] > A[0])
    {
      cout << 0 << endl;
      return 0;
    }
  for (ll i = 1; i < N-1; i++)
    {
      if (T[i-1] < T[i])
	{
	  if (A[i] < T[i])
	    {
	      cout << 0 << endl;
	      return 0;
	    }
	}
      else if (A[i] > A[i+1])
	{
	  if (A[i] > T[i])
	    {
	      cout << 0 << endl;
	      return 0;
	    }
	}
      else if (T[i] < A[i])
	{
	  pattern *= T[i];
	  pattern %= mod;
	}
      else 
	{
	  pattern *= A[i];
	  pattern %= mod;
	  //cout << i<<endl;
	  
	}
      //cout << i <<"\t"<<pattern<< endl;
    }
  cout << pattern % mod << endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import math

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

# 現在の最大値を覚える
b = [a[0] for _ in range(n)]
tmp = a[0]

for i in range(1, n): 
    if a[i] >= tmp:
        tmp = a[i]
    b[i] = tmp 

ans = 0 
for i in range(n):
    ans += (b[i]-a[i])

print(ans)


Measured memory_bytes: 32856
#include<stdio.h>
int min(int a, int b){return a>b?b:a;}
int n, m;
char c;
int main(void){
  while((c=getchar())!=10){
    m += ((c-'0') ^ (n&1));
    n++;
  }
  printf("%d\n", min(m, n-m));
}


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

int main(){
        int n,i;
        long long ans=0;
        cin >> n;
        vector<long long> a(n);
        for(i=0;i<n;++i) cin >> a.at(i);
        sort(a.begin(),a.end(),greater<long long>());
        if(n%2==0) for(i=0;i<(n-2)/2;++i) ans += a.at(i+1)*2;
        else{
                for(i=0;i<(n-2)/2;++i) ans += a.at(i+1)*2;
                ans += a.at((n-2)/2+1);
        }
        ans += a.at(0);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 4760
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n,s,sum,mi,ma;
	int i;
	while (cin >> n) {
		sum = 0;
		ma = 0; mi = (int)MOD;
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			cin >> s; sum += s; mi = min(mi, s); ma = max(ma, s);
		}
		sum -= ma + mi;
		cout << sum / (n-2) << endl;
	}
	return 0;
}


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

int N, h[100], ans = 0;

void search(int i, int j){
    // 水やりしないならreturn
    if(h[j] < i)
        return;
    // 水やりする
    // 新しい島でないならreturn
    if(j != 0 && h[j-1] >= i)
        return;
    // 新しい島
    ans++;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)
        cin >> h[i];
    int max = 0;
    for(int i=0;i<N;i++){
        if(h[i] > max)
            max = h[i];
    }
    for(int i=1;i<=max;i++){
        for(int j=0;j<N;j++){
            search(i, j);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
flag=0
now=0
i=0
count=0
c=[0]*N
r=[0]
c[0]=1
while flag==0:
  now=A[now]-1
  count+=1
  if count==K:
    flag=1
  elif c[now]==1:
    flag=2
  c[now]=1
  r.append(now)
if flag==1:
  print(now+1)
else:
  o=[i for i, x in enumerate(r) if x == now]
  print(r[(K-o[0])%(o[1]-o[0])+o[0]]+1)

Measured memory_bytes: 32384
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int n,a[100005],cnt;
int Abs(int x){
	if (x>=0) return x; else return -x;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	for (int i=1;i<=n+1;i++){
		cnt+=Abs(a[i]-a[i-1]);
	}
	for (int i=1;i<=n;i++){
		if (a[i]>a[i-1] && a[i]>a[i+1]){
			cout<<cnt-2*(a[i]-max(a[i-1],a[i+1]))<<endl;
		}else if (a[i]<a[i-1] && a[i]<a[i+1]){
			cout<<cnt-2*(min(a[i-1],a[i+1])-a[i])<<endl;
		}else{
			cout<<cnt<<endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static int countAB(final String text) {
		int count = 0;
		int index = 0;
		while (true) {
			index = text.indexOf("AB", index);
			if (index < 0)
				return count;
			count += 1;
			index += 2;
		}
	}

	public static int solve(final String[] in) {
		int beginsWithB = 0;
		int endsWithA = 0;
		int sum = 0;
		int both = 0;
		for (int i = 0; i < in.length; ++i) {
			final String si = in[i].trim();
			final boolean b = si.charAt(0) == 'B';
			final boolean a = si.charAt(si.length() - 1) == 'A';
			if (a && b) {
				++both;
			} else {
				if (a)
					++endsWithA;
				if (b)
					++beginsWithB;
			}
			sum += countAB(si);
		}
		
		sum += Math.max(both - 1, 0);
		if (both > 0) {
			if (endsWithA > 0) {
				sum += 1;
				endsWithA -= 1;
			}
			if (beginsWithB > 0) {
				sum += 1;
				beginsWithB -= 1;
			}
		}

		sum += Math.min(endsWithA, beginsWithB);
		return sum;
	}

	public static void main(final String[] args) {
		@SuppressWarnings("resource")
		final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		final int N = in.nextInt();

		final String[] S = new String[N];
		for (int i = 0; i < N; ++i) {
			S[i] = in.next().trim();
		}
		System.out.println(solve(S));
	}
}


Measured memory_bytes: 30928
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
const long long MOD = 1000000007;
typedef long long ll;

ll n,a,b;
string s,t,u;

int main() {
  cin >> s;
  n=s.size();
  rep(i,n) t+='x';
  cout << t << endl;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
map<int,int> dic;
int a;
rep(i,n){
    cin>>a;
    dic[a]++;
    dic[a-1]++;
    dic[a+1]++;
}
int x=-1;
int num=-1;
for(auto v:dic){
    if(chmax(num,v.second)){
        x=v.first;
    }
}
cout<<num<<endl;
return 0;
}

Measured memory_bytes: 4736
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n = int(input())
keta = int(len(str(n)))
c = 0



if keta ==1:
    print(n)
elif keta ==2:
    print(9)
elif keta ==3:
    print(9+n-10**2+1)
elif keta == 4:
    print(900+9)
elif keta == 5:
    print(9+900+n-10**4+1)
elif keta == 6:
    print(9+900+90000)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdlib>
#include <typeinfo>

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

using namespace std;

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

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

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

string T;
string L;

int main() {
    map<char, int> result;
    for (char c = 'a'; c <= 'z'; ++c) {
        result[c] = 0;
    }

    while (getline(cin, L)) {
        for (int i = 0; i < L.length(); ++i) {
            unsigned char c = L[i];
            if (isupper(c)) {
                c = tolower(c);
            }
            if (result.count(c) > 0) {
                result[c]++;
            }
        }
    }

    for (auto x: result) {
        printf("%c : %d\n", x.first, x.second);
    }
}



Measured memory_bytes: 3256
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
void solve()
{
	ll N;
	cin>>N;
	string s;
	cin>>s;
	for(ll i=0;i<s.length();i++)
	{
		ll x=((s[i]-65)+N)%26;
		char val=x+65;
		cout<<val;
	}
	cout<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    string S;
    cin >> S;
    ll s = atoi(S.c_str());
    ll l = s % 100;
    ll h = s / 100;
    bool lv = l >= 13 || l == 0;
    bool hv = h >= 13 || h == 0;
    if (lv && hv)
    {
        puts("NA");
    }
    // YYMMではありえないこと
    else if (lv)
    {
        puts("MMYY");
    }
    // MMYYではありえないこと
    else if(hv)
    {
        puts("YYMM");
    }
    else
    {
        puts("AMBIGUOUS ");
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
bool vis[100005];
int dfs(int src , list<int> adj[]){
  if(vis[src]==true) return dp[src];
	vis[src]=true;
  int len=0;
  for (auto u=adj[src].begin();u!=adj[src].end();u++){
  	len=max(1+dfs(*u,adj),len);
  }
  dp[src]=len;
    return dp[src];

}
int main(){
  int v,e;
  cin>>v>>e;
  int x,y;
  list< int> adj[v+1];
  for(int i=0;i<e;i++){
  	cin>>x>>y;
    adj[x].push_back(y);
  }
  
 // memset(vis, false, sizeof vis);
  int len=0;
  for(int i=1;i<=v;i++){
  	len=max(len,dfs(i,adj));
  //  memset(vis,false, sizeof vis);
  }
  
  cout<<len<<endl;
}


Measured memory_bytes: 7424
#include <iostream>
#include <stack>
#include <string>
#include <stdlib.h>
using namespace std;

int main(){
    stack<int> S;
    string s;
    int a,b;
    while(cin >> s){
        switch (s[0]){
            case '+':
                a = S.top();
                S.pop();
                b = S.top();
                S.pop();
                S.push(b+a);
                break;
            case '-':
                a = S.top();
                S.pop();
                b = S.top();
                S.pop();
                S.push(b-a);
                break;
            case '*':
                a = S.top();
                S.pop();
                b = S.top();
                S.pop();
                S.push(b*a);
                break;
            case '/':
                a = S.top();
                S.pop();
                b = S.top();
                S.pop();
                S.push(b/a);
                break;
            default:
                S.push(stoi(s));
        }
    }
    cout << S.top() << endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
typedef long long ll;
using namespace std;
int main() {
    int n; ll l; cin >> n >> l;
    vector<ll> a(n); repeat (i,n) cin >> a[i];
    vector<int> ans;
    repeat (i,n-1) {
        if (a[i] + a[i+1] >= l) {
            repeat (j,i) ans.push_back(j);
            repeat_from_reverse (j,i,n-1) ans.push_back(j);
            break;
        }
    }
    if (ans.empty()) {
        assert (n >= 2);
        cout << "Impossible" << endl;
    } else {
        cout << "Possible" << endl;
        for (int i : ans) cout << i+1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
        ll H, W;
        cin>>H>>W;
        if(H%3==0||W%3==0){
                cout<<0<<endl;
                return 0;
        }
        ll res=100000000000;
        for(int i=1;i<H;i++){
                ll mx, mn;
                mx=max(W*i, max((W/2)*(H-i), (W-W/2)*(H-i)));
                mn=min(W*i, min((W/2)*(H-i), (W-W/2)*(H-i)));
                res=min(res, mx-mn);
        }
        for(int i=1;i<W;i++){
                ll mx, mn;
                mx=max(H*i, max((H/2)*(W-i), (H-H/2)*(W-i)));
                mn=min(H*i, min((H/2)*(W-i), (H-H/2)*(W-i)));
                res=min(res, mx-mn);
        }
        res=min(res, (W/3+1)*H-(W/3)*H);
        res=min(res, (H/3+1)*W-(H/3)*W);
        cout<<res<<endl;
        return 0;
}


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

int n ; double p[3005];
double dp[3005][3005];
double func(int i , int h)
{
	if(i<h)
	return(0);
	
	if(h==0)
	return(1);
	
	if(i==0)
	return(0);
	
	if(dp[i][h]!=-1)
	return(dp[i][h]);
	double t = func(i-1,h-1)*p[i]+ func(i-1,h)*(1-p[i]); 
	return(dp[i][h]=t);
	
}

int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
cin>>n ; 
for(int i = 1; i<=n; i++)
cin>>p[i];
for(int i =0 ; i<=n; i++)
{
	for(int j = 0 ; j<=n ; j++)
	dp[i][j]= -1; 
}
cout<<fixed;
cout<<setprecision(10);
cout<<func(n,(n+1)/2);
return(0);

}
	


Measured memory_bytes: 70912
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct P{int x,y,cost;};
#define INF (1<<25)
#define rep(i,n) for(int i=0; i<n ;i++)

int dist(P a,P b){
	return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(){
	int w,h;
	
	while(cin >> w >> h , w) {
		vector<P> data[5];
		P start , goal ;
		
		start.cost = 0 , goal.cost = 0;
		
		rep(i,h)rep(j,w){
			char c;	cin >> c;
			if(c != '.'){
				if(c == 'S'){
					start.x = j , start.y = i;	
				}else if(c == 'G'){
					goal.x = j , goal.y = i;
				}else{
					P t = {j,i,0};
					data[c-'1'].push_back(t);
				}
			}
		}
		int ret = INF , num ;
		
		P dp[5][1000];
		rep(lp,5){ // start
			rep(i,5)rep(j,1000){dp[i][j].cost = INF;}
			
			int so = (lp+1)%5;
			rep(i,data[so].size()){
				dp[so][i] = data[so][i];
				dp[so][i].cost = dist(data[so][i],start);
			}
			
			rep(Z,3){ //kurikaesi
				int z = (lp+Z+2)%5;
				int prev = (z+4)%5;
				rep(i,data[prev].size()){ // izen
					rep(j,data[z].size()){ //now
						int cost = dp[prev][i].cost + dist(dp[prev][i],data[z][j]);
						//cout << dist(dp[prev][i],data[z][j]) << endl;
						if(dp[z][j].cost > cost){
							dp[z][j] = data[z][j];
							dp[z][j].cost = cost;
						}
					}
				}
			}
			rep(i,data[(lp+4)%5].size() ){
				int kCost = dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal);
				if( kCost < ret){
					ret = kCost , num = lp+1; 
				}
			}
		}
		
		if(ret == INF)cout << "NA" << endl; 
		else cout << num << " " << ret << endl; 
	}
}

Measured memory_bytes: 1060
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

#####################################


#4:25
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
maxv=0
maxid=-1
for i in range(n-1):
    if(maxv<a[i]+a[i+1]):
        maxv=a[i]+a[i+1]
        maxid=i+1

if(maxv<k):
    print("Impossible")
    exit()
print("Possible")
for j in range(maxid-1):
    print(j+1)
    
for j in range(n-maxid-1):
    print(n-1-j)
    
print(maxid)

Measured memory_bytes: 63984
/**
 * Created by hiramekun at 00:27 on 2020-05-19.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (n / (a + b)) * a + min((n % (a + b)), a) << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nmLine = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nmLine[0]);
        int m = Integer.parseInt(nmLine[1]);
        int nm = n * m;

        String[] aLine = scanner.nextLine().split(" ", n);
        long[] aArr = new long[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = Long.parseLong(aLine[i]);
        }

        String[] bLine = scanner.nextLine().split(" ", m);
        long[] bArr = new long[m];
        for (int i = 0; i < m; i++) {
            bArr[i] = Long.parseLong(bLine[i]);
        }

        Arrays.sort(aArr);
        Arrays.sort(bArr);

		long mod = 1000000007;
        long answer = 1;
        int aInd = n - 1;
        int bInd = m - 1;
        for (int i = nm; i >= 1; i--) {
            if (aInd >= 0 && aArr[aInd] == i && bInd >= 0 && bArr[bInd] == i) {
                aInd--;
                bInd--;
            } else if (aInd >= 0 && aArr[aInd] == i) {
                answer *= m - 1 - bInd;
                aInd--;
            } else if (bInd >= 0 && bArr[bInd] == i) {
                answer *= n - 1 - aInd;
                bInd--;
            } else if ((n - 1 - aInd) * (m - 1 - bInd) > (nm - i)) {
                answer *= (n - 1 - aInd) * (m - 1 - bInd) - (nm - i);
            } else {
                answer = 0;
                break;
            }
            answer %= mod;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
#!/usr/bin/env python
# coding: utf-8

# In[5]:


# import itertools


# In[35]:


S = input()


# In[36]:


# mylist = list(map(lambda x: "".join(x), list(set(itertools.permutations(S)))))
# ngs = []
# for w in ["a","b","c"]:
#     ngs.append(w+w)
#     for x in ["a","b","c"]:
#         ngs.append(w+x+w)
# for word in mylist:
#     for ng in ngs:
#         if ng in word:
#             break
#     else:
#         print("YES")
#         break
# else:
#     print("NO")


# In[39]:


a_cnt = S.count("a")
b_cnt = S.count("b")
c_cnt = S.count("c")
if abs(a_cnt-b_cnt) <= 1 and abs(a_cnt-c_cnt) <= 1 and abs(b_cnt-c_cnt) <= 1:
    print("YES")
else:
    print("NO")


# In[ ]:






Measured memory_bytes: 9020
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0,r = 0;
    int pointer=0;
    REP(i,n){
        if(s[i]=='('){
            pointer++;
        }
        else{
            if(pointer==0)l++;
            else pointer--;
        }
    }
    r=pointer;
    
    REP(i,l){
        cout << "(";
    }
    cout << s;
    REP(i,r){
        cout << ")";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    string n;
    cin >> n;
    int sum=0;
    rep(i,n.size()) {
        sum+=(n[i]-'0');
        sum=sum%9;
    }
    if(sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  
  string a[101];
  for (int i = 0; i < N; i++) cin >> a[i];
  
  sort(a, a + N);
  
  for (int i = 0; i < N; i++) cout << a[i];
  cout << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a[5], k;

int main() {
	inc(i, 5) { cin >> a[i]; }
	cin >> k;
	
	cout << (a[4] - a[0] <= k ? "Yay!" : ":(") << endl;
	
	return 0;
}


Measured memory_bytes: 256
/// In the name of God
#include <bits/stdc++.h>
//#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int N = 1e6, mod = 1e9 + 7;
inline int ad(int x,int y){
    x += y;
    if(x < mod) return x;
    return x - mod;
}
inline int mu(int x,int y){
    return 1LL * x * y % mod;
}
inline int bpow(int x,int y = mod - 2){
    int res = 1;
    while(y){
        if(y & 1) res = mu(res, x);
        x = mu(x, x);
        y >>= 1;
    }
    return res;
}
int fact[N], inv[N];
void prep(){
    for(int i=0; i<N; i++)
        fact[i] = (!i ? 1 : mu(i, fact[i - 1]));
    inv[N - 1] = bpow(fact[N - 1]);
    for(int i=N-1; i--; )
        inv[i] = mu(inv[i + 1], i + 1);
}
inline int C(int r,int n){
    if(r < 0 || n < 0 || r > n) return 0;
    return mu(fact[n], mu(inv[r], inv[n - r]));
}

const int maxn = 2e5 + 10;
vi adj[maxn], col[maxn], rem[maxn];
int c[maxn], w[maxn];
bool cmp(int x,int y){
    return w[x] < w[y];
}
void ad_e(int u,int v){
    adj[u].push_back(v);
    adj[v].push_back(u);
}
bool mark[maxn];
vi ver;
void dfs(int v){
    if(mark[v]) return;
    mark[v] = 1;
    ver.push_back(v);
    for(auto u : adj[v])
        dfs(u);
}
map<int,int> cnt;
int main(){
    IOS;
    prep();
    int n, one, two;
    cin >> n >> one >> two;
    for(int i=0; i<n; i++){
        cin >> c[i] >> w[i];
        c[i]--;
        col[c[i]].push_back(i);
    }
    vi fir;
    for(int i=0; i<n; i++){
        sort(all(col[i]), cmp);
        for(int j=1; j<col[i].size(); j++)
            if(w[col[i][j]] + w[col[i][0]] <= one)
                ad_e(col[i][j], col[i][0]);
            else
                rem[i].push_back(col[i][j]);
        if(col[i].size())
            fir.push_back(col[i][0]);
    }
    sort(all(fir), cmp);
    for(int j=1; j<fir.size(); j++)
        if(w[fir[0]] + w[fir[j]] <= two)
            ad_e(fir[0], fir[j]);
    for(int i=0; i<n; i++){
        if(i == c[fir[0]]) continue;
        for(auto j : rem[i])
            if(w[j] + w[fir[0]] <= two)
                ad_e(j, fir[0]);
    }
    if(fir.size() != 1){
        int tw = fir[1];
        for(auto j : rem[c[fir[0]]])
            if(w[j] + w[tw] <= two)
                ad_e(j, tw);
    }
    int ans = 1;
    for(int i=0; i<n; i++){
        ver.clear();
        if(mark[i]) continue;
        dfs(i);
        vi p;
        cnt.clear();
        for(auto i : ver){
            p.push_back(c[i]);
            cnt[c[i]]++;
        }
        sort(all(p));
        p.resize(unique(all(p)) - p.begin());
        int ha = ver.size();
        for(auto i : p){
            ans = mu(ans, C(cnt[i], ha));
            ha -= cnt[i];
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 43508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5005;
ll a[N],dp[N][N];
inline void cmn(ll&a,ll b){if(a>b)a=b;}
int main()
{
	ll n,A,B,ans=1ll<<60;scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	memset(dp,0x3f,sizeof(dp));dp[0][0]=0;
	for(int i=1;i<=n;i++)for(int j=0;j<=n;j++)if(a[i]>j)cmn(dp[i][j],dp[i-1][j]+A),cmn(dp[i][a[i]],dp[i-1][j]);else cmn(dp[i][j],dp[i-1][j]+B);
	for(int i=0;i<=n;i++)cmn(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 196096
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
tes = False
num = int(stdin.readline().rstrip())
for k1 in range(1, 10):
    for k2 in range(1, 10):
        if (num == k1 * k2):
            print('Yes')
            tes = True
            break
    if (tes):
        break
if (not tes):
    print('No')


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

int* array;
int size;

void buildMaxHeap(int index){
	int left = index * 2 + 1;	
	int right = index * 2 + 2;	

	int max = index;
	if(left < size)max = array[index] > array [left] ? index : left; 
	if(right < size)max = array[max] > array [right] ? max : right; 

	if(max != index){
		int buf = array[index];
		array[index] = array[max];
		array[max] = buf;
		
		buildMaxHeap(max);
	}
	
}

int main(){
	ios_base::sync_with_stdio(false);

	cin >> size;

	array = new int[size];

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

	for(int i = size / 2 - 1; i >= 0; i --){
		buildMaxHeap(i);
	}

	for(int i = 0; i < size; i ++){
		cout << " " << array[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <set>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

int solve(int X, set<int> nums)
{
    u int min = -1, result = 0;

    REPR(i, X + 1, *nums.begin() - 1)
    {
        if (!nums.count(i) and abs(X - i) < min)
        {
            min = abs(X - i);
            result = i;
            break;
        }
    }

    REP(i, X, *nums.rbegin() + 2)
    {
        if (!nums.count(i) and abs(X - i) < min)
        {
            min = abs(X - i);
            result = i;
            break;
        }
    }

    return result;
}

int main()
{
    int X; 
    u int N;
    cin >> X >> N;

    set<int> nums;
    if (N == 0)
        nums.insert(0);

    REP(i, 0, N)
    {
        u int a;
        cin >> a;
        nums.insert(a);
    }

    cout << solve(X, nums) << "\n";

    return 0;
}

Measured memory_bytes: 3624
i = int(input())
s = input()
l = s.split()
l_int = [int(n) for n in l]
tmp = 0
for j in range(i):
    if j % 2 ==0:
        # print(l_int[j])
        if l_int[j] % 2 != 0:
            # print("a")
            # print(l_int[j])
            tmp += 1
print(tmp)


Measured memory_bytes: 9020
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] L = Console.ReadLine().Split(' ');
		int S = int.Parse(L[0]);
		int W = int.Parse(L[1]);

		if(S <= W){
				Console.WriteLine("unsafe");
		}else{
				Console.WriteLine("safe");
		}

	}
}



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

long long mod = 1000000000 + 7;

long long modplus(long long a, long long b){
	long long ans = a + b;
	ans %= mod;
	return ans;
}

long long modminus(long long a, long long b){
	long long ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}

long long modmul(long long a, long long b){
	long long ans = (a % mod) * (b % mod);
	ans = ((ans % mod) + mod) % mod;
	return ans;
}

long long modpow(long long A, long long P){
	long long a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	long long adash = modmul(a,a);
	if(p % 2) return modmul(modpow(adash, p / 2), a);
	else return modpow(adash, p / 2);
}

long long moddiv(long long a, long long b){
	long long divisor = modpow(b, mod - 2);
	return modmul(a,divisor);
}

long long comb(long long n, long long m){
	if(n == 0)return 1;
	if(m == 0)return 1;
	if(n < m) return 0;
	long long ans = 1;
	for(long long i=0;i<m;i++){
		ans = modmul(ans, n-i);
	}
	for(long long i=0;i<m;i++){
		ans = moddiv(ans, i+1);
	}
	return ans;
}

int main(){
	long long S;
	cin >> S;
	long long ans = 0;
	for(int i=1;i<=S/3;i++){
		long long tmp = S - 3 * i;
		tmp += i-1;
		ans = modplus(ans, comb(tmp, i-1));
		// cout << i << ":" << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
const int MAXS = 105;
char S[MAXS];
int N;

int main() {
  scanf(" %s", S);
  N = strlen(S);
  int cnt = 0;
  for (int i=0, j=N-1; i < j; ++i, --j) {
    if (S[i] != S[j]) ++cnt;
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 256
x=int(input())

if 400 <= x <=599:
    print('8')
if 600 <= x <=799:
    print('7')
if 800 <= x <=999:
    print('6')
if 1000 <= x <= 1199:
    print('5')
if 1200 <= x <= 1399:
    print('4')
if 1400 <= x <= 1599:
    print('3')
if 1600 <= x <= 1799:
    print('2')
if 1800 <= x <= 1999:
    print('1')

Measured memory_bytes: 9184
long[][] dp;
const ulong MAX = 1000000;
long[] fact, fact_inv, inv;
ulong MOD = 1000000007;

void main() {
	auto ip = readAs!(int[]), X = ip[0], Y = ip[1];
	fact = new long[](MAX);
	fact_inv = new long[](MAX);
	inv = new long[](MAX);

	fact[0] = fact[1] = 1;
	fact_inv[0] = fact_inv[1] = 1;
	inv[1] = 1;
	foreach(i; 2..MAX) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
	}

	long COM(int n, int k) {
		if(n < k) return 0;
		if(n < 0 || k < 0) return 0;
		return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
	}

	auto k = (X + Y) / 3;
	if((X + Y) % 3 != 0) {
		writeln(0);
		return;
	}
	COM(k, X-k).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 28028
<?php
[$N, $K] = ints();
$dp[0] = array_merge([0],ints());
for($i = 1; $i < 64; $i++){
  for($j = 1; $j <= $N; $j++){
    $dp[$i][$j] = $dp[$i-1][$dp[$i-1][$j]];
  }
}
$c = 1;
$i = 0;
while($K >> $i){
  if($K >> $i & 1)$c=$dp[$i][$c];
  $i++;
}
echo $c;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}

Measured memory_bytes: 423640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}

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


int main(){
  ll n,m,t; cin >> n >> m >> t; vl num(m);
  rep(i,m){ ll x; cin >> x; num[i] = x; }
  
  sort(all(num));
  
  ll sum = 0;
  for(ll x : num){
    if(x < t) sum++;
    else break;
  }
  
  cout << min(m - sum, sum) << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

x,y = LI()
print(x*y, x*2+y*2)


Measured memory_bytes: 5992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

ll b,d,a;

int main(){
	cin>>b>>d>>a;
	ll c = a%mod;
	if(a >= b){
		 c += d%mod * (max(0ll,(a-d)/(b-d)) % mod);
	}
	c = (c%mod+mod)%mod;
	cout << c << endl;
}


Measured memory_bytes: 3076
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        static long mod = (long)Math.Pow(10, 9) + 7;

        public static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            string testS = S;

            int index = (int)(N-1);

            while (index > 0)
            {
                if (testS[index] == ')' && testS[index - 1] == '(')
                {
                    testS = testS.Remove(index - 1, 2);
                    if (testS.Length < index) index--;
                }
                index--;
            }

            string addsL = "";
            string addsR = "";

            for (int i = 0; i < testS.Length; i++)
            {
                if (testS[i] == ')')
                {
                    addsR += '(';
                }
                else
                {
                    addsL += ')';
                }
            }

            Console.WriteLine(addsR+S+addsL);
            Console.ReadLine();
        }

    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	double x[2],y[2],r[2];
	for(int i=0;i<2;i++){
		cin>> x[i]>> y[i]>> r[i];
	}
	
	double d = sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]));
	
	if(d > r[0]+r[1]){
		cout<< "0"<< endl;
		return true;
	}
	if(d < (max(r[0],r[1]) - min(r[0],r[1])) ){
		if(r[0] < r[1]){
			cout<< "-2"<< endl;
		}
		if(r[0] > r[1]){
			cout<< "2"<< endl;
		}
		return true;
	}
	cout<< "1"<<endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}

	return 0;
}

 

Measured memory_bytes: 1224
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef double db;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
const int N=1e6+5,mo=1e9+7;
int n,m,K,i,j,k,q1,q2;
ll f[2][2005][2],sum[2005];
int ans;
int main()
{
	scanf("%d %d %d",&n,&m,&K);
	m--;K--;
	q1=0;
	q2=1;
	f[0][0][0]=1;
	fo(i,1,max(n,m)*2)
	{
		fo(j,0,n) sum[j+1]=(sum[j-1+1]+f[q1][j][0]+f[q1][j][1])%mo;
		fo(j,0,n)
		{
			f[q2][j][0]=(sum[j+1]-sum[j-1+1])%mo;
			k=max(0,j-K);
			f[q2][j][1]=(sum[j-1+1]-sum[k-1+1])%mo;
		}
		fo(j,0,n)
			if (j%K==n%K&&(i*K-j)%K==m%K&&i*K-j<=m)
				ans=(ans+f[q2][j][1])%mo;
		q1^=1;q2^=1;
	}
	ans=(ans+mo)%mo;
	printf("%d",ans);
}

Measured memory_bytes: 256
import sys

num_str = sys.stdin.readline().strip()
for i in range(8):
  tmp_str = list(num_str)
  if i % 2 == 1:
    tmp_str.insert(3, '+')
  else:
    tmp_str.insert(3, '-')
  if (i // 2) % 2 == 1:
    tmp_str.insert(2, '+')
  else:
    tmp_str.insert(2, '-')
  if (i // 4) % 2 == 1:
    tmp_str.insert(1, '+')
  else:
    tmp_str.insert(1, '-')
  tmp_str = ''.join(tmp_str)
  exec_str = 'a=' + tmp_str
  exec(exec_str)
  if a == 7:
    print(tmp_str + '=7')
    break
    

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

using namespace std;

typedef long long LL;
const int N = 55;

int n, d, x, p[N], m[N], ind[N]; 
vector<int> e[N];
LL value[N], cost[N], f[N * N * N];

void dfs(int u) {
  value[u] = 1;
  cost[u] = m[u];
  for (int i = 0; i < e[u].size(); ++i) {
    int v = e[u][i];
    dfs(v);
    value[u] += value[v];
    cost[u] += cost[v]; 
  }
}

bool cmp(int i, int j) {
  return cost[i] * value[j] < cost[j] * value[i]; 
}

void upd(LL &a, LL b) {
  if (a == -1) a = b;
  else a = min(a, b);
}

int main() {
  cin >> n >> x >> d;
  for (int i = 1; i <= n; ++i) {
    cin >> m[i];
    if (i > 1) { cin >> p[i]; e[p[i]].push_back(i); }
  }
  
  dfs(1);
  
  for (int i = 0; i < n; ++i) ind[i] = i + 1;
  sort(ind, ind + n, cmp);

  fill(f, f + N * N * N + 1, -1);
  f[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int s = (i == 1 ? N : min(d, N));
    for (int j = 1; s; j <<= 1) {
      int v = min(s, j);
      for (int k = N * N * N; k >= 0; --k) {
        if (k + v * value[i] <= N * N * N && f[k] != -1)
          upd(f[k + v * value[i]], f[k] + v * cost[i]);
      }
      s -= v;
    }
  }

  LL max_v = 0;
  for (int i = 0; i <= N * N * N; ++i) {
    if (f[i] == -1 || f[i] > x) continue;
    LL cur_x = x - f[i];
    LL cur_v = i;
    for (int j = 0; j < n; ++j) {
      LL k = cur_x / cost[ind[j]];
      if (ind[j] != 1) k = min(k, 1LL * d - min(N, d));
      cur_x -= k * cost[ind[j]];
      cur_v += k * value[ind[j]];
    }
    max_v = max(max_v, cur_v);
  }

  cout << max_v << endl;

  return 0;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


struct cam{
    ll k,dis;
};
bool comp(cam x,cam y){
    return x.k<y.k;
}

ll ca(vector<cam>v){
    
    ll vs=v.size();
    ll res=0;
    sort(all(v),comp);
    priority_queue<ll>q;
    ll pos=v.size()-1;
    rrep(i,vs,1){
        while(pos>=0&&v[pos].k>=i){
            q.push(v[pos].dis);
            pos--;
        }
        if(!q.empty()){
            res+=q.top();q.pop();
        }
    }
    
    return res;
}

bool anspro(){
    ll n;
    cin>>n;
    vector<cam>vl,vr;
    ll ans=0;
    rep(i,0,n-1){
        ll a,b;
        cam x;
        cin>>x.k>>a>>b;
        if(a>b){
            ans+=b;
            x.dis=a-b;
            vl.pb(x);
        }else{
            ans+=a;
            x.dis=b-a;
            x.k=n-x.k;
            vr.pb(x);
        }
    }
    
    ll pl=ca(vl);
    ll pr=ca(vr);
   // cout<<ans<<" "<<pl<<" "<<pr<<endl;
    cout<<ans+pl+pr<<endl;
    
    return 0;
}

int main(){fastio
    ll t;cin>>t;
    while(t--){
        anspro();
    }
    
    return 0;
}



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

int main() {
    string s;
    cin >> s;
    int one = 0;
    if(s[0]=='1') ++one;
    if(s[1]=='1') ++one;
    if(s[2]=='1') ++one;
    cout << one << endl;
	
	return 0;
}


Measured memory_bytes: 256