akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>

using namespace std;

queue <int> D;
int N, K;
long long int can[100000];
int canm[100000];
int first;
long long int ans = 1000000000;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> can[i];
		if (i == 0) continue;
		if (can[i] >= 0 && can[i - 1] < 0)first = i;
		canm[i] = can[i] - can[i - 1] + canm[i - 1];
	}
	if (can[N - 1] < 0) first = N;
	if (K != 1) {
		for (int i = 0; i < N - K + 1; i++) {
			if (i < first && i + K - 1 >= first) {
				ans = min(ans, -can[i] + can[i + K - 1] + min(-can[i], can[i + K - 1]));
			}
			if (i == first) {
				ans = min(ans, can[i + K - 1]);
			}
			if (i + K - 1 == first - 1) {
				ans = min(ans, -can[i]);
			}
		}
	}
	if (K == 1) {
		if (first == 0) {
			ans = can[first];
		}
		else if (first == N) {
			ans = -can[N - 1];
		}
		else {
			ans = min(can[first], -can[first - 1]);
		}
	}
	else if (K == N) {
		if (first == 0) {
			ans = can[N - 1];
		}
		else if (first == N) {
			ans = -can[0];
		}
		else {
			ans = -can[0] + can[N - 1] + min(-can[0], can[N - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

const int maxn = 1005;

char c3[10][10]={
	{'a','a','.'},
	{'.','.','a'},
	{'.','.','a'} 
};
char c4[10][10]={
    {'a','a','b','c'},
    {'d','d','b','c'},
    {'b','c','a','a'},
    {'b','c','d','d'}
};
char c5[10][10]={
    {'a','a','b','b','a'},
    {'b','c','c','.','a'},
    {'b','.','.','c','b'},
    {'a','.','.','c','b'},
    {'a','b','b','a','a'}
};
char c6[10][10] = {
	"aabc..",
	"ddbc..",
	"..aabc",
	"..ddbc",
	"bc..aa",
	"bc..dd"
};
char c7[10][10]={
    {'a','a','b','b','c','c','.'},
    {'d','d','.','d','d','.','a'},
    {'.','.','d','.','.','d','a'},
	{'.','.','d','.','.','d','b'},
	{'d','d','.','d','d','.','b'},
	{'.','.','d','.','.','d','c'},
	{'.','.','d','.','.','d','c'} 
};

char ans[maxn][maxn];

void print3(int x, int n)
{
	if (!n) return ;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			ans[x + i][x + j] = c3[i][j];
	return print3(x + 3, n - 3);
}

void print(int x, int n)
{
	if (!n) return ;
	if (n >= 8 || n == 4) {
		for (int i = 0; i < 4; ++i)
			for (int j = 0; j < 4; ++j)
				ans[x + i][x + j] = c4[i][j];
		return print(x + 4, n - 4);
	}
	if (n == 5) {
		for (int i = 0; i < 5; ++i)
			for (int j = 0; j < 5; ++j)
				ans[x + i][x + j] = c5[i][j];
		return print(x + 5, n - 5);
	}
	if (n == 6) {
		for (int i = 0; i < 6; ++i)
			for (int j = 0; j < 6; ++j)
				ans[x + i][x + j] = c6[i][j];
		return print(x + 6, n - 6);

	}
	if (n == 7) {
		for (int i = 0; i < 7; ++i)
			for (int j = 0; j < 7; ++j)
				ans[x + i][x + j] = c7[i][j];
		return print(x + 7, n - 7);
	}

}

int main()
{
	int n;
	scanf("%d", &n);
	if (n <= 2) return puts("-1"), 0;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) ans[i][j] = '.';
	if (n % 3 == 0) print3(1, n);
	else print(1, n);
	for (int i = 1; i <= n; ++i) printf("%s\n", ans[i] + 1);
	return 0;
}


Measured memory_bytes: 2176
#include <cstdio>

int n, r;
int card[55], tmp[55];

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

Measured memory_bytes: 1032
from collections import Counter
def resolve():
    n=int(input())
    l=[input() for i in range(n)]
    c=Counter(l)
    maxl=[]
    cntmax=max(c.values())
    for name,kazu in c.items():
        if kazu==cntmax:
            maxl.append(name)
    maxl.sort()
    for i in maxl:
        print(i)
resolve()

Measured memory_bytes: 35700
# include <bits/stdc++.h>
using namespace std;
# define ll long long
const int N = 2e5 + 10, mod = 1e9 + 7, INF = 1e9 + 100;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    ll n, k, ans = 0;
    cin >> n >> k;
    vector < ll > a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end());
    n -= k;
    for(int i = 0; i < n; i++)ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b ) {
	if(a>b)
		return a;
	else return b;
}
//vector<pair<int,int>> v(ma.begin(),ma.end());

ll mod = 1e9 + 7;
int main() {
	int a,b;
	cin>>a>>b;
	cout<<a*b;
	
return 0;
}/*
8 -2 5 2 5 3 -30 6 9
0 -2 5 2 5 3 

a - b>0 and other max(nos)>a
*/

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 105;

signed main(){
    int n;
    cin >> n;
    int A[n_max][n_max];
    FOR(i,1,n+1) FOR(j,1,n+1) A[i][j] = 1;

    int sta = n;
    while(sta > 0){
        if(n % 2== 1) A[sta][n - sta] = 0;
        else A[sta][n-sta + 1] = 0;
        sta --;
    }
    int cnt = 0;
    FOR(i,1,n+1){
        FOR(j,i+1,n+1) if(A[i][j]) cnt ++;
    }

    cout << cnt  << endl;
    FOR(i,1,n+1){
        FOR(j,i+1,n+1){
            if(A[i][j]){
                cout << i << " " << j << endl;
            }
        }
    }


    
}

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

#define rep(a,b) for(int ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define arrayInput for(int ii = 0; ii<n; ii++) cin >> arr[ii];
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define lg 1000000000

int main()
{
  string s;
  cin >> s;
  if(s[s.length()-1] != 's') 
     cout << s + 's';
  else cout << s + "es"; 
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define p(a) printf("%lld\n",a);
ll n;
const ll mod=1e9+7;
vector<ll> g[200005];
bool used[200005]={0};
ll size[200005]={0};
ll njie[200005]={0};
ll nfan[200005]={0};
ll sum[200005]={0};
ll a[200005]={0};
ll qpow(ll a,ll b)
{
	if(b==0) return 1;
	else if(b==1) return a;
	ll c=qpow(a,b/2);
	if(b%2==0) return c*c%mod;
	else return c*c%mod*a%mod;
}
void dfs1(ll u)
{	//printf("%lld ",u);
	used[u]=true;
	for(ll i=0;i<g[u].size();i++)
	{
		ll v=g[u][i];
		if(used[v]) continue;
		dfs1(v);
		size[u]+=size[v];
		a[u]=a[u]*a[v]%mod*nfan[size[v]]%mod;
	}
	a[u]=a[u]*njie[size[u]-1]%mod;
}
void change(ll u,ll v)
{
	a[u]=a[u]*nfan[size[u]-1]%mod;
	a[u]=a[u]*njie[size[u]-size[v]-1]%mod;
	a[u]=a[u]*njie[size[v]]%mod;
	a[u]=a[u]*qpow(a[v],mod-2)%mod;
	size[u]=size[u]-size[v];
	a[v]=a[v]*nfan[size[v]-1]%mod;
	size[v]=size[v]+size[u];
	a[v]=a[v]*njie[size[v]-1]%mod;
	a[v]=a[v]*a[u]%mod;
	a[v]=a[v]*nfan[size[u]]%mod;
}
void dfs2(ll u)
{
	sum[u]=a[u];
	used[u]=true;
	for(ll i=0;i<g[u].size();i++)
	{
		ll v=g[u][i];
		if(!used[v])
		{
			change(u,v);
			dfs2(v);
			change(v,u);
		}
	}
}
int main()
{
	scanf("%lld",&n);
	njie[0]=1;
	for(ll i=1;i<=n;i++) njie[i]=njie[i-1]*i%mod,a[i]=1,size[i]=1;
	nfan[n]=qpow(njie[n],mod-2);
	for(ll i=n-1;i>0;i--) nfan[i]=nfan[i+1]*(i+1)%mod;
	nfan[0]=nfan[1];
	for(ll i=0;i<n-1;i++)
	{
		ll u,v;
		scanf("%lld%lld",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1);
	memset(used,0,sizeof(used));
	dfs2(1);
	for(ll i=1;i<=n;i++)
	{
		printf("%lld ",sum[i]);
	}
}

Measured memory_bytes: 22640
#import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]

lst = sorted(AB, key=lambda x: x[1], reverse=True)
deadline = lst[0][1]

for i in range(N):
  if lst[i][1] < deadline:
    deadline = lst[i][1] - lst[i][0]
  else:
    deadline = deadline - lst[i][0]
  if deadline < 0:
    print('No')
    exit()
else:
    print('Yes')



Measured memory_bytes: 57408
#include<bits/stdc++.h>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <queue>
#include <unordered_map>
#define ll long long
#define pii pair <int, int>
#define pll pair <long long, long long>
#define plxy pair <long long, pll>
#define INT_MAX 1e18
#define Keep_calm_You_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace std;
const int mod=1e9+7;
const int N=3e3+5;
string s,t;
ll dp[N][N],ans;
ll solve(ll i,ll j)
{
    if(i==s.size() || j==t.size())
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    dp[i][j]=max(solve(i+1,j),solve(i,j+1));
    if(s[i]==t[j])
    {
        dp[i][j]=max(dp[i][j],1+solve(i+1,j+1));
    }
    return dp[i][j];
}

int main()
{
    string s2="";
    ll x;
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    ans=solve(0,0);
    ll i=0,j=0;
    while(i<s.size() && j<t.size())
    {
        if(s[i]==t[j])
        {
            s2+=s[i];
            i++;
            j++;
        }
        else if(dp[i+1][j]>dp[i][j+1])
        {
            i++;
        }
        else
        {
            j++;
        }
    }
    cout<<s2;
    return 0;
}


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

int main(){
  int num[2222];
  for(int i=0;i<2010;i++){
    num[i] = 0;
  }
  //cout << num[1876] << endl;
  for(int i=0;i<=1000;i++){
    for(int j=0;j<=1000;j++){
      num[i+j]++;
    }
  }
  int n;
  while(cin >> n){
    int ans = 0;
    for(int i=0;i<=n;i++){
      if(n-i <= 2000 && i <= 2000){
	ans += num[i]*num[n-i];
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(int i=1;i<=n;++i)
typedef long long ll;
struct Mnt{
	ll t,a;
	bool det;
};

int main(void){
	int N;
	ll res=1;
	cin>>N;
	vector<Mnt> m(N+2);
	m[0].t=m[N+1].t=0;
	rep1(i,N){
		cin>>m[i].t;
		m[i].det=(m[i-1].t!=m[i].t);
	}
	rep1(i,N)cin>>m[i].a;
	bool NG=false;
	for(int i=N;i>0;i--){
		bool det=(m[i].a!=m[i+1].a);
		if(m[i].det){
			if(m[i].t>m[i].a)NG=true;
			if(det && m[i].t!=m[i].a)NG=true;
			//else-> *1
		}
		if(det && m[i].t<m[i].a)NG=true;
		if(NG){
			res=0;
			break;
		}
		if(!det && !m[i].det){
			res*=min(m[i].t,m[i].a);
			res%=1000000007;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000001
using ll=long long;

int main(){
    ll n,a,b,c,d,e;cin>>n>>a>>b>>c>>d>>e;
    ll m=min({a,b,c,d,e});
    ll ans=(n+m-1)/m+4;
    cout<<ans<<endl;
}

Measured memory_bytes: 888
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a = [INT() for _ in range(M)]
ng = [0]*(N+1)
for i in a:
	ng[i] = 1

dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(2, N+1):
	for j in range(1, 3):
		if not ng[i-j]:
			dp[i] = (dp[i]+dp[i-j])%mod
print(dp[N])


Measured memory_bytes: 11552
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
let sp = input.split("\n");
for( let i = 0; sp[i] !== "0 0"; i++ ) {
  let hw = sp[i].split(" ").map(Number);
  let h = hw[0]; w = hw[1];
  for( let hh = 0; hh < h; hh++ ) {
    let row = "";
    let plus = hh % 2 === 0 ? 0 : 1;
    for( let ww = 0 + plus; ww < w + plus; ww++ ) {
      row += ww % 2 === 0 ? "#" : ".";
    }
    console.log(row);
  }
  console.log();
}

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

int main() {
	ll n,m,d;
	cin>>n>>m>>d;
	ll mi=d+1,ma=n-d;
	ll sum=0;
	if(ma>=mi&&d!=0){
		sum+=(ma-mi+1)*2;
		sum+=n-(ma-mi+1);
	}
	else{
		sum+=n;
	}
	double ans=double(sum)*(m-1)/(n*n);
	printf("%.10f",ans);
	// your code goes here
	return 0;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int S, W;
	cin >> S >> W;
	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
	return 0;
}



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

typedef long long ll;
typedef pair<int, int> ii; 

const int mod = 1e9 + 7; 
const int maxn = 2e5 + 10;
ll inv[maxn], fact[maxn]; 

ll C(int n, int r) {
	return fact[n] * (inv[r] * inv[n - r] % mod) % mod;
}
ll way(int x1, int y1, int x2, int y2) {
	int dx = x2 - x1, dy = y2 - y1;
	return C(dx + dy, dx);
}

void pre() {
	fact[0] = fact[1] = inv[0] = inv[1]= 1;
	for(int i = 2; i < maxn; ++i) {
		inv[i] = -(mod / i) * inv[mod % i] % mod;
		inv[i] += mod;
	} 
	for(int i = 2; i < maxn; ++i) {
		fact[i] = fact[i - 1] * i % mod;
		inv[i] = inv[i] * inv[i - 1] % mod;
	}
}
int main(int argc, char const *argv[]) { pre();
	int h, w, a, b; 
	scanf("%d %d %d %d", &h, &w, &a, &b);
	ll ans = 0; 
	for(int i = 0; i <= h - a; i++) {
		ans += (way(1, 1, i, b) * way(i, b + 1, h, w)) % mod;
		if(ans >= mod) ans -= mod;
	}
	printf("%lld\n", ans);
}

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

signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll h,w,k;
    cin>>h>>w>>k;
    ll mod=1e9+7;
    ll dp[h+1][w+1]={};
    dp[0][1]=1;
    ll fib[10]={1,2,3,5,8,13,21,34,55,89};
    for(ll i=0;i<h;i++){
        for(ll j=1;j<=w;j++){
            dp[i+1][j] += (dp[i][j] * fib[max(0LL,j-2)] * fib[max(0LL,w-j-1)] )% mod;
            dp[i+1][j] %= mod;
            dp[i+1][j] += (dp[i][j-1] * fib[max(0LL,j-3)] * fib[max(0LL,w-j-1)]) % mod;
            dp[i+1][j] %= mod;
            if(j+1<=w) dp[i+1][j] += (dp[i][j+1] * fib[max(0LL,j-2)] * fib[max(0LL,w-j-2)]) % mod;
            dp[i+1][j] %= mod;
            //cerr<<i<<" "<<j<<" "<<dp[i+1][j]<<endl;
        }
    }
    cout<<dp[h][k]<<endl;
    
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int p[n];
  rep(i, n) { cin >> p[i]; }

  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    int mx = max(p[i - 1], max(p[i], p[i + 1]));
    int mn = min(p[i - 1], min(p[i], p[i + 1]));
    if (p[i] != mx && p[i] != mn) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<int> ans(n);
    
    int cnteven = 0;
    int cntodd = 0;
    int posR, posL;
    rep(i, n) {

        if(i%2 == 0) {
            cnteven++;
        }
        else {
            cntodd++;
        }

        if(i < n-1 && s[i] == 'R' && s[i+1] == 'L') {
            posR = i;
            posL = i+1;
        }

        if( (i == n-1) ||  (i < n-1 && s[i] == 'L' && s[i+1] == 'R') ) {
            if(posR%2 == 0) {
                ans[posR] = cnteven;
                ans[posL] = cntodd;
            }
            else {
                ans[posR] = cntodd;
                ans[posL] = cnteven;
            }
            cntodd = 0;
            cnteven = 0;
        }

    }

    rep(i, n) {
        cout << ans[i] << " ";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e2+5;
int n, m, f[N][N][N], ans; char s[N];
int main()
{
    scanf("%s", s+1), n = strlen(s+1), m = read();
    for(int i = 1; i <= n; ++i) f[0][i][i] = 1;
    for(int k = 0; k <= m; ++k)
        for(int l = 2; l <= n; ++l)
            for(int i = 1, j = l; j <= n; ++i, ++j)
            {
                f[k][i][j] = max(f[k][i+1][j], f[k][i][j-1]);
                if(s[i] == s[j]) f[k][i][j] = max(f[k][i][j], f[k][i+1][j-1]+2);
                if(k) f[k][i][j] = max(f[k][i][j], f[k-1][i+1][j-1]+2);
            }
    for(int i = 0; i <= m; ++i) ans = max(ans, f[i][1][n]);
    printf("%d\n", ans);
    return 0;
}

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

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

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

struct Union{
private:
	vector< int >par;
	vector< int >Rank;
    vector< ll >sz;
	int N;
public:
	void init(int n) {
		N = n;
		par.resize(N + 1);
		Rank.resize(N + 1);
        sz.resize( N + 1 );
		for (int i = 0;i <= N;i++)par[i] = i, Rank[i] = 0,sz[i]=1;
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
    ll siz(int x){
        if(par[x]==x)return sz[x];
         else return sz[x]=siz(par[x]);
    }
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (Rank[x] < Rank[y])par[x] = y;
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;
		}
        sz[x]+=sz[y];
        sz[y]=sz[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

ll n,m,a[100010],b[100010];
ll diff[100010];

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

void solve(){
    Union uf;
    uf.init(n);
    for(int i=m-1;i>=0;i--){
        if(uf.same(a[i],b[i])){
            if(i)diff[i-1]+=diff[i];
            continue;
        }
        diff[i]+=uf.siz(a[i])*uf.siz(b[i]);
        if(i)diff[i-1]+=diff[i];
        uf.unite(a[i],b[i]);
    }
    for(int i=0;i<m;i++){
        cout<<n*(n-1)/2LL-diff[i+1]<<endl;
    }
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>

int main()
{
    int x,a,b,c,z;
    scanf("%d",&x);
    a=x%10;
    x=x/10;
    b=x%10;
    x=x/10;
    c=x%10;
    x=x/10;
    z=x%10;
    x=x/10;
    if(a == b && a==c){
        printf("Yes");
    }
    else if(z == c && z == b){
        printf("Yes");
    }
    else
        printf("No");


}


Measured memory_bytes: 128
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　int[] a = new int[4];
           for(int i =0 ; i< 4; i++){
              a[i] = int.Parse(Console.ReadLine()); 
           }

            Console.WriteLine("{0}", (a[0]< a[1] ? a[0] : a[1]) + (a[2]< a[3] ? a[2] : a[3]));
        }
 }

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

int main(){
  int64_t N,x;
  cin>>N>>x;
  vector<int64_t> a(N);
  for(int i=0;i<N;++i) cin>>a.at(i);

  int64_t ans=0;
  for(int i=0;i<N-1;++i){
    if(a.at(i)+a.at(i+1)>x){
      ans += (a.at(i)+a.at(i+1))-x;
      a.at(i+1)=max(x-a.at(i),int64_t(0));
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FasterIO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    ordered_set st;

    long long n, rs=0;

    cin>>n;

    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        int lo=st.order_of_key(x);
        st.insert(x);
        if(lo==0) rs++;
    }
    cout<<rs<<endl;
    return 0;
}


Measured memory_bytes: 9600
// #pragma GCC optimize(3)
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100010
#define inf 0x3f3f3f3f3f3f3f3f
#define int long long
using namespace std;
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9) write(x/10);putchar(x%10+'0');}
int read(){int d=0,w=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')
w=-1;for(;c>='0'&&c<='9';c=getchar())d=(d<<1)+(d<<3)+c-48;return d*w;}
void wln(int x){write(x);putchar('\n');}
void wrs(int x){write(x);putchar(' ');}
int reac()
{
	char c=getchar();
	for(;c!='-'&&c!='+';c=getchar());
	return c=='+'?1:-1;
}
int n,a[maxn],c[maxn],f[maxn][3];
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	n=read();
	c[1]=1;
	a[1]=read();
	for(int i=2;i<=n;a[i++]=read())
		c[i]=reac();
	f[1][0]=a[1];
	f[1][1]=f[1][2]=-inf;
	for(int i=2;i<=n;i++)
	{
		f[i][0]=max(f[i-1][0],f[i-1][1])+a[i]*c[i];
		f[i][1]=max(max((c[i]==-1?f[i-1][0]:-inf)+a[i]*c[i],f[i-1][1]+(c[i]==-1?abs(a[i]*c[i]):a[i]*c[i]*-1)),f[i-1][2]+a[i]*c[i]*-1);
		f[i][2]=max((c[i]==-1?f[i-1][1]:-inf)+a[i]*c[i]*-1,f[i-1][2]+(c[i]==-1?abs(a[i]*c[i]):a[i]*c[i]));
		// wrs(f[i][0]);
		// wrs(f[i][1]);
		// wln(f[i][2]);
	}
	write(max(f[n][0],f[n][1]));
	return 0;
}


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


    int main()
    {


         ios_base::sync_with_stdio(false);
         cin.tie(NULL);
      /*  #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif*/
    int a,b;
    cin>>a>>b;
    for(int i=b-a+1;i<b+a;i++)
    {

      cout<<i<<" "; 
    }
    cout<<endl;
    return 0;


    }

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
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; }

const ll INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;

int N;
ll W, weight[MAX_N], value[MAX_N];
ll dp[MAX_N][MAX_V];
 
int main() {
    cin >> N >> W;
    rep(i, N) {
        cin >> weight[i] >> value[i];
    }

    rep(i, MAX_N) {
        rep(j, MAX_V) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    rep(i, N) {
        for(int sum_v = 0; sum_v < MAX_V; sum_v++) {
            if(sum_v - value[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
            }

            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    ll ans = 0;
    for(int sum_v = 0; sum_v < MAX_V; sum_v++) {
        if(dp[N][sum_v] <= W) {
            ans = sum_v;
        }
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 86272
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>
using namespace std;

int main(){
    int N;
    cin>>N;
    multiset<int> S;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        auto ite = S.lower_bound(a);
        if(ite!=S.begin()) S.erase(--ite);
        S.insert(a);
    }
    cout<<S.size()<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize(cont,W,V) cont.resize(W,V);
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;




// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
int main() {
    cout.precision(15);
    cout << fixed;
    ll N,M,K;
    vector<ll> A,B;
    cin>>N>>M>>K;
    Resize(A,N+1,0);
    Resize(B,M+1,0);
    REP(i,N)
        cin>>A[i+1];
    REP(i,M)
        cin>>B[i+1];
    REP(i,N) {
        A[i+1]=A[i+1]+A[i];
    }
    REP(i,M) {
        B[i+1]=B[i+1]+B[i];
    }
    ll ans=0;
    for(int i=0;i<=N;++i) {
        ll sa=0;
        ll re=K;
        re-=A[i];
        sa+=i;
        auto it=upper_bound(ALL(B),re);
        --it;
        sa+=distance(B.begin(),it);
        re-=*it;

        if (re<0)sa=0;
        ans=max(ans,sa);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 6368
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;

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

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

const int N = 2e5 + 10, mod = 1e9 + 7;


int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        long long a, b, c;
        cin >> a >> b >> c;
        if((c - a - b) * (c - a - b) > 4 * a * b && c - a - b > 0) puts("Yes");
        else puts("No");
    }    
    return 0;
}

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

using namespace std;

int main()
{
  int n, tl;
  cin >> n >> tl;
  int ans = -1, now = 10000;
  for (int i = 0; i < n; i++)
  {
    int c, t;
    cin >> c >> t;
    if (t <= tl && c <= now)
    {
      ans = i + 1;
      now = c;
    }
  }
  if (ans != -1)
    cout << now << endl;
  else
    cout << "TLE" << endl;

  return 0;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

temp = [0] * n
for i in range(q):
    temp[a[i]-1] += 1

for i in range(n):
    temp[i] += k-q
    if temp[i]>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 11776
n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
diff_x.sort(reverse=True)
if n >= m:
    print(0)
else:
    print((x[m - 1] - x[0]) - sum(diff_x[0:n - 1]))

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

int main() {
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  sort(vec.begin(), vec.end());
  if (vec.at(2) == vec.at(0) + vec.at(1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

#define int long long

string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";

int make_str (string ts) {
    int st = 1, ans = 0;
    for (int i = ts.size() - 1; i >= 0; --i) {
        ans += (ts[i] - '0') * st;
        st *= 10;
    }
    return ans;
}

void solve() {
    int k;
    cin >> k;
    vector <int> kek;
    int id = 0;
    while (id < s.size()) {
        int id2 = id;
        while (id2 < s.size() && s[id2] >= '0' && s[id2] <= '9') ++id2;
        //cout << id << ' ' << id2 << endl;
        kek.push_back(make_str(s.substr(id, id2 - id)));
        id = id2 + 2;
    }
    cout << kek[k - 1];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int  N,M;
    long long Q, inf = 1e17;
    cin >> N >> M >> Q;
    vector<long long> cost(N,inf),L(N,1),R(N,1),A(M),B(M),C(M);
    for(int i = 0; i < M; ++i){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--,B[i]--;
    }
    cost[0] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            cost[B[j]] = min(cost[B[j]],cost[A[j]] + Q - C[j]);  
        }
    }
    auto tmp = cost;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            tmp[B[j]] = min(tmp[B[j]],tmp[A[j]] + Q - C[j]);  
        }
    }
    L[0] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            L[B[j]] = min(L[A[j]],L[B[j]]);  
        }
    }
    R[N-1] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            R[A[j]] = min(R[A[j]],R[B[j]]);  
        }
    }
    for(int i = 0; i < N; ++i){
        if(tmp[i]<cost[i] && !L[i] && !R[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(0LL,-cost[N-1]) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	bool ok = false;
	rep(i, 8)
	{
		if (s.substr(0, 7 - i) + s.substr(s.size() - i, i) == "keyence")
		{
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

using namespace std;

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

int w,h;
vector<string> board;

bool input(){
	cin>>w>>h;
	if(w==0)return false;
	
	board.clear();
	rep(i,h){
		string s;
		cin>>s;
		board.pb(s);
	}
	return true;
}

int B,W;

int saiki(int y,int x){
	if(y<0 || y>=h || x<0 || x>=w)return 0;
	
	if(board[y][x]=='#')return 0;
	
	if(board[y][x]=='W'){
		W++;
		return 0;
	}
	if(board[y][x]=='B'){
		B++;
		return 0;
	}
	
	int ret = 1;
	int dx[] = {1,0,-1,0};
	int dy[] = {0,1,0,-1};
	
	board[y][x]='#';
	
	rep(i,4){
		ret += saiki(y+dy[i], x+dx[i]);
	}
	
	return ret;
}

void solve(){
	int ansB = 0;
	int ansW = 0;
	rep(i,h){
		rep(j,w){
			B=0;
			W=0;
			
			int cnt = saiki(i,j);
			
			if(W==0 && B!=0)ansB += cnt;
			if(B==0 && W!=0)ansW += cnt;
		}
	}
	
	cout<<ansB<<" "<<ansW<<endl;
}

int main(){
	while(input())solve();
}

Measured memory_bytes: 1416
#include<stdio.h>
int main()
{
    int a[110],n,x,i,j,sum=0,min=1000000,ttl;
    scanf("%d%d\n",&n,&x);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<min)min=a[i];
    }
    for(i=0;i<n;i++)
    {
      sum+=a[i];
    }
    x-=sum;
    ttl=x/min;
    ttl+=n;
    printf("%d",ttl);
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  rep(i, 3){
    if(n[i] == '1')
      cout << '9';
    else
      cout << '1';
  }

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


Measured memory_bytes: 3500
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

h, w = nl()
a = [nl() for _ in range(h)]

ans = []
flg = False# 奇数を見つけているかどうか
for y in range(h):
    for x in range(w):
        if flg:
            ans.append([y + 1, x - 1 + 1, y + 1, x + 1])
            if a[y][x] % 2 == 1:
                flg = False
        else:
            if a[y][x] % 2 == 1:
                flg = True
    if flg:
        if y + 1 < h:
            ans.append([y + 1, w - 1 + 1, y + 1 + 1, w - 1 + 1])
            a[y + 1][w - 1] += 1
        flg = False
    
print(len(ans))
for x in ans:
    print(*x)

Measured memory_bytes: 30260
if __name__ == '__main__':
  
  a, b, c, d = map(int, input().split())

  if a <= c and b >= d:
    print(d-c)
  elif c <= a and d >= b:
    print(b-a)
  elif a < c and d > b and c < b:
      print(b-c)
  elif c < a and b > d and a < d:
      print(d-a)
  else:
      print(0)
     

Measured memory_bytes: 3060
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [readline().strip() for _ in range(N)]
    
    c = Counter(S)
    
    print(f'AC x ' + str(c['AC']))
    print(f'WA x ' + str(c['WA']))
    print(f'TLE x ' + str(c['TLE']))
    print(f'RE x ' + str(c['RE']))
    
    return


if __name__ == '__main__':
    main()


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

int main(){
    int M,H;
    int x,y,r;
    cin>>M>>H>>x>>y>>r;
    if(x+r>M||x-r<0||y+r>H||y-r<0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
int main(){
  cin >> N;
  vector<int> p(N);
  for(int i = 1;i <= N;i++){
    cin >> p[i - 1];
  }
  int ans = 0;
  for(int i = 1;i <= N;i++){
    int cnt = 0;
    for(int j = 0;j < N;j++){
      cnt += (p[j] >= i);
    }
    if(cnt >= i){
      ans = i;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3088
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = il()

    for k in range(K, N):
        if A[k - K] < A[k]:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 30000
num=int(input())
n1=num//100
n2=num%100
if 1<=n1 and n1<=12 and 1<=n2 and n2<=12:
    ans='AMBIGUOUS'
elif 1<=n1 and n1<=12:
    ans='MMYY'
elif 1<=n2 and n2<=12:
    ans='YYMM'
else:
    ans='NA'
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strcmp()

#define N_LIST 2002000

typedef struct list_tbl
{
	int key;
	int prev;
	int next;
} list_t;

int lineno;
list_t list[N_LIST];
int ix;
int head;
int tail;
int room;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
insert(int key)
{
	list[ix].key = key;
	list[ix].next = head;
	int next = head;
	head = ix;

	if (next == -1)
	{
		list[ix].prev = tail;
		tail = ix;
	}
	else
	{
		list[ix].prev = list[next].prev;
		list[next].prev = ix;
	}

	ix++;
}

void
delete(int key)
{
	int next;
	int* pnext;
	int l;

	pnext = &head;
	for (l = head; l != -1 && list[l].key != key; l = list[l].next)
		pnext = &list[l].next;

	if (l == -1)
		return;

	next = list[l].next;
	*pnext = next;

	if (next == -1)
		tail = list[l].prev;
	else
		list[next].prev = list[l].prev;
}

void
delete_first()
{
	head = list[head].next;
	if (head == -1)
		tail = -1;
	else
		list[head].prev = -1;
}

void
delete_last()
{
	tail = list[tail].prev;
	if (tail == -1)
		head = -1;
	else
		list[tail].next = -1;
}

int
main(int argc, char** argv)
{
	char command[15];
	int x = 0;
	int n = 0;
	int l;
	int i;

	head = -1;
	tail = -1;
	room = 0;
	ix = 0;

	scanf("%d", &n);
	lineno = 0;
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s", command);
		if (strcmp(command, "insert") == 0)
		{
			scanf("%d", &x);
			insert(x);
		}
		else if (strcmp(command, "delete") == 0)
		{
			scanf("%d", &x);
			delete(x);
		}
		else if (strcmp(command, "deleteFirst") == 0)
			delete_first();

		else if (strcmp(command, "deleteLast") == 0)
			delete_last();
	}

	const char* sep = "";
	for (l = head; l != -1; l = list[l].next)
	{
		printf("%s%d", sep, list[l].key);
		sep = " ";
	}

	printf("\n");
	return 0;
}

Measured memory_bytes: 14936
#include <stdio.h>
#include <stdlib.h>

/*qsortの使い方*/
int cmp_int(const void* v1, const void* v2)
{
  const int _v1 = *((const int*)v1);
  const int _v2 = *((const int*)v2);

  if ( _v1 > _v2 ) {
    return 1;
  } else if ( _v1 < _v2 ) {
    return -1;
  } else {
    return 0;
  }
}
/*qsortの使い方*/

int main(void)
{
  int A[10];
  int ans;
  int num1, num2;
  
  scanf("%d %d %d", &A[0], &A[1], &A[2]);
  
  qsort(A, 3, sizeof(int), cmp_int);
  
  num1 = A[2] - A[1];
  num2 = A[1] - A[0];
  ans = num1 + num2;

  printf("%d", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

class Data{
public:
  int s,e,sum;
  bool f;
  Data();
};
Data::Data(){
  sum = 0;
};

int main(){

  int n;
  while(1){
    cin >> n;
    if(n == 0)break;
    map<string,Data > md;
    
    //  cout << " n = " << n << endl;//

    for(int i = 0 ; i < n ; i++){
      string date,id;
      int h,m;
      char c;

      cin >> date;
      //cout << "date = " << date << endl;//
      scanf("%0d:%0d",&h,&m);
      //cout << "h = " << h << " m = " <<m << endl; //
      cin >> c >> id;
      // cout << "c = " << c << " id = " << id << endl; 

      // cout << "i = " << i << endl;
      // cout << "id = " << 002 << " sum = " << md["002"].sum << endl;
      
      


      if(c == 'I'){
	md[id].s = h * 60 + m;
	md[id].f = true;
	md[id].e = INF;


	/*
	if(id == "002"){////
	  
	  cout << "002 : sum = "<<  md[id].sum  << " f = " << md[id].f << endl;
	  cout << " c = " << c << " 000 : f = " << md["000"].f << endl;
	}
	*/


      }
      else { // c == O
	md[id].e =  h * 60 + m;


	if(id == "000"){
	  //  cout << "!" << endl;//

	  map<string,Data>::iterator it;
	  for(it = md.begin() ; it != md.end(); it++){
	    if(it->first == "000")continue;
	    
	    Data & V = it->second;
	    Data & G = md["000"];

	    if(!V.f)continue;
	    
	    
	    
	    if(V.s <= G.s && G.e <= V.e)V.sum += G.e - G.s;
	    else if(V.s <= G.s && V.e <= G.e)V.sum += V.e - G.s;
	    else if(G.s <= V.s && V.e <= G.e)V.sum += V.e - V.s;
	    else if(G.s <= V.s && G.e <= V.e)V.sum += G.e - V.s;
	  }
	}
	else{
	  Data & V = md[id];
	  Data & G = md["000"];
	  if(!G.f){
	    md[id].s = 0;
	    md[id].e = 0;
	    md[id].f = false;
	    continue;
	  }

	  if(V.s <= G.s && G.e <= V.e)V.sum += G.e - G.s;
	  else if(V.s <= G.s && V.e <= G.e)V.sum += V.e - G.s;
	  else if(G.s <= V.s && V.e <= G.e)V.sum += V.e - V.s;
	  else if(G.s <= V.s && G.e <= V.e)V.sum += G.e - V.s;
	}
	md[id].s = 0;
	md[id].e = 0;
	md[id].f = false;
      }
    }
     int maxi = 0;
     map<string,Data>::iterator it;
     for(it = md.begin() ; it != md.end(); it++){
       //cout << it->first << ' ' << it->second.sum << endl;//
       maxi = max(it->second.sum,maxi);
     }
     cout << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 1016
import numpy as np

N, W = map(int, input().split())

r = 10 ** 5 + 100
dp = np.array([[0]+[float("inf")]*(r-1)]*(N+1))
for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[i,:v] = dp[i-1,:v]
    dp[i,v:r] = np.minimum(dp[i-1,v:r], dp[i-1,:r-v]+w)
    
print(max(np.where(dp[N]<=W)[0]))

Measured memory_bytes: 93012
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n), t(n, 0);
    for (ll i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    ll ans = 0;
    for (ll i = 0; i < m; i++)
    {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        if (h[a] > h[b])
        {
            t[b]--;
        }
        else if (h[a] < h[b])
        {
            t[a]--;
        }
        else
        {
            t[a]--;
            t[b]--;
        }
    }

    for (ll i = 0; i < n; i++)
    {
        if(t[i]==0)
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
	return 0;
}


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

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

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=-10000000000;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> s(N);
	rep(i,N) cin>>s[i];
	ll n10mn=10000000000,sum=0;
	rep(i,N){
		if(s[i]%10!=0 && s[i]<n10mn) n10mn=s[i];
		sum+=s[i];
	}
	if(sum%10!=0) cout<<sum;
	else{
		if(n10mn==10000000000) cout<<0;
		else{
			cout<<sum-n10mn;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   
   int a[100], n, i, p;
   long r, res,result = 0, min = 300000000;
   
   scanf("%d\n", &n);

   for(i = 0; i <= n-1 ; i++){
       scanf("%d", &a[i]);
   }
   
   for(p = 0; p<101 ;p++){
       i = 0;
       result = 0;
       for(; i<=n-1; i++){
          r = a[i] - p;
          res = r * r;
          result += res;
       }
       if(min > result){
           min = result;
       }
   }

   printf("%ld\n", min);

   
   return 0;
}

Measured memory_bytes: 128