akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
// const int k_mod = 1e9 + 7;
const int k_mod = 998244353;

typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
} edge;
template <typename T, typename K> struct P {
	T a; K b;
};
int main( void ){
	int N; cin >> N;
	int buff[ 3 ] = {};
	int ans = 0;
	rep( i, 0, N ){
		string S; cin >> S;
		int l = S.size();
		rep( j, 1, l ){
			if (S[ j - 1 ] == 'A' && S[ j ] == 'B'){
				ans++;
			}
		}
		if (S[ 0 ] == 'B' && S[ l - 1 ] == 'A')
			buff[ 2 ]++;
		else if (S[ 0 ] == 'B')
			buff[ 1 ]++;
		else if (S[ l - 1 ] == 'A')
			buff[ 0 ]++;
	}
	if (buff[ 2 ] != 0){
		if (max( buff[ 0 ], buff[ 1 ] ) != 0)
			ans += buff[ 2 ] + min( buff[ 0 ], buff[ 1 ] );
		else
			ans += buff[ 2 ] - 1;

	}
	else {
		ans += min( buff[ 0 ], buff[ 1 ] );
	}

	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

int main() {
  string X; cin >> X;
  int stack = 0, puyo = 0;
  for (int i = 0; i < (int)X.size(); ++i) {
    if (X[i] == 'S') ++stack;
    else if (stack > 0) --stack, ++puyo;
  }
  cout << (int)X.size() - puyo*2 << endl;
}


Measured memory_bytes: 3740
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int comp(const void *a, const void *b)
{
    int x, y;
    x = *(int *)a;
    y = *(int *)b;
    
    return (x - y);
}

int main(void)
{
    int n;
    int i, j;
    int groupA[16192], groupB[16192];
    int h, m, s, hh, mm, ss;
    int ans;
    int prev;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d:%d:%d %d:%d:%d", &h, &m, &s, &hh, &mm, &ss);
            groupA[i] = h * 3600 + m * 60 + s;
            groupB[i] = hh * 3600 + mm * 60 + ss;
        }
        groupA[n] = INT_MAX;
        groupB[n] = INT_MAX;
        
        qsort(groupA, n + 1, sizeof(int), comp);
        qsort(groupB, n + 1, sizeof(int), comp);
        
        ans = i = j = 0;
        prev = 0;
        
        while (groupA[i] != INT_MAX && groupB[j] != INT_MAX){
            if (groupA[i] < groupB[j]){
                i++;
                if (prev == 0){
                    ans++;
                }
                else {
                    prev--;
                }
            }
            else {
                j++;
                prev++;
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

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

using namespace std;
typedef long long ll;

int main() {
    int n,k;
    cin >> n >> k;
    int ans=1;
    rep(i,n){
        if(ans>k){
            ans+=k;
        }
        else{
            ans*=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=2e5;
const int oo=1e9+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int get(int x)
{
    int dem=1;
    while (x)
    {
        if (x%2==0) x--;
        x/=2;
        dem++;
    }
    return dem;
}
int n,L;
vector<iii> q;
int main()
{
	//freopen("All Your Paths are Different Lengths.inp","r",stdin);
	//freopen("All Your Paths are Different Lengths.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>L; L--;
    n=get(L);
    int k=n;
    while (L)
    {
        if (L%2==0)
        {
            q.push_back(iii(ii(1,k),L));
            L--;
            q.push_back(iii(ii(k-1,k),0));
            q.push_back(iii(ii(k-1,k),L/2+1));
            L=L/2;
        } else
        {
            q.push_back(iii(ii(k-1,k),0));
            q.push_back(iii(ii(k-1,k),L/2+1));
            L=L/2;
        }
        k--;
    }
    cout<<n<<" "<<q.size()<<endl;
    for (int i=0;i<q.size();i++)
    {
        cout<<q[i].fs.fs<<" "<<q[i].fs.sd<<" "<<q[i].sd<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

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

  bool is_no = false;
  rep(i,2) {
    if (S[i]!=S[2]) is_no = true;
  }
  if (is_no == true) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007

lli IsPrime(lli num)
{
  lli a=0;
    double sqrtNum = sqrt(num);
    for (lli i = 2; i <= sqrtNum; i ++)
    {
        if (num % i == 0)
        {
          a=max(a,i);
        }
    }
  if(a) // 素数ではない
            return a;

    // 素数である
    return num;
}


int main(){
  lli N;
  cin >>N;
  
  if(IsPrime(N)==N){
  cout << N-1 << endl;
  }
  else
    cout << IsPrime(N)+N/IsPrime(N)-2 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if (a == b && b != c) {
            System.out.println("Yes");
        } else if (a == c && c != b) {
            System.out.println("Yes");
        } else if (c == b && b != a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
            
        }
    }
}


Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
char s[105], t[105];
int main()
{
	int i, j;
	scanf("%s%s", s, t);
	printf("%s", t);
	printf("%s", s);
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3003,mod=1e9+7,inv2=5e8+4;
int n,m,Q,a[N],f[N][N];
void add(int &x,int y){x=(x+y)%mod;}
int main()
{
	scanf("%d%d",&n,&Q);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[i][j]=a[i]<a[j]?1:0;
	for(int T=1;T<=Q;T++)
	{
		int x,y;scanf("%d%d",&x,&y);
		for(int i=1;i<=n;i++)
		if(i!=x&&i!=y)
		{
			f[i][x]=f[i][y]=1ll*(f[i][x]+f[i][y])*inv2%mod;
			f[x][i]=f[y][i]=1ll*(f[x][i]+f[y][i])*inv2%mod;
		}
		f[x][y]=f[y][x]=1ll*(f[x][y]+f[y][x])*inv2%mod;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<i;j++)
	ans=(ans+f[i][j])%mod;
	for(int i=1;i<=Q;i++)ans=2ll*ans%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll 
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 struct sch{
  ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b) 
{ 
    return (a.s < b.s); 
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll lcm(ll a,ll b)
{
  return a*b/gcd(a,b);
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1; 
    x = x % p;  
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}
int main()
{
    ll n,d;
    cin>>n>>d;
    ll x,y;
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        if(d*d>=x*x+y*y)
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

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

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 998244353;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

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

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }

ll dp[4010][4010];

int main(){

  string s = stin();
  ll n = SZ(s);
  vector<ll> a(2*n, 0);
  vector<ll> b(2*n, 0);
  REP(i, n){
    a[i] = s[i] - '0';
    b[i] = 2 - a[i];
  }
  vector<ll> as(2*n+1, 0);
  vector<ll> bs(2*n+1, 0);
  REP(i, 2*n){
    as[i+1] = as[i] + a[i];
    bs[i+1] = bs[i] + b[i];
  }

  dp[0][0] = 1;
  
  REP(i, 2*n){
    REP(j, i+1){
      REP(k, 2){
        ll na = j + k;
        ll nb = i + 1 - na;
        if(na <= as[i+1] && nb <= bs[i+1]){
          dp[i+1][na] += dp[i][j];
          if(dp[i+1][na] >= MOD){
            dp[i+1][na] -= MOD;
          }
        }
      }
    }
  }

  ll ans = 0;
  REP(i, 2*n+1){
    ans += dp[2*n][i];
    if(ans >= MOD){
      ans -= MOD;
    }
  }

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


Measured memory_bytes: 123648
S = input()
A = int(S[:2])
B = int(S[2:])
if 1 <= A <= 12 and 1 <= B <= 12:
    print('AMBIGUOUS')
elif 1 <= A <= 12:
    print('MMYY')
elif 1 <= B <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3068
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

ll comb(ll n)
{
    return(n*(n-1)/2);
}

int main()
{
    ll n;
    scanf("%lld",&n);
    ll a[n],k[n];
    for(int i=0;i<n;i++)
    {
        a[i]=0;
    }

    for(int i=0;i<n;i++)
    {
        scanf("%lld",&k[i]);
        a[k[i]-1]=a[k[i]-1]+1;
    }

    ll ans=0;
    for(int i=0;i<n;i++)
    {
    ans=ans+comb(a[i]);
    }

    for(int i=0;i<n;i++)
    {
        ll out=ans;
        out=out-((a[k[i]-1]-1));
        printf("%lld\n",out);
    }
    
    return 0;
}

Measured memory_bytes: 5632
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


int main(){

  int N,M;

  scanf("%d %d",&N,&M);

  /*
  int A[N];
  int i;
  for(i=0;i<N;i++){
   scanf("%d",&A[i]);
   }
  */
 int Co,Cu;
 Co =1;
 Cu =1;
 int i;
 for(i=0;i<2;i++){
  Co = Co*(N-i);
 }
 for(i=0;i<2;i++){
  Cu = Cu*(M-i);
 }
 printf("%d",(Co+Cu)/2);







 return(0);
 }


Measured memory_bytes: 128
h = gets.split("").map(&:to_i)
n = h.size - 1


ans_01 = 0
ans_10 = 0

n.times do |i|
  if i % 2 == 0
    if h[i] == 0
      ans_10 += 1
    else
      ans_01 += 1
    end
  else
    if h[i] == 1
      ans_10 += 1
    else
      ans_01 += 1
    end
  end
end

puts [ans_10, ans_01].min


Measured memory_bytes: 7676
def main():
    A, B = map(int, input().split())
    S = input()

    valid = False
    if S.count("-") == 1:
        s_a, s_b = S.split("-")
        if len(s_a) == A and len(s_b) == B:
            valid = True

    if valid:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


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

int main(){
    ll n,ans=0;
    cin>>n;
    for(int i=1; i<=n; i++) {
        if(i%3 != 0 && i%5 != 0) {
            ans += i;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3620
N = int(input())
h = list(map(int,input().split()))

ans = 0
while sum(h) > 0:
  for k in range(len(h)):
    if h[k] > 0:
      h = h[k:]
      break
  for k in reversed(range(len(h))):
    if h[k] > 0:
      h = h[:(k+1)]
      break
  cnt = 1
  for k in range(len(h)):
    if h[k] == 0 and h[k+1] > 0:
      cnt += 1
  h = [max(c-1,0) for c in h]
  ans += cnt

print(ans)

Measured memory_bytes: 3064
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var p = o.l();
  var x = 0;
  for(var i = 0; i < n; i++){
    if(i+1 !== p[i])x++;
  }
  return x<=2?"YES":"NO";
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<bool> > g(N,vector<bool>(N,false));
    vector<int> V(N-1);
    rep(i,N-1)V[i] = i+1;
    rep(i,M){
        int u,v;cin >> u >> v;
        u--;v--;
        g[u][v] = g[v][u] = true;
    }
    int res = 0;

    do{
        int u = 0;
        rep(i,V.size()){
            if(!g[u][V[i]])break;
            u = V[i];
            if(i == V.size()-1)res++;
        }


    }while (next_permutation(V.begin(),V.end()));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool rMin(int &a, int b) {
    return b < a ? a = b, true : false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;
    cin>>n;
    vector<int> dp(n, 1e9);
    int h[100000];
    for(int i = 0; i< n; i++) cin>>h[i];
    dp[0] = 0;
    for(int i = 1; i< n; i++){
        for(int j : {1, 2}){
            if(i-j >= 0) rMin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout<<dp[n-1]<<"\n";
        
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for (int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// vector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)

// ll dp[1005][3] = {99999999};

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, 0, n) cin >> h[i];
    vector<ll> dp(n + 1, INF);
    //dp[i]:足場iで支払うコストの最小値
    dp[0] = 0;
    rep(i, 0, n) {
        rep(j, 0, k+1) {
            if (i + j < n) {
                chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
            }
        }

    }
    cout << dp[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
    int H,W;cin>>H>>W;
    char s[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)
        cin >> s[i][j];
    }
    
    int L[H][W],R[H][W],U[H][W],D[H][W];

    for(int i=0;i<H;i++){
        if(s[i][0]=='#') L[i][0]=0;
        else L[i][0]=1;
        if(s[i][W-1]=='#') R[i][W-1]=0;
        else R[i][W-1]=1;
    }
    for(int i=0;i<W;i++){
        if(s[0][i]=='#') U[0][i]=0;
        else U[0][i]=1;
        if(s[H-1][i]=='#') D[H-1][i]=0;
        else D[H-1][i]=1;

    }

    for(int i=0;i<H;i++){
        for(int j=1;j<W;j++)
            if(s[i][j]=='.') L[i][j]=L[i][j-1]+1;
            else L[i][j]=0;     
    }
      
    for(int i=1;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='.') U[i][j]=U[i-1][j]+1;
            else U[i][j]=0;
        }
    }
  for(int i=H-2;i>=0;i--){
    for(int j=W-1;j>=0;j--){
      if(s[i][j]=='.')D[i][j]=D[i+1][j]+1;
      else D[i][j]=0;
    }
  }
  

    for(int i=H-1;i>=0;i--){
        for(int j=W-2;j>=0;j--){
            if(s[i][j]=='.') R[i][j]=R[i][j+1]+1;
            else R[i][j]=0;
        }
    }

    for(int i=H-2;i>=0;i--){
        for(int j=W-1;j>=0;j--){
            if(s[i][j]=='.') D[i][j]=D[i+1][j]+1;
            else D[i][j]=0;
        }
    }

    int Max=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)
        Max=max(Max,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  cout <<Max<<endl;

}

Measured memory_bytes: 70032
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

struct Unionfind {
	vector< int > par;
	Unionfind(int N) : par(N,-1){
	}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(x == y) return 0;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return 1;
	}
	int root(int k) {
		if(par[k] < 0) return (k);
		return (par[k] = root(par[k]));
	}
	bool same(int x, int y){
		x = root(x);
		y = root(y);
		return x==y;
	}
	int size(int k) {
		return (-par[root(k)]);
	}
};

int main(){
	
	int n,m; cin>>n>>m;
	Unionfind uf(n);
	for(int i=0; i<m; i++){
		int x,y,z; cin>>x>>y>>z;
		x--; y--;
		uf.unite(x,y);
	}
	int cnt{};
	for(int i=0; i<n; i++){
		if(uf.root(i)==i) cnt++;
	}
	cout << cnt << endl;
	
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n,a[maxn],q,x,y,ans=0;
map<int,int> m;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n) cin >> a[i];
    rep(n) {m[a[i]]++;ans+=a[i];}
    cin >> q;
    while(q--){
        cin >> x >> y;
        ans+=(y-x)*m[x];
        m[y]+=m[x];
        m.erase(x);
        print1(ans);
    }
	return 0;
}


Measured memory_bytes: 8312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(a.at(i) % 2 == 0 && a.at(i) % 3 != 0 && a.at(i) % 5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  
  cout << "APPROVED" << endl;
  return 0;
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = 	{1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  int c=0;
  vector<pair<int,int>> a(n);
  vector<pair<int,int>> b(n);
  rep(i,n)
    cin >> a.at(i).second >> a.at(i).first;
  sort(all(a));
  reverse(all(a));
  rep(i,n)
    cin >> b.at(i).first >> b.at(i).second;
  sort(all(b));
  rep(i,n){
    rep(j,n){
      if(((b.at(i).first)>(a.at(j).second))&&((b.at(i).second)>(a.at(j).first))){
        a.at(j)=make_pair(300,300);
        c++;
        break;
      }
    }
  }
  
  cout << c << endl;
}
      
    

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    if h%3 == 0 or w%3 == 0: # 綺麗に三等分できるケース
        print(0)
        exit()

    ans = INF
    th = h//2
    for i in range(1,w//2+2):
        tate = i*h
        yoko1 = (w-i)*th
        yoko2 = (w-i)*(h-th)
        M = max(tate,yoko1,yoko2)
        m = min(tate,yoko1,yoko2)
        ans = min(ans,M-m)

        amari = (w-i)//2
        yoko3 = amari*h
        yoko4 = (w-i-amari)*h
        M = max(tate,yoko3,yoko4)
        m = min(tate,yoko3,yoko4)
        ans = min(ans,M-m)

    tw = w//2
    for i in range(1,h//2+2):
        tate = i*w
        yoko1 = (h-i)*tw
        yoko2 = (h-i)*(w-tw)
        M = max(tate,yoko1,yoko2)
        m = min(tate,yoko1,yoko2)
        ans = min(ans,M-m)

        amari = (h-i)//2
        yoko3 = amari*w
        yoko4 = (h-i-amari)*w
        M = max(tate,yoko3,yoko4)
        m = min(tate,yoko3,yoko4)
        ans = min(ans,M-m)

    print(ans)


if __name__=="__main__":
    main()


Measured memory_bytes: 74164
#岩田くんのアドバイスからmapを使って作り直したもの

rec = input().split()
n, a, b = map(int, rec)
nin = [a, b]

nmax = min(nin)
nmin = n - min(n, (n - nin[0]) + (n - nin[1]))
print(str(nmax) + " " + str(nmin))

Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <queue>
using namespace std;

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

	vector<int> b(200000,0);
	
	for (int i = 0; i < n - 1;i++) {
		int a = 0;
		cin >> a;
		b.at(a - 1) = b.at(a - 1)+1;
	}

	for (int i = 0; i < n; i++) {
		cout << b.at(i) << endl;
	}
	


	return 0;
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<long long int>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vb vector<bool>
#define vvl vector<vector<ll> >
#define vvi vector<vector<int> >
#define pl pair<ll,ll>
#define pb push_back
#define PI 3.14159265
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fri(s,n) for(int i=s;i<n;i++)
#define frj(s,n) for(int j=s;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define vsi vector<set<int> >
#define pii pair<int,int>
#define inf 1e9
#define vpii vector<pair<int,int> >


ll power(ll a,ll b){
    if(b==0)
        return 1;
    if(b&1)
        return a*power(a,b-1);
    ll temp=power(a,b/2);
    return temp*temp;
    }
bool mycompare(ll a,ll b){
    return a>b;
    }

void solve(int *height,int *beauty,int n){
	ll dp[n];//dp[i] will give me the maximum beaty we can get including flower i
  	map<ll,ll> m;
  	ll ans=beauty[0];
  	m[height[0]]=beauty[0];
  	dp[0]=beauty[0];
  	for(int i=1;i<n;i++){
    	int h=height[i],b=beauty[i];
      	dp[i]=b;
      	auto it=m.upper_bound(h);
      	if(it!=m.begin()){
        	it--;
          	dp[i]+=it->second;
        	}
      	it=m.upper_bound(height[i]);
      	while(it!=m.end() && it->second<=dp[i]){
        	auto temp=it;
          	temp++;
          	m.erase(it);
          	it=temp;
        }
        m[h]=dp[i];
        ans=max(ans,dp[i]);

    }

	cout<<ans;

	}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
  	cin>>n;
  	int height[n];
  	for(int i=0;i<n;i++)
      cin>>height[i];
  	int beauty[n];
  	for(int i=0;i<n;i++)
      cin>>beauty[i];
  	solve(height,beauty,n);


	}



Measured memory_bytes: 19072
/// @author MUSTAFA MOGHAZY
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
 int n, k, x, y;
 cin>>n>>k>>x>>y;
 ll sum = 0;
 if(n>=k){
 sum += k*x;
 sum += (n-k)*y;
 cout<<sum;
 }
 else
    cout<<n*x;
}


Measured memory_bytes: 3644
import collections
import sys
N=int(input())
ans=0
ANS=[]
A = list(map(int, input().split()))
new_A = sorted(A, reverse=True)
j=0
#print(new_A)
for i in range(len(A)-1):
    if new_A[j]==new_A[j+1]:
        ANS.append(new_A[j])
        #print(ANS)
        j+=1
    if len(ANS)==2:
        print(ANS[0]*ANS[1])
        sys.exit()
    j+=1
print("0")

Measured memory_bytes: 20508
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	if b-a+1 <= 2*k {
		for i := a; i <= b; i++ {
			fmt.Println(i)
		}
	} else {
		for i := a; i < a+k; i++ {
			fmt.Println(i)
		}
		for i := b - k + 1; i <= b; i++ {
			fmt.Println(i)
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define out(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(100);
    v[0] = 2;
    v[1] = 1;
    FOR(i,2,87) {
        v[i] = v[i-1] + v[i-2];
    }

    out(v[n])

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int ans = 1;
        while(ans <= n) {
            ans *= 2;
        }
        System.out.println(ans/2);
    }
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i=0; i<M; i++) cin >> A.at(i);
    int sum = 0;
    for(int i=0; i<M; i++) sum += A.at(i);
    if(sum > N) cout << -1<< endl;
    else cout << N - sum << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>

#define MAX 100000


int p(int i) {
  return i/2;
}

int l(int i){
  return 2*i;
}

int r(int i){
  return 2*i+1;
}




int main(){
  int T,i,b,arry[MAX+1];
  int w,e,o;
 
  
  scanf("%d",&T);

  for(i=1;i<=T;i++){
    scanf("%d",&arry[i]);
  }

  for(i=1;i<=T;i++){
    printf("node %d: key = %d, ",i,arry[i]);
    if(p(i)>=1) printf("parent key = %d, ",arry[w=p(i)]);
    if(l(i)<=T) printf("left key = %d, ",arry[e=l(i)]);
    if(r(i)<=T) printf("right key = %d, ",arry[o=r(i)]);
    printf("\n");
  }

  return 0;
}
                  



Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int min = Integer.MAX_VALUE;
        boolean check = false;
        int[] cost = new int[n];
        int[] time = new int[n];

        for (int i = 0; i < n; i++) {
            cost[i] = sc.nextInt();
            time[i] = sc.nextInt();
            if (cost[i] < min && time[i] <= t) {
                min = cost[i];
                check = true;
            }
        }
        if (check) {
            System.out.println(min);
        } else {
            System.out.println("TLE");
        }
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define MOD 1000000007
#define INF 1000000000000000000
#define SPA << " " << 
using namespace std;
 
int main(){
	int n, k, sum = 0;
	int a[500];
	int b[500];
	int sum1[500];
	int sum2[500];
	priority_queue<int> pq;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 1; i*i <= sum; i++){
		if(!(sum%i)){
			pq.push(i);
			if(i*i != sum){
				pq.push(sum/i);
			}
		}
	}
	while (!(pq.empty())){
		int x = pq.top();
		pq.pop();
		for (int j = 0; j < n; j++){
			b[j] = a[j] % x;
		}
		sort (b, b + n);
		sum1[0] = b[0];
		sum2[n-1] = x - b[n-1];
		for (int j = 1; j < n; j++){
			sum1[j] = sum1[j-1] + b[j];
		}
		for (int j = n-2; j >= 0; j--){
			sum2[j] = sum2[j+1] + x - b[j];
		}
		for (int l = 0; l < n - 1; l++){
			if (sum1[l] == sum2[l+1]){
				if (sum1[l] <= k){
					cout << x << endl;
					return 0;
				}
			}
		}
	}
	cout << 1 << endl;
	return 0;
}


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

int main() {
  int h,a;
  int c = 0;
  cin >> h >> a;
  while (true) {
	h -= a;
    c++;
    if (h <= 0) {
      cout << c;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

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

using namespace std;
typedef long long ll;

ll hp;

int main() {
    ll nummonsters = 1;
    ll ans = 0;
    cin >> hp;
    while (hp >= 1) {
        ans += nummonsters;
        nummonsters *= 2;
        hp = hp / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t  = sc.nextLine().split(" ");
		int n       = Integer.parseInt(t[0]);
		int m       = Integer.parseInt(t[1]);
		int a;
		String b;
		boolean[] x = new boolean[n];
		Arrays.fill(x, false);
		Map<Integer, Integer> map = new HashMap<>();

		for(int i = 0; i < m; i++) {

			a = sc.nextInt() - 1;
			b = sc.next();
			if(!x[a]) {
				if(b.equals("WA")) {
					if(map.containsKey(a)) {
						map.put(a, map.get(a) + 1);
					}else {
						map.put(a, 1);
					}
				}else {
					x[a] = true;
				}
			}
		}
		int c = 0;
		int d = 0;

		for(boolean q : x) {
			if(q)c++;
		}
		for(Entry<Integer, Integer> w : map.entrySet()) {
			if(x[w.getKey()]) {
				d += w.getValue();
			}
		}

		System.out.println(c + " " + d);
	}
}

Measured memory_bytes: 64088
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    vector<int> f {a,b,c,d,e};
    int min = 99999;
    do {
        int sum = 0;
        for(int i = 0; i < f.size(); i++){
            sum += f[i];
            if(i != f.size()-1 && sum%10 != 0) sum += 10 - sum%10;
        }
        min = std::min(min, sum);
    }while(next_permutation(f.begin(), f.end()));
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;
int N;

int main() {

  int A, B, C;
  int ret=0;

  cin >> N;

  if (N%10 == 7 || N/10%10 == 7 || N/100%10 == 7)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int n,i;
  long k;
  P u[100010];
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> u[i].first >> u[i].second;
  sort(u,u+n);
  i=0;
  while (k>0){
    k-=u[i].second;
    i++;
  }
  cout << u[i-1].first << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
char s[N],a[N],c[10];
int n,l,r,q,opt,flag=1,f;
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    l=2e5;r=l+n-1;
    for(int i=1;i<=n;i++)a[i+l-1]=s[i];
    scanf("%d",&q);
    flag=1;
    while(q--){
        scanf("%d",&opt);
        if(opt==1)flag=-flag;
        else{
            cin>>f>>c;
            if(f==1&&flag==1)a[--l]=c[0];
            if(f==1&&flag==-1)a[++r]=c[0];
            if(f==2&&flag==1)a[++r]=c[0];
            if(f==2&&flag==-1)a[--l]=c[0];
        }
    }
    if(flag==1){
        for(int i=l;i<=r;i++)cout<<a[i];
    }
    else for(int i=r;i>=l;i--)cout<<a[i];
}



Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
char s[105],t[105];
int main()
{
	scanf("%s%s",s+1,t+1);
	int l=strlen(s+1);
	int i=1;
	for (int j=1;j<=l;j++)
		if (s[i]==t[j])
		{
			int a=i+1,b=j+1;
			if (a>l) a-=l;
			if (b>l) b-=l;
			while (s[a]==t[b])
			{
				a++,b++;
				if (a>l) a-=l;
				if (b>l) b-=l;
				if (a==i)
				{
					printf("Yes\n");
					return 0;
				}
			}
		}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b , m = 0;
    string s;
    cin >> a >> b >> s;
    for( int i = 0 ; i < a + b + 1; i ++ ) {
        if( i == a && s[i] != '-' ) m = 1; 
        else if( i != a && s[i] != '0' && s[i] != '1' && s[i] != '2' && s[i] != '3' && s[i] != '4' && s[i] != '5' && s[i] != '6' && s[i] != '7' && s[i] != '8' &&  s[i] != '9' ) m = 1;
    }
    if( m == 1 ) cout << "No";
    else cout << "Yes";
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
const ll M=1e5+6;
ll dp[M],a[M],k;
ll rec(ll index)
{
	if(index<=2)
		return dp[index];
	if(dp[index]!=-1)
		return dp[index];

	else
	{
		ll mn=1e16;
		
		for(ll i=1;i<=k;i++)
		{
			if(index-i>=1)
			{
				mn=min(mn,abs(a[index]-a[index-i])+rec(index-i));
			}
		}
		
		dp[index]=mn;
		return dp[index];
	}
}
int main()
{
	ll n,i,j,x,y,t,m;
	cin >> n >> k;
	for(i=1;i<=n;i++)
		cin >> a[i],dp[i]=-1;
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	cout << rec(n) << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

struct UnionFind {
    vector<int> p, s;
    UnionFind(size_t n) : p(n, -1), s(n, 1) {}
    int root(int u) { 
        while (p[u] != -1) u = p[u];
        return u;
    }
    bool same(int i, int j) {
        return root(i) == root(j);
    }
    void unite(int u, int v) {
        u = root(u); v = root(v);
        if (u != v) {
            if (s[u] < s[v]) swap(u, v);
            p[v] = u;
            s[u] += s[v];
        }
    }
    int size(int i) {
        return s[root(i)];
    }
};
void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n + 1);
    vector<int> adj(n + 1);
    set<pair<int, int>> adj_set;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
        adj[a]++;
        adj[b]++;
        adj_set.insert(make_pair(a, b));
        adj_set.insert(make_pair(b, a));
    }
    vector<int> blk(n + 1);
    for (int i = 0; i < k; ++i) {
        int c, d;
        cin >> c >> d;
        if (uf.same(c, d) && adj_set.count(make_pair(c, d)) == 0) {
            blk[c]++;
            blk[d]++;
        }
    }
    for (int i = 1; i <= n; ++i) {
        int ans = uf.size(i) - adj[i] - blk[i] - 1;
        cout << ans << ' ';
    }
    cout << '\n';
}

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

Measured memory_bytes: 11776
#include <stdio.h>
#define N 100
#define A 0
#define B 0
#define C 0
#define INF 1000000

int n,hi[N][N];

void ShortestPath();

int main(){
  int i,j,st,a,q,t;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      hi[i][j]=INF;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&st,&t);

    for(j=0;j<t;j++){
      scanf("%d%d",&a,&q);
      hi[st][a]=q;
    }
  }

  ShortestPath();

  return 0;
}
    
void ShortestPath(){
  int i,k,st,min;
  int de[N],judge[N];

  for(i=0;i<n;i++){
    de[i]=INF;
    judge[i]=0;
  }

  de[0]=0;
  judge[0]=1;

  while(1){
    min=INF;
    st=-1;
    for(i=0;i<n;i++){
      if(min > de[i] && judge[i]!=2){
	st=i;
	min=de[i];
      }
    }
    if(st==-1) break;
    judge[st]=2;

    for(k=0;k<n;k++){
      if(judge[k] !=2 && hi[st][k] !=INF){
	if(hi[st][k]+de[st] < de[k]){
	  de[k]=de[st]+hi[st][k];
	  judge[k]=1;
	}
      }
    }
  }
    
  for(i=0;i<n;i++){
    printf("%d ",i);
    printf("%d\n",de[i]);
  }
}



Measured memory_bytes: 2112
#include<iostream>
#include <string>
#include <vector>
using namespace std;
using uint = unsigned int;

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	
	vector<uint> A(Q);
	for(uint i=0; i<Q; i++) {
		cin >> A[i];
	}
	
	vector<int> P(N);
	
	for(uint i=0; i<Q; i++) {
		uint p = A[i] - 1;
		P[p]++;
	}
	
	for(uint h=0; h<N; h++) {
		if (K + P[h] - Q > 0) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var HMHMK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var hour = (HMHMK[2] - HMHMK[0]) * 60;
            var min = HMHMK[3] - HMHMK[1];
            var sum = hour + min;
            var K = HMHMK[4];
            if (sum >= K)
            {
                Console.WriteLine(sum - K);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

    }
}

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

long long dp[402][402], pref[402], a[402];
long long solve(int i, int j){
    //cout<<i<<", "<<j<<"\n";
    if(i>=j) return 0;
    //if(i+1==j) return a[i]  +a[j];
    if(dp[i][j]!=-1) return dp[i][j];
    int k;
    long long ans = 1e18;
    for(k=i+1; k<=j;k++) 
        ans  = min(ans, pref[k-1] - pref[i-1] + pref[j] - pref[k-1] + solve(i, k-1) + solve(k, j));
    //cout<<i<<", "<<j<<": "<<ans<<"\n";
    return dp[i][j] = ans;
}
int main() {
	int n;
	cin>>n;
	int i;
	for(i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j] = -1;
	for(i=1;i<=n;i++)
	    cin>>a[i], pref[i] = pref[i-1] + a[i];
	 cout<<solve(1, n);
	return 0;
}

Measured memory_bytes: 1536
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        n:usize,
        a:[usize;n]
    }
    let mut even = 0_usize;
    let mut odd = 0;
    for i in a {
        if i % 2 == 0 {
            even += 1;
        } else {
            odd += 1;
        }
    }

    if even + odd == 1 {
        println!("YES");
        return;
    }

    if odd % 2 != 0 {
        println!("NO");
        return;
    }
    println!("YES");
}


Measured memory_bytes: 3712
A=int(input()) #500
B=int(input()) #100
C=int(input()) #50
X=int(input())
cnt=0
for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0, C+1):
            if 500*i+100*j+50*k==X:
                cnt+=1
            else:
                continue
print(cnt)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            int[] hw = ReadAndParseIntArr();
            int h = hw[0];
            int w = hw[1];
            char[,] a = new char[h, w];
            for (int i = 0; i < h; i++)
            {
                string sz = Console.ReadLine();
                bool white = true;
                for (int j = 0; j < w; ++j)
                {
                    if (sz[j] == '#')
                    {
                        white = false;
                        break;
                    }
                }
                if (white)
                {
                    for (int j = 0; j < w; ++j)
                    {
                        a[i, j] = '*';
                    }
                }
                else
                {
                    for (int j = 0; j < w; ++j)
                    {
                        a[i, j] = sz[j];
                    }
                }
            }
            // 縦の圧縮済み
            for (int j = 0; j < w; ++j)
            {
                bool white = true;
                for (int i = 0; i < h; ++i)
                {
                    if (a[i,j] == '#') { white = false; break; }
                }
                if (white)
                {
                    for (int i = 0; i < h; ++i)
                    {
                        a[i,j] = '*';
                    }
                }
            }

            for (int i = 0; i < h; ++i)
            {
                string sz = "";
                for (int j = 0;j<w;++j)
                {
                    if(a[i,j] != '*')
                    {
                        sz += a[i, j];
                    }
                }
                if (sz != "")
                {
                    Console.WriteLine(sz);
                }
            }
        }
    }
}

Measured memory_bytes: 13140