akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int N;
long long int A, B;
long long int h[100005];

bool IsPossible(long long int K) {

	long long int count = 0;

	for (int i = 1; i <= N; i++) {
		if (h[i] < K*B) { continue; }
		else { count += (h[i] - K*B + A - B - 1) / (A - B); }
	}

	//cout << "count= " << count << endl;

	if (count <= K) { return true; }
	return false;
}

long long int BINARY(void) {

	long long int left = 0;
	long long int right = 10000000008;
	long long int med;

	while (right > left + 1) {
		med = (left + right) / 2;
		if (IsPossible(med)) {
			right = med;
		}
		else {
			left = med;
		}
	}
	return right;
}

int main(void) {

	cin >> N;
	cin >> A >> B;
	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; h[i] = tmp;
	}

/*	for (int K = 1; K <= 10; K++) {
		cout << IsPossible(K) << endl;
	}*/

	cout << BINARY() << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	double x,y;
	int cnt=0;
	while(n--)
	{
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=m)
		cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3856
#include<cstdio>
#include<stack>

using namespace std;

struct Coord {
  int row;
  int col;
};

int solve (int W, int H);
  
int main () {
  int W, H;

  while(1)
    {
      scanf("%d%d", &W, &H);
      if(W==0 && H==0) break;	
      printf("%d\n", solve(W,H));	
    }
}

int solve (int W, int H) {
  int n=0;
  char M[H+2][W+2];
  Coord start;
  for (int i=0; i<=W+1; i++) { M[0][i] = '#'; M[H+1][i] = '#'; }
  for (int i=1; i<=H; i++) { M[i][0] = '#'; M[i][W+1] = '#'; } 
  for (int i=1; i<=H; i++) {
    for (int j=1; j<=W; j++) {
      scanf(" %c", &M[i][j]);
      if (M[i][j]=='@') {
	start.row = i;
	start.col = j;
      }
    }
  }

  
  stack<Coord> S;
  S.push(start);
  while (!S.empty()) {
    Coord current = S.top(); S.pop();
    n++;
    int D1[]={1,0,-1,0}; int D2[]={0,-1,0,1};
    for (int d=0; d<4; d++) {
      Coord nc = current;
      nc.row += D1[d];
      nc.col += D2[d];
      if(M[nc.row][nc.col]!='#' && M[nc.row][nc.col]!='*' && M[nc.row][nc.col]!='@')
	{
	  M[nc.row][nc.col] = '*';
	  S.push(nc);
	}
    } 
    
  }
  return n;
}

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

int main(){
  long long l, r;
  cin >> l >> r;
  if(r-l > 2019){
    cout << 0 << endl;
  }else{
    long long res=2018;
    for(long long i=l; i<r; i++){
      for(long long j=i+1; j<=r; j++){
        res = min(res, (i*j)%2019);
      }
    }
    cout << res << endl;
  }
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) {
    p("Yes");
  } else {
    p("No");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define double long double
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<int,int> P;
const long long MOD=1000000007;
clock_t time_ini = clock();
double time_diff(){
  ll time_tmp = clock();
  const double time = static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
  return time;
}
#define saiaku if(time_diff() > 1990)
vector <ll> dp;
vector <ll> H;

void solve(long long N, long long K, std::vector<long long> h){
  if(N<=K) K = N-1;
  dp = vector<ll> (N+1, 0);
  for (ll i = 0; i < K; i++)
  {
    dp[i] = abs(h[i]-h[0]);
  }

  for (ll i = K; i < N; i++)
  {
    vector <ll> d;
    for (ll j = 1; j <= K; j++)
    {
      d.push_back(dp[i-j] + abs(h[i] - h[i-j]));
    }
    dp[i] = *min_element(d.begin(), d.end());
  }
  cout << dp[N-1] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
import math
def do():
    l = 0
    r = 10**9 + 1
    res = 10**10
    while l <= r:
        mid = (l+r) // 2
        if do2(mid) is True: # 作れるなら
            res = min(res, mid)
            r = mid - 1
        else:
            l = mid + 1
    return res


def do2(target):
    res = 0
    if target == 0:
        return False
    t = math.log(target, 2)
    kk = k
    for i in range(n):
        if target >= dat[i]:
            break
        kk -= math.ceil(dat[i] / target) - 1
        if kk < 0:
            return False
    return True

n, k = map(int, input().split())
dat = list(map(lambda x: int(x), input().split()))
dat.sort(reverse=True)
print(do())


Measured memory_bytes: 104664
// AtCoder Beginner Contest 128 - Problem D: equeue (https://atcoder.jp/contests/abc128/tasks/abc128_d)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN { 55 }, MAXK { 105 };
const ll oo { 1LL << 62 };

ll st[MAXN][MAXN][MAXK];    // st[i][j][k] - soma máxima usando o intervalo [i, j] com k operações

ll dp(int i, int j, int k, const vector<ll>& xs)
{
    if (k == 0)
        return 0;

    if (j < i)
        return 0;

    if (st[i][j][k] != -oo)
        return st[i][j][k];

    auto res = max(dp(i + 1, j, k - 1, xs) + xs[i], dp(i, j - 1, k - 1, xs) + xs[j]);
    res = max(0LL, res);

    if (k > 1)
    {
        res = max(res, dp(i + 1, j, k - 2, xs));
        res = max(res, dp(i, j - 1, k - 2, xs));
    }

    st[i][j][k] = res;

    return res;
}

ll solve(int N, int K, const vector<ll>& xs)
{
    for (int i = 0; i <= N; ++i)
        for (int j = 0; j <= N; ++j)
            for (int k = 0; k <= K; ++k)
                st[i][j][k] = -oo;

    return max(0LL, dp(0, N - 1, K, xs));
}

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

    int N, K;
    cin >> N >> K;

    vector<ll> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, K, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
const ll INF = 1LL<<60;
int main() {
  int N, K;
  cin>>N>>K;
  vector<ll> pos, neg;
  REP(i,N) {
    ll x; cin>>x;
    if(x>=0) pos.push_back(x);
    else neg.push_back(-x);
  }
  reverse(neg.begin(), neg.end());
  ll ans = 1LL << 60;
  for(int i = min((int)pos.size(), K) - 1; i>=0; i--) {
    ll cand = pos[i];
    if(i < K-1) {
      cand *= 2;
      int rem = K-i-1;
      if(neg.size() >= rem) {
        cand += neg[rem-1];
      }	else cand = INF;
    }
    ans = min(cand, ans);
    //    cout << "P " << i << " " << cand << " " << ans << endl;               
  }

  for(int i = min((int)neg.size(), K) - 1; i>=0; i--) {
    ll cand = neg[i];
    if(i < K-1) {
      cand *= 2;
      int rem = K-i-1;
      if(pos.size() >= rem) {
        cand += pos[rem-1];
      }	else cand = INF;
    }
    ans = min(cand, ans);
    //    cout << "N " << i << " " << cand << " " << ans << endl;               
  }

  //    cout << "ANswer = ";                                                    
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1656
/**
 *    author:  tourist
 *    created: 12.12.2019 18:53:30       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> x(n);
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> s[i];
  }
  long long ans = 0;
  long long best = (long long) -9e18;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    best = max(best, -sum + x[i]);
    sum += s[i];
    ans = max(ans, sum - x[i] + best);
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

int n, d;

int main()
{
    cin >> d >> n;
    if(n == 100) n = 101;
    while(d--) n *= 100;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
W = [input() for _ in range(N)]

before = [W[0]]
for i in range(1,N) :
    if W[i] in before :
        print("No")
        exit()
    if W[i-1][-2] != W[i][0] :
        print("No")
        exit()
    before.append(W[i])

print("Yes")


Measured memory_bytes: 3060
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e5;
std::vector<std::vector<pair<int, int>>> g;
int n;
int cols[N];

void dfs(int i = 0, int p = -1) {
  for(auto to : g[i]) if(to.first != p) {
    int j = to.first;
    int c = to.second;
    cols[j] = cols[i] ^ c;
    dfs(j, i);
  }
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  g.resize(n);
  for(int i = 0; i < n - 1; i++) {
    int a, b, c; std::cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(b, c&1);
    g[b].emplace_back(a, c&1);
  }
  dfs();
  for(int i = 0; i < n; i++) {
    cout << cols[i] << "\n";
  }
  return 0;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100010;

int n, m;
int p[maxn + 5], q[maxn + 5];

pair<int, int> a[(maxn << 1) + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	REP(i, 0, n) scanf("%d", p + i), a[i] = mp(p[i], 0);
	REP(i, 0, m) scanf("%d", q + i), a[n + i] = mp(q[i], 1);
	sort(a, a + n + m);
	static int cnt[2] = {0};
	memset(cnt, 0, sizeof cnt);
	LL ans = 0;
	REP(i, 0, n + m)
	{
		int tmp = (a[i].y ? n + 1 : m + 1);
		tmp -= cnt[!a[i].y]; 
		ans += (LL)a[i].x * tmp;
		++cnt[a[i].y];
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	ll sum=a*100,su=0;
	rep(i,101){
		rep(j,101){
			rep(k,101){
				rep(l,101){
					ll w=100*a*i+100*b*j;
					ll s=c*k+d*l;
					if(w+s<=f && 100*s<=w*e && su*(w+s)<=s*sum){
						su=s;
						sum=s+w;
					}
				}
			}
		}
	}
	cout << sum << " " << su << endl;
	return 0;
}

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

int main(){
    int m,t,p,r;
    while(cin>>m>>t>>p>>r,m){
        vector<vector<int>> team(t,vector<int>(p,-100));
        for(int i=0;i<r;i++){
            int mm,tt,pp,jj;
            cin>>mm>>tt>>pp>>jj;
            if(!jj)
                team[tt-1][pp-1]=mm+(-(team[tt-1][pp-1]+100))*20;
            else
                team[tt-1][pp-1]--;

        }
        vector<tuple<int,int,int>> rank(t,make_tuple(0,0,0));
        for(int i=0;i<t;i++)
            get<2>(rank[i])=i+1;
        for(int i=0;i<t;i++){
            for(int j=0;j<p;j++)
                if(team[i][j]>=0){
                    get<0>(rank[i])++;
                    get<1>(rank[i])-=team[i][j];
                }


        }
        sort(rank.begin(),rank.end(),greater<tuple<int,int,int>>());
        queue<int> q;
        pair<int,int> pre=make_pair(-1,-1);
        string res="";
        for(int i=0;i<t;i++){
            if(pre==make_pair(get<0>(rank[i]),get<1>(rank[i]))){
                q.push(get<2>(rank[i]));
                continue;
            }
            else{
                if(!res.empty())
                    res+=",";
                int s=q.size();
                for(int j=0;j<s;j++){
                    int a=q.front();
                    if(j!=s-1){
                        res+=to_string(a)+"=";
                        }
                    else
                        res+=to_string(a);

                    q.pop();

                }
                q.push(get<2>(rank[i]));
                pre=make_pair(get<0>(rank[i]),get<1>(rank[i]));
            }

        }
        if(!res.empty() && !q.empty())
            res+=',';
        for(int i=0;!q.empty();i++){
            if(q.size()!=1){
                res+=to_string(q.front())+"=";

            }
            else
                res+=to_string(q.front());
            q.pop();
        }
        cout<<res<<endl;
    }

    return 0;
}

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

using namespace std;

typedef long long	ll;

const int N = int(2e5) + 10;
bool vis[N][2][3];
ll dp[N][2][3];
ll pref[2];
ll suf[2];
ll a[N];
const ll inf = ll(1e18);
int n;

ll solve(int i, int flag, int cnt){
	if(cnt > 2 || (cnt == 2 && (n & 1) == 0)){
		return -inf;
	}

	if(i == n){
		if(n & 1)
			return cnt >= 1 ? 0 : -inf;
		else
			return 0;
	}

	bool &v = vis[i][flag][cnt];
	ll &ans = dp[i][flag][cnt];

	if(v){
		return ans;
	}

	v = true;

	ans = -inf;

	if(flag){
		ans = solve(i + 1, 0, cnt) + a[i];
	}

	ans = max(ans, solve(i + 1, 1, cnt + flag));

	return ans;
}

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

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

	printf("%lld\n", solve(0, 1, 0));	

	return 0;
}

Measured memory_bytes: 31484
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <list>
#include <ctime>
#include <memory.h>
#include <bitset>
#include <climits>

#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define pi 3.141592653589793
#define y1 kjdfshnvoavaofobiopj
using namespace std;

int n, ary[210], ans;

int main(){
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);

cin>>n;
for(int i = 0; i < 2*n; i++)
	cin>>ary[i];
sort(ary, ary+2*n, greater<int>());
for(int i = 1; i < 2*n; i+=2)
	ans += ary[i];
cout<<ans<<endl;

return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int N;
#define MAXN 101
int L[MAXN*2];
int main(){
    cin >> N;
    priority_queue<int> PQ;
    rep(i,2*N){
        int a;
        cin >> a;
        PQ.push(a);
    }
    ll ans = 0;
    rep(i,N){
        int a = PQ.top();PQ.pop();
        int b = PQ.top();PQ.pop();
        ans += min(a,b);
    }
    cout << ans << endl;
    return 0;


}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	int N, M;
	cin >> N >> M;

	vector<Vi> lan(M);
	for (int i = 0; i < N; ++i) {
		int K;
		cin >> K;
		for (int j = 0; j < K; ++j) {
			int L;
			cin >> L;
			--L;
			lan[L].push_back(i);
		}
	}

	vector<Vi> g(N);
	for (int i = 0; i < M; ++i) {
		int len = (int)lan[i].size();
		for (int j = 0; j < len - 1; ++j) {
			g[lan[i][j]].push_back(lan[i][j + 1]);
			g[lan[i][j + 1]].push_back(lan[i][j]);
		}
	}
	
	vector<bool> ok(N);
	int pass = 0;
	queue<int> q;
	q.push(0);
	ok[0] = true;
	while (!q.empty()) {
		int node = q.front();
		q.pop();
		++pass;
		for (const auto& chd : g[node]) {
			if (ok[chd]) continue;
			q.push(chd);
			ok[chd] = true;
		}
	}

	cout << (pass == N ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 8440
#include<stdio.h>
#include<algorithm>
int main()
{
	long long n,a[10000],i,r;
	while(scanf("%lld",&n),n)
	{
		for(i=0;i<n;++i)scanf("%lld",&a[i]);
		std::sort(a,a+n);
		for(i=r=0;i<n;++i)r+=a[i]*(n-i-1);
		printf("%lld\n",r);
	}
}

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

const int mxN=1e5+1;
vector<string>op(mxN);

vector<char>ans;

signed main(){
    int a,b,n;
    cin>>a>>b>>n;
    int tk=min(b,n);
    if(tk==b)
        tk-=1;
    int ans=a*tk;
    ans/=b;
    cout<<ans<<endl;
}

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

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 INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];


void solve(long long N, std::vector<long long> h){
    // 初期化
    for(int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for(int i = 1; i < N; ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[N-1] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#pragma GCC target("avx2")

#include <cstdio>
using namespace std;

constexpr int c_max = 26;
constexpr int D = 365;
constexpr int INF = 1e9;
int c[c_max];
int s[D][c_max];
int best_score[D];
int last[c_max];

inline int calc_score(const int &day, const int schedule[], const int &examining) {
  int ans;
  if (day == 0) ans = s[day][examining];
  else ans = best_score[day - 1] + s[day][examining];
  
  for (int i = 0; i < c_max; i++) {
    if (i == examining) continue;
    ans -= (day - last[i]) * c[i];
  }

  return ans;
}

int main() {
  // input part
  scanf("%*d");

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

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < c_max; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  // end of the input part

  int schedule[D];

  for (int d = 0; d < D; d++) {
    int best = -INF;
    int contest_to_hold = 0;
    for (int type = 0; type < c_max; type++) {
      int score = calc_score(d, schedule, type);
      if (best < score) {
        best = score;
        contest_to_hold = type;
      }
    }
    last[contest_to_hold] = d;
    schedule[d] = contest_to_hold;
  }

  for (const auto &x : schedule) {
    printf("%d\n", x+1);
  }
  return 0;
}

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

int a[4][4], n = 3;
int main(){
	rep(i,3)rep(j,3)scanf("%d", &a[i][j]);
	rep(i,101)rep(j,101)rep(k,101){
		int ans = 0;
		for(int y = 0;y < 3;y++){
			int f = 0;
			if(a[y][0]-i < 0)f = 1;
			if(a[y][1]-j < 0)f = 1;
			if(a[y][2]-k < 0)f = 1;
			if(a[y][0]-i != a[y][1]-j)f = 1;
			if(a[y][1]-j != a[y][2]-k)f = 1;
			if(f)ans = 1;
		}
		if(ans == 0){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  ll k = N/(A+B);
  ll r = N%(A+B);
  ll ans = 0;
  if(r <= A) ans = k*A + r;
  else ans = k*A + A;

  cout << ans << endl;
 }

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

  while(1) {

  int price;
  cin >> price;
  if (price == 0) break;
  int otsuri = 1000 - price;
  int nCoin = 0;
  nCoin += otsuri/500;
    otsuri = otsuri % 500;

  nCoin += otsuri/100;
  otsuri = otsuri % 100;

  nCoin += otsuri/50;
  otsuri = otsuri % 50;

  nCoin += otsuri/10;
  otsuri = otsuri % 10;

    nCoin += otsuri/5;
  otsuri = otsuri % 5;
  nCoin += otsuri;

  cout << nCoin << endl;
}

    }



Measured memory_bytes: 3012
import sys
input = sys.stdin.readline

def ok(s):
    for i in range(len(s)+1):
        for j in range(i, len(s)+1):
            # for k in range(len(s)):
            #     if i <= k and k < j:
            #         print("_", end="")
            #     else:
            #         print(s[k], end="")
            # print(" ", s[:i] + s[j:])
            if s[:i] + s[j:] == "keyence":
                return True
    return False

def main():
    s = input().strip()
    print("YES" if ok(s) else "NO")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    
    int X, A, B;
    cin >> X >> A >> B;
    cout << X - A - (X - A) / B * B << endl;
    
    return 0;
}


Measured memory_bytes: 3564
float a,b,c,d,p=57.29578;main(){for(;~scanf("%f%f%f%f",&a,&b,&c,&d);)a+1&&printf("%.0f\n",6378.1*acos(sin(a/p)*sin(c/p)+cos(a/p)*cos(c/p)*cos(b/p-d/p)));}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a==0)cout << 1 << endl;
  if(b==0)cout << 2 << endl;
  if(c==0)cout << 3 << endl;
  if(d==0)cout << 4 << endl;
  if(e==0)cout << 5 << endl;
}   


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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    if(N % K == 0){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (a,b,c,d) = {
        let t:Vec<i64> =read::<String>().chars().map(|x|  x.to_digit(10).unwrap() as i64).collect();
        (t[0],t[1],t[2],t[3])
    };
    if a + b + c + d == 7 { println!("{}+{}+{}+{}=7",a,b,c,d); return;}
    if a + b + c - d == 7 { println!("{}+{}+{}-{}=7",a,b,c,d); return;}
    if a + b - c + d == 7 { println!("{}+{}-{}+{}=7",a,b,c,d); return;}
    if a + b - c - d == 7 { println!("{}+{}-{}-{}=7",a,b,c,d); return;}
    if a - b - c - d == 7 { println!("{}-{}-{}-{}=7",a,b,c,d); return;}
    if a - b - c + d == 7 { println!("{}-{}-{}+{}=7",a,b,c,d); return;}
    if a - b + c - d == 7 { println!("{}-{}+{}-{}=7",a,b,c,d); return;}
    if a - b + c + d == 7 { println!("{}-{}+{}+{}=7",a,b,c,d); return;}
}

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

count = 0
amount = 0
for i in range(N+1):
    number = str(i)
    for x in number:
        x = int(x)
        amount += x

    if A <= amount <= B:
        number = int(i)
        count += i

    amount = 0

print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	int s = 0;
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
		s = s ^ a.at(i);
	}
	
	for (int i = 0; i < N; i++) {
		b.at(i) = s ^ a.at(i);
		cout << b.at(i) << endl;
	}

}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

bool check(string s){
  int N = s.size();
  int h = N/2;
  bool ok = true;
  if(N%2==1){
    REP(i,h+1){
      if(s[i]!=s[N-1-i]){ ok = false; break;}
    }
  }else{
    REP(i,h+1){
      if(s[i]!=s[N-1-i]){ ok = false; break;}
    }
  }
  return ok;
}

int main(){
  string s; cin>>s;

  bool ok = check(s);
  if(ok){
    int N = s.size();
    int h = N/2;
    string s1,s2;
    s1 = s.substr(0,h );
    s2 = s.substr(h+1,h);
    if(check(s1)==false || check(s2)==false){ ok = false;}
    //cout <<s1 <<"\n"<<s2<<"\n";
  }
  cout << (ok?Liny:Linn);
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int left, right;
    left = 1;
    right = N;
    int L, R;
    for (int i = 0; i < M; i++)
    {
        cin >> L >> R;
        if (left < L)
            left = L;
        if (R < right)
            right = R;
    }
    int ans = right - left + 1;
    ans = (ans > 0)? ans : 0;
    cout << ans << endl;
   	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <cctype>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
	cout << fixed << setprecision(10);

	double a, b, d;
	cin >> a >> b >> d;

	double h = b * sin(d / 180 * M_PI);
	double s = a * h / 2;
	double c = sqrt(a * a + b * b - 2 * a * b * cos(d / 180 * M_PI));
	double l = a + b + c;

	cout << s << endl;
	cout << l << endl;
	cout << h << endl;

	return 0;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  string s;
  int q;
  cin >> s >> q;
  string s1 = "",s2 = "";
  bool rev = true;

  rep(i,q){
    int t; cin >> t;
    if(t==1){
      rev = !rev;
    }else if(t==2){
      int f;
      char c;
      cin >> f >> c;
      if(f==1){
        if(rev) s1.push_back(c);
        else s2.push_back(c);
      }else if(f==2){
        if(rev) s2.push_back(c);
        else s1.push_back(c);
      }
    }
  }

  if(rev){
    reverse(all(s1));
    cout << s1 + s + s2 << endl;
  }else{
    reverse(all(s));
    reverse(all(s2));
    cout << s2 + s + s1 << endl;
  }

}


Measured memory_bytes: 4320
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n)
  {
    ll a;
    cin >> a;
    mp[a]++;
  }
  vector<ll> v;
  for (auto p : mp)
  {
    if (p.second >= 4)
    {
      v.push_back(p.first);
      v.push_back(p.first);
    }
    else if (p.second >= 2)
    {
      v.push_back(p.first);
    }
  }
  v.push_back(0);
  v.push_back(0);
  sort(all(v), greater<ll>());
  cout << v[0] * v[1] << endl;

  return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 


#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000020
#define maxn 200005
#define eps 0.0000001

const ll mod=1e9+7;
const ll inf=1e18+2;

int n,m;
int freq[maxn];
vector<int> mx[maxn];


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	int T=1;
//	cin>>T;

	while(T--)
	{

		cin>>n>>m;

		for(int i=0;i<m+2;i++)
		{
			freq[i]=0;
			mx[i].clear();
		}

		map<int,int> mp;

		for(int i=0;i<n;i++)
		{
			int tmp;
			cin>>tmp;
			freq[tmp%m]++;
			mp[tmp]++;
		}
		for(auto h:mp)
		{
			mx[h.fi%m].pb(h.se);
		}
		for(int i=1;i<m;i++) sort(mx[i].begin(), mx[i].end(), greater<int>());

		int ans=freq[0]/2;

		int lim=m/2;

		if(m%2==0)
		{
			ans+=freq[lim]/2;
			freq[lim]=0;
			lim--;
		}

		for(int i=1;i<=lim;i++)
		{
			int now=min(freq[i],freq[m-i]);
			ans+=now;
			freq[i]-=now;
			freq[m-i]-=now;
		}
		for(int i=1;i<m;i++)
		{
			if(!mx[i].size()) continue;

			int indx=0;
			while(indx<mx[i].size() and freq[i])
			{
				if(mx[i][indx]<=freq[i])
				{
					ans+=mx[i][indx]/2;
					freq[i]-=(mx[i][indx]/2)*2;
				}
				else
				{
					ans+=freq[i]/2;
					break;
				}
				indx++;
			}
		}

		cout<<ans<<'\n';

	}
	

	return 0;
}

Measured memory_bytes: 16392
using System;
class Program
{
	static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');
		int k = int.Parse(input[0]);
		int n = int.Parse(input[1]);
        string[] aaray = Console.ReadLine().Split(' ');

        int[] hikaku = new int[n];
        int saichou = 0;
        int saichoukukan = 0;
        for(int i = 0; i < (n-1); i++){
            int a = int.Parse(aaray[i]);
            int b = int.Parse(aaray[i+1]);
            hikaku[i] = System.Math.Abs(b-a);
            if(hikaku[i]>saichou){
                saichou = hikaku[i];
                saichoukukan = i;
            }
        }
        // 最初と最後の比較
        int aa = int.Parse(aaray[0]);
        int bb = int.Parse(aaray[n-1]);
        int cc = k - bb;
        hikaku[n-1] = aa+cc;
        if(hikaku[n-1]>saichou){
            saichou = hikaku[n-1];
            saichoukukan = n-1;
        }

        int kyori = 0;
        for(int i = 0; i < n; i++){
            if(saichoukukan != i){
                kyori += hikaku[i];
            }
        }

        Console.WriteLine(kyori);
    }
}

Measured memory_bytes: 34652
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

from math import gcd

INF = float('inf')
NIL = - 1

N = int(input())
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N ** 2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        if tmp == 1:
            ans += N 
            continue
        for k in range(1, N + 1):
            if k == 1:
                ans += 1
                continue
            ans += gcd(tmp, k)
print(ans)




Measured memory_bytes: 9532
#include <stdio.h>
#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef unsigned long long ull;

int main(){
    int T, A;
    int N;
    int i;
    ull inT, inA;
    scanf("%d", &N);

    REP(i, N){
        scanf("%d %d", &T, &A);
        if(i == 0){
            inT = T, inA = A;
        }else{
            ull tempA, tempT;
            int f;
            f = inA % A == 0? 0 : 1;
            tempA = (inA/A + f) * A;
            f = inT % T == 0? 0 : 1;
            tempT = (inT/T + f) * T;
            if(tempA/A < tempT/T){
                inT = tempT;
                inA = A * (tempT/T);
            }else{
                inA = tempA;
                inT = T * (tempA/A);
            }
        }
    }
    printf("%llu\n", inA + inT);
    return 0;
}

/*
必ず増加する数字X, Yの比p:qが与えられる.
X以上のpの倍数のうち最小の数字X_pと, Y以上のqの倍数のうち最小の数字Y_qを計算し
X_p/pとY_q/qのうち大きい方を取って,
X = X_p, Y = q/p * X_p
あるいは
X = p/q * Y_q, Y = Y_q
を採用すれば良い.
*/

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,y; cin>>n>>y; y/=1000;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n-i;++j){
			int k=n-i-j;
			if(10*i+5*j+k==y){
				cout<<i<<" "s<<j<<" "s<<k<<"\n"s;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n"s;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

bool cmp1(pii x, pii y) {
    return x.fi < y.fi;
}

bool cmp2(pii x, pii y) {
    return x.se > y.se;
}

int main() {
    int n; cin >> n;
    vector <string> s(n);
    int sum = 0;
    vector <pii> ps, ng;
    FOR(i, 0, n - 1) {
        cin >> s[i];
        pii x = {0, 0};
        for (char j : s[i]) {
            if (j == '(') x.se++;
            else {
                if (x.se) x.se--;
                else x.fi++;
            }
        }
        if (x.fi <= x.se) ps.pb(x);
        else ng.pb(x);
        sum += x.se - x.fi;
    }
    // cout << sum << endl;
    if (sum != 0) return cout << "No\n", 0;
    sort(all(ps), cmp1);
    sort(all(ng), cmp2);
    int cur = 0;
    for (pii x : ps) {
        // cout << x.fi << ' ' << x.se << endl;
        if (cur - x.fi < 0) return cout << "No\n", 0;
        cur += x.se - x.fi;
    }
    for (pii x : ng) {
        // cout << x.fi << ' ' << x.se << ' ' << cur << endl;
        if (cur - x.fi < 0) return cout << "No\n", 0;
        cur += x.se - x.fi;
    }
    cout << "Yes\n";
}

Measured memory_bytes: 42324
N,M = map(int, input().split())
num = []
out = 0

for n in range(N):
    num.append(-1)

for i in range(M):
    s,c = map(int, input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        print(-1)
        exit()

for i in range(N):
    if num[i] == -1:
        num[i] = (1 if N>1 and i == 0 else 0)

if N>1 and num[0] == 0:
    print(-1)
    exit()

for i in range(N):
    out += num[i]*(10**(N-i-1))


print(out)

Measured memory_bytes: 3316
def solve(string):
    n, *abc = map(int, string.split())
    a = sorted(abc[:n], reverse=True)
    b = sorted(abc[n:2 * n], reverse=True)
    c = sorted(abc[2 * n:], reverse=True)
    ab = [0] * n
    j = 0
    for i, _a in enumerate(a):
        while j <= n - 1 and _a < b[j]:
            j += 1
        ab[i] = j
    bc = [0] * (n + 1)
    j = 0
    for i, _b in enumerate(b, start=1):
        while j <= n - 1 and _b < c[j]:
            j += 1
        bc[i] = j

    for i in range(1, len(bc)):
        bc[i] += bc[i - 1]
    return str(sum([bc[_ab] for _ab in ab]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(3)])))


Measured memory_bytes: 41088
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


N = int(input())

sum = 0
for _ in range(N):
    x, u = input().split()
    if u == 'JPY':
        sum += float(x)
    else:
        sum += float(x) * 380000.0

print(sum)


Measured memory_bytes: 2940
n,k = map(int,input().split())
ans = 0

for i in range(k,n+2):
    tmpans = 0
    s1 = (0+i-1)*i//2
    s2 = (n-i+1 + n)*i//2
    tmpans = s2-s1+1
    ans += tmpans
print(max(1,ans%(10**9+7)))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<string> s;
    s.push_back("AC");
    s.push_back("WA");
    s.push_back("TLE");
    s.push_back("RE");
    Vec<i32> C(4);
    for (i32 i = 0; i < N; i++) {
        string S;
        cin >> S;
        if (S == s[0]) C[0]++;
        else if (S == s[1]) C[1]++;
        else if (S == s[2]) C[2]++;
        else if (S == s[3]) C[3]++;
    }
    for (i32 i = 0; i < 4; i++) {
        cout << s[i] << " x " << C[i] << endl;
    }

}


Measured memory_bytes: 3624
from math import sqrt
from functools import reduce
from operator import mul

# 素因数分解
def factoring(n):
    f_list = [0 for _ in range(n + 1)]

    i = 2
    while n != 1:
        if n % i == 0:
            n /= i
            f_list[i] += 1

        else:
            i += 1

    return f_list

# 1 3 5 7 15 21 35 105
# 3 5 7
if __name__ == '__main__':
    n = int(input())
    targets = list(filter(lambda x: x % 2 != 0, range(1, n + 1)))

    count = 0
    for t in targets:
        s = reduce(mul, map(lambda x: x + 1, filter(lambda x: x != 0, factoring(t))), 1)
        if s == 8:
            count += 1

    print(count)


Measured memory_bytes: 3572
def f(n):
    spiral = [list(' ' for i in range(n)) for i in range(n)]
    for i in range(n):
        spiral[i][0] = '#'
    for i in range(n):
        spiral[0][i] = '#'
    for i in range(n):
        spiral[i][-1] = '#'
        
    return spiral
        
def draw(n, m):
    #down
    for w in range(m, n):
        spiral[n-1][w] = '#'
    if n-m == 2:
        return
    #left
    for h in range(m, n):
        spiral[h][m] = '#'
    if n-m == 3:
        return
    #up
    for w in range(m, n-2):
        spiral[m][w] = '#'
    if n-m == 4:
        return
    #right
    for h in range(m, n-2):
        spiral[h][n-3] = '#'
    if n-m == 5:
        return
        
    draw(n-2, m+2)

c = 0
for i in range(input()):
    if c != 0:
        print
    n = input()
    if n == 1:
        spiral = [['#']]
    elif n == 2:
        spiral = [['##'],['# ']]
    elif 3 <= n:
        spiral = f(n)
    if 4 <= n:
        draw(n, 2)
    for line in spiral:
        print ''.join(line)
    c = 1

Measured memory_bytes: 4312
#include<stdio.h>
int main(){
  int a,b,c,x,y;
  long ans;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  if(a+b<=c*2){
    ans=x*a+y*b;
    printf("%ld\n",ans);
    return 0;
  }
  else{
    if(x>y){
      ans=c*y*2;
      if(a>c*2){
        ans+=c*2*(x-y);
      }
      else{
        ans+=a*(x-y);
      }
    }
    else{
      ans=c*x*2;
      if(b>c*2){
        ans+=c*2*(y-x);
      }
      else{
        ans+=b*(y-x);
      }
    }
    printf("%ld\n",ans);
    return 0;
  }
}


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

int main() {
  int N = 0;
  long long ans = 1;
  long long MOD = pow(10, 9) + 7;
  cin >> N;
  rep(n, N){
    ans *= n+1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256