akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    string s;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    while(n != 0){
        if(n % 2 == 0){
            s = "0" + s;
            n /= -2;
        }else{
            s = "1" + s;
            n = (n - 1) / -2;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
using namespace std;

// cout << fixed << setprecision(12)

int main(){
  lint N;
  cin >> N;
  lint max = sqrt(N) / 1;
  
  
  lint ans = 0;
  
  for(lint i=2; i<=max; i++){
    lint tmp = 0;
    while(N%i==0){
      N /= i;
      tmp++;
    }
    for(lint j=1; tmp>=j; j++){
      tmp -= j;
      ans++;
    } 
  }
  if(N>1) ans++;
  
  cout << ans << endl;
}
 

Measured memory_bytes: 3704
S=[input(),input(),input()]
turn2num={'a':0,'b':1,'c':2}
turn='a'
ans=''
while True:
  if len(S[turn2num[turn]])==0:
    ans=turn
    break
  next_turn=S[turn2num[turn]][0]
  S[turn2num[turn]]=S[turn2num[turn]][1:]
  turn=next_turn
  
print(ans.upper())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string str, tr;
int dp[3009][3009];
bool b[3009][3009];
int main()
{
	cin >> str >> tr;
	for (int i = 1; i <= str.size(); i++)
	{
		for (int j = 1; j <= tr.size(); j++)
		{
			if (str[i - 1] == tr[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
				b[i][j] = 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int in = dp[str.size()][tr.size()] - 1;
	char ans[3009] = "";
	int r = str.size(), c = tr.size();
	while (r && c)
	{
		if (str[r - 1] == tr[c - 1])
		{
			ans[in] += str[r - 1];
			in--;
			r--, c--;
		}
		else if (dp[r-1][c]>dp[r][c-1])
		{
			r--;
		}
		else
		{
			c--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 44416
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans;
  if(s=="SUN")ans=7;
  else if(s=="MON")ans=6;
  else if(s=="TUE")ans=5;
  else if(s=="WED")ans=4;
  else if(s=="THU")ans=3;
  else if(s=="FRI")ans=2;
  else if(s=="SAT")ans=1;
  cout<<ans<<endl;
 return 0; 
}

Measured memory_bytes: 256
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll x,n;
	cin>>x>>n;
	bool f=0;
	vi v(105,0);
	ll y;
	rep(i,0,n) {
		cin>>y;
		v[y]=1;
	}
	rep(i,0,101) {
		if(!v[x-i]) {
			cout<<x-i<<endl;
			return;
		}
		if(!v[x+i]) {
			cout<<x+i<<endl;
			return;
		}
	}

	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 3796
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        char[] a = in.ns().toCharArray();
        char[] b = in.ns().toCharArray();
        char[] c = in.ns().toCharArray();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if(a[i]==b[i]){
                if(a[i]!=c[i]) ans++;
            }else{
                if(c[i]==a[i]) ans++;
                else{
                    if(c[i]==b[i]) ans++;
                    else ans += 2;
                }
            }
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21076
#include<stdio.h>
int n,a,b,s;
int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++){
        int t=(i/10)%10+i%10+(i/100)%10+(i/1000)%10+(i/10000)%10;
        if(a<=t&&t<=b) s+=i;
    }
    printf("%d\n",s);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;
int main(){
  int N;
  cin >>N;
  int K;
  cin >>K;
  vector<int>sun(N);
  rep(i,K){
  	int d;
    cin >>d;
    rep(j,d){
    	int a;
      	cin>> a;
      	sun[a-1]=1;
    }
  }
  int c=0;
  rep(i,N){
  	if(sun[i]!=1)c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String S = sc.next();
			String T = sc.next();
			int rightPrediction = 0;
			if (S.length() == T.length()) {
				for (int i = 0; i < S.length(); i++) {
					if (S.charAt(i) == T.charAt(i)) {
						rightPrediction++;
					}
				}
			}
			System.out.println(rightPrediction);
		}
	}
}


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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

int n, ans, a[4];
char s[100005];

inline bool find( int x ) 
{
	int cnt = 0;
	for( int i = 1; i <= 3; i++ )
		a[i] = 0;
	while(x)
		a[++cnt] = x % 10, x = x / 10;
	int j = 1;
	cnt = 3;
	for( int i = 2; i >= 0; i-- ) 
	{
		while(s[j] - '0' != a[cnt] && j <= n)
			j++;
		if(s[j] - '0' == a[cnt])
			--cnt;
		++j;
	}
	return cnt == 0;
}

int main()
{
	n = _;
	scanf("%s", s + 1);
	for( int j = 0; j <= 999; j++ ) 
		if(find(j)) 
			// cout << j << ln,
			++ans;
	cout << ans << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;

int n;

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

    cin >> n;

    cout << (n + 1) / 2 - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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


int main(){
    long long n,k;
    cin>>n>>k;
    vector<long long> h(n);
    rep(i,n)cin>>h[i];
    
    //昇順ソート
    //sort(h.begin(),h.end(),greater<int>());
    //降順ソート
    sort(h.begin(),h.end(),greater<int>());
    
    long long ans=0;
    for(int i=k;i<n;i++){
        ans+=h[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
n, y = map(int, input().split())
m, g, s = -1, -1, -1

for ng in range(n+1):
  for nm in range(n+1 - ng):
    ns = n - nm - ng
    if 10000*nm + 5000*ng + 1000*ns == y:
      m, g, s = nm, ng, ns
      
print(m, g, s)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

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

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    ll s, w;
    cin >> s >> w;

    if(s<=w){
        cout << "unsafe" << "\n"; 

    }else{
        cout << "safe" << "\n"; 
    }
    return 0;



}


Measured memory_bytes: 3648
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n;
int a[100000+100];
ll p(ll pp,ll qq)
{
	ll ss=1;
	for(int i=1;i<=qq;i++)
	{
		ss=ss*pp%mod;
	}
	return ss;
}
int main()
{
	int flag=0,x;
	memset(a,0,sizeof a);
	cin>>n;
	cin>>x;
	a[x]++;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++)
	{
		cin>>x;
		a[x]++;
	}
	if(a[0]>1) flag=1;
	int f=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==0&&f==0) f=1;
		if(a[i]!=0&&f==1)
		{
			flag=1;
			break;
		}
	}
	ll sum=1;
	if(flag)
	{
		printf("0\n");
	}
	else
	{
		for(int i=1;i<n-1;i++)
		{
			if(a[i]==0) break;
			sum=(sum*p(a[i],a[i+1]))%mod;
		}
		printf("%lld\n",sum%mod);
	}
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

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

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  int max_sum = 0;
  rep(i, k) {
      if (max({a,b,c}) == a) a *= 2;
      if (max({a,b,c}) == b) b *= 2;
      if (max({a,b,c}) == c) c *= 2;
  }
  max_sum += a + b + c;
  
  cout << max_sum << endl;
  return 0;
}

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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("input.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int r;
    cin >> r;
    int ans=(r*r);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ml m
#define mr m + 1
#define lson id << 1
#define rson id << 1 | 1
#define Error(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
const int maxm = 1e6 + 15;

int a[maxn];

int main() {
#ifdef NEKO
	freopen("C:\\Nya.txt", "r", stdin);
#endif
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == -1) continue;
		if(a[a[i]] == i) {
			ans++;
			a[a[i]] = -1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define N 300000

int x,y,n,a[N],c[N],head[N],tot,xb,ans;
struct edge{int v,nxt;}e[N];

void add(int x,int y){
	e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;
}

void dfs(int u,int fa){
	c[u]=a[++xb];
	for (int i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa) dfs(v,u);
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	for (int i=1;i<=n;++i) scanf("%d",a+i);
	sort(a+1,a+n+1,greater<int>());
	for (int i=2;i<=n;++i) ans+=a[i];
	dfs(1,0);
	printf("%d\n",ans);
	for (int i=1;i<=n;++i) printf(i==n?"%d\n":"%d ",c[i]);
	
	return 0;
}
			

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

using namespace std;

int main() {
    string S, found;
    cin >> S;
    int hi = 1;
    if ((S.size()%2)==1) cout <<"No";
    else {
        for (int i2 = 0; i2<S.size();){
            found = S.substr(i2,2);
            i2 +=2;
            if (found !="hi") {
                hi = -1;
                break;
            }
        }
        if(hi ==1)cout << "Yes";
        else cout << "No";
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,0,n) cin >> a[i];
  deque<int>d;
  rep(i,0,n){
    int p = lower_bound(d.begin(),d.end(),a[i])-d.begin();
    if(p == 0) d.push_front(a[i]);
    else d[p-1] = a[i];
  }
  cout << d.size() << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int N, i, j;
	scanf("%lld", &N);
	vector<int> s(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &s[i]);
	}
	int ans = 0;
	for(i = 1; i < N; i++){
		int now = 0;
		for(j = 1; i * j < N - 1 - i && i * j != N - 1 - i * j && i * (j - 1) != N - 1 - i * j; j++){
			now += s[i * j] + s[N - 1 - i * j];
//			printf("now(%lld, %lld) = %lld\n", i, j, now);
			ans = max(ans, now);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
	int A, B; 
	cin >> A >> B;
	if(A + 1 < B){
		cout << 2 * B - 1 << endl;
	}else if(A - 1 > B){
		cout << 2 * A - 1 << endl;
	}else{
		cout << A + B << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int>l(n);
    for (int i = 0; i < n; i++)
    {
        cin>>l[i];
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            for (int k = j+1; k < n; k++)
            {
                if(l[i] !=l[j] && l[j] !=l[k] && l[i] != l[k]){
                    if(abs(l[i] - l[j]) < l[k] && l[k] < l[i] +l[j]){
                        ans++;
                    }
                }  
            }
            
        }
        
    }
    cout<<ans<<endl;
    
    return 0;
}

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

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

int n,a,b;
string s;

int main() {
    cin>>n>>a>>b;
    cin>>s;
    int c = a+b;

    int p=0, q=0;
    rep(i,n) {
        bool f = false;
        if(s[i]=='a'){
            if(p < c) {
                f = true;
            }
            p++;
        }else if(s[i]=='b'){
            q++;
            if(p<c and q<=b) {
                f = true;
                p++;
            }
        }
        cout << (f ? "Yes" : "No") << endl;
    }


    return 0;
}

Measured memory_bytes: 896
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  if(A.at(0)==0){cout<<0<<endl;}
  else{
    ll ans=A.at(0);
    for(ll i=1;i<N;i++){
      if(ans>(1000000000000000000)/A.at(i)){cout<<-1<<endl;return 0;}
      else{ans*=A.at(i);}
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3996
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll ans=0,n,d;cin>>n>>d;
  rep(i,0,n){
    ll x,y;cin>>x>>y;
    if(x*x+y*y<=d*d)++ans;
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3656
N = int(input())
M = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i,m in enumerate(M):
  if i+m >= N:
    continue
  L[i+m] += 1
for i,m in enumerate(M[::-1]):
  if i+m >= N:
    continue
  R[i+m] += 1
R = R[::-1]
#print(L)
#print(R)
print(sum([l*r for l,r in zip(L,R)]))

Measured memory_bytes: 32216
#include <iostream>
#include <utility>
#include <algorithm>

#define MAX_N 100010
using namespace std;

int bit[MAX_N],m,l[3*MAX_N],r[3*MAX_N];
pair<int,int> p[3*MAX_N];

int sum(int i){
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i& -i;
	}
	return s;
}

void add(int i, int x){
	while(i<=m){
		bit[i] += x;
		i += i&-i;
	}
}

int main(){
	int i,n,k,j = 0;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> l[i] >> r[i];
		p[i] = make_pair(r[i]-l[i]+1,i);
	}
	sort(p,p+n);
	for(i=0;i<=m;i++){
		bit[i] = 0;
	}
	for(i=1;i<=m;i++){
		int ans = 0;
		while(p[j].first<i && j<n){
			add(l[p[j].second],1);
			add(r[p[j].second]+1,-1);
			j++;
		}
		ans += n-j;
		for(k=0;k<=m;k += i){
			ans += sum(k);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string a;
	cin >> a;

	if (a == "SUN") cout << 7;
	if (a == "MON") cout << 6;
	if (a == "TUE") cout << 5;
	if (a == "WED") cout << 4;
	if (a == "THU") cout << 3;
	if (a == "FRI") cout << 2;
	if (a == "SAT") cout << 1;
	cout << endl;
	return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    
    
    int mx=t.size(),n=s.size(),m=t.size();
   
    for(int i=0;i<=(n-m);++i)
    { int c=0;
   
        for(int j=0;j<t.size();++j)
        {
            if(s[i+j]!=t[j])
            {
                c++;
            }
        }
        mx=min(mx,c);
    }
    
    cout<<mx<<endl;
    
}


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

const int N = 45;
const int md = 1e9 + 7;

int n, X, Y, Z;
vector<int> G[1 << 17];
int f[N][1 << 17][2];

bool has(int mask, int bit) { return (mask & (1 << (bit - 1))); }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> X >> Y >> Z;
	for (int mask = 0; mask < (1 << 17); ++mask) {
		vector<int> pref;
		pref.push_back(0);
		for (int i = 0; i < 17; ++i) if (mask & (1 << i)) pref.push_back(i + 1);
		for (int nxt = 1; nxt < 11; ++nxt) {
			int nmask = 0;
			for (int i : pref) {
				int j = i + nxt;
				if (j <= 17) nmask |= (1 << (j - 1));
			}
			G[mask].push_back(nmask);
		}
	}

	f[0][0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int mask = 0; mask < (1 << 17); ++mask) for (int ok = 0; ok < 2; ++ok) {
			if (!f[i-1][mask][ok]) continue;
			for (auto nmask : G[mask]) {
				int nok = ok;
				if (has(nmask, Z) && has(nmask, Z + Y) && has(nmask, Z + Y + X)) nok = 1;
				f[i][nmask][nok] = (f[i][nmask][nok] + f[i-1][mask][ok]) % md;
			}
		}
	}

	int ans = 0;
	for (int mask = 0; mask < (1 << 17); ++mask) {
		ans = (ans + f[n][mask][1]) % md;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 55552
import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]

Rmin = np.min(R)
Lmax = np.max(L)
if Rmin >= Lmax:
    num = np.min(R) - np.max(L) + 1
else:
    num = 0
print(num)

Measured memory_bytes: 20724
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	int n,m,i,j;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		vector<char> str,conv[2];
		for(i=0;i<n;i++)
		{
			char a,b;
			cin >> a >> b ;
			conv[0].push_back(a);
			conv[1].push_back(b);
		}
		
		cin >> m ;
		
		for(i=0;i<m;i++)
		{
			char a;
			cin >> a ;
			for(j=0;j<conv[0].size();j++)
			{
				if(a==conv[0][j])
				{
					a=conv[1][j];
					break;
				}
			}
			str.push_back(a);
		}
		for(i=0;i<str.size();i++)
			cout << str[i] ;
		cout << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef long long int LL;
typedef pair<LL, int> PLI;
typedef vector<PLI> VP;

int n, l, a[100010];
bool growing[100010];
priority_queue<PLI, VP, greater<PLI> > Q;
LL nowtime = 0;

int main()
{
  scanf("%d%d", &n, &l);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]);

  for(int i = 1; i <= n; i++)
    if(a[i] > a[i - 1] && a[i] > a[i + 1]){
      growing[i] = true;
      Q.push(MP(l - a[i], i));
    }
  
  while(!Q.empty()){
    PLI breaked = Q.top();
    Q.pop();
    nowtime = breaked.first;
    a[breaked.second] = 0;

    if(breaked.second > 1 && !growing[breaked.second - 1] && a[breaked.second - 1] > a[breaked.second - 2]){
      growing[breaked.second - 1] = true;
      Q.push(MP((LL)l - a[breaked.second - 1] + nowtime, breaked.second - 1));
    }

    if(breaked.second < n && !growing[breaked.second + 1] && a[breaked.second + 1] > a[breaked.second + 2]){
      growing[breaked.second + 1] = true;
      Q.push(MP((LL)l - a[breaked.second + 1] + nowtime, breaked.second + 1));
    }
  }
  
  printf("%lld\n", nowtime);
  return 0;
}

Measured memory_bytes: 2748
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())


inline int bsf(int n)
{
  int z;
  __asm__("bsf %1, %0;" :"=r"(z) :"r"(n));
  return z;
}

int n;
int fortune[30];
int bridge[30];
char memo[1 << 25];

char calc(int use, int sum) {
  if (memo[use] != -1) { return memo[use]; }
  int rev = ((1 << n) - 1) ^ use;
  while (rev) {
    int i = bsf(rev);
    rev -= rev & -rev;
    int nsum = sum + fortune[i];
    if (nsum > bridge[i]) { return memo[use] = 0; }
  }
  rev = ((1 << n) - 1) ^ use;
  while (rev) {
    int i = bsf(rev);
    rev -= rev & -rev;
    int nsum = sum + fortune[i];
    int nuse = use | (1 << i);
    if (calc(nuse, nsum)) {
      return memo[use] = 1;
    }
  }
  return memo[use] = 0;
}

int main() {
  while (scanf("%d", &n), n) {
    memset(memo, -1, (1 << n));
    memo[(1 << n) - 1] = 1;
    REP(i, n) {
      scanf("%d %d", &fortune[i], &bridge[i]);
    }
    printf("%s\n", calc(0, 0) ? "Yes" : "No");
  }
}

Measured memory_bytes: 32000
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <list>
#include <vector>
#include <map>

#pragma warning(disable:4996)

using namespace std;
#define FUNC(string) cout<<str<<endl 

int main(void) {
	long int a, b, c;
	double d;
	long int ans;
	cin >> a >> b >> c;
	if (a > b) {
		if (a > c) {
			if (a % 2 == 0)
				ans = 0;
			else
				ans = (a / 2 + 1)*b*c - a / 2 * b*c;
		}
		else {
			if (c % 2 == 0)
				ans = 0;
			else
				ans = (c / 2 + 1)*b*a - c / 2 * b*a;
		}
	}
	else if (b > c) {
		if (b % 2 == 0)
			ans = 0;
		else
			ans = (b / 2 + 1)*a*c - b / 2 * a*c;
	}
	else {
		if (c % 2 == 0)
			ans = 0;
		else
			ans = (c / 2 + 1)*b*a - c / 2 * b*a;
	}

	cout << ans << endl;

	return 0;
}

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

int const N=1e5+5, M=1e5+5, OO = 0x3f3f3f3f;

int n,m,u,v,ans;
vector <int> adj[N];

int mem[N];
int solve(int u)
{
    if(mem[u]!=-1)
        return mem[u];
    int ret=0;
    for(int v : adj[u])
        ret=max(ret,1+solve(v));
    return mem[u]=ret;
}



int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
    scanf("%d %d",&n, &m);
    for(int i=0; i<m; i++)
    {
        scanf("%d %d",&u, &v);
        adj[--u].push_back(--v);
    }
    memset(mem, -1, sizeof mem);
    for(int i=0; i<n; i++)
        ans=max(ans,solve(i));
    printf("%d\n",ans);


}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n, a, b; cin >> n >> a >> b;
    int maxSub = min(a, b);
    int blah = a+b-n;
    int minSub = 0;
    minSub = max(minSub, blah);
    cout << maxSub << " " << minSub << endl;
    return 0;
}


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

using namespace std;

const int N = 1e5+7;
const long long INF = 1e18;

int a, b, q;
long long s[N], t[N];

inline long long calc(long long ss, long long tt, long long xx)
{
    if (ss <= xx && tt <= xx) {
        return xx-min(ss, tt);
    } else if (ss >= xx && tt >= xx) {
        return max(ss, tt)-xx;
    } else {
        return min(abs(ss-xx), abs(tt-xx))+abs(ss-tt);
    }
}

int main()
{
    scanf("%d %d %d", &a, &b, &q);
    for (int i = 1; i <= a; ++i)
        scanf("%lld", s+i);
    for (int i = 1; i <= b; ++i)
        scanf("%lld", t+i);
    long long x, res;
    for (int i = 1; i <= q; ++i) {
        scanf("%lld", &x);
        int ps = lower_bound(s+1, s+a+1, x)-s,
            pt = lower_bound(t+1, t+b+1, x)-t;
        res = INF;
        for (int i = -1; i <= 0; ++i) {
            if (ps+i > a || ps+i < 1) continue;
            for (int j = -1; j <= 0; ++j) {
                if (pt+j > b || pt+j < 1) continue;
                res = min(res, calc(s[ps+i], t[pt+j], x));
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 2816
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	cin >> n;
	cout << (n-1)*n/2;	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int linearSearch(int i);

int matrix_main[10000+1];
int count_main=0;

int main(){
  int count=0;
  int input;
  int count_sub;
  int i=0,j=0;


  scanf("%d",&count_main);
  while(i != count_main){
    scanf("%d",&matrix_main[i]);
    i++;
  }
  
  scanf("%d",&count_sub);
  //  fprintf(stderr,"count_sub: %d\n",count_sub);
  for(i = 0 ; i < count_sub ; i++ ){
    scanf("%d",&input);
    //fprintf(stderr,"first_input : %d\n",input);
    if(linearSearch(input)) {
      count++;
      //fprintf(stderr,"now_count :%d input: %d\n",count,input);
    }
  }
  printf("%d\n",count);
  return 0;
}

int linearSearch(int key){
  int j=0;

  matrix_main[count_main] = key;

  while(matrix_main[j] != key){
    
    //if(j == count_main) return 0;
    j++;
  }
  return j != count_main;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef long long llong;

#define MAX 200001

int main(int argc, char const *argv[])
{
  int a, b;
  int n, m, k;
  int i, j, ans = 0;
  llong ATotal[MAX] = {0};
  llong BTotal[MAX] = {0};
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 1; i <= n; i++)
  {
    scanf("%d", &a);
    if (i == 0)
    {
      ATotal[i] = a;
    }
    else
    {
      ATotal[i] = ATotal[i - 1] + a;
    }
  }

  for (int i = 1; i <= m; i++)
  {
    scanf("%d", &b);
    if (i == 0)
    {
      BTotal[i] = b;
    }
    else
    {
      BTotal[i] = BTotal[i - 1] + b;
    }
  }

  j = m;
  for (i = 0; i <= n; i++)
  {
    if (ATotal[i] > k)
    {
      break;
    }

    while (BTotal[j] > k - ATotal[i])
    {
      j--;
    }
    ans = max(ans, i + j);
  }

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

  return 0;
}

Measured memory_bytes: 4840
//
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define MODU 1000000007
// ll modpow (ll a, ll b, ll m){
//   if(b==0) return 1;
//   else{
//     ll z = modpow(a, b/2, m);
//     z = (z*z)%m;
//     if(b%2==0) return z;
//     else return (z*a)%m;
//   }
// }
// ll gcd(ll a, ll b){
//   if(b==0) return a;
//   else return gcd(b, a%b);
// }

int i, j;
int main(){
  ll n, temp;
  cin >> n;
  ll arr1[n], arr2[n];
  memset(arr1,0,sizeof(arr1)); memset(arr2,0,sizeof(arr2));
  cin >> arr1[0];
  for(i = 1; i < n; i++){
    cin >> temp; arr1[i] = temp+arr1[i-1];
  }
  cin >> arr2[0];
  for(i = 1; i < n; i++){
    cin >> temp; arr2[i] = temp+arr2[i-1];
  }
  ll out = arr1[0]+arr2[n-1];
  for(i = 1; i < n; i++){
    out = max(out,arr1[i]+arr2[n-1]-arr2[i-1]);
  }
  cout << out << endl;
  return 0;
}
// notes
//


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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

bool is_product_overflow(ull a, ull b) {
	ull prod = a * b;
	return (prod / b != a);
}

void Main()
{
	ull N,D;
	std::cin >> N;
	std::cin >> D;

	D = D * D;

	ull c = 0;
	for (int i = 0; i < N; ++i)
	{
		ll x, y;
		cin >> x;
		cin >> y;
		ll d = x * x + y * y;
		if (d <= D) {
			++c;
		}
	}
	cout << c;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	int N;

	cin >> N;

	std::vector<int> d(N);

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

	std::sort(d.begin(), d.end());

	int tmp = N / 2;

	if (d[tmp] == d[tmp-1])
	{
		cout << 0;
		return 0;
	}

	cout << d[tmp] - d[tmp - 1];




	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,k;
    cin>>n>>k;
    int count=0;
    while(n!=0){
        n/=k;
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(int (i)=0;(i)<int(n);(i)++)
using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  char A[N][N], B[M][M];
  REP(i,N) REP(j,N) cin >> A[i][j];
  REP(i,M) REP(j,M) cin >> B[i][j];
  bool flag = false;
  REP(i,N-M+1){
    REP(j,N-M+1){
      REP(k,M){
        REP(l,M){
          if(A[i+k][j+l] != B[k][l]){
            flag = true;
            break;
          }
          if(k == M-1 && l == M-1){
            cout << "Yes" << endl;
            return 0;
          }
        }
        if(flag) break;
      }
      flag = false;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int winnum(string s)
{
    int ans = 0;
    s = s.substr(1, s.length() - 2);
    for(int i = 0; i < s.length(); i++){
        ans += (s[i] - '0') * (int)pow(10, s.length() - 1 - i);
    }
    // cout << ans << endl;
    return ans / 2 + 1;
}

int solve(string s)
{
    if(find(s.begin() + 1, s.end() - 1, '[') == s.end() - 1) return winnum(s);
    // cout << s << endl;
    vector<int> num;
    int kakkonum = 0;
    int start;
    for(int i = 1; i < s.length() - 1; i++){
        if(s[i] == '['){
            if(kakkonum == 0) start = i;
            kakkonum++;
        }
        if(s[i] == ']'){
            kakkonum--;
        }
        if(kakkonum == 0){
            num.push_back(solve(s.substr(start, i - start + 1)));
        }
    }
    sort(num.begin(), num.end());
    int ans = 0;
    for(int i = 0; i < num.size() / 2 + 1; i++){
        ans += num[i];
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        cout << solve(s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1328
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var S = ReadLine();
            var xy = Sarray();
            var cnt = 0L;
            var dir = 0L;
            var fNums = Enumerable.Range(0, 2).Select(_ => new List<long>()).ToArray();

            fNums[1].Add(0);
            foreach (var s in S)
            {
                if (s == 'T')
                {
                    fNums[dir].Add(cnt);
                    cnt = 0;
                    dir = (dir + 1) % 2;
                    continue;
                }
                ++cnt;
            }
            fNums[dir].Add(cnt);
            
            for (var i = 0; i < 2; ++i)
            {
                var dp = new HashSet<long>();
                dp.Add(fNums[i][0]);
                for (var j = 1; j < fNums[i].Count; ++j)
                {
                    var d = new HashSet<long>(dp.Count * 2);
                    foreach (var p in dp)
                    {
                        d.Add(p + fNums[i][j]);
                        d.Add(p - fNums[i][j]);
                    }
                    dp = d;
                }
                if(!dp.Contains(xy[i]))
                {
                    WriteLine("No");
                    return;
                }
            }
            WriteLine("Yes");
        }
    }
}

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

using namespace std;
typedef  long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int cw[300001];
int ce[300001];
int ccw[300001];
int cce[300001];



int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = 987654321;
    if (s[0] == 'W')
        cw[0] = 1;
    else
        ce[0] = 1;

    for (int i = 1; i < n; i++) {
        if (s[i] == 'W') {
            cw[i] += (cw[i-1]+1);
            ce[i] += (ce[i-1]);
        }
        else if (s[i] == 'E') {
            cw[i] += (cw[i-1]);
            ce[i] += (ce[i-1]+1);

        }
    }
    if (s[n-1] == 'W')
        ccw[n-1] = 1;
    else
        cce[n-1] = 1;

    for (int i = n-2; i >= 0; i--) {
        if (s[i] == 'W') {
            ccw[i] += (ccw[i+1]+1);
            cce[i] += (cce[i+1]);
        }
        else if (s[i] == 'E') {
            cw[i] += (ccw[i+1]);
            cce[i] += (cce[i+1]+1);

        }
    }

    for (int i = 0; i < n; i++) {
        int total = cw[i] + cce[i];
        ans = min(ans, total);

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


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

class Program
{
    public static void Main()
    {


        var N = int.Parse(Console.ReadLine());
        var P = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();

        int count = 0;

        for(int i = 0; i < N;i++ )
        {
            if(P[i] != i + 1)
            {
                count = count + 1;
            }
        }

        if(count == 0 || count == 2)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

        
    }
}

Measured memory_bytes: 13268
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> T ceil(T a, T b) { return a / b + !!(a % b); }

int main() {
    int a, b; cin >> a >> b;
    cout << ceil(a, b) - a / b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int row,col;
};

int HP,MAX_HP;
int H,W;
int damage[26],POW[13],portion[12];
int max_HP[1001][4096];
char base_map[100][101],move_route[1000];
Info info[1001];


void func(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		scanf("%s",base_map[row]);
	}

	int T;
	scanf("%d",&T);

	char buf[2];
	int tmp;

	for(int i = 0; i < T; i++){
		scanf("%s %d",buf,&tmp);
		damage[buf[0]-'A'] = tmp;
	}

	int S;
	scanf("%d",&S);

	int index = 0;

	for(int i = 0; i < S; i++){
		scanf("%s %d",buf,&tmp);
		for(int k = 0; k < tmp; k++){
			move_route[index++] = buf[0];
		}
	}

	S = index;

	info[0].row = 0;
	info[0].col = 0;

	for(int i = 0; i < S; i++){
		switch(move_route[i]){
		case 'U':
			info[i+1].row = info[i].row-1;
			info[i+1].col = info[i].col;
			break;
		case 'D':
			info[i+1].row = info[i].row+1;
			info[i+1].col = info[i].col;
			break;
		case 'R':
			info[i+1].row = info[i].row;
			info[i+1].col = info[i].col+1;
			break;
		case 'L':
			info[i+1].row = info[i].row;
			info[i+1].col = info[i].col-1;
			break;
		}
	}

	int P;
	scanf("%d",&P);

	for(int i = 0; i < P; i++){
		scanf("%d",&portion[i]);
	}

	for(int i = 0; i <= S; i++){
		for(int state = 0;state < POW[P];state++)max_HP[i][state] = 0;
	}

	max_HP[0][0] = HP;

	int next_damage,next_HP,next_state;

	for(int move = 1; move <= S; move++){
		next_damage = damage[base_map[info[move].row][info[move].col]-'A'];
		for(int state = 0; state < POW[P]; state++){
			if(max_HP[move-1][state] == 0)continue;

			if(max_HP[move-1][state] > next_damage){
				max_HP[move][state] = max(max_HP[move][state],max_HP[move-1][state]-next_damage);
			}

			for(int loop = 0; loop < P; loop++){
				if(state & (1 << loop)){
					//Do nothing
				}else{
					next_HP = min(MAX_HP,max_HP[move-1][state]+portion[loop]);
					if(next_HP <= next_damage)continue;
					next_state = state + POW[loop];

					max_HP[move][next_state] = max(max_HP[move][next_state],next_HP-next_damage);
				}
			}
		}
	}

	for(int state = 0; state < POW[P];state++){
		if(max_HP[S][state] > 0){
			printf("YES\n");
			return;
		}
	}
	printf("NO\n");
}

int main(){

	for(int i = 0; i < 13; i++)POW[i] = pow(2,i);

	for(int i = 0; i < 26; i++)damage[i] = 999;

	while(true){
		scanf("%d %d",&HP,&MAX_HP);
		if(HP == 0 && MAX_HP == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 19244
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int arr[100001];
vector<pair<int,int> > v;
int n,m;


bool cmp(const pair<int, int> &a, const pair<int, int> &b)
{
    if(a.first == b.first)
        return a.second > b.second;
    return a.first > b.first;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr,arr+n);
    int num, val;
    for(int i = 0; i < m; i++)
    {
        cin >> num >> val;
        v.push_back(make_pair(val,num));
    }

    sort(v.begin(),v.end(),cmp);
    int j = 0; //v_ind
    for(int i =0; i < m; i++)
    {
        if(v[i].first > arr[j] && v[i].second > 0 && j < n)
        {
            v[i].second -= 1;
            arr[j] = v[i].first;
            i--;
            j++;
        }
    }

    long long int result = 0;
    for(int i = 0; i < n; i++)
        result += arr[i];

    cout << result;




}


Measured memory_bytes: 1784