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

using namespace std;

const int inf = 999999;

int main()
{
  int n, m, s, t, u, a[101][101], p, q, v;
  
  while(cin>>n>>m>>s>>t>>u && n){
    fill(&a[0][0], &a[100][100], inf);
    for(int i = 0; i <= n; i++)
      a[i][i] = 0;
    
    while(m--){
      cin >> p >> q;
      cin >> a[p][q];
    }
    
    for(int k = 1; k <= n; k++)
      for(int i = 1; i <= n; i++)
	for(int j = 1; j <= n; j++)
	  a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
    
    m = inf;
    for(int i = 1; i <= n; i++)
      m = min(m, a[s][i]+a[i][t]+a[i][u]);
    
    cout << m << endl;
  }
  
  return 0;
}

Measured memory_bytes: 0
def divs(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            x,y = i, n//i
            divisors.append([x,y])
    return divisors

N = int(input())
div = divs(N)
x,y = div[-1]
print(max(len(str(x)),len(str(y))))

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

signed main(){
    int N;cin>>N;
    int ans=0;
    vector<int> A(N);
    REP(i, N){ 
        cin >> A[i];
    }
    REP(i,N-1){
        if(A[i]&1){ 
            if(A[i+1]!=0){ 
                ans++;
                A[i]--;A[i+1]--;
            }
        }
    }
    //REP(i,N) cout<<A[i]<<" \n"[i==N-1];
    REP(i,N) ans+=A[i]/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] x = new long[N];
        long[] y = new long[N];
        long[] h = new long[N];
        long H = 0;
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            h[i] = sc.nextLong();
        }
        for (int cx = 0; cx <= 100; cx++) {
            for (int cy = 0; cy <= 100; cy++) {
                long needH = -1;
                for (int i = 0; i < N; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    long tmp = h[i] + Math.abs(cx - x[i]) + Math.abs(cy - y[i]);
                    if (needH == -1) {
                        needH = tmp;
                    } else {
                        if (needH != tmp) {
                            needH = -2;
                            break;
                        }
                    }
                }
                if (needH == -2) {
                    continue;
                }
                for (int i = 0; i < N; i++) {
                    if (h[i] != 0) {
                        continue;
                    }
                    long dist = Math.abs(cx - x[i]) + Math.abs(cy - y[i]);
                    if (needH > dist) {
                        needH = -2;
                        break;
                    }
                }
                if (needH == -2) {
                    continue;
                }
                System.out.println(cx + " " + cy + " " + needH);
                return;
            }
        }
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int n,m,p;

void drop(const int x,const int y,const int turn,vector<vector<vector<int>>> &block){
    for(int i=0;i<n;i++){
        if(block[x][y][i]==0){
            block[x][y][i]=turn;
            return;
        }

    }
}

bool isrange(int x,int y,int z){
    return 0<=x && x<n && 0<=y && y<n && 0<=z && z<n;
}

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

bool win(const int turn,const vector<vector<vector<int>>> &block){
    bool wined=false;
    for(int i=0;i<13;i++){
        for(int x=0;x<n;x++){
            for(int y=0;y<n;y++){
                for(int z=0;z<n;z++){
                    if(block[x][y][z]==turn){
                        int cnt=1;
                        for(int r=1;;r++){
                            int xx=x+dx[i]*r;
                            int yy=y+dy[i]*r;
                            int zz=z+dz[i]*r;
                            if(isrange(xx,yy,zz) && block[xx][yy][zz]==turn){
                                cnt++;
                            }
                            else{break;}
                        }
                        for(int r=1;;r++){
                            int xx=x-dx[i]*r;
                            int yy=y-dy[i]*r;
                            int zz=z-dz[i]*r;
                            if(isrange(xx,yy,zz) && block[xx][yy][zz]==turn){
                                cnt++;
                            }
                            else{break;}

                        }
                        if(cnt>=m){
                            wined=true;
                        }
                    }

                }

            }
        }
    }
    return wined;
}

int main(){
    while(cin>>n>>m>>p,n){
        vector<vector<vector<int>>> block(n,vector<vector<int>>(n,vector<int>(n,0)));
        int finished=0;
        int res=-1;
        for(int i=0;i<p;i++){
            int turn=((i+1)%2)*2-1;
            int x,y;
            cin>>x>>y;
            x--,y--;
            if(finished) continue;
            drop(x,y,turn,block);
            if(win(turn,block)){
                finished=turn;
                res=i+1;
            }
        }
        if(finished==0) cout<<"Draw"<<endl;
        else if(finished==1) cout<<"Black "<<res<<endl;
        else cout<<"White "<<res<<endl;
    }

}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define pb push_back
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int mod = 1e9 + 7;
 
ll S, mul = 9, cnt, ans;
int pref[15000005];
bool ck[100000005];
 
ll binpw(ll base, ll pw){
	ll ans = 1;
	while(pw){
		if(pw & 1) ans = (ans * base) % mod;
		base = (base * base) % mod;
		pw >>= 1;
	}
	return ans;
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin >> S;
	ck[0] = 1;
	for(int i = 1; i <= 7; i++){
		for(int j = 1; j <= mul; j++){
			++cnt;
			pref[cnt] = pref[cnt - 1] + i;
			ans += (pref[cnt] >= S && ck[pref[cnt] - S]);
			ck[pref[cnt]] = 1;
		}
		mul *= 10;
	}
	//cout << "OK\n";
	int pos = -1;
	int temp = pref[cnt];
	for(int i = 1; temp <= (S + 100000000); i++){
		temp += 8;
		ans += (temp >= S && ck[temp - S]);
	}
	//cout << ans << "\n";
	for(int i = (S - 1) / 8; i >= 1; i--){
		if(!(S % i)){
			ll tmp = S / i, tmp2 = binpw(10, tmp - 1) * 9;
			//cout << tmp << " " << tmp2 % mod << "\n";
			//if(tmp2 < i) continue;
			//cout << ans << " " << tmp2 << "\n";
			ans = (ans + tmp2 - i + 1 + mod) % mod;
		}
		else{
			ans++;
			if(ans >= mod) ans -= mod;
		}
	}
	if(!(S % 8)){
		ans += 90000000 - S / 8;
		//cout << 90000000 - S / 8 + 1 << "\n";
		//if(ans >= mod) ans -= mod;
		if(ans >= mod) ans -= mod;
	}
	cout << ans;
}

Measured memory_bytes: 109992
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
	int a[]={111,222,333,444,555,666,777,888,999};
	int n;
	cin>>n;
	for(int i=0;i<9;i++)
		if(a[i]>=n)
		{
			printf("%d\n",a[i]);
			break;
		}	
	return 0;
}

Measured memory_bytes: 256
A[9999],B[9999];z(int*a,int*b){return*b-*a;}
main(n,m,i,j){for(;scanf("%d",&n),m=n+n;puts(i>n?"No":"Yes")){
for(i=0;i<n;i++)scanf("%d",A+i);
for(i=0;i<n;i++)scanf("%d",B+i);
for(i=qsort(A,n,4,z);i<n;A[i++]?i=n+1:1)for(j=0;j<n;j++)if(B[j])A[i]--,B[j]--;
}exit(0);}

Measured memory_bytes: 736
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  get(N);
  vector<ll> A(N);
  FOR(i, N) cin >> A[i];
  ll a = 0;
  FOR(i, N) {
    if (i % 2 == 0) {
      a += A[i] * 2;
    } else {
      a -= A[i] * 2;
    }
  }
  a /= 2;
  cout << a << " ";
  FORIN(i, 1, N) {
    a = (A[i - 1] - a / 2) * 2;
    if (i < N - 1) {
      cout << a << " ";
    } else {
      cout << a << endl;
    }
  }
  return 0;
}

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

using namespace std;

using int64 = long long;

int main()
{
  int N, A[10000], B[10000];

  cin >> N;
  int64 latte = 0, malta = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    latte += A[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
    malta += B[i];
  }

  int64 add = 0;
  for(int i = 0; i < N; i++) {
    add += (max(B[i] - A[i], 0) + 1) / 2;
  }

  if(malta - latte < 0 || add > malta - latte) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

}



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

int main() {
  int n;
  cin >> n;
  map<string,int> mp;
  for(int i=1;i <= n;i++) {
    string s = to_string(i);
    char first = s[0];
    char second = s[s.length() - 1];
    s.clear();
    s += first;
    s += second;
    mp[s]++;
  }
  long long ans = 0;
  for(pair<string,int> p : mp) {
    string s = p.first;
    int freq = p.second;
    if(s[0] == s[1]) {
      ans += (long long) freq * freq;
    }
    else {
      swap(s[0],s[1]);
      ans += (long long) freq * mp[s];
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main()
{
    int n,t;
    cin >> n >> t;
    int mi = INF;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        if(b <= t) mi = min(mi,a);
    }
    if(mi == INF) cout << "TLE" << endl;
    else cout << mi << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n = 0;
		String[] conv = new String[123];

		while ((line = br.readLine()) != null) {
			if (n == 0) {
				if ((n = Integer.parseInt(line)) == 0)
					break;
			} else {
				if (line.contains(" ")) {
					conv[line.charAt(0)] = line.substring(2);
				} else {
					if (conv[line.charAt(0)] != null)
						System.out.print(conv[line.charAt(0)]);
					else
						System.out.print(line);
				}
				n--;
				if (n == 0 && line.length() == 1) {
					System.out.println();
					conv = new String[123];
				}
			}
		}
	}
}

Measured memory_bytes: 36100
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    string s;
    in>>s;
    int n=s.length();
    string t=s,u,v;
    u=v=s.substr(0,n/2);
    reverse(t.begin(),t.end());
    reverse(v.begin(),v.end());
    puts(u==v&&s==t?"Yes":"No");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
int main(){
    cout.precision(30);
    long double a,b,c;
    cin >> a >> b >> c;
    if(c - a - b<0){
        cout << "No" << endl;
    }else{
        if(4*a*b<(c - a - b)*(c - a - b)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
from collections import deque

n, s, t = map(int, input().split(' '))
s -= 1
t -= 1

v = [[] for i in range(n)]
f = [0]*n

for i in range(n-1):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    f[a] += 1
    f[b] += 1
for i in range(n):
    if f[i] == 0:
        l.append(i)
depth = [-1]*n
depth[t] = 0
q = deque([t])
while q:
    x = q.popleft()
    for y in v[x]:
        if depth[y] < 0:
            depth[y] = depth[x]+1
            q.append(y)
l = depth[:]
d = [-1]*n
d[s] = 0
q = deque([s])
while q:
    x = q.popleft()
    for y in v[x]:
        if d[y] < 0:
            d[y] = d[x]+1
            q.append(y)
l = sorted(range(n), key=lambda x:-depth[x])
for i in l:
    if d[i] < depth[i]:
        break
print(depth[i] - 1)



Measured memory_bytes: 39688
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;
//abc170
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    //V<P> p(n);
    map<ll,ll> mp;
    set<ll> st;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
        st.insert(a[i]);
    }
    //sort(all(a));
    ll ans=n;
    for(auto p:mp){
        if(p.sc>1) ans-=p.sc;
        else{
            if(p.ft!=1){
            bool ok=0;
            ll v=p.ft;
            for(ll i=1;i*i<=p.ft;i++){
                if(v%i==0){
                    if(st.count(i)){
                        ok=1;
                        break;
                    }
                    if(v/i!=i&&i!=1){
                        ll u=v/i;
                        if(st.count(u)){
                            ok=1;
                            break;
                        }
                    }
                }
            }if(ok) ans--;
            }
            
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 26628
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>

using namespace std;

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

vector<int> get;
int main(){
  while(1){
  int n,m;
  cin>>n>>m;
  if(n==0)break;
  get.clear();
  vector<int> dat;
  dat.push_back(0);
  rep(i,n){
    int a;
    cin>>a;
    dat.push_back(a);
  }
  n++;

  rep(j,dat.size()){
    for(int k=0;k<dat.size();k++){
      get.push_back(dat[j]+dat[k]);
    }
  }
  sort(get.begin(),get.end());

  int ans=0;
  /*  rep(j,get.size()){
    printf("%d\n",get[j]);
    }puts("");*/
  rep(i,get.size()){
    if(m-get[i]<0)continue;
    int t=*(upper_bound(get.begin(),get.end(),m-get[i])-1);
    ans=max(ans,t+get[i]);
  }
  printf("%d\n",ans);
}
}

Measured memory_bytes: 4956
#include<cstdio>
int main()
{
	int Prnum,Drnum,T1[105],T2,Drtype;
	while(scanf("%d",&Prnum)!=EOF){
		int sum = 0;
		int change;
		for(int i = 0; i < Prnum; i++){
			scanf("%d",&T1[i]);
			sum+=T1[i];
		}
		scanf("%d",&Drnum);
			for(int i = 0; i < Drnum; i++){
				scanf("%d %d",&Drtype,&T2);
				change = T1[Drtype-1] - T2;
				printf("%d\n",sum-change);
			}
		
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
    int n,d;cin >> n >> d;
    int a[d][n];
    for(int i = 0;i<n;i++){
        for(int j = 0;j<d;j++){
            cin >> a[j][i];
        }
    }
    int ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            double sum = 0;
            for(int k = 0;k<d;k++){
                sum += (a[k][i] - a[k][j])*(a[k][i] - a[k][j]);
            }
            sum = sqrt(sum);
            //cout << sum << endl;
            int ue = ceil(sum);
            int uc = floor(sum);
            if(ue == uc) ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0) (__VA_ARGS__)
#define rep_0(i, end) for (int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for (int i = (fr); i <= (ba); ++i)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

bool same (const std::vector<int>& X, const std::vector<int>& Y) {
  rep (i, X.size()) {
    if (X[i] != Y[i]) return false;
  }
  return true;
}

int main() {

  int N;
  std::cin >> N;
  std::vector<int> A(N), P(N), Q(N);
  std::iota(all(A), 1);
  rep (i, N) std::cin >> P[i];
  rep (i, N) std::cin >> Q[i];

  int p, q, now = 0;
  do {
    if (same(A, P)) p = now;
    if (same(A, Q)) q = now;
    ++now;
  } while (std::next_permutation(all(A)));

  std::cout << std::abs(p - q) << '\n';
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int s[9];
    fill(s, s + 9, 0);
    REP(i, n)
    {

        int a;
        cin >> a;
        if (a <= 3199)
        {
            s[a / 400]++;
        }
        else
        {
            s[8]++;
        }
    }
    long long minv = 0;
    long long maxv = 0;
    REP(i, 8)
    {
        if (s[i] > 0)
        {
            minv++;
            maxv++;
        }
    }
    if (s[8] > 0)
    {
        minv = max(minv, 1LL);
        maxv += s[8];
    }
    cout << minv << " " << maxv << endl;
}

Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long p[110000];
long long q[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%lld%lld",p+i,q+i);
	}
	long long left=0;
	long long right=inf*2;
	while(left+1<right){
		long long M=(left+right)/2;
		long long cur=0;
		for(int i=0;i<a;i++){
			if(p[i]>M)continue;
			cur+=(M-p[i])/q[i]+1;
			if(cur>=b)break;
		}
		if(cur>=b){
			right=M;
		}else left=M;
	}
	printf("%lld\n",right);
}

Measured memory_bytes: 1792
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    inf=1000
    h,w=MI()
    ss=[[c=="#" for c in input()] for _ in range(h)]
    mx=0
    for si in range(h):
        for sj in range(w):
            if ss[si][sj]:continue
            bfs={}
            bfs[si,sj]=0
            vis=[[False]*w for _ in range(h)]
            vis[si][sj]=True
            while bfs:
                nxt={}
                for (i,j),d in bfs.items():
                    if d>mx:mx=d
                    for ni, nj in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:
                        if ni<0 or nj<0 or ni>=h or nj>=w:continue
                        if ss[ni][nj]:continue
                        if vis[ni][nj]:continue
                        vis[ni][nj]=True
                        nxt[ni,nj]=d+1
                bfs=nxt
    print(mx)

main()

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int sum = a + b + c;
  int m = max(a, max(b,c));
  if(2*m == sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

// ############################################################################################

#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define FORE(i, a, n) for (i = (a); i < (int)(n); ++i)
#define Size(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<long double, long double>

#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >

#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

#define mod 1000000007
#define inf 1e18

#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// ############################################################################################

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2) res = (res * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return res % mod;
}

void a_k_s() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
}

int n;
double prob[3005], dp[3005][1505];

double solve(int i, int h) {
    // Base Case
    if (h == 0)
        return 1;
    if (i == 0)
        return 0;

    // Look Up
    if (dp[i][h] != -1) {
        return dp[i][h];
    }

    // Recursive Case
    double op1 = prob[i] * solve(i - 1, h - 1);
    double op2 = (1 - prob[i]) * solve(i - 1, h);

    return dp[i][h] = op1 + op2;
}

int main() {
    a_k_s();

    FOR(i, 0, 3005) {
        FOR(j, 0, 1505) {
            dp[i][j] = -1;
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }

    cin >> n;
    FOR(i, 1, n + 1) {
        cin >> prob[i];
    }

    cout << fixed << setprecision(10) << solve(n, (n + 1) / 2) << endl;

    return 0;
}

Measured memory_bytes: 39328
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int a, b;
	cin >> a >> b;
	if(a%2 != b%2) cout << (a+b+1)/2 << endl;
	else cout << (a+b)/2 << endl;
	return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t; cin>>s>>t;
    int a, b; cin>>a>>b;
    string u; cin>>u;
    if(s==u) a--;
    if(t==u) b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		Arrays.sort(a);
		
		int res = 0;
		
		for(int i = 0; i < n-1; i++) {
			if(a[i]<= x) {
				x-=a[i];
				res++;
			}else{
				break;
			}
		}
		
		if( x == a[a.length-1]) {
			res++;
		}
		
		System.out.println(res);
	}
}


Measured memory_bytes: 22996
I=lambda:map(int,input().split())
N,M=I()
H=[0]+list(I())
O=[0]+[1]*N
for _ in range(M):
    A,B=I()
    if H[A]<=H[B]:O[A]=0
    if H[A]>=H[B]:O[B]=0
print(sum(O))

Measured memory_bytes: 20104
MAX_T = int(1e5)
N, C = map(int, input().split())
s, t, c = [], [], []
for i in range(N):
    _s, _t, _c = map(int, input().split())
    s.append(_s)
    t.append(_t)
    c.append(_c-1)

chs = [[0] * (MAX_T + 1) for i in range(C)]
for i in range(N):
    chs[c[i]][s[i]] += 1
    chs[c[i]][t[i]] -= 1

ups = [0] * (MAX_T + 1)
downs = [0] * (MAX_T + 1)
for i in range(MAX_T):
    ups[i] = sum([chs[j][i] for j in range(C) if chs[j][i] > 0])
    downs[i] = sum([-chs[j][i] for j in range(C) if chs[j][i] < 0])

ans = 0
cur = 0
for i in range(MAX_T+1):
    cur += ups[i]
    ans = max((ans, cur))
    cur -= downs[i]

print(ans)


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,A=0;
  cin >> N >> X;
  
  vector<int> M(N);
  for(int i=0; i<N; i++) {
    cin >> M.at(i);
    X -= M.at(i);
    A++;
  }
  if(X > 0 ) {
    sort(M.begin(),M.end());
    while( X >= M.at(0) ) {
      A++;
      X -= M.at(0);
    }
  }

  cout << A << endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return (is);
}

constexpr int MAX = 3010000;
constexpr int MOD = 1000000007;

//Please set MAX and MOD!!========================================

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(int n, int k) {
	if (n < k || n < 0 || k < 0) return (0);
	return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}

int main() {
	ll r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	
	ll sum = 0;
	COMinit();
	for (int i = r1 + 1; i <= r2 + 1; i++) {
		(sum += COM(i + c2, i)) %= mod;
		(sum += (mod - COM(i + c1 - 1, i))) %= mod;
	}
	cout << sum << endl;

	return (0);
}


Measured memory_bytes: 70912
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define REPR(i, x, n) for(int i = n - 1 ; i >= x ; i--)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) REPR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ll も int も longlongにしてしまう
    #define int long long

	int N; cin >> N;

    int count = 0;
    int s = 11;
    while (count != N) {
        bool ok = true;
        int last = sqrt(s);
        while (last != 1) {
            if (s % last == 0) {
                ok = false; 
                break;
            } 
            last--;
        }
        if (ok) {
            count++;
            cout << s;
            if (count == N) cout << endl;
            else cout << " ";
        }
        s += 5;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  
  int p[n];
  for(int i=0; i<n; i++){
    cin>>p[i];
  }
  
  int ans=0;
  
  for(int i=1; i<n-1; i++){
    vector<int> x(3);
    for(int j=0; j<3; j++){
      x[j]=p[i+j-1];
    }
    sort(x.begin(), x.end());
    if(x[1]==p[i]){
      ans++;
    }
  }
  
  cout<<ans<<endl;
  
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 H, W;
	cin >> H >> W;
	vector<string> f(H);
	REP(i, H) {
	  cin >> f[i];
	}
	auto d = make_v<int64>(H, W);
	fill_v<int64>(d, INF_LL);
	d[0][0] = (f[0][0] == '#');
	REP(i, H) {
	  REP(j, W) {
	    if (i+1 < H) chmin(d[i+1][j], d[i][j] + (f[i+1][j] == '#' && f[i][j] != '#'));
      if (j+1 < W) chmin(d[i][j+1], d[i][j] + (f[i][j+1] == '#' && f[i][j] != '#'));
	  }
	}
	cout << d[H-1][W-1] << endl;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

ll pow_mod(ll n, ll m, ll mod=1000000007){
    ll a = 1;
    while(m>0){
        if(m&1) a = a*n % mod;
        n = n*n % mod;
        m >>= 1;
    }
    return a;
}

ll combi(ll n, ll m, ll mod=1000000007){
    static const ll N_MAX = 200000;
    static vll fac(N_MAX+1, -1);
    static vll ifac(N_MAX+1, -1);

    if(fac[0]<0){
        fac[0] = ifac[0] = 1;
        rep(i, N_MAX){
            fac[i+1] = fac[i] * (i+1) % mod;
            ifac[i+1] = ifac[i] * pow_mod(i+1, mod-2, mod) % mod;
        }
    }

    if(n<=0 && m<=0) return 1;
    if(n<m || n<0) return 0;
    return (ifac[n-m] * ifac[m] % mod) * fac[n] % mod;
}

int main(){
    cout << setprecision(20);
    ll n, m, k;
    cin >> n >> m >> k;

    ll count = 0;
    REP(d, 1, n){
        ll a = d * (n-d) * m * m % 1000000007;
        a = a * combi(n*m-2, k-2) % 1000000007;
        count = (count+a) % 1000000007;
    }
    REP(d, 1, m){
        ll a = d * (m-d) * n * n % 1000000007;
        a = a * combi(n*m-2, k-2) % 1000000007;
        count = (count+a) % 1000000007;
    }

    cout << count << endl;
}



Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

struct WS{
  vvl d = vv(0, 0, 0, ll);
  ll N;
  WS(ll n){
    N = n;
    d.resize(n+1, vll (n+1, 10000000000));
    init();
  }
  void init(){
    re(i, N+1) d[i][i] = 0;
  }
  void insert(ll a, ll b, ll c){
    d[a][b] = min(d[a][b], c);
  }
  void warshall(){
    init();
    re(i, N+1) re(s, N+1) re(t, N+1) d[s][t]=min(d[s][t],d[s][i]+d[i][t]);
  }
};
int main(int argc, char const *argv[]) {
  ll h, w, t;std::cin >> h >> w;
  WS ws(10*10);
  re(i, 10){
     re(j, 10){
       std::cin >> t;
       ws.insert(i, j, t);
     }
  }
  ws.warshall();
  ll ans = 0;
  re(i, h) {
    re(j, w){
      std::cin >> t;
      if(t==-1) continue;
      ans += ws.d[t][1];
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
def matrixChainMultiplication():
    for i in range(1, n+1):
        m[i][i] = 0

    for l in range(2, n+1):
        for i in range(1, n-l+2):
            j = i + l - 1
            m[i][j] = INF
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j])
    return m[1][n]

if __name__ == "__main__":
    INF = 10000000000000
    p = []
    n = int(input())
    m = [[None] * (n+1) for i in range(n+1)]
    for i in range(n):
        inp = list(map(int, input().split()))
        if i == 0:
            p.append(inp[0])
            p.append(inp[1])
        else:
            p.append(inp[1])
    print(matrixChainMultiplication())

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

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define P 1000000007

#define NN 100010

ll F[NN], IF[NN];
void gcd(int a,int b,int &x,int &y) {
  if(b==0){x=1,y=0;return;}
  gcd(b,a%b,y,x),y-=a/b*x;
}
int inv(int n) {
  int x,y;gcd(n,P,x,y);
  if(x<0)x+=P;return x;
}

ll cc(int n, int m) {
	//printf ("%d %d\n", n, m);
	if (m < 0) return 0;
	if (m > n) return 0;
	return (ll) F[n] * IF[m] %P * IF[n-m]%P;
}

ll ff(int m, int k) {
	if (k == 0) {
		if (m == 0) return 1;
		return 0;
	}
	return cc(m+k-1, k-1);
}

int main () {
	F[0]=1;for(int i=1;i<NN;i++)F[i]=(ll)F[i-1]*i%P;
	IF[NN-1]=inv(F[NN-1]);for(int i=NN-1;i;i--)IF[i-1]=(ll)IF[i]*i%P;
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	if (B&1) {
		puts ("0");
		return 0;
	}
	ll S = 0;
	for (int j = 0; j*3 <= C; j++) {
		C -= 3*j;
		for (int i = 0; i <= C; i ++) {
			if (A-(C-i) < 0) continue;
			ll T = ff(i, B/2);
			// C-i : 31
			T = (ll)T*ff(C-i, B/2+1)%P;
			// A-(C-i) : 1
			T = (ll)T*ff(A-(C-i), B/2 + (C-i) + 1)%P;
			
			T = (ll)T*ff(j, B/2 + A + 1)%P;
			(S += T) %= P;
		}
		C += 3*j;
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int result = Math.max(c - (a - b), 0);

        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int V[100005];
int main(){
    int n;
    cin >> n;
    ll temp=0;
    rep(i,n){
        int a;
        cin >> a;
        V[a]++;
        temp+=a;
    }
    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b>> c;
        int k=V[b];
        V[b]=0;
        V[c]+=k;
        temp+=c*k-b*k;
        cout<<temp<<endl;
    }
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n;
    cin >> n;
    ll ara[n];
    ll mm = -1, mn = 1000;
    for(ll i =0; i < n; i++)
    {

        cin >> ara[i];
        mm = max(mm, ara[i]);
        mn = min(mn, ara[i]);
    }
    ll ans = inf;
    for(ll i = mn; i <= mm; i++)
    {

        ll xx = 0;
        for(ll j = 0; j < n; j++)
        {

            xx += (ara[j]-i)*(ara[j]-i);
        }
        ans=min(ans,xx);
    }
    cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int fact(int n) {
        if (n == 0)
            return 1;

        return n * fact(n - 1);
    }
    int calculateRank(String s){

        int rank = 1;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1 ; j < s.length(); j++) {
                if (s.charAt(i) > s.charAt(j)) {
//                    System.out.println(str.charAt(j));
                    rank = rank + fact(s.length() - (i + 1));
                }
            }
        }
        return rank;
    }

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

        int N= sc.nextInt();
        String P=new String();
        String Q=new String();

        for(int i=0;i<N;i++){
            P=P+sc.next();
        }


        for(int i=0;i<N;i++){
            Q=Q+sc.next();
        }
//        System.out.println("p:"+P);
//        System.out.println("q:"+Q);

        Main obj=new Main();

        int j;
        j=obj.calculateRank(P);
        int k;
        k= obj.calculateRank(Q);
        int q=j-k;
        if (q <0)
            q=-1 * q;
        System.out.println(q);

    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

ll n;
ll x[55], y[55];
typedef long double ld;
ld ans;

void f(ld p, ld q)
{
    ld ans2 = 0;
    for(ll i = 0; i < n; i++)
    {
        ans2 = max(ans2, (x[i] - p) * (x[i] - p) + (y[i] - q) * (y[i] - q));
    }
    ans = min(ans, ans2);
}

int main()
{
    ans = 1000000;
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &x[i], &y[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            if(i == j) continue;
            f((ld)(x[i] + x[j]) / 2, (ld)(y[i] + y[j]) / 2);
            for(ll k = 0; k < n; k++)
            {
                if(j == k || k == i) continue;
                if(x[i] * y[j] + x[j] * y[k] + x[k] * y[i] == x[k] * y[j] + x[i] * y[k] + x[j] * y[i]) continue;
                ld a1 = (ld)(x[i] - x[j]) / (y[j] - y[i]);
                ld b1 = (ld)(y[i] + y[j]) / 2 - 1.0 * (x[i] * x[i] - x[j] * x[j]) / (y[j] - y[i]) / 2;
                ld a2 = (ld)(x[k] - x[j]) / (y[j] - y[k]);
                ld b2 = (ld)(y[k] + y[j]) / 2 - 1.0 * (x[k] * x[k] - x[j] * x[j]) / (y[j] - y[k]) / 2;
//                if(y[j] == y[i]) f((ld)(x[i] + x[j]) / 2.0, (ld)a2 * (x[i] + x[j]) / 2.0 + b2);
//                else if(y[k] == y[j]) f((ld)(x[k] + x[j]) / 2.0, (ld)a1 * (x[j] + x[k]) / 2.0 + b1);
//                else f((b1 - b2) / (a2 - a1), (a2 * b1 - b2 * a1) / (a2 - a1));
                if(y[i] != y[j] && y[j] != y[k]) f((b1 - b2) / (a2 - a1), (a2 * b1 - b2 * a1) / (a2 - a1));
            }
        }
    }
    printf("%.16Lf", sqrt(ans));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int p,q;

    while(cin >> p >> q) {
        vector<int> v,m;
        int last = 0;

        p %= q;
        m.push_back(p);
        p *= 10;

        while(true) {

            v.push_back(p/q);
            last = p%q;

            if(last == 0) break;
            if(find(m.begin(),m.end(),last) != m.end()) break;

            m.push_back(last);
            p = last;
            p *= 10;
        }

        rep(i,v.size()) cout << v[i];
        cout << endl;

        if(last == 0) continue;

        bool flag = false;
        rep(i,v.size()) {
            if(m[i] == last) flag = true;

            if(flag) cout << "^";
            else cout << " ";
        }
        cout << endl;

    }

    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int v[N];
int dp[N];
int n, k;
int f(int i){
    if(i == n - 1)return 0;
    int &ans = dp[i];
    if(ans == -1){
        ans = 1e9;
        for(int j = 1; j <= k; j++)
            if(i + j < n)
                ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));
            else
                break;
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n >> k;
    fore(i, 0, n)cin >> v[i];
    cls(dp, -1);
    cout << f(0) << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 10792