akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>


int main(void){
    int n;
    char suit[36];
    int number[36];
    char suitc[36];
    int numberc[36];
    int i, j;
    int itmp;
    char ctmp;
    int flag;
    int minij;


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

    for (i = 0; i < n; i++){
        suitc[i] = suit[i];
        numberc[i] = number[i];
    }

    for (j = 0; j < n - 1; j++){
        flag = 0;
        for (i = n - 2; i >= j; i--){
            if(number[i] > number[i+1]){
                itmp = number[i];
                number[i] = number[i+1];
                number[i+1] = itmp;
                ctmp = suit[i];
                suit[i] = suit[i+1];
                suit[i+1] = ctmp;
                flag = 1;
            }
        }
        if (flag == 0){
            break;
        }
    }
    for (i = 0; i < n - 1; i++){
        printf("%c%d ", suit[i], number[i]);
    }

    printf("%c%d", suit[n-1], number[n-1]);

    printf("\nStable\n");

    for (i = 0; i < n; i++){
        minij = i;
        for (j = i; j < n; j++){
            if (numberc[minij] > numberc[j]){
                minij = j;
            }
        }
        itmp = numberc[minij];
        ctmp = suitc[minij];
        numberc[minij] = numberc[i];
        suitc[minij] = suitc[i];
        numberc[i] = itmp;
        suitc[i] = ctmp;
    }

    for (i = 0; i < n - 1; i++){
        printf("%c%d ", suitc[i], numberc[i]);
    }

    printf("%c%d", suitc[n-1], numberc[n-1]);

    flag = 0;

    for (i = 0; i < n; i++){
        if (number[i] != numberc[i] || suit[i] != suitc[i]){
            flag = 1;        
        }
    }

    if (flag){
        printf("\nNot stable\n");
    }else{
        printf("\nStable\n");
    }

    return 0;
}

Measured memory_bytes: 1848
N = int(input())
A = list(map(int, input().split()))
B = []

for item in A:
    if item%2==0:
        B.append(item)
cnt = 0
ans = ''
for item in B:
    if item%3!=0:
        if item%5!=0:
            ans = 'DENIED'
if ans!='DENIED':
    ans = 'APPROVED'
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
                    
                    
using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/*int main() 
{
    double  D, T, S;
    cin >> D >> T >> S; 
    if (T >= D/S) cout << "Yes" << endl;
    else cout << "No" << endl;
}*/

int main() 
{
    int N, X, T;
    cin >> N >> X >> T;
    int ans = 0, sum = 0;
    while (N > sum)
    {
        ans += T;
        sum += X;
    // cout << ans << endl;
    }
    cout << ans << endl;
    
    
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  int len = S.length();
  int ans, max = 0;
  for(int i=0; i<len; i++){
    if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C'){
      ans = 1;
      for(int j=i+1; j<len; j++){
        if(S[j] == 'A' || S[j] == 'T' || S[j] == 'G' || S[j] == 'C'){
          ans++;
        }else break;
      }
      if(ans > max) max = ans;
    }
    ans = 0;
  } 
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 888
S = input()
A = {}
flag = 0
for i in S:
    if i in A:
        A[i] += 1
    else:
        A[i] = 1
for i in A:
    if A[i] == 2:
        continue
    else:
        flag=1
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
s = int(input())
front = s//100
back = s%100
if (front > 12 or front < 1) and (back > 12 or back < 1):
    print('NA')
elif front > 12 or front < 1:
    print('YYMM')
elif back > 12 or back < 1:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int d;
  cin >> d;
  if (d == 25){
    cout << "Christmas\n";
  }
  if (d == 24){
    cout << "Christmas Eve\n";
  }
  if (d == 23){
    cout << "Christmas Eve Eve\n";
  }
  if (d == 22){
    cout << "Christmas Eve Eve Eve\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);
    	String s = sc.next();

    	Map<Character, Integer> map = new HashMap<>();
    	for (int i = 0; i < 4; i++) {
    		char c = s.charAt(i);
    		if (map.containsKey(c)) {
    			int n = map.get(c);
    			n++;
    			map.put(c, n);
    		} else {
    			map.put(c, 1);
    		}
    	}
    	char c = s.charAt(0);
    	if (map.size() == 2 && map.get(c) == 2) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
   	}
}


Measured memory_bytes: 23124
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

int W, H, mas[111][111] = {0}, ans = 0;
int dy[] = {-1, 0, 1, -1, 0, 1}, dx[][6] = { {-1, -1, -1, 0, 1, 0}, 
                                             {0, -1, 0, 1, 1, 1} };
vector <vector<bool> > used;
vector <iP> pt;

void bfs(){

  queue <iP> que;
  que.push(iP(1, 0));
  while(!que.empty()){
    iP now = que.front(); que.pop();
    if(!used[now.sc][now.fr]) continue;
    for(int i = 0; i < 6; i++){
      int nx = now.fr + dx[now.sc%2][i], ny = now.sc + dy[i];
      if(0 <= nx && nx <= W+1 && 0 <= ny && ny <= H+1 && mas[ny][nx] == 0){
        que.push(iP(nx, ny));
        used[now.sc][now.fr] = false;
      }
      else if(0 <= nx && nx <= W && 0 <= ny && ny <= H && mas[ny][nx]){
        ans++;
      }
    }
  }
}

int main(){
  
  cin >> W >> H;
  used = vector<vector<bool> >(H + 2, vector<bool>(W + 2, true));
  for(int i = 1; i <= H; i++)
    for(int j = 1; j <= W; j++)
      cin >> mas[i][j];
  
  bfs();
  cout << ans << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> vec(N,0);
    for(int i=0;i<N;++i){
        cin>>vec[i];
    }
    int ans=INT_MAX,temp;
    for(int i=-100;i<=100;++i){
        temp=0;
        for(int j=0;j<N;++j){
            temp+=(vec[j]-i)*(vec[j]-i);
        }
        ans=min(ans,temp);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+10;
const int E = 50;
int n, cnt[E][2], kk[E];
ll k, a[N], f[E][2];

inline void chkMax(ll &x, ll y){if (x < y) x = y;}

int main()
{
	scanf("%d%lld", &n, &k);
	for (int i = E-1; i >= 0; -- i)
		kk[i] = (k>>i)&1;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= n; ++ i){
		ll a;
		scanf("%lld", &a);
		for (int j = 0; j < E; ++ j)
			++ cnt[j][(a>>j)&1];
	}
	memset(f, -1, sizeof(f));
	f[E-1][1] = 0;
	for (int i = E-2; i >= 0; -- i)
		for (int j = 0; j <= 2; ++ j){ // 1 : limited
			if (f[i+1][j] == -1) continue;
			for (int o = 0, ub = j ? kk[i] : 1; o <= ub; ++ o)
				chkMax(f[i][o == kk[i] && j], f[i+1][j] + cnt[i][o^1]*(1ll<<i));
		}
	printf("%lld", max(f[0][0], f[0][1]));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long long int h,sum=0,n, i, num[100000];
	scanf("%lld%lld", &h, &n);
	
	for(i = 1; i<=n; i++)
	{
		scanf("%lld", &num[i]);
		sum+=num[i];
	}
	if(sum>= h)
		printf("Yes\n");
	else 
		printf("No\n");
		
	return 0;
}

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

int main() {
    ll N, ans = 0;
    cin >> N;
    vi A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    ll now = 0;
    while (now != 1) {
        if (ans > N) {
            cout << -1 << endl;
            return 0;
        }
        now = A[now];
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

const int N = 101;
int ans[N * N * N];
void pre() {
   for(int i = 1; i < N; i++) {
      for(int j = 1; j < N; j++) {
         for(int k = 1; k < N; k++) {
            ans[i * i + j * j + k * k + i * j + j * k +  k * i]++;
         }
      }
   }
}
void solve() {
   int n;
   cin >> n;
   for(int i = 0; i < n; i++) {
      cout << ans[i + 1] << endl;
   }
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   pre();
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}

Measured memory_bytes: 3724
n = 0
x = 0
multiplier = 0
result = 0

def solve():
	global x
	global n
	global multiplier
	global result
	#print(x)
	if x>n:
		return
	if x>0:
		if str(3) in str(x) and str(5) in str(x) and str(7) in str(x):
			result+=1
	for i in range(3,8,2):
		x+=(i*(10**multiplier))
		multiplier+=1
		solve()
		multiplier-=1
		x-=(i*(10**multiplier))
	return

n = int(input())
solve()
print(result)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll a,b,k;
  cin>>a>>b>>k;
ll count=0;
  ll ans=1;
  for(ll i=100;i>0;i--){
  if(a%i==0&&b%i==0){
    count++;
    if(count==k)
      ans=i;
  }}
  cout<<ans;
  return 0;
 
}
 

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )

template < typename T >
inline T read( )
{
	register T x = 0;
	register char ch = gc( );
	register bool f = 0;
	while( !std::isdigit( ch ) )
	{
		f = ( ch == '-' );
		ch = gc( );
	}
	while( std::isdigit( ch ) )
	{
		x = x * 10 + ( ch - '0' );
		ch = gc( );
	}
	return f ? -x : x;
}

template < typename T >
void print( T x )
{
	if( x < 0 )
	{
		x = -x;
		pc( '-' );
	}
	if( x < 10 )
	{
		pc( x + 48 );
		return;
	}
	print < T > ( x / 10 );
	pc( x % 10 + 48 );
	return ;
}

namespace Solution
{
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( ' ' )
#define ptl( i ) print < long long > ( i ), putchar( ' ' )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
	const int Maxn = 204001;
	std::map < std::string, int > mp;
	int cnt[ 4 ], n;
	void fakemain( )
	{
		mp[ "WA" ] = 1;
		mp[ "AC" ] = 0;
		mp[ "TLE" ] = 2;
		mp[ "RE" ] = 3;
		std::cin >> n;
		std::string str;
		For( i, 1, n )
		{
			std::cin >> str;
			cnt[ mp[ str ] ]++;
		}
		std::cout << "AC x " << cnt[ 0 ] << std::endl; 
		std::cout << "WA x " << cnt[ 1 ] << std::endl; 
		std::cout << "TLE x " << cnt[ 2 ] << std::endl;
		std::cout << "RE x " << cnt[ 3 ] << std::endl; 
		return;
	}

} // namespace Solution

int main( int argc, char* argv[] )
{
	Solution::fakemain( );
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
	int h1, m1, h2, m2, k;
	int ans;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	ans = h2 * 60 + m2 - h1 * 60 - m1 - k;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

ll labs(ll a)
{
    if (a >= 0) return a;
    else return -a;
}

ll f(ll X, ll K, ll D)
{
    if (X / D > K)
    {
        return X - D * K;
    }
    
    K -= X / D;
    X = X % D;
    if (K % 2 == 0)
        return X;
    else
        return D - X;
}

int main()
{
    ll X, K, D;
    io >> X >> K >> D;

    ll ans = f(labs(X), K, D);
    io << ans << BR;
}

Measured memory_bytes: 3804
//Takahashi Calendar
#include<iostream>
using namespace std;
int main() {
	int m, d;
	cin >> m >> d;
	if (d < 22) {
		cout << "0" << endl;
		}
	else {
		int a[d - 21], count = 0;
		for (int i = 22; i <= d; i++) {
			a [i - 22] = ((i % 10) > 1 ? (i % 10) : 0) * ((i / 10) > 1 ? (i / 10) : 0);
		}

		for (int i = 1; i <= m; i++) {
			for (int j = 0; j <= d - 22; j++) {
				if (a[j] == i) {
					count += 1;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
# 01010...
pata = 0
# 10101...
patb = 0
for i, c in enumerate(s):
    val = i%2
    if val == 0:
        if c == "0":
            patb += 1
        if c == "1":
            pata += 1
    if val == 1:
        if c == "1":
            patb += 1
        if c == "0":
            pata += 1

print(min(pata, patb))

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

const int mod=1000000007,MAX=200005,INF=1<<30;
#define all(x) (x).begin(),(x).end()


int main(){
    
    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(all(A));
    reverse(all(A));//昇順にして
    
    ll ans=0;
    
    for(int i=1;i<N;i++) ans+=A[i/2];//一番大きい数を1回
 									//それ以降大きい順に2回足す
  									//理屈は分かったけどすごい実装だ
  									//出来上がった円形じゃなくて着いた順にカウントされるのが肝なんだな
  									//割り込み利益が大きいところにどんどん入れていくから最小値だけ除いた数よりずいぶん大きくなるんだな
    
    cout<<ans<<endl;
}


Measured memory_bytes: 4840
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    bool is7 = false;
    while (n > 0) {
        if (n % 10 == 7) is7 = true;
        n /= 10;
    }
    if (is7) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>

int main(){
   int r,d,i;
   long x;
    
   scanf("%d %d %ld",&r,&d,&x);
   for (i=0;i<10;i++) {
      x=r*x-d;
      printf("%ld\n",x);
   }
   return 0;
}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

// 4近傍
// int dy[]={0, 1, 0, -1};
// int dx[]={1, 0, -1, 0};

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

ll gcd(ll x,ll y){
    if(x == 0) return y;
    return gcd(y%x,x);
}

void solve(){
    int h,w;
    cin >> h >> w;
    string s;
    for(int i = 0; i < h; i++){
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}

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

    solve();

    return 0;
}


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(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==1){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }else{
        cout<<(a+b)/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
#define int          long long
const int INF = 0x3F3F3F3F3F3F3F3F;
const int MOD = 1e9+7;
ld EPS = 1e-12;

const int N = 105, T = 1e5 + 5;
int n, W, w[N], v[N], dp[N][T];

int REC(int id, int rm)
{
    if( id>=n )
        return 0;
    if( dp[id][rm]!=-1 )
        return dp[id][rm];
    int ans = 0;
    if( rm>=w[id] )
        ans = max( ans, REC( id+1, rm-w[id] ) + v[id] );
    ans = max( ans, REC( id+1, rm ) );
    dp[id][rm] = ans;
    return ans;
}

signed main()
{
    VR46 // DONT USE DEQUE IF NOT NECESSARY
    // int t;cin>>t;rep(test,1,t)
    {
        cin >> n >> W;
        rep(i,0,n-1)
            cin >> w[i] >> v[i];
        mem( dp, -1 );
        cout << REC( 0, W ) << endl;
    }
}

Measured memory_bytes: 82304
#include<stdio.h>
#include<string.h>
#include<math.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 63-A

int main(void)
{
	int w, i;
	char S[1000];
	scanf("%s", S);
	scanf("%d", &w);
	for (i = 0; i < strlen(S); i = i + w)
	{
		printf("%c", S[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int k,a,b,w=0,i;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
           w=1;
        }
    }
    if(w==1)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");
    }
}


Measured memory_bytes: 1628
# A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, b, r = map(int, input().split())
total = b+r
circle = n//total
diff = n % total
if b <= diff:
    print(b + circle*b)
else:
    print(diff + circle*b)


Measured memory_bytes: 2940
n,m=map(int,input().split())
a=list(map(int,input().split()))
arr=[]
for i in a:
	arr.append([i,1])
for i in range(m):
	x,y=map(int,input().split())
	arr.append([y,x])
arr=sorted(arr,key=lambda item:item[0],reverse=True)
ans=0
for i in range(len(arr)):
	if arr[i][1]>n:
		ans+=(arr[i][0]*n)
		break
	else:
		ans+=(arr[i][0]*arr[i][1])
		n-=arr[i][1]
print(ans)

Measured memory_bytes: 39340
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

string s;

int main()
{
    cin >> s;
    if (s[2]==s[3]&&s[4]==s[5])cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var a = Console.ReadLine().Trim();
        var b = Console.ReadLine().Trim();
        Console.WriteLine(a[0] == b[2] && a[1] == b[1] && a[2] == b[0] ? "YES" : "NO");
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[1000];
int main()
{
	scanf("%s",a+1);
	int n = strlen(a+1);
	ll k;cin>>k;
	bool ok = 1;
	for(int i=1;i<n;i++)
		if(a[i]!=a[i+1])ok = 0;
	if(ok){
		long long ans = n;
		ans *= k;
		cout << ans/2 << endl;
		return 0;
	}
	int l = 1,r = n;
	ll ans  = 0;
	if(a[1]==a[n]){
		while(a[l+1]==a[n])l++;
		while(a[r-1]==a[n])r--;
//		cout<<"!"<<l<<" "<<r<<endl;
//		cout<<"->"<<a[l]<<" "<<a[r]<<endl;
		int a = l,b = n-r+1,len = a+b;
//		cout<<"!"<<a<<" "<<b<<endl;
		ans += 1LL*(k-1)*(len/2);
		ans += a/2;
		ans += b/2;
		l++;r--;
	}
//	cout<<"!!!!!!"<<ans<<endl;
//	cout<<"!"<<l<<" "<<r<<endl;
	for(int i=l;i<=r;){
		int j = i;
		while(j+1<=r&&a[j+1]==a[i])j++;
//		cout<<"->"<<i<<" "<<j<<" "<<l<<" "<<r<<endl;
		ll len = (j-i+1);
//		if(len/2)cout<<len/2<<endl;
		ans += (len/2)*k;
		i = j+1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int a, b;
    string op;
    cin >> a >> op >> b;
    int result;
    while(op != "?"){
        if (op == "+"){
            result = a + b;
        }
        else if (op == "-"){
            result = a - b;
        }
        else if (op == "*"){
            result = a * b;
        }
        else if (op == "/"){
            result = a / b;
        }
        cout << result << endl;
        cin >> a >> op >> b;
    }
}


Measured memory_bytes: 3144
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int main(){
  int x,a,b;
  scanf("%d %d %d",&x,&a,&b);
  x -= a;
  printf("%d\n",x%b);
}


Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let A = read::<usize>();
    let B = read::<usize>();
    let C = read::<usize>();

    let diff = A - B;
    if diff > C {
        println!("{}", 0);
    }
    else {
        println!("{}", C-diff);
    }
}



Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int a=0,b=0,c=0,n, m, k = 0;
	char str[5];
	char x, y;
	scanf("%c %c", &x,&y);
	a=(long long int)x;
    b=(long long int)y;
	if (a < b) { printf("<"); }
	if (a == b) { printf("="); }
	if (a > b) { printf(">"); }
	
}

Measured memory_bytes: 128
# W , H, x, y and r
W, H, x, y, r = map(int, input().split())

min_x = x - r
max_x = x + r
min_y = y - r
max_y = y + r

if (min_x >= 0 and min_y >= 0) and (max_x <= W and max_y <= H):
    print('Yes')
else:
    print('No')




Measured memory_bytes: 5596
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var n = long.Parse(Console.ReadLine());
    var sqrt = (int)Ceiling(Sqrt(n));
    long min = long.MaxValue;
    for (int i = 1; i <= sqrt; i++) {
      if (n % i == 0) min = Min(min, i + n / i - 2);
    }
    Console.WriteLine(min);
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b == 15) {
    cout << '+' << endl;
  } else if (a * b == 15) {
    cout << '*' << endl;
  } else {
    cout << 'x' << endl;
  }
  return 0;
}

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

#define SQR(x) ((x)*(x))

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


int main() {
    //freopen("hi.txt","r",stdin);
    int n,p;
    scanf("%d%d",&n,&p);
    int odd=0,even=0;
    int a;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        if(a%2){
            odd++;
        }
        else{
            even++;
        }
    }
    if(odd==0 && p%2==0){
        printf("%lld\n",1LL<<even);
        return 0;
    }
    ll ans=0;
    ans+=1LL<<(odd-1);
    ans<<=even;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		if((A*B)%2==0)System.out.println("Even");
		else System.out.println("Odd");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	int n=s.size();
	int m=t.size();
	bool ans=false;
	for(int i=n-m;i>=0;--i){
		bool flg=true;
		for(int j=0;j<m;++j){
			if(s.at(i+j)==t.at(j) || s.at(i+j)=='?') continue;
			else{
				flg=false;
				break;
			}
		}
		if(flg){
			rep(j,m){
				s.at(i+j)=t.at(j);
			}
			ans=true;
			break;
		}
	}
	rep(i,n) if(s.at(i)=='?') s.at(i)='a';
	if(ans) cout << s << endl;
	else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
n=int(input())
k=list(input())

kk=0
for i in range(1000):
  if i<10:
    p=['0','0',str(i)]
  elif i<100:
    p=['0',str(i)[0],str(i)[1]]
  else:
    p=list(str(i))
    
  flag=0
  for w in k:
    if w==p[flag]:
      flag+=1
    if flag==3:
      break
  
  if flag==3:
    #print(i)
    kk+=1
  else:pass

print(kk)

Measured memory_bytes: 42732
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

ll floor_sum(ll n, ll m, ll a, ll b) {
    
    ll ans = 0;
    if(a >= m) {
        ans += (n-1) * n * (a/m) / 2;
        a %= m;
    }
    if(b >= m) {
        ans += n * (b/m);
        b %= m;
    }

    ll y_max = (a*n + b) / m, x_max = (y_max*m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);

    return ans;
}

int main() {
    ll t;
    cin >> t;

    rep(i, t) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        out(floor_sum(n, m, a, b));
    }

    re0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <utility>
#include <queue>
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;
static const int INF=1000000000;

int N,M;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
queue<pair<int, int> > Q;

char map[1000][1000];
int dis[1000][1000] = {INF};
int main(){
	cin >> N >> M;

	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			cin >> map[i][j];
			if (map[i][j] == '#'){
				Q.push(make_pair(i,j));
				dis[i][j] = 0;
			}
		}
	}
	int tx,ty, ans=0;
	while(!Q.empty()){
		pair<int, int> p = Q.front();Q.pop();
		for (int i=0;i<4;i++){
			tx = p.first + dx[i];
			ty = p.second + dy[i];
			if(0 <= tx && tx <= N-1 && 0 <= ty && ty <= M-1 && map[tx][ty] == '.'){
				map[tx][ty] = '#';
				dis[tx][ty] = dis[p.first][p.second] + 1;
				ans = max(ans, dis[tx][ty]);
				Q.push(make_pair(tx,ty));
			}
		}
	}
	// for(int i=0;i<N;i++){
	// 	for(int j=0;j<M;j++){
	// 		cout << map[i][j];
	// 		}
	// 		cout << endl;
	// 	}
	cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define SYAMU(a) memset(a,0,sizeof(a))
#define pb push_back
#define mp make_pair

vector<pair<int,int> > a; // score, num;
int used[810];

int main() {
    int x,y;
    while(scanf("%d,%d",&x,&y)) {
        if(x==0) break;
        a.pb(mp(y,x));
    }

    sort(a.rbegin(),a.rend());

    int q, n = a.size();
    while(cin>>q) {
        int rank = 0;
        SYAMU(used);
        rep(i,n) {
            if(!used[a[i].first]) {
                used[a[i].first]++; rank++;
            }
            if(a[i].second == q) {
                cout << rank << endl;
            }
        }
    }


    return 0;
}

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

typedef long long ll;

int main(){
	int I, O, T, J, L, S, Z;
	scanf("%d%d%d%d%d%d%d", &I, &O, &T, &J, &L, &S, &Z);
	ll ans = O;
	if (!I || !J || !L){
		ans += I >> 1 << 1;
		ans += J >> 1 << 1;
		ans += L >> 1 << 1;
	}
	else{
		if (J % 2 != L % 2){
			ans += I;
			ans += J >> 1 << 1;
			ans += L >> 1 << 1;
		}
		else{
			if (J % 2 == 1){
				ans += I;
				ans += J;
				ans += L;
				if (I % 2 == 0) -- ans;
			}
			else{
				ans += I >> 1 << 1;
				ans += J;
				ans += L;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

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

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

    int result = 0;
    for (int p = 0; p < N; p++) {
        int cur = 0;
        for (int i = 0; i <= p; i++)
            cur += A[0][i];
        for (int i = p; i < N; i++)
            cur += A[1][i];
        result = max(result, cur);
    }   

    cout << result << "\n";

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] D = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); 
        
        Arrays.sort(D);
        
        System.out.println(D[N/2] - D[N/2-1]);

    }
}


Measured memory_bytes: 39304
#include<iostream>
using namespace std;
long double sum , ans;
long double c;
long long n, a[1005];
int main(){
	cin >> n;
	sum  = 0 ;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum += 1.0 / a[i];
	}
	ans = 1.0 / sum;
	cout << ans << endl;
}

Measured memory_bytes: 256
s=input()
l=len(s)
ans=0
for i in range(l):
  for j in range(1,l-i+1):
    t=s[i:i+j]
    for k in range(j):
      if t[k]=='A' or t[k]=='C' or t[k]=='G' or t[k]=='T':
        continue
      else:
        break
    else:
      ans=max(ans,j)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	cin>>a;
	int se[n],sw[n];
	for(int i=0;i<n;i++){
		se[i]=0;
		sw[i]=0;
	}
	if(a[0]=='E')
		se[0]=1;
	else
		sw[0]=1;
	for(int i=1;i<n;i++)
		if(a[i]=='E'){
			se[i]=se[i-1]+1;
			sw[i]=sw[i-1];
		}
		else{
			sw[i]=sw[i-1]+1;
			se[i]=se[i-1];
		}
	int minv=300001;
	for(int i=0;i<n;i++){
		int sum=0;
		if(i==0)
			sum=se[n-1]-se[0];
		else if(i==n-1)
			sum=sw[n-2];
		else
			sum=sw[i-1]+(se[n-1]-se[i]);
		minv=min(minv,sum);
	}
	cout<<minv<<endl;
}

Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int q = int.Parse(Console.ReadLine());
            int an;
            if (q % 2 == 0)
            {
                an = q;
            }
            else { an = q * 2; }
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

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

        Integer[] abc = new Integer[3];
        for(int i=0; i<3; i++) {
            abc[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        sc.close();

        Arrays.sort(abc, Collections.reverseOrder());

        int target = 0;
        for(int i=0; i<k; i++) {
            abc[0] *= 2;
        }
        System.out.println(abc[0] + abc[1] + abc[2]);
    }
}


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

int main() {
    cout<<setprecision(10)<<fixed;
    int n,k;
    cin>>n>>k;
    vector<double> p(n),q(n+1,0);

    rep(i,n){
      double P;
      cin>>P;
      p[i]=(P+1)/2;
    }
    rep(i,n){
      q[i+1] = q[i] + p[i];
    }

    double ans=0;

    rep(i,n-k+1){
      double now_ans=0;
      now_ans=q[i+k]-q[i];
      ans=max(ans,now_ans);
    }
    cout<<ans<<endl;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int[] memo = new int[6];

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                double input = double.Parse(Console.ReadLine());

                if (input < 165.0) memo[0]++;
                else if (input < 170.0) memo[1]++;
                else if (input < 175.0) memo[2]++;
                else if (input < 180.0) memo[3]++;
                else if (input < 185.0) memo[4]++;
                else memo[5]++;
            }

            for (int i = 0; i < 6; i++)
            {
                sb.Append(i + 1);
                sb.Append(':');

                for (int j = 0; j < memo[i]; j++)
                {
                    sb.Append('*');
                }
                sb.Append("\n");
            }
            Console.Write(sb);
        }
    }
}

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

int H,W;
char s[100][100];

int dist[100][100];
bool visited[100][100];
int white_cnt=0;

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

int ans=-1;

class Node{
public:
    int x,y;
    Node(int a, int b):x(a),y(b){}
};

void input(){
    cin>>H>>W;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            cin>>s[i][j];
            if(s[i][j]=='.') ++white_cnt;
        }
    }
}

void init(){
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            dist[i][j]=-1;
        }
    }
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            visited[i][j]=false;
        }
    }
}

void bfs(){
    init();
    queue<Node> que;
    Node S(0,0);
    visited[0][0]=true;
    dist[0][0]=0;
    que.push(S);
    while(!que.empty()){
        Node cur=que.front();
        que.pop();
        int cur_x=cur.x;
        int cur_y=cur.y;
        for(int i=0;i<4;++i){
            int next_x=cur_x+dx[i];
            int next_y=cur_y+dy[i];
            bool b=0<=next_x&&next_x<W&&0<=next_y&&next_y<H;
            if(s[next_y][next_x]=='#'||visited[next_y][next_x]||!b) continue;
            visited[next_y][next_x]=true;
            dist[next_y][next_x]=dist[cur_y][cur_x]+1;
            Node next(next_x,next_y);
            que.push(next);
        }
    }   
}

void output(){
    if(dist[H-1][W-1]==-1) cout<<-1<<endl;
    else cout<<white_cnt-dist[H-1][W-1]-1<<endl;
}

int main(){
    input();
    bfs();
    output();
}

Measured memory_bytes: 3600
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

c = Counter(A)

ans = 0
for key, val in c.items():
    if key == val:
        continue
    else:
        if val - key > 0:
            ans += min(val, val - key)
        else:
            ans += val

print(ans)


Measured memory_bytes: 18676
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int r,c,n;
struct point{
	int id,x,y;
}p[maxn];
int tot,top;
int s[maxn];
bool vis[maxn];
bool onedge(point x){return !x.x||!x.y||x.x==r||x.y==c;}
int calc(point x)
{
	if(x.y==0) return x.x;
    if(x.x==r) return r+x.y;
    if(x.y==c) return 2*r+c-x.x;
	if(x.x==0) return 2*r+2*c-x.y;
}
bool cmp(point x,point y){return calc(x)<calc(y);}
int main()
{
	r=read();c=read();n=read();
	for(int i=1;i<=n;i++)
	{
		point x1,x2;
		x1.id=x2.id=i;
		x1.x=read();x1.y=read();
		x2.x=read();x2.y=read();
		if(onedge(x1) && onedge(x2)) p[++tot]=x1,p[++tot]=x2;
	}
	sort(p+1,p+1+tot,cmp);
	for(int i=1;i<=tot;i++)
	{
		if(vis[p[i].id] && s[top]!=p[i].id) break;
		if(top && s[top]==p[i].id) top--;
		else s[++top]=p[i].id,vis[p[i].id]=1;
	}
	puts(top?"NO":"YES");
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <math.h>

void Kock(int, double, double, double, double);

int main(){

  int n;

  scanf("%d", &n);

  printf("%.8f %.8f\n", 0,0, 0,0);
  
  Kock(n, 0, 0, 100, 0);
 
  printf("%.8f %.8f\n", 100.0, 0.0);

  return 0;

}

void Kock(int n, double p1x, double p1y, double p2x, double p2y){
  
  double sx, sy, ux, uy, tx, ty;

  if(n == 0)
    return;

  sx = (2 * p1x + p2x) / 3;

  sy = (2 * p1y + p2y) / 3;

  tx = (p1x + 2 * p2x) / 3;

  ty = (p1y + 2 * p2y) / 3;

  ux = (tx - sx) * (1/(double)2) - (ty - sy) * (sqrt(3)/2) + sx;

  uy = (tx - sx) * (sqrt(3)/2) + (ty - sy) * (1/(double)2) + sy;
  

  Kock((n - 1), p1x, p1y, sx, sy);
  
  printf("%.8f %.8f\n", sx, sy);

  Kock((n - 1), sx, sy, ux, uy);

  printf("%.8f %.8f\n", ux, uy);

  Kock((n - 1), ux, uy, tx, ty);

  printf("%.8f %.8f\n", tx, ty);

  Kock((n - 1), tx, ty, p2x, p2y);
  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
bool dp[4001][16001];
int x,y,tx,ty,ax[4001],ay[4001];
 
void dfsx(int t,int n){
	if(dp[t][n+8000])return;
	if(t<tx){
		dfsx(t+1,n+ax[t]);
		dfsx(t+1,n-ax[t]);
	}
	dp[t][n+8000]=1;
}
 
void dfsy(int t,int n){
	if(dp[t][n+8000])return;
	if(t<ty){
		dfsy(t+1,n+ay[t]);
		dfsy(t+1,n-ay[t]);
	}
	dp[t][n+8000]=1;
}
 
int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s>>x>>y;
	bool fx=1;
	for(int i=0;i<s.length();++i){
		if(s[i]=='F'){
			if(fx)++ax[tx];
			else ++ay[ty];
		}else{
			if(fx)fx=0,++tx;
			else fx=1,++ty;
		}
	}
	if(s[s.length()-1]=='F'){
		if(fx)++tx;
		else ++ty;
	}
	dfsx(1,ax[0]);
	bool xx=dp[tx][8000+x]==1?1:0;
	memset(dp,0,sizeof(dp));
	dfsy(0,0);
	bool yy=dp[ty][8000+y]==1?1:0;
	if(xx&&yy)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 62976
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << endl;
  return 0;
}

Measured memory_bytes: 3624
s = input()
ans = 0
for i in range(2**(len(s)-1)):
    plus = [""]*(len(s))
    fomula = ""
    for j in range(len(s)-1):
        if(i >> j & 1):
            plus[j] = "+"
    for k in range(len(s)):
        fomula += s[k] + plus[k]
    ans += eval(fomula)
print(ans)

Measured memory_bytes: 8856
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
  int H[1000], W[1000];
  int i, j, num1=1, num2=1;
  H[0]=-1;
  W[0]=-1;
  while(H[num1-1] != 0 && W[num1-1] != 0){
    cin >>H[num1];
    cin >>W[num1];
    num1=num1+1;
  }

  while(H[num2] != 0 && W[num2] != 0){
      for(i=0;i<H[num2];i++){
        
        for(j=0;j<W[num2];j++){
          cout <<"#" ;
        }
        cout <<endl;
      }
      cout <<endl;
      num2++;
  }
}

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	String str= sc.nextLine();
	String str1=str.toUpperCase();
	if(str==str1)
	{
		System.out.println("A");
	}
	else
	{
		System.out.println("a");

	}
	
	
	
				
		
	}
}

Measured memory_bytes: 35724
#include<iostream>

using namespace std;

int main() {
	
	int w, h, x, y, r;
	
	while( cin >> w) {
		
		cin >> h >> x
			>> y >> r;
			
		if( x <0 || y < 0)	
		cout << "No\n";	
			
		else if( x + r > w || y + r > h)	
		cout << "No\n";
		
		else
		cout << "Yes\n";
	}
	
	return 0;
}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/arc097/tasks/arc097_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

string solve(){
    string res;
    string s; cin >> s;
    ll K; cin >> K;
    vector<string> str;
    for(int i = 0; i < s.length();i++){
        for(int j = 1; j <= K && i+j<=s.length();j++){
            str.push_back(s.substr(i,j));
        }
    }
    sort(str.begin(),str.end());
    str.erase(unique(str.begin(),str.end()),str.end());
    res = str[K-1];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1660