akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

int n, a, b, c, res = LINF;
vector<int> l;

void dfs(vector<int>& vec){
    if(vec.size() == n){
        if(find(all(vec), 1) != vec.end() && find(all(vec), 2) != vec.end() && find(all(vec), 3) != vec.end()){
            int suma = 0, sumb = 0, sumc = 0, cnt = 0;
            rep(i,n){
                if(vec[i] == 1){
                    suma += l[i];
                }else if(vec[i] == 2){
                    sumb += l[i];
                }else if(vec[i] == 3){
                    sumc += l[i];
                }
                cnt += (vec[i] != 0);
            }
            chmin(res, abs(a-suma) + abs(b-sumb) + abs(c-sumc) + 10 * (cnt - 3));
        }
        return;
    }
    for(int i = 0; i <= 3; ++i){
        vec.emplace_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n >> a >> b >> c;

    l.resize(n);

    for(auto&& e : l){
        cin >> e;
    }

    vector<int> vec;

    dfs(vec);

    cout << res << '\n';

    return 0;
}

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

class grtr {
public:
  bool operator()(const string &s, const string &t) {
    return s.size()!=t.size() ? s.size()<t.size() : s<t;
  }
};

int main() {
  
  map<string, int, grtr> mp;
  int n; cin>>n;
  string s; int a;
  
  for(int i=0;i<n;i++) {
    cin>>s>>a;
    mp[s]+=a;
  }

  for(map<string,int,grtr>::iterator it=mp.begin();it!=mp.end();it++)
    cout << it->first << " " << it->second << endl;
  
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    int n;
    string s,t;

    cin>>n>>s>>t;

    FOR(i,0,n-1){
        cout<<s[i]<<t[i];
    }
}


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

#define SEAT_S 6000
#define SEAT_A 4000
#define SEAT_B 3000
#define SEAT_C 2000

int main(){
	for(int i=0;i<4;i++){
		int t,n;
		cin>>t>>n;
		switch(t){
			case 1:
				cout<<SEAT_S*n<<endl;
				break;
			case 2:
				cout<<SEAT_A*n<<endl;
				break;
			case 3:
				cout<<SEAT_B*n<<endl;
				break;
			case 4:
				cout<<SEAT_C*n<<endl;
				break;
			default:
				break;
		}
	}
	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;


//std::vector<std::set<int>> g;




int main(){
    rep(i,3){
        string s;
        std::cin >> s;
        std::cout << char(s[0]+'A'-'a');
    }
    std::cout  << std::endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    unsigned long long int k, a, b, can_act;

    cin >> k >> a >> b;

    if(k >= a + 1 && b > a){
        
        can_act = k - (a - 1);

        if(can_act % 2 == 0){
            unsigned long long int tmp = a + (b - a) * (can_act / 2);
            if(k + 1 < tmp){
                cout << tmp;
            }else cout << k + 1;
        }else{
            unsigned long long int tmp = a + 1 + (b - a) * (can_act / 2);
            if(k + 1 < tmp){
                cout << tmp;
            }else cout << k + 1;
        }
    }else cout << k + 1;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>

using namespace std;
#define int long
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() 
{
	int N;
	cin >> N;
	if (N % 2 == 1)
	{
		cout << "0";
		return 0;
	}
	int cnt = 0;
	int i = 10;
	while (1)
	{
		cnt += N / i;
		i *= 5;
		if (i > N)break;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int h, w; scanf("%d%d", &h, &w);
	char s[h][w];
	rep(i, h) rep(j, w) cin >> s[i][j];
	
	pair<int, int> q = mp(0, 0);
	
	while(true){
		s[q.fir][q.sec] = '.';
		if(q == mp(h-1, w-1)) break;
		
		if(q.fir != h-1 && s[q.fir+1][q.sec] == '#'){
			q = mp(q.fir+1, q.sec);
		}else if(q.sec != w-1 && s[q.fir][q.sec+1] == '#'){
			q = mp(q.fir, q.sec+1);
		}else{
			cout << "Impossible" << endl;
			return 0;
		}
	}
		
	rep(i, h) rep(j, w) if(s[i][j] == '#'){
		cout << "Impossible" << endl;
		return 0;
	}
	
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1,5):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for d,q in dq:
    t0 = t[d]
    last2 = deepcopy(last)
    manzoku = s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last2[d][t0] = last2[d-1][t0]
            manzoku -= c[t0] * (d - last2[d][t0])
            last2[d][q] = d
            manzoku += c[q] * (d - last2[d-1][q])
        else:
            if last2[j][t0] == d:
                last2[j][t0] = last2[d-1][t0]
                manzoku -= c[t0] * (d - last2[d][t0])
            if last2[j][q] == last2[d-1][q]:
                last2[j][q] = d
                manzoku += c[q] * (d - last2[d-1][q])
    if manzoku > 0:
        t[d] = q
        last = last2

del t[0]

print(*t,sep='\n')

Measured memory_bytes: 184300
#include<stdio.h>
int main() {
	int r, c, i, j, a[101][101] = { 0 };
	scanf("%d %d", &r, &c);
	for (i = 0;i < r;i++) {
		for (j = 0;j < c;j++) {
			scanf("%d", &a[i][j]);
			a[i][c] += a[i][j];
		}
	}
	for (j = 0;j < c;j++) {
		for (i = 0;i < r;i++) {
			a[r][j] += a[i][j];
		}
		a[r][c] += a[r][j];
	}
	for(i=0;i<r+1;i++){
		for (j = 0;j < c+1;j++) {
			printf("%d", a[i][j]);
			if (j != c) {
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  int n; cin >> n;
  vector<int> idx(n, 0);
  int maxv = 0;
  rep(i, n) {
    int a; cin >> a; --a;
    idx[a] = idx[a - 1] + 1;
    chmax(maxv, idx[a]);
  }

  int ans = n - maxv;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5, MAX = 2e5 + 1;
int n, q, A, B, x[N], cost[N];
class SegTree {
private:
	int t[N << 2];
	void build(int l, int r, int x) {
		if (l == r) {
			t[x] = infll;
			return;
		}
		int m = (l + r) >> 1;
		build(l, m, x << 1), build(m + 1, r, x << 1 | 1);
		t[x] = infll;
	}
	void upd(int l, int r, int pos, int x, int val) {
		if (l == r) {
			t[x] = val;
			return;
		}
		int m = (l + r) >> 1;
		if (pos <= m) upd(l, m, pos, x << 1, val);
		else upd(m + 1, r, pos, x << 1 | 1, val);
		
		t[x] = min(t[x << 1], t[x << 1 | 1]);
	}
	int get(int l, int r, int s, int e, int x) {
		if (l > e || r < s) return infll;
		if (s <= l && r <= e) return t[x];
		int m = (l + r) >> 1;
		return min(get(l, m, s, e, x << 1), get(m + 1, r, s, e, x << 1 | 1));
	}
public:
	int n;
	void init(int _n) {
		n = _n;
		build(0, n - 1, 1);
	}
	void upd(int pos, int val) {
		upd(0, n - 1, pos, 1, val);
	}
	int get(int l, int r) {
		return get(0, n - 1, l, r, 1);
	}
} st[2];
int dp[N];
int solve() {
	cost[0] = abs(x[0] - A);
	fw (i, 1, q) cost[i] = cost[i - 1] + abs(x[i] - x[i - 1]);
	fw (i, 0, 2) st[i].init(MAX);
	memset(dp, 63, sizeof dp);
	int mnThing = infll;
//	cout << "A = " << A << " B = " << B << "\n";
	fw (i, 0, q) {
		//Assign the whole prefix of 0 -> i to the A gay.
		int costB = 0;
		if (i < q - 1) costB = abs(x[i + 1] - B);
		dp[i] = cost[i] + costB;
		
		if (i < q - 1) {
			dp[i] = min(dp[i], st[0].get(0, x[i + 1]) + cost[i] + x[i + 1]);
			dp[i] = min(dp[i], st[1].get(x[i + 1], MAX - 1) + cost[i] - x[i + 1]);
			
			st[0].upd(x[i], dp[i] - cost[i + 1] - x[i]);
			st[1].upd(x[i], dp[i] - cost[i + 1] + x[i]);
			
			mnThing = min(mnThing, dp[i] - cost[i + 1]);
		} else {
			dp[i] = min(dp[i], mnThing + cost[i]);
		}
//		cout << "dp[" << i << "] = " << dp[i] << "\n";
	}
	return dp[q - 1];
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q >> A >> B;
	fw (i, 0, q) cin >> x[i];
	
	int ans = solve();
	swap(A, B);
	ans = min(ans, solve());
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 17408
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t A, B;
	int K;
	int i;
	if (scanf("%" SCNu64 "%" SCNu64 "%d", &A, &B, &K) != 3) return 1;
	for (i = 0; i < K; i++) {
		if (i % 2 == 0) {
			if (A % 2 != 0) A--;
			B += A / 2;
			A /= 2;
		} else {
			if (B % 2 != 0) B--;
			A += B / 2;
			B /= 2;
		}
	}
	printf("%" PRIu64 " %" PRIu64 "\n", A, B);
	return 0;
}


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

int main() {
  int n, k, s = 0;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  rep(i, k) s += v[i];
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import math

n,d = map(int,input().split())
p = []
for i in range(n):
    p.append(list(map(int,input().split())))

ans = 0
for i in range(n):
    for j in range(n):
        t0 = 0
        for k in range(d):
            t0 += pow(p[i][k]-p[j][k],2)
        t  = math.sqrt(t0)
        if t.is_integer() and t != 0:
            ans += 1
print(ans//2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, N;
  string op;
  cin >> N;
  cin >> A;

  int remainder = N % 500;
  if (remainder == 0){
    cout << "Yes" << endl;
  } else {
   	if (remainder <= A) {
      cout << "Yes" << endl; 
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
import Data.Int (Int64)

solve :: Integral a => a -> a -> a -> a
solve n a b
    | a > b = 0
    | n == 1 = if a == b then 1 else 0
    | n == 2 = 1
    | n >= 3 = if a == b then 1 else (b - a) * (n - 2) + 1
    | otherwise = 0

main :: IO ()
main = do
    [n, a, b] <- fmap read . words <$> getLine :: IO [Int64]
    print $ solve n a b


Measured memory_bytes: 508
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
signed main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
 if(n==7||n==5||n==3) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


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

int main(void) {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long ans = 0;
    long long ma = A[0];
    for (int i = 0; i < N; i++) {
        ma = max(ma, A[i]);
        ans += ma - A[i];
    }
    cout << ans << endl;
    return 0;
}

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

ll gcd(ll x,ll y){
  if(y==0){
    return x;
  }else{
    return gcd(y,x%y);
  }
}

vector<pair<ll,int>> factorize(ll n){
  vector<pair<ll,int>> res;
  for(ll i=2;i*i<=n;i++){
    if((n%i)!=0){
      continue;
    }
    res.emplace_back(i,0);
  
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if(n!=1){
      res.emplace_back(n,1);
  }
  return res;
}
 
      
  

int main(){
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);
  auto f=factorize(g);
  int ans=f.size()+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;

ll get_lower(vector<ll> &v,ll qi){
	vector<ll>::iterator it = lower_bound(v.begin(),v.end(),qi);
	if(it == v.end()) return v[v.size()-1];
	return *it;
}

ll get_upper(vector<ll> &v,ll qi){
	vector<ll>::iterator it = upper_bound(v.begin(),v.end(),qi);
	cout <<  "it"<<" "<< *it <<endl;
	if(it == v.end()) return v[0];
	return *it;
}

int main(){
	ll a,b,q;
	
	cin >> a >> b >> q;
	vector<ll> sv(a),tv(b);
	
	for(ll i=0;i<a;++i){
		cin >> sv[i];
	}
	for(ll i=0;i<b;++i){
		cin >> tv[i];
	}
	sort(sv.begin(),sv.end());
	sort(tv.begin(),tv.end());
	
	for(ll i=0;i<q;++i){
		ll qi;
		cin >> qi;
	//	cout << qi <<endl;
		vector<ll>::iterator it = lower_bound(sv.begin(),sv.end(),qi);
		if(it == sv.end()) it--;
		ll sl = *it;
		ll su = (*it == sv[0]) ? * it : *(it-1);
		
		it = lower_bound(tv.begin(),tv.end(),qi);
		if(it == tv.end()) it--;
		ll tl = *it;
		ll tu = (*it == tv[0]) ? * it : *(it-1);
		
		ll data[4] = {sl,tl,su,tu};
		ll res = 50000000009;
		//cout <<tl<<" " <<tu <<" "  << sl << " " << su << endl;
		
		for(ll j=0;j<4;++j){
			ll first = data[j];
//			cout << first <<endl;
			for(ll k=1;k<4;k+=2){
				ll second = data[(j+k)%4];
				res = min(res,abs(qi-first)+abs(first-second));
			}
		}
		cout << res << endl;
	}
	
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(c>=a && c<=b) co("Yes");
  else co("No");
  
  return 0;
}

Measured memory_bytes: 256
import sys
class Lazysegtree:
    def __init__(self, A, intv, initialize = True):
        #区間は 1-indexed で管理
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        #self.segf = segf
        self.lazy = [None]*(2*self.N0)
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-2, -1, -1):
                self.data[i] = min(self.data[2*i], self.data[2*i+1]) 
        else:
            self.data = [intv]*(2*self.N0)
  
    def _ascend(self, k):
        k = k >> 1
        c = k.bit_length()
        for j in range(c):
            idx = k >> j
            self.data[idx] = min(self.data[2*idx], self.data[2*idx+1])
              
    def _descend(self, k):
        k = k >> 1
        idx = 1
        c = k.bit_length()
        for j in range(1, c+1):
            idx = k >> (c - j)
            if self.lazy[idx] is None:
                continue
            self.data[2*idx] = self.data[2*idx+1] = self.lazy[2*idx] \
            = self.lazy[2*idx+1] = self.lazy[idx] 
            self.lazy[idx] = None
              
              
    def query(self, l, r):
        L = l+self.N0
        R = r+self.N0
        self._descend(L//(L & -L))
        self._descend(R//(R & -R) - 1)
          
        s = self.intv                                                                   
  
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R])
            if L & 1:
                s = min(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s
      
    def update(self, l, r, x):
        L = l+self.N0
        R = r+self.N0
  
        Li = L//(L & -L)
        Ri = R//(R & -R)
        self._descend(Li)
        self._descend(Ri-1)
          
        while L < R :
            if R & 1:
                R -= 1
                self.data[R] = x
                self.lazy[R] = x
            if L & 1:
                self.data[L] = x
                self.lazy[L] = x
                L += 1
            L >>= 1
            R >>= 1
          
        self._ascend(Li)
        self._ascend(Ri-1)
  
N, Q = map(int, input().split())
T = Lazysegtree([None]*N, 2**31-1, initialize = False) 
Ans = []
for _ in range(Q):
    t, *q = map(int, sys.stdin.readline().split())
    q[1] += 1
    if t:
        Ans.append(T.query(*q))
    else:
        T.update(*q)
print('\n'.join(map(str, Ans)))


Measured memory_bytes: 17384
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int s;
    cin >> s;
    int a[1000010] = {0};
    int x = s;
    a[s] = 1;
    for(int i = 2;i <=1000000;i++){
        if(x%2){
            x = 3*x + 1;
        }else{
            x = x/2;
        }

        if(a[x] == 1){
            cout << i << endl;
            return 0;
        }else{
            a[x] = 1;
        }
    }


    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 8064
#include <iostream>

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

    if(s.at(0) != s.at(1) || s.at(1) != s.at(2) || s.at(2) != s.at(0)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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 long long INF=1LL << 60;




int main() {
 long long a,b;
 cin>>a>>b;
 long long ret=0;
 if(a==1&&b==1){
   ret=1000000;
 }
 else{
   if(a==1){
     ret+=300000;
   }
   if(a==2){
     ret+=200000;
   }
   if(a==3){
     ret+=100000;
   }
   if(b==1){
     ret+=300000;
   }
   if(b==2){
     ret+=200000;
   }
   if(b==3){
     ret+=100000;
   }
 }
 cout<<ret<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N;
    cin >> N;
    
    if((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])){
        cout << "Yes" << endl;   
    }else {
        cout << "No" << endl;
    }
}

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

int main(){
    int N;
    cin >> N;
    vector<string> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<string> vote(1);
    stack<int> num;
    sort(all(vec));
    vote[0] = vec[0];
    num.push(0);
    int left = 0;
    int right = 0;
    while(right < N){
        if (right == N - 1){
            if (vec[right] == vec[left]){
                num.top()++;
            }
            else{
                vote.push_back(vec[right]);
                num.push(1);
            }
            right++;
        }
        else{
            if (vec[right] == vec[left]){
                num.top()++;
                right++;
            }
            else{
                vote.push_back(vec[right]);
                num.push(0);
                left = right;
            }
        }
    }
    int len = vote.size();
    vector<pair<int,string> > group(len);
    vector<string> ans(0);
    rep(i,len){
        group[i].first = num.top();
        num.pop();
        group[i].second = vote[len - 1 - i];
    }
    sort(all(group));
    repr(i,len - 1){
        if (group[i].first == group[len - 1].first){
            ans.push_back(group[i].second);
        }
    }
    sort(all(ans));
    int len_ans = ans.size();
    rep(i,len_ans){
        cout << ans[i] << endl;
    }
}


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



int main() {
  double dans=0;
  int n;
  cin >>n;
  rep(i,n){
    double d;
    cin >> d;
    dans+=1/d;
  }
  printf("%.12lf\n",1/dans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n==22)
        printf("Christmas Eve Eve Eve\n");
    else if(n==23)
        printf("Christmas Eve Eve\n");
       else if(n==24)
        printf("Christmas Eve\n");
    else if(n==25)
        printf("Christmas\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[110][100100]; 

void chmax( ll &a, ll b){
  if( a < b){ a = b;} return;}

int main(){
  for(ll i = 0; i < 110; i++){for(ll j = 0; j < 100100; j++){ dp[i][j] = 0;}}
  ll N,W; cin >> N >> W;
  vector<ll> w(N); vector<ll> v(N);
  for(ll i = 0; i < N; i++){ cin >> w[i] >> v[i];}
  
  dp[0][w[0]] = v[0];
  
  for(ll i = 0; i < N-1; i++){
    for(ll j = 0; j <= W; j++){
     
      chmax(dp[i+1][j], dp[i][j]);
      
      if(j >= w[i+1]){chmax(dp[i+1][j], dp[i][j-w[i+1]] + v[i+1]);}
      
    }}
  ll res = 0;
  for(ll i = 0; i <= W; i++){ res = max(res, dp[N-1][i]);}
  cout << res << endl; return 0;}
        

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

int main() {
  int n,m;
  string ans = "No";

  cin >> n >> m;

  vector<int> a(n,0);
  int total=0;

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

  int c=0;
  for(int i=0;i<n;i++) {
    if(a[i] >= (double)total/(4*m)) {c++;}
  }

  if(c>=m) ans="Yes";

  //cout << c << " " <<total<<endl;
  cout <<ans << endl;

  return 0;
}


Measured memory_bytes: 256
inf = float('inf')

N,K = map(int,input().split())
ans = inf
X = []
Y = []
XY = []
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
    XY.append((x,y))

X = sorted(X)
Y = sorted(Y)

for i, left in enumerate(X):
    for right in X[i+1:]:
        for j, bottom in enumerate(Y):
            for top in Y[j+1:]:
                cnt = 0
                for x, y in XY:
                    if left <= x <= right and bottom <= y <= top:
                        cnt += 1
                S = (right-left)*(top-bottom)
                if cnt >= K and S < ans:
                    ans = S

print(ans)

Measured memory_bytes: 49132
<?php

fscanf(STDIN,'%s', $s);

$str = str_split($s);

$res = '';
foreach ($str as $index => $char) {
    if ($char === '1') {
        $res .= '1';
    } else if ($char === '0') {
        $res.='0';
    } else{
        if ($res !== ''){
            $res = substr($res, 0, -1);
        }
    }
}

echo $res.PHP_EOL;

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i, a, n, b, x, y, z;
    cin>>n>>a>>b;
    x = n/(a+b);
    y = n%(a+b);
    z = x*a + min(a,y);
    cout<<z<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1)
#define nui 100
#define INF 100000000000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define F(i,a,n) for(ll i=a;i<n;i++)
#define B(i,a,n) for(ll i=n-1;i>=a;i--)
#define tc int t;cin>>t;while(t--)
#define tcf int t;cin>>t;for(int w=1;w<=t;w++)
#define pfn cout<<"-1\n"
#define pfp cout<<"1\n";



using namespace std;


ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

ll fermat_inv(ll y) {return binpow(y, mod - 2);}



int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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



    string s;
    getline(cin, s);
    char a;
    F(i, 0, s.size())
    {
        if (s[i] == 'r')
        {
            a = s[i + 2];
            break;
        }
    }
    cout << "A" << a << "C\n";



    return 0;

}

Measured memory_bytes: 3584
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;

int main() {
	string s;
	cin >> s;
	int coun = 0;
	rep(i, s.size()){
		if (i % 2 == 0) {
			if (s[i] == 'R')coun++;
			if (s[i] == 'U')coun++;
			if (s[i] == 'D')coun++;
		}
		else {
			if (s[i] == 'L')coun++;
			if (s[i] == 'U')coun++;
			if (s[i] == 'D')coun++;
		}
	}
	if (coun == s.size())cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

//abc:141,aoj:---

Measured memory_bytes: 256
N = int(input())
ts = list(map(int,input().split()))
vs = list(map(int,input().split()))

maxv = [0]
for v,t in zip(vs,ts):
    maxv[-1] = min(maxv[-1], v)
    for ti in range(t*2):
        maxv.append(v)
T = len(maxv)

for i in range(T-1):
    maxv[i+1] = min(maxv[i+1], maxv[i] + 0.5)

maxv[-1] = 0
for i in reversed(range(T-1)):
    maxv[i] = min(maxv[i], maxv[i+1] + 0.5)

ans = 0.0
for i in range(T-1):
    ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)


Measured memory_bytes: 3500
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        int ans = 0;
        
        for(int i = 1; i <= n; i++){
            if(a <= calEachNum(i) && calEachNum(i) <= b){
                ans += i;
            }
        }
        
        out.println(ans);
        out.close();
        
    }
    
    public static int calEachNum(int x){
            
        int total = 0;
        boolean isLast = false;
            
        while(!isLast){
            if(x >= 10){
                total += x % 10;
                x /= 10;
            }else{
                total += x;
                isLast = true;
            }
        }
        return total;
    }
}

Measured memory_bytes: 32840
#include <iostream>

using namespace std;


int main(int argc, char *argv[]){
	int d,S;
	while(cin>>d){
		S=0;
		for(int i=0;i<600;i+=d){
			S+=i*i*d;
		}
		cout<<S<<endl;
	}
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    cout << n<<":";
    int fac=2;
    vector<int> factors;
    if (n%fac==0)
    {
        while (n%fac==0)
        {
            factors.push_back(fac);
            n=n/fac;
        }
    }
    fac++;
    while (fac*fac<=n)
    {
        if (n%fac==0)
        {
            while (n%fac==0)
            {
                n/=fac;
                factors.push_back(fac);
            }
        }
        fac+=2;
    }
    if (n!=1) factors.push_back(n);
    for (int i=0;i<factors.size();i++) cout << " " << factors[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
#define MAX_DIST (double)99999999999.0

class Dijkstra{
public:
    struct edge{
        int to;
        double cost;
    };
    int vertex;
    vector<vector<edge>> graph;
    vector<double> dist;

    Dijkstra(int n){
        vertex = n;
        graph = vector<vector<edge>>(n);
        dist = vector<double>(n);
    };

    void dijkstra(int s){
        priority_queue<pdi, vector<pdi>, greater<pdi>> que;
        fill(dist.begin(), dist.end(), MAX_DIST);
        dist[s] = 0;
        que.push(pdi(0, s));

        while (!que.empty()){
            pdi p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < graph[v].size(); i++) {
                edge e = graph[v][i];
                if (dist[e.to] > dist[v] + e.cost && !(dist[e.to] == MAX_DIST && dist[v] == MAX_DIST)){
                    dist[e.to] = dist[v] + e.cost;
                    que.push(pdi(dist[e.to], e.to));
                }
            }
        }

    }

    void addEdge(int from, int to, double cost) {
        edge e;
        e.to = to;
        e.cost = cost;
        graph[from].push_back(e);
    }
};

struct xyr{
    ll x;
    ll y;
    ll r;
};

int main(){
    xyr start, goal;
    int n;
    cin >> start.x >> start.y >> goal.x >> goal.y;
    start.r = 0; goal.r = 0;
    cin >> n;
    vector<xyr> barrier(n+2);
    for(int i = 1; i < n+1; i++){
        cin >> barrier[i].x >> barrier[i].y >> barrier[i].r;
    }
    barrier[0] = start;
    barrier[n+1] = goal;

    Dijkstra d(n+2);
    for(int i = 0; i < n+2; i++){
        for(int j = i+1; j < n+2; j++){
            double cost;
            cost = max(sqrt((barrier[i].x-barrier[j].x)*(barrier[i].x-barrier[j].x)+
            (barrier[i].y-barrier[j].y)*(barrier[i].y-barrier[j].y))-(barrier[i].r+barrier[j].r),0.0);
            d.addEdge(i,j,cost);
            d.addEdge(j,i,cost);
        }
    }
    d.dijkstra(0);
	printf("%.10f\n", d.dist[n+1]);
    return 0;
}


Measured memory_bytes: 22640
//~raam
//~created : Jun 04, 2020 - 2.41.07 PM IST

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

#define ll long long

void solve(){
   ll n, k;
   cin >> n >> k;
   int a[n];
   for(int i = 0; i < n; ++i){
      cin >> a[i];
      --a[i];
   }
   int vis[n] = {};
   int cur = 0;
   vector<int> cycle;
   while(!vis[cur]){
      vis[cur] = 1;
      cycle.push_back(cur);
      cur = a[cur];
   }

   int id = 0;
   for(int i = 0; i < int(cycle.size()); ++i){
      if(cycle[i] == cur){
         id = i;
         break;
      }
   }

   if(k <= id){
      cout << cycle[k] + 1;
   }else{
      k -= id;
      cout << cycle[id + (k % (int(cycle.size()) - id))] + 1;
   }
}

int main(){

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

   int t; t=1;
   while(t--)solve();
}


Measured memory_bytes: 5792
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL A[200000];
 
LL ans = 0;

void solve(){
	sort(A,A+N);//昇順にソート
	//各ペアについて積を取ってそれらのうち大きいものから順に
	//K個取ることを考える
	//取った数のうちK番目の数が最小値なのでこれを2部探索で求める
	LL left = -INF;//ギリギリOKな数値
	LL right = INF;//ギリギリアウトな数値
	while(left+1<right){
		LL center = (left+right)/2;

		//center未満の数がK個以下かどうかを
		//このラムダ式と二部探索で判定する
		auto ok = [&](){
			LL sum = 0;//Aの異なる2つの要素の積のうち、center未満であるものの数
			for(int i=0;i<N;i++){
				if(A[i]>=0){
					int l = -1;//ギリギリOKなインデックス
					int r = N;//ギリギリアウトなインデックス
					while(l+1<r){
						//A[i]とA[i]以外の何かの積のうち
						//center未満であるものの数をcと仮定
						int c = (l+r)/2;
						if(A[i]*A[c]<center) l = c;
						else r = c;
					}
					sum += (LL)l + 1LL;
				}
				if(A[i]<0){
					int l = -1;//ギリギリOKなインデックス
					int r = N;//ギリギリアウトなインデックス
					while(l+1<r){
						//A[i]とA[i]以外の何かの積のうち
						//center未満であるものの数をcと仮定
						int c = (l+r)/2;
						if(A[i]*A[c]<center) r = c;
						else l = c;
					}
					sum += (N-(LL)r);
				}
				if(A[i]*A[i]<center) sum--;
			}
			sum /= 2;
			return sum<K;
		};

		if(ok()) left = center;
		else right = center;
	}

	ans = left;//取った数のうちK番目の数(選んだ数のうち最小値)
}
 
int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N, M;
    scan(N, M);
    auto c = new int[](N);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        c[ai]++;
        c[bi]++;
    }
    auto ok = c.all!(ci => ci % 2 == 0);
    writeln(ok ? "YES" : "NO");
}


Measured memory_bytes: 3708
# https://atcoder.jp/contests/arc062/tasks/arc062_a
# C - AtCoDeerくんと選挙速報

from math import ceil
from decimal import Decimal

N=int(input())
T=[0]*N
A=[0]*N
p=1
q=1
for i in range(N):
    T[i],A[i]=map(int,input().split())
   
    s = ceil(p/T[i])
    t = ceil(q/A[i])
    r = max(s,t)
    p = Decimal(T[i]*r)
    q = Decimal(A[i]*r) 
    #print(p,q)
    
print(p+q)


Measured memory_bytes: 10016
#include<bits/stdc++.h>
#define pdd              pair<double, double>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
 {
    return (a*b)/gcd(a, b);
 }
bool sortByVal(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.second < b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
    fast;
    ll i,j,n,c=0,d=0,e=0,f=0,m,sum=0;
    string a,b,s;
    cin>>a;
    for(i=0;i<(a.size())/2;i++)
    {
        if(a[i]!=a[a.size()-1-i])
        {
            c++;
            break;
        }
    }
    if(c!=0)
    {
        cout<<"No";
    }
    else
    {
        e=(a.size()-1)/2;
        f=(a.size()+3)/2;
        f--;
        b=a.substr(0,e);
        s=a.substr(f);
        if(b==s)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<sstream>
#include<vector>
#include<ctime>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int inf=0x3f3f3f3f;
int main()
{
	IOS;
	ll h,n;
	cin>>h>>n;
	ll x,sum=0,f=0;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		sum+=x;
	}		
	if(h<=sum) 
	{
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

typedef long long lli;

main(){
  lli n, h[501];
  cin >> n;
  h[0] = 0;
  for(int i=1;i<=n;i++) cin >> h[i];
  sort(h, h+n);
  lli ans = 0, pre = 0;
  for(int i=1;i<=n;i++){
    //if(h[i] == h[i-1]) continue;
    lli rem = n - i + 1;
    lli id = min(rem / 4, h[i]);
    lli a = rem * (h[i] - h[i-1]);
    lli b = max(0LL, rem * id - rem * pre) - max(0LL, (id * (id + 1) * 2 - pre * (pre + 1) * 2));
    ans += a - b; 
    pre = id;
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 1176
# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

# struct
class struct:
  def __init__(self,a,b,c):
    self.a=a
    self.b=b
    self.c=c

n=int(input())
if n==2:
  a,b=map(int,input().split())
  print(max(a,b))
  exit()
elif n==3:
  a,b,c=map(int,input().split())
  print(max(gcd(a,b),gcd(a,c),gcd(b,c)))
  exit()
else:
  l=list(map(int,input().split()))
  a=l[0]
  b=l[1]
  c=l[2]
  d=l[3]
  l2=[]
  l2.append(struct(a,b,gcd(a,b)))
  l2.append(struct(a,c,gcd(a,c)))
  l2.append(struct(a,d,gcd(a,d)))
  l2.append(struct(b,c,gcd(b,c)))
  l2.append(struct(b,d,gcd(b,d)))
  l2.append(struct(c,d,gcd(c,d)))
  l2=sorted(l2,key=lambda x:(x.c,x.a,x.b))
  l3=[l2[0].a,l2[0].b,l2[1].a,l2[1].b]
  jama=10000000000000000
  if l3.count(l3[0])>1:
    jama=l3[0]
  if l3.count(l3[1])>1:
    jama=l3[1]
  if l3.count(l3[2])>1:
    jama=l3[2]
  if l3.count(l3[3])>1:
    jama=l3[3]
  mein=100000000000000000
  if jama==a:
    mein=gcd(gcd(b,c),d)
  if jama==b:
    mein=gcd(gcd(a,c),d)
  if jama==c:
    mein=gcd(gcd(a,c),d)
  if jama==d:
    mein=gcd(gcd(b,c),a)
  for x in l[4:]:
    xx=gcd(mein,x)
    yy=gcd(mein,jama)
    if xx<yy:
      jama=x
      mein=yy
    else:
      mein=xx
  print(mein)

Measured memory_bytes: 14164
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);

int main(){
  int N;
  cin >> N;
  ll a[N], tmp[N-1];
  ll sum = 0, ans;
  rep(i, N){
    cin >> a[i];
    sum += a[i];
  }
  tmp[0] = a[0];
  ans = abs(2*tmp[0] - sum);
  if(N>2){
    rep(i, N-2){
      tmp[i+1] = a[i+1]+tmp[i];
      if(abs(2*tmp[i+1] - sum) < ans){
        ans = abs(2*tmp[i+1] - sum);
      }
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3328
K = int(input())


dp = [[1 for _ in range(10)]]
dp
s = [[sum(dp[0][1:i + 1]) for i in range(1, 10)]]
ends = s[0][8]

for j in range(10 * 5):
    dp.append([dp[j][0] + dp[j][1]] + [dp[j][i - 1] + dp[j][i] + dp[j][i + 1]
                                       for i in range(1, 9)] + [dp[j][8] + dp[j][9]])
    s.append([ends + sum(dp[j + 1][1:i + 1]) for i in range(1, 10)])
    ends = s[j + 1][8]
    if ends > 10**5:
        break


def search(jj, ii, m):
    if jj == 0:
        return ii
    else:
        if ii != 0:
            if m <= dp[jj - 1][ii - 1]:
                return (ii) * 10**jj + search(jj - 1, ii - 1, m)
            elif m <= dp[jj - 1][ii - 1] + dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m - dp[jj - 1][ii - 1])
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii - 1] - dp[jj - 1][ii])
        else:
            if m <=  dp[jj - 1][ii]:
                return (ii) * 10**jj + search(jj - 1, ii, m)
            else:
                return (ii) * 10**jj + search(jj - 1, ii + 1, m - dp[jj - 1][ii])


for j in range((len(s))):
    if s[j][8] >= K:
        jj = j
        break
for i in range(9):
    if s[jj][i] >= K:
        ii = i + 1
        if ii > 1:
            m = K - s[jj][i - 1]  # 該当するところの文字で始まる何番目の数かを取得
        else:
            m = K - s[jj - 1][8]
        break

print(search(jj, ii, m))


Measured memory_bytes: 38256
#include<cstdio>
#include<algorithm>
long long int gcd(long long int a, long long int b){
	if(a<b){
		long long int c=a;
		a=b;
		b=c;
	}
	if(a%b==0){
		return b;
	}else{
		return gcd(b, a%b);
	}
}
int main(){
	long long int n,m;
	scanf("%lld%lld",&n,&m);
	char s[n+1]={};
	char t[m+1]={};
	scanf("%s%s",s,t);
	long long int l=n*m/gcd(n ,m);
	int mode=0;
	for(long long int i=0;i<gcd(n, m);i++){
		if(s[l*i/m]!=t[l*i/n]){
			mode=1;
		}
	}
	if(mode==0)printf("%lld\n",l);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

const ll mod = 1000000007;


int main() {
	int n;
	cin >> n;
	vector<ll> as(62, 0);
	rep(i, n) {
		ll a;
		cin >> a;
		int cur = 0;
		while(a > 0) {
			if (a & 1) {
				as[cur]++;
			}
			a = a / 2;
			cur++;
		}
	}
	ll cur = 1;
	ll ans = 0;
	for (int i = 0; i < 62; i++) {
		ll one = as[i];
		ll zero = n - one;
		ll total = (one * zero) % mod;
		ans = (ans + (total * cur) % mod) % mod;

		cur = (2 * cur) % mod;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	cin>>n;
	if (n=="Rainy")
	{
		cout<<"Sunny"<<endl;
	}
	if (n=="Sunny")
	{
		cout<<"Cloudy"<<endl;
	}
	if (n=="Cloudy")
	{
		cout<<"Rainy"<<endl;
	}
	return 0;
 } 

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D){
  	cout << "Balanced";
  }
  else if(A + B > C + D){
  	cout << "Left";
  }
  else if(A + B < C + D){
  	cout << "Right";
  }
}


Measured memory_bytes: 256