akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <cstdio>
using namespace std;
 
const int n_MAX = 100,m_MAX = 100,l_MAX=100;
int a[n_MAX][m_MAX], b[m_MAX][l_MAX];
long int c[n_MAX][l_MAX];
 
void input(int n,int m,int l){
    for (int i1 = 0; i1 < n; i1++){
        for (int i2 = 0; i2 < m; i2++){
            cin >> a[i1][i2];
        }
    }
    for (int i1 = 0; i1 < m; i1++){
        for (int i2 = 0; i2 < l; i2++){
            cin >> b[i1][i2];
        }
    }
}
 
void matrix(int n,int m,int l){
    for (int i1 = 0; i1 < n; i1++){
        for (int i3 = 0;; i3++){
            c[i1][i3] = 0;
            for (int i2 = 0; i2 < m; i2++){
                c[i1][i3] += a[i1][i2] * b[i2][i3];
            }
            cout << c[i1][i3];
            if (i3 + 1 == l)break;
            cout << ' ';
        }
        cout << endl;
    }
}
 
int main(){
 
    int n, m, l;
    cin >> n >> m >> l;
 
    input(n, m, l);
 
    matrix(n, m, l);
 
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if((n / 10) % 10 == 9 || n % 10 == 9) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    long long int ang;
    long long int ttl = 1;
    long long int N[100005];
    bool lanjut = true;
    bool printtotal = true;
    scanf("%lld", &ang);
    
    for (long long int i = 1; i <= ang; i++){
        scanf("%lld", &N[i]);
        if(N[i]==0){
            printf("0\n");
            lanjut = false;
            break;
        }
    }
    
      if(lanjut){
          for(int i = 1; i<=ang;i++){
                if(1000000000000000000/ttl >= N[i]){
                  ttl *= N[i];
            }
            else{
                printf("-1\n");
                printtotal = false;
                break;
            }    
        }    
        if(printtotal){
            printf("%lld\n",ttl);
        }
    }
    return 0;
}

Measured memory_bytes: 2512
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[]) {
  int N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  string ans = "";
  while (N != 0) {
    if (N % 2 != 0) {
      N--;
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }

    N /= -2;
  }

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


Measured memory_bytes: 256
from itertools import permutations
from math import factorial
N = int(input())
data = []
for _ in range(N):
    x, y = map(int, input().split())
    data.append((x,y))
res = 0
for a in permutations(data,N):
    x0, y0 = a[0]
    for x, y in a[1:]:
        res += ((x-x0)**2 + (y-y0)**2)**(0.5)
        x0, y0 = x, y

print(res/factorial(N))

Measured memory_bytes: 74436
import sys
sys.setrecursionlimit(10**7)


n = int(input())
col = [0]*n
next = [[] for i in range(n)]
d = [float('INF')]*n
d[0]=0

def dfs(now,parent):
    for next1,w1 in next[now]:
        if next1 == parent:
            continue
        elif d[next1]==float('INF'):
            d[next1]=d[now]+w1
            dfs(next1,now)

for i in range(n-1):
    u , v , w = map(int, input().split())
    next[u-1].append((v-1,w))
    next[v-1].append((u-1,w))

dfs(0,-1)

for i in range(n):
    if d[i]%2==0:
        print('0')
    else:
        print('1')



Measured memory_bytes: 84392
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*void chmax(P &a,P b) {
  if (a.ft<b.ft) a.sc=max(a.ft,b.sc), a.ft=b.ft;
  else a.sc=max(a.sc,b.ft);
}*/

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<int> a(n);
    cinf(n,a);
    ll r=0,l=0;
    ll ans=0;
    V<int> b(20,0);
    bool flag=1;
    while(l<n){
        bool ok=1;
        rep(i,20){
            if(a[r]>>i&1){
                if(flag) b[i]++;
            }
            if(b[i]>1) ok=0;
        }
        if(ok){
            flag=1;
            if(r<n-1) r++;
            else{
                ans+=(r-l+1)*(r-l)/2+(r-l+1);
                break;
            }
        }else{
            flag=0;
            ans+=r-l;
            rep(i,20){
                if(a[l]>>i&1) b[i]--;
            }
            l++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    _ <- B.getLine
    as <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let b1 = V.length $ V.filter odd as
        b4 = V.length $ V.filter (\x -> x `mod` 4 == 0) as
        b2 = V.length as - b1 - b4
    putStrLn $ if b2 == 0
                then if b1 <= b4 + 1 then "Yes" else "No"
                else if b1 <= b4     then "Yes" else "No"


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str;
		while ((str = br.readLine()) != null) {
			if (str.equals("-")) break;
			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				int h = Integer.parseInt(br.readLine());
				str = str.substring(h, str.length()) + str.substring(0, h);
			}
			
			System.out.println(str);
		}
	}

}

Measured memory_bytes: 24336
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, vector<ll> a) {
  using PQ = priority_queue<ll, vector<ll>, greater<ll>>;
  PQ que;
  ll sum = 0;
  vector<ll> x, y;
  REP(i,N) {
    que.push(a[i]);
    sum += a[i];
  }
  x.push_back(sum);
  REP(i,N) {
    sum += a[N+i];
    que.push(a[N+i]);
    sum -= que.top();
    que.pop();
    x.push_back(sum);
  }
  sum = 0;
  reverse(ALL(a));
  while (!que.empty()) que.pop();
  REP(i,N) {
    que.push(-a[i]);
    sum += a[i];
  }
  y.push_back(sum);
  REP(i,N) {
    sum += a[N+i];
    que.push(-a[N+i]);
    sum -= -que.top();
    que.pop();
    y.push_back(sum);
  }
  reverse(ALL(y));
  // for (ll i: x) cout << i << " ";
  // cout << endl;
  // for (ll i: y) cout << i << " ";
  // cout << endl;
  ll res = -1e18;;
  REP(i,N+1) chmax(res, x[i] - y[i]);
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> a(3*N-1+1);
	for (int i = 0 ; i <= 3*N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 8048
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
#print(a) 
x=0;y=0;z=0
c=0;d=0;e=0
ss=[[0,0,0] for _ in range(n)]
ans=1
for i in range(n):
    if a[i]==c:
        l[i]='r'
        c+=1
    elif a[i]==d:
        l[i]='b'
        d+=1
    elif a[i]==e:
        l[i]='g'
        e+=1
    ss[i][0]=c;ss[i][1]=d;ss[i][2]=e
ss=[[0,0,0]]+ss
#print(ss)
p=[0,0,0]
for i in range(1,n+1):
    p[0]=ss[i][0]-ss[i-1][0];p[1]=ss[i][1]-ss[i-1][1];p[2]=ss[i][2]-ss[i-1][2]
    #print(p)
    if ss[i-1][0]==ss[i-1][1]==ss[i-1][2] and p[0]==1:
        ans=ans*3%(10**9+7)
    elif ss[i-1][0]==ss[i-1][1] and p[0]==1:
        ans=ans*2%(10**9+7)
    elif ss[i-1][1]==ss[i-1][2] and p[1]==1:
        ans=ans*2%(10**9+7)
    if p==[0,0,0]:
        ans=0
        break
print(ans%(10**9+7))


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	int y,m,d;
	while(cin>>y>>m>>d){
		int val = d+100*m+10000*y;
		if(val>=8+100*1+10000*1989)			cout<<"heisei"<<" "<<(y-1989+1)<<" "<<m<<" "<<d<<endl;
		else if(val>=25+100*12+10000*1926)	cout<<"showa" <<" "<<(y-1926+1)<<" "<<m<<" "<<d<<endl;
		else if(val>=30+100*7 +10000*1912)	cout<<"taisho"<<" "<<(y-1912+1)<<" "<<m<<" "<<d<<endl;
		else if(val>=8 +100*9 +10000*1868)	cout<<"meiji" <<" "<<(y-1868+1)<<" "<<m<<" "<<d<<endl;
		else cout<<"pre-meiji"<<endl;
	}
}


/*

??????	??????
meiji	1868. 9. 8	???	1912. 7.29
taisho	1912. 7.30	???	1926.12.24
showa	1926.12.25	???	1989. 1. 7
heisei	1989. 1. 8	???
*/

Measured memory_bytes: 1164
#include <stdio.h>

int main(void)
{
  int a,b,c,d;
  
  scanf("%d %d %d %d",&a,&b,&c,&d);
  
  for(;;){
    c-=b;
    if(c<=0){
      printf("Yes");
      break;
    }
    a-=d;
    if(a<=0){
      printf("No");
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1724
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[][][] rp = new int[4][3][10];
		
		for(int db = 0; db < 4; db++) {
			for(int df = 0; df < 3; df++) {
				for(int dr = 0; dr < 10; dr++) {
					rp[db][df][dr] = 0;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			
			rp[b-1][f-1][r-1] += v;
		}
		
		for(int pb = 0; pb < 4; pb++) {
			if(pb != 0) {
				System.out.println("####################");
			}
			for(int pf = 0; pf < 3; pf++) {
				for(int pr = 0; pr < 10; pr++) {
					System.out.print(" " + rp[pb][pf][pr]);
				}
				System.out.println();
			}
		}
	}
}



Measured memory_bytes: 29768
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, K;
ll A[101010], LA[101010], RA[101010];

int main() {
    scanf("%d%d", &N, &K);
    for (int j = 0; j < N; ++j) {
        scanf("%lld", A+j);
    }
    for (int j = 0; j < N; ++j) {
        LA[j] = max(0LL, A[j]);
        if (j > 0 && LA[j-1] > 0) LA[j] += LA[j-1];
    }
    for (int j = N-1; j >= 0; --j) {
        RA[j] = max(0LL, A[j]);
        if (j < N-1 && RA[j+1] > 0) RA[j] += RA[j+1];
    }

    for (int j = 1; j < N; ++j) {
        A[j] += A[j-1];
    }

    ll ans = -1;
    for (int j = 0; j + K-1 <= N-1; ++j) {
        ll w = max(0LL, (j==0 ? A[K-1] : A[j+K-1] - A[j-1]));
        if (j > 0) w += LA[j-1];
        if (j+K <= N-1) w += RA[j+K];
        ans = max(ans, w);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
ll dp[55][5050];
int main( ){
    int n,a;
    cin>>n>>a;
    vi x(n);
    int X=a;
    rep(i,0,n)cin>>x[i],chmax(X,x[i]),x[i]-=a;
    dp[0][n*X]=1;
    rep(i,0,n){
        rep(j,0,2*X*n+1){
            int ni=i+1;
            int nj=j+x[i];
            if(0<=nj&&nj<=X*n*2)
                dp[ni][nj]=dp[i][nj]+dp[i][j];
            else
            {
                dp[ni][j]=dp[i][j];
            }
        }
    }
    cout<<dp[n][n*X]-1<<endl;
    return 0;
}




Measured memory_bytes: 2176
n = int(input())
g =[[] for _ in range(n)]
for i in range(n-1):
  u,v,w = map(int,input().split())
  g[u-1].append((v-1,w))
  g[v-1].append((u-1,w))
distance = [-1]*n
distance[0] = 0
q = [0]
while q:
  p = q.pop()
  for a,b in g[p]:
    if distance[a] == -1:
      distance[a] = distance[p]+b
      q.append(a)
for i in range(n):
  print((distance[i])%2)

Measured memory_bytes: 70816
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
#define f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ALL(x) begin(x),end(x)
using namespace std; 


void solve()
{
   int k;cin>>k;
   int n;cin>>n;

    vi a(n);

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

    a.emplace_back(a[0]+k); 

    int ma=0;
    for(int i = 1;i < a.size(); ++i){
        ma=max(ma,a[i]-a[i-1]);
    }

    printf("%lld\n",k-ma);
}

int32_t main()
{   
     f_ip
     
     solve();

     return 0;
}


Measured memory_bytes: 4864
import math
from fractions import Fraction
n,k=map(int,input().split())
if n>=k:
	result = (n-k+1)/n
else:
	result = 0
for i in range(1,min(n+1,k)):
	if math.log(k/i,2)==int(math.log(k/i,2)):
		time = int(math.log(k/i,2))
	else:
		time = int(math.log(k/i,2))+1
	result+=float(Fraction(1, n)*(Fraction(1, 2)**(time)))
print(result)

Measured memory_bytes: 5052
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

int main() {
    int cnt[26] = { 0 };
    for(char ch; cin >> ch; ) {
        if(isalpha(ch)) {
            if(isupper(ch)) ch = tolower(ch);
            cnt[ch - 'a']++;
        }
    }
    for(int i = 0; i < 26; i++) {
        cout << (char)('a' + i) << " : " << cnt[i] << endl;
    }
}

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

typedef long long ll;

const int mod = 1000000007;
const int INF = 1001001001;

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

const ll MOD = 998244353;

int main() {
    int n;
    cin >> n;
    ll m = 1;
    vector<ll> dcnt(n +100, 0);
    vector<ll> d(n + 100, 0);
    rep(i, n) {
        cin >> d[i];
        m = max(m, d[i]);
        dcnt[d[i]] += 1;
    }

    if(dcnt[0] == 0 || dcnt[0] >= 2 || d[0] != 0) cout << 0 << endl;
    else {
        ll ans = 1;
        for(ll i = 1; i <= m; i++) {
            if(dcnt[i] == 0) {
                cout << 0 << endl;
                return 0;
            }
            for(ll j = 0; j < dcnt[i]; j++) {
                ans *= dcnt[i-1];
                ans %= MOD;
            }

            
        }

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

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#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;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(qi,q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      swap(s,t);
    } else {
      int f; char c;
      cin >> f >> c;
      if (f == 1) {
        t += c;
      } else {
        s += c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

bool reach[MAX_N];
vector<int> edge[MAX_N];

void dfs(int now){ //連結成分の数を数える
    if(reach[now]) return;
    reach[now]=true;
    rep(i,edge[now].size()) dfs(edge[now][i]);
}

int main(void){
    int N;
    cin >> N;
    int A[N+1],B[N+1];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    A[N]=0,B[N]=0;
    rep(i,N) A[N]=A[N]^A[i],B[N]=B[N]^B[i];
    multiset<int> a,b;
    rep(i,N+1) a.insert(A[i]),b.insert(B[i]);
    if(a!=b){
        cout << -1 << endl;
        return 0;
    }
    int ans=N;
    if(A[N]!=B[N]){ //XORが異なる場合
        ans++;
        rep(i,N) if(A[i]!=B[i] && A[N]==B[i]){ //XORを等しくしておく　操作1回分
            swap(A[i],A[N]);
            break;
        }
    }
    rep(i,N) if(A[i]!=B[i] && A[N]==B[i]){ //XORが目標の数列にあるかつ元々揃ってない場合1回少なくて済む
        ans--;
        break;
    }
    map<int,int> V;
    pint P[N+1];
    rep(i,N+1) P[i].fi=A[i],P[i].se=i;
    sort(P,P+N+1);
    rep(i,N+1) if(A[i]!=B[i]) V[A[i]]=i;
    rep(i,N+1){
        if(A[i]==B[i]) ans--; //元から揃ってるところは使わない
        else{
            edge[V[A[i]]].push_back(V[B[i]]);
            edge[V[B[i]]].push_back(V[A[i]]);
        }
        if(i==N && A[i]==B[i]) ans++; //XORの部分は数えない
    }
    rep(i,N) if(P[i].fi==P[i+1].fi){
        edge[P[i].se].push_back(P[i+1].se);
        edge[P[i+1].se].push_back(P[i].se);
    }
    rep(i,N+1) if(!reach[i]) if(A[i]!=B[i]) dfs(i),ans++;
    cout << ans << endl;
}

Measured memory_bytes: 26624
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::cout << (n == m ? "Yes" : "No") << std::endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long int
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	int result = 0;
	for( int i = 0; i < N-1; ++i ) {
		if( S[i] == S[i+1] ) { result += 1; }
	}

	result = min( result + 2*K, N-1 );
	cout << result << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

int main() {
	int N; cin >> N;
	map<int, int> mp;
	set<int> s;

	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		mp[a]++;
		s.insert(a);
	}

	int ans = 0;

	while (!s.empty()) {
		set<int>::iterator it = s.begin();
		int i = *it;
		if (mp[i] < i) ans += mp[i];
		else ans += (mp[i] - i);
		s.erase(it);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9216
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<iostream>
#include<algorithm>//next_permutation

using namespace std;
int main() {
	int N, R;
	cin >> N >> R;
	if (N >= 10) {
		cout << R;
	}
	else {
		cout << R + 100 * (10 - N);
	}
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

const int BOTH = 0;
const int EAST = 1;
const int NORTH = 2;
const int mod = 100000;

int w, h;
int memo[100][100][3][3];

int dfs(int x = 0, int y = 0, int can = BOTH, int prev = 0) {
	if(x == w - 1 && y == h - 1)
		return 1;

	if(memo[x][y][can][prev] != -1)
		return memo[x][y][can][prev];

	int res = 0;
	if(can <= 1 && x < w - 1) {
		int next_can = BOTH;
		if(prev == NORTH)
			next_can = EAST;

		res += dfs(x + 1, y, next_can, EAST);
	}
	if(can % 2 == 0 && y < h - 1) {
		int next_can = BOTH;
		if(prev == EAST)
			next_can = NORTH;

		res += dfs(x, y + 1, next_can, NORTH);
	}

	return memo[x][y][can][prev] = res % mod;
}

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

	while(cin >> w >> h, w) {
		memset(memo, -1, sizeof(memo));
		cout << dfs() % mod << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1568
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    H, W, R, C = map(int, readline().split()); R -= 1; C -= 1
    if H == W == 0:
        return False
    G0 = [[] for i in range(H*W+1)]
    G1 = [[] for i in range(H*W+1)]
    g = H*W
    for i in range(H):
        *s, = map(int, readline().split())
        k = W*i
        if i:
            for j in range(W):
                if s[j]:
                    G1[k+j].append(k+j-W)
                    G1[k+j-W].append(k+j)
                else:
                    G0[k+j].append(k+j-W)
                    G0[k+j-W].append(k+j)
        else:
            for j in range(W):
                if s[j]:
                    G1[j].append(g)
                    G1[g].append(j)
                else:
                    G0[j].append(g)
                    G0[g].append(j)
        *s, = map(int, readline().split())
        for j in range(W-1):
            if s[j+1]:
                G1[k+j].append(k+j+1)
                G1[k+j+1].append(k+j)
            else:
                G0[k+j].append(k+j+1)
                G0[k+j+1].append(k+j)
        if s[0]:
            G1[k].append(g)
            G1[g].append(k)
        else:
            G0[k].append(g)
            G0[g].append(k)
        if s[W]:
            G1[k+W-1].append(g)
            G1[g].append(k+W-1)
        else:
            G0[k+W-1].append(g)
            G0[g].append(k+W-1)
    *s, = map(int, readline().split())
    k = (H-1)*W
    for j in range(W):
        if s[j]:
            G1[k+j].append(g)
            G1[g].append(k+j)
        else:
            G0[k+j].append(g)
            G0[g].append(k+j)

    u0 = [0]*(H*W+1)
    u1 = [0]*(H*W+1)
    u0[g] = u1[g] = 1
    que = deque([g])
    while que:
        v = que.popleft()
        for w in G0[v]:
            if u0[w]:
                continue
            if u1[w]:
                que.append(w)
            u0[w] = 1
        for w in G1[v]:
            if u1[w]:
                continue
            if u0[w]:
                que.append(w)
            u1[w] = 1
    if u0[R*W + C]:
        write("Yes\n")
    else:
        write("No\n")
    return True
while solve():
    ...


Measured memory_bytes: 93072
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
using namespace std;
const int64_t INF=10000000000000000;
struct Restriction{
	int digit;
	int number;
};
int64_t powi(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powi(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	int begin,end;
	if(n==1){
		begin=0;
		end=9;
	}else if(n==2){
		begin=10;
		end=99;
	}else{
		begin=100;
		end=999;
	}
	vector<Restriction> res;
	for(int i=0;i<m;i++){
		int temp_s,temp_c;
		cin>>temp_s>>temp_c;
		res.push_back(Restriction{temp_s,temp_c});
	}
	int ans=-1;
	for(int num=begin;num<=end;num++){
		bool isans=true;
		for(auto i1=res.begin();i1!=res.end();i1++){
			if((num/powi(10,n-(i1->digit)))%10!=(i1->number)){
				isans=false;
				break;
			}
		}
		if(isans){
			ans=num;
			break;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 55
#define ll long long

using namespace std;

struct ball{
	ll x,y;
}b[N];

int n,tot,ans = 100;

map < pair < ll , ll > , int > mp;

bool cmp(ball ,ball);

int main(){
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> b[i].x >> b[i].y;
	sort(b + 1, b + 1 + n, cmp);
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			ll p = b[j].x - b[i].x,q = b[j].y - b[i].y;
			++tot;
			int cnt = 0;
			for(int k = 1; k <= n; ++k){
				if(mp[make_pair(b[k].x - p, b[k].y - q)] != tot)
					++cnt;
				mp[make_pair(b[k].x,b[k].y)] = tot;
			}
			ans = min(ans , cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

bool cmp(ball a,ball b){
	if(a.x == b.x) return a.y < b.y;
	return a.x < b.x;
}


Measured memory_bytes: 4096
! 2020.1.18
!
      program answer
      implicit none
      integer :: H,W,N
      integer :: ans
!
      read(*,*) H
      read(*,*) W
      read(*,*) N
!
      if(H > W) then
        ans = N/H
        if(mod(N,H)/=0) ans = ans+1
      else
        ans = N/W
        if(mod(N,W)/=0) ans = ans+1
      end if
!
      write(*,*) ans
!
      end program answer

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<char> ans;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    bool ok = true;
    if (a+b+c != 2) {
        rep(i,n) {
            if (s[i] == "AB") {
                if (a >= b) {a--; b++; ans.push_back('B');}
                else {a++; b--; ans.push_back('A');}
            }
            if (s[i] == "BC") {
                if (b >= c) {b--; c++; ans.push_back('C');}
                else {b++; c--; ans.push_back('B');}
            }
            if (s[i] == "AC") {
                if (a >= c) {a--; c++; ans.push_back('C');}
                else {a++; c--; ans.push_back('A');}
            }
            if (a < 0 || b < 0 || c < 0) {ok = false; break;}
        }
    } else {
        rep(i,n) {
            if (s[i] == "AB") {
                if (a == 1 && b == 1 && i != n-1) {
                    if (s[i+1] == "AB") {a++; b--; ans.push_back('A');}
                    if (s[i+1] == "AC") {a++; b--; ans.push_back('A');}
                    if (s[i+1] == "BC") {b++; a--; ans.push_back('B');}
                } else {
                    if (a < b) {a++; b--; ans.push_back('A');}
                    else {b++; a--; ans.push_back('B');}
                }
            }
            if (s[i] == "AC") {
                if (a == 1 && c == 1 && i != n-1) {
                    if (s[i+1] == "AB") {a++; c--; ans.push_back('A');}
                    if (s[i+1] == "AC") {a++; c--; ans.push_back('A');}
                    if (s[i+1] == "BC") {c++; a--; ans.push_back('C');}
                } else {
                    if (a < c) {a++; c--; ans.push_back('A');}
                    else {c++; a--; ans.push_back('C');}
                }
            }
            if (s[i] == "BC") {
                if (c == 1 && b == 1 && i != n-1) {
                    if (s[i+1] == "AB") {b++; c--; ans.push_back('B');}
                    if (s[i+1] == "AC") {c++; b--; ans.push_back('C');}
                    if (s[i+1] == "BC") {b++; c--; ans.push_back('B');}
                } else {
                    if (c < b) {c++; b--; ans.push_back('C');}
                    else {b++; c--; ans.push_back('B');}
                }
            }
            if (a < 0 || b < 0 || c < 0) {ok = false; break;}
        }
    }
    if (ok) {
        cout << "Yes" << endl;
        rep(i,n) cout << ans[i] << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(m);
  ll cu=0;
  rep(i,m){
    cin>>a[i];
    cu+=a[i];
  }
  if(n<cu){
    COUT(-1);
  }
  else{
    COUT(n-cu);
  }
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main()
{
  int n, tmp, c=0, ans;
  cin >> n;
  tmp = n;
  while(tmp)
  {
      tmp /= 10;
      c++;
  }
  if(c == 1)
    ans = n;
  else if(c == 2)
    ans = 9;
  else if(c == 3)
    ans = n-99+9;
  else if(c == 4)
    ans = 909;
  else if(c == 5)
    ans = n-9999+909;
  else if(c == 6)
    ans = 90909;
  
  cout << ans <<"\n";
  return 0;
}

Measured memory_bytes: 256
a=input()
n=int(a[0:2])
m=int(a[2:4])
if 0<n<=12 and 0<m<=12:
    print('AMBIGUOUS')
elif 0<n<=12:
    print('MMYY')
elif 0<m<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 61808
#include <stdio.h>
#define Max 100000
 
int a[Max];
int partition(int,int); 
 
int main(){

  int n,q;
  int i;
 
  scanf("%d",&n);

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

  q = partition(0,n-1);
 
  for(i = 0; i < n; i++){
    if(i == q) printf("[");
 
      printf("%d",a[i]);
 
      if(i == q) printf("]");
 
      if(i != n-1) printf(" ");
  }

  printf("\n");
 
  return 0;
}
 
int partition(int p,int r){

  int x;
  int i,j;
  int s;
 
  x = a[r];
  i = p-1;

  for(j = p; j < r; j++){
    if(a[j] <= x){
      i++;
      s = a[i];
      a[i] = a[j];
      a[j] = s;
    }
  }
      s = a[i+1];
      a[i+1] = a[r];
      a[r] = s;
  
    return i+1;
  }

Measured memory_bytes: 992
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;

string s;
int main(){
    cin>>s;
    if(s[0] == s[1] && s[1]== s[2]) puts("No");
    else puts("Yes");

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int N=1e5+10;
int dp[N],in[N];
vector<int> edge[N];
queue<int> q;
int main()
{
	int n,m,i,j,a,b,ans=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++) scanf("%d%d",&a,&b),in[b]++,edge[a].push_back(b);
	for(i=1;i<=n;i++) if(in[i]==0) q.push(i);
	while(!q.empty())
	{
		int now=q.front();q.pop();
		for(i=0;i<edge[now].size();i++)
		{
			int y=edge[now][i];
			dp[y]=max(dp[y],dp[now]+1);
			in[y]--;
			if(in[y]==0) q.push(y);
		}
	}
	for(i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9916
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#include <math.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 101010;

ll arr[MAX];

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    ll n;
    cin >> n;
    rep(i, n){
        cin >> arr[i];
        if((i == 0) != (arr[i] == 0)){
            cout << 0 << endl;
            return 0;
        }
    }
    
    ll numSum[MAX];
    ll ma = 0;
    rep(i, n){
        numSum[arr[i]]++;
        ma = max(ma, arr[i]);
    }
    ma++;
    ll res = 1LL;
    ll tmp =998244353LL;
    rep2(i, 1, ma){
        ll prod = 1;
        rep(j, numSum[i]){
            prod *= numSum[i-1];
            prod %= tmp;
        }
        res *= prod;
        res %= tmp;
    }
    cout << res <<  endl;
    
    return 0;
}


Measured memory_bytes: 1792
// Problem: https://codeforces.com/contest/1285/problem/E
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
#define ford(i, a, b, c)        for(int i=(a); i<(b); i+=(c))
#define fori(i, a, b)           ford(i,a,b,1)
#define rep(i, n)               fori(i,0,n)
#define ifor(i, a, b)           for(int i=(a); i>=(b); i--)
#define si(x)                   ((int)x.size())
#define SS                      ({int x;scanf("%d",&x);x;})
#define pb                      push_back
#define mp                      make_pair
#define all(a)                  a.begin(),a.end()
#define inf                     (int)1e9
#define linf                    (long long)1e18
#define V                       vector
#define S                       string
#define XX                      first
#define YY                      second
#define P(x)                    cout<<x<<"\n"
#define PVI(v)                  rep(i, si(v)) cout<<v[i]<<" "; puts("")
#define PPI(p)                  cout<<"("<<p.first<<", "<<p.second<<")\n"
#define PVPI(v)                 rep(i, si(v)) cout<<"("<<v[i].first<<", "<<v[i].second<<")"<<(i==si(v)-1?"":", ");puts("")
#define PA(arr1, arr2)          for(auto it = arr1; it != arr2; it++) cout<<*it<<" "; puts("");
typedef V<int> vi;
typedef V<S> vs;
typedef long long ll;
typedef pair<int,int> pii;
const int MOD7 = 1000000000+7;
const int MOD9 = 1000000000+9;
/* ################### Program Body starts here ################ */

int ans[100000] = {}, penalty[100000] = {};

int main() {
    int n = SS,  m = SS;
    int total = 0;
    rep(i, m) {
        int x = SS;
        S s;
        cin>>s;
        if (s == "WA") {penalty[x-1]++;}
        else {
            if (!ans[x-1]) {
                total += penalty[x-1];
                ans[x-1] = 1;
            }
        }
    }
    cout<<count(ans, ans+n, 1)<<" "<<total<<"\n";

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)

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

  pair<ll, ll> AB[N];
  rep(i, N) {
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB, AB+N);
  ll dp_l[N+2][T+1], dp_r[N+2][T+1];

  rep(i, N+2) rep(j, T+1) dp_l[i][j] = dp_r[i][j] = 0;
  rep(i, N) {
    ll A = AB[i].first, B = AB[i].second;
    rep(t, T+1) {
      dp_l[i+1][t] = dp_l[i][t];
      if (t-A >= 0)
        dp_l[i+1][t] = max(dp_l[i][t], B + dp_l[i][t-A]);
    }
  }
  ll ans = 0;
  rep(i, N) {
    ans = max(ans, dp_l[i][T-1] + AB[i].second);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 141056
#include<stdio.h>
int main(void){
    char s[10], S[10];
    int sI, SI;
    scanf("%c %c", &s[0], &S[0]);
    if ( s[0] == 'A') sI = 1;
    if ( s[0] == 'B') sI = 2;
    if ( s[0] == 'C') sI = 3;
    if ( s[0] == 'D') sI = 4;
    if ( s[0] == 'E') sI = 5;
    if ( s[0] == 'F') sI = 6;
    if ( S[0] == 'A') SI = 1;
    if ( S[0] == 'B') SI = 2;
    if ( S[0] == 'C') SI = 3;
    if ( S[0] == 'D') SI = 4;
    if ( S[0] == 'E') SI = 5;
    if ( S[0] == 'F') SI = 6;
    /*printf("%c %c\n%d %d\n",s[0], S[0], sI, SI);*/
    if ( sI < SI) printf("<\n", S);
    else if ( sI > SI)printf(">\n", s);
    else if ( sI = SI ) printf("=\n");
    return 0;
}

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

int main(){
  int N,K; cin >> N >> K;
  int h[100000];
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  sort(h,h+N);
  int result=1e9;
  int temp;
  for(int i=0; i<=N-K; i++){
    temp=h[i+K-1]-h[i];
    result=min(result,temp);
  }
  cout << result << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e5+5,mod=1e9+7;
int tr[105][N];
void add(int,int,int);
int ask(int,int);
int a[105];
int main(){
    int n,K;
    scanf("%d%d",&n,&K);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    if(K==0){
        printf("%d",1);
        return 0;
    }
    tr[0][0]=1;
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        tr[i][0]=tr[i-1][0];
        for(int j=1;j<=K;j++){
            add(i,j,(1LL*mod+ask(i-1,j)-ask(i-1,max(0,j-a[i]-1)))%mod);
            if(j<=a[i]) add(i,j,1);
        }
    }
    printf("%d\n",(int)((1LL*mod+ask(n,K)-ask(n,max(0,K-1)))%mod));
}
int ask(int id,int i){
    int re=0;
    while(i){
        re+=tr[id][i];
        re%=mod;
        i-=i&-i;
    }
    return re;
}
void add(int id,int i,int k){
    while(i<N){
        tr[id][i]+=k;
        tr[id][i]%=mod;
        i+=i&-i;
    }
}


Measured memory_bytes: 40832
X,N=map(int, input().split())
p=list(map(int, input().split()))

a = 100
num = 0

for i in range(202):
    if (i-100) not in p:
        b = (i-100)-X
        if abs(b) < a:
            a = abs(b)
            num = (i-100)

print(num)


Measured memory_bytes: 9184
Q,H,S,D = map(int, input().split())
N = int(input())

H = min(H, Q * 2)
S = min(S, H * 2)
D = min(D, S * 2)

#print(S, D)

ans = (N // 2) * D + (N - (N // 2) * 2) * S
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

void solve(int m,int n){
  const int MAX = 8368792;
  vector<bool> data(MAX,true);
  vector<int> ans;
  for(int i=m;i<=MAX;i++){
    // cout<<i<<endl;
    if(data[i]){
      ans.pb(i);
      for(int j=i;j<=8368792;j+=i){
	data[j]=false;
      }
    }
  }
  // cout<<n<<" "<<ans.size()<<endl;
  cout<<ans[n]<<endl;
}

int main(){
  int m,n;
  while(cin>>m>>n,n|m){
    solve(m,n);
  }
  return 0;
}



Measured memory_bytes: 10240
#include <iostream>
#include <vector>

using namespace std;

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

  vector<vector<int>> s(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;

    s[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
      --s[i][j];
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool flg = true;

    for (int m = 0; m < M; ++m) {
      int cnt = 0;
      for (auto sw: s[m]) {
        if ((i >> sw) & 1) ++cnt;
      }
      if (cnt % 2 != p[m]) flg = false;
    }
    if(flg) ++ans;

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
int n,k;cin>>n>>k;
int ans=0;
if(10<=n)ans=k;
else ans=100*(10-n)+k;
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

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

using namespace std;

int main(void)
{
	string S;
	cin >> S;

	cout << S.substr(0, 3) << endl;

	rewind(stdin);
	char c = getchar();
	return 0;
}


Measured memory_bytes: 3576
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;


struct edge { int from, to, cost; };

int main() {
	IOS;
	const ll INF = LMAX;
	ll v, e, r;
	cin >> v >> e >> r;
	vector<edge> ed(e);
	vector<ll> d(v, INF);
	d[r] = 0;
	REP(i, e) {
		cin >> ed[i].from >> ed[i].to >> ed[i].cost;
	}
	REP(i, v) {
		REP(j, e) {
			edge tmp = ed[j];
			if (d[tmp.from] != INF && d[tmp.to] > d[tmp.from] + tmp.cost) {
				d[tmp.to] = d[tmp.from] + tmp.cost;
				if (i == v - 1) {
					dump("NEGATIVE CYCLE");
					return 0;
				}
			}
		}
	}
	REP(i, v) {
		if (d[i] == INF)dump("INF");
		else dump(d[i]);
	}
}




Measured memory_bytes: 3224
#include <stdio.h>

int main(){
  int N;
  long long int A[200000],B[200000];
  long long int S=0LL;
  scanf("%d",&N);
  for(int i=1;i<=N+1;i++) 
    scanf("%lld",A+i);
  for(int i=1;i<=N;i++) 
    scanf("%lld",B+i);
  B[0]=0;
  B[N+1]=0LL;
  long long int C=0;
  for(int i=1;i<=N+1;i++){
    S+=A[i]>B[i-1]?B[i-1]:A[i];
    A[i]=A[i]>B[i-1]?A[i]-B[i-1]:0;
    S+=A[i]>B[i]?B[i]:A[i];
    B[i]=A[i]>B[i]?0:B[i]-A[i];
  }
  printf("%lld\n",S);
  return 0;
}

Measured memory_bytes: 3232
def GridRepainting():
    H, W = map(int, input().split())
    strlist = []
    for _ in range(0, H):
        strlist.append(list(input()))
    for i in range(0, H):
        for j in range(0, W):
            if strlist[i][j] == '#':
                if i > 0:
                    if strlist[i - 1][j] == '#':continue
                if i != H - 1:
                    if strlist[i + 1][j] == '#':continue
                if j > 0:
                    if strlist[i][j - 1] == '#':continue
                if j != W - 1:
                    if strlist[i][j + 1] == '#':continue
                print('No')
                return()

    print('Yes')
    return()

GridRepainting()


Measured memory_bytes: 3064