akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const int INF = 1 << 30;

struct Edge {
    int to; int cap; int rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
};

struct Flow {
    vector <vector<Edge>> G;
    vector<bool> used;
    Flow(int n) : G(n), used(n, false) {}
    void add_edge(int from, int to, int cap) {
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size() - 1));
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;

        Flow fl(n+m+2);
        int a[n], b[m];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            fl.add_edge(n+m, i, 1);
        }
        for (int i = 0; i < m; i++) {
            cin >> b[i];
            fl.add_edge(n+i, n+m+1, 1);
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (gcd(a[i], b[j]) > 1) fl.add_edge(i, n+j, 1);
            }
        }

        cout << fl.max_flow(n+m, n+m+1) << '\n';
    }

    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
int min_range(int left_ind,int right_ind, vector<int> &v){
	int mini = 101;
	for(int i = left_ind;i<=right_ind;i++){
		mini = min(v[i],mini);
	}
	for(int i = left_ind;i<=right_ind;i++){
		v[i] -= mini;
	}
	return mini;
}
int main(){
	int n,a;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> a;
		h[i]=a;
		//cout << h[i];
	}
	
	int count=0;
	//int k = 0;
	while(true){
		int left=-1,right=-1;
		//for(int i = 0;i<n;i++) cout << i << " " << h[i] << endl;
		
		if(h[0]>0) left = 0;
		for(int i =1;i<n;i++){
			if(h[i]>0 && h[i-1]==0 && left!=0) left = i;
			if(h[i-1]>0 && h[i] ==0) {right = i-1; break;}
		}
		//cout << left << "           " << right << endl;
		if(right == -1) right = n-1;
		int c = min_range(left,right,h);
		count+=c;
		//cout << c << endl;
		//k++;
		if(left == -1) break;
	}
	cout << count;
}
		
		
    
	



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

using namespace std;

#define ll long long
#define pb push_back
#define sz size()
#define S second
#define F first
#define all(x) x.begin(), x.end()

typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vector < int > >  vvi;

void solve(){
    string s;
    cin >> s;
    int cnt = 0;
    if(s[0] == 'R')
        cnt++;
    if(s[1] == 'R'){
        cnt++;
    }
    if(s[2] == 'R'){
        cnt++;
    }
    if(s[1] == 'S'){
        //cout << min(cnt, 1) << " ";
        cnt = min(cnt, 1);
    }
    cout << cnt;
}

signed main() {
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}





Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,a,b;
  cin >> x >> a >> b;
  if (a-b>=0){
      cout << "delicious" << endl;
  }else if(a+x-b>=0){
      cout << "safe" << endl;
  }else{
      cout << "dangerous"  << endl;
  }
}


Measured memory_bytes: 256
using System;
public class Hello{
    static int Calc(int x){
        int ret = 0;
        while(x % 100 == 0){
            x /= 100;
            ret++;
        }
        return ret;
    }
    public static void Main(){
        int[] n = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        int D = n[0];
        int N = n[1];
        
        int cnt = 0;
        int val = 0;
        
        while(cnt < N){
            val++;
            if(Calc(val) == D){
                cnt++;
            }
        }
        Console.WriteLine(val);
    }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin >> x;
    auto f = [](int d) {
        switch ((d - 1) % 7) {
        case 0:
            return "fri";
        case 1:
            return "sat";
        case 2:
            return "sun";
        case 3:
            return "mon";
        case 4:
            return "tue";
        case 5:
            return "wed";
        case 6:
            return "thu";
        }
    };
    cout << f(x) << endl;
}


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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  int x, y, a, x0, x1, y0, y1;
  x0 = 0;
  y0 = 0;
  x1 = W;
  y1 = H;
  rep(i, N) {
    cin >> x >> y >> a;
    if (a == 1) x0 = max(x, x0);
    if (a == 2) x1 = min(x, x1);
    if (a == 3) y0 = max(y, y0);
    if (a == 4) y1 = min(y, y1);
  }
  
  if (x1 <= x0 || y1 <= y0) cout << 0 << endl;
  else cout << (y1 - y0)*(x1 - x0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
    int n,m;
    cin >> n >> m;
    dsu d(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        d.merge(a,b);
    }
    cout << d.groups().size()-1<<endl;
}

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

int main() {
  int n;
  cin >> n;
  
  int max = 0;
  int sum = 0;
  
  vector<int> p(n);
  for (int i=0; i<n; i++){
    cin >> p.at(i);
    sum += p.at(i);
    if (max < p.at(i)){
      max = p.at(i);
    }
  }
  
  sum = sum - max/2;
  
  cout << sum << endl;
  
}


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    ll n, k;
    cin >> n >> k;
    vector<P> a(n);
    rep(i, n) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());

    ll num = 0;
    int ans = 0;
    rep(i, n) {
        num += a[i].second;
        if (num >= k) {
            ans = a[i].first;
            break;
        }
    }


    cout << ans;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3964
#include <stdio.h>

typedef struct{
    int k, l, r;
}node;

node nodes[500001];

void insert(int index, int z)
{
    int x = 0, y;

    nodes[index].k = z;
    nodes[index].l = -1;
    nodes[index].r = -1;

    if(index == 0)
        return ;

    while(x >= 0){
        y = x;
        if(z < nodes[x].k){
            x = nodes[x].l;
        }else{
            x = nodes[x].r;
        }
    }

    if(z < nodes[y].k)
        nodes[y].l = index;
    else
        nodes[y].r = index;
}

void find(int z)
{
    int x = 0;
    while(x >= 0 && nodes[x].k != z){
        if(z < nodes[x].k){
            x = nodes[x].l;
        }else{
            x = nodes[x].r;
        }
    }

    if(nodes[x].k == z)
        printf("yes\n");
    else
        printf("no\n");
}

void pre(int id)
{
    if(id == -1)
        return ;
    printf(" %d", nodes[id].k);
    pre(nodes[id].l);
    pre(nodes[id].r);
}

void ino(int id)
{
    if(id == -1)
        return ;
    ino(nodes[id].l);
    printf(" %d", nodes[id].k);
    ino(nodes[id].r);
}

int main(void)
{
    int i, n;
    int index = 0, z;
    char buf[16];
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s", buf);
        if(buf[0] == 'i'){
            scanf("%d", &z);
            insert(index++, z);
        }else if(buf[0] == 'p'){
            if(index > 0){
                ino(0);
                printf("\n");
                pre(0);
                printf("\n");
            }
        }else if(buf[0] == 'f'){
            scanf("%d", &z);
            find(z);
        }
    }

    return 0;
}

Measured memory_bytes: 5304
# A%B,2A%B,3A%B.....
#(k + b)a % b = (k * a + b * a) % b = k * a % b
a,b,c = map(int,input().split())
ans = "NO"
for i in range(a,a*b,a):
  if i % b == c:
    ans = "YES"
print(ans)

Measured memory_bytes: 2940
#include <cstdio>
    #include <cstring>
    #include <iostream>
    #define MN 4010
    #define mod 998244353
     
    int f[MN][MN];
    int r[MN], b[MN];
    char s[MN];
     
    int main()
    {
    	scanf("%s", s + 1);
    	int n = strlen(s + 1); 
    	for(int i = 1; i <= n; i++)
    	{
    		int x = s[i] - '0';
    		r[i] = r[i - 1]; b[i] = b[i - 1];
    		if(x == 0) r[i] += 2;
    		if(x == 1) r[i]++, b[i]++;
    		if(x == 2) b[i] += 2;
    	}
    	for(int i = n + 1; i <= 2 * n; i++) r[i] = r[i - 1], b[i] = b[i - 1];
    	f[0][0] = 1;
    	for(int i = 1; i <= 2 * n; i++)
    	{
    		for(int j = 0; j <= i; j++)
    		{
    			int k = i - j;
    			if(j > r[i] || k > b[i]) continue;
    			if(j) f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;
    			if(k) f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
    		}
    	}
    	printf("%d\n", f[2 * n][r[n]]);
    }

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n; cin>>n;
	vector<lint> a(n);
	map<lint,lint> ma;
	REP(i,n){
		cin>>a[i];
		ma[a[i]]++;
	}
	lint init = 0;
	for(auto e: ma){
		init += e.second*(e.second-1)/2;
	}
	lint ans;
	REP(i,n){
		if(ma[a[i]]>=2) ans = init - ma[a[i]]*(ma[a[i]]-1)/2 + (ma[a[i]]-1)*(ma[a[i]]-2)/2;
		else if(ma[a[i]]==1) ans = init;
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

int bfs(int n,vector<vector<int>> &adj){
    vector<bool> vis(n+1,false);
    queue<int> q;
    vis[1]=true;
    q.push(1);
    int l=0;
    while(!q.empty()){
        int sz=q.size();
        l++;
        while(sz-->0){
            int u=q.front();q.pop();
            // if(u==2){return l;}
            for(int v:adj[u]){
                if(v==2){return l;}
                if(!vis[v]){
                    q.push(v);
                    vis[v]=true;
                }
            }
        }
    }
    return -1;
}

void solve(){
    int n;
    cin>>n;
    
    vector<vector<int>> adj(n+1);
    
    for(int u=1;u<=n;u++){
        int v;
        cin>>v;
        adj[u].push_back(v);
    }
    
    cout<<bfs(n,adj)<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    ll A, B, ans;
    cin >> A >> B;

    ans = A * B;
    if(A < B){
        ll tmp = A;
        A = B;
        B = tmp;
    }

    ll R = A % B;
    while(R != 0){
      A = B;
      B = R;
      R = A % B;
  }

  cout << ans / B << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	static String line = "";
	static char[] array = line.toCharArray();
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		line = sc.next();
		int x = sc.nextInt();

		for(int i=0;i<x;i++) {
			String o = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(o.equals("replace")) {
				String c = sc.next();
				replace(a, b, c);
			}else if(o.equals("reverse")) {
				reverse(a, b);
			}else if(o.equals("print")) {
				print(a, b);
			}
		}

		sc.close();
	}

	public static void replace(int a, int b, String c) {
		String x = line.substring(0, a);
		String y = line.substring(b+1);

		line = x + c + y;
	}

	public static void reverse(int a, int b) {
		String x = line.substring(0, a);
		String y = line.substring(b+1);
		String z = line.substring(a, b+1);
		char[] zc = z.toCharArray();
		int count = zc.length - 1;

		String d = "";

		for(int i=0; i<zc.length; i++) {
			d += String.valueOf(zc[count--]);
		}

		line = x + d + y;
	}

	public static void print(int a, int b) {
		System.out.println(line.substring(a, b+1));
	}
}


Measured memory_bytes: 47692
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int input;
    set<int> s;
    for(int i=0;i<n;i++){
        cin >> input;
        if(s.find(input) == s.end())s.insert(input);
        else s.erase(input);
    }
    
    cout << s.size() << endl;
    
    return 0;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    string t = "CODEFESTIVAL2016";
    int ans = 0;
    rep(i, s.size()) if (s[i] != t[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main<i> {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        int s = x - (k - 1);
        int e = x + (k - 1);

        for (int i = s; i <= e; i++) {
            System.out.println(i);
        }
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll l = n*m/gcd(n, m);

    ll p = l/n;
    ll q = l/m;
    ll r = p*q/gcd(p, q);
    for(ll i = 0; i < l; i+=r) {
        if(!(s[i/p] == t[i/q])) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
    return 0;//setprecision(20) <<
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)

string s, t;
int q, a, b, c, d, pres[100050], pret[100050];

int main() {
	cin >> s >> t >> q;
	s = " " + s;
	t = " " + t;
	FOR(i, 1, s.length()-1) {
		pres[i] = pres[i-1] + (s[i] == 'A' ? 1 : 2);
		pres[i] %= 3;
	}
	FOR(i, 1, t.length()-1) {
		pret[i] = pret[i-1] + (t[i] == 'A' ? 1 : 2);
		pret[i] %= 3;
	}
	while (q--) {
		cin >> a >> b >> c >> d;
		if ((pres[b] - pres[a-1] + 3) % 3 == (pret[d] - pret[c-1] + 3) % 3) cout << "YES\n";
		else cout << "NO\n";
	}
}


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

int dp[2][3];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
	
	int t1, t2, t3;
	for (int i = 0; i < n - 1; ++i) {
		cin >> t1 >> t2 >> t3;
		dp[1][0] = max(dp[0][1], dp[0][2]) + t1;
		dp[1][1] = max(dp[0][0], dp[0][2]) + t2;
		dp[1][2] = max(dp[0][0], dp[0][1]) + t3;
		
		for (int i = 0; i < 3; ++i) {
			dp[0][i] = dp[1][i];
		}
	}
	
	cout << max(dp[0][0], max(dp[0][1], dp[0][2])) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

using i64 = long long;
using P = pair<i64, i64>;

int main(){
    i64 n;
    cin >> n;
    vector<i64> a(n), b(n);
    priority_queue<P, vector<P>, greater<P>> pq;
    for(int  i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        pq.push(P(b[i], i));
    }
    i64 t = 0;
    for(int i = 0; i < n; ++i){
        P tp = pq.top(); pq.pop();
        i64 idx = tp.second;
        if(t + a[idx] > b[idx]){
            cout << "No" << endl;
            return 0;
        }
        t += a[idx];
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 9584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, a;
    scanf("%ld%ld", &n, &a);

    printf("%ld\n", n*n-a);
  
    return 0;
}


Measured memory_bytes: 128
import Data.List

large2pow::Int -> Int
large2pow 0 = 1
large2pow n = mod ((large2pow (n-1))*2) 1000000007

solver::Int -> Bool -> Int
solver _  False= 0
solver n  True = if mod n 2 ==0 then large2pow (div n 2) else large2pow (div (n-1) 2)

check::[Int]->Int -> Bool
check dat n
  | (mod n 2 == 0) = ([(2*i)-1|i<-[1..(div n 2)],j<-[0,1]]==(sort dat))
  | (mod n 2 == 1) = ([2*i|i<-[0..(div n 2)],j<-[0,1]]==(0:(sort dat)))


main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  ac<-getLine
  let dat = map read (words ac) ::[Int]
  print (solver n (check dat n))


Measured memory_bytes: 30588
import java.util.*;

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

        int n = s.nextInt();
        String str = s.next();

        String answer;

        if (n % 2 != 0)
            answer = "No";
        else {
            String first = str.substring(0, n / 2);
            String second = str.substring(n / 2);

            answer = first.equals(second) ? "Yes" : "No";
        }

        System.out.println(answer);
    }
}

Measured memory_bytes: 22100
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case)]

macro_rules! input {
    ($($s:tt : $r:tt),*) => {
        let stdin = std::io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        $(let $s:$r = iter.next().unwrap().parse().unwrap();)*
    };
}

macro_rules! input_vv {
    ($s:tt, $n:tt) => {
        let stdin = std::io::stdin();
        for _ in 0..$n {
            let mut buf = String::new();
            stdin.read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            $s.push(
                (iter.next().unwrap().parse().unwrap()
                , iter.next().unwrap().parse().unwrap()))
        }
    };
}

fn main() {
    input!(N:u64);
    let mut AB:Vec<(u64, u64)> = Vec::new();
    input_vv!(AB, N);

    let mut ab = AB.clone();
    ab.sort_by_key(|x| x.1);

    let mut time = 0;
    for (a, b) in ab {
        time += a;
        if b < time {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 13380
h,w = map(int,input().split())
maze =["."*(w+2)] + [ "." + input() + "." for i in range(h) ] + ["."*(w+2)]
ans = []

for i in range(1,h+1):
    temp = ""
    for j in range(1,w+1):
        cnt = 0
        if maze[i][j] == "#":
            temp += "#"
        else:
            for y in range(-1,2,1):
                for x in range(-1,2,1):
                    if maze[i+y][j+x] == "#":
                        cnt += 1
            temp += str(cnt)
    ans += [temp]
for i in range(h):
    print(*ans[i],sep="")

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n, k; cin >> n >> k;
	cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "DEBUG: " << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------

const int N = 1E6 + 100;
int n, K, a[N];
vector<LL> b;

int main() {
    cin >> n >> K;
    FOR (i, 0, n) cin >> a[i];
    FOR (i, 0, n) {
        LL s = 0;
        FOR (j, i, n) {
            s += a[j];
            b.push_back(s);
        }
    }
    LL ans = 0;
    FORD (t, 41, -1) {
        int cnt = 0; ans |= (1LL << t);
        for (const LL& x: b) if ((x & ans) == ans) cnt++;
        dbg(t, cnt);
        if (cnt < K) ans &= ~(1LL << t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn = 1e5+5;
ll n,m;
vector<ll> a;
ll s[maxn];
bool check(ll k)
{
    ll cnt = 0;
    for(int i=0;i<n;i++)
    {
        cnt += a.end()-lower_bound(a.begin(),a.end(),k-a[i]);
    }
    return cnt>=m;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    ll tmp;
    for(int i=0;i<n;i++)
    {
        cin>>tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    for(int i=1;i<=n;i++) s[i] = s[i-1]+a[i-1];
    ll l=0,r=1e6;
    ll base;
    while(l<=r)
    {
        int mid = (l+r)>>1;
        if(check(mid)) {l=mid+1,base=mid;}
        else r=mid-1;
    }
    ll ans = 0,num = 0;
    for(int i=0;i<n;i++)
    {
        int t = lower_bound(a.begin(),a.end(),base-a[i])-a.begin();
        num+=n-t;
        ans+=s[n]-s[t]+(n-t)*a[i];
    }
    ans += (ll)(m-num)*base;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1908
#include<stdio.h>
#include<string.h>
int main()
{   char a[110];
    int i,j,k,l,ck=1;;
    gets(a);
    i=strlen(a);
    for(k=0;k<i;k++)
    {
        l=a[k];
        if(l<97 || l>122)
        {
            ck=0;
            break;
        }
    }
    if(i>=3 && i<=100 && ck==1)
    {


    j=i;
    j=j-2;
    printf("%c%d%c\n",a[0],j,a[i-1]);
    }
    return 0;
}


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

int main() {

	int k, s;
	cin >> k >> s;

	int x, y;
	int count = 0;

	for (x = 0; x <= k; x++) {
		for (y = 0; y <= k; y++) {
			if (s-x-y >= 0 && s-x-y <= k) {
				count++;
			}
		}
	}


	cout << count << endl;

	return 0;

}


Measured memory_bytes: 256
console.log((args=>{
  const [N,A,B] = args.trim().split` `.map(BigInt);
  if ( (B-A) % 2n === 0n ) return `${(B-A)/2n}`;
  return `${((N-B<A-1n)?N-B:A-1n)+(B-A+1n)/2n}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 29552
#include<stdio.h>
#include<stdlib.h>
int main(){
  long long int i,n,a[100010],ans=0,k=0,min=1000000001;
  scanf("%lld\n",&n);
  for(i=0;i<n;i++){
    scanf("%lld ",&a[i]);
    ans=ans+abs(a[i]);
    if(a[i]<0){
      k++;
    }
    if(abs(a[i])<min){
      min=abs(a[i]);
    }
  }
  if(k%2==0){
    printf("%lld\n",ans);
  }
  else{
    printf("%lld\n",ans-min*2);
  }
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;
#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N, T;
  cin >> N >> T;

  int min_v = INF;
  int max_d = 0;
  int cnt = 0;
  REP(i, N) {
    int A;
    cin >> A;
    if(max_d == A - min_v) {
      cnt++;
    } else if(max_d < A - min_v) {
      cnt = 1;
      max_d = A - min_v;
    }
    max_d = max(max_d, A - min_v);
    min_v = min(min_v, A);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
use std::io;


fn main() {
    let mut n = read::<usize>();
    n.sort();
    if n[0] + n[1] == n[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string t;
 
  cin >> t;
  
  for (int i = 0; i < t.size(); i++) {
 
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
 
  }
  cout << t << endl;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

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

/*
int N;
ll h[100010];

// DP テーブル
ll dp[100010];
*/

int main()
{
	int N, K; cin >> N >> K;
	string S; cin >> S;

	vector<int> nums;

	if (S[0] == '0') nums.push_back(0);

	for (int i = 0; i < S.size();)
	{
		int j = i;

		while (j < S.size() && S[j] == S[i]) j++;
		nums.push_back(j - i);
		i = j;
	}

	if (S[0] == '0') nums.push_back(0);

	vector<int> sums((int)nums.size() + 1);
	for (int i = 0; i < nums.size(); i++) sums[i + 1] = sums[i] + nums[i];

	int res = 0;

	for (int left = 0; left < sums.size(); left += 2)
	{
		int right = left + 2 * K + 1;
		if (right >= sums.size()) right = sums.size() - 1;

		res = max(res, sums[right] - sums[left]);
	}

	cout << res << endl;
}


Measured memory_bytes: 1272
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(*A)
print(count)



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

#define MAX 100

int main() {
  int n;
  int i, j;
  int temp;
  int x[MAX];
  int suma, sumb;

  cin >> n;
  
  for (i = 0; i < n; i++){
    cin >> x[i];
  }
  
  for (i = 0; i < n; i++){
    for (j = i; j < n; j++){
      if (x[i] < x[j]) {
        temp = x[i];
        x[i] = x[j];
        x[j] = temp;
      }
    }
  }
  
  suma = 0;
  sumb = 0;
  for (i = 0; i < n; i++) {
    if ((i % 2) == 0) {
      suma += x[i];
    } else {
      sumb += x[i];
    }
  }
  cout << (suma - sumb) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll N, i,ans, l[50], K;
int main()
{
    cin >> N >> K;
    for(i=0;i<N;i++)
    {
        cin >> l[i];
    }
    sort(l, l+N);
    for(i=N-1;i>N-K-1;i--)
    {
        ans += l[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
constexpr int INF = std::numeric_limits<int>::max() / 2;  // 1.073741823e9
constexpr int64 INF64 = std::numeric_limits<int64>::max() / 2;  // 4.611686018427387903e18
constexpr int MOD = 1000000007;

template<typename T> std::vector<T> divisor(T n) {
  std::vector<T> res;
  for (T i = 1; i * i <= n; ++i) {
    if (n % i == 0){
      res.push_back(i);
      if (i * i != n){
        res.push_back(n / i);
      }
    }
  }
  std::sort(res.begin(), res.end());

  return res;
}

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int64 n; cin >> n;
  vector<int64> vec = divisor(n);

  int64 ans = 1e15;
  for (size_t i = 0; i < vec.size(); ++i) {
    if (vec[i] + n / vec[i] - 2 < ans) {
      ans = vec[i] + n / vec[i] - 2;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#define ll long long
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

const int N = 1e5;
int x[N * 2 + 10], y[N * 2 + 10], fa[N * 2 + 10];

int getfa(int u) {
	return u == fa[u] ? u : fa[u] = getfa(fa[u]);
}

void unit(int u, int v) {
	u = getfa(u);
	v = getfa(v);
	if (u == v) return;
	x[u] += x[v];
	y[u] += y[v];
	x[v] = y[v] = 0;
	fa[v] = u;
}

int main() {
	for (int i = 1; i <= 2 * N; i++) {
		fa[i] = i;
		if (i <= N) x[i] = 1;
		if (i > N) y[i] = 1;
	}
	int n = read();
	int t = n;
	while (n--) {
		int u = read(), v = read();
		v += N;
		unit(u, v);
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++) ans += 1LL * x[i] * y[i];
	printf("%lld\n", ans - t);
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = (1 << 30) - 1;
const ll LINF = (1L << 62) - 1;
const ll MOD = 1000000007;
template <class T> inline void chmin(T& a, T& x) { a = a < x ? a : x; }
template <class T> inline void chmax(T& a, T& x) { a = a > x ? a : x; }

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

  int q;
  string s;
  cin >> s >> q;
  bool isReverse = false;
  string r = "";
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      isReverse = isReverse ? false : true;
    } else {
      int f;
      char c;
      cin >> f >> c;
      bool back = (f == 1 && isReverse) || (f == 2 && !isReverse);
      if (back) {
        s.push_back(c);
      } else {
        r.push_back(c);
      }
    }
  }
  reverse(all(r));
  s = r + s;
  if (isReverse) reverse(all(s));
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 1196
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 1/20/2019, 8:47:19 PM
# Powered by Visual Studio Code
#

x = gets.chomp.split(" ").map{|i| i.to_i}
x.sort!
puts x[0] * x[1] / 2


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    string a;
    int n;
    cin>>n;
    cin>>a;
    int ans = 0;
    for(int i = 0; i < n-2; i++){
        if(a[i] == 'A' && a[i+1] == 'B' && a[i+2] == 'C'){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


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

int main(){
    string s;cin>>s;
    if(s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout << "ABC"<<endl;
    }
}

Measured memory_bytes: 3628
import itertools

n, m, q = map(int, input().split())
a = []
b = []
c = []
d = []
for _ in range(q):
    a_, b_, c_, d_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
    c.append(c_)
    d.append(d_)

max_score = -1
for v in itertools.combinations_with_replacement(tuple(range(1, m+1)), n):
    scores = []
    for i in range(q):
        if v[b[i]-1] - v[a[i]-1] == c[i]:
            scores.append(d[i])
    score = sum(scores)
    if max_score < score:
        max_score = score
print(max_score)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {cout << "Balanced" << endl;
       }
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    if(N==M){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define inf			1e12
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n, w;
	cin >> n >> w;

	int sum = 0;
	vector<vector<int>> v(n, vector<int>(2));

	for (int i = 0; i < n; i++) {
		cin >> v[i][1] >> v[i][0];
		sum += v[i][0];
	}

	sort(v.begin(), v.end());

	vector<vector<int>> dp(sum + 1, vector<int>(n + 1, inf));

	for (int i = 0; i <= n; i++)
		dp[0][i] = 0;

	for (int i = 1; i <= sum; i++) {
		for (int j = 1; j <= n; j++) {
			if (v[j - 1][0] > i) {
				dp[i][j] = dp[i][j - 1];
				continue;
			}
			int valLeft = i - v[j - 1][0];

			dp[i][j] = min(dp[i][j - 1], v[j - 1][1] + dp[valLeft][j - 1]);
		}
	}

	int ans = 0;

	for (int i = sum; i > 0; i--) {
		if (dp[i][n] <= w) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

long long n,a,b;

int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if(n>1&&b>=a||n==1&&b==a)
		printf("%lld\n",(n-2)*(b-a)+1);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

k = onem()

a,b = m()

aa = -(-a//k)

bb = b//k
if aa <= bb:
    print("OK")
else:
    print("NG")








Measured memory_bytes: 65120
#
# abc093 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 5 4"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 6 3"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """31 41 5"""
        output = """23"""
        self.assertIO(input, output)


def resolve():
    I = list(map(int, input().split()))
    I.sort()

    t = 2*I[2]-I[0]-I[1]
    # X = max(A, B, C)
    if t % 2 == 0:
        print(t//2)
    # X = max(A, B, C) + 1
    else:
        print((t+3)//2)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16260
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d%d", &a,&b);
	if (a != 1 && b != 1)
	{
		printf("1");
	}
	if (a != 2 && b != 2)
	{
		printf("2");
	}
	if (a != 3 && b != 3)
	{
		printf("3");
	}
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
// #include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif




int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    long long int n; std::cin >> n;
    long long int res = 0;
    for(long long int x = 1; ; ++x){
        long long int y = n / x; if(x * y >= n) --y;
        if(y <= 0) break;
        res += y;
    }
    std::cout << res << '\n';
    


    

    return 0;
}

Measured memory_bytes: 3644
using System;

class Program
{
    static void Main()
    {
        int[, ,] house = 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++)
                {
                    house[i, j, k] = 0;
                }


        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int b = int.Parse(s[0]) - 1;
            int f = int.Parse(s[1]) - 1;
            int r = int.Parse(s[2]) - 1;
            int v = int.Parse(s[3]);
            house[b, f, r] += v;
        }

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write(" {0}", house[i, j, k]);
                }
                Console.WriteLine();
            }
            if(i != 3)
            {
                Console.Write("####################");
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9076
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] As = new int[N+1];
		int[] Bs = new int[N+1];
		int[] Cs = new int[N+1];
		int[][] dp = new int[N+1][3];

		As[0] = 0;
		Bs[0] = 0;
		Cs[0] = 0;
		for (int i = 0; i <= N; ++i) {
			for (int j = 0; j < 3; ++j) {
				dp[i][j] = 0;
			}
		}
		for (int i = 1; i <= N; ++i) {
			As[i] = sc.nextInt();
			Bs[i] = sc.nextInt();
			Cs[i] = sc.nextInt();
		}
		dp[1][0] = As[1];
		dp[1][1] = Bs[1];
		dp[1][2] = Cs[1];


		//dp[i][j] := i日目までの最大の幸福度。jは、a or b or c ( 0 or 1 or 2)
		for (int i = 2; i <= N; ++i) {
			dp[i][0] = Math.max(dp[i-1][1] + As[i], dp[i-1][2] + As[i]);
			dp[i][1] = Math.max(dp[i-1][0] + Bs[i], dp[i-1][2] + Bs[i]);
			dp[i][2] = Math.max(dp[i-1][0] + Cs[i], dp[i-1][1] + Cs[i]);
		}
		System.out.println(Math.max(dp[N][2],Math.max(dp[N][0], dp[N][1])));
	}

}


Measured memory_bytes: 105996