akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int get_gcd(int n, int m) {
	if (n < m) swap(n, m);
	while (m) {
		swap(n, m);
		m %= n;
	}
	return n;
}

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

	int N, X;
	vector<int> ps;
	cin >> N >> X;
	ps.push_back(X);
	int p;
	int ans = -1;
	rep(i, 0, N)
	{
		cin >> p;
		ps.push_back(p);
	}
	sort(all(ps));
	rep(i, 0, SZ(ps) - 1)
	{
		if (ans == -1)
		{
			ans = ps[i + 1] - ps[i];
		}
		else
		{
			ans = get_gcd(ans, ps[i + 1] - ps[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int a[3];
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	sort(a, a + 3);
	printf("%d\n", a[1] * a[0] / 2);

	Please AC;
}


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

long long mod=998244353;
long long fact[300010];
long long res[300010];
long long poww(long long x,long long n)
{
	if(n==0) return 1;
	else if(n==1) return x;
	else if(n%2==0) return (poww(x,n/2)%mod*poww(x,n/2)%mod)%mod;
	else if(n%2!=0) return (poww(x,n/2)%mod*poww(x,n/2)%mod*x%mod)%mod;
}
long long C(long long k,long long n)
{
	return (fact[n]*res[k]) % mod * res[n-k] % mod;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n,a,b,k;
	cin >> n >> a >> b >> k;
	fact[0]=1,res[0]=1;
    for(long long i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]=fact[i]%mod;
	}
	for(long long i=1;i<=n;i++)
	{
		res[i]=poww(fact[i],mod-2);
		res[i]=res[i]%mod;
	}
	long long ans=0;
	for(long long i=0;i<=n;i++)
	{
		if((k-a*i)%b==0 && (k-a*i)>=0)
		{
			long long t=(k-a*i)/b;
			if(t<=n)
			{
			ans+=(C(t,n) * C(i,n))%mod;
			ans=ans%mod;
		    }
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H, W; cin >> H >> W;
  vector<string> M(H); rep(i,H) cin >> M[i];
  int alp = H*W;
  vector<vector<int>> g(alp, vector<int>(alp,1e9));
  rep(y,H){
    rep(x,W){
      if(x==W-1) continue;
      if(M[y][x] == '.' && M[y][x+1] == '.'){
        g[y*W+x][y*W+x+1] = g[y*W+x+1][y*W+x] = 1;
      }
      //cerr << "z";
    }
  }
  //cerr << "a";
  rep(x,W){
    rep(y,H){
      if(y==H-1) continue;
      if(M[y][x] == '.' && M[y+1][x] == '.'){
        g[y*W+x][(y+1)*W+x] = g[(y+1)*W+x][y*W+x] = 1;
      }
    }
  }
  //cerr << "b";
  rep(i,alp) g[i][i]= 0;
  rep(k,alp) rep(i,alp) rep(j,alp) g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
  int ans = 0;
  rep(y,alp){
    rep(x,alp){
      if(g[y][x] != 1e9){
        ans = max(ans, g[y][x]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

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

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> A(N, -1);
    int ans = 0;
    REP(i, N) {
        int a;
        cin >> a;
        a--;
        if (A[a] == i) ans++;
        A[i] = a;
    }
    cout << ans << endl;

    return 0;
}

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

int n, k, h[100002], dp[100002];

int main(){
	cin >> n >> k;
	for (int i=0;i<n;i++) cin >> h[i];
	dp[0]=0;	
	for (int i=1;i<n;i++){
		dp[i]=1e9;
		for (int j=1;j<=k;j++){
			if (i-j<0) continue;
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                int A = sc.nextInt()-1;
                a[A]++;
            }
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] == 0) ans++;
        }

        System.out.println(ans);
    }
}



Measured memory_bytes: 46120
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main() {
	long long n;
	cin >> n;

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

	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());

	cout << a.size() << endl;

	return 0;
}

Measured memory_bytes: 9600
s = input()
n = len(s)

def helper(i, x, op):
    if i == 4:
        if x == 7:
            return op
        else:
            return ""
    
    op_p = helper(i+1, x+int(s[i]), op + "+" + s[i])
    if op_p != "":
        return op_p
    
    op_m = helper(i+1, x-int(s[i]), op + "-" + s[i])
    if op_m != "":
        return op_m
    
    return ""


result = helper(1, int(s[0]), s[0])
if result == "":
    print(result)
else:
    print(result + "=7")


Measured memory_bytes: 38452
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, a[N], b[N], cur_up;
signed main() {
	cin >> n;
	for(int i = 1; i <= n; ++ i)
		cin >> a[i] >> b[i];
	for(int i = n; i >= 1; -- i) {
		a[i] += cur_up;
		int mul = (a[i] / b[i]) + (a[i] % b[i] != 0);
		cur_up += (b[i] * mul - a[i]); 
	}
	cout << cur_up;
}

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

int main(void){
  int k,n; cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll ans=0;
  int dp=0;
  int posi;
  for(int i=1;i<n;i++){
    dp=max(dp,abs(a[i]-a[i-1]));
    if(abs(a[i]-a[i-1]==dp)) posi=i;
  }
  dp=max(dp,abs(k-(a[n-1]-a[0])));
  cout << k-dp << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int answer = 0;
	for (int C = 1; C <= N; C += 2) {
		int num_of_divisors = 0;
		for (int X = 1; X <= C; ++X) {
			if (C % X == 0) {
				++num_of_divisors;
			}
		}
		if (num_of_divisors == 8) {
			++answer;
		}
	}
	cout << answer << '\n';
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
/*
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
*/
ll ans,n,x;
int main()
{
    scanf("%lld%lld",&n,&x);
    ans=n;
    ll a=n-x,b=x;
    while(a&&b)
    {
        if(a>=b)
        {
            ll t=a/b;
            ans+=b*(t*2-(a%b==0));
            ll c=a;a=b;b=c%b;
        }
        else
        {
            ll t=b/a;
            ans+=a*(t*2-(b%a==0));
            b%=a;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long aaa(long long, long long);
long long t[100] = {};

long long aaa(long long x, long long y)
{
	long long r, x1, y1;
	if (x < y)
	{
		x1 = y;
		y1 = x;
	}
	else
	{
		x1 = x;
		y1 = y;
	}
	r = x1 % y1;
	while (r != 0)
	{
		x1 = y1;
		y1 = r;
		r = x1 % y1;
	}
	return y1;
}

int main()
{
	int n;
	long long ans;
	long long g;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t[i]);
	}
	ans = t[0];
	for (int i = 0; i < n-1; i++)
	{
		g = aaa(ans, t[i + 1]);
		ans *=(t[i + 1] / g);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut d: [i64; n],
    }

    d.sort();

    let ans = d[n/2] - d[n/2-1];

    println!("{}", ans);
}


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

int main(){
    int x;
  cin>>x;
    for(int i=-118;i<120;i++){
        for(int j=-118;j<120;j++){
        if (pow(i,5)-pow(j,5)==x) {
            cout <<i<<" "<<j;
          return 0;
        }
        }
    }
}

Measured memory_bytes: 4024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <unordered_set>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

LL gcd(LL m, LL n) {
    if (m < n) swap(m,n);
    while (n) {
        m %= n;
        swap(m,n);
    }
    return m;
}


void solve() {
    LL a,b;
    cin >> a >> b;
    int ans = 1;
    LL g = gcd(a,b);
    if (g % 2 == 0) {
        ++ans;
        while (g % 2 == 0) g /= 2;
    }
    for (LL i = 3; i * i <= g;i+=2) {
        if (g % i == 0) {
            ++ans;
            g /= i;
        }
        while (g % i == 0) g/= i;
    }
    if (g > 1) ++ans;
    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> vec(9, 0);

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a <= 399) {
			vec[0] = 1;
		}
		else if (a <= 799) {
			vec[1] = 1;
		}
		else if (a <= 1199) {
			vec[2] = 1;
		}
		else if (a <= 1599) {
			vec[3] = 1;
		}
		else if (a <= 1999) {
			vec[4] = 1;
		}
		else if (a <= 2399) {
			vec[5] = 1;
		}
		else if (a <= 2799) {
			vec[6] = 1;
		}
		else if (a <= 3199) {
			vec[7] = 1;
		}
		else {
			vec[8] += 1;
		}

	}

	int types = 0;
	int min = 0, max = 0;

	for (int i = 0; i < vec.size() - 1; i++)
	{
		if (vec[i] == 1) {
			types++;
		}
	}

	min = types;
	max = types;


	if (types == 0) {
		min = 1;
	}

	max += vec[8];



	cout << min << " " << max << endl;





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <tuple>
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const long long INF = 1e18L + 5; // 10^18
#define fastIN  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fastIN
   // freopen("input.in","r",stdin);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
      cout<<"bust";
    else 
    cout<<"win";
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = unsafe { _read_value!(_scanned, $t) };
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub unsafe fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            str::from_utf8_unchecked(target).parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        n: usize,
        m: usize,
        c: i32,
        bs: [i32; m],
        ass: [[i32; m]; n],
    }
    let r = ass
        .into_iter()
        .filter(|as_| as_.iter().zip(&bs).map(|(a, &b)| a * b).sum::<i32>() + c > 0)
        .count();
    println!("{}", r);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,mo=1e9+7;
ll f[N][N],c[N][N];
ll n;
void move(ll &a,ll b){
	a=(a+b)%mo;
}
int main(){
	cin>>n;
	for (int i=0;i<=n;i++){
		c[i][0]=c[i][i]=1;
		for (int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mo;
	}
	f[1][0]=f[1][1]=n;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=i;j++){
			for (int k=max(j,1);k+i<=n;k++){
				if ((j+k)&1)continue;
				for (int x=0;x<=k;x++){
					int j1=abs(k-2*x-j)/2;
					move(f[i+k][j1],f[i][j]*c[n-i][k]%mo*c[k][x]);
				}
			}
		}
	}
	cout<<f[n][0]<<endl;
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static string Sharp(int n)
    {
        var result = "";
        if (n % 2 == 0)
        {
            for (int i = 0; i < n / 2; i++) result += "#.";
        }
        else
        {
            for (int i = 0; i < (n - 1) / 2; i++) result += "#.";
            result += "#";
        }
        return result;
    }
    public static string Dot(int n)
    {
        var result = "";
        if (n % 2 == 0)
        {
            for (int i = 0; i < n / 2; i++) result += ".#";
        }
        else
        {
            for (int i = 0; i < (n - 1) / 2; i++) result += ".#";
            result += ".";
        }
        return result;
    }
    public static void Main()
    {
        var flag = 1;
        while (flag == 1)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0)
            {
                flag = 0;
                goto end;
            }
            var line1 = Sharp(w);
            var line2 = Dot(w);
            if (h % 2 == 0)
            {
                for (int i = 0; i < h / 2; i++)
                {
                    Console.WriteLine(line1);
                    Console.WriteLine(line2);
                }
                Console.WriteLine();
            }
            else
            {
                for (int i = 0; i < (h -1) / 2; i++)
                {
                    Console.WriteLine(line1);
                    Console.WriteLine(line2);
                }
                Console.WriteLine(line1);
                Console.WriteLine();
            }
            end:;
        }


    }
}

Measured memory_bytes: 8720
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    double P[6], Q[6];
    int k;
    for (int i = 0;i < 6;i++) {
        cin >> k;
        P[i] = double(k) / 100.0;
    }
    for (int i = 0;i < 6;i++) {
        cin >> k;
        Q[i] = double(k) / 100.0;
    }
    vector<double> T;
    T.push_back(0.0);
    T.push_back(1.0);
    for (int i = 0;i < 6;i++) {
        if (P[i] == 0.0 || Q[i] == 0.0) continue;
        double r = P[i] / Q[i];
        T.push_back(1.0 / (1.0 + r));
        T.push_back(r / (1.0 + r));
    }
    double sol = 1.0;
    for (int i = 0;i < T.size();i++) {
        double ans = 0.0;
        double p = T[i];
        for (int j = 0;j < 6;j++) {
            ans += max(p * P[j], (1.0 - p) * Q[j]);
        }
        sol = min(sol, ans);
    }
    cout.precision(20);
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 998244353 //((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

ll st[N<<1];
void update(int i, int d) {
    st[i] = d;
    for(i>>=1;i>0;i>>=1) {
        st[i] = (st[i<<1] + st[i<<1|1]) % mod;
    }
}
ll sum_range(int l, int r) {
    ll ret = 0;
    for(;l<r;l>>=1,r>>=1) {
        if(l&1) ret += st[l++];
        if(r&1) ret += st[--r];
    }
    return ret % mod;
}
void solve() {
    int n,k;
    cin>>n>>k;
    vector<pi> v(k);
    REP(i,0,k-1) {
        cin>>v[i].first>>v[i].second;
    }
    update(n+n-1,1);
    REPN(i,n-1,1) {
        for(auto it:v) {
            st[i+n-1] += sum_range(min(n<<1,i+n-1+it.first),min(i+n+it.second,n<<1));
        }
        st[i+n-1] %= mod;
        update(i+n-1,st[i+n-1]);
    }
    cout<<st[n];
    /*
    5 2
    1 1
    3 4

    0 0 0 1 1
    1 2 3 4 5
    */
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 6736
n=int(input())
arr=list(map(int,input().split()))
dp=[[[10**18,10**18] for _ in range(n)] for _ in range(n)]
for i in range(n):
  dp[i][i][0]=arr[i]
  dp[i][i][1]=0
for i in range(1,n):
  for j in range(n-i):
    for k in range(i):
      if dp[j][j+i][1]>dp[j][j+k][0]+dp[j+k+1][j+i][0]+dp[j][j+k][1]+dp[j+k+1][j+i][1]:
        dp[j][j+i][1]=dp[j][j+k][0]+dp[j+k+1][j+i][0]+dp[j][j+k][1]+dp[j+k+1][j+i][1]
        dp[j][j+i][0]=dp[j][j+k][0]+dp[j+k+1][j+i][0]
print(dp[0][n-1][1])

Measured memory_bytes: 88664
#include <iostream>
#include <list>
#include <deque>

using namespace std;

int Q;
deque<int> dqmin1, dqmin2;
deque<int> dqmax1, dqmax2;
list<int> all;

int main(void)
{
	
	while(1){
		cin >> Q;
		if(Q == 0) break;
		
		int type, x;
		
		all.clear(); all.push_back(0);
		dqmin1.clear(), dqmin2.clear();
		dqmax1.clear(), dqmax2.clear();
		auto center = all.begin();
		
		for(int q = 0; q < Q; q++){
			cin >> type;
			
			if(type == 0){
				cin >> x;
				all.push_back(x);
				
				while(dqmin2.size() && dqmin2.back() > x) dqmin2.pop_back();
				dqmin2.push_back(x);
				while(dqmax2.size() && dqmax2.back() < x) dqmax2.pop_back();
				dqmax2.push_back(x);
				
				if(all.size() % 2 == 0){
					center++;
					if(dqmin2.size() && dqmin2.front() == *center) dqmin2.pop_front();
					if(dqmin1.empty() || dqmin1.back() > *center) dqmin1.push_back(*center);
					if(dqmax2.size() && dqmax2.front() == *center) dqmax2.pop_front();
					if(dqmax1.empty() || dqmax1.back() < *center) dqmax1.push_back(*center);
				}
			}
			
			if(type == 1){
				cout << *center << endl;
				
				if(dqmin1.size() && dqmin1.back() == *center) dqmin1.pop_back();
				if(dqmax1.size() && dqmax1.back() == *center) dqmax1.pop_back();
				
				auto tmp = center; tmp++;
				all.erase(center);
				center = tmp;
				
				if(all.size() % 2) center--;
				else{
					if(dqmin2.size() && dqmin2.front() == *center) dqmin2.pop_front();
					if(dqmin1.empty() || dqmin1.back() > *center) dqmin1.push_back(*center);
					if(dqmax2.size() && dqmax2.front() == *center) dqmax2.pop_front();
					if(dqmax1.empty() || dqmax1.back() < *center) dqmax1.push_back(*center);
				}
			}
			
			if(type == 2){
				cout << dqmin1.back() << endl;
			}
			
			if(type == 3){
				cout << dqmin2.front() << endl;
			}
			
			if(type == 4){
				cin >> x;
				cout << dqmin1[dqmin1.size()-x] << endl;
			}
			
			if(type == 5){
				cin >> x;
				cout << dqmin2[x-1] << endl;
			}
			
			if(type == 6){
				cout << dqmax1.back() << endl;
			}
			
			if(type == 7){
				cout << dqmax2.front() << endl;
			}
			
			if(type == 8){
				cin >> x;
				cout << dqmax1[dqmax1.size()-x] << endl;
			}
			
			if(type == 9){
				cin >> x;
				cout << dqmax2[x-1] << endl;
			}
		}
		
		cout << "end" << endl;
	}
	
	return 0;
}


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

int main() {
    int n,d,x,a,sum=0;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        cin>>a;
        sum+=d/a;
        if(d%a!=0){
            sum++;
        }
    }
    cout<<x+sum<<'\n';
	return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int n,k;
  cin>>n>>k;
  vi d(k);
  vector<vi> a(k,vi(n));
  rep(i,k){
    cin>>d[i];
    rep(j,d[i]) cin>>a[i][j];
  }
  vi cnt(n+1,0);
  rep(i,k)rep(j,d[i]){
    cnt[a[i][j]]++;
  }
  int ans=0;
  FOR(i,1,n) if(cnt[i]==0) ans++;

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3604
N, Y = gets.split.map(&:to_i)

N.downto(0) do |x|
  next if 10000 * x > Y
  (N-x).downto(0) do |y|
    z = N - x - y
    if Y == 10000 * x + 5000 * y + 1000 * z
      puts "#{x} #{y} #{z}"
      exit
    end
  end
end

puts "-1 -1 -1"


Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void){
  int q,c,a,n;
  scanf("%d",&q);
  FOR(q){
    scanf("%d %d %d",&c,&a,&n);
    int ans=min(c,min(a,n));
    c=max(c-ans,0);
    a=max(a-ans,0);
    ans+=min(c/2,a);
    c=max(c-2*min(c/2,a),0);
    ans+=c/3;
    PRN(ans);
  }
  return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b, c; cin >> a >> b >> c;
	if (a < c && c < b) {
		cout << "Yes" << endl;
	}
	else if (a > c && c > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
import sys
n, m = map(int, input().split())
check = [list(map(int, input().split())) for i in range(m)]

for i in range(1000):
    x = str(i)
    if len(x) != n:
        continue
    flg = True
    for s, c in check:
        if x[s-1] == str(c):
            pass
        else:
            flg = False
    if flg:
        print(i)
        sys.exit()
print(-1)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    cin>>n>>q;
    vector<tuple<ll,ll,ll>> L(n);
    rep(i,n) cin>>get<1>(L[i])>>get<2>(L[i])>>get<0>(L[i]);
    sort(all(L));
    vector<ll> ans(q,-1);
    map<ll,ll> D;
    set<ll> s;
    rep(i,q){
        ll d;
        cin>>d;
        s.insert(d);
        D[d]=i;
    }
    rep(i,n){
        auto t=L[i];
        ll X=get<0>(t);
        ll S=get<1>(t);
        ll T=get<2>(t);
        auto it=s.lower_bound(S-X);
        while (it != s.end() && *it < T-X ) {
            ans[D[*it]]=X;
			s.erase(it++);
		}
    }
    rep(i,q) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 30080
H,W=map(int,input().split())
Cr = []
for _ in range(H):
  Cr += list(input())
  
from collections import Counter
Cr=Counter(Cr)

cntod=0
cnt4=0

for cr in Cr.most_common():
  c=cr[1]
  if c%2==1:
    cntod+=1
    cnt4+=(c-1)//4
  else:
    cnt4+=c//4
ret = 'No'
if H%2==0 and W%2==0:
  if cntod==0 and cnt4==(H*W)//4:
    ret = 'Yes'
if H%2==0 and W%2==1:
  if cntod==0 and cnt4>=(H*(W-1))//4:
    ret = 'Yes'
if H%2==1 and W%2==0:
  if cntod==0 and cnt4>=((H-1)*W)//4:
    ret = 'Yes'
if H%2==1 and W%2==1:
  if cntod==1 and cnt4>=((H-1)*(W-1))//4:
    ret = 'Yes'
print(ret)

Measured memory_bytes: 3436
import 'dart:async';
import 'dart:io';
import 'dart:convert';

Stream<String> get lineStream =>
    stdin.transform(utf8.decoder).transform(const LineSplitter());

Future<List<String>> readLines() async {
  final lines = <String>[];
  await for (var line in lineStream) {
    lines.add(line);
  }
  return lines;
}

void main() async {
  final lines = await readLines();
  final char0 = '0'.codeUnitAt(0);
  var n = List.from(lines[0].runes.map((e) => e - char0));
  var sum = 0;
  for (var c in n) {
    sum += c;
  }
  print(sum % 9 == 0 ? 'Yes' : 'No');
}


Measured memory_bytes: 17540
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100, maxd = 2020;
int x[maxn], y[maxn];
int cnt[maxd][maxd];
int p[3][maxd][maxd];
long long lim[3];
int main(){
	int n, d; cin >> n >> d;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	for(int i = 0; i < n; i++) cnt[x[i] % d][y[i] % d]++;
	for(int i = 0; i < d; i++) for(int j = 0; j < d; j++) cnt[i + d][j] = cnt[i][j + d] = cnt[i + d][j + d] = cnt[i][j];
	int lo = 1, hi = n * d, ans = n * d;
	while(lo <= hi){
		int mid = (lo + hi)>>1;
		int a = mid / d, b = mid % d;
		lim[0] = 1ll * (a + 1) * (a + 1);
		lim[1] = 1ll * (a + 1) * a;
		lim[2] = 1ll * a * a;
		for(int i = 0; i < 2*d; i++) for(int j = 0; j < 2*d; j++){
			for(int k = 0; k < 3; k++){
				p[k][i][j] = cnt[i][j] <= lim[k];
				if(i) p[k][i][j] += p[k][i-1][j];
				if(j) p[k][i][j] += p[k][i][j-1];
				if(i && j) p[k][i][j] -= p[k][i-1][j-1];
			}
		}
		auto query = [&](int ty, int x, int y, int xe, int ye){
			if(x > xe || y > ye) return 0;
			int ans = p[ty][xe][ye];
			if(x) ans -= p[ty][x - 1][ye];
			if(y) ans -= p[ty][xe][y - 1];
			if(x && y) ans += p[ty][x - 1][y - 1];
			return ans;
		};
		bool ok = false;
		for(int i = 0; i < d; i++){
			for(int j = 0; j < d; j++){
				int p1 = query(0, i, j, i + b - 1, j + b - 1) == b * b;
				int p2 = (query(1, i + b, j, i + d - 1, j + b - 1) + query(1, i, j + b, i + b - 1, j + d - 1)) == 2 * b * (d - b);
				int p3 = query(2, i + b, j + b, i + d - 1, j + d - 1) == (d - b) * (d - b);
				if(p1 && p2 && p3) ok = true;
			}
		}
		if(ok) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 64640
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

X = int(input())
for i in range(100000):
    ans = X + i
    if is_prime(ans):
        break
print(ans)


Measured memory_bytes: 2940
// type a
//a...いけそう
//b...自信がない
//c...お試し
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma endregion



int main() {
	lint n; cin >> n;
	vector<lint> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	lint cnt = 0;
	for (lint i = n - 1; i >= 0; i--) {
		lint d = (a[i] + cnt) % b[i];
		if (d != 0) cnt += b[i] - d;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 4804
n = int(input())
primelist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
v = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(15):
    e = primelist[i]
    k = n
    while k != 0:
        k = k // e
        v[i] += k

x2 = 0
x4 = 0
x14 = 0
x24 = 0
x74 = 0
for e in v:
    if e >= 2:
        x2 += 1
for e in v:
    if e >= 4:
        x4 += 1
for e in v:
    if e >= 14:
        x14 += 1
for e in v:
    if e >= 24:
        x24 += 1
for e in v:
    if e >= 74:
        x74 += 1


sum = 0
sum += max(0, x4 * (x4 - 1) * (x2 - 2) // 2)
sum += max(0, x24 * (x2 - 1))
sum += max(0, x14 * (x4 - 1))
sum += x74
print(sum)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define int long long
using namespace std;
int32_t main(){
	int n, d; cin >> n >> d;
	int res = 0;
	for (int i = 0 ; i < n ; i++) {
		int a, b; cin >> a >> b;
		res += (sqrt((a*a) + (b*b)) <= d);
	}
	cout << res << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_K = 112345;
int win[MAX_K];
int a[105];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) a[i] = nextInt();
  for (int k = 0; k <= K; k++) {
    int can_win = 0;
    for (int i = 0; i < N; i++) {
      if (k - a[i] >= 0 && win[k - a[i]] == 0) {
        can_win = 1;
      }
    }
    win[k] = can_win;
  }
  cout << (win[K] ? "First" : "Second") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[101];
void solve(){
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 2 && i % 2 == 0) cnt++;
	}
	
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using std::string;
using std::queue;
using std::map;
using std::set;
using std::vector;
int n;
map<string,int> mp;
set<string> st[2010]; 
vector<int> edge[2010];
int in[2010];
char s[100010];
int tot;
string str[2010];
bool init()
{
	memset(in,0,sizeof(in));
	for(int i = 0; i < 2010; i++) edge[i].clear();
	tot = 0; mp.clear();
	scanf("%d",&n);
	if(!n) return false;
	for(int i = 0; i < n; i++)
	{
		scanf("%s",s);
	    string tmp = "";
		int j;
		for(j = 0; s[j]!=':'; j++) tmp += s[j];
		if(mp.find(tmp) == mp.end()) mp[tmp] = tot++,str[tot-1] = tmp;
		int fa = mp[tmp];
		tmp = "";
		for(j++;s[j];j++)
		{
			if(s[j]==',' || s[j] == '.')
			{
				if(mp.find(tmp) == mp.end()) mp[tmp] = tot++,str[tot-1]=tmp;
				edge[mp[tmp]].push_back(fa);
				in[fa]++;
				tmp = "";
			}
			else tmp += s[j];
		}
	}
//	for(int i= 0; i < tot; i++) std::cout<<str[i]<<std::endl;
	return true;
}
void solve()
{
	queue<int> Q;
	for(int i = 0; i < tot; i++) st[i].clear();
	for(int i = 0; i < tot; i++) if(!in[i]) 
	{
	//	printf("i=%d\n",i);
		Q.push(i);
		st[i].insert(str[i]);
	}
	while(!Q.empty())
	{
		int fr = Q.front();Q.pop();
		for(int i = 0; i < edge[fr].size(); i++)
		{
			int to = edge[fr][i];
			--in[to];
			for(set<string>::iterator it = st[fr].begin(); it != st[fr].end(); it++)
			{
				st[to].insert(*it);
			}
			if(!in[to])
			{
				Q.push(to);
			}
		}
	}
	printf("%d\n",st[0].size());
}
int main()
{
	while(init())
		solve();
}

Measured memory_bytes: 1784
#include <stdio.h>

int main(void) {
	int min,max;
	int now,nowsum;
	int n,i,j;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		min=0x7fffffff;max=-0x7fffffff;
		for(i=0;i<n;i++) {
			for(j=0,nowsum=0;j<5;j++) {
				scanf("%d",&now);
				nowsum+=now;
			}
			if(nowsum<min)min=nowsum;
			if(nowsum>max)max=nowsum;
		}
		printf("%d %d\n",max,min);
	}
	return 0;
}

Measured memory_bytes: 0
n,a,b = map(int,input().split())
ans = 0

if (b-a)%2 == 0:
  ans = min([(b-a)//2,b-1,n-a])
else:
  ans = min([b-1,n-a,(b-a-1)//2+a,(b-a-1)//2+n-b+1])

# print([(b-a)//2,b-1,n-a])
# print([b-1,n-a,(b-a-1)//2+a,(b-a-1)//2+n-b+1])
print(ans)


Measured memory_bytes: 2940
// Problem : C - Pyramid
// Contest : Virtual Judge - Showdown
// URL : https://vjudge.net/contest/391413#problem/C
// Memory Limit : 1048 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,pp=0;
	cin>>n;
	vi x(n),y(n),h(n);
	loop(i,n)
	{
		cin>>x[i]>>y[i]>>h[i];
		if(h[i])
		pp=i;
	}
	int cx,cy,H;
	loop(i,101)
	{
		loop(j,101)
		{
			bool flag=true;
			H=h[pp]+abs(i-x[pp])+abs(j-y[pp]);
			loop(k,n)
			if(h[k]!=max(0,H-abs(i-x[k])-abs(j-y[k])))
				flag = false;
			if(flag)
			{
				cout<<i<<" "<<j<<" "<<H;
				return 0;
			}
		}
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3604
int main(){
    int W, H, x, y, r;
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    if(W>x && H>y && (x-r)>=0 && (y-r)>=0 && (x+r)<=W && (y+r)<=H){
        printf("Yes\n");}
        else{
            printf("No\n");
        }
    return 0;
}

Measured memory_bytes: 584
a = input().split()
if (max(int(a[0]), int(a[1])) - min(int(a[0]), int(a[1]))) > (max(int(a[0]), int(a[2])) - min(int(a[0]), int(a[2]))):
    print("B")
elif (max(int(a[0]), int(a[1])) - min(int(a[0]), int(a[1]))) < (max(int(a[0]), int(a[2])) - min(int(a[0]), int(a[2]))):
    print("A")


Measured memory_bytes: 3064