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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll a; cin >> a;
    long double b; cin >> b;

//    long double ans = a * (b * 100) / 100;
    long double ans = a * b;

    cout << (ll)ans << endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define Vec2(T, n1, n2, vs) vector<vector<T>> vs(n1, vector<T>(n2))
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n1, n2, xs) Vec2(T, xs, n1, n2); For(i, n1) For(j, n2) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))

using namespace std;
using ll = long long;

int main(void){
    Cin(int, h);
    Cin(int, w);
    Vec2(bool, h, w, s);
    For(i, h) For(j, w){
        Cin(char, c);
        s[i][j] = (c == '#');
    }

    For(i, h) For(j, w){
        if(s[i][j]){
            if( (i-1 >= 0 && s[i-1][j]) || (i+1 < h && s[i+1][j]) || (j-1 >= 0 && s[i][j-1]) || (j+1 < w && s[i][j+1])) continue;
            Cout("No");
            return 0;
        }
    }
    
    Cout("Yes");
}


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

static const int MAX = 1e3;
const int INF = 1e9;
bool visited[MAX][MAX];
int d[MAX][MAX];

int main(){
    int h, w;
    int ch, cw, dh, dw;
    cin >> h >> w;
    cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            visited[i][j] = (s[j] == '#');
            d[i][j] = INF;
        }
    }
    priority_queue<tuple<int, int, int>> pq;
    pq.emplace(0, ch, cw);
    d[ch][cw] = 0;
    while(!pq.empty()){
        int ucost, uh, uw;
        tie(ucost, uh, uw) = pq.top();
        ucost = -ucost;
        pq.pop();
        visited[uh][uw] = true;
        if(d[uh][uw] < ucost) continue;
        auto check = [&](int i, int j, bool c){
            if(i < 0 || h <= i) return;
            if(j < 0 || w <= j) return;
            if(visited[i][j]) return;
            if(d[i][j] > d[uh][uw] + c){
                d[i][j] = d[uh][uw] + c;
                if(c){
                    pq.emplace(-ucost-1, i, j);
                } else {
                    pq.emplace(-ucost, i, j);
                }
            }
        };
        check(uh+1, uw, 0);
        check(uh, uw+1, 0);
        check(uh-1, uw, 0);
        check(uh, uw-1, 0);
        for(int i = uh-2; i <= uh+2; i++){
            for(int j = uw-2; j <= uw+2; j++){
                if(i == uh && j == uw) continue;
                check(i, j, 1);
            }
        }
    }
    cout << (d[dh][dw] == INF ? -1 : d[dh][dw]) << endl;
    return 0;
}

Measured memory_bytes: 8532
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            a[x]++; a[y]++;
        }
        boolean ans = true;
        for (int i = 0; i < n; i++) {
            if(a[i] % 2 != 0){
                ans = false;
                break;
            }
        }
        System.out.println(ans ? "YES" : "NO");
        sc.close();

    }

}


Measured memory_bytes: 65544
def main():
    N = int(input())
    A = [int(n) for n in input().split()]

    M = 10 ** 9 + 7

    ans = 0
    cache = sum(A) % M
    for i in range(N-1):
        cache -= A[i]
        ans += A[i] * cache % M
    print(ans % M)


main()


Measured memory_bytes: 94320
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 1e5;
const int MV = 1e5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
int MA = -INF , MI = INF , ANS;

ll n , m;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> m;
    if( m < n )
        swap( n , m );

    if( n == 1 )
    {
        if( m == 1 )
            cout << 1 << "\n";
        else
            cout << m-2 << "\n";
    }
    else
        cout << (n-2) * (m-2) << "\n";
    return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s == u) a--;
    else b--;

    cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        sc.close();

        StringBuilder sb = new StringBuilder();

        while(n > 0) {
            n--;
            sb.append((char)('a' + n % 26));
            n /= 26;
        }
        System.out.println(sb.reverse());
    }
}


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




 
int main()
{
  int n,d,x;
  scanf("%d%d%d",&n,&d,&x);
  int a[n],i,j,cnt=n;
  for(i=0;i<n;++i) 
  { scanf("%d",&a[i]);
     for(j=1;;++j)
     {
        if((j*a[i]+1)<=d)
            cnt++;
       
        else
           break;
     }
  }
  
  printf("%d",cnt+x);
            
  
  
     
}

        

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

public class Main {
	
	static class Islands implements Comparable<Islands>{
		int a, b;
		public Islands(int a, int b) {
			this.a=a;
			this.b=b;
		}
		
		public int compareTo(Islands s) {
			return (this.b==s.b)? this.a-s.a:this.b-s.b;
		}
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		Islands[] land=new Islands[M];
		for(int i=0; i<M; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			land[i]=new Islands(a, b);
		}
		Arrays.sort(land);
		int last=0, count=0;
		
		for(int i=0; i<M; i++) {
			if(land[i].a>last) {
				last=land[i].b-1;
				count++;
			}
		}
		
		System.out.println(count);
		
		
		sc.close();
	}	
}

Measured memory_bytes: 90024
#include <stdio.h>
int main(void)
{
	int a, b;//各辺の長さの宣言
	int menseki, syu;//面積と周の長さの宣言
	scanf("%d", &a);
	scanf("%d", &b);

	if ((1 <= a) && (b <= 100))
	{
		menseki = a*b;//面積計算
		syu = (2 * a) + (2 * b);// 周の計算
		printf("%d %d\n", menseki, syu);

	}
	return 0;
}


Measured memory_bytes: 2688
import sys
import numpy as np
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

def main():
    n, k = map(int, input().split())
    a = np.array([int(x) for x in input().split()])
    key = make_divisors(np.sum(a))
    
    for v in key:
        mod = np.sort(a%v)
        c1, c2 = 0, np.sum(mod)
        judge = c2
        for i in range(n-1, -1, -1):
            c1 += v-mod[i]
            c2 -= mod[i]
            judge = min(judge, max(c1, c2))
        if judge <= k:
            print(v)
            sys.exit()
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 27252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}

int main() {
  int N,W; cin >> N >> W;
  vector<int> v(N),w(N);
  rep(i,N) cin >> v[i] >> w[i];

  vector<vector<int>> dp(N+1, vector<int>(W+1));

  rep(i,N) {
    rep(j,W+1) {
      if (j < w[i]) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
    }
  }

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


Measured memory_bytes: 6836
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

using vi = vector<int>;
using pii = pair<int, int>;
using sp = set<pii>;

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

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

    int cnt[n];
    fill(cnt, cnt + n, 0);
    for (int i = 0; i < n; i++) {
        cnt[a[i]]++;
        cnt[b[i]]++;
    }

    if (*max_element(cnt, cnt + n) > n) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    vi posa[n], posb[n];
    for (int i = 0; i < n; i++) {
        posa[a[i]].push_back(i);
        posb[b[i]].push_back(i);
    }

    sp sa, sb;
    for (int i = 0; i < n; i++) {
        if (posa[i].size() > 0) {
            sa.emplace(posa[i].size() + posb[i].size(), i);
        }
        if (posb[i].size() > 0) {
            sb.emplace(posa[i].size() + posb[i].size(), i);
        }
    }

    int ans[n];
    while (!sa.empty()) {
        auto x = prev(sa.end());
        auto y = prev(sb.end());
        if (*x == *y) {
            if (sa.size() == 1 || sb.size() > 1 && prev(y)->first > prev(x)->first) {
                y--;
            } else {
                x--;
            }
        }

        pii pa = *x, pb = *y;

        ans[posa[pa.second].back()] = pb.second;

        posa[pa.second].pop_back();
        sa.erase(pa);
        if (sb.count(pa)) {
            sb.erase(pa);
        }
        pa.first--;
        if (posa[pa.second].size()) {
            sa.insert(pa);
        }
        if (posb[pa.second].size()) {
            sb.insert(pa);
        }

        posb[pb.second].pop_back();
        if (sa.count(pb)) {
            sa.erase(pb);
        }
        sb.erase(pb);
        pb.first--;
        if (posa[pb.second].size()) {
            sa.insert(pb);
        }
        if (posb[pb.second].size()) {
            sb.insert(pb);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] + 1 << " \n"[i==n-1];
    }
    cout.flush();

    return 0;
}


Measured memory_bytes: 47252
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

const int MAX_A = 100;

int sort(const int N, int (*a)[MAX_A]) {
    int count = 0;

    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j >= i + 1; j--) {
            if ((*a)[j] < (*a)[j - 1]) {
                swap((*a)[j], (*a)[j - 1]);
                count++;
            }
        }
    }

    return count;
}

int main(void) {
    int N;
    cin >> N;

    int A[MAX_A];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int count = sort(N, &A);

    cout << A[0];
    for (int i = 1; i < N; i++) {
        cout << " " << A[i];
    }
    cout << endl;

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/**
*   author: j o s e m a g o
*   user: m a m i s a k i
**/
using namespace std;

/***PLANTILLA***/

using namespace __gnu_pbds; //*st.find_by_order(1);  st.order_of_key(p);
#pragma GCC optimize ("Ofast")
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mset(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define sz(x) ((int)(x).size())
#define rsz resize
#define ln "\n"
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef double dbl;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ld PI = 2*acos(0.0);
const int MOD = 1000000007;

string tostring(auto a){
    stringstream ss;ss<<a;string s = ss.str();
    return s;
}

/**Mi Debug**/
#define var(x) cout<<#x<<" = ";
#define db(x) cout<<#x<<" = "<<x<<"\n";
void dbvector(vector<auto>&v){
    int c = -1;
    for(auto i: v){
        c++;cout<<"["<<c<<":"<<i<<"] ";
    }cout<<"\n";
}
void dbmapa(map<auto,auto>mp){
   for(auto x : mp) cout<<"{"<<x.first<<":"<<x.second<<"} ";cout<<"\n";
}
void dbstring(string v){
    int c = -1;
    for(auto i: v){
        c++;cout<<"["<<c<<":"<<i<<"] ";
    }cout<<"\n";
}

/***********Code***************/

const int JJJ = 100100;










int main(){

  //freopen("input.in","r",stdin);
  //freopen("input.out","w",stdout);

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



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

    vector<ll>q = a;
    sort(q.begin(),q.end());
    ll cont = 0;
    ll aa = 0,bb = 0;
    do{
        cont++;
        if(a == q){
            aa = cont;
        }
        if(b == q){
            bb = cont;
        }



    }while(next_permutation(q.begin(),q.end()));

    cout<<abs(aa-bb);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		int tmp = a - b;
		int ans = c - Math.min(c, tmp);

		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    ll k;
    cin>>s>>k;
    vector<ll>v;
    int i,st=0,n=s.size();
    for(i=1;i<n;i++){
        if(s[i]!=s[st]){
            v.push_back(i-st);
            st=i;
        }
    }
    v.push_back(n-st);
    if(v.size()==1){
        printf("%lld",n*k/2);
        return 0;
    }
   ll ans=0;
   for(ll x:v)ans+=x/2;
   ans*=k;
   if(s[0]==s[n-1]){
        ans-=v[0]/2*(k-1)+v[v.size()-1]/2*(k-1);
        ans+=(v[0]+v[v.size()-1])/2*(k-1);
   }
   printf("%lld",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

LL k;
vector<LL> d;
queue<pair<LL,LL>> q;

void dbfs(LL x, LL td) {
  if(d[x] <= td) return;
  d[x] = td;
  dbfs(x*10%k, td);
  q.emplace((x+1)%k,td+1);
}

int main(void)
{
  cin >> k;
  d.assign(k, k);
  q.emplace(1,1);
  while(!q.empty()) {
    dbfs(q.front().first, q.front().second);
    q.pop();
  }
  cout << d[0] << endl;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
ll b[N];

int main() {
  int n;
  scanf("%d", &n);
  ll ans = 0;
  for(int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    b[i] = x - i;
  }
  sort(b + 1, b + 1 + n);
  ll base;
  base = b[n / 2 + 1];
  for(int i = 1; i <= n; ++i) {
    ans += abs(b[i] - base);
  }
  printf("%lld\n", ans);
  return 0;
}

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

public class Program
{
    #region Standard I/O
    readonly TextReader input;
    readonly TextWriter output;

    X[] ReadLine<X>(Func<string, X> func)
    {
        return input.ReadLine().Split(' ').Select(func).ToArray();
    }

    void WriteLineOne(object obj)
    {
        output.WriteLine("{0}", obj);
    }

    void WriteLineMany(params object[] objects)
    {
        output.WriteLine(string.Join(" ", objects.Select(obj => obj.ToString())));
    }
    #endregion

    long n, a, b, c, d;

    void Read()
    {
        var line = ReadLine(long.Parse);
        n = line[0];
        a = line[1];
        b = line[2];
        c = line[3];
        d = line[4];
    }

    bool IsOk(int m)
    {
        // a + Σ(c + p_i) - Σ(c + q_i) = b となる (p_i), (q_i) が存在すればよい。
        // ただし 0 <= p_i, q_i <= d - c = r。
        // (p_i) の長さを m とする。(q_i) の長さは l。
        var r = d - c;
        var l = n - 1 - m;

        // a + (m - l) * c + Σp - Σq = b
        // Σp - Σq = b - a + (l - m) * c = f
        // Σp は [0, m * r] 上を、Σq は [0, l * r] 上を自由に動く。
        // Σp - Σq は [-l * r, m * r] 上を自由に動く。
        // f ∈ [-l * r, m * r] であればよい。
        var f = b - a + (l - m) * c;
        return -l * r <= f && f <= m * r;
    }

    bool Solve()
    {
        for (var m = 0; m <= n - 1; m++)
        {
            if (IsOk(m)) return true;
        }

        return false;
    }

    public void Run()
    {
        Read();
        WriteLineOne(Solve() ? "YES" : "NO");
    }

    public Program(TextReader input, TextWriter output)
    {
        this.input = input;
        this.output = output;
    }

    public static void Main(string[] args)
    {
        new Program(Console.In, Console.Out).Run();
    }
}


Measured memory_bytes: 13396
N = int(input())
happy_list = []
happy = 0
for i in range(N):
  A, B = map(int,input().split())
  happy -= B
  happy_list.append(A + B)
happy_list.sort(reverse = True)
for i in range(N):
  if(i % 2 == 0):
    happy += happy_list[i]
print(happy)

Measured memory_bytes: 7388
#include <iostream>

using namespace std;
using ll = long long;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  ll maxl = 1, minr = n;
  for(ll i=0; i<m; ++i){
    ll l, r;
    cin >> l >> r;
    if(maxl < l) maxl = l;
    if(minr > r) minr = r;
  }
  ll res;
  if(minr < maxl) res = 0;
  else res = minr - maxl + 1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};



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

    int h,w;
    cin >> h >> w;
    vvec field(h,vec(w,'.'));
    vvi dist(h,vi(w,INF));
    vector<pair<int,int>> kuro;
    --h,--w;
    int cnt = 0;
    rep(i,h+1){
        rep(j,w+1){
            cin >> field[i][j];
            if(field[i][j] == '#') {
                dist[i][j]=0;
                kuro.pb({i,j});
            }
        }
    }
    queue<i_i> que;
    for(auto it : kuro){
        que.push(it);        
    }

    while(!que.empty()){
        i_i  c = que.front(); que.pop();
        rep(i,4){
            int nx = c.fs + dx[i], ny = c.sc+dy[i];
            if(0<=nx && nx <= h && 0<= ny && ny <= w && field[nx][ny] != '#' && dist[nx][ny] == INF){
                //cout << nx << ny << endl;
                que.push({nx,ny});
                dist[nx][ny] = dist[c.fs][c.sc] + 1; 
            }
        }
    }
    int ans = 0;
    rep(i,h+1){
        rep(j,w+1){
            ans = max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21232
import heapq

N,M=map(int,input().split())
d={}
for i in range(M):d[i]=[0]
for i in range(N):
    a,b=map(int,input().split())
    if 0<=M-a:
        d[M-a].append(b)

hq=[]
ans=0
for i in range(M)[::-1]:
    [heapq.heappush(hq,-j) for j in d[i]]
    ans-=heapq.heappop(hq)
print(ans)

Measured memory_bytes: 30240
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,b,f,r,v;cin>>n;
	int room[4][3][10]={0};
	while(n--){
		cin>>b>>f>>r>>v;b--;f--;r--;
		room[b][f][r]+=v;
	}
	for(b=0;b<4;b++){
		for(f=0;f<3;f++){
			for(r=0;r<10;r++){
				cout<<" "<<room[b][f][r];
			}
			cout<<endl;
		}
		if(b<3){for(r=0;r<20;r++){cout<<'#';}cout<<endl;}
		
	}
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<A){
        cout << K << endl;
    }else if(A <= K && K <= A+B){
        cout << A << endl;
    }else if(A+B <= K && K < A+B+C){
        cout << A - 1 *(K-(A+B)) << endl;
    }else{
        cout << A - C << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
S = input()
T = input()

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[j]=="?":
                    Slr[j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
print(ans)



Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	long long int x,y=0,z,a,b,sum = 0;
	char c[101];
	for(b=0;b<100;b++) c[b] = '0';
	scanf("%s",c);
	scanf("%lld",&x);
	while(c[y] == '1') y++;
	if (y+1>x) printf("1");
	else printf("%c",c[y]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
int N,L;

int main(){
    cin>>N>>L;
    string s[N];
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    sort(s,s+N);

    for(int i=0;i<N;i++) cout<<s[i];
    cout<<"\n";
    return 0;
}




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

int main() {
	int n, m, a, b;
	cin >> n >> m;
	vector<int> vec(n);
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		vec[a - 1]++;
		vec[b - 1]++;
	}
	for (int i = 0; i < n; i++) cout << vec[i] << endl;
}


Measured memory_bytes: 256
A, B, C = list(map(int, input().split()))

_max = max([A,B,C])

answer = 0
answer += (_max-A)//2 + (_max-B)//2 + (_max-C)//2

_map = {0:0, 1:2, 2:1}
answer += _map[(_max-A)%2 + (_max-B)%2 + (_max-C)%2]

print(answer)


Measured memory_bytes: 3060
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e5+69, INF=2e9+6969;

ll W,n,dp[101][R];
pair <ll,ll> t[R];

int main()
{
	scanf("%lld%lld", &n, &W);
	for(int i=0;i<n;++i)
	{
		ll a,b;
		scanf("%lld%lld", &a, &b);
		t[i]=mp(a,b);
	}
	
	sort(t,t+n);
	for(int i=t[0].fi;i<=W;++i)
	{
		dp[0][i]=t[0].se;
	}
		for(int j=1;j<n;++j)
		{
			for(int w=1;w<=W;++w)
			{
				if(t[j].fi>w) {dp[j][w]=dp[j-1][w]; continue;}
				dp[j][w]=max(dp[j-1][w],dp[j-1][w-t[j].fi]+t[j].se);
			}			
		}
		//  for(int i=0;i<n;++i)
		//  {
			//  for(int j=1;j<=W;++j)
			//  {
				//  printf("%lld ", dp[i][j]);
			//  }
			//  puts("");
		//  }
		printf("%lld\n", dp[n-1][W]);
	return 0;
}


Measured memory_bytes: 82216
n, m = map(int, input().split())
p = list(map(lambda x: int(x)-1, input().split()))
q = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(m)]

par = [x for x in range(n)]
rank = [0]*n

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]

def unite(x, y):
  x = find(x)
  y = find(y)
  if x == y: return
  if rank[x] < rank[y]:
    par[x] = y
  else:
    par[y] = x
    if rank[x] == rank[y]: rank[x] += 1

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

for x, y in q:
  unite(x, y)
#print(par)
#print(rank)
ans = 0
for i in range(n):
  if same(p[i], i): ans += 1
print(ans)

Measured memory_bytes: 30968
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    int a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;


    return 0;
}


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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

ll n, m;

bool bfs(vllll path)
{
    vb pass(n, false);
    pass[0] = true;
    queue<int> q;
    q.push(0);
    int cnt = 1;
    while (!q.empty())
    {
        int sp = q.front();
        q.pop();
        rep(i, 0, n)
        {
            if (path[sp][i] && !pass[i])
            {
                q.push(i);
                pass[i] = true;
                cnt++;
            }
        }
        if (cnt == n)
            return false;
    }
    return true;
}

int main(void)
{
    cin >> n >> m;
    vll a(m), b(m);
    vllll path(n, vll(n));
    rep(i, 0, m)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        path[a[i]][b[i]] = 1;
        path[b[i]][a[i]] = 1;
    }

    ll ans = 0;
    rep(i, 0, m)
    {
        path[a[i]][b[i]] = 0;
        path[b[i]][a[i]] = 0;

        if (bfs(path))
            ans++;

        path[a[i]][b[i]] = 1;
        path[b[i]][a[i]] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))
import copy
Y=copy.copy(X)
Y.sort()

if Y[N//2]==Y[N//2-1]:
    for i in range(N):
        print(Y[N//2])
else:
    for i in range(N):
        if X[i]<=Y[N//2-1]:
            print(Y[N//2])
        else:
            print(Y[N//2-1])


Measured memory_bytes: 30764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const char NL = '\n';
const int MOD = 1e9 + 7;

void solve()
{
    int x; cin >> x;
    int ans = 0;
    if (x >= 1800) {
        ans = 1;
    } else if (x >= 1600) {
        ans = 2;
    } else if (x >= 1400) {
        ans = 3;
    } else if (x >= 1200) {
        ans = 4;
    } else if (x >= 1000) {
        ans = 5;
    } else if (x >= 800) {
        ans = 6;
    } else if (x >= 600) {
        ans = 7;
    } else if (x >= 400) {
        ans = 8;
    }
    cout << ans << NL;
} 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        int[] nm = in.readLineAsIntArray();
        final int N = nm[0];
        final int M = nm[1];

        City[] cities = new City[M];
        for (int i = 0; i < M; i++) {
            int[] py = in.readLineAsIntArray();
            cities[i] = new City(i, py[0], py[1]);
        }

        Arrays.sort(cities, (City c1, City c2) -> (c1.pref == c2.pref) ? (c1.year - c2.year) : (c1.pref - c2.pref));
        int idx = 1;
        for (int i = 0; i < M - 1; i++) {
            cities[i].idName = String.format("%06d%06d", cities[i].pref, idx);
            if (cities[i].pref == cities[i + 1].pref) {
                idx++;
            } else {
                idx = 1;
            }
        }
        cities[M - 1].idName = String.format("%06d%06d", cities[M - 1].pref, idx);

        Arrays.sort(cities, (City c1, City c2) -> c1.number - c2.number);

        for (int i = 0; i < M; i++) {
            System.out.println(cities[i].idName);
        }

    }

    class City {
        final int number;
        final int pref;
        final int year;
        String idName;

        public City(int num, int pref, int year) {
            this.number = num;
            this.pref = pref;
            this.year = year;
        }
    }

    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

Measured memory_bytes: 118092
#include <iostream>
#include <limits>

int main() {
    int N, L;
    std::cin >> N >> L;

    int idx = 0;
    int abs_diff = std::numeric_limits<int>::max();
    for (int i = 1; i <= N; ++i) {
        const auto tmp = std::abs(L + i - 1);
        if (abs_diff > std::abs(L + i - 1)) {
            idx = i;
            abs_diff = tmp;
        }
    }

    const int total = N * L + N * (N - 1) / 2;

    const int ret = total - (L + idx - 1);

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
def gcd(a,b,c):
    #1
    seq  = [a,b,c]
    seq.sort()
    while b > 0:
        r = c%b
        c = b
        b = r
    #2
    seq_2 = [a,c]
    seq_2.sort()
    while a > 0:
        r = c%a
        c = a
        a = r
    return c

from functools import reduce

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(i,k+1):
        for k in range(j,k+1):
            t = len(set([i,j,k]))
            
            if t == 1:
                ans += gcd(i,j,k)
                
            elif t == 2:
                ans += gcd(i,j,k)*3
            
            elif t == 3:
                ans += gcd(i,j,k)*6
    

print(ans)


Measured memory_bytes: 9564
N = int(input())
T = [None] * N
X = [None] * N
Y = [None] * N

for i in range(N):
    T[i], X[i], Y[i] = map(int, input().split())

def is_reachable(t, x, y):
    x, y = abs(x), abs(y)
    if t >= (x + y):
        if (t - x - y) % 2 == 0:
            return True
    return False

ans = 'No'
if is_reachable(T[0], X[0], Y[0]):
    ans = 'Yes'
    for i in range(N-1):
        t, x, y = T[i+1], X[i+1], Y[i+1]
        t, x, y = t - T[i], x - X[i], y - Y[i]
        if not is_reachable(t, x, y):
            ans = 'No'
            break
print(ans)

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

int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, a, b;
vector<ll> h;

void solve() {
    ll st = 0, end = ll(1e9);
    while (end - st > 1) {
        ll c = 0;
        ll center = (end + st) / 2;
        each(i, h) {
            if (i - b * center > 0) c += ceil(double(i - b * center) / (a - b));
        }
        if (c <= center) end = center;
        else st = center;
    }
    cout << end << endl;
}

int main() {
    cin >> n >> a >> b;
    rep(i, n) {
        ll temp;
        cin >> temp;
        h.emplace_back(temp);
    }
    solve();
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
long long gcd(long long a,long long b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b){
    return a/gcd(a,b)*b;
}
long long n,t[100],ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>t[i];
    ans=t[0];
    for(int i=1;i<n;i++)ans=lcm(t[i],ans);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define mk make_pair
#define pb push_back
#define pf push_front
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int A, B, Q, s[100100], t[100100];

signed main()
{
    cin >> A >> B >> Q;
    A++;
    B++;
    s[0] = -INFL;
    t[0] = -INFL;
    for(int i = 1; i < A; i++){
        cin >> s[i];
    }
    for(int i = 1; i < B; i++){
        cin >> t[i];
    }
    s[A] = INFL;
    t[B] = INFL;
    for(int i = 0; i < Q; i++){
        int x;
        cin >> x;
        int cursr = lower_bound(s, s + A, x) - s;
        int cursl = cursr - 1;
        int curtr = lower_bound(t, t + B, x) - t;
        int curtl = curtr - 1;
        int a = s[cursr];
        int b = s[cursl];
        int c = t[curtr];
        int d = t[curtl];
        vector<int> v;
        v.pb(max(a, c) - x);
        v.pb(x - min(b, d));
        v.pb(a - x + 2 * (x - d));
        v.pb(x - d + 2 * (a - x));
        v.pb(c - x + 2 * (x - b));
        v.pb(x - b + 2 * (c - x));
        sort(v.begin(), v.end());
        printf("%lld\n", v[0]);
    }


    return 0;
}
/*


*/




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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//
int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    vector<int> ans;
    for(int i = min(a, b); i > 0; --i){
        if((a % i == 0) && (b % i == 0)){
            ans.push_back(i);
        }
    }
    cout << ans[k - 1] << endl;
    return 0;
}



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

public class Main{
	public static void main(String[] args){
		new Main().solve();
	}

	void solve(){

		Scanner cin = new Scanner(System.in);
		int MAX = 1 << 15;
		MAX += 1;
		int[][] dp = new int[MAX][5];
		dp[0][0] = 1;
		for(int i=1;i*i<=MAX;i++){
			int a = i * i;
			for(int j=0;j+a<MAX;j++){
				for(int k=0;k<4;k++){
					dp[j+a][k+1] += dp[j][k];
				}
			}
		}

		while(true)
		{
			int n = cin.nextInt();
			if(n==0) return;
			int ret = 0;
			for(int i=0;i<5;i++) ret += dp[n][i];
			System.out.println(ret);
		}
	}
}

Measured memory_bytes: 13000
#include <stdio.h>

int main(){
	
	int h,w,i;
	char a[101][101];
	
	scanf("%d %d",&h,&w);
	
	for(i=0;i<h;i++){
		scanf("%s",&a[i]);
	}
	
	for(i=0;i<w+2;i++){
		printf("#");
	}
	
	printf("\n");
	
	for(i=0;i<h;i++){
		printf("#%s#\n",a[i]);
	}
	
	for(i=0;i<w+2;i++){
		printf("#");
	}
	printf("\n");
	
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll H, A;
    cin >> H >> A;
    cout << (H+A-1)/A << endl;
    return 0;
}

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

using namespace std;






int main() {

	int n, m;

	int L = 0;
	int R = 0;

	int wkL;
	int wkR;


	cin >> n >> m;

	cin >> L >> R;

	for (int i = 0; i < m-1; i++) {
		cin >> wkL >> wkR;

		if (L < wkL)L = wkL;
		if (wkR < R)R = wkR;
	}

	int ans = R - L + 1;


	if (R - L < 0)ans = 0;

	cout << ans << endl;


	return 0;




}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    A.sort()
    n = N-1
    p = bisect_left(A, A[n] / 2)
    low = max(0, p - 1)
    high = min(N - 1, p)
    if n == high:
        return "%d %d" % (A[n], A[low])
    elif A[low] > A[n] - A[high]:
        return "%d %d" % (A[n], A[low])
    else:
        return "%d %d" % (A[n], A[high])


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 998244353

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll n, S;
ll a[3001];
ll dp[3001][3001];

ll solve(ll id, ll W)
{
	// base cases
	if(W > S) return 0;
	if(id >= n) {
		if(W != S) return 0;
		else return 1;
	}
	if(dp[id][W] != -1) return dp[id][W];
	dp[id][W] = 0;
	dp[id][W] += solve(id+1,W+a[id]) % MOD;
	dp[id][W] += (2 * (solve(id+1,W) % MOD)) % MOD;
	dp[id][W] %= MOD;
	return dp[id][W];
}

int main()
{
    // Fast_IO();
    cin >> n >> S;
    f(i,0,n-1) cin >> a[i];
    f(i,0,n-1) f(j,0,S) dp[i][j] = -1;
    cout << solve(0,0);
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
vector<string> S;
pll mk[1010101];
vector<pll> lvv, rvv,svv;
pll mks;
pll mks2;
ll ans;
ll i, j, k;


pll calc(string& s){
    ll a = 0, b = 0;
    ll i;
    pll ret;
    ll len = s.length();
    fornum(i,0,len){
        if(s[i]=='('){
            ++a;
        }else{
            if(a==0)
                ++ret.first;
            else
                --a;
        }
        if(s[len-1-i]==')'){
            ++b;
        }else{
            if(b==0)
                ++ret.second;
            else
                --b;
        }
    }
    return ret;
}


int main(){
    cin >> N;

    if(N==1){
        string s;
        cin >> s;
        pll a = calc(s);
        if(a.first==0&&a.second==0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
        return 0;
    }

    S.resize(N);
    fornum(i,0,N){
        cin >> S[i];
    }

    fornum(i,0,N){
        mk[i] = calc(S[i]);
        //cout << mk[i].first << mk[i].second << endl;
        if(mk[i].first<mk[i].second){
            lvv.push_back({mk[i].first, i});
        }else if(mk[i].first>mk[i].second){
            rvv.push_back({mk[i].second, i});
        }else{
            svv.push_back({mk[i].first, i});
        }
    }

    sort(lvv.begin(), lvv.end());
    sort(rvv.begin(), rvv.end());
    ll ln = 0;
    fornum(i,0,lvv.size()){
        ll ii = lvv[i].second;
        ln -= mk[ii].first;
        if(ln<0){
            printf("No\n");
            return 0;
        }
        ln += mk[ii].second;
    }
    ll rn = 0;
    fornum(i,0,rvv.size()){
        ll ii = rvv[i].second;
        rn -= mk[ii].second;
        if(rn<0){
            printf("No\n");
            return 0;
        }
        rn += mk[ii].first;
    }

    if(rn!=ln){
        printf("No\n");
        return 0;
    }
    fornum(i,0,svv.size()){
        ll ii = svv[i].second;
        if(ln<mk[ii].first||mk[ii].second>rn){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 65708
/**
 * @author      : omgursocute
 * @created     : 20/01/2020
 * @task        : B
 */

// ===== TEMPLATE STARTS HERE ===== //

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define FORa(i, a, b) for(ll i = (a); i <= (b); ++i)
#define FORb(i, a, b, c) for(ll i = (a); i <= (b); i += (c))
#define FORn(i, n) for(ll i = 0; i < (n); ++i)
#define FORra(i, a, b) for(ll i = (a); i >= (b); --i)
#define FORrb(i, a, b, c) for(ll i = (a); i >= (b); i -= (c))
#define FORrn(i, n) for(ll i = ((n)-1); i >= 0; --i)
#define NUMARGC(_1, _2, _3, _4, NAME, ...) NAME
#define FOR(...) NUMARGC(__VA_ARGS__, FORb, FORa, FORn)(__VA_ARGS__)
#define RFOR(...) NUMARGC(__VA_ARGS__, FORrb, FORra, FORrn)(__VA_ARGS__)

#define XFOR(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define RXFOR(i, x) for(__typeof((x).rbegin()) i = (x).rbegin(); i != (x).rend(); ++i)

#define pll pair<ll, ll>
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range(x, a, b) ((x).begin()+a), ((x).begin()+b)
#define pb push_back

#define sqr(x) 1ll*(x)*(x)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << '[' << #x << ']' << " = " << x << '\n'
#else
#define debug(x) "cute"
#endif

namespace io {
	void Speed() {
		ios::sync_with_stdio(false);
		cin.tie(NULL); cout.tie(NULL);
	}
#ifndef ONLINE_JUGDE
	void In(string s) {freopen(s.c_str(), "r", stdin);}
	void Out(string s) {freopen(s.c_str(), "w", stdout);}
	void setIO(string s) {In(s + ".inp"); Out(s + "out");}
#endif
}

// ======= TEMPLATE ENDS HERE ======= //

int main() {
	io::Speed();

	int a, b;
	cin >> a >> b;
	FOR(i, max(a, b)) cout << min(a, b);

	return 0;
}



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

int main(){
    int N,M;
    cin >> N >> M;
    int H[N + 1];
    int T[N + 1];
    for (int i = 1; i<=N; i++) {
        cin >> H[i];
        T[i] = 0;
    }
    for(int i = 0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        T[a] = max(T[a], H[b]);
        T[b] = max(T[b], H[a]);
    }

    int cnt = 0;
    for (int i = 1; i<=N; i++) {
        if (H[i] > T[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,ans=1e9,a[2][N];
char s[N];
int zh(int x,int l,int r)
{
	if(l>r)
		return 0;
	return a[x][r]-a[x][l-1];
}
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++)
	{
		int x=s[i]=='W';
		a[0][i]=a[0][i-1],a[1][i]=a[1][i-1];
		a[x][i]++;
	}
	for(int i=0;i<=n;i++)
	{
		int v1=zh(1,1,i),v2=zh(0,i+1,n);
		ans=min(ans,max(v1,v2));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	fastio
	int h,a;
	cin>>h>>a;
	double ans=h*1.0/a;
	cout<<ceil(ans);
	return 0;
}

Measured memory_bytes: 3808