akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split(' '))
s = [''] * h
l = [[0] * w] * h
r = [[0] * w] * h
u = [[0] * w] * h
d = [[0] * w] * h


for i in range(h):
  s[i] = input()
  l[i] = [0] * w
  r[i] = [0] * w
  u[i] = [0] * w
  d[i] = [0] * w
# print(h, w)
# print(s)
# print(l, r, u, d)

for i in range(h):
  for j in range(w):
    c = s[i][j]
    
    if c == '#':
      l[i][j] = 0
    else:
      if j == 0:
        l[i][j] = 1
      else:
        l[i][j] = l[i][j-1] + 1

for i in range(h):
  for j in range(w-1, -1, -1):
    c = s[i][j]
    
    if c == '#':
      r[i][j] = 0
    else:
      if j == (w-1):
        r[i][j] = 1
      else:
        r[i][j] = r[i][j+1] + 1

for j in range(w):
  for i in range(h):
    c = s[i][j]
    
    if c == '#':
      u[i][j] = 0
    else:
      if i == 0:
        u[i][j] = 1
      else:
        u[i][j] = u[i-1][j] + 1

for j in range(w):
  for i in range(h-1, -1, -1):
    c = s[i][j]
    
    if c == '#':
      u[i][j] = 0
    else:
      if i == (h-1):
        d[i][j] = 1
      else:
        d[i][j] = d[i+1][j] + 1
# print(l)
# print(r)
# print(u)
# print(d)

ans = 0

for i in range(h):
  for j in range(w):
    total = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
    if ans < total:
      ans = total

print(ans)

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

using namespace std;

int main()
{
    long N, Sum, a = 0;
    cin >> N;

    for (int i = 1; i <= 100000; i++)
    {
        Sum = i * i;

        if (Sum <= N)
        {
            a++;
        }

        if (Sum > N)
        {
            break;
        }
    }

    cout << a * a;
}

Measured memory_bytes: 256
def solve(N, X, D):
    if D == 0:
        if X == 0:
            return 1
        return N+1
    L = {0: [(0, 1), (1, -1)]}
    coef_l = 0
    coef_r = 1
    for coef_x in range(1, N+1):
        m = X * coef_x % D
        l = X * coef_x // D + coef_l
        r = X * coef_x // D + coef_x * N - coef_r
        coef_l = coef_r
        coef_r += coef_x + 1
        if m not in L:
            L[m] = []
        L[m].append((l, 1))
        L[m].append((r+1, -1))
    ans = 0
    #print(L)
    for Q in L.values():
        Q.sort()
        cnt = 0
        last = None
        for val, sign in Q:
            if cnt > 0:
                ans += val - last
            cnt += sign
            last = val
    return ans

N, X, D = map(int, input().split())
print(solve(N, X, D))


Measured memory_bytes: 88016
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
vector<P>v[100001];
vector<int> dp[10001];
int get(string x){
  int res=0;
  r(i,x.size())res=res*10+(x[i]-'0');
  return res;
}
int dist(P a,P b){
  return abs(a.first-b.first)+abs(a.second-b.second);
}
string s;
int e,w,h;
int main(){
  while(cin>>w>>h,h){
    r(i,100001)v[i].clear();
    r(i,10001)dp[i].clear();
    P t;
    r(i,h)r(j,w){
      cin>>s;
      if(s=="G")t=P(i,j);
      if(s=="S")v[0].push_back(P(i,j));
      if(isdigit(s[0])){
        int x=get(s);
        v[x].push_back(P(i,j));
        dp[x].push_back(1e9);
      }
    }
    r(i,99999)if(v[i].size()==0){
      v[i].push_back(t);
      dp[i].push_back(1e9);
      e=i;
      break;
    }
    dp[0].push_back(0);
    r(i,e)r(j,v[i].size())r(k,v[i+1].size())
      dp[i+1][k]=min(dp[i+1][k],dp[i][j]+dist(v[i][j],v[i+1][k]));
    cout<<dp[e][0]<<endl;
  }
}

Measured memory_bytes: 5960
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define dbgarrmint(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j].x<<" ";}cerr<<endl;}
#else
#define dbg(...)
#define dbgmap(...)
#define dbgarr(...)
#define dbgdp(...)
#define dbgmint(...)
#define dbgarrmint(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,m;
    cin>>n>>m;

    VP vp;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        vp.emplace_back(a,b);
    }
    sort(ALL(vp));
    ll cnt = 0;
    priority_queue<ll> q;
    ll ans = 0;
    REP(i,1,m+1){
        while(cnt<n && vp[cnt].fi<=i){
            q.push(vp[cnt].se);
            cnt++;
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    out(ans);
    return  0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n;cin>>n;
    int ans=0;
    rep(i,1,n+1){
        int cnt=0;
        rep(j,1,i+1){
            if(i%j==0)cnt++;
        }
        if(i%2==0)continue;
        if(cnt==8){
            //cout<<i<<endl;
         ans++;
        }
    }cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

mp::cpp_int gcd(mp::cpp_int a, mp::cpp_int b) {
	mp::cpp_int r, temp;
	if (a < b) { 
		temp = a; 
		a = b; 
		b = temp; 
	}
	while ((r = a%b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int main(){
	mp::cpp_int a, b;
	cin >> a >> b;

	vector<mp::cpp_int> a_div(0);
	vector<mp::cpp_int> b_div(0);
	vector<mp::cpp_int> div(0);

	mp::cpp_int sqrta = (mp::cpp_int) sqrt(a);
	for (unsigned int i = 1; i < sqrta + 1; i++) {
		if (a % i == 0) {
			a_div.push_back(i);
			if (i != a/i) {
				a_div.push_back(a/i);
			}
		}
	}
	mp::cpp_int sqrtb = (mp::cpp_int) sqrt(b);
	for (unsigned int i = 1; i < sqrtb + 1; i++) {
		if (b % i == 0) {
			b_div.push_back(i);
			if (i != b/i) {
				b_div.push_back(b/i);
			}
		}
	}

	for (unsigned int i = 0; i < a_div.size(); i++) {
		mp::cpp_int temp = a_div[i];
		for (unsigned int j = 0; j < b_div.size(); j++) {
			if (temp == b_div[j]) {
				div.push_back(temp); 
			}
		}
	}

	sort(div.begin(), div.end());
	int size = div.size();
	int count = 1;
	for (unsigned int i = 1; i < size; i++) {
		bool plus = true;
		for (unsigned int j = 1; j < i; j++) {
			if (gcd(div[i], div[j]) != 1) {
				plus = false;
				break;
			} 
		}
		if (plus) {
			count++;
		}
	}

	cout << count;

	return 0;
}

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

int n, A[50];

bool solve(int i, int m){
  if(m == 0) return true;
  if(i >= n) return false;
  int res = solve(i+1, m) | solve(i+1, m-A[i]);
  return res;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  int q;
  cin >> q;
  int *M = new int[q];
  for(int i=0;i<q;i++){
    cin >> M[i];
  }

  for(int i=0;i<q;i++){
    if(solve(0, M[i])) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}



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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    print(max(0, c - (a - b)));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

bool chmin (int &a, int b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	std::size_t n;
	std::cin >> n;
	std::vector<long long> a(n);
    std::vector<int> index(n);
    for (auto &e : a) std::cin >> e;

	std::iota(index.begin(), index.end(), 0);
	std::sort(index.begin(), index.end(), [&](int l, int r) { return (a[l] > a[r]); });

	int j = index[0], c = 0;
	long long s = 0;
	std::vector<long long> count(n, 0);
    for (std::size_t id = 0; id < n; id++) {
        const int &i = index[id];
        if (i < j) {
            const long long val = (s - a[i] * c);
            count[j] += val;
            s -= val;
            j = i;
        }
        c++;
        s += a[i];
        if (i == 0) {
            for (std::size_t k = id + 1; k < n; k++) {
                s += a[index[k]];
            }
            count[i] += s;
            break;
        }
    }

	for (auto ans : count) {
		std::cout << ans << '\n';
	}

	return 0;
}

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

constexpr long double pi = acos(-1.0L), eps = 1e-10;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  bool valid = true;
  for (int i = 1; i < n - 1; ++i) {
    vector<pair<long double, int>> p;
    for (int j = 0; j < n; ++j) {
      if (j != i) {
        p.emplace_back(atan2l(y[j] - y[i], x[j] - x[i]), j);
      }
    }
    sort(begin(p), end(p));
    p.push_back(p[0]);
    p.back().first += 2 * pi;
    int cnt = 0;
    for (int j = 0; j < n - 1; ++j) {
      cnt += (p[j].second < i) ^ (p[j + 1].second < i);
    }
    if (cnt != 2) {
      valid = false;
      break;
    }
    long double a = 0, b = 0;
    for (int j = 0; j < n - 1; ++j) {
      if (p[j].second < i and p[j + 1].second < i) {
        a += p[j + 1].first - p[j].first;
      }
      if (p[j].second > i and p[j + 1].second > i) {
        b += p[j + 1].first - p[j].first;
      }
    }
    if (a > pi + eps or b > pi + eps) {
      valid = false;
      break;
    }
  }
  cout << (valid ? "Possible\n" : "Impossible\n");
}



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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
const ll INF = 1e18;
const ll lim = 3000;
int costo[60][60];
int tiempo[60][60];
int cambio[60][2];

bool vis2[60][3000];
set<pair<int,int>> vis;


int main(){

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

	ll n, m, s;
	cin >> n >> m >> s;

	vector<vector<int>> graph(n);

	int a, b, c, d;
	for(int i =0; i < m; i++){
		cin >> a >> b >> c >> d;
		--a;--b;
		graph[a].push_back(b);
		graph[b].push_back(a);
		costo[a][b] = costo[b][a] = c;
		tiempo[a][b] = tiempo[b][a] = d;
	}

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

	priority_queue<iii, vector<iii>, greater<iii>> pq;
	pq.push({0,{min(s, lim),0}});

	vector<ll> dist(n, INF);
	while(!pq.empty()){
		ll curr_time = pq.top().first;
		ll curr_money = pq.top().second.first;
		ll curr_index = pq.top().second.second;
		pq.pop();
		
		if(vis2[curr_index][curr_money])continue;
			vis2[curr_index][curr_money] = true;
		
		dist[curr_index] = min(curr_time, dist[curr_index]);

		//Visitarte a ti mismo
		if(curr_money < 3000){
			pq.push({curr_time + cambio[curr_index][1], {min(curr_money + cambio[curr_index][0], lim), curr_index}});
		}

		for(auto& it : graph[curr_index]){
			if(costo[curr_index][it] <= curr_money){
				pq.push({curr_time + tiempo[curr_index][it], {curr_money - costo[curr_index][it], it}});
			}
		}	
	}


	for(int i = 1; i < n; i++){
		cout << dist[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 15780
#include<stdio.h>
int main(void)
{
	int x,y,wk;
	while(1)	{
		scanf("%d %d",&x,&y);
		if(x==0 && y==0)	break;
		if(x>y){
		wk=x;
		x=y;
		y=wk;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}


Measured memory_bytes: 2032
// By Atul Rathore

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

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	


int main()
{
	fastio;
	int n;
	cin>>n;
	int c=0;
	while(n)
	{
		if(n%10==7)c=1;
		n/=10;
	}
	if(c==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
}


Measured memory_bytes: 3612
#include<stdio.h>

int sq(int n){
  return n*n;
}

int sum(int d,int n){
  if(n>=600){
    return 0;
  }
  else{
    return d*sq(n)+sum(d,n+d);
  }
}

void doit(){
  int n;
  if(scanf("%d",&n)!=EOF){
    printf("%d\n",sum(n,0));
    doit();
  }
}

int main(){
  doit();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

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

    int sum = 0;
    
    cin >> n;
    temp = n;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10; temp /=10;
    sum += temp % 10;
    if (n % sum) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if ((A + B) >= 24) {
        	System.out.println(A + B - 24);
    		} else {
    		System.out.println(A + B);
    	}
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;
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; }

using namespace std;

ll dfs(int ,ll,ll);

string s;
int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    cin>>s;
    reverse(s.begin(),s.end());
    cout << dfs(0, 1, 0) / 2 << endl;

    return 0;
}


ll dfs(int i ,ll t, ll sum)
{
    ll rec = 0;
    if(i==s.size())return sum;
    rec+=dfs(i+1,1,sum+(s[i]-'0')*t);
    rec+=dfs(i+1,t*10,sum+(s[i]-'0')*t);
    return rec;
}

Measured memory_bytes: 256
let n, t0 = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ts = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let _ = Array.iteri (fun i t -> ans := !ans + if i < n - 1 then min t0 @@ ts.(i + 1) - t else t0) ts; Printf.printf "%d\n" !ans

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int N = 1e5 + 5;

// ll fact[nax], invfact[nax];

// void pre()
// {
// 	fact[0] = 1;
// 	forn(i, 1, nax)
// 	{
// 		fact[i] = mult(fact[i - 1], i);
// 	}

// 	invfact[nax - 1] = mypow(fact[nax - 1], mod - 2);

// 	ford(i, nax, 1)
// 	{
// 		invfact[i - 1] = mult(invfact[i], i);
// 	}
// }

// ll ncr(ll n, ll r)
// {
// 	if (r > n)
// 		return 0;

// 	ll ans = mult(fact[n], mult(invfact[n - r], invfact[r]));

// 	return ans;
// }

ll parent[N];
ll Rank[N];
ll Size[N];

void make_set(ll x)
{
	parent[x] = x;
	Rank[x] = 0;
	Size[x] = 1;
}

ll find_set(ll x)
{
	if (parent[x] == x)
		return x;

	parent[x] = find_set(parent[x]);
	return parent[x];
}

void union_set(ll x, ll y)
{
	ll px = find_set(x);
	ll py = find_set(y);

	if (px != py)
	{
		if (Rank[px] == Rank[py])
		{
			parent[py] = px;
			Rank[px]++;
			Size[px] += Size[py];
		}
		else if (Rank[px] > Rank[py])
		{
			parent[py] = px;
			Size[px] += Size[py];
		}

		else
		{
			parent[px] = py;
			Size[py] += Size[px];
		}
	}
}
int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		ll n, m, k;
		cin >> n >> m >> k;

		forn(i,1,n+1)
		{
			make_set(i);
		}

		vector<ll>Friend[n+1];
		vector<ll>block[n+1];

		ll a,b;
		forn(i,0,m)
		{
			cin>>a>>b;
			Friend[a].pb(b);
			Friend[b].pb(a);

			union_set(a,b);
		}

		forn(i,0,k)
		{
			cin>>a>>b;
			block[a].pb(b);
			block[b].pb(a);
		}

		forn(i,1,n+1)
		{
			find_set(i);
		}

		forn(i,1,n+1)
		{
			ll par = parent[i];
			ll ans = Size[find_set(i)] - 1;

			set<ll>s;

			for(auto x : Friend[i])
			{
				if(parent[x] == par)
				{
					s.insert(x);
				}
			}
			for(auto x : block[i])
			{
				if(parent[x] == par)
				{
					s.insert(x);
				}
			}

			ans -= s.size();
			cout<<ans<<endl;
		}

	}

	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	ll t = 1, a = 1;
	int N; cin >> N;
	while (N--) {
		int p, q; cin >> p >> q;
		ll k = max((t+p-1)/p, (a+q-1)/q);
		t = k * p, a = k * q;
	}
	cout << t + a << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int i,j = 0;

        for(i = 1; i < 10; i++) {
            for(j = 1; j < 10; j++) {
                int nij = i * j;
                if (N == nij) {
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 22608
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

        
    
int main(){
  int n, k; cin >> n >> k; ll ans = 0;
  if(k==0){
    cout << (ll)n*n << endl; return 0;
  }
  for(int i=k+1; i<=n; i++){
    ans+=((ll)n/i)*((ll)i-k);
    //cout << n/i << " " << i-k << endl;
    if(n%i) ans+=max(((ll)n%i-k+1), 0LL);
    //cout << n%i-k+1 << endl;
  }
  cout << ans << endl;  
}

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

typedef long long i64;

i64 ans[51];

int main()
{
    i64 k;
    cin >> k;

    i64 q = k % 50, h = k / 50;

    cout << "50\n";

    for (int i(0); i < 50; i++)
        ans[i] = 50 - 1 + h;

    i64 scade(0);
    for (int i(0); i < 50; i++) {
        ans[i] -= scade;
        if (q) {
            q--;
            ans[i]++;
            scade++;
        }
    }
    for (int i(0); i < 50; i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np    
N = int(input())
vstr = input().split()
vs = [int(v) for v in vstr]

for i in range(N-1):
    valarg = np.argmin(vs)
    val1 = vs.pop(valarg)
    valarg = np.argmin(vs)
    val2 = vs.pop(valarg)
    vs.append((val1+val2)/2)
    if len(vs) == 1:
        break
print(vs[0])


Measured memory_bytes: 21544
#include <stdio.h>
#define REP(i,n) for(int i=0; i<n;i++)
int main()
{
    int A,B[3],C[3],D[3];
    char num[5]={'*'};
    char op[3];
    op[0]='+'; op[1]='-';
    
    scanf("%s",num);
    A = num[0]-48; B[0]= num[1]-48; C[0]= num[2]-48; D[0]= num[3]-48;
    B[1]= -B[0]; C[1]= -C[0]; D[1]= -D[0];
    
    REP(i,2)
    {
        REP(j,2)
        {
            REP(k,2)
            {
                if(A+B[i]+C[j]+D[k]==7)
                {
                    printf("%d%c%d%c%d%c%d=7\n",A,op[i],B[0],op[j],C[0],op[k],D[0]);
                    return 0;
                    i=j=k=2;
                }
                
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 128
[<EntryPoint>]
let main argv =
    //printfn "Gokigenyou!"
    let n = System.Console.ReadLine() |> int
    let a =
        match n with
        | n when n % 2 = 1 -> n/2 + 1
        | _ -> n/2
    let ans = (float a) / (float n)

    System.Console.WriteLine(ans)
    0


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e6+5;

string s;

int32_t main()
{
    cin>>s;
    int len=s.size();
    int ans=0, cur=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='0')
            continue;
        ans=max(ans, (len-i-1)*9 + (s[i]-'1') + cur);
        cur+=(s[i]-'0');
    }
    ans=max(ans, cur);
    cout<<ans;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <stdio.h>


using namespace std;
int main()
{   
    // 整数の入力
    int i;
    char a;
    vector<char> abc{};
    cin >> i;
    while(cin >> a){
        for(int n = 0;n<i;n++){
            if(a>='Z'){
                a='A';
            }
            else{
                ++a;
            }
        }
        cout << a;
    }

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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; }

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

    int N, M; cin >> N >> M;
    vector<bool> start(N, false);
    vector<bool> goal(N, false);
    rep(i, M) {
        int a, b; cin >> a >> b;
        if(a == 1) start[b - 1] = true;
        if(b == N) goal[a - 1] = true;
    }
    int flg = 0;
    rep(i, N) {
        if(start[i] && goal[i]) flg = 1;
    }
    if(flg) COUT("POSSIBLE");
    else COUT("IMPOSSIBLE");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int l,r,d;
    cin >> l >> r >> d;
    print(r/d-(l-1)/d);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    int N, K;
    cin >> N >> K;
    int ans = 0;
    while (N) {
        N /= K;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

namespace ABC144A_9x9
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = input[0];
            int b = input[1];

            if (a <= 9 && b <= 9)
            {
                Console.WriteLine(a * b);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


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

bool ans[2001];

int main(){

	ios_base::sync_with_stdio(false);

	int buf; 
	int numOfNumber;

	cin >> numOfNumber;
	for(int i = 0; i < 2001; i++)ans[i] = false;

	for(int i = 0; i < numOfNumber; i ++){
		cin >> buf;
		for(int j = 2000; j >=  0 ; j--){
			if(ans[j])ans[j + buf] = true;
		}
		ans[buf] = true;
	}

	cin >> buf;

	while(cin >> buf){
		cout <<( ans[buf] ? "yes" : "no") << endl;
	}

	return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

long long GCD(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (b == 0) return a;
    else return GCD(b, a % b);
}


vector<bool> isprime;
vector<int> Era(int n) {
    isprime.resize(n, true);
    vector<int> res;
    isprime[0] = false; isprime[1] = false;
    for (int i = 2; i < n; ++i) isprime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (isprime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) isprime[j] = false;
        }
    }
    return res;
}

int main() {
    long long N; cin >> N;
    vector<long long> a(N+1);
    for (int i = 0; i < N+1; ++i) cin >> a[i];
    reverse(a.begin(), a.end());

    set<long long> res;
     
    // f(x) ≡ 0 の場合
    long long g = 0;
    for (int i = 0; i < N+1; ++i) g = GCD(g, a[i]);
    auto pf = prime_factorize(g);
    for (auto p : pf) res.insert(p.first);

    // N 以下の素数 p をすべて試す
    auto prs = Era(10101);
    for (auto p : prs) {
        vector<long long> c(p, 0);
        for (int d = 0; d < p; ++d) c[d] = a[d] % p;
        for (int d = p; d <= N; ++d) {
            int r = d % (p-1);
            if (r == 0) r = p-1;
            c[r] = (c[r] + a[d] % p) % p;
        }

        bool ok = true;
        for (int d = 0; d < p; ++d) if (c[d] != 0) ok = false;
        if (ok) res.insert(p);
    }
    for (auto p : res) cout << p << endl;
}














Measured memory_bytes: 384
N,M=map(int,input().split())
Shop=[[int(x) for x in input().split()] for y in range(N)]
Shop=sorted(Shop,key = lambda x:x[0])

ans=0
for a,b in Shop:
    if b < M:
        ans += (a*b)
        M-=b
    else:
        ans += (M*a)
        break

print(ans)

Measured memory_bytes: 23524
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def find(self, x):
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        self.par[x] = y

    def same(self, x, y):
        return self.find(x) ==  self.find(y)


n, m = map(int, input().split())
p = list(map(int, input().split()))
p = [v-1 for v in p]

uf = UnionFind(n)
for _ in range(m):
    x, y = map(int, input().split())
    uf.unite(x-1, y-1)

ans = 0
for i in range(n):
    if uf.same(i, p[i]):
        ans += 1

print(ans)


Measured memory_bytes: 14188
let f()=List.map int_of_string(Str.split(Str.regexp" ")(read_line()))open Array;;match f()with[n;m]->let a,b=make(n*m)0,make m 0in for i=0to n-1do List.iteri(fun j e->a.(m*i+j)<-e)(f())done;for i=0to m-1do b.(i)<-read_int()done;for i=0to n-1do let c=ref 0in for j=0to m-1do c:=!c+a.(m*i+j)*b.(j)done;Printf.printf"%d
"!c done|_->()

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

int main() {
  int A, B, C, D;
  int train_fare, bus_fare, total_fare;

  cin >> A >> B>>C>>D;
  train_fare = A;
  if (A > B) train_fare = B;
  bus_fare = C;
  if (C > D) bus_fare = D;
  total_fare = train_fare + bus_fare;

  cout << total_fare << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int const maxN=100001;
int chi[maxN],par[maxN],a[maxN],b[maxN];
long long w[maxN];
int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
}
void unite(int x,int y){
    int rx=root(x),ry=root(y);
    if(rx!=ry){
        chi[rx]+=chi[ry];
        par[ry]=rx;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        par[i]=i;
        chi[i]=1;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    for(int i=m-1;i>=0;i--){
        if(same(a[i],b[i]))w[i]=0;
        else w[i]=((long long)chi[root(a[i])])*chi[root(b[i])];
        unite(a[i],b[i]);
    }
    long long sum=0;
    for(int i=0;i<m;i++){
        sum+=w[i];
        printf("%lld\n",sum);
    }
    return 0;
}

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

typedef long long ll;
#define pb push_back
#define mod 1000000007

// int gcd(int a, int b) {   if (b == 0) return a; return gcd(b, a % b);  }
// int lcm(int a,int b){return a/gcd(a,b)*b;}
string solve(){
    int n;
    cin>>n;
    int a[n],b[n],c=0;
    string ans="No";
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i]==b[i]) c++;
        else c=0;
        if(c>=3){
            ans = "Yes";
        }
    }
    return ans;

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // int t;
    // cin>>t;
    // while(t--){
    //     cout<<solve()<<"\n";
    // }
    cout<<solve();
    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 5)
        cout << 0 << endl;
    else if (6 <= a && a <= 12)
        cout << b / 2 << endl;
    else
        cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<lli,lli> P;

struct edge{ int u, v, cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
};

void displayVector(vector<lli> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}



int main(){
	int n; cin >> n;
	vector<lli> a(n); REP(i,n){ cin >> a[i]; }
	lli out = 0;
	REP(i,n){ out = lli(out ^ a[i]); }
	REP(i,n-1){ cout << lli(out ^ a[i]) << " ";}	
	cout << lli(out^a[n-1]) << endl;
	return 0;
}

Measured memory_bytes: 4784
n = int(input())
s = input()

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)


Measured memory_bytes: 9288
# coding: utf-8
x,n = map(int, input().split())
a = list(map(int, input().split()))
xx = x

while(True):
    if x in a:
        x-=1
    else:
        break
    
    if xx in a:
        xx+=1
    else:
        x = xx
        break

print(x)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
vector<int> v;
vector<int> adj[200005];

void dfs(int src, int par){
    v.push_back(src);
    for(int i : adj[src]){
        if(par != i){
            dfs(i, src);
        }
    }
    v.push_back(src);
    return;
}

int main() {
    int n ,q;
    cin>>n>>q;
    v.push_back(0);
    for(int i=0;i<(n-1);i++){
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, -1);
    v.push_back(0);
    //cout<<v.size()<<"\n";
    int m = (int)v.size();
    int x[n+1], y[n+1];
    for(int i=0;i<=n;i++){
        x[i] = -1;
        y[i] = -1;
    }
    for(int i=0;i<m;i++){
        if(x[v[i]] == -1){
            x[v[i]] = i;
        }else{
            y[v[i]] = i;
        }
    }
    lli ans[m+1];
    for(int i=0;i<m;i++)ans[i] = 0;
    while(q--){
        int p, val;
        cin>>p>>val;
        ans[x[p]] += val;
        ans[y[p] + 1]-=val;
    }
    for(int i=1;i<m;i++){
        ans[i] = ans[i-1] + ans[i];
    }
    for(int i=1;i<=n;i++){
        cout<<ans[x[i]]<<" ";
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 24436
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int diff(vector<int> p, vector<int> q) {
    int d = 0;
    do {
        if (p == q) return d;
        ++d;
    } while (next_permutation(p.begin(), p.end()));

    return -1;
}

int main() {
    int n; cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> q[i];
    }
    
    int d1 = diff(p, q);
    int d2 = diff(q, p);

    if (d1 != -1) cout << d1 << endl;
    else cout << d2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
long long zxgbs(long long x,long long y)  
{     
    int z=y;  
    while(x%y!=0)  
    {  
        z=x%y;  
        x=y;  
        y=z;    
    }  
    return z;  
} 

long long  GetCount(long long a,long long b,long long c)
{
	long long count = 0;
	if(a%c==0)
	{
		count++;
		count += ((b-a))/c; 
	} 
	else
	{
		count += (a%c+(b-a))/c;		
	}

	return count;
}
 
int main()
{
	long long a,b,c,d,ans=0;
	cin>>a>>b>>c>>d;
	
	ans = b-a+1 - GetCount(a,b,c)-GetCount(a,b,d) + GetCount(a,b,c*d/__gcd(c,d));
//cout<<__gcd(c,d);	
//cout<<GetCount(a,b,c);
//cout<<GetCount(a,b,d);

	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,t,c=1001;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(b<=t){
            c=min(c,a);
        }
    }
    if(c>1000){
        cout<<"TLE"<<endl;
    }else{
        cout<<c<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;cin>>n;
  vector<long long>a(n+1);
  long long x=0;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=n;i++){
    if(i%2)x+=a[i];
    else x-=a[i];
  }
  cout<<x<<' ';
  for(int i=1;i<=n-1;i++){
    cout<<a[i]*2-x<<' ';
    x=a[i]*2-x;
  }
}

Measured memory_bytes: 2048
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int x,k,d;cin >> x >> k >> d;
    int p = x%d;
    // if(p<0)p+=d;
    // cout << p << endl;
    if(abs(x)/d>=k) cout << abs(x)-k*d << endl;
    else {
        k-=abs(x)/d;
        if(k%2==1) cout << min(abs(p-d),abs(p+d)) << endl;
        else cout << abs(p) << endl;
    }
    // cout << -3%5 << endl;
    return 0;
}
/*
-3 2 1
*/

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 100001; 

// int dp[101][N];
ld n;

ld dp[301][301][301];


ld rec(int a, int b, int c){
    if(a < 0 || b < 0 || c < 0)
        return 0;
    if(a+b+c == 0)
        return 0;
    if(dp[a][b][c] != -1)
        return dp[a][b][c];

    ld ans = ((rec(a-1,b,c)*a/(a+b+c))  + (rec(a+1,b-1,c)*b/(a+b+c)) + (rec(a,b+1,c-1)*c/(a+b+c))) + n/(a+b+c) ;

    return dp[a][b][c] = ans ;

}


void solve(){
    cin>>n;

    int* a = new int[(int)n];

    forn(i,0,n-1)
        cin>>a[i];

    int b=0,c=0,d=0;

    // memset(dp, -1, sizeof(dp));
    for(int i=0;i<301;i++){
        for(int j=0;j<301;j++){
            for(int k=0;k<301;k++){
                dp[i][j][k] = -1;
            }   
        }   
    }

    forn(i,0,n-1){
        if(a[i]==1)
            b++;
        else if(a[i]==2)
            c++;
        else 
            d++;
    }

    ld ans = rec(b,c,d);

    cout<<PSET(ans,16)<<endl;





}
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 426496
r0, r1 = map(int, input().split())
a0, a1 = 1, 0
b0, b1 = 0, 1
while 0 < r1:
    q1 = r0 // r1
    a0, a1 = a1, a0 - q1 * a1
    b0, b1 = b1, b0 - q1 * b1    
    r0, r1 = r1, r0 % r1
  
print(a0, b0)

Measured memory_bytes: 7636
import heapq
import sys
input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        b, c = map(int, input().split())
        yield b, c

def main():
    _, M = map(int, input().split())
    A = list(map(int, input().split()))
    total = sum(A)
    heapq.heapify(A)

    for b, c in sorted(readlines(M), key=lambda x: -x[1]):
        for _ in range(b):
            o = heapq.heappushpop(A, c)
            if o < c:
                total += c - o
            else:
                break
            
    print(total)

main()

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

long long LCM(long long c,long long d){
	long long res=d;
	if(c%d!=0)res=LCM(d,c%d);
	return res;
}
int main() {
    clock_t cTimeStart, cTimeEnd;
    cTimeStart = clock();           // 現在時刻
    string str;
    cin>>str;
    int len=str.size();
    for(int i=0;i<len;++i){
    	cout<<str[len-i-1];
    }
    cout<<endl;
    cTimeEnd = clock();           // 現在時刻
//    cout<< "処理時間:" <<(cTimeEnd - cTimeStart)/1000 << "[ms]" << endl;

	return 0;
}

Measured memory_bytes: 1180
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    n = int(N[l])
    ans = 0
    for a in range(min(n+1,10)):
        for b in range(min(n+1-a,10)):
            for c in range(min(n+1-a-b,10)):
                for d in range(min(n+1-a-b-c,10)):
                    if a+b+c+d == n:
                        #print(a,b,c,d)
                        ans = ans + 1
    print(ans)


Measured memory_bytes: 5600
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int m, fi, y, n, tf, c, max, a, b, i;
    double p;

    m = sc.nextInt();
    for(;m-- > 0;){
      fi = sc.nextInt(); y = sc.nextInt();
      max = fi;
      for(n = sc.nextInt();n-- > 0;){
        tf = sc.nextInt(); p = sc.nextDouble(); c = sc.nextInt();
        a = fi;
        if(tf == 0){
          b = 0;
          for(i = 0;i < y;i++){
            b += (int)(a * p); a -= c;
          }
          if(max < a + b)max = a + b;
        }else{
          for(i = 0;i < y;i++){
            b = (int)(a * p); a += b - c;
          }
          if(max < a)max = a;
        }
      }
      out.println(max);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

int main(){
  int d, g; cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  
  for (int i=0; i<d; i++){
    cin >> p.at(i) >> c.at(i);
  }
  
  int ans = 10000;
  
  for (int tmp=0; tmp < (1 << d); tmp++){
    int count = 0;
    int sum = 0;
    int max = 0;
    for (int i=0; i < d; i++){
      if (tmp >> i & 1){
        sum += (i+1)*100*p.at(i) + c.at(i);
        count += p.at(i);
      }
      else {
        max = i;
      }
    }
    if (sum < g) {
      int t = 100*(max+1);
      if ((g-sum)%t == 0){
        if ((g-sum+t)/t > p.at(max)) {continue;}
        count += ((g-sum)/t);
      }
      else {
        if ((g-sum+2*t)/t > p.at(max)) {continue;}
        count += ((g-sum+t)/t);
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600