akhauriyash/Code-Regression huggingface dataset:
#22
N,x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()

if sum(a) ==x:
    print(N)
elif sum(a) < x:
    print(N-1)
else:
    for i in range(N):
        if sum(a[0:i+1]) >x:
            print(i)
            break
    

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

#define Need_For_Speed ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(NULL);

#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define sz size()
#define fi first
#define se second

#define batr ONLINE_JUDGE
#define all(x) (x).begin(),(x).end()
#define skip continue

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 17, maxN = 4 * N, darr = 1e3 + 17, mod = 1e9 + 7;

ll a, b, c, k;

int main () {
	Need_For_Speed;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a - b;
	}
	else {
		cout << b - a;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

struct ToUpper {
	char operator()(char c) { return toupper(c); }
};

int num[20][20];

int main() {
	memset(num, 0, sizeof(num));
	string st;
	while (getline(cin, st)) {
		int x = st[0] - '0';
		int y = st[2] - '0';
		x += 5;
		y += 5;
		int size = st[4] - '0';

		for (int i = 0; i < 20; ++i) {
			for (int j = 0; j < 20; ++j) {
				if (size == 1) {
					int lim = 2;
					int sa = abs(i - y) + abs(j - x);
					if (sa < lim)num[i][j]++;
				}
				else if (size == 3) {
					int lim = 3;
					int sa = abs(i - y) + abs(j - x);
					if (sa < lim)num[i][j]++;
				}
				else {
					if (abs(i - y) <= 1 && abs(j - x) <= 1)num[i][j]++;
				}
				
			}
		}
	}
	int a = 0;
	int b = 0;
	for (int i = 5; i < 15; ++i) {
		for (int j = 5; j < 15; ++j) {
			if (!num[i][j])a++;
			b = max(b, num[i][j]);
		}
	}
	cout << a <<endl<< b << endl;
	return 0;
} 

Measured memory_bytes: 3152
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int n, k, d[9];

bool c(int a){
	int i = 10000;
	rep(l, 5){
		if(i>a) {i/=10; continue;}
		rep(j, k) if((a/i)%10 == d[j]) return false;
		i/=10;
	}
	return true;
}

int main(void){
	cin >> n >> k;
	rep(i, k) cin >> d[i];
	
	while(1){
		if(c(n)) break;
		else n++;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int high[10]={0}, ans[3]={0,-1,-2};
	int i,l;
	
	for(i=0; i<10; i++)
		scanf("%d",&high[i]);
	
	ans[0]=high[0];
	if(ans[0]<high[1]){
	ans[1]=ans[0];
	ans[0]=high[1];
	}else{
	ans[1]=high[1];
	}
	for(i=2; i<10; i++){
		if(ans[2]<high[i]){
			if(ans[1]<high[i]){
				if(ans[0]<high[i]){
				ans[2]=ans[1];
				ans[1]=ans[0];
				ans[0]=high[i];
				continue;
				}
				ans[2]=ans[1];
				ans[1]=high[i];
				continue;
			}
				ans[2]=high[i];
		}
	}
	for(i=0; i<3; i++)
		printf("%d\n",ans[i]);

	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t a,b,n; cin>>a>>b>>n;
	int64_t x=min(b-1,n);
	cout<<floorf64x((long double)a*x/b)-a*floorf64x((long double)x/b)<<"\n"s;
}

Measured memory_bytes: 3796
N,A,B = map(int,input().split())
ans = 0
for i in range(N+1):
    n = i
    sum = 0
    while n > 0:
        sum += n % 10
        n = int(n/10)
    if(A<=sum<=B):
        #print(sum,i)
        ans += i
print(ans)


Measured memory_bytes: 9056
#include<iostream>
#include<vector>
#define ull long long

using namespace std;

int main(){
    int K, tmp;
    ull tmpl, tmpu;
    ull max=2LL, min=2LL;
    cin >> K;
    vector< ull > vect(K);

    for(int i=0; i<K ; i++){
        cin >> vect[i];
    }
    if(vect[K-1] != 2LL){
        cout << "-1" << endl;
    }else{

        for(int i=K-1; i>=0 ; i--){
            tmpl = min/vect[i];
            tmpu = max/vect[i];
            if(tmpl*vect[i] != min && ((tmpl + 1)*vect[i] > max || (tmpl +1) * vect[i] < min )){
                cout << -1 << endl;
                break;
            }
            if(tmpl*vect[i] != min){
                min = (tmpl + 1)*vect[i];
            }
            max = tmpu*vect[i] + vect[i] - 1;
            if( i == 0 ){
                cout << min << " " << max << endl;
            }
        }
    }

    return 0;

}


Measured memory_bytes: 1024
#include<stdio.h>
 
int main(void){
   char tmp[20]={"\0"};
   scanf("%s",tmp);
   if(tmp[0]=='S')
     puts("Cloudy");
   if(tmp[0]=='C')
       puts("Rainy");
   if(tmp[0]=='R')
       puts("Sunny");
  return 0;
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int H,W;
int SRC,DST;
const int MAX_H = 100;
char S [MAX_H] [MAX_H + 1];
const int MAX_N = 10000;
struct edge{
	int to,cap,rev;
};
vector<edge> G [MAX_N * 2 + 2];
bool vis [MAX_N * 2 + 2];
const int INF = 1e9;

void add_edge(int u,int v,int cap)
{
	G [u].push_back(edge{v,cap,int(G [v].size())});
	G [v].push_back(edge{u,0,int(G [u].size()) - 1});
}

int dfs(int curr,int f)
{
	if(curr == DST) return f;
	vis [curr] = true;
	for(auto& it : G [curr]) if(vis [it.to] == false && it.cap > 0){
		int d = dfs(it.to,min(f,it.cap));
		if(d == 0) continue;
		it.cap -= d;
		G [it.to] [it.rev].cap += d;
		return d;
	}
	return 0;
}

int max_flow()
{
	int res = 0,f;
	do{
		memset(vis,0,sizeof(vis));
		f = dfs(SRC,INF);
		res += f;
		if(res >= INF) return -1;
	}while(f > 0);

	return res;
}

int main()
{
	scanf("%d%d",&H,&W);
	FOR(i,0,H){
		scanf("%s",S [i]);
	}

	SRC = MAX_N * 2;
	DST = MAX_N * 2 + 1;
	FOR(i,0,H) FOR(j,0,W){
		if(S [i] [j] == 'S'){
			add_edge(SRC,i * W + j,INF);
			add_edge(SRC,i * W + j + MAX_N,INF);
		}
		if(S [i] [j] == 'T'){
			add_edge(i * W + j,DST,INF);
			add_edge(i * W + j + MAX_N,DST,INF);
		}
		if(S [i] [j] != '.'){
			add_edge(i * W + j,i * W + j + MAX_N,1);
			add_edge(i * W + j + MAX_N,i * W + j,1);
		}
	}
	FOR(i,0,H){
		FOR(j,0,W) FOR(k,0,W) if(j != k && S [i] [j] != '.' && S [i] [k] != '.'){
			add_edge(i * W + j,i * W + k,INF);
		}
	}
	FOR(i,0,W){
		FOR(j,0,H) FOR(k,0,H) if(j != k && S [j] [i] != '.' && S [k] [i] != '.'){
			add_edge(j * W + i + MAX_N,k * W + i + MAX_N,INF);
		}
	}

	printf("%d\n",max_flow());

	return 0;
}


Measured memory_bytes: 61824
using System;

class Program {
    static void Main(string[] args){
        int N = int.Parse(Console.ReadLine());
        long[] A = new long[N+1];
        A[N] = 0;
        for(int i=0;i<N;i++){
            A[i] = long.Parse(Console.ReadLine());
        }
        long ans = 0;
        for(int i=0;i<N;i++){
            ans += A[i]/2;
            if(A[i]%2==1 && A[i+1]>0){
                ans++;
                A[i+1]--;
            }
        }
        Console.WriteLine(ans);
        
    }
}

Measured memory_bytes: 7512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int N;
int a[200000],b[200000],B[200000];
int ans = 0;

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

    cin >> N;
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];

    REP(i,29)
    {
        int t = 1 << i;
        REP(k,N) B[k] = b[k] % (2 * t);

        sort(B, B + N);
        ll int sum = 0;

        REP(k,N)
        {
            ll int fixed_a = a[k] % (2 * t);

            int T_01 = lower_bound(B, B + N, t - fixed_a) - B;
            int T_12 = lower_bound(B, B + N, 2 * t - fixed_a) - B;
            int T_23 = lower_bound(B, B + N, 3 * t - fixed_a) - B;
            
            sum += (T_12 - T_01) + (N - T_23);
        }

        if(sum % 2 == 1) ans += t;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
int main()
{
	int n,m,s;
	scanf("%d%d%d",&n,&m,&s);
	if(abs(m-s)%2==0)
	{
		printf("Alice\n");
	}
	else
	{
		printf("Borys\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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 rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
int main(){
    string s;
    std::cin >> s;

    std::vector<string> v;
    int n=s.size();
    int p=0;
    rep(i,n-1){
        if(s[i]=='>'&&s[i+1]=='<'){
            v.pb(s.substr(p,i-p+1));
            p=i+1;
        }
    }
    v.pb(s.substr(p,n-p));
    ll ans=0;
    rep(i,v.size()){
        int m=v[i].size();
        int t=0;
        rep(j,m-1){
            if(v[i][j]=='<'&&v[i][j+1]=='<')t++;
            else if(v[i][j]=='>'&&v[i][j+1]=='>')t=m-j-1;
            else t=max(t+1,m-j-1);
            ans+=t;
   //         std::cout << t << ' ';
        }
 //       std::cout  << std::endl;
        
    }
    string dd=v[v.size()-1];
    if(dd[dd.size()-1]=='<')ans+=dd.size();
    dd=v[0];
    if(dd[0]=='>')ans+=dd.size();
  //  erep(i,v)std::cout << i << std::endl;
    std::cout << ans << std::endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  reverse(ALL(s));
  rep(i, n) {
    if(s[i] == 'r') {
      if(i+5 < n && s.substr(i, 6) == "resare") {
        i+=5;
        continue;
      }
      
      if(i+6 < n && s.substr(i, 7) == "remaerd") {
        i += 6;
        continue;
      }

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

    if(s[i] == 'e') {
      if(i+4 < n && s.substr(i, 5) == "esare") {
        i += 4;
        continue;
      }

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

    if(s[i] == 'm') {
      if(i+4 < n && s.substr(i, 5) == "maerd") {
        i += 4;
        continue;
      }

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

  cout << "YES" << endl;
}

Measured memory_bytes: 3748
/*
Author: Srinjoy
Language: C++ 17
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define fileinput(s) freopen(s,"r",stdin)
#define MINUS(a) memset(a,0xff,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }
 
template<class T>
istream& operator >> (istream& in, pair<T, T> & v){ in >> v.fi >> v.se;return in; }

void printArr(vector<int> arr){
	cout<<"\n------------------------------------\n";

	for(int i=0;i<arr.size();i++) cout<<arr[i]<<" ";
	
	cout<<"\n------------------------------------\n";
}

int dp[1001][100][2]; 
int K;

int solve(int pos, int cnt, int tight, vector<int> num) { 
	
	if (pos == num.size()) { 
		if (cnt <= K) 
			return 1; 
		return 0; 
	} 

	
	if (dp[pos][cnt][tight] != -1) 
		return dp[pos][cnt][tight]; 

	int ans = 0; 

	int limit = (tight ? 9 : num[pos]); 

	for (int dig = 0; dig <= limit; dig++) { 
		int currCnt = cnt; 

		if (dig != 0) 
			currCnt++; 

		int currTight = tight; 

		
		if (dig < num[pos]) 
			currTight = 1; 

		ans += solve(pos + 1, currCnt, currTight, num); 
	}

	return dp[pos][cnt][tight] = ans;

}

int calc(string s1){
	vector<int> nums;
	for(char c:s1){
		nums.push_back( (int)(c - '0') );
	}
	//printArr(nums);

	memset(dp, -1, sizeof(dp)); 
	return solve(0,0,0,nums);
} 


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

	vector<int> nums;

	string start = "0";

	K=k;
	int p1 = calc(n) - calc(start);
	
	K=k-1;
	int p2 = calc(n) - calc(start);

	cout<< abs(p2-p1)<<endl;


	
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N;
	cin >> N;
	while (1) {
		vector<pair<int, string>>ps;
		for (int i = 0; i < N; ++i) {
			string st; int a, b, c; cin >> st >> a >> b >> c;
			int score = a * 3 + c;
			ps.emplace_back(score*100-i+99, st);
		}
		sort(ps.begin(), ps.end(),greater<pair<int,string>>());
		for (auto p : ps) {
			cout << p.second << "," << p.first/100 << endl;
		}
		cin >> N;
		if (!N)break;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
while True:
    m,f,r=list(map(int,input().split()))
    if m==f==r==-1: break
    s=m+f
    print('F' if m*f<0 or s<30 else 'D' if 30<=s<50 and r<50 else 'C' if 50<=s<65 or 30<=s<50 and 50<=r else 'B' if 65<=s<80 else 'A')

Measured memory_bytes: 7720
using System;
using System.Linq;

namespace ConsoleApp1
{
    struct Burger
    {
        public long Bun { get; }
        public long Patty { get; }

        public long TotalCount => Bun + Patty;

        public Burger(long bun, long patty)
        {
            Bun = bun;
            Patty = patty;
        }

        public static Burger operator +(Burger left, Burger right)
            => new Burger(left.Bun + right.Bun, left.Patty + right.Patty);
    }

    class Program
    {
        const int MaxN = 55;
        static Burger?[] burgers = new Burger?[MaxN];

        static Burger GetBurger(int level)
        {
            if (level == 0)
                return new Burger(0, 1);
            if (burgers[level] != null)
                return burgers[level].GetValueOrDefault();

            return (burgers[level] = new Burger(1, 0)
                                     + GetBurger(level - 1)
                                     + new Burger(0, 1)
                                     + GetBurger(level - 1)
                                     + new Burger(1, 0)).GetValueOrDefault();
        }

        static long Solve(int level, long count)
        {
            if (level == 0)
            {
                return count;
            }

            long result = 0;
            long remain = count;
            Burger lowerBurger = GetBurger(level - 1);

            remain -= 1;   // bun
            if (remain <= 0)
                return result;

            if (lowerBurger.TotalCount <= remain)
            {
                result += lowerBurger.Patty;
            }
            else
            {
                result += Solve(level - 1, remain);
            }

            remain -= lowerBurger.TotalCount;
            if (remain <= 0)
                return result;

            remain -= 1;    // putty
            result += 1;    // 

            if (remain <= 0)
                return result;

            if (lowerBurger.TotalCount <= remain)
            {
                result += lowerBurger.Patty;
            }
            else
            {
                result += Solve(level - 1, remain);
            }

            return result;
        }

        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split();
            int n = int.Parse(array[0]);
            long x = long.Parse(array[1]);
            Console.WriteLine(Solve(n, x));
        }

        static void ReadInt2(out int first, out int second)
        {
            var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            first = array[0];
            second = array[1];
        }
    }
}

Measured memory_bytes: 13268
H,W=map(int,input().split())
A=[input() for i in range(H)]
mod=10**9+7
dp=[[0]*W for i in range(H)]
dp[0][0]=1
for i in range(H):
    for j in range(W):
        if i+1<H and A[i+1][j]=='.':
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod
        if j+1<W and A[i][j+1]=='.':
            dp[i][j+1]+=dp[i][j]
            dp[i][j+1]%=mod
print(dp[H-1][W-1])

Measured memory_bytes: 53360
from functools import reduce
from itertools import combinations
from math import gcd


def func(A):
    n = len(A) - len(set(A))
    if n > 0 and n+1 != A.count(1):
        return False
    is_A = [False] * (10**6+1)
    for a in A:
        is_A[a] = True
    n = 0
    for i in range(2, 10**6+1, 2):
        if is_A[i]:
            n += 1
    if n > 1:
        return False
    for i in range(3, 10**6+1, 2):
        n = 0
        for j in range(i, 10**6+1, i):
            if is_A[j]:
                n += 1
        if n > 1:
            return False
    return True


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    if func(A):
        # if not all(gcd(i, j)==1 for i, j in combinations(A, 2)):
        #     raise NameError
        print('pairwise coprime')
    elif reduce(gcd, A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')
    

if __name__ == '__main__':
    solve()

Measured memory_bytes: 239612
N=int(input())
lasta=0
headb=0
spec=0
cnt=0
for _ in range(N):
    s=str(input())
    cnt+=s.count("AB")
    if s[0]=="B" and s[-1]=="A":
        spec+=1
    elif s[-1]=="A":
        lasta+=1
    elif s[0]=="B":
        headb+=1
        
if abs(headb-lasta)>=spec:
    print(min(headb,lasta)+spec+cnt)   
elif lasta==0 and headb==0 and spec>0:
    print(spec-1+cnt)
elif lasta==0 and headb==0 and spec==0:
    print(cnt)
else:
    print(spec-abs(headb-lasta)+max(headb,lasta)+cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans;
signed main()
{
    cin>>n>>k;
    if(k&1)
    {
    	int num=n/k;
    	cout<<num*num*num;
    	return 0;
    }
    int num=n/k;
    int num2=n/k+(n%k>=(k>>1));
    cout<<num*num*num+num2*num2*num2;

}

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

int main(void){
    char *s = (char*)malloc(100001 * sizeof(char));
    scanf("%s", s);
    int l = strlen(s);
    int dict['z' + 1] = {0};
    int i;
    for(i=0; i<l; i++) {
        dict[s[i]] = 1;
    }

    for(i='a'; i<='z'; i++) {
        if(dict[i] == 0) {
            printf("%c\n", (char)i);
            free(s);
            return 0;
        }
    }
    printf("None\n");


    free(s);
    return 0;
}


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

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);

    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;

    if(K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }

    return 0;
}

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

int main() {
  int n; cin >> n;
  loop(i,0,n) cout << "ACL";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3604
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 10^^9 + 7;

void main() {
    int n;
    scan(n);

    auto a = new int[](n);
    auto b = new int[](n);
    auto c = new int[](n);

    foreach (i ; 0 .. n) {
        scan(a[i], b[i], c[i]);
    }

    auto dp = new int[][](n + 1, 4);
    fillAll(dp, -inf);
    dp[0][0] = 0;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. 4) {
            if (j != 1) {
                dp[i+1][1] = max(dp[i+1][1], dp[i][j] + a[i]);
            }
            if (j != 2) {
                dp[i+1][2] = max(dp[i+1][2], dp[i][j] + b[i]);
            }
            if (j != 3) {
                dp[i+1][3] = max(dp[i+1][3], dp[i][j] + c[i]);
            }
        }
    }

    int ans = max(dp[n][1], dp[n][2], dp[n][3]);

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main(){
	int n;
	int x;
	cin >> n;
	x = n*100/108;
	bool posssible = true;
	bool stop = false;
	while(posssible && !stop){
		int price = x;
		price *= 108;
		price /= 100;
		if(price==n){
			stop = true;
			x--;
		}else if(price>n){
			posssible = false;
		}
		x++;
	}
	if (posssible){
		printf("%d\n", x);
	}else{
		printf(":(\n");
	}

}

Measured memory_bytes: 256
import sys,bisect
input = sys.stdin.readline
def main():
    x,y,z,k = map(int,input().split())
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))
    c = tuple(map(int,input().split()))
    
    ab = []
    for e in a:
        for w in b:
            ab.append(e+w)
    ab.sort()
    
    ok = -1
    ng = 10**11
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        cnt = 0
        for e in c:
            cnt += len(ab)-bisect.bisect_left(ab,mid-e)
        if cnt >= k:
            ok = mid
        else:
            ng = mid
    
    res = []
    for e in c:
        ind = bisect.bisect_left(ab,ok-e)
        for i in range(ind,len(ab)):
            res.append(e+ab[i])
    res.sort()
    for i in range(1,k+1):
        print(res[-i])
if __name__ == '__main__':
    main()


Measured memory_bytes: 522960
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

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

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
	k_007();
	int n;
	cin >> n;
	int a[n];
	int sum = 0;
	f(i, n)
	{
		cin >> a[i];
		sum += a[i];
	}

	int mean = sum / n;
	int ans1 = 0, ans2 = 0;
	f(i, n)
	{
		ans1 += (abs(mean - a[i])) * (abs(mean - a[i]));
		ans2 += (abs(mean + 1 - a[i])) * (abs(mean + 1 - a[i]));

	}

	cout << min(ans1, ans2) << endl;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 3696
import java.util.*;
import java.io.*;
import java.math.BigInteger;

 
public class Main implements Runnable {
  static Scanner in;
  // static FastReader in;
  static PrintWriter out;
  static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
  static int[][] dirs = {{0, -1}, {1, 0}, {0, +1}, {-1, 0}};
 
  static int[][] E;
  // static List<int[]>[] adj;
  static List<Integer>[] adj;
  static int[] vis;
 
  static long INFL = (long) 1e15 + 7;
  static int INF = (int) 1e7 + 9;
 
  static int T, n, m, k, count;
  static boolean flag;
  static int[] a, b;
  static int[][] map;

  static int mod = 998244353;
 
  static void solve() throws Exception {
    long n = in.nextLong();
    if (n % 2 == 1 || n < 10) {out.println(0); return;}

    long res = 0;
    long cur = 10;

    while (n >= cur) {
      // System.out.println(cur);
      res += (n / cur);
      cur *= 5;
    }

    out.println(res);

  }


  public static void main(String[] args) throws Exception {
 
    in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    // in = new FastReader();
    out = new PrintWriter(System.out);
 
    // int T = in.nextInt();
    // for (int tt = 1; tt <= T; tt++) {
    //   // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    //   // t.start();
    //   // t.join();
    //   solve();
    // }
 
    // // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    // // t.start();
    // // t.join();
    solve();
 
    out.flush();
    out.close();
  }
 
  @Override
  public void run() {
    try {
      solve();
    } catch (Exception e) {
      e.printStackTrace(); 
    }
  }
 
  static class FastReader {
    public BufferedReader br; 
    StringTokenizer st; 
    public FastReader() {br = new BufferedReader(new InputStreamReader(System.in));} 
    String next() { 
      while (st == null || !st.hasMoreElements()) { 
          try {st = new StringTokenizer(br.readLine());} 
          catch (IOException e) {e.printStackTrace();} 
      } 
      return st.nextToken(); 
    } 
    int nextInt() {return Integer.parseInt(next());} 
    long nextLong() {return Long.parseLong(next());} 
    double nextDouble() {return Double.parseDouble(next());} 
    String nextLine() {
      String str = ""; 
        try {str = br.readLine();} 
        catch (IOException e) {e.printStackTrace();} 
        return str; 
    }
  }

  static void as(boolean result) throws Exception {
    if (!result) {
      throw new Exception();
    }
  }

  static int modInverse(int a, int m) { 
    int m0 = m; 
    int y = 0, x = 1; 
    if (m == 1) {return 0;} 
    while (a > 1) { 
      // q is quotient 
      int q = a / m; 
      int t = m; 
      // m is remainder now, process 
      // same as Euclid's algo 
      m = a % m; 
      a = t; 
      t = y; 
      // Update x and y 
      y = x - q * y; 
      x = t; 
    } 
    // Make x positive 
    if (x < 0) 
      x += m0; 
    return x; 
  } 
} 

Measured memory_bytes: 21716
N=int(input())
s=list(input())
S=[0]*N
for i in range(N):
  S[i]=int(s[i])
ct=0
for i in range(10):
  if not i in S:
    continue
  T=S[S.index(i)+1:]
  for j in range(10):
    if not j in T:
      continue
    U=T[T.index(j)+1:]
    for k in range(10):
      if k in U:
        ct+=1
print(ct)

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = min(n, m/2);
    if(m/2 > n)
    {
        ans += ((m/2) - n)/2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int ans = 0;
		char[] alp = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		for(int i = 1; i < n; i++) {
			String x = s.substring(0, i);
			String y = s.substring(i, n);
			int cout = 0;
			for(int j = 0; j < 26; j ++) {
				if(y.contains(String.valueOf(alp[j])) && x.contains(String.valueOf(alp[j]))) cout++;
			}
			ans = Math.max(ans, cout);
		}
		System.out.println(ans);
	}
}


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


int main(){
    int x,y;
    cin >> x >> y;
    if(y%2 == 0 && x*4 >= y && x*2 <= y)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll compare_asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll compare_desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}
/*void qsort(配列のアドレス,配列のサイズ,sizeof(配列の型),比較関数(昇順or降順)) */

int main(){
    ll a,b,x;
    scanf("%lld %lld %lld",&x,&a,&b);

    ll day=b-a;
    if(a>=b)printf("delicious\n");
    else if(day<=x)printf("safe\n");
    else printf("dangerous\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    cin >> x >> y;
    cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}




Measured memory_bytes: 256
def main():
    from sys import stdin
    input=stdin.readline
    
    import numpy as np
    import scipy.sparse.csgraph as sp

    n, m, l = map(int, input().split())
    abc = [list(map(int, input().split())) for _ in [0]*m]
    q = int(input())
    st = [list(map(int, input().split())) for _ in [0]*q]
    inf = 10**12
    dist = np.full((n, n), inf, dtype=np.int64)
    for i in range(n):
        dist[i][i] = 0
    for a, b, c in abc:
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c
    dist = sp.shortest_path(dist)

    inf = 10**3
    dist2 = np.full((n, n), inf, dtype=np.int16)
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    dist2 = sp.shortest_path(dist2)

    for i in range(n):
        for j in range(n):
            if dist2[i][j] == inf:
                dist2[i][j] = -1
            else:
                dist2[i][j] -= 1
    for s, t in st:
        print(int(dist2[s-1][t-1]))


main()


Measured memory_bytes: 44072
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int n, a[100000],i;

	scanf("%d", &n);

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

	for (n; 0 < n; n--){
		if (n == 1){
			printf("%d", a[n - 1]);
		}
		else{
			printf("%d ", a[n - 1]);
		}
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 1036
n = int(input())

D = [] * n

for i in range(n):
    D.append(list(map(int, input().split())))

ans = 'No'

for i in range(0, n-2):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 62492
#include<iostream>
#include<cmath>
using namespace std;
long long n,p,maxn=0,k,t;

int Judge(long long x,long long y){
	long long num=0;
	while(y%x==0){
		num++;
		y=y/x;
		if(num>=n) break;
	}
	return num;
}
int main(){
	
	cin>>n>>p;
	
	if(n==1) cout<<p<<endl;
	else if(n>=40) cout<<"1"<<endl;
	else{
		for(long long i=2;;i++){
			k=pow(i,n);
			if(k>=p){
				t=i; break;
			}
		}
		//cout<<t<<endl;
		for(long long i=2;i<=t;i++){
			long long x=Judge(i,p);
			if(x>=n) maxn=i;	
		}
		if(maxn==0) cout<<"1"<<endl;
		else cout<<maxn<<endl;
	}
	return 0;	
} 

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> l(n + 1);
  l[0] = 2;
  l[1] = 1;
  for (int i = 2; i <= n; i++) {
    l[i] = l[i - 1] + l[i - 2];
  }
  cout << l[n] << '\n';
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N;
    cin >> N;
    cout << N / 2 + N % 2 << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 100000;

int N;
vi ans(MAX_N+1, 0);

void calc(int n) {
  int B = n;
  while (B < N) {
    for (int i = 1; i+B <= N; i++) {
      ans[i+B] = min(ans[i+B], ans[i]+1);
    }
    B *= n;
  }
}

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    ans[i] = i;

    int c = i;
    while (c % 6 == 0) c /= 6;
    if (c == 1) ans[i] = 1;
    c = i;
    while (c % 9 == 0) c /= 9;
    if (c == 1) ans[i] = 1;
  }
  calc(6);
  calc(9);
  cout << ans[N] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
	int n, i, j, num;
	char mark, markList[4] = { 'S','H','C','D' };
	bool card[4][13];
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			card[i][j] = true;
		}
	}
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> mark >> num;
		switch (mark) {
		case 'S':
			card[0][num - 1] = false;
			break;
		case 'H':
			card[1][num - 1] = false;
			break;
		case 'C':
			card[2][num - 1] = false;
			break;
		case 'D':
			card[3][num - 1] = false;
			break;
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (card[i][j]) {
				cout << markList[i] << ' ' << j + 1 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int ans=1e9+10;
	for(int i=-100;i<=100;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			cnt+=abs(a[j]-i)*abs(a[j]-i);
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

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

int map[21][21];

int main()
{
	int N, M;
	while (cin >> N, N)
	{
		memset(map, 0, sizeof(map));
		for (int i=0; i<N; i++)
		{
			int x, y;
			cin >> x >> y;
			map[y][x] = 1;
		}

		cin >> M;
		int px=10, py=10;
		while (M--)
		{
			char c;
			int n;
			cin >> c >> n;
			for (int i=1; i<=n; i++)
			{
				switch(c)
				{
					case 'N':
						py++;
						break;
					case 'E':
						px++;
						break;
					case 'S':
						py--;
						break;
					case 'W':
						px--;
						break;
				}
				map[py][px] = 0;
			}
		}

		bool f=1;
		for (int y=0; y<=20; y++)
		for (int x=0; x<=20; x++)
			if (map[y][x])
			{
				f=0; break;
			}

		cout << (f ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<n;i++){
        int j = n - i;
        if(i==j)continue;
        ans ++ ;
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 123321;
char S[MAX];
int nextL[MAX], nextR[MAX], goal[MAX], ans[MAX];

int main(){

    // 1. 入力情報取得.
    scanf("%s", S);
    int l = strlen(S);
    
    // 2. 各初期位置について, 以下の情報を保存(0-index).
    // 2-1. 初期位置に, 'R' が記載されていたとして, 次に, 'L' が 始めて出現するケース.
    int posL = -1;
    for(int i = l - 1; i >= 0; i--){
        if(S[i] == 'L') posL = i;
        nextL[i] = posL;
    }
    
    // 2-2. 初期位置に, 'L' が記載されていたとして, 次に, 'R' が 始めて出現するケース.
    int posR = -1;
    for(int i = 0; i < l; i++){
        if(S[i] == 'R') posR = i;
        nextR[i] = posR;
    }
    
    // 3. 各マスについて, 1グーゴル回後の位置を計算.
    // 初期位置が, 'R' or 'L' で 分岐.
    for(int i = 0; i < l; i++){
        if(S[i] == 'R'){
            int dist = nextL[i] - i;
            if(dist % 2 == 0) goal[i] = nextL[i];
            else              goal[i] = nextL[i] - 1;
        }
        if(S[i] == 'L'){
            int dist = i - nextR[i];
            if(dist % 2 == 0) goal[i] = nextR[i];
            else              goal[i] = nextR[i] + 1;
        }
    }
    
    // 4. 移動後の位置情報が, goalに保存されているので集計.
    for(int i = 0; i < l; i++) ans[goal[i]]++;
    
    // 5. 出力 ～ 後処理.
    for(int i = 0; i < l; i++) printf("%d ", ans[i]);
    return 0;

}

Measured memory_bytes: 2176
import heapq

q = int(input())
ans = []
mini = 0
left, right = [], []
cnt = 0
mid = None
for _ in range(q):
    qi = input()
    if qi == '2':
        if cnt%2 == 0:
            ans.append([-left[0], mini])
        else:
            ans.append([mid, mini])
    else:
        kind, a, b = map(int, qi.split())
        if cnt%2 == 1:
            mini += abs(mid-a) + b
            heapq.heappush(left, -min(mid, a))
            heapq.heappush(right, max(mid, a))
            mid = None
        else:
            if cnt == 0:
                mid = a
                mini = b
                cnt += 1
                continue
            l = -heapq.heappop(left)
            r = heapq.heappop(right)
            if a <= l:
                mini += l-a + b
                heapq.heappush(left, -a)
                heapq.heappush(right, r)
                mid = l
            elif a <= r:
                mini += b
                heapq.heappush(left, -l)
                heapq.heappush(right, r)
                mid = a
            else:
                mini += a-r + b
                heapq.heappush(left, -l)
                heapq.heappush(right, a)
                mid = r
        cnt += 1

for i, j in ans:
    print(i, j)

Measured memory_bytes: 100252
#include <stdio.h>
#include <string.h>
#define STMAX 50
int main(void)
{
  int i, slen, tlen, spos, tpos, sflag = 0;
  char str[STMAX+1], ttr[STMAX+1];
  scanf("%s%*c", str);
  scanf("%s%*c", ttr);
  slen = strlen(str);
  tlen = strlen(ttr);
  spos = slen - 1;
  tpos = tlen - 1;
  while (spos >= tlen - 1) {
    tpos = tlen - 1;
    while (tpos >= 0 && (str[spos+tpos-tlen+1] == ttr[tpos] || str[spos+tpos-tlen+1] == '?')) tpos--;
    if (tpos == -1) {
      sflag = 1;
      break;
    }
    spos--;
  }
  if (sflag) {
    for (i = spos; i > spos - tlen; i--) str[i] = ttr[i-spos+tlen-1];
    for (i = 0; i < slen; i++) {
      if (str[i] == '?') str[i] = 'a';
    }
    printf("%s\n", str);
  } else printf("UNRESTORABLE\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxn 5010
#define inf 1000000000
using namespace std;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n;
int v[maxn],f[maxn],g[maxn],h[maxn];
struct edge
{
    int to,nxt;
}e[maxn];
int head[maxn],edge_cnt;
void add(int from,int to)
{
    e[++edge_cnt]={to,head[from]},head[from]=edge_cnt;
}
void dfs(int x)
{
    for(int i=head[x];i;i=e[i].nxt) dfs(e[i].to);
    for(int i=1;i<=v[x];++i) g[i]=inf;
    g[0]=0;
    for(int i=head[x];i;i=e[i].nxt)
    {
        int y=e[i].to;
        for(int j=0;j<=v[x];++j)
        {
            h[j]=inf;
            if(j-v[y]>=0) h[j]=min(h[j],g[j-v[y]]+f[y]);
            if(j-f[y]>=0) h[j]=min(h[j],g[j-f[y]]+v[y]);
        }
        for(int j=0;j<=v[x];++j) g[j]=h[j];
    }
    for(int i=0;i<=v[x];++i) f[x]=min(f[x],g[i]);
}
int main()
{
    read(n);
    for(int i=2,p;i<=n;++i) read(p),add(p,i);
    for(int i=1;i<=n;++i) read(v[i]),f[i]=inf;
    dfs(1),puts(f[1]!=inf?"POSSIBLE":"IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}

void solve() { 
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < n; ++i) {
		cout << s[i] << t[i];
	}    
}


Measured memory_bytes: 256
#include<iostream>


int main() {
	int m, d;
	std::cin >> m >> d;
	int ans = 0;
	for (int i = 2; i <= 9; i++) {
		for (int j = 2; j <= 9 && i * 10 + j <= d; j++) {
			if (i * j <= m) {
				ans++;
			}
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A___The_Number_of_Even_Pairs
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = a[0];
            int m = a[1];
            int answer;

            if (n == 0)
            {
                n = 1;
            }

            if (m == 0)
            {
                m = 1;
            }

            answer = n * (n - 1) / 2 + m * (m - 1) / 2;

            Console.WriteLine(answer);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140