akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)

int main() {
  int x,a,b;cin>>x>>a>>b;
  int c = abs(x-a);
  int d = abs(x-b);
  char ans = c < d ? 'A': 'B';
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = list(map(int, input().split()))
s = sum(l)
c = 0
p = 0
for el in l:
    if el >= (s/(m*4)):
        c = c + 1
    if c == m:
        p = 1
        break

if p == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// range sum query using segment tree

class segment_tree {
	vector<long> t;
	long size;
public:
	segment_tree() {
	}

	segment_tree(long n) {
		t.assign(4 * n + 1, 0);
		size = n;
	}

	void initialize(long n) {
		t.assign(4 * n + 1, 0);
		size = n;
	}

	void initialize_with_array(long startpos, long l, long r, vector<int>& v) {
		if (l == r) {
			t[startpos] = v[l];
		}
		else {
			long m = (l + r) / 2;
			initialize_with_array(2 * startpos, l, m, v);
			initialize_with_array(2 * startpos + 1, m + 1, r, v);

			t[startpos] = t[startpos * 2] + t[startpos * 2 + 1];
		}
	}

	void initialize_array(vector<int>& v) {

		initialize_with_array(1, 0, size - 1, v);
	}


	void update(long index, long val) { // insert val into location index
		update_full(1, 0, size - 1, index, val);
	}

	void update_full(long startpos, long l, long r, long index, long val) {
		if (l > r) return;
		if (l == r) {
			t[startpos] += val;
		}
		else {
			long m = (l + r) / 2;
			if (index <= m) update_full(2 * startpos, l, m, index, val);
			else update_full(2 * startpos + 1, m + 1, r, index, val);

			t[startpos] = t[startpos * 2] + t[startpos * 2 + 1];	// range sum
		}
	}

	long query(long l, long r) {  // get range min/max between l and r
		if (l > r) {
			return 0;
		}
		return query_full(1, 0, size - 1, l, r);
	}

	long query_full(long startpos, long left, long right, long l, long r) {	 // left/right = current range, l/r = intended query range
		if ((left >= l) && (right <= r)) return t[startpos];
		long m = (left + right) / 2, ans = 0;
		if (m >= l) {
			ans += query_full(startpos * 2, left, m, l, r);
		}
		if (m + 1 <= r) {
			ans += query_full(startpos * 2 + 1, m + 1, right, l, r);
		}
		return ans;
	}
};

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

	long long n, i, j, k, ans = 0;
	cin >> n >> k;
	vector<long long> s(n + 1, 0), a(n + 1);
	for (i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] -= k;
		s[i] = s[i - 1] + a[i];
	}
	vector<pair<long long, long long>> plist(n + 1);
	for (i = 0; i <= n; i++) plist[i] = { s[i], i };
	sort(plist.begin(), plist.end());

	segment_tree st(n + 1);
	for (i = 0; i <= n; i++) {
		ans += st.query(0, plist[i].second - 1);
		st.update(plist[i].second, 1);
	}

	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 12800
#include <iostream>
#include <map>

using namespace std;

int n, Q;
long long ans(0);
map<int, int> q;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        ans += x;
        q[x]++;
    }
    cin >> Q;
    while (Q--) {
        int x, y;
        cin >> x >> y;
        if (q.find(x) != q.end()) {
            ans += (y - x) * q[x];
            q[y] += q[x];
            q[x] = 0;
        }
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 7308
#include <iostream>

using namespace std;

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

    int mi = 1145141919, ret = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (mi > p) mi = p, ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
typedef pair<int,int> I;

int main(){
    int n,m;
    cin>>n>>m;
    I s[100010];
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        s[i]=make_pair(--b,a);
    }
    sort(s,s+m);
    int ans=1,r=s[0].first;
    for(int i=1;i<m;i++){
        if(r<s[i].second){
            ans++;
            r=s[i].first;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include    <iostream>

using namespace std;

int main() {
    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;
    cout << (((0 <= x-r && x+r <= W) && (0 <= y-r && y+r <= H)) ? ("Yes") : ("No")) << endl;

    return 0;
}


Measured memory_bytes: 3116
n = list(map(int,input().split()))
n.sort(reverse=True)
a = n[0]-n[1]
b = n[0]-n[2]
if a == 0 and b == 0:
    print(0)
if a != 0 and b == 0:
    if a%2 == 0:
        print(int(a/2))
    elif a == 1:
        print(2)
    elif a%2 != 0:
        print(int(2+(a-1)/2))
if a == 0 and b != 0:
    if b%2 == 0:
        print(int(b/2))
    elif b == 1:
        print(2)
    elif b%2 != 0:
        print(int(2+(b-1)/2))
if a != 0 and b != 0:
    if a == 1 and b == 1:
        print(1)
    elif a%2 == 0 and b%2 == 0:
        print(int(a/2+b/2))
    elif a%2 != 0 and b%2 == 0:
        print(int(2+(a-1)/2+b/2))
    elif a%2 == 0 and b%2 != 0:
        print(int(2+a/2+(b-1)/2))
    elif a%2 != 0 and b%2 != 0:
        print(int(1+(a-1)/2+(b-1)/2))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_set>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll m, n;
    cin >> m >> n;
    
    vector<vector<int>> vec(m,vector<int>(n, 0));
    for(int i= 0; i<m;i++){
        for(int j = 0;j<n;j++){
            char x;
            cin >> x;
            vec[i][j] = x;
        }
    }
    
    vector<vector<int>> dp(m,vector<int>(n, 0));
    
    dp[0][0] = (vec[0][0] == '#');
    
    // for(int i = 1;i<dp.size();i++){
    //     dp[0][i] = dp[0][i-1] + (vec[0][i-1] == '.' && vec[0][i] == '#');
    // }
    
    // for(int i = 1;i<dp.size();i++){
    //     dp[i][0] = dp[i-1][0] + (vec[i-1][0] == '.' && vec[i][0] == '#');
    // }
    
    for(int i= 0; i<m;i++){
        for(int j = 0;j<n;j++){
            if(i+j != 0){
            if(i == 0){
                dp[i][j] = dp[i][j-1] + (vec[i][j-1] == '.' && vec[i][j] == '#');
            }
            else if(j == 0){
                dp[i][j] = dp[i-1][j] + (vec[i-1][j] == '.' && vec[i][j] == '#');
            }
            else{
            dp[i][j] = min(dp[i-1][j] + (vec[i-1][j] == '.' && vec[i][j] == '#')
                          ,dp[i][j-1] + (vec[i][j-1] == '.' && vec[i][j] == '#'));
            }
            }
            
        }
    // cout << '\n';
    }
    cout << dp[m-1][n-1];
}








Measured memory_bytes: 384
import numpy as np

N, T = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

# 自分より左にある最安値
A_cummin = np.minimum.accumulate(A)
# 差額
profit = A - A_cummin

ans = (profit == profit.max()).sum()
print(ans)


Measured memory_bytes: 24228
while True:
    a, op, c = input().split()
    if op == "?": break
    elif op == "+": print(int(a) + int(c))
    elif op == "-": print(int(a) - int(c))
    elif op == "*": print(int(a) * int(c))
    elif op == "/": print(int(a) // int(c))


Measured memory_bytes: 5596
//16
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

struct S{
  int c,nc,ng;
};

int main(){
  for(int n,u;cin>>n>>u,n|u;){
    int ng[20],pr[20]={};
    for(int i=0;i<n;i++){
      int k;
      cin>>ng[i]>>k;
      while(k--){
	int r;
	cin>>r;
	pr[i]|=1<<r;
      }
    }
    queue<S> que;
    S is={0,0,0};
    que.push(is);
    bool p[1<<20];
    fill(p,p+(1<<n),false);
    for(;;){
      S c=que.front();
      if(c.ng>=u)break;
      que.pop();
      if(p[c.c]++)continue;
      for(int i=0;i<n;i++){
	if(!(c.c&1<<i)&&!(pr[i]&~c.c)){
	  S n={c.c|1<<i,c.nc+1,c.ng+ng[i]};
	  que.push(n);
	}
      }
    }
    cout<<que.front().nc<<endl;
  }
  return 0;
}

Measured memory_bytes: 26648
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

bool G[20][20];
vector<pair<int, int> > DXDY { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int main() {
  int h, w; cin >> h >> w;
  loop(y,0,h) loop(x,0,w) {
    char c; cin >> c;
    G[y][x] = c == '.';
  }
  int max_ = 0;
  const int INF = 10000000;
  loop(startY,0,h) loop(startX,0,w) {
    if (!G[startY][startX]) continue;
    int dp[20][20];
    loop(y,0,h) loop(x,0,w) dp[y][x] = INF;
    queue<pair<int, int> > Q;
    Q.push({ startX, startY });
    dp[startY][startX] = 0;
    bool finish = false;
    while (Q.size() and !finish) {
      auto xy = Q.front(); Q.pop();
      for (auto&&dxdy : DXDY) {
        int x = xy.first + dxdy.first;
        int y = xy.second + dxdy.second;
        if (x < 0 or x >= w) continue;
        if (y < 0 or y >= h) continue;
        if (!G[y][x]) continue;
        if (dp[y][x] < INF) continue;
        dp[y][x] = dp[xy.second][xy.first] + 1;
        Q.push({ x, y });
      }
    }
    
    loop(y,0,h) loop(x,0,w) {
      if (dp[y][x] == INF) continue;
      max_ = max(max_, dp[y][x]);
    }
  }
  cout << max_ << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
int main(void){
    char s[101], p[101], tmp;
    int  i, j, sn=0, pn=0, count=0;
    
    scanf("%s %s", s, p);
    
    while(s[sn] != '\0') sn++;
    while(p[pn] != '\0') pn++;
    
    for(i=0; i<sn; i++){
        
        //最初の文字で判定
        for(j=0; j<pn; j++){
            if(p[j] == s[j]){
                count++;
            }
        }
        if(count == pn){
            puts("Yes");
            break;
        }
        
        //文字の入れ替え
        tmp = s[0];
        for(j=0; j<sn; j++){
            s[j] = s[j+1];
        }
        s[sn-1] = tmp;
        
        //全て当てはまらなかった時、Noと表示
        if(i == sn - 1){
            puts("No");
        }
        
        //リセット
        count = 0;
    }
    
    return 0;
}



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

using namespace std;
typedef long long ll;

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

int n, m, k;
char row[1000'010];
int xs, ys, xe, ye;
vector<vector<char>> board;
vector<vector<int>> dist;

int main() {
    scanf("%d%d%d", &n, &m, &k);
    scanf("%d%d%d%d", &xs, &ys, &xe, &ye);
    board = vector<vector<char>>(n + 2, vector<char>(m + 2, '@'));
    dist = vector<vector<int>>(n + 2, vector<int>(m + 2, INF));
    for (int i = 1; i <= n; i++) {
        scanf("%s", &row[1]);
        for (int j = 1; j <= m; j++) board[i][j] = row[j];
    }

    dist[xs][ys] = 0;
    queue<pair<int, int>> q;
    q.push({xs, ys});
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= k; j++) {
                int xx = x + dx[i] * j;
                int yy = y + dy[i] * j;
                if (board[xx][yy] == '@' || dist[xx][yy] <= dist[x][y])
                    break;
                if (dist[xx][yy] == dist[x][y] + 1)
                    continue;
                dist[xx][yy] = dist[x][y] + 1;
                q.push({xx, yy});
            }
        }
    }
    int ans = dist[xe][ye];
    if (ans == INF) ans = -1;
    printf("%d\n", ans);
}


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

int n, r;
int p[64], c[64];

int main() {
  for(;;) {
    scanf("%d %d", &n, &r);
    if( n == 0 and r == 0 ) break;
    for(int i = 0; i < r; ++i) {
      scanf("%d %d", &p[i], &c[i]);
    }
    int res = n;
    for(int i = r - 1; i >= 0; --i) {
      if( n - c[i] < res ) {
        res -= p[i] - 1;
      }
      else if( n - c[i] - (p[i] - 1) < res and res <= n - c[i] ) {
        res += c[i];
      }
    }
    printf("%d\n", res);
  }

  return 0;
}

Measured memory_bytes: 3184
n = int(input())
 
def check(p):
  c = 0
  for i in range(1,p+1):
    if p % i == 0:
      c += 1
  return c
 
ans = 0
for i in range(1,n+1):
  if i % 2 == 1:
    if check(i) == 8:
      ans += 1
      
print(ans)

Measured memory_bytes: 9092
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int d[111], f[111];
bool visited[111];
vector<vector<int> > g(111);
int t;
void dfs(int x){
  t++;
  d[x] = t;
  visited[x] = true;
  for(auto &u : g[x]){
    if(!visited[u]){
      dfs(u);
    }
  }
  t++;
  f[x] = t;
}

int main(){
  int n; cin >> n;
  FOR(i,0,n){
    int u, k; cin >> u >> k;
    FOR(j,0,k){
      int v;
      cin >> v;
      g[u].push_back(v);
    }
  }
  FOR(i,0,n+1) visited[i] = false;
  t = 0;
  FOR(i,1,n+1){
    if(!visited[i]) dfs(i);
  }

  FOR(i,1,n+1){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

Measured memory_bytes: 3232
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//

ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if (a==0) return 0; if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(void) {

    int N, M; cin >> N >> M;
    ll ans;
    if (abs(N - M) >= 2) {
        ans = 0;
    }
    else if (abs(N - M) == 1) {
        ans = modmul(modfact(N),modfact(M));
    }
    else {
        ans = modmul(2, modmul(modfact(N), modfact(M)));
    }
    out(ans);




    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int a = 0;
	int hantei = 0;
	int b[3]={0};

	for (i = 0; i < 3; i++)
	{
			scanf("%d", &a);
			b[i] = a;
			a = 0;
	}

	if (b[2] == 1)
	{
		hantei = 2;
	} else {
		hantei = b[0] + b[1] + b[2];
	}

	if (hantei == 2)
	{
		printf("Open\n");
	
	} else {

		printf("Close\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long int ll;
using namespace std;

int main()
{
  int x,a;
  cin >> x >> a;
  if(x<a) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string s;
  	cin >> s;
  	long long int key;
  cin >> key;
  char ans = s[0];
  for (int i = 0; i < s.size() && i < key; i++){
  	if(s[i] != '1') {
    	ans = s[i];
      break;
    }
  }
  cout << ans <<'\n';
}

Measured memory_bytes: 256
// organize and stay in moment  - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define f(i,x,n) for(int i=x;i<n;++i)
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int m=1e9+7;

vector<int> pr;
int prime[200005]={0};
void seive(){
  for(int i=2;i<200005;++i){
    if(prime[i]==0){
      pr.pb(i);
      for(int j=2*i;j<200005;j+=i){
        prime[j]=1;
      }
    }
  }
}

// -----------------------------------------------------------------------
 
 
 int exp(int a,int b){
  int r=1;
  while(b!=0){
    if(b&1){
      r*=a;
    }
    b/=2;
    a*=a;
  }
  return r;
 }

// -----------------------------------------------------------------------

 
void solve(){ 
  int h1,m1,h2,m2,k; 
  cin>>h1>>m1>>h2>>m2>>k;
  int h=(h2-h1-1)*60;
  h+=(m2+60-m1-k);
  cout<<h;
}
 
// -----------------------------------------------------------------------
 
 
int32_t main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);  
  int t=1; //  cin>>t;
  //seive();
  while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,ans=0;cin>>n>>m;
  vector<int> all(m,n);
  for(int i=0;i<n;i++){
    int k;cin>>k;
    for(int j=0;j<k;j++){
      int t;cin>>t;t--;
      all.at(t)--;
    }
  }
  for(int i=0;i<m;i++) if(!all.at(i)) ans++;
  cout<<ans<<endl;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;

    std::vector<pair<int, bool>> B(N);
    REP(i, N) {
        int b;
        std::cin >> b;
        B[i] = make_pair(b, false);
    }

    auto get_max_itr = [&]() -> auto {
                           int max = 0;
                           auto ret = B.begin();
                           FOR(v, B) {
                               if(v->second) continue;
                               if(max <= v->first) {
                                   max = v->first;
                                   ret = v;
                               }
                           }
                           return ret;
                       };

    auto itr = get_max_itr();
    vector<int> ans;
    vector<int> table(N, 0);
    while(true) {
        auto index = distance(B.begin(), itr);
        if(!itr->second && index + 1 == itr->first + table[index]) {
            ans.push_back(itr->first);
            itr->second = true;
            for_each(table.begin() + index, table.end(), [](int& x){ x++; });
            itr = get_max_itr();
        }
        else if(itr == B.begin()) {
            if(ans.size() != B.size()) {
                std::cout << -1 << std::endl;
            }
            else {
                reverse(ALL(ans));
                REP(i, N) {
                    std::cout << ans[i] << std::endl;
                }
            }
            break;
        }
        else {
            itr--;
        }
    }

    return 0;
}


Measured memory_bytes: 256
W, H, N = gets.split.map(&:to_i)
l, r, t, b = [0, W, H, 0]
N.times do 
    x, y, a = gets.split.map(&:to_i)
    case a
    when 1
        l = [l, x].max
    when 2
        r = [r, x].min
    when 3
        b = [b, y].max
    when 4
        t = [t, y].min
    end
end
p [r-l, 0].max * [t-b, 0].max

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

int main()
{
	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	string C;
	cin >> C;

	if (S == C) A--;
	if (T == C) B--;

	cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[27],b[27];

int main() {
	ll n;
	cin>>n;
	for(int i=0;i<27;i++){
		b[i]=INF;
	}
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		for(int j=0;j<s.size();j++){
			char z=s[j];
			a[z-'a']++;
		}
		for(int j=0;j<27;j++){
			b[j]=min(a[j],b[j]);
			a[j]=0;
		}
	}
	for(int i=0;i<27;i++){
		if(b[i]==0){
			continue;
		}
		for(int j=0;j<b[i];j++){
			cout << char(i+'a');
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
  int n,m;
  cin >> n>> m;
  vector<P> ans;
  //偶奇場合分け
  if(n%2) {//奇数
    for(int l=1,r=n-1;l < r;l++,r--){
      ans.emplace_back(l,r);
    }
  }else{//偶数
    bool flag = false;
    for(int l = 1,r=n-1;l<r;l++,r--){
      if(!flag && r-l <= n/2){
        --r;
        flag = true;
      }
      ans.emplace_back(l,r);
    }
  }
  rep(i,m){
    printf("%d %d\n",ans[i].first, ans[i].second);
  }
  return 0;
} 

Measured memory_bytes: 4296
#include <iostream>

using namespace std;

int ans[500][500];
//int m = 0;

void calc(int n, int s, int m){
    if(s == 1) return;
    for(int i = n; i < n+s/2; i++){
        for(int j = n+s/2; j <n+s; j++){
            ans[i][j] = m;
        }
    }
    calc(n, s/2, m+1);
    calc(n+s/2, s-s/2, m+1);
}

int main(){
    int N;
    cin >> N;
    calc(0, N, 1);
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            cout << ans[i][j];
            if(j == N-1) cout << endl;
            else cout << ' ';
        }
    }
}

Measured memory_bytes: 1408
N=int(input())
suits=["S","H","C","D"]
cards=[]
for _ in range(N):
	s,n=input().split()
	if s=="S":
		cards.append(int(n))
	elif s=="H":
		cards.append(13+int(n))
	elif s=="C":
		cards.append(26+int(n))
	else:
		cards.append(39+int(n))
for i in range(1,53):
	if i not in cards:
		print(suits[(i-1)//13],(i-1)%13+1)




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

using namespace std;

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

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

bool func(string s)
{
    vvi G = {{1, 2}, {6, 3}, {1, 6}, {4, 5}, {5, 2}, {2, 1}, {6, 6}};
    
    int p = 0;
    for(char c : s){
        p = G[p][c-'0'];
    }
    
    return p == 5;
}

int main()
{
    string s;
    while(cin >> s, s != "#"){
        cout << (func(s) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, k, ans;
vector<Int> p;
vector<Int> q;
template <class M> class sliding_window{
public:
	vector<M> &v;
	Int k, pos = -1;
	function<bool(M, M)> fn;
	deque<Int> dq;
	sliding_window(vector<M> &_v, Int _k, function<bool(M, M)> _fn) : v(_v), k(_k), fn(_fn) {};
	M get(Int p){
		assert(pos <= p);
		for(; pos<p; ++pos){
			Int t = pos + 1;
			while(!dq.empty() && fn(v[t], v[dq.front()])) dq.pop_front();
			while(!dq.empty() && fn(v[t], v[dq.back()])) dq.pop_back();
			dq.push_back(t);
		}
		while(!dq.empty() && dq.front() < p-k) dq.pop_front();
		assert(!dq.empty());
		return v[dq.front()];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	p.resize(n);
	for(auto &i:p) cin >> i;
	q.resize(n);
	q[0] = 1;
	for(Int i=1; i<n; ++i) q[i] = p[i] > p[i-1] ? q[i-1] + 1 : 1;
	ans = 1;
	bool f = (q[k-1] < k);
	sliding_window<Int> a(p, k, [](Int x, Int y){return x<y;}), b(p, k, [](Int x, Int y){return x>y;});
	for(Int i=k; i<n; ++i){
		bool g, h;
		g = a.get(i) == p[i-k];
		h = b.get(i) == p[i];
		if(q[i] >= k){
			if(f) ++ans;
			f = false;
		}else if(!g || !h){
			++ans;
		}
//		cout << i << "\n";
//		for(auto i:a) cout << i << " ";
//		cout << "\n";
//		cout << i << " " << "01"[g] << " " << "01"[h] << "\n";
	}
	cout << ans << "\n";
}

Measured memory_bytes: 4992
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int ans = 0;
int A[100];

void dfs(int x, int y, int c){
	if(x == y){
		ans += A[x] -c;
		return;
	}

	int m = 101;
	for(int i = x; i <=y; i++){
		if(A[i] < m) m = A[i];
	}
	
	for(int i = x; i <=y; i++){
		if(A[i] == m){
			ans += m - c;
			dfs(x, i-1, m);
			if(i < y) dfs(i+1, y, m); 
			break;
		}
	}
	
}

int main(){

	int N;

	cin >> N;

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

	dfs(0, N-1, 0);

	cout << ans << endl;

	return 0;
}


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

signed main() {
    int K, A, B;
    cin >> K >> A >> B;

    if (A + 2 >= B) {
        cout << K + 1 << endl;
        return 0;
    }

    int ans = A;
    ans += (K - A + 1) / 2 * (B - A);
    ans += (K - A + 1) % 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
const ll BetsuMOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	ll n, k;
	cin >> n >> k;
	VV dp(61, V(n)); // ダブリングは繰り返し二乗法みたいな
	rep(i, n) {
		cin >> dp[0][i];
		dp[0][i]--;
	}
	rep(i, 60) rep(j, n) {
		dp[i + 1][j] = dp[i][dp[i][j]];
	}
	int ans = 0;
	rep(i, 61) {
		if (k & (1LL << i)) ans = dp[i][ans];
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 51792
x,y = map(int,input().split())
cnt = 0
if y<(2*x):
    cnt+=1
if y>(4*x):
    cnt+=1
if (y-(2*x))%2 != 0:
    cnt+=1
if cnt==0:
    print("Yes")
if cnt!= 0:
    print("No")

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

int main() {
  int k, s;
  cin >> k >> s;
  
  int cnt = 0;
  rep(x, k+1) {
    if (x > s) break;
    rep(y, k+1) {
      if (x+y > s) break;
      int z = s-x-y;
      if (z >= 0 && z <= k) cnt++;
    }
  }
  
  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>

using namespace std;
typedef long long ll;
int MAX_N = 50;
int MAX_M = 50;
int N,M;
vector<vector<int>> eg(MAX_N,vector<int>(MAX_N));
vector<int> A(MAX_M),B(MAX_M);
set<int> se;
bool res;

bool dfs(int u){
    //cout << u << " " << se.size()  << endl;
    if(se.size()==N) {
        return true;
    }

    for(int v=0;v<N;v++){
        if(eg[u][v]==1 && se.count(v)==0) {
            se.insert(v);
            res = dfs(v);
            //se.erase(v);
        }
    }
    return res;
}

int main() {

    cin >> N >> M;
    vector<int> ct(N);
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        A[i]--,B[i]--;
        ct[A[i]]++,ct[B[i]]++;
        eg[A[i]][B[i]] = 1;
        eg[B[i]][A[i]] = 1;
    }
    int st=0;
    for(int i=0;i<N;i++){
        if(ct[i]==1){
            st=i;
            break;
        }
    }
    //cout << st << endl;
    int ans=0;
    for(int i=0;i<M;i++){
        eg[A[i]][B[i]]=0;
        eg[B[i]][A[i]]=0;
        bool jg=false;
        se.erase(se.begin(),se.end());
        se.insert(st);
        res=false;
        //cout << endl;
        //cout << i << " " << A[i] << " " << B[i] << endl;
        jg=dfs(st);
        se.erase(st);
        if(!jg) ans++;
        eg[A[i]][B[i]]=1;
        eg[B[i]][A[i]]=1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//Volume5-0533
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args){

		final int   N = 10;
		      int[] W = new int[N],
			        K = new int[N];

		Scanner sc = new Scanner(System.in);
		for(int i=0;i<N;i++){W[i] = sc.nextInt();}
		for(int i=0;i<N;i++){K[i] = sc.nextInt();}
		Arrays.sort(W);
		Arrays.sort(K);
		System.out.println((W[7]+W[8]+W[9])+" "+(K[7]+K[8]+K[9]));
	}
}

Measured memory_bytes: 17372
N, K = gets.chomp.split.map(&:to_i)
dArr = []
aArr = []
K.times do |k|
    dArr.push(gets.chomp.to_i)
    aArr.push(gets.chomp.split.map(&:to_i))
end

puts (N - aArr.flatten.uniq.size).to_s

Measured memory_bytes: 14548
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x)             (int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x)         cout << #x << " = " << x << endl
#define trace(x)         cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){
    
	int a, b, c, k; cin>>a>>b>>c>>k;
	if(k<=a) cout<<k;
	else if(k>a and k<=(a+b)) cout<<a;
	else if(k>a+b){
		int left = k-(a+b);
		cout<<a-left;
	}
	
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3484
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2*n-1) {
    cout << "No" << endl;
    return 0;
  }
  if (x == 2) {
    cout << "Yes" << endl;
    int d = 3;
    for (int i = 1; i <= 2*n-1; ++i) {
      if (i == n-1) cout << x;
      else if (i == n) {
        cout << 1;
      }
      else {
        cout << d;
        ++d;
      }
      cout << endl;
    }
    return 0;
  }
  if (x == 2*n-2) {
    cout << "Yes" << endl;
    int d = 1;
    for (int i = 1; i <= 2*n-1; ++i) {
      if (i == n-1) cout << x;
      else if (i == n) {
        cout << 2*n-1;
      }
      else {
        cout << d;
        ++d;
      }
      cout << endl;
    }
    return 0;
  }
  cout << "Yes" << endl;
  int d = 3;
  for (int i = 1; i <= 2*n-1; ++i) {
    if (i == n-2) cout << 2*n-1;
    else if (i == n-1) cout << 1;
    else if (i == n) cout << x;
    else if (i == n+1) cout << 2*n-2;
    else if (i == n+2) cout << 2;
    else {
      if (d == x) ++d;
      cout << d;
      ++d;
    }
    cout << endl;
  }
}

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

using namespace std;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = n; i >= 0; --i) {
        if (s.substr(n - i, i) == t.substr(0, i)) {
            cout << 2 * n - i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cctype>
 
using namespace std;
 
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)

int main() {
    int n;
    cin >> n;
    int a[114];
    rep(i,n) cin >> a[i];

    int cnt_swap = 0;
    FOR(i,0,n) FOR(j,1,n) {
        if(a[j-1] > a[j]) swap(a[j-1], a[j]), ++cnt_swap;
    }

    rep(i,n) {
        cout << a[i];
        if(i != n-1) cout << " ";
    }
    cout << "\n";
    cout << cnt_swap << endl;


    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 99999999;
int main(){
  ll n,x,y;
  cin >> n >> x >> y;
  vector<ll> v(n+1); //1~nまでの頂点
  vector<ll> ans(n); //1~n-1まで使う
  for(ll i=1;i<=n;++i){
    vector<ll> dist(n+1,INF);
    queue<ll> q;
    auto push = [&]( ll v, ll d ){
      if( dist[v] != INF ) return;
      dist.at(v) = d;
      q.push(v);
    };
    push(i,0);
    while( !q.empty() ){
      ll v = q.front();q.pop();
      ll d = dist.at(v);
      if( v-1 >= 1 ) push(v-1,d+1);
      if( v+1 <= n ) push(v+1,d+1);
      if( v == x ) push(y,d+1);
      if( v == y ) push(x,d+1);
    }
    for(ll i=1;i<=n;i++){
      ans[dist[i]]++;
    }
  } 
  for(ll i=1;i<n;++i){
    cout << ceil((double)ans[i]/2.0) << endl;
  }
    
  
  return 0;
}

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

typedef long long ll; 

int main()
{ 
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<a+b+c+ max({a,b,c})*(pow(2,k)-1)<<endl;
    
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>

using namespace std;
using LLI = long long int;

//vector<int>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//vector<int>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//vector<int>dir_x2 = { 0,0,1,-1 };
//vector<int>dir_y2 = { 1,-1,0,0 };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x,LLI y) {
//	return x / gcd(x,y) * y;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

int main(void) {
	int N, M,a;
	cin >> N >> M;
	vector<int>vec;
	vector<int>vec2;
	for (int i = 0; i < M;i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < M - 1;i++) {
		vec2.push_back(vec[i + 1] - vec[i]);
	}
	sort(vec2.rbegin(),vec2.rend());
	LLI ans = vec[M - 1] - vec[0];
	for (int i = 0; i < min(N - 1, M - 1);i++) {
		ans -= vec2[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	int m;
	int z=0;
	double n;
	scanf("%d %d",&a,&b);
	n=double(a+b)/2;
	m=(int)n;
	if((n-m)<0.5)
   		z=m;
	else
   		z=m+1;
	printf("%d",z);
	return 0;
} 

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

ll N, C, W[105], V[105];
ll dp[105][100005];

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

	cin >> N >> C;
	for (ll i = 0; i < N; i++) {
		cin >> W[i] >> V[i];
	}

	for (ll i = 0; i < 105; i++) {
		for (ll j = 0; j < 100005; j++) {
			dp[i][j] = 1e15;
		}
	}
	dp[0][V[0]] = W[0];
	dp[0][0] = 0;

	for (ll i = 1; i < N; i++) {
		for (ll j = 0; j <= 100000; j++) {
			dp[i][j] = dp[i-1][j];
			if (j - V[i] >= 0 && dp[i-1][j-V[i]] != -1) {
				dp[i][j] = min(dp[i][j], dp[i-1][j-V[i]]+W[i]);
			}
		}
	}

	ll ans = 0;
	for (ll i = 0; i <= 100000; i++) {
		if (dp[N-1][i] != -1 && dp[N-1][i] <= C) {
			ans = i;
		}
	}

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

Measured memory_bytes: 82304
function main(input) {
  const N = parseInt(input.split('\n')[0], 10);
  const p = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));

  //最初から昇順の場合にYES表示

  

  var possible=0;

  for(var i=0; i<N-1; i++){
    for(var j=i+1; j<N; j++){
      var tempArr = p.slice();
      tempArr[i]=p[j];
      tempArr[j]=p[i];
      //console.log(tempArr);

      //昇順か判定する変数
      var judge=0;

      for(var k=0; k<N-1; k++){
        if(tempArr[k]<tempArr[k+1]){
          judge++
        }
      }
      //console.log(judge);
      
      //昇順だった時の操作
      if(judge==N-1){
        //console.log("昇順です");
        possible++
      }
    }
  }

  if(possible>0){
    console.log("YES");
  }else{
    var a=0;
  var def=0;
  for(var i=0; i<N-1; i++){
    if(p[i]<p[i+1]){
      def++
    }
  }
  if(def==N-1){
    //console.log("昇順です");
    a++
  }
  if(a>0){
    console.log("YES");
  }else{
    console.log("NO");
  }
    
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    vector<int> bkt(N+1, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        bkt[A[i]]++;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        bkt[B[i]]++;
    }
    
    for (int i = 1; i <= N; i++) {
        if (bkt[i] > N) {
            cout << "No\n";
            return 0;
        }
    }
    vector<int> ami(N+1, 1e9), ama(N+1, -1), bmi(N+1, 1e9), bma(N+1, -1);
    for (int i = 0; i < N; i++) {
        ami[A[i]] = min(ami[A[i]], i);
        ama[A[i]] = max(ama[A[i]], i);
        bmi[B[i]] = min(bmi[B[i]], i);
        bma[B[i]] = max(bma[B[i]], i);
    }
    vector<int> imos(N, 0);
    for (int i = 0; i <= N; i++) {
        if (ama[i] >= 0 && bma[i] >= 0) {
            int st = (ami[i]-bma[i]+N)%N;
            int en = (ama[i]-bmi[i]+N+1)%N;
            imos[st]++;
            imos[en]--;
            if (en < st) imos[0]++;
        }
    }
    for (int i = 1; i < N; i++) {
        imos[i] += imos[i-1];
    }
    cout << "Yes\n";
    for (int i = 0; i < N; i++) {
        if (imos[i] == 0) {
            for (int j = 0; j < N; j++) {
                cout << B[(j-i+N)%N];
                if (j < N-1) cout << " ";
                else cout << "\n";
            }
            return 0;
        }
    }
}


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

using namespace std;

using Int  = int_fast64_t;
using UInt = uint_fast64_t;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

void sub()
{
    const auto C(cin2var<char>());
    cout << static_cast<char>(C + 1) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

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

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

    ll balance=100;
    ll x;
    cin>>x;
    ll count=0;
    while(balance<x)
    {
        balance=balance + (ll)(balance*0.01);
        ++count;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3652
import itertools

n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
d = []
for i in range(5):
    d.append(i)
p_list = list(itertools.combinations(d, 3))

for i in range(n):
    name = input()
    if name[0] == 'M':
        m +=1
    elif name[0] == 'A':
        a +=1
    elif name[0] == 'R':
        r +=1
    elif name[0] == 'C':
        c +=1
    elif name[0] == 'H':
        h +=1
con = [m,a,r,c,h]
ans = 0
for i in range(len(p_list)):
    ans += con[p_list[i][0]] * con[p_list[i][1]] * con[p_list[i][2]]
    
print(ans)

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

int K;

void solve()
{
	if(K%2 == 0 || K%10 == 5) cout << -1 << '\n';
	else{
		int cur = 1, x = 7;
		while(true){
			if(x % K == 0){
				cout << cur << '\n';
				return;
			}
			(x = 10*x+7)%=K;
			cur++;
		}
	}
}


int main()
{
	cin >> K;
	solve();
	return 0;
}

Measured memory_bytes: 3644
#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<iostream>
using namespace std;
int main(){
    int H, W, i, j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if((i+j)%2==0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << n / 2 << endl;
  else
    cout << n / 2 + 1 << endl;
}


Measured memory_bytes: 3624
# ALDS1_3_B.
# ラウンドロビンスケジューリング。

def main():
    data = input().split()
    n = int(data[0]); q = int(data[1])
    list = [] # ここに順に格納していく感じ。
    for i in range(n):
        list.append(input().split())
        list[i][1] = int(list[i][1])
    t = 0
    while len(list) > 0:
        if list[0][1] > q:
            name = list[0][0]; time = list[0][1]
            del list[0]
            list.append([name, time - q])
            t += q
        else:
            t += list[0][1]
            print(list[0][0] + " " + str(t))
            del list[0]

if __name__ == "__main__":
    main()



Measured memory_bytes: 16848
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll A[1010][1010];
    queue<P> q;
    rep(i, H+2) {
        rep(j, W+2) {
            if (i == 0 || j == 0 || i == H+1 || j == W+1) {
                A[i][j] = 1;
                continue;
            }
            char c;
            cin >> c;
            if (c == '.') A[i][j] = 0;
            else {
                A[i][j] = 1;
                q.push(make_pair(i,j));
            }
        }
    }
    ll ans = 0;
    while(q.size() > 0) {
        ll sze = q.size();
        rep(i, sze) {
            P p = q.front();
            q.pop();
            if (A[p.first+1][p.second] == 0) {
                A[p.first+1][p.second] = 1;
                q.push(make_pair(p.first+1, p.second));
            }
            if (A[p.first-1][p.second] == 0) {
                A[p.first-1][p.second] = 1;
                q.push(make_pair(p.first-1, p.second));
            }
            if (A[p.first][p.second+1] == 0) {
                A[p.first][p.second+1] = 1;
                q.push(make_pair(p.first, p.second+1));
            }
            if (A[p.first][p.second-1] == 0) {
                A[p.first][p.second-1] = 1;
                q.push(make_pair(p.first, p.second-1));
            }
        }
        ans++;
    }
    print(ans-1);
    return 0;
}

Measured memory_bytes: 24500