akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define forw(i,a,n) for (int i=a;i<n;i++)
#define ford(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
#define SZ(x) ((int)(x).size())

typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;

const ll mod=1000000007;
const int maxn = 1e5 + 3;
void mf(){
	freopen("input.in","r",stdin);
	//freopen("output.ou","w",stdout);
}
//START SOL
ll a[maxn], f[maxn];
int n, k;
void minself(ll& a, ll b){
	a = min(a,b);
}
void solve(){
	cin>>n; k = 2;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 2; i <= n; i++){
		f[i] = 1e9 + 5;
		for(int j = 1; j <= k; j++){
			if(i - j < 1) break;
			minself(f[i], f[i-j] + abs(a[i] - a[i-j]));
		}
	}
	cout<<f[n]<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);
	#ifdef tuanh
		mf();
	#endif
	solve();
	return 0;
}

Measured memory_bytes: 1792
s = input()
n = len(s)
sum = 0
# 数字の間を全探索
for i in range(2**(n-1)):
    f = ""
    for j in range(n):
        f += s[j]
        # iを右にj個削り、1桁目のビットが1かどうか
        if i>>j & 1 == 1:
            f += "+"
    sum += eval(f)
print(sum)

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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    int n; cin >> n;
    int ans=0;
    if(n>=105) ans++;
    if(n>=135) ans++;
    if(n>=165) ans++;
    if(n>=189) ans++;
    if(n>=195) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back
int cnt[100005];
main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for(int i=1; i<=100; i++){
		for(int j=1; j<=100; j++){
			for(int k=1; k<=100; k++){
				int val=i*i+j*j+k*k+i*j+i*k+j*k;
				cnt[val]++;
			}
		}
	}
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		cout<<cnt[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4116
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int size=s.length();
    int k=0;

    for(int i=0;i<size;i++){
        if(i%2==0){
            if(s[i]=='R'){
                continue;
            }
            else if(s[i]=='L'){
                cout<<"No"<<endl;
                k=1;
                break;
            }
        }
        else{
            if(s[i]=='L'){
                continue;
            }
            else if(s[i]=='R'){
                cout<<"No"<<endl;
                k=1;
                break;
            }
        }
    }
    if(k==0){
        cout<<"Yes"<<endl;
    }
    return 0;
}


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL a, b, c;
    cin >> a >> b >> c;

    for(LL i = 1; i <= b; i++){
        if((i * a) % b == c)
            return cout << "YES\n", 0;
    }

    cout << "NO\n";
    return 0;
}



Measured memory_bytes: 256
from collections import Counter

N = int(input())
D = Counter(list(map(int, input().split())))
M = int(input())
T = Counter(list(map(int, input().split())))

res = "YES"

for i in T:
  if i not in D or T[i] > D[i]:
    res = "NO"
    break

print(res)

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

#define int long long

int32_t main()
{
      int n;
      cin >> n;
      vector<int> A(n + 1);
      int total = 0;
      for(int i = 0; i < n + 1; i++)
      {
            cin >> A[i];
            total += A[i];
      }
      vector<int> B(n);
      for(int i = 0; i < n; i++)
            cin >> B[i];

      for(int i = 0; i < n; i++)
      {
            if(A[i] <= B[i])
            {
                  B[i] -= A[i];
                  A[i] = 0;
                  if(A[i + 1] <= B[i] )
                  {
                        A[i + 1] = 0;
                  }
                  else
                        A[i + 1] -= B[i];

            }
            else
            {
                  A[i] -= B[i];
            }
      }
      int alive = 0;
      for(int i = 0; i < n+1; i++)
            total -= A[i];
      cout << total ;
      return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int k, n;
    cin >> k >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    a.push_back(a[0] + k);
    
    int l = 0;
    rep(i, n) {
        l = max(l, a[i+1]-a[i]);
    }

    cout << k - l << endl;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n;
    cin>>n;

    vector <int> a(n);
    int s=0;
    loop(i,0,n)
    {
        cin>>a[i];
        s+=a[i];
    }
    vector <int> suf(n);
    suf[n-1]=0;

    for(int i=n-2;i>=0;i--)
    {
        suf[i]=(suf[i+1]+a[i+1])%mod;
    }
    int ans=0;

    loop(i,0,n)
    {
        ans=(ans+((a[i]*(suf[i])))%mod)%mod;
    }

    cout<<ans;




    return 0;
}


Measured memory_bytes: 6368
fn main() {
    let input = read_vec::<i32>();
    let n = input[0];
    let y = input[1];

    for a in 0..n+1 {
        for b in 0..n-a+1 {
            let c = n - a - b;
            let res = a * 10000 + b * 5000 + c * 1000;
            if res == y {
                println!("{} {} {}", a, b, c);
                return;
            }
        }
    }

    println!("-1 -1 -1");
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n;cin>>n;
    string s;cin>>s;
    string ans=s;
    rep(i,s.size()){
        int x=s[i]-'A';
        x=(x+n)%26;
        s[i]='A'+x;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long ea(long, long);

int main()
{
	long a,b,c,d;
	long countC,countD;
	long l,g;
	long ans1,ans2;

	scanf("%ld %ld %ld %ld", &a,&b,&c,&d);

	countC = b/c;
	countD = b/d;
	g = ea(c,d);
	l = c*d/g;
	ans1 = b - countC - countD + b/l;

	countC = (a-1)/c;
	countD = (a-1)/d;
	g = ea(c,d);
	l = c*d/g;
	ans2 = (a-1) - countC - countD + (a-1)/l;

	printf("%ld\n",(ans1-ans2));

	return 0;
}

long ea(long c, long d )
{
	long g,x;
	while(1)
	{
		if(c%d!=0) 
		{
			x = c;
			c = d;
			d = x%d;	
	}
		else
		{
			g = d;
			break;
		}
	}
	return g;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int h,w;
  char s[50][50];
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> s[i][j];
    }
  }
  bool ans = true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.') continue;
      int count = 0;
      if(j!=0 && s[i][j-1]=='#') count++;
      if(i!=0 && s[i-1][j]=='#') count++;
      if(j!=w-1 && s[i][j+1]=='#') count++;
      if(i!=h-1 && s[i+1][j]=='#') count++;
      if(count == 0) ans = false;
      if(!ans) break;
    }
    if(!ans) break;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int[] count = new int[27];
        String s;
        while(sc.hasNext()){
            s = sc.next();
            s = s.toLowerCase();
            for(int i=0;i<s.length();i++){
                int w = s.charAt(i);
                if(w-'a'>=0&&w-'a'<26){
                    count[w-'a']++;
                }
            }   
        }
        for(int j=0;j<26;j++){
            char c = (char)('a'+j);
            System.out.println(c+" : "+count[j]);
        }
    }
}


Measured memory_bytes: 26068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define EPS 1e-9
#define mp make_pair
#define x first
#define y second
const double PI = acos(-1);
const int N = 200010;
const ll oo = 1e18;
typedef pair<int, int> pii;

int n , m, da[N], db[N];
bool rmv[N];

vector<int> g[N];

char tmp[N];

set<pii> s1, s2;

int main() {
	cin >> n >> m;
	scanf("%s", tmp + 1);
	for (int u, v, i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) {
		for (auto v : g[i]) {
			if (tmp[v] == 'A')
				da[i]++;
			else
				db[i]++;
		}
		s1.insert(mp(da[i], i));
		s2.insert(mp(db[i], i));
	}
	while ((s1.size() && (*s1.begin()).x == 0) || (s2.size() && (*s2.begin()).x == 0)) {
		int rm = -1;
		if (s1.size() && (*s1.begin()).x == 0) {
			rm = (*s1.begin()).y;
		} else {
		  rm = (*s2.begin()).y;
		}
		rmv[rm] = 1;
		s1.erase(mp(da[rm], rm));
		s2.erase(mp(db[rm], rm));
		for (auto v : g[rm]) {
			if (rmv[v])continue;
			s1.erase(mp(da[v], v));
			s2.erase(mp(db[v], v));
			da[v] -= (tmp[rm] == 'A');
			db[v] -= (tmp[rm] == 'B');
			s1.insert(mp(da[v], v));
			s2.insert(mp(db[v], v));
		}
	}
	if(s1.size()){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 29952
#include<iostream>
#include<string>
#include<array>
#include<vector>
using namespace std;

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

	int size = s.size();

	for(int i=0;i<size;i++){
		cout<<'x';
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 3628
A, B, C, K = map(int, input().split())

ans = 0

if K > 0:
    ans += min(K, A) * 1
    K -= A

if K > 0:
    ans += min(K, B) * 0
    K -= B

if K > 0:
    ans += min(K, C) * (-1)
    K -= C

print(ans)

Measured memory_bytes: 9116
L,R = map(int,input().split())

ans = 2019
for i in range(L,R+1):
    if i % 2019 == 0:
        ans = 0
        break

if ans != 0:
    for j in range(L,R+1):
        for i in range(L,j):
            if i * j % 2019 < ans:
                ans = i * j % 2019

print(ans)


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n; cin >> n, n;){
        vs str(n);
        rep(i, n) cin >> str[i];

        set<int> del;
        rep(i, n){
            rep(j, n){
                if(i == j || str[j].size() < str[i].size()) continue;

                rep(k, str[j].size() - str[i].size()){
                    if(str[j].substr(k, str[i].size()) == str[i]){
                        del.insert(i);
                    }
                }
            }
        }
        for(auto itr = del.rbegin(); itr != del.rend(); itr++){
            str.erase(str.begin() + *itr);
        }
        n -= del.size();

        vector<vs> sub(n, vs(n));
        rep(i, n){
            rep(j, n){
                if(i == j) continue;

                sub[i][j] = str[j];
                for(int k = min(str[i].size(), str[j].size()); k > 0; k--){
                    if(str[j].substr(0, k) != str[i].substr(str[i].size() - k, k)) continue;

                    sub[i][j].erase(0, k);
                    break;
                }
            }
        }


        vector<vs> dp(1 << n, vs(n));

        rep(i, 1 << n){
            rep(j, n){
                if(dp[i][j] == "" && i != 0) continue;

                rep(k, n){
                    if(i & (1 << k)) continue;
                    int next_idx = i | (1 << k);

                    string next_str = dp[i][j] + (i == 0 ? str[k]:sub[j][k]);

                    if(dp[next_idx][k] == ""){
                        dp[next_idx][k] = next_str;
                        continue;
                    }
                    
                    if(dp[next_idx][k].size() > next_str.size()) dp[next_idx][k] = next_str;
                    else if(dp[next_idx][k].size() == next_str.size()) dp[next_idx][k] = min(dp[next_idx][k], next_str);
                }
            }
        }

        string res = dp[(1 << n) - 1][0];
        range(i, 1, n){
            if(res.size() > dp[(1 << n) - 1][i].size()) res = dp[(1 << n) - 1][i];
            else if(res.size() == dp[(1 << n) - 1][i].size()) res = min(res, dp[(1 << n) - 1][i]);
        }

        cout << res << endl;
    }

	return 0;
}

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

using namespace std;

int arr[51];
long long d[51][51][2501];

int main() {
	int n, a;
	scanf("%d %d", &n, &a);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &arr[i]);

	d[0][0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j)
			for (int k = 0; k <= 2500; ++k) {
				d[i][j][k] = d[i - 1][j][k];
				if (j - 1 >= 0 && k - arr[i] >= 0)
					d[i][j][k] += d[i - 1][j - 1][k - arr[i]];
			}

	long long ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= 2500; ++j)
			if (j % i == 0 && j / i == a)
				ans += d[n][i][j];

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 49152
s = input()
#S = list(map(input().split()))
#s = [1 if i=='R' else 0 for i in S]

ans=[0]*len(s)
start=0
for i in range(len(s)-1):
    if s[i]=='R' and s[i+1]=='L':
        j=i
        ans[j]+=((i-start+1)//2)+((i-start+1)%2)
        ans[j+1]+=((i-start+1)//2)
    if s[i]=='L' and s[i+1]=='R':
        start = i+1
        ans[j]+=((i-j)//2)
        ans[j+1]+=((i-j)//2)+((i-j)%2)
    
    if i==len(s)-2:
        ans[j]+=((i+1-j)//2)
        ans[j+1]+=((i+1-j)//2)+((i+1-j)%2)
        
        
print(''.join(str(x)+' ' for x in ans)[:-1])

Measured memory_bytes: 54692
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 0
  W = 1
  for i in range(1, N+1):
    if i in g:
      if i-prev_i != 1:
        W = (W * pow(B, i-prev_i, M)) % M
      else:
        W = (W * B) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, W = i, W
  
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

Measured memory_bytes: 61324
#include <stdio.h>
 
int main(void) {
    int h, w;
    int i, j;
     
    while (scanf("%d %d", &h, &w), h || w) {
 
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++) {
                putchar('#');
            }
            puts("");
        }
        puts("");
    }
    return 0;
}


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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());

            char[] CS = new char[N];
            char check = S[K-1];

            for(int i=0; i<N; i++)
            {
                if(S[i] == S[K - 1])
                {
                    CS[i] = S[i];
                }
                else
                {
                    CS[i] = '*';
                }
            }

            string ans = new string(CS);
            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
 
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  vector<bool> s(n+10,true);
  vector<long long> dp(n+10,0);
  for(int i=0;i<m;i++){
    cin>>a[i];
    s[a[i]]=false;
  }
  dp[0]=1;
  if(s[1]) {
    dp[1]=1;
  }
  else{
    dp[1]=0;
  }
  for(int i=1;i<n+1;i++){
    if(s[i+1]){
      dp[i+1]=dp[i]+dp[i-1];
      dp[i+1]%=(1000000000+7);
    }
    else{
      dp[i+1]=0;
    }
  }
  cout<<dp[n]<<endl;
  
  
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e+9+7;
ll tic(ll n){
    return (n*(n+1))/2;
}

int main(){
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int i=k; i<=n+1; i++){
        ans = (ans + (tic(n) - (tic(n-i))) - tic(i-1) + 1) % MOD; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 61;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<lint> w(n), d(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> d[i];
    }
    lint ng    = 0;
    lint ok    = inf;
    auto check = [&](lint mid) {
        lint cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (w[i] <= mid)
                cnt += 1 + (mid - w[i]) / d[i];
        }
        return cnt >= k;
    };
    while (abs(ok - ng) != 1) {
        lint mid               = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)

using namespace std;
using namespace __gnu_pbds; 

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    if(a.ss==b.ss)return a.ff<b.ff;
    return a.ss < b.ss;
}

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

int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k,V=0,W=0;
    cin>>n>>k;
    vpll v(n);
    from(i,n){
        ll a,b;
        cin>>a>>b;
        v[i]=mb(a,b);
        V+=b;
        W+=a;
    }
    //sort(all(v),func);
    if(k>=W)cout<<V;
    else {
        ll ar[n][V];
        ll mn=v[0].ff,ans=0;
        //memset(ar,0,sizeof(ar));
        from(i,n){
            mn=min(mn,v[i].ff);
            ar[i][0]=mn;
        }    
        from(i,V){
            if(i<=v[0].ss-1)ar[0][i]=v[0].ff;
            else ar[0][i]=inf;
            //cout<<ar[0][i]<<" ";
        }    
        //cout<<"\n";
        //cout<<ar[n][k];
        for(ll i=1;i<n;i++){
            for(ll j=1;j<V;j++){
                if(v[i].ss>=j+1)ar[i][j]=min(ar[i-1][j],v[i].ff);
                else ar[i][j]=min(ar[i-1][j],v[i].ff+ar[i-1][j-v[i].ss]);
            }
        }
        for(ll i=0;i<n;i++){
            for(ll j=0;j<V;j++)
                if(ar[i][j]<=k){
                    ans=max(ans,j+1);
                }
        }
        cout<<ans;
    }
}    

Measured memory_bytes: 81080
N, M = map(int, input().split())
A = [input() for k in range(N)]
B = [input() for k in range(M)]

for k in range(N-M+1):
    for l in range(len(A[0])-len(B[0])+1):
        t = 0
        for p in range(len(B[0])):
            for q in range(M):
                if A[k+q][l+p] == B[q][p]:
                    t += 1
        if t == len(B[0])*M:
            print("Yes")
            exit(0)
print("No")

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

int main() {
  int h,w;
  cin>>h>>w;
  char a[h+1][w+1];
  int b[h+1][w+1];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
      b[i][j]=0;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i-1>=0&&a[i-1][j+1]=='#')b[i][j]++;
      if(j-1>=0&&a[i+1][j-1]=='#')b[i][j]++;
      if(a[i+1][j]=='#')b[i][j]++;
      if(a[i][j+1]=='#')b[i][j]++;
      if(a[i+1][j+1]=='#')b[i][j]++;
      if(i-1>=0&&a[i-1][j]=='#')b[i][j]++;
      if(j-1>=0&&a[i][j-1]=='#')b[i][j]++;
      if(i-1>=0&&j-1>=0&&a[i-1][j-1]=='#')b[i][j]++;        
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#')cout<<'#';
      else cout<<b[i][j];
    }
    cout<<endl;
  }
  return 0;
}
  

  

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = []
l1 = 1
l2 = 1 + M + 1
for i in range(M):
    now = M - i
    if i % 2 == 0:
        ans.append([l1, l1 + now])
        l1 += 1
    else:
        ans.append([l2, l2 + now])
        l2 += 1
for row in ans:
    print(row[0], row[1])


Measured memory_bytes: 22604
#include <stdio.h>
#include <string.h>
char s[101];
main()
{
  int i,r1,r2,len,f;
  char c;
  while(scanf("%s",s) && s[0] != '#')
  {
    r1=0;
    r2=1;
    len=strlen(s);
    for(i=len-1,f=0;i>=0;i--)
      {
	c=s[i];
	if(c=='n' || c=='w')
	  {
	    if(c=='w')
	      r1++;
	    else if(f==1)
	      r1--;
	    f=1;
	    r2 <<=1,r1 <<=1;
	  }
      }
    r1*=45;
    r2>>=1;

    if((r1 & 1)==0 && r2 >1)
      r1/=2,r2/=2;

    if(r2>1)
      printf("%d/%d\n",r1,r2);
    else
      printf("%d\n",r1/r2);
  }
  return(0);
}

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

using namespace std;
#define ll long long int
const int MAXN = 2e5 + 10;

vector<int> g[MAXN];

void bipartition(int u, int p, vector<vector<int>> &bipartitions, int id){
    bipartitions[id].push_back(u);
    for( auto & v: g[u] ){
        if( v != p ){
            bipartition(v, u, bipartitions, id ^ 1);
        }
    }
}

void solve(){
    int n; cin >> n;
    for(int i = 1; i < n; ++i){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<vector<int>> numbers(3);
    for(int i = 1; i <= n; ++i){
        numbers[i % 3].push_back(i);
    }

    vector<vector<int>> bipartitions(2);
    bipartition(1, 0, bipartitions, 0);

    if(bipartitions[0].size() >= bipartitions[1].size() ){
        swap(bipartitions[0], bipartitions[1] );
    }

    vector<int> p(n + 1);
    if( bipartitions[0].size() >= numbers[1].size() and bipartitions[1].size() >= numbers[2].size() ){
        for(int i = 0; i < 2; ++i){
            for(auto & u: bipartitions[i]){
                if( !numbers[i + 1].empty() ){
                    p[u] = numbers[i + 1].back();
                    numbers[i + 1].pop_back();
                } else {
                    p[u] = numbers[0].back();
                    numbers[0].pop_back();
                }
            }
        }
    } else {
        for(int i = 0; i < 2; ++i){
            for(auto & u: bipartitions[i] ){
                for(int j = 0; j < 3; ++j){
                    if( !numbers[j].empty() ){
                        p[u] = numbers[j].back();
                        numbers[j].pop_back();
                        break;
                    }
                }
            }
        }
    }

    for(int i = 1; i <= n; ++i){
        cout << p[i] << " ";
    }
    cout << '\n';

}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}


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

int main(){
    int N;
    cin>>N;
    for(int x = 111; x <= 999; x += 111){
        if(x >= N){
            cout<<x<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
/*input
1
1000000000
*/

#include<bits/stdc++.h>

using namespace std;

#define sz 100005

int input[sz];

bool check_back(int x)
{
	if(x<0){
		return false;
	}
	if(x <= 0){
		return true;
	}

	if(input[x] >= input[x-1]){
		return check_back(x-1);
	}
	else if(input[x] >= input[x-1] - 1){
		input[x-1] --;
		return check_back(x-1);
	}
	return false;
}

int main(){
	int N;
	cin>>N;
	for(int i=0; i<N; i++)
	{
		cin>>input[i];
	}
	if(check_back(N-1)){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}


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

int main(){

int a,b;
char op;

while(1){
    cin>>a>>op>>b;

    if(op=='+'){
        cout<<a+b<<endl;
    }else if(op=='-'){
        cout<<a-b<<endl;
    }else if(op=='*'){
        cout<<a*b<<endl;
    }else if(op=='/'){
        cout<<a/b<<endl;
    }else if(op=='?'){
        break;
    }

}
    return 0;
}


Measured memory_bytes: 3048
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

template <typename T>
class Segtree {
private:
    int n;
    vector <T> tr;
    T neutral_tr = {};

    T merge(T a, T b) {
        T ans;
        int i = 0, j = 0;
        while (i < sz(a) && j < sz(b)) {
            if (a[i] < b[j])
                ans.pb(a[i++]);
            else
                ans.pb(b[j++]);
        }
        while (i < sz(a))
            ans.pb(a[i++]);
        while (j < sz(b))
            ans.pb(b[j++]);
        return ans;
    }

    int smaller(int v, int x) {
        return lower_bound(all(tr[v]), x) - tr[v].begin();
    }

    template <typename U>
    void build(const vector <U>& a) {
        forn (i, 0, n) 
            tr[i + n] = {a[i]};
        for (int i = n - 1; i > 0; i--)
            tr[i] = merge(tr[2 * i], tr[2 * i + 1]);
    }
public:
    template <typename U>
    Segtree(const vector <U>& a) : n(sz(a)) {
        tr.resize(2 * n, neutral_tr);
        build(a);
    }

    Segtree(int _n) : n(_n) {
        tr.resize(2 * n, neutral_tr);
    }

    int get(int l, int r, int x) {
        int ans = 0;
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l % 2)
                ans += smaller(l++, x);
            if (r % 2)
                ans += smaller(--r, x);
        }
        return ans;
    }
};

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    map <int, int> lst;
    vector <int> a(n), prevs(n);
    forn (i, 0, n) {
        int x;
        cin >> x;
        a[i] = x;
        if (lst.find(x) == lst.end())
            prevs[i] = -1;
        else
            prevs[i] = lst[x];
        lst[x] = i;
    }
    Segtree <vector <int>> tr(prevs);
    while (q --> 0) {
        int l, r;
        cin >> l >> r, --l;
        cout << tr.get(l, r, l) << "\n";
    }
    return 0;
}

Measured memory_bytes: 119672
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: chars,
    k: usize,
  }
  let n: Vec<_> = n.into_iter().map(|c| c as i64 - '0' as i64).collect();
  let mut same = vec![vec![0; k+1]; n.len()+1];
  let mut less = vec![vec![0; k+1]; n.len()+1];
  same[0][0] = 1;
  for i in 0 .. n.len() {
    for c in 0 .. k + 1 {
      if n[i] == 0 {
        same[i+1][c] += same[i][c];
      }
      if c > 0 && n[i] != 0 {
        same[i+1][c] += same[i][c-1];
      }
      less[i+1][c] = less[i][c];
      if n[i] != 0 {
        less[i+1][c] += same[i][c];
      }
      if c > 0 {
        less[i+1][c] += less[i][c-1] * 9;
        if n[i] > 1 {
          less[i+1][c] += same[i][c-1] * (n[i] - 1);
        }
      }
    }
  }
  // dbg!(&same);
  // dbg!(&less);
  puts!("{}\n", same[n.len()][k] + less[n.len()][k]);
}


Measured memory_bytes: 4352
n, y = map(int, input().split())

flg = 0

def calc():
    global flg
    for i in range(n + 1):
        for j in range(n + 1):
            k = n - (i + j)
            if k < 0:
                break
            y_now = 10000 * i + 5000 * j + 1000 * k
            if i + j + k == n and y_now == y:
                print(i,j,k)
                flg = 1
                return

    if flg != 1:
        print('-1', '-1', '-1')

calc()


Measured memory_bytes: 3060
import collections as c
ip = lambda : map(int, input().split())

#################
N = int(input())
mod = 1000000007
A=0
T=1
C=2
G=3
dp = [[[[0,0,0,0] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]

for j in range(4):
    for k in range(4):
        for l in range(4):
            dp[3][j][k][l] = 1
dp[3][A][G][C],dp[3][A][C][G],dp[3][G][A][C] = 0,0,0

for i in range(4,N+1):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                dp[i][j][k][l] += (dp[i-1][A][j][k]+dp[i-1][T][j][k]+dp[i-1][C][j][k]+dp[i-1][G][j][k]) % mod
                dp[i][j][k][l] %= mod



    dp[i][A][G][C],dp[i][A][C][G],dp[i][G][A][C] = 0,0,0

    dp[i][T][G][C] -= dp[i-1][A][T][G]

    dp[i][G][G][C] -= dp[i-1][A][G][G]
    #dp[i][G][A][C] -= dp[i-1][A][G][A]
    dp[i][G][T][C] -= dp[i-1][A][G][T]

r = 0
for j in range(4):
    for k in range(4):
        r += sum(dp[N][j][k])
        r %= mod
print(r%mod)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
  int h,w;cin >>h>>w;
  vector<int>mx(h,-1);
  vector<int>mint(h,INF);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char a;cin >>a;
            if(a=='#'){
                mx[i]=max(mx[i],j);
                mint[i]=min(mint[i],j);
            }
        }
    }
    bool flg=true;
    for (int i = 0; i < h-1; ++i) {
        if(mx[i]>mint[i+1])flg=false;
        if(mint[i]==INF)flg=false;
    }
    if(flg)puts("Possible");
    else puts("Impossible");
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
 public class Main{
   public static void main(String[] args){
     Scanner stdIn = new Scanner(System.in);
     
     int x = stdIn.nextInt();
     
       if (x >= 400 && x <= 599){System.out.print("8"); }
       else if (x >= 600 && x <= 799) {System.out.print("7");}
       else if (x >= 800 && x <= 999) {System.out.print("6");}
       else if (x >= 1000 && x <= 1199) {System.out.print("5");}
       else if (x >= 1200 && x <= 1399) {System.out.print("4");}
       else if (x >= 1400 && x <= 1599) {System.out.print("3");}
       else if (x >= 1600 && x <= 1799) {System.out.print("2");}
       else if (x >= 1800 && x <= 1999) {System.out.print("1");}
                                
   }
 }

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

public class Main{
    public static void main(String[]args){
     Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     int b = sc.nextInt();int c = sc.nextInt();
     int ans = 0;
     int temp = a - b;
     ans = c - temp;
     if(ans <= 0){
         System.out.println(0);
     }
     else{System.out.println(ans);}
    }
}

Measured memory_bytes: 24276
n = int(input())
v_list = list(map(int,input().split()))
v_list_odd = v_list[::2]
v_list_ev = v_list[1::2]
import collections
c_odd = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_ev)

c_odd = sorted(c_odd.items(),key=lambda x:x[1],reverse = True)
c_even = sorted(c_even.items(),key=lambda x:x[1],reverse = True)
if c_odd[0][0] != c_even[0][0]:
  print(n - c_odd[0][1] - c_even[0][1])
else:
  if len(c_odd) == 1 and len(c_even) == 1:
    print(n - c_odd[0][1])
  elif len(c_odd) == 1:
    print(n - c_odd[0][1] - c_even[1][1])
  elif len(c_even) == 1:
    print(n - c_odd[1][1] - c_even[0][1])
  else:
    print(n - max(c_odd[1][1] + c_even[0][1],c_odd[0][1] + c_even[1][1]))

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

public class Main {
	
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int[][][] map = new int[4][3][10];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					map[i][j][k] = 0;
				}
			}
		}
		
		String x = "";
		try {
			x = in.readLine();
			int num = Integer.parseInt(x);
			
			for (int i = 0; i < num; i++) {
				x = in.readLine();
				String[] data = x.split(" ");
				int b = (Integer.parseInt(data[0]) - 1);
				int f = (Integer.parseInt(data[1]) - 1);
				int r = (Integer.parseInt(data[2]) - 1);
				int v = Integer.parseInt(data[3]);
				
				map[b][f][r] = map[b][f][r] + v;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + map[i][j][k]);
				}
				System.out.println();
			}
			if (i != 3) {
				System.out.println("####################");
			}
		}
	}
}

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

using namespace std;

const int maxn=103;
const int maxw=1e9+5;
const int maxv=1e5+5;

long long dp[maxv];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, w;
	cin >> n >> w;
	long long w1, l1;
	for(int i=0; i<maxv; i++){
		dp[i]=1e12;
	}
	dp[0]=0;
	for(int i=0; i<n; i++){
		cin >> w1 >> l1;
		for(int j=maxv; j>=l1; j--){
			dp[j]=min(dp[j], dp[j-l1]+w1);
		}
	}
	int maks=0;
	for(int i=0; i<maxv; i++){
		if(dp[i]<=w){
			maks=i;
		}
	}
	cout << maks << '\n';
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

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

		//一列をintのArrayListに変換
		List<String> l = Arrays.asList(sc.nextLine().split(" "));
		ArrayList<Integer> nl = new ArrayList<Integer>();
		for(String s: l) {
			nl.add(Integer.parseInt(s));
		}
		int r = nl.get(0);
		int g = nl.get(1);
		int b = nl.get(2);
		int n = nl.get(3);
		int k = 0;
		int result = 0;

		for(int i=0;i<=n;i++) {
			for(int j=0;j<=n;j++) {
				if(i==0&&j==0) {
					if((float)n%(float)b==0) {
						result++;
					}
				}else if(i*r+j*g==n) {
					result++;
				}else if(n-(i*r+j*g) > 0 && (float)(n-(i*r+j*g)) % (float)b==0) {
					result++;
				}
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 22228
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int A[b];
  for(int i=0;i<b;i++){
    cin>>A[i];
  }
  int max=0;
  for(int i=1;i<b;i++){
    if(A[max]<A[i]){
      int t=A[max];
      A[max]=A[i];
      A[i]=t;
    }
  }
  int count=0;
  for(int i=0;i<b;i++){
    count+=A[i];
  }
  if(count>=a){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
 return 0; 
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k % 2 == 0){
        cout << a - b << endl;
    }
    else{
        cout << b - a << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main() {
    int a,n,m;
    cin >> n >>m;
    long long x[n],y[m],X=0,Y=0;
 long long mod1=0;
    long long z = pow(10,9.0)+7;
//x_nへの数値の代入
    for(a = 0;a < n; a++) cin >> x[a];
//y_nへの数値の代入
    for(a = 0;a < m; a++) cin >> y[a];
//答えの算出
    //x
    for(a = 0;a < n-1; a++){
        X +=(n-a-1)*x[n-a-1]-(n-a-1)*x[a];
     //   cout << (n-a-1)<<"x"<<x[n-a-1] <<" - " <<(n-a-1)<<"x"<<x[a] <<"を計算したよ！" <<endl;
  //      cout << "現在のXの値は" << X << endl;
    }
    //y
    for(a = 0;a < m-1; a++){
        Y += (m-a-1)*y[m-a-1]-(m-a-1)*y[a];
    //    cout << (m-a-1)<<"x"<<y[m-a-1] <<" - " <<(m-a-1)<<"x"<<y[a] <<"を計算したよ！" <<endl;
  //      cout << "現在のYの値は" << Y << endl;
    }
    //modulo
//    cout << X % z<<endl;
//    cout << Y % z << endl;
mod1 = (X%z) *(Y % z);
cout << mod1 % z;
    return 0;
}

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

#define SORT(vec) sort(vec.begin(), vec.end());


using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

	int N; cin >> N;
	double ans;

	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		ans += 1.0/a;
	}
	
	cout << 1.0/ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, ret = 0;
	cin >> n;
	string s[3];
	for (int i=0; i<3; i++) cin >> s[i];
	
	for (int i=0; i<n; i++) {
		int cnt[26];
		for (int j=0; j<26; j++) cnt[j] = 0;
		for (int j=0; j<3; j++) {
			cnt[s[j][i] - 'a']++;
		}
		int m = 0;
		for (int i=0; i<26; i++) m = max(m, cnt[i]);
		ret += 3 - m;
	}
	
	cout << ret << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main(){
  int H,W;
  cin >> H >> W;
  rep(i,H)rep(j,W){
    string S;
    cin >> S;
    if(S=="snuke") cout << (char)('A'+j) << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

const vector<tuple<int, int>> dxy = {
//        make_pair(1, 0),  // 右
//        make_pair(1, 1),  // 右 下
//        make_pair(-1, 0),  // 下
//        make_pair(-1, -1),  // 下　左
//        make_pair(-1, 0),  // 左
//        make_pair(-1, -1),  // 左 上
//        make_pair(0, -1),  // 上
//        make_pair(1, -1),  // 右 上
        make_pair(1, 0),
        make_pair(0, 1),
        make_pair(-1, 0),
        make_pair(0, -1),
        make_pair(1, 1),
        make_pair(-1, 1),
        make_pair(-1, -1),
        make_pair(1, -1),
};

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

int main()
{
    int H, W; cin >> H >> W;
    string board[50];
    rep (i, 0, H) cin >> board[i];

    rep (i, 0, H) {
        rep (j, 0, W) {
            if ('#' == board[i][j]) continue;

            int num = 0;
            rep (k, 0, dxy.size()) {
                const int x = j + get<0>(dxy[k]);
                const int y = i + get<1>(dxy[k]);

                if (y < 0 or H <= y) continue;
                if (x < 0 or W <= x) continue;
                if ('#' == board[y][x]) num++;
            }
            board[i][j] = char(num + '0');
        }
    }

    rep (i, 0, H) cout << board[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,ans=0;
    cin>>n;
    vec A(n),B(n),C(n),D(n),E(n+1);
    rep(i,n) cin>>A[i];
    rep(i,n) cin>>B[i];
    rep(i,n) cin>>C[i];
    sort(all(A)),sort(all(B)),sort(all(C));
    rep(i,n) D[i]=C.end()-upper_bound(all(C),B[i]);
    E[0]=0;
    rep(i,n) E[i+1]=E[i]+D[i];
    rep(i,n) ans+=E[n]-E[upper_bound(all(B),A[i])-B.begin()];
    cout<<ans;
}

Measured memory_bytes: 4224
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
int main() {
    int N;
    Int X =0;
    Int Y =0;
    cin >> N;

    vector<int> c = vector<int>(N);
    vector<int> v = vector<int>(N);

    for(int i=0; i<N; i++){
        cin >> v[i];
    }
    for(int i=0; i<N; i++){
        cin >> c[i];
    }
    for(int i=0; i<N; i++){
        if(v[i]-c[i]>0){
            X+= v[i];
            Y+= c[i];
        }
    }

    cout << X-Y << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10 ** 9 + 7

dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0] = 1
for j in range(m + 1):
    dp[0][j] = 1


for i, es in enumerate(s, 1):
    for j, et in enumerate(t, 1):
        if es == et:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]

        dp[i][j] %= mod

ans = dp[n][m]
print(ans)


Measured memory_bytes: 73180
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int cur,ma,N;
string S;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	FORR(c,S) {
		if(c=='D') cur--;
		if(c=='I') cur++;
		ma=max(ma,cur);
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256