akhauriyash/Code-Regression huggingface dataset:
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  string t;
  cin >> s >> t;
  t.pop_back();
  if(s == t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

// macros
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INT_IN(a) int a; cin >> a
#define STR_IN(s) string s; cin >> s
#define PRINTLN(s) cout << s << endl
#define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl;

// util functions
template<class T> inline T sqr(T x) {return x*x;}

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T>inline T max(vector<T> v){T max=v[0]; FOR(i, 1, v.size())max=MAX(v[i], max); return max;}
template <typename T>inline T min(vector<T> v){T min=v[0]; FOR(i, 1, v.size())min=MIN(v[i], min); return min;}
template <typename T>inline vector<T> concat(vector<T> a, vector<T> b){vector<T> ab; ab.reserve(a.size()+b.size());ab.insert(ab.end(),a.begin(),a.end());ab.insert(ab.end(),b.begin(),b.end());return ab;}

// types
typedef long long LL;

// consts
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  #x << " = " << (x) << endl
#define debug(x) #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(){
    char op;
    while(true){
        INT_IN(a);
        cin >> op;
        INT_IN(b);
        if(op == '?') break;
        PRINTLN((op == '+' ? a + b :
                 op == '-' ? a - b :
                 op == '*' ? a * b : a / b));
    }
   return 0;
}

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

vector<int> par(200005);
vector<int> ran(200005);

vector<int> par2(200005);
vector<int> ran2(200005);


void init(int n){
  for(int i=0;i<n;i++){
    par.at(i)=i;
    ran.at(i)=0;
    par2.at(i)=i;
    ran.at(i)=0;
  }
}

int find(int x){
  if(par.at(x)==x) return x;
  else return par[x] = find(par[x]);
}

int find2(int x){
  if(par2.at(x)==x) return x;
  else return par2[x] = find2(par2[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y) return;

  if(ran.at(x)<ran.at(y)){
    par[x]=y;
  }
  else{
    par[y]=x;
    if(ran.at(x)==ran.at(y)) ran.at(x)++;
  }
}
void unite2(int x,int y){
  x = find2(x);
  y = find2(y);
  if(x==y) return;

  if(ran2.at(x)<ran2.at(y)){
    par2[x]=y;
  }
  else{
    par2[y]=x;
    if(ran2.at(x)==ran2.at(y)) ran2.at(x)++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}
bool same2(int x,int y){
  return find2(x) == find2(y);
}

int n;
int k;
int l;
typedef pair<int,int> p;
vector<p> pq(100005);
vector<p> rs(100005);

vector<p> root_node(200005);
map<p,int> mapp;

int main(){
  cin >> n;
  cin >> k;
  cin >> l;
  for(int i=0;i<k;i++){
    cin >> pq.at(i).first;
    cin >> pq.at(i).second;
  }
  for(int i=0;i<l;i++){
    cin >> rs.at(i).first;
    cin >> rs.at(i).second;
  }
  init(n);
  for(int i=0;i<k;i++){
    unite(pq.at(i).first,pq.at(i).second);
  }
  for(int i=0;i<l;i++){
    unite2(rs.at(i).first,rs.at(i).second);
  }
  for(int i=1;i<n+1;i++){
    int parent = find(i);
    int parent2 = find2(i);
    p pp(parent,parent2);
    root_node.at(i)=pp;
    mapp[pp]=0;
  }
  for(int i=1;i<n+1;i++){
    mapp[root_node.at(i)]+=1;
  }
  for(int i=1;i<n+1;i++){
    p pp = root_node.at(i);
    cout << mapp[pp] << ' ';
  }
  cout << endl;
}

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

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

const int N = 1e5 + 5;
bool S[N];
int p[N];
int n, m;

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

  cin >> n >> m;
  int nb;
  string s;
  int res = 0, pn = 0;
  for (int i = 0; i < m; ++i) {
    cin >> nb >> s;
    if (s == "AC") {
      if (!S[nb]) {
        S[nb] = true;
        ++res;
        pn += p[nb];
      }
    } else {
      if (!S[nb]) {
        ++p[nb];
      }
    }
  }

  cout << res << ' ' << pn << endl;
  
  return 0;
}


Measured memory_bytes: 768
def main():
    N = int(input())
    s = input()
    dot = 0
    has = 0
    for c in s:
        if c == ".":
            dot += 1
        else:
            has += 1
    left_dots = 0
    left_has = 0
    right_dots = dot
    right_has = has
    ans = min(dot, has)
    for left in range(N):
        c = s[left]
        if c == ".":
            left_dots += 1
            right_dots -= 1
        else:
            left_has += 1
            right_has -= 1
        # print(left_has, right_dots)
        ans = min(left_has+ right_dots, ans)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3500
N, L, T = map(int, input().split())
x = ["" for i in range(N)]
w = ["" for i in range(N)]
for i in range(N):
    x[i], w[i] = map(int, input().split())

y = [[i, ""] for i in range(N)]
for i in range(N):
    y[i][1] = (x[i] + (-1)**(w[i]+1)*T) % L

count = 0
for i in range(N):
    if w[0] < w[i]:
        count += (2 * T + L - x[i] + x[0]) // L
    elif w[0] > w[i]:
        count += (2 * T + x[i] - x[0]) // L

if w[0] == 1:
    num = count % N
else:
    num = -count % N

if w[0] == 1:
    y.sort(key=lambda x: (x[1], -x[0]))
else:
    y.sort(key=lambda x: (x[1], x[0]))

for i in range(N):
    if y[i][0] == 0:
        index = i
        break

for i in range(N):
    print(y[(index-num+i) % N][1])


Measured memory_bytes: 35536
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

ans = 0
s = 0

for i in range(39, -1, -1):
    cnt = [0, 0]
    for a in A:
        cnt[(a >> i) & 1] += 1
    b = 0 if cnt[0] > cnt[1] else 1
    if s + (1 << i) > k:
        b = 1
    if b == 0:
        s += 1 << i
    ans += cnt[b] * (1 << i)

print(ans)

Measured memory_bytes: 14620
#include <cstdio>
#include <cmath>
 
#define MAX 100000

bool prime[MAX + 1];
int count[MAX + 1];
int N, L, R;

int main() {
  // 素数配列をエラトステネスの篩を使って生成
  // 素数であれば false, 素数でなければ true
  for (int i = 2; i < sqrt(MAX); ++ i)
    if (!prime[i])
      for (int j = i + i; j <= MAX; j += i)
        prime[j] = true;

  // N と (N + 1) / 2 が素数である要素配列を生成
  // 条件が成立すれば 1、成立しなければ 0
  for (int i = 3; i <= MAX; i += 2)
    if (!prime[i] && !prime[(i + 1) >> 1])
      count[i] = 1;

  // 累積和を生成
  for (int i = 3; i <= MAX; ++ i)
    count[i] += count[i - 1];

  scanf("%d", &N);
  while (N --) {
    scanf("%d%d", &L, &R);
    printf("%d\n", count[R] - count[L - 1]);
  }

  return 0;
}


Measured memory_bytes: 2216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
void solve()
{
    ll n,m=0,k=0,i=1,j,p,f,x, y, z;
    ll ans=0, a[N], b[N] = {};
    cin>>n>>m>>k;
    if(m*k>=n) cout<<"Yes";
    else cout<<"No";
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 3644
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> k;
  rep(i, k) s += "ACL";
  Cout(s);
  return 0;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  rep(i,n-1){
    if(A[i] == A[i+1]){
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
using namespace std;
char s[200005];
vector<int> v[200005];
int cnt[200005][2];
struct cmp
{
	bool operator()(const int &a,const int &b) const
	{
		int ca=min(cnt[a][0],cnt[a][1]),cb=min(cnt[b][0],cnt[b][1]);
		if (ca==cb)
		return (a<b);
		return (ca<cb);
	}
};
set<int,cmp> st;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	getchar();
	scanf("%s",s);
	while (m--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
		cnt[a][s[b]-'A']++;
		cnt[b][s[a]-'A']++;
	}
	for (int i=0;i<n;i++)
	st.insert(i);
	while (!st.empty())
	{
		int node=*st.begin();
		if (min(cnt[node][0],cnt[node][1]))
		break;
		st.erase(node);
		for (int u:v[node])
		{
			if (st.find(u)==st.end())
			continue;
			st.erase(u);
			cnt[u][s[node]-'A']--;
			st.insert(u);
		}
	}
	printf(st.empty()? "No":"Yes");
}

Measured memory_bytes: 20864
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static long inf = (long) 1e14;
	static int n, q;
	static ArrayList<Integer>[] ad;
	static long[][] memo;
	static boolean f;
	static boolean vis[];
	static int[] size, pa;
	static double[] x, y;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		System.out.println(Math.max(Math.max(a * c, a * d), Math.max(c * b, b * d)));
		out.close();
	}

	static int[] si;
	static ArrayList<Integer> primes;

	static void seive(int N) {
		si = new int[N];
		primes = new ArrayList<>();
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 25432
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <DEBUG.h>
#ifndef LL
#define LL long long
#endif
#ifndef uLL
#define uLL unsigned long long
#endif
#ifndef uL
#define uL unsigned int
#endif
#ifndef iL
#define iL int
#endif
#ifndef iS
#define iS short
#endif
#ifndef uS
#define uS unsigned short
#endif
#ifndef uC
#define uC unsigned char
#endif
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(a) (((a)<0)?(-(a)):(a))
#define sgn(a) (((a)<0)?(1):(0))
#define movs(a,b,l) (memmove((a),(b),sizeof(*(b))*(l)))
#define stosb(a,b,l) (memset((a),(b),sizeof(*(a))*(l)))
LL num[100000],ans[3007][3007];
int main()
{
	LL a,b,c,i,j,k,n,m;
	for (i=1;i<=3;i++)
	{
		scanf("%lld",&num[i]);
	}
	scanf("%lld",&n);
	for (i=0;i<=3;i++)
	{
		for (j=0;j<=n;j++)
		{
			ans[i][j]=0;
		}
	}
	ans[0][0]=1;
	for (i=1;i<=3;i++)
	{
		ans[i][0]=1;
		for (j=1;j<num[i];j++)
		{
			ans[i][j]=ans[i-1][j];
		}
		for (;j<=n;j++)
		{
			ans[i][j]=ans[i-1][j]+ans[i][j-num[i]];
		}
		//print64(ans[i],n+1);
	}
	printf("%lld\n",ans[3][n]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int64 dfs(const int64 i, int64 pre, const int64& n, const vector<int64>& a, vector<int64>& ans) {
//    cerr << "test ans : " << ans << " " <<  pre << endl;
    if (pre < (a[i]+1)/2) return -1;
    ans[i] += a[i];
    if (i == n) {
        return a[i];
    }

    pre = min(LONG_MAX/3LL, (pre*2 - a[i]));
    int64 u = dfs(i+1, pre, n, a, ans);
    if (u < 0 || pre < (u+1)/2) return -1;
//    cerr << "pre : " << pre << " " << " u : " << u << endl;
    ans[i] += min(pre, u);
    return min(pre, u) + a[i];
}

int main() {
    int64 n;
    cin >> n;
    vector a(n+1,0LL);
    for (int64 i=0; i<=n; i++) cin >> a[i];

    if (n==0) {
        cout << (a[0]==1? 1 : -1) << endl;
        return 0;
    }

    vector<int64> ans(n+1, 0);
    ans[0] = 1;
    int64 u = dfs(1, 1, n, a, ans);
//    debug(ans);
    if (a[0] != 0) u = -1;
    if (u >= 0) {
        cout << accumulate(ans.begin(), ans.end(), 0LL) << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = scanner.nextInt();
		}

		int max = 0;
		int count = 0;
		for (int i = 0; i < N - 1; i++) {
			if (H[i] >= H[i + 1]) {
				count++;
			}
			else {
				count = 0;
			}
			max = Math.max(max, count);
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 49860
n = int(input())
aSum = 0
bSum = 0
ans = 0
cards = [int(x) for x in input().split()]

for j in range(1,n+1):
    if j % 2 == 1:
        aSum += max(cards)
        cards.remove(max(cards))
    else:
        bSum += max(cards)
        cards.remove(max(cards))
ans = aSum - bSum
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
#include<map>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int n;


int yakusu(int x) {
	int cnt = 0;
	for (int i = 1; i <= x; i++)
		if (x%i == 0)cnt++;
	if (cnt == 8) return 1;
	else return 0;
}

int main() {
	int ans = 0;
	cin >> n;
	for (int j = 19; j <= n; j += 2)
		ans += yakusu(j);
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;

ll N, Q;
vector<ll> S, T, X;
vector<ll> D;

set<P> st;

int main() {
    cin >> N >> Q;
    S.resize(N);
    T.resize(N);
    X.resize(N);
    rep(i, N) cin >> S[i] >> T[i] >> X[i];
    D.resize(Q);
    rep(i, Q) cin >> D[i];

    rep(i, Q) {
        st.insert(P(D[i], i));
    }

    // 工事の情報
    vector<tuple<ll, ll, ll>> A(N);
    rep(i, N) {
        A[i] = tie(X[i], S[i], T[i]);
    }
    sort(A.begin(), A.end());

    // rep(i, N) {
    //     int a, b, c;
    //     tie(a, b, c) = A[i];
    //     printf("%d %d %d\n", a, b, c);
    // }
    // return 0;

    vector<ll> ans(Q);
    for (int i = 0; i < N; i++) {
        ll x, l, r;
        tie(x, l, r) = A[i];

        auto it = st.lower_bound(P(l - x, -1));
        while (it != st.end()) {
            if (it->first >= r - x) break;
            ans[it->second] = x;
            st.erase(it++);
        }
    }

    rep(i, Q) {
        cout << (ans[i] == 0 ? -1 : ans[i]) << endl;
    }

}

Measured memory_bytes: 26880
using System;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var x = Convert.ToInt32(Console.ReadLine());

            var s = x % 60;
            x /= 60;
            var m = x % 60;
            x /= 60;
            var h = x % 60;
            Console.WriteLine(h + ":" + m + ":" + s);
        }
    }
}

Measured memory_bytes: 9224
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 3e3+35;
const int mod = 998244353;
LL dp[maxn][maxn];
int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for(int i = a;i <= c; ++i){
        for(int j = b;j <= d; ++j){
            if(i==a&&j==b) continue;
            dp[i][j] = (dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1))%mod;
        }
    }
    cout << (dp[c][d]+mod)%mod << '\n';
    return 0;
}

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

int main(){
    int n,m,x,y,temp;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++){
        cin>>temp;
        if(temp>x)x=temp;
    }
    for(int i=0;i<m;i++){
        cin>>temp;
        if(temp<y)y=temp;
    }
    if(x<y)cout<<"No War"<<endl;
    else cout<<"War"<<endl;


}

Measured memory_bytes: 256
# include <iostream>
# include <string>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  int c=0;
    
  if(s.at(0)=='1') c++;
  if(s.at(1)=='1') c++;
  if(s.at(2)=='1') c++;
  
  cout << c << endl;
  
}

Measured memory_bytes: 256
import sys
n, m = map(int, input().split())
d = {}
for _ in range(m):
  s, c = map(int, input().split())
  if (n != 1 and s == 1 and c == 0) or (s in d and d[s] != c):
    print("-1")
    sys.exit()
  d[s] = c

for i in range(1, n+1):
  if i in d:
    print(d[i], end = "")
  else:
    print("1" if n != 1 and i == 1 else "0", end = "")
print()

Measured memory_bytes: 3188
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = parseInt(chunk.trim(), 10);
  var arr = [""]
  for (i = 1; i <= x; i++) {
    if (i % 3 == 0 || haveThree(i)) {
      arr.push(i);
    }
  }
  console.log(arr.join(" "));
});

function haveThree(num)
{
  if (num == 0) {
    return false;
  } else if (num % 10 == 3) {
    return true;
  } else if (haveThree(Math.floor(num / 10))) {
    return true;
  }
}

Measured memory_bytes: 10048
#include <bits/stdc++.h> 
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
const char nc[20]={'0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F','G','H','I','J'};
string ans;
int main()
{
    int m,n,k,t;
    cin>>m;
    n=-2;
    ans="";
    if(m==0){
    	cout<<0;
    	return 0;
	}
    while(m!=0){
        k=m%n;
        t=m/n;
        if(k<0)
        {
            k-=n;
            t++;
        }
        m=t;
        ans.push_back(nc[k]);
    }
    for(int i=ans.length()-1;i>=0;i--)
        cout<<ans[i];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* Written by Nishant Mittal aka nishantwrp */
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define modnum 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();

/*

███╗   ██╗██╗███████╗██╗  ██╗ █████╗ ███╗   ██╗████████╗██╗    ██╗██████╗ ██████╗ 
████╗  ██║██║██╔════╝██║  ██║██╔══██╗████╗  ██║╚══██╔══╝██║    ██║██╔══██╗██╔══██╗
██╔██╗ ██║██║███████╗███████║███████║██╔██╗ ██║   ██║   ██║ █╗ ██║██████╔╝██████╔╝
██║╚██╗██║██║╚════██║██╔══██║██╔══██║██║╚██╗██║   ██║   ██║███╗██║██╔══██╗██╔═══╝ 
██║ ╚████║██║███████║██║  ██║██║  ██║██║ ╚████║   ██║   ╚███╔███╔╝██║  ██║██║     
╚═╝  ╚═══╝╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝     
                                                                                                       
*/
int ans = 0;


signed main()
{
FAST
int a,b;
cin>>a>>b;
int c = a+b;
if (c %2 == 1)
{
  cout<<"IMPOSSIBLE";
} else {
  cout<<c/2;
}
return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll memo[100010];
int a[100010];
int n, m;

ll calc(int x) {
	if (a[x] == 1) return 0;
	if (x > n) return 0;
	if (x == n) return 1;
	ll& res = memo[x];
	if (~res) return res;
	res = 0;
	res += calc(x + 1);
	res %= INF;
	res += calc(x + 2);
	res %= INF;
	return res;
}

void solv() {
	
	int h, w;
	cin >> h >> w;
	string tb[2010];
	for (size_t i = 0; i < h; i++)
	{
		cin >> tb[i];
	}

	int tb1[2010][2010];
	memset(tb1, 0, sizeof(tb1));
	for (size_t i = 0; i < h; i++)
	{
		
		for (size_t j = 0; j < w; j++)
		{
			if (tb[i][j] == '.') {
				tb1[i][j] = 1;
				if (j > 0) {
					tb1[i][j] += tb1[i][j - 1];
				}
			}
		}

		for (int j = w - 1; j >= 0; j--)
		{
			if (tb[i][j] == '.' && tb1[i][j + 1] > 0) {
				tb1[i][j] = tb1[i][j + 1];
			}
		}
	}

	int tb2[2010][2010];
	memset(tb2, 0, sizeof(tb2));
	for (size_t i = 0; i < w; i++)
	{

		for (size_t j = 0; j < h; j++)
		{
			if (tb[j][i] == '.') {
				tb2[j][i] = 1;
				if (j > 0) {
					tb2[j][i] += tb2[j-1][i];
				}
			}
		}

		for (int j = h - 1; j >= 0; j--)
		{
			if (tb[j][i] == '.' && tb2[j+1][i] > 0) {
				tb2[j][i] = tb2[j + 1][i];
			}
		}
	}
	int res = 0;
	for (size_t i = 0; i < h; i++)
	{
		for (size_t j = 0; j < w; j++)
		{
			res = max(res, tb1[i][j] + tb2[i][j] - 1);
		}
	}
	cout << res << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}
 

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    double ans=0.0;
    FOR(i,1,n){
        int m=0;
        while(i*(1ll<<m) < k) m++;
        ans += (double)1/n*(double)1/(1<<m);
    }
    cout<<setp(12)<<ans<<endl;
    return 0;
}


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

using namespace std;

string input;
typedef string::iterator State;

int m;

bool cons( State &s, char ch ) {
  if(*s == ch) {
    //cout << *s;
    s ++;
    return true;
  }
  return false;
}

int formula( State &s ) {
  
  // <formula> ::= "T" | "F"
  if(cons(s, 'T')) return true;
  if(cons(s, 'F')) return false;
  
  // <formula>  ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k"
  if(isalpha(*s)) { return (m>>(*(s++)-'a')) & 1; }

  // <formula> ::= "-" <formula>
  if(cons(s, '-')) return !formula(s);
  
  // <formula> ::= "(" <formula> "*" <formula> ")"
  // <formula> ::= "(" <formula> "+" <formula> ")"
  // <formula> ::= "(" <formula> "->" <formula> ")"
  int ret;
  if(cons(s, '(')) {
    ret = formula(s);
    
    if(cons(s, '*')) {
      ret &= formula(s);
    }
    if(cons(s, '+')) {
      ret |= formula(s);
    }
    if(cons(s, '-')) {
      cons(s, '>');
      ret = ret<=formula(s);
    }

    cons(s, ')');
  }
  
  return ret;
}

int main() {
  
  while( getline(cin, input) ) {
    if(input == "#") break;
    bool l, r;
    bool ok = 1;
    for(m=0; m<(1<<11); m++) {
      State s = input.begin();
      l = formula(s);
      cons(s, '=');
      r = formula(s);
      //cout << endl;
      if(l != r) ok = 0;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1220
a, b = map(int, input().split())
if a>0 and b>0:
    print("Positive")
elif a==0 or b==0:
    print("Zero")
elif (a>0 and b<0) or (a<0 and b>0):
    print("Zero")
elif ((a+b)+1)%2==0:
    print("Positive")
else:
    print("Negative")

Measured memory_bytes: 9128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   string S,T;
   cin>>S>>T;
   int A,B;
   cin>>A>>B;
   string U;
   cin>>U;
   if(U==S)
   {
       A--;
   }
   if(U==T)
   {
       B--;
   }
   cout<<A<<" "<<B;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005

void solve(){
    int n;
    cin >> n;
    cout << n+n*n+n*n*n;
}




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

        int tt;
        tt=1;
       // cin >> tt;
        while(tt--){
            solve();
        }
        

}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=509;
int a[N],n,K,y[N],sum,ans;
bool check(int x){
    int sum=0;
    for(int i=1;i<=n;i++){y[i]=a[i]%x;sum+=y[i];}
    sort(y+1,y+n+1);
    int lim=n-sum/x;
    sum=0;
    for(int i=1;i<=lim;i++)sum+=y[i];
    return sum<=K;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>K;
    for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
    int lim=sqrt(sum);
    for(int i=1;i<=lim;i++)if(sum%i==0){
        if(check(i))ans=max(ans,i);
        if(check(sum/i))ans=max(ans,sum/i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
N = input() # 1行, 単数

print(N[0:3])


Measured memory_bytes: 61660
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+10;
struct Point{
    ll x,y;
    Point(){}
    Point(ll _x,ll _y):x(_x),y(_y){}
    bool operator < (const Point &P)const{
        return x<P.x||(x==P.x&&y<P.y);
    }
    Point operator - (const Point &P)const{
        return Point(x-P.x,y-P.y);
    }
    ll Cross(const Point & P)const{
        return x*P.y-y*P.x;
    }
    void pt(){printf("(%lld,%lld)\n",x,y);}
}p[maxn],cxh1[maxn],cxh2[maxn];
ll Area(Point P1,Point P2){return P1.Cross(P2);}
ll s1[maxn][2],s2[maxn][2];
Point down_Convexhull[maxn],up_Convexhull[maxn];
void solve(ll s[maxn][2],int n,bool rev){
    int top1=0,top2=0;
    for(int i=0;i<n;i++){
        if(i)s[i][0]=s[i-1][0],s[i][1]=s[i-1][1];
        while(top1>1&&(p[i]-down_Convexhull[top1-2]).Cross(down_Convexhull[top1-1]-down_Convexhull[top1-2])>=0){ //rev==0:下凸包
            s[i][0]-=Area(down_Convexhull[top1-2]-down_Convexhull[0],down_Convexhull[top1-1]-down_Convexhull[0]);top1--;
        }down_Convexhull[top1++]=p[i];
        if(top1>2)s[i][0]+=Area(down_Convexhull[top1-2]-down_Convexhull[0],down_Convexhull[top1-1]-down_Convexhull[0]);

        while(top2>1&&(up_Convexhull[top2-1]-up_Convexhull[top2-2]).Cross(p[i]-up_Convexhull[top2-2])>=0){ //rev==0:上凸包
            s[i][1]-=Area(up_Convexhull[top2-1]-up_Convexhull[0],up_Convexhull[top2-2]-up_Convexhull[0]);top2--;
        }up_Convexhull[top2++]=p[i];
        if(top2>2)s[i][1]+=Area(up_Convexhull[top2-1]-up_Convexhull[0],up_Convexhull[top2-2]-up_Convexhull[0]);
    }
    if(rev){
        for(int i=0;i<n/2;i++){
            swap(s[i][0],s[n-i-1][0]);
            swap(s[i][1],s[n-i-1][1]);
        }
    }
}
int main(){
  //  freopen("in.txt","r",stdin);
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++){scanf("%lld%lld",&p[i].x,&p[i].y);}
    if(n<=3){printf("0\n");return 0;}sort(p,p+n);
    solve(s1,n,0);reverse(p,p+n);
    solve(s2,n,1);reverse(p,p+n);
//    for(int i=0;i<n;i++){
//        printf("%I64d %I64d\n",s1[i][0],s1[i][1]);
//    }cout<<"***************\n";
//    for(int i=0;i<n;i++){
//        printf("%I64d %I64d\n",s2[i][0],s2[i][1]);
//    }
    ll ans=s1[n-1][0]+s1[n-1][1];
    for(int i=0;i<n-1;i++){
        if(p[i].x==p[i+1].x)continue;
        ans=min(ans,s1[i][0]+s1[i][1]+s2[i+1][0]+s2[i+1][1]);
    }
    for(int i=n-1;i>0;i--){
        if(p[i].x==p[i-1].x)continue;
        ans=min(ans,s1[i-1][0]+s1[i-1][1]+s2[i][0]+s2[i][1]);
    }
    printf("%lld\n",ans/2+ans%2);
    return 0;
}


Measured memory_bytes: 9472
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	parts := strings.Split(scanner.Text(), " ")
	t, _ := strconv.Atoi(parts[0])
	a, _ := strconv.Atoi(parts[1])

	var minIndex int
	var minValue float64
	scanner.Scan()
	parts = strings.Split(scanner.Text(), " ")
	for i := 0; i < n; i++ {
		h, _ := strconv.Atoi(parts[i])
		v := float64(t) - float64(h)*float64(0.006)
		sub := math.Abs(v - float64(a))
		if i == 0 || sub < minValue {
			minValue = sub
			minIndex = i + 1
		}
	}

	fmt.Println(minIndex)
}

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

using namespace std;

int main() {

	int n, m;

	cin >> n >> m;

	if (abs(n - m) > 1)
	{
		cout << 0 << endl;
		return 0;
	}

	long long int ans = 1;

	for (int i = 1; i <= n; i++)
		ans = (ans*i) % 1000000007;
	for (int i = 1; i <= m; i++)
		ans = (ans*i) % 1000000007;

	if (n == m)
		ans = (ans * 2) % 1000000007;

	cout << ans << endl;

	return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var dummy = new[] { int.MaxValue };
            var B = dummy.Concat(Console.ReadLine().Split(' ').Select(int.Parse)).Concat(dummy).ToList();
            Console.WriteLine(Enumerable.Range(0, N).Sum(i => Math.Min(B[i], B[i + 1])));
        }
    }
}


Measured memory_bytes: 13396
def solve():
    n = int(input())
    H = list(map(int, input().split()))
    B = [True] * n
    last = 0
    for i in range(0, n - 1):
        if H[i] <= H[i + 1]:
            continue
        for j in range(i, last - 1, -1):
            if H[j] > H[j + 1]:
                if B[j] and H[j] - 1 == H[j + 1]:
                    H[j] -= 1
                    B[j] = False
                else:
                    return "No"
            else:
                break
        last = i
    return "Yes"
print(solve())


Measured memory_bytes: 14396
M,z,s=998244353,1,0
d=[1]+[0]*7**6
e=[1]+[0]*7**6
for _ in'_'*input():
 a=input();s+=a;i=s;z*=3
 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print (z+~s%2*e[s//2]*3)%M

Measured memory_bytes: 157776
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MAXN = 200000;

ll a[26], b[26], c[150][26], d[150];

char S[MAXN + 5]; int f[MAXN + 5];
int main() {
	int n, m; ll l, r;
	scanf("%s%lld%lld", S + 1, &l, &r);
	n = strlen(S + 1), m = n / 2;
	
	f[0] = -1, f[1] = 0;
	for(int i=2;i<=m;i++) {
		int j = f[i - 1];
		while( j != -1 && S[i] != S[j + 1] )
			j = f[j];
		f[i] = j + 1;
	}
	
	int p = m - f[m];
	for(int i=1;i<=p;i++) c[0][S[i] - 'a']++;
	for(int i=1;i<=m;i++) c[1][S[i] - 'a']++;
	int k; d[0] = p, d[1] = m;
	for(k=1;d[k]<=r;k++) {
		for(int j=0;j<26;j++)
			c[k + 1][j] = c[k][j] + c[k - 1][j];
		d[k + 1] = d[k] + d[k - 1];
	}
	
	ll t = r;
	for(int i=k;i>=0;i--) {
		if( t >= d[i] ) {
			for(int j=0;j<26;j++)
				a[j] += c[i][j];
			t -= d[i];
		}
	}
	for(int i=1;i<=t;i++)
		a[S[i] - 'a']++;
		
	t = l - 1;
	for(int i=k;i>=0;i--) {
		if( t >= d[i] ) {
			for(int j=0;j<26;j++)
				a[j] -= c[i][j];
			t -= d[i];
		}
	}
	for(int i=1;i<=t;i++)
		a[S[i] - 'a']--;
	
	for(int i=0;i<26;i++) printf("%lld ", a[i]);
}

Measured memory_bytes: 2328
#include <stdio.h>

int main(void){
    int n,i,tp=0,hp=0,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        char t[100],h[100];
        scanf("%s",t);
        scanf("%s",h);
        for(k=0;k<100;k++){
            int tn=t[k];
            int hn=h[k];
            if(hn<96 || hn>123){
                if(tn>96 && tn<123){
                    tp+=3;
                    break;
                }else{
                    tp++;
                    hp++;
                    break;
                }
            }else if(tn<96 || tn>123){
                if(hn>96 && hn<123){
                    hp+=3;
                    break;
                }else{
                    tp++;
                    hp++;
                    break;
                }
            }else if(t[k]>h[k]){
                tp+=3;
                break;
            }else if(t[k]<h[k]){
                hp+=3;
                break;
            }
        }
    }
    printf("%d %d\n",tp,hp);
    return 0; /*0?????????*/
}

Measured memory_bytes: 596
// /*
// power code taken from geeks for geeks
// */
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 1000001LL
#define INF 1000000000LL
using namespace std;
typedef long long ll;
typedef long double ld;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
    return 1LL;

    ll P = power(k, p/2LL);
    P = (P * P) % MODD;

    if (p % 2 == 1)
    P = (P * k) % MODD;

return P;
}


struct p_str{
    ll a, b;
};


void solve(){
    ll N, W;
    cin >> N >> W;

    ll w[N + 1], v[N + 1];
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
    }

    ll dp[N + 1][W];
    memset(dp, 0, sizeof(dp));
    ll ans=0;
    for(ll i = 1; i <= N; i++){
        for(ll j = 0; j <= W; j++){
            dp[i][j]=dp[i - 1][j];
            if(j - w[i] >= 0){
                dp[i][j]=max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
            ans = max(ans, dp[i][j]);
        }
    }

    cout<<ans<<endl;

}



int main(){




    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;

    // init();

    // cin>>t;

    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 82492
#include<stdio.h>

int main(void){
    char number[1001];
    int i,sum;
    
    while(1){
        scanf("%s",number);
        
        if(number[0]=='0')
            break;
        for(i=0;number[i]!='\0';i++){
            sum+=number[i]-'0';
        }printf("%d\n",sum);
        sum=0;
    }return 0;
}

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

struct UnionFind{
    vector<int> par;
    vector<int> dep;

    UnionFind(int siz){
        par.assign(siz, 0);
        dep.assign(siz, 0);
        for(int i = 0; i < siz; i++){
            par[i] = i;
        }
    };

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(dep[x] < dep[y]) par[x] = y;
        else{
            par[y] = x;
            if(dep[x] == dep[y]) dep[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

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

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

int main(){
    int n; cin >> n;
    vector<long long> x(n), y(n);
    for(int i = 0; i < n ; i++) cin >> x[i] >> y[i];

    vector<edge> e;

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });

    for(int i = 0; i < ids.size()-1; i++){
        int u = ids[i], v = ids[i+1];
        e.push_back({u, v, x[v] - x[u]});
    }

    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    for(int i = 0; i < ids.size()-1; i++){
        int u = ids[i], v = ids[i+1];
        e.push_back({u, v, y[v] - y[u]});
    }

    sort(e.begin(), e.end(), comp);
    UnionFind uf(n);
    long long res = 0;
    for(auto E: e){
        int u = E.from, v = E.to;
        long long cost = E.cost;
        if(uf.same(u, v)) continue;
        uf.unite(u, v);
        res += cost;
    }
    cout << res << endl;
}

Measured memory_bytes: 8392
import java.io.BufferedReader
import java.io.InputStreamReader

data class Card(val suit: Char, val value: Char) {
    override fun toString(): String {
        return "$suit$value"
    }
}

fun bubbleSort(a: Array<Card>) {
    for (i in 0 until a.size) {
        for (j in a.size-1 downTo i+1) {
            if (a[j].value < a[j-1].value) {
                run { val t = a[j]; a[j] = a[j-1]; a[j-1] = t }
            }
        }
    }
}

fun selectionSort(a: Array<Card>) {
    for (i in 0 until a.size) {
        val minIdx = (i until a.size).minBy { a[it].value }
        minIdx?.let { val t = a[i]; a[i] = a[minIdx]; a[minIdx] = t }
    }
}

fun isStable(a: Array<Card>, b: Array<Card>) =
        (0 until a.size).all { it -> a[it].suit == b[it].suit }

fun main(args: Array<String>) {
    val a = BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())
            .drop(n = 1)
            .map { Card(it[0], it[1]) }
            .toTypedArray()


    val b = a.copyOf()

    bubbleSort(a)
    selectionSort(b)

    println(a.joinToString(" "))
    println("Stable")
    println(b.joinToString(" "))
    println(if (isStable(a, b)) "Stable" else "Not stable")
}


Measured memory_bytes: 31868
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
		cout << "Yes" << endl;
	}
	else if (S[0] == S[2] && S[1] == S[3] && S[0] !=S[1]) {
		cout << "Yes" << endl;
	}
	else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

// read to vector
// for example M_RTV(as, int, n) expands to the below:
// ```
// vector<int> as(n);
// for(int lcnt = 0; lcnt < n; lcnt++) cin >> as[lcnt];
// ```
#define M_RTV(ident, type, cnt) \
    do {\
        vector<type> ident(cnt);\
        for(int lcnt = 0; lcnt < cnt; lcnt++) cin >> ident[lcnt];\
    } while(false)

// shorthand for range
#define M_RG(ident) ident.begin(), ident.end()

// https://qiita.com/EqualL2/items/b4683db7ab4e90545bb2
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << int(log(n)/log(k))+1 << endl;
}


Measured memory_bytes: 512