akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}
template <class T> T permutation(ll n, ll k) { T f(1); for (ll i=0; i<k; ++i, --n) f *= n; return f; }
template <class T> T factorial(ll n) { return permutation<T>(n,n); }
template <class T> T binomial(ll n, ll k) { return permutation<T>(n,k) /= factorial<T>(k); }

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll a) { n *= a; clamp(); return *this; }
    modint& operator /= (modint const& a) { *this *= a.inv(); return *this; }
    modint& operator += (modint const& a) { n += a.n; if (n >= Mod) n -= Mod; return *this; }
    modint& operator -= (modint const& a) { n -= a.n; if (n < 0) n += Mod; return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint inv() const { return this->pow(Mod-2); }
    ll get() { return n; }
    modint pow(ll p) const {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        return modint(a);
    }
};

const ll Mod = 998244353;
using mint = modint<Mod>;

mint dp[200005];
mint sum[200005];

int main() {
    fastio;
    ll ans=0;
    ll N,K;
    cin >> N >> K;
    vector<pair<int,int>> v;
    rep(i,K) {
        int l,r;
        cin >> l >> r;
        v.push_back({l,r});
    }
    dp[1] = 1;
    sum[1] = 1;
    for (int i=2; i<=N; ++i) {
        for (auto p : v) {
            int lpos = max(i - p.second-1,0);
            int rpos = max(i - p.first,0);
            mint s = sum[rpos] - sum[lpos];
            dp[i] += s;
        }
        sum[i] += dp[i] + sum[i-1];
    }
    cout << dp[N] << endl;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A.at(i);

    int counter1=0;
    int counter2=0;
    for (int i=0;i<N;i++) {
        if (A.at(i)%2==0) {
            if (A.at(i)%3==0||A.at(i)%5==0) { 
                counter1++;
                counter2++;
            }
            else counter2++;
        }
    }

    if (counter1==counter2) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
struct SegmentTree {
    int N;
    vector<T> node;

    SegmentTree(vector<T> &v) {
        int sz = v.size();
        N = 1; while (N < sz) N *= 2;
        node.assign(2*N,0);

        for (int i = 0; i < sz; i++) node[i+N] = v[i];
        for (int i = N-1; i > 0; i--) node[i] = max(node[i<<1|0],node[i<<1|1]);
    }

    void update(int x, T val) {
        x += N;

        node[x] = val;
        while (x > 1) {
            x >>= 1;
            node[x] = max(node[x<<1|0],node[x<<1|1]);
        }
    }

    T getmax(int l, int r) {
        T res = 0;
        l += N; r += N;
        while (l < r) {
            if (l & 1) res = max(res,node[l++]);
            l >>= 1;
            if (r & 1) res = max(res,node[--r]);
            r >>= 1; 
        }

        return res;
    }    
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> h(N),A(N);
    rep(i,N) cin >> h[i];
    rep(i,N) cin >> A[i];

    vector<ll> ans(N+1);
    SegmentTree<ll> sg(ans);
    rep(i,N) {
        ll val = sg.getmax(0,h[i]);
        sg.update(h[i],val+A[i]);
    }

    cout << sg.getmax(0,N+1) << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=998244353;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()


ll a,b,c,d;
const ll s=3005;
vvll dp(s,vll(s,0));

void solve(){
  cin >> a >> b >> c >> d;
  dp[a][b]=1;
  rep(i,a,c+1){
    if(i!=a) dp[i][b]=(b*dp[i-1][b])%mod;
    rep(j,b+1,d+1){
     dp[i][j]=(j*dp[i-1][j])%mod;
	 dp[i][j]+=(i*dp[i][j-1])%mod;
	 dp[i][j]-=((i-1)*(((j-1)*dp[i-1][j-1])%mod))%mod;
     dp[i][j]+=mod;
     dp[i][j]%=mod; 
    }
  }
  
 cout << dp[c][d]%mod << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

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

int main(){
  int N,ma=0,sum=0;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=1;i<N;i++){
    sum+=a.at(i);
  }
  if(sum>a.at(0)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;


int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int x; cin >> x;
    if(x == 7 || x == 5 || x == 3)
        cout << "YES";
    else
        cout << "NO";
    
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
mod=10**9+7
ans=0
A=[0]*k
for i in range(k,0,-1):
  a=0
  A[i-1]=pow((k//i),n,mod)
  m=i*2
  while m<=k:
    A[i-1]=(A[i-1]-A[m-1])%mod
    m=m+i
  ans=(ans+i*A[i-1])%mod
print(ans%mod)

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

using namespace std;

typedef long long LL;
struct Node {
    int root;
    LL diff;
};

int root(int n, vector<Node> &nodes) {
    if(nodes[n].root == n) return n;
    const int r = root(nodes[n].root, nodes);
    nodes[n].diff += nodes[nodes[n].root].diff;
    return nodes[n].root = r;
}

bool unite(int a, int b, vector<Node> &nodes, LL w) {
    const int ra = root(a, nodes);
    const int rb = root(b, nodes);
    if(nodes[ra].root == nodes[rb].root) return false;
    nodes[ra].root = nodes[rb].root;
    nodes[ra].diff = w - nodes[a].diff + nodes[b].diff;
    return true;
}

bool solve() {
    int N, M;
    cin >> N >> M;
    if(!N && !M) return false;

    vector<Node> nodes(N);
    for(int i = 0; i < N; ++i) {
        nodes[i].root = i;
        nodes[i].diff = 0;
    }
    for(int i = 0; i < M; ++i) {
        string cmd;
        cin >> cmd;
        if(cmd == "!") {
            int a, b, w;
            cin >> a >> b >> w;
            --a; --b;
            unite(a, b, nodes, w);
        } else {
            int a, b;
            cin >> a >> b;
            --a; --b;
            root(a, nodes);
            root(b, nodes);
            if(nodes[a].root != nodes[b].root) {
                cout << "UNKNOWN" << endl;
            } else {
                const LL diff = nodes[a].diff - nodes[b].diff;
                cout << diff << endl;
            }
        }
    }
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 4860
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			if (i*M + j*N - 2 * j * i == K) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}


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

int main() {
  double ans = 0.0;
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  for(int i=0;i<n;++i) cin>>x[i]>>y[i];
  
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  
  do {
    double sum = 0.0;
    for (int i=0;i<n-1;++i){
      sum += sqrt(pow(x[p[i+1]] - x[p[i]], 2) + pow(y[p[i+1]] - y[p[i]], 2));
    }
    // cout << fixed << setprecision(7) << sum << endl;
    ans += sum;
  } while(next_permutation(p.begin(), p.end()));

  double div = 1.0;
  for(int i=1;i<n+1;++i){
    div *= i;
  }

  ans /= double(div);
  cout << fixed << setprecision(7) << ans << endl;
  return 0;
}

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

int f(int r,int d,int x){
  return x*r-d;
}

int main(){
  int r,d,x; cin>>r>>d>>x;
  for(int i=0;i<10;i++){
    x = f(r,d,x);
    cout<<x<<endl;
  }
  
  return 0;
}
  

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

string s;
int a[222222], b[222222];

int main(void)
{
	int n, k, c, i;

	cin >> n >> k >> c >> s;
	s = '.' + s;

	int cnta = 0;
	a[0] = -1e8;
	for (i = 1; i <= n; i++)
		if (s[i] == 'o')
			if (i - a[cnta] > c)
				a[++cnta] = i;

	int cntb = 0;
	b[0] = 1e8;
	for (i = n; i >= 1; i--)
		if (s[i] == 'o')
			if (b[cntb] - i > c)
				b[++cntb] = i;

	for (i = 1; i <= min(cnta, k); i++)
		if (a[i] == b[min(cntb, k) - i + 1])
			cout << a[i] << "\n";
	return 0;
}

Measured memory_bytes: 3392
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll n;
vector<ll>a(410);
vector<ll>b(410);
vector<vector<ll> >c(410,vector<ll>(410,-1));
vector<vector<ll> >dp(410,vector<ll>(410,-1));
ll solve(ll x,ll y){
    if(x==y){
        dp[x][y]=0;
        return 0;
    }
    if(dp[x][y]!=-1)return dp[x][y];
    ll res=inf*inf;
    REP(i,x,y){
        res=min(solve(x,i)+c[x][i]+solve(i+1,y)+c[i+1][y],res);
    }
    dp[x][y]=res;
    return dp[x][y];
}
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    b[0]=a[0];
    REP(i,1,n)b[i]=b[i-1]+a[i];
    rep(i,n){
        REP(j,i,n){
            if(i==0)c[i][j]=b[j];
            else {
                c[i][j]=b[j]-b[i-1];
            }
        }
    }
    cout<<solve(0,n-1)<<endl;
}

Measured memory_bytes: 2944
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        var ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine(ab.Sum() % 2 == 0 ? (ab.Sum() / 2).ToString() : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 13396
N = int(input())
S = input()

count = 0
for p in range(10):
    s = S.find(str(p))
    if s == -1:
        continue
    for q in range(10):
        t = S.find(str(q), s + 1)
        if t == -1:
            continue
        for r in range(10):
            u = S.find(str(r), t + 1)
            if u != -1:
                count += 1
print(count)

Measured memory_bytes: 9272
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static StringBuilder sb = new StringBuilder();
static int N,M,K;
    static void Main()
    {
Read1();
result+=(N/500)*1000;
result+=((N%500)/5)*5;
                  Console.WriteLine(result.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

Measured memory_bytes: 13140
import java.util.*;
/*型 変数名[配列サイズ];int day[7]; 
int day[7], value;
day[0] = 3; // 最初の要素を 3 で初期化。
day[1] = 4;
day[2] = 8;
value = day[2]; // 要素2の値をvalueに代入する。value は8になる。
day[0] = 3; // 最初の要素を 3 で初期化。
day[1] = 4;
day[2] = 8;
value = day[2]; // 要素2の値をvalueに代入する。value は8になる。
*/

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        

        int n = sc.nextInt();
        int x;
        int a[] = new int [n];
        
        for(int i = 1; i <= n; i++){
            x=sc.nextInt();
            a[i-1] =x;
        }
        // 
        // 配列の値を出力
//        for(int i = 1; i <= n; i++){
//            System.out.print(a[i-1]);
//        }
            
        for(int i = n-1; 0<=i; i--){

/*int i;
for ( i = 0; i < n; i++ ){
    if ( i ) printf(" "); /* i が1以上のとき、つまり最初の要素ではないとき、空白を出力 */
/*    printf("%d", a[i]);
}
printf("\n");   */
            if(i==0){
             System.out.print(a[i]);        
            }else{
             System.out.print(a[i] + " ");
            }
        }  System.out.println();

    }
}



Measured memory_bytes: 26076
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

# 2文字か3文字
S = list(rs())
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        print(i+1, i+2)
        exit()
for i in range(len(S)-2):
    if S[i] == S[i+2]:
        print(i+1, i+3)
        exit()

print(-1, -1)


Measured memory_bytes: 3956
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int num1 = num/1000;
		int num2 = num%1000/100;
		int num3 = num%100/10;
		int num4 = num%10;
		if(num1==num2){
			if(num2==num3){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			if(num2 == num3){
				if(num4==num3){
					System.out.println("Yes");
				}else{
					System.out.println("No");
				}
			}else{
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1, MAXN = 3e5 + 10, mod = 998244353;
int fc[N], ifc[N];
long long  power(long long a, long long b) {
	if (!b)
		return 1;
	long long rtr = power(a, b / 2);
	if (b % 2)
		return rtr * rtr % mod * a % mod;
	return rtr * rtr % mod;
}
void getFc() {
	fc[0] = ifc[0] = 1;
	for (int i = 1; i < N; i++) {
		fc[i] = 1ll * fc[i - 1] * i % mod;
		ifc[i] = 1ll * ifc[i - 1] * power(i, mod - 2) % mod;
	}
	return;
}
long long ch(int x, int y) {
	return 1ll * fc[y] * ifc[x] % mod * ifc[y - x] % mod;
}
int main() {
	long long n, a, b, k, ans = 0;
	cin >> n >> a >> b >> k;
	getFc();
	for (int i = 0; i <= n; i++) {
		long long rn = k - i * a;
		if (rn >= 0 && rn % b == 0 && rn / b <= n)
			ans = (ans + 1ll * ch(i, n) * ch(rn / b, n) % mod) % mod;
	}
	cout << ans;
}


Measured memory_bytes: 2560
import Data.List

main = do
  str <- getLine
  let [n, k] = map read (words str) ::[Int]
  str <- getLine
  let a = take n $ map read (words str) ::[Int]
  let list = sort $ map (\x -> length x) $ group $ sort a
  if length list <= k
    then print 0
    else print $ sum $ take ((length list) - k) list
  

Measured memory_bytes: 76156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;

#define REP(i,n) for(ll (i) = 0; (i) < (n); ++(i))


signed main(){
    ll n;
    cin >> n;
    V a(n);
    for(auto& x : a)
        cin >> x;

    vector<ll> rui(n+1, 0);
    REP(i,n)rui[i+1] = rui[i] + a[i];

    M f;
    M b;
    REP(i,n+1){
        b[rui[i]] = i;
    }
    for(ll i = n; i >= 0; --i){
        f[rui[i]] = i;
    }
    ll ans = 0;
    for(auto x : f){
        ll pos = x.first;
        if(!(b[pos] - f[pos]))continue;
        ans = max(ans, b[pos] - f[pos]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 31048
#include<bits/stdc++.h>
using namespace std;
const int MAXN = (1<<8)+5;
long long d[MAXN][8];
int n,m;
vector<int>E[10];
int mp[10][10];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--,b--;
        mp[a][b]=1;
        mp[b][a]=1;
    }
    d[1][0]=1;
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                bool ok = (i&(1<<k));
                if(mp[j][k]&&!ok){
                    int next = i|(1<<k);
                    d[next][k] = d[next][k] + d[i][j];
                }
            }
        }
    }
    long long sum = 0;
    for(int i=0;i<n;i++){
        sum+=d[(1<<n)-1][i];
    }
    cout<<sum<<endl;
}


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

typedef long long ll;
#define pii pair<int, int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , m;

int main()
{
    _FastIO;
    cin >> n >> m;
    multiset<int> ms;
    vector<int> v;
    for(int i = 1; i < 2 * m; i += 2){
        v.push_back(i);
    }
    for(int i = 2; i < 2 * n + 1; i += 2){
        v.push_back(i);
    }
    for(int i = 0; i < v.size() - 1; i++){
        for(int j = i + 1; j < v.size(); j++){
            ms.insert(v[i] + v[j]);
        }
    }
    int ans = 0;
    multiset<int>::iterator it;
    for(it = ms.begin(); it != ms.end(); it++){
        if((*it) % 2 == 0)
            ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"yes"<<"\n"
#define no cout<<"no"<<"\n"
#define INF (int)1e4
#define nax (int)1e5+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N 3005
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
// look for  all edge cases
//search for a pattern



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


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1LL<<60)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



vector<pair<int, int>> edge[1000];


long long d1[1000], d2[1000];
bool g[1000];

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

	int n, m;
	cin >> n >> m;
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edge[a].emplace_back(b, c);
	}
	rep(i, n)d1[i] = -INF;
	d1[0] = 0;
	rep(i, n){
		rep(j, n){
			for (auto e : edge[j]){
				d1[e.first] = max(d1[e.first], d1[j] + e.second);
			}
		}
	}
	memcpy(d2, d1, sizeof(d1));
	g[n-1]=true;
	rep(i, n){
		rep(j, n){
			for (auto e : edge[j]){
				d2[e.first] = max(d2[e.first], d2[j] + e.second);
				if (g[e.first])g[j]=true;
			}
		}
	}

	rep(i,n){
		if (d1[i] < d2[i] && g[i]){
			cout << "inf" << endl;
			return 0;
		}
	}
	cout << d1[n - 1] << endl;
	

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
int main()
{
	int s=0,a,n;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		s+=a%2;
	}
	cout<<(s%2?"NO":"YES")<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

bool isPrime(int a){
    bool f=true;
    if(a==2) return f;
    int x=pow(a,0.5)+1;
    for(int i=2;i<=x;++i){
        if(a%i==0) f=false;
    }
    return f;
}

int main(){
    int a;
    cin >> a;
    while(!isPrime(a)){
        ++a;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[85];

int main() {
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    dp[0] = 1000;
    rep(i, N){
        dp[i + 1] = dp[i];
        rep(j, i){
            chmax(dp[i + 1], dp[j] / A[j] * A[i] + dp[j] % A[j]);
        }
    }

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

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
 
int main () {
    
    int n; cin >>n;
    int x = n;

    int ans = 0;
    while (n > 0) {
        ans += n % 10;
        n /= 10;
    }
    
    if (x % ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    int N;
    cin >> N;
    ve<ld> p(N);
    in(N,p);
    
    ve<ve<ld>> dp(N+1,ve<ld>(N+1,0.0));
    dp[0][0] = 1.0;
    
    rep(i,N){
        
        rep(j,N) dp[i+1][j+1] += dp[i][j]*p[i];
        rep(j,N) dp[i+1][j] += dp[i][j]*(1-p[i]);
        
    }

    ld ans = 0.0;
    reps(i,(N+1)/2,N+1) ans += dp[N][i];

    
    outset(10);
    cout << ans << endl;
    
    //outmat(dp);
    

    return 0;
}


Measured memory_bytes: 141056
N, M = [int(elm) for elm in input().split(" ")] 

As = sorted([int(elm) for elm in input().split(" ")], reverse=True)


BCs = []
for i in range(M):
    B, C = [int(elm) for elm in input().split(" ")] 
    BCs.append([B, C])

BCs = sorted(BCs, key=lambda x: -x[1])

out = 0
bc_i = 0
count = 0
B, C = BCs[bc_i]

for A in As:
    if C >= A and bc_i < M:
        while C >= A: 
            #print("plus", B, C, "A", A)
            out += (B*C)

            count += B
            bc_i += 1
            if bc_i == M or count > N:
                break
            B, C = BCs[bc_i]
            
    if count > N:
        out -= C * (count-N)
        break
    elif count == N:
        break

    out += A
    #print("plus", A)
    count += 1

print(out)

Measured memory_bytes: 29560
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;
ll gcd( ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main (void) {
    ll A, B, ans;
    scanf("%lld %lld", &A, &B);
    ans = A * B / gcd(A,B);
    printf("%lld\n", ans);
    return 0;
}

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

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

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
a_set = set([int(input()) for _ in range(m)])
comb_list = [1, 1]
if 1 in a_set:
    comb_list[1] = 0
for i in range(2, n+1):
    if i in a_set:
        comb_list.append(0)
    else:
        comb_list.append((comb_list[-2]+comb_list[-1])%(10**9+7))
print(comb_list[n])


Measured memory_bytes: 13216
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
# from numpy.fft import rfft, irfft
import numpy as np
def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 200003
    P=mod

    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    cur=1
    base=2
    atoi=[0]*P
    itoa=[0]*(P-1)
    cnt=[0]*(P-1)
    for i in range(0,P-1):
        atoi[cur]=i
        itoa[i]=cur
        cur=cur*base%mod

    ta2=0
    for a in A:
        if a==0:
            continue
        i=atoi[a]
        cnt[i]+=1
        ta2+=a*a%P
    rf=np.fft.rfft(cnt, 2*(P-1))
    X = np.rint(np.fft.irfft(rf * rf)).astype(np.int64)
    #printe(X,sum(X))
    ans=0
    for i in range(P-1):
        ans+=itoa[i]*(X[i]+X[P-1+i])

    print(int((ans-ta2)//2))

if __name__ == "__main__":
    main()

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

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for (int i = a; i <= b; i++) {
        if (c%i == 0) {
            count++; 
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int is_prime(int a)
{
    for (int i = 2; i <= sqrt(a) + 0.01; i++)
    {
        if (a%i == 0){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int N;
    cin >> N;
    int count = 0;
    for (int i = 11;;i+=10){
        if (is_prime(i))
        {
            cout << i << " ";
            count++;
            if (count >= N){
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define pii 3.14
#define mod (ll)(1e9 + 7)
#define inf (ll)(1e18)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pi pair<int,int>
#define N (ll)(2e5+5)

void solve()
{
    ll n;
    cin>>n;

    ll arr[n][3],dp[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
            dp[i][j] = 0;
            if(i==0)
                dp[i][j] = arr[i][j];
        }
    }



    for(ll i=1;i<n;i++)
    {
        dp[i][0] = arr[i][0] + max(dp[i-1][1] , dp[i-1][2]);
        dp[i][1] = arr[i][1] + max(dp[i-1][0] , dp[i-1][2]);
        dp[i][2] = arr[i][2] + max(dp[i-1][1] , dp[i-1][0]);
    }

    ll ans = 0;
    for(int j=0;j<3;j++)
        ans = max(ans , dp[n-1][j]);

    cout<<ans<<"\n";
}

int main()
{
    fio;
    ll tc = 1;
   // cin>>tc;
    while(tc--)
    {
        solve();
    }
}


Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
//map<string,int>cnt;
int main()
	{
	int  a,b;
	int x,y,z,maxx;
	scanf("%d%d",&a,&b);
	x=a+b;
	y=a-b;
	z=a*b;
	 maxx=x;
	maxx=max(maxx,y);
	maxx=max(maxx,z);
	printf("%d\n",maxx);


	return 0;
	}

Measured memory_bytes: 384
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
  var A = Math.max(input[0]+input[1],input[0]-input[1],input[0]*input[1]);
  if(A==-0){
  A=0
  }
  console.log(A)
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N=int(input())
d={'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(N):
    d[input()]+=1
print('AC x '+str(d['AC']))
print('WA x '+str(d['WA']))
print('TLE x '+str(d['TLE']))
print('RE x '+str(d['RE']))

Measured memory_bytes: 9208
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()

  val t01 = Array(s.length) { if (it % 2 == 0) {'0'} else {'1'} }
  val t10 = Array(s.length) { if (it % 2 == 0) {'1'} else {'0'} }


  var count01 = 0
  var count10 = 0
  for (i in 0 until s.length)  {
    val c = s[i]
    if (c != t01[i]) count01++
    if (c != t10[i]) count10++
  }

  val ans = Math.min(count01, count10)
  println(ans)
}


Measured memory_bytes: 34452
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define ldb long double
#define clr(x) memset(x,0,sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
const int size1 = 1e5+7;
const int size2 = 1e4;
const ll mod = 1e9+7;
 
// ll fact[size1];
 
// ll pw(ll x,ll y,ll md)
// {
//     if(y==0)return 1;
//     ll p =pw(x,y/2,md);
//     p = (p*p)%md;
//     if(y%2==1)p = (p*x)%md;
//     return p;
// }
// ll gcd(ll a,ll b)
// {
//  if(b==0)return a;
//  a = a%b;
//  return gcd(b,a);
// }
// ll inverse(ll x,ll mod)
// {
//     return pw(x,mod-2,mod);
// }
// ll ncr(ll n,ll r,ll mod)
// {
//     ll num = fact[n];
//     ll den = (fact[r] * fact[n-r])%mod;
//     den = inverse(den,mod);
 
//     ll ans = (num*den)%mod;
//     return ans;
// }
// vector<ll> adj1[size1];
// vector<ll> adj[size1];
// ll d[size1];
// ll n,m;
// void dikstra(ll s)
// {
//     for(ll i=1;i<=n;i++)d[i]=1e9;
//     d[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> q;
//     q.push({0, s});
//     while(!q.empty())
//     {
//         ll v = q.top().ss;
//         ll d_v = q.top().ff;
//         q.pop();
//         if(d_v!=d[v])continue;
//         for(auto to:adj1[v])
//         {
//             ll len = 1;
//             if(d[v] + len < d[to])
//             {
//                 d[to] = d[v]+len;
//                 q.push({d[to],to});
//             }
//         }
//     }
// }
 
// ll smallestPrimeFactor[size1];
 
// void seive(){
//     clr(smallestPrimeFactor);
 
//     for(ll i=2;i<size1;i++){
//         if(smallestPrimeFactor[i]!=0)continue;
//         smallestPrimeFactor[i] = i;
//         for(ll j=2*i;j<size1;j+=i){
//             smallestPrimeFactor[j]=i;
//         }
//     }    
// }
 ll sum[2005][2005];
 ll dp[2005][2005];
int main()
{
    //cout<<setprecision(12)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    
    ll T;
    //cin>>T;
    T = 1;
    while(T--)
    {
        //cout<<"Case #"<<cas<<": ";cas++;
        ll n;cin>>n;
        vector<pll> vi;
        vector<ll> plus,sub;
        for(ll i=0;i<n;i++){
            ll x,y;cin>>x>>y;
            vi.pb(mp(x,y));
            plus.pb(x+y);
            sub.pb(x-y);
        }

        sort(plus.begin(),plus.end());
        sort(sub.begin(),sub.end());

        ll ans = plus[n-1]-plus[0];
        ans = max(ans,sub[n-1]-sub[0]);

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 11476
#include <iostream>
#include <string>

using namespace std;

int main(){
	int ac=0,bc=0;
	for(int i=0;i<3;++i){
		char c;
		cin >> c;
		if(c == 'A')ac++;
		else bc++;
	}
	if(ac == 0||bc == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
}

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

int main(){
    
    //データ定義
    long long dataCnt;
    int minPrice; /*最小価格*/
    int maxValue = -1000000000; /*最大利益*/
    int wPrice; /*一時領域*/

    //データ数を取得
    cin >> dataCnt;

    //最大利益を求める
    cin >> minPrice;
    for(int i = 1; i < dataCnt; i++){
        //データ読み込み
        cin >>  wPrice;
        //最大利益の更新
        maxValue = max(maxValue, wPrice - minPrice);
        //最小価格の更新
        minPrice = min(minPrice, wPrice);
    }

    //結果出力
    cout << maxValue << endl;
}


Measured memory_bytes: 3124
n, m = map(int,input().split())
 
l_p = 1
r_p = n
 
for j in range(m):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

if a > 0:
  print(a)
else:
  print(0)

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int K;
  scanf("%d", &K);
  std::vector<long long > A(K);
  for (int i=0; i<K; i++){
    scanf("%lld", &A[i]);
  }
  long long min=0;
  long long max=10e15;
  //  printf("initial [%lld, %lld]\n", min, max);
  while(max-min>1) {
    //printf("in [%lld, %lld]\n", min, max);
    long long mid = (min+max)/2;
    long long x=mid;
    for (int i=0; i<K; i++) {
      x=x-x%A[i];
    }
    //printf("x=%lld\n", x);
    if (x>=2){
      max=mid;
    } else {
      min=mid;
    }
    //printf("out [%lld, %lld]\n", min, max);
  }
  long long ans1=max; // 2以上となる最小のN
  min=0;
  max=10e15;
  while(max-min>1) {
    long long mid = (min+max)/2;
    long long x=mid;
    for (int i=0; i<K; i++) {
      x=x-x%A[i];
    }
    if (x<=2){
      min=mid;
    } else {
      max=mid;
    }
  }
  long long ans2=min;
  if (ans1>ans2){
    printf("-1\n");
  } else {
    std::cout<<ans1<<" "<< ans2<<std::endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	vector<int> l(n), r(n);
	for(int i = 0; i < n; i++){
		cin>>l[i]>>r[i];
	}
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	if(n&1){
		int k = n/2;
		cout<<r[k] - l[k] + 1<<'\n';
	}else{
		int k = n/2;
		cout<<r[k] + r[k - 1] - l[k] - l[k - 1] + 1<<'\n';
	}

	return 0;
}

Measured memory_bytes: 4768
N,Q = map(int, input().split())
import copy
import sys

sys.setrecursionlimit(10**6)
es = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)


point = [0] * N

for i in range(Q):
    p,x = map(int, input().split())
    point[p-1] += x 

ans = [0] * N
ans[0] = point[0] # 一番上の根なのでこれだけ
visited = [False] * N
visit_cnt = 1
from collections import deque
nexts = deque([0])
while len(nexts) >= 1:
    now = nexts.popleft()
    visited[now] = True

    for next in es[now]:
        if visited[next] == True:
            continue
        nexts.append(next)
        ans[next] = ans[now] + point[next]


print(*ans)

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

int main(){
    int m,d;cin>>m>>d;
    int ans = 0;
    for(int i=1; i<=m; i++){
        for(int j=1; j<=d; j++){
            int d1 = j%10;
            int d10 = j/10;
            if(d1>=2&&d10>=2&&d1*d10==i)ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll h , w, k ; cin >> h >> w >> k;
    vector<string> chc(h);
    rep(i,h) cin >> chc.at(i);

    ll ans = INF;

    for(int i=0;i<(1<<(h-1));i++){
        bitset<12> s(i);
        ll a = s.count();
        vector<ll> x(a+1,0);
        vector<ll> xreset(a+1,0);

        ll hakoidx = 0;
        bool flag = 0;

        ll anskouho = a;
        bool bitflag = 0;

        for(int yk = 0 ;yk < w ;yk++){
            for(int tt = 0;tt<h;tt++){
                if(chc.at(tt).at(yk)=='1') x.at(hakoidx)++;

                if(x.at(hakoidx)>k){
                    flag = 1;
                    break;
                }
                
                if(s[tt]) hakoidx++;
            }

            hakoidx = 0;

            if(flag){
                anskouho++;
                x = xreset;

                for(int tt = 0;tt<h;tt++){
                    if(chc.at(tt).at(yk)=='1')x.at(hakoidx)++;

                    if(x.at(hakoidx)>k){
                        bitflag = 1;
                        break;
                    }
                    
                    if(s[tt]) hakoidx++;
                }

            }

            //cout << yk << " " << anskouho << endl;

            flag = 0;
            if(bitflag) break;
            hakoidx = 0;

        }
        if(bitflag) continue;
        ans = min(ans,anskouho);
        //cout << ans << endl;

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		String result = "no";
		HashSet<Character> hs = new HashSet<Character>();
		for(int i = 0; i < s.length(); i++){
		    hs.add(s.charAt(i));
		}
		if(hs.size() == s.length()) result = "yes";

		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23636
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
ll a[2][n];
fo(i,0,2)
{
    fo(j,0,n)
    cin>>a[i][j];
}
ll ans=0;
fo(d,0,n)
{
temp=0;
fo(j,0,d+1)
temp+=a[0][j];
fo(j,d,n)
temp+=a[1][j];
ans=max(temp,ans);
}
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

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

int main() {
    int N;
    cin >> N;
    int A = 0;
    int B = 0;
    int count = 0;
    int check = 0;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        int M;
        M = s.size();

        if (s.at(0) == 'B') {
            B++;
        }

        if (s.at(M - 1) == 'A') {
            A++;
        }

        if (s.at(0) == 'B' && s.at(M - 1) == 'A') {
            check++;
        }

        for (int j = 0; j < M; j++) {
            if (j != M - 1 && s.at(j) == 'A' && s.at(j + 1) == 'B') {
                count++;
            }
        }
    }

    count += min (A, B);

    if (A == B && B == check && check != 0) {
        count--;
    }
    cout << count << endl;
}

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


#define sf scanf
#define pf printf

using namespace std;



long long ar[100100];


int main()
{
    int n , m , a ;
    long long sum = 0 , b;
    sf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i)
    {
        sf("%lld" , &ar[i]);
        sum = sum + ar[i];
    }
    sf("%d" , &m);
    for(int i = 0 ; i < m ; ++i)
    {
        sf("%d %lld" , &a , &b);
        sum = sum - ar[a];
        sum = sum + b;
        pf("%lld\n" , sum);
        sum = sum - b;
        sum = sum + ar[a];
    }

    return 0;
}


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


int main(){
    int K,A,B;
    cin >> K >> A >> B;
    bool canDivided =false;
    for(int i=A;i<=B;i++)
    {
        if(i%K == 0)
        {
            canDivided = true;
        }
    }

    if(canDivided)
    {
        std::cout << "OK";
    }else{
        std::cout << "NG";
    }

    return 0;
}


Measured memory_bytes: 3652