akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++)
    cin >> s.at(i);
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++)
    cin >> t.at(i);
  
  vector<int> w(N+M);
  for (int i=0; i<N; i++) {
    if (w.at(i) == 0) {
      for (int j=i; j<N; j++) {
        if (s.at(j) == s.at(i))
          w.at(j) = i+1;
      }
      for (int j=0; j<M; j++) {
        if (t.at(j) == s.at(i))
          w.at(N+j) = i+1;
      }
    }
  }
  
  int x=0, y=0;
  for (int i=0; i<N+1; i++) {
    y=0;
    for (int j=0; j<N; j++)
      if (w.at(j) == i)
        y += 1;
    for (int j=0; j<M; j++)
      if (w.at(N+j) == i)
        y -= 1;
    if (y > x)
      x = y;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
string s;

int main(){
	int n;
	scanf("%d",&n); 
	cin>>s;
	if(s.size()>n){
		for(int i=0;i<n;i++){
			printf("%c",s[i]);
		}
		printf("...");
	}
	else cout<<s;
	return 0;
}





Measured memory_bytes: 3752
#include <bits/stdc++.h>
 
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define FOR(i, to) for (int i = 0; i < (to); ++i)
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
#define MOD 1000000007
#define INF 1000000000LL * 100000000LL
#define Nmax 202020

ll X,Y,Z;
string S;

int main() {
  cin >> X;
  cout << X * X << endl;

  return 0;
}
 


Measured memory_bytes: 256
# coding: utf-8
# 35

while True:
    H,W = map(int,input().split())
    if H==0 and W==0:
        break
    for j in range(1,H+1):
        if j%2==0:
            for i in range(1,W+1):
                if i%2==0:
                    print('#',end='')
                else:
                    print('.',end='')
            print()
        else:
            for i in range(1,W+1):
                if i%2==0:
                    print('.',end='')
                else:
                    print('#',end='')
            print()
    print()
    



Measured memory_bytes: 7008
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map( int, input().split() )
uf = UnionFind( N )
for i in range( M ):
  a, b = map( int, input().split() )
  uf.union( a - 1, b - 1 )
ret = 0
for i in range(N):
  ret = max( ret, uf.size(i))
print( ret )


Measured memory_bytes: 14496
A = list(map(int, input().split()))
A_sort = sorted(A)
max_A = A_sort[2]

if (max_A - A_sort[0])%2 == 0 and (max_A - A_sort[1])%2 == 0:
    print((max_A - A_sort[0])//2+(max_A - A_sort[1])//2)
elif (max_A - A_sort[0])%2 == 1 and (max_A - A_sort[1])%2 == 1:
    print((max_A - A_sort[1])//2+(max_A - A_sort[0])//2+1)
elif (max_A - A_sort[0])%2 == 1 or (max_A - A_sort[1])%2 == 1:
    print((max_A - A_sort[1])//2+(max_A - A_sort[0])//2+2)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

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

    string s;
    cin >> s;

    int r=0;
    for (int i=0;i<N;++i) {
        if (s[i]=='R') ++r;
    }

    cout << (r > (N-r) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    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();
    return f * x; 
}
int n, m, s[10], c[10];
int d[10];
void init(){
    n = read(), m = read();
    memset(d, -1, sizeof(d));
}
void solve(){
    for (int i = 1; i <= m; ++i){
        s[i] = read(), c[i] = read();
        if (d[s[i]] == -1) d[s[i]] = c[i];
        else if (d[s[i]] != c[i]) {
            printf("-1\n");
            return ;
        }
    }
    if (d[1] == 0 && n > 1) {
            printf("-1\n");
            return ;
        }
    if (d[1] == -1){
        if (n > 1) d[1] = 1;
        else d[1] = 0;
    } 
    for (int i = 2; i <= n; ++i)
        if (d[i] == -1) d[i] = 0;
    for (int i = 1; i <= n; ++i)
        putchar('0' + d[i]);
    putchar('\n');
}
int main(){
    init();
    solve();
    return 0;
}

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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c;
	if (a * b < c) {
		cout << a * b;
	}
	else {
		cout << c;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double t = 0;
    if(x<a*b/2){ // 
        double y = 2 * x / b;
        double as = asin(y / sqrt(b*b+y*y));
        t = as / M_PI * (double)180;
    }else{
        double l = (b - x/a) * 2;
        double as = asin(a / sqrt(l*l+a*a));
        t = as / M_PI * (double)180;
        // cout << l << ' ' << as << ' ' << t << endl;
    }
    

    t = 90 - t;
    cout << fixed << setprecision(10) << t << endl;
    return 0;
}
 
 


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k,q;
int a[2521];
int srt[2521];

pii b[2521];
int bit[2521];
void init(){
  REP(i,2521)bit[i]=0;
}
void add(int i,int x){
  for(;i<2521;i+=i&-i)bit[i]+=x;
}
int sum(int i){
  int ret = 0;
  for(;i>0;i-=i&-i)ret+=bit[i];
  return ret;
}

bool check(int lo, int hi){
  int m = 0;
  REP(i,n)if(lo<=a[i] && a[i]<=hi)b[m++]=pii(a[i], i);
  if(m<q)return false;
  sort(b,b+m);
  set<int> ngpos;
  ngpos.insert(-1);
  ngpos.insert(n);
  REP(i,n)if(a[i]<lo)ngpos.insert(i);
  init();
  int kos = 0;
  REP(i,m){
    int p = b[i].second;
    set<int>::iterator it = ngpos.lower_bound(p);
    int ri = *it;
    it--;
    int le = *it;
    int ad = sum(ri) - sum(le+1);
    if(ri-le-1>=k+ad){
      kos++;
      if(kos>=q)return true;
      add(p+1,1);
    }else{
      ngpos.insert(p);
    }
  }
  return false;
}

int main(){
  scanf("%d%d%d",&n,&k,&q);
  REP(i,n)scanf("%d",a+i);
  // srand(time(NULL));
  // REP(i,n)a[i] = rand();
  int ans = 1<<30;
  REP(i,n)srt[i] = a[i];
  sort(srt,srt+n);
  int high = 0;
  REP(i,n){
    CHMAX(high, i);
    while(high<n){
      if(check(srt[i], srt[high])){
        CHMIN(ans, srt[high]-srt[i]);
        break;
      }else{
        high++;
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 384
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    vector<int> cnt(10, 0);
    rep(i, 4) {
        int n;
        cin >> n;
        ++cnt[n];
    }
    
    if (cnt[1] && cnt[9] && cnt[7] && cnt[4]) cout << "YES\n";
    else cout << "NO\n";
    return;
}



Measured memory_bytes: 3608
// copied by Nurstan Duisengaliev
// skatal                        
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define int ll 
using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;                         

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
string a;
int d;
int kol1[10001][101];
int kol2[10001][101];
void solve () {
	cin >> a >> d;
	int n = sz (a);
	for (int i = 1; i <= 9; i ++) {
		kol1[1][i % d] ++;  \
		kol2[1][i % d] ++;
	}
	kol2[1][0] ++;
	for (int i = 1; i < n; i ++) {
		for (int j = 0; j < d; j ++) {
			for (int o = 0; o <= 9; o ++) {
				if (o == 0) {
					kol2[i + 1][j] += (kol2[i][j] % mod);
					kol2[i + 1][j] %= mod;		
				}
				else {
					kol2[i + 1][(j + o) % d] += (kol2[i][j] % mod);
				    kol1[i + 1][(j + o) % d] += (kol2[i][j] % mod);
				    kol1[i + 1][(j + o) % d] %= mod;
				    kol2[i + 1][(j + o) % d] %= mod;
				}
			}
		}
	}
	kol2[0][0] = 1;
	ll ans = 0;
	for (int i = 1; i < n; i ++) {
		ans += (kol1[i][0]);
		ans %= mod;		
	}
	int sum = 0;
	for (int i = 0; i < n; i ++) {
		if (i == 0) {
			for (int j = 1; j < a[i] - '0'; j ++) {
				ans += kol2[n - i - 1][(d - ((sum + j) % d)) % d];
				ans %= mod;		
			}
		}	
		else {
		    for (int j = 0; j < a[i] - '0'; j ++) {
		    	ans += kol2[n - i - 1][(d - ((sum + j) % d)) % d];
				ans %= mod;	
		    }
		}
		sum += a[i] - '0';
	}
	if (sum % d == 0) ans ++;
	ans %= mod;
	cout << ans << endl;
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 19388
D, G = map(int, input().split())
Q = []
for i in range(D):
    p, c = map(int, input().split())
    Q.append([p, c,(i+1)*100])
ans = 10**18
for i in range(2**D):
    state = format(i,'0%ib'%(D))
    value = 0
    count = 0
    for s,(p,c,v) in zip(state,Q):
        if s == '1':
            value += p*v + c
            count += p
    if value >= G:
        ans = min(ans,count)
    else:
        for s,(p,c,v) in zip(reversed(state),reversed(Q)):
            if s == '1':
                continue
            if (G-value) > v*(p-1):
                value += v*(p-1)
                count += p-1
            else:
                if (G-value)%v == 0:
                    c = (G-value)//v
                else:
                    c = int((G-value)/v)+1
                value += v*c
                count += c
                ans = min(ans,count)
                break
print(ans)

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

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

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

  long long int a[n+1], b[n];
  FOR(i,n+1)
    cin >> a[i];
  FOR(i, n)
    cin >> b[i];

  long long int res(0);
  FOR(i, n) {
    res += min(a[i], b[i]);
    if (b[i] > a[i]) {
      res += abs(max(0LL, a[i+1] - (b[i] - a[i])) - a[i+1]);
      a[i+1] = max(0LL, a[i+1] - (b[i] - a[i]));
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
from collections import deque
h, w = map(int, input().split())
maze = ''
for _ in range(h):
    maze += input() + '#'
n = h*(w+1)
graph = [[] for _ in range(n)]
dire = [-w-1, -1, 1, w+1]
for i in range(n):
    if maze[i]=='#':
        continue
    for j in dire:
        ind = i+j
        if ind < 0 or n <= ind or maze[ind]=='#':
            continue
        graph[i].append(ind)
que = deque()
def BFS(node):
    for i in graph[node]:
        if lengths[i]<0:
            lengths[i] = lengths[node]+1
            que.append(i)
    if len(que)>0:
        BFS(que.popleft())
starts = [i for i, j in enumerate(graph) if len(j)>0]
max_len = 0
for start in starts:
    lengths = [-1]*n
    lengths[start] = 0
    BFS(start)
    max_len = max(max_len, max(lengths))
print(max_len)

Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long X, long long Y, long long Z){
  cout << Z << " " << X << " " << Y << endl;
}

int main(){
  long long X;
  scanf("%lld",&X);
  long long Y;
  scanf("%lld",&Y);
  long long Z;
  scanf("%lld",&Z);
  solve(X, Y, Z);
  return 0;
}


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

int main(void){
    long long N,i,x,y,min;
    scanf("%lld",&N);
    min=N;
    for(i=2;i<=sqrt(N);i++)
        if(N%i==0){
            x=i;
            y=N/i;
            if(min>x+y-2)
                min=x+y-2;
        }
    if(min!=N)
        printf("%lld",min);
    else
        printf("%lld",N-1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<bool> dp(100001,false);
  for(int i=100;i<=105;i++)dp[i]=true;
  for(int i=106;i<=100001;i++)dp[i]=dp[i-100] || dp[i-101] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105];
  int ans=dp[n]?1:0;
  cout << ans << endl;
}


Measured memory_bytes: 3616
def main():
    A,B,C = list(map(int,input().split()))
    if A%2 == 0 or B%2 == 0 or C%2 == 0:
        print(0)
    else:
        print(min(A*C,A*B,C*B))

if __name__ == '__main__':
    main()

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

int main() {
  int A, B ;
  string op;
  cin >> A >> B ;

  if ( ( A * B ) % 2 == 0 ) {
  cout << "Even" << endl;
  }
  else  {
  cout << "Odd" << endl;
  }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MAX = 10000+10;
LL dp[MAX];

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

  int N;
  cin >> N;

  vector<pair<PLL,PLL>> xs(N);
  /*
  VL ws(N), ss(N), vs(N);
  REP(i,N) cin >> ws[i] >> ss[i] >> vs[i];
  */
  REP(i,N){
    cin >> xs[i].FF.SS >> xs[i].SS.FF >> xs[i].SS.SS;
    xs[i].FF.FF = xs[i].FF.SS + xs[i].SS.FF;
  }
/*
  VI ix(N);
  REP(i,N) ix[i] = i;
  sort(ALL(ix), [&](const int i, const int j){ return ws[i] + ss[i] <= ws[j] + ss[j];});
*/
  SORT(xs);

  LL ans = 0;
  REP(i,N){
    for(int w=xs[i].SS.FF;w>=0;--w){
      if(w + xs[i].FF.SS >= MAX) maxi(ans, dp[w] + xs[i].SS.SS);
      else maxi(dp[w+xs[i].FF.SS], dp[w] + xs[i].SS.SS);
    }
  }
  /*
  for(int i: ix){
    for(int w=ss[i];w>=0;--w){
      if(w + ws[i] >= MAX) maxi(ans, dp[w] + vs[i]);
      else maxi(dp[w+ws[i]], dp[w] + vs[i]);
    }
  }
  */
  REP(i,MAX) maxi(ans, dp[i]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;

int n,m;
vector<vector<int> >lang;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main() {
    cin>>n>>m;
    lang.resize(m+5);
    UnionFind unio(n);
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        for(int j=0;j<p;j++){
            int mm;
            cin>>mm;
            if(lang[mm].size())
                unio.unionSet(lang[mm][0], i);
            lang[mm].push_back(i);
        }
    }
    if(unio.size(0)!=n){
        cout<<"NO"<<endl;
    }else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll a,b,c;
  cin >> a >> b >> c;
  ll d =c-a-b;
  if(d>0 && d*d>4*a*b)	cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
const int mod = 1e9 + 7;
const int M = 4e3 + 11;
int n, f[M][M];
int a[N], b[N];
int fac[M<<1], inv[M<<1];
int cal(int a, int b){
    return 1LL * fac[a+b] * inv[a] % mod * inv[b] % mod;
}
int main(){
    cin>>n;
    int ans = 0;
    inv[0] = inv[1] = fac[0] = fac[1] = 1;
    for(int i = 2;i <= 8000; i++){ 
        fac[i] = 1ll * fac[i-1] * i % mod;
        inv[i] = mod - 1LL * mod / i * inv[mod%i] % mod;
    }
    for(int i = 2;i <= 8000; i++){
        inv[i] = 1ll * inv[i-1] * inv[i] % mod;
    }
    for(int i = 1;i <= n; i++){
        scanf("%d%d", &a[i], &b[i]);
        f[-a[i]+2000][-b[i]+2000]++;
    }
    for(int i = 0;i <= 4000; i++){
        for(int j = 0;j <= 4000; j++){
            if(!f[i][j])continue;
            int F = f[i][j];
            (f[i+1][j] += F) %= mod;
            (f[i][j+1] += F) %= mod;
        }
    }
    for(int i = 1;i <= n; i++){
        (ans += (mod - cal(a[i] << 1, b[i] << 1) + f[2000+a[i]][2000+b[i]]) % mod) %= mod;
    }
    ans = 1LL * ans * inv[2] % mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b) {
	return __gcd(a,b);
}
long long lcm(long long a,long long b) {
	return a*b/gcd(a,b);
}
int main ()
{
	long long n, m, t=0, q, i=0;
	cin>>n>>m;
	long long a[n+1];
	for(i=1; i<=n; i++){
		cin>>a[i];
		a[i]/=2;
	}
	long long k=1;
	for(i=1; i<=n; i++)
		k=lcm(a[i],k);
	for(i=1; i<=n; i++){
		t=0;
		while(a[i]%2==0){
			a[i]/=2;
			t++;
		}
		if(i==1)
		q=t;
		if(q!=t){
		cout<<"0";
		return 0;
		}
	}
	cout<<(m/k)-(m/(2*k))<<endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        int[][] seg = new int[n][n];
        for(int i = 0; i < m; i++)
            seg[sc.nextInt()-1][sc.nextInt()-1]++;

        for(int i = 1; i < n; i++) {
            seg[0][i] += seg[0][i-1];
            seg[i][0] += seg[i-1][0];
        }
        for(int i = 1; i < n; i++) {
            for(int j = 1; j < n; j++) {
                seg[i][j] += seg[i-1][j] + seg[i][j-1] - seg[i-1][j-1];
            }
        }

        for(int i = 0; i < q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            int cnt = 0;
            if(l == 1 || r == 1)
                cnt = seg[r-1][r-1];
            else
                cnt = seg[r-1][r-1] + seg[l-2][l-2] - seg[r-1][l-2] - seg[l-2][r-1];
            System.out.println(cnt);
        }


    }
}


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

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    vector<vector<LL>> v;
    vector<pair<LL,LL>> x;
    Problem(LL n):n(n),v (n,vector<LL>(2)),x(n){};

    void solve(){
        pair<int,int> argmax,argmin;
        LL maxi=0, mini=LINF;
        for(int i=0; i<n; ++i){
            for(int j=0; j<2; ++j){
                cin >> v[i][j];
                if(v[i][j]<mini)argmin={i,j},mini=v[i][j];
                if(v[i][j]>maxi)argmax={i,j},maxi=v[i][j];
            }
            x[i].first=max(v[i][0],v[i][1]);
            x[i].second=min(v[i][0],v[i][1]);
        }
        sort(x.begin(),x.end(),[](pair<LL,LL>&a, pair<LL,LL>&b){return a.second>b.second or (a.second==b.second and a.first>b.first);});
        multiset<LL> m;
        vector<pair<int,pair<int,int>>> intervals;
        for(int i=0; i<n; ++i){
            m.insert(x[i].first);
        }
        for(int i=0,ok=0; i<n-1; ++i){
            m.insert(x[i].second);
            m.erase(m.lower_bound(x[i].first));
            if(x[i].first==maxi)ok=1;
            if(ok)intervals.push_back({*m.rbegin()-*m.begin(),{*m.rbegin(),*m.begin()}});
        }
        sort(intervals.begin(),intervals.end());
        LL ans = LINF;
        //最大と最小を両方赤で塗る
        if(argmax.first!=argmin.first){
            //2つ青いボールが決まっている
            LL lb = min(v[argmax.first][!argmax.second],v[argmin.first][!argmin.second]);
            LL ub = max(v[argmax.first][!argmax.second],v[argmin.first][!argmin.second]);
            for(auto && i :intervals){
                if(i.second.first>=ub and i.second.second<=lb){
                    ans = min(ans,(maxi-mini)*(i.second.first-i.second.second));
                    break;
                }
            }
        }else{
            //最大と最小が同じ箱に入っていたら無理
        }
        //大きい方を赤、小さい方を青
        LL min_red = LINF, max_blue = 0;
        for(int i=0; i<n; ++i){
            min_red = min(min_red,max(v[i][0],v[i][1]));
            max_blue = max(max_blue,min(v[i][0],v[i][1]));
        }
        ans = min(ans, (maxi-min_red)*(max_blue-mini));
        cout << ans << "\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 28020
#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long  ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[100001];
vector<pair<ll, ll>> p;
int main() {
	ll n, m; cin >> n >> m;
	rep(i, 0, n)cin >> a[i];
	sort(a, a + n);

	rep(i, 0, m) {
		ll b, c; cin >> b >> c;
		p.push_back(make_pair(c, b));
	}
	sort(p.begin(), p.end());
	reverse(p.begin(), p.end());

	ll L = 0;
	ll ans = 0;
	for (vector<pair<ll, ll>>::iterator it = p.begin(); it != p.end(); it++) {
		ll R = it->second + L - 1;
		ll*  i = lower_bound(a + L, a + n, it->first);
		ll q = min(R, (ll)((i - a) - 1));

		if (q - L + 1 == 0)break;

		ans += (q - L + 1)*it->first;
		L += (q - L + 1);// it->second;
	}

	rep(i, L, n) ans += a[i];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3188
//https://beta.atcoder.jp/contests/abc112/tasks/abc112_c
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main() {
    int n;
    cin>>n;
    vector<LL> x(n),y(n),h(n);
    for(int i:range(n)){
        cin>>x[i]>>y[i]>>h[i];
    }
    LL latte,ei,beet;

    for(LL X:range(0,101)){
        for(LL Y:range(0,101)){
            vector<LL> H1;
            vector<LL> H2;
            for(int i:range(n)){
                LL diff = abs(X-x[i])+abs(Y-y[i]);
                if(h[i]>0)H1.push_back(diff+h[i]);
                else H2.push_back(diff);
            }
            sort(ALL(H1));
            sort(ALL(H2));
            if(H1.size()==0){
                latte=X;
                ei = Y;
                beet = H2.front();
            }
            else{
                if(H1.front()!=H1.back())continue;
                if(H2.size()>0){
                    if(H1.front()<=H2.front()){
                        cout<<X<<" "<<Y<<" "<<H1.front()<<endl;
                        return 0;
                    }
                }
                else{
                    cout<<X<<" "<<Y<<" "<<H1.front()<<endl;
                    return 0;
                }
            } 
        }
    }
    cout<<latte<<" "<<ei<<" "<<beet<<endl;

    return 0;
}


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

int N;
ll h[100010];
ll dp[100010];

ll rec(int i){
    
    if(dp[i] < INF) return dp[i];
    
    if(i == 0) return 0;
    
    ll res = INF;
    res = min(res, rec(i-1) + abs(h[i] - h[i-1]));
    if (i > 1) res = min(res, rec(i-2) + abs(h[i] - h[i-2]));
    
    return dp[i] = res;
}

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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N; cin >> N;
    int abc[N][3]; for(int i = 0; i < N; i++) for(int j = 0; j < 3; j++) cin >> abc[i][j];
    int dp[N+10][3]; for(int i = 0; i < N; i++) for(int j = 0; j < 3; j++) dp[i][j] = -INF;
    
    //dp初期化
    for(int i = 0; i < 3; i++) dp[0][i] = abc[0][i];
    
    //本番
    for(int i = 1; i < N; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(k == j) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j]);
            }
        }
    }
    
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < 3; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

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 N;
int v[100005][3];

int dp[100005][3];
int ans;

int main(){
    cin>>N;
    for(int i=0;i<N;++i)for(int j=0;j<3;++j)cin>>v[i][j];
    for(int i=0;i<3;++i)dp[0][i]=v[0][i];
    for(int i=0;i<N;++i){
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(j==k)continue;
                chmax(dp[i+1][k],dp[i][j]+v[i+1][k]);
            }    
        }
    }
    for(int i=0;i<3;++i)chmax(ans,dp[N-1][i]);
    cout<<ans<<endl;
}

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

int main() {
    int q[3];
    for(int i = 0; i < 3; i++) cin >> q[i];
    sort(q, q+3);
    if(q[0] == q[1]) cout << q[2] << endl;
    else cout << q[0] << endl;
    return 0;
}


Measured memory_bytes: 256
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

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

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) {
	int ans = 1;
	while (n) {
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int k,x; cin >> k >> x;
	For(i,x-k+1,x) cout << i << ' ';
	For(i,x,x+k) cout << i << ' ';
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    vector<set<int> > a(n);
    REP(i, n) {
        int k;
        cin >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            a[i].insert(tmp);
        }
    }

    set<int> ans;
    if (n == 1) cout << a[0].size() << '\n';
    else {
        set_intersection(a[0].begin(), a[0].end(),
                a[1].begin(), a[1].end(),
                inserter(ans, ans.end()));
        REP(i, n) {
            set<int> tmp;
            set_intersection(ans.begin(), ans.end(),
                    a[i].begin(), a[i].end(),
                    inserter(tmp, tmp.end()));
            ans.clear();
            ans = tmp;
        }
        cout << ans.size() << '\n';
    }
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,a;
	std::cin >> n >> a;
	if (n % 500 <= a) {
		std::cout << "Yes" << '\n';
	}
	else {
		std::cout << "No" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i = 0;
  string yn = "Yes";
  string tapdance;
  cin >> tapdance;
  while (i < tapdance.size()) {
    if (tapdance.at(i) == 'L' && i % 2 == 0) {
      yn = "No";
    }
    if (tapdance.at(i) == 'R' && i % 2 == 1) {
      yn = "No";
    }
    i++;
  }
  cout << yn << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s[60],x;
int t[60];
int main(){
	int i,n,sum = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> s[i] >> t[i];
	}
	cin >> x;
	int j = -1;
	for(i=0;i<n;i++){
		if(x==s[i]){
			j = i;
			break;
		}
	}
	for(i=j + 1;i<n;i++){
		sum += t[i];
	}
	cout << sum << endl;
}
			

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		int n;
		cin >> n;
		while (n) {
			vector<int> a(n);
			REP(i, n) {
				cin >> a[i];
			}
			vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
			RREP(i, n + 1) {
				FOR(j, i, n + 1) {
					if (j - i >= 2) {
						if (dp[i + 1][j - 1] == j - i - 2) {
							if (abs(a[i] - a[j - 1]) <= 1) {
								dp[i][j] = j - i;
							}
						}
					}
					int tmp = 0;
					FOR(k, i, j+1) {
						chmax(tmp, dp[i][k] + dp[k][j]);
					}
					chmax(dp[i][j], tmp);
					
				}
			}
			put(dp[0][n]);
			cin >> n;
		}
		
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}



Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    long long ans,ans1,ans2;
    ans=x*a+y*b;
        if(x>y)
        {
            ans1=y*2*c+(x-y)*a;
        }
        else
        {
            ans1=x*2*c+(y-x)*b;
        }
    //int d=abs(x-y);
        ans2=max(x,y)*2*c;
        cout<<min(ans,min(ans1,ans2))<<endl;
}


Measured memory_bytes: 256
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
p=10**9+7

A_=Counter(A)
A_=A_.most_common()

flag=N%2

for a in A_:
    if a[0]%2==flag:
        print(0)
        exit()
    elif a[0]==0 and a[1]!=1:
        print(0)
        exit()
    elif a[0]!=0 and a[1]!=2:
        print(0)
        exit()

ans=1
for i in range(N//2):
    ans*=2
    ans%=p
print(ans%p)

Measured memory_bytes: 16096
#include <iostream>
#include <string>
using namespace std;
#define REP(i,to) for(i=0;i<(to);i++)

int main() {
	int i, j, k, l;
	string S; cin >> S;
	int K; cin >> K;
	char ans;

	REP(i, 100) {
		if (S[i] != '1') {
			ans = S[i];
			break;
		}
	}

	if (i != 0 && i + 1 > K) {
		ans = '1';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int m = 1e9 + 7;
int n;
string s1, s2;
long long calc(int index, int num_c, int mode){
	if(index == n){
		return 1;
	}
	long long ans = 1;
	if(s1.at(index) == s2.at(index)){
		if(mode == 1){
			ans = (calc(index + 1, 2, 0)) % m;	
		}
		else{
			ans = (num_c * calc(index + 1, 2, 0)) % m;
		}
	}
	else{
		int x = 2;
		if(num_c == 3){
			x = 6;
		}
		if(mode == 1){
			x -= 3;
		}
		ans = (x * calc(index + 2, 3, 1)) % m;
		
	}
	return ans;
}
int main(int argc, char const *argv[])
{
	cin >> n;
	getline(cin, s1);
	getline(cin, s1);
	getline(cin, s2);
	cout << calc(0, 3, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

count_ab = 0
count_start_b = 0
count_finish_a = 0
count_start_b_finish_a = 0
for i in range(N):
    s = input()
    count_ab += s.count('AB')
    # print(s, s[0], s[-1])
    if s[0] == 'B' and s[-1] == 'A':
        count_start_b_finish_a += 1
    elif s[0] == 'B':
        count_start_b += 1
    elif s[-1] == 'A':
        count_finish_a += 1

# print(count_start_b_finish_a, count_finish_a, count_start_b)

if not count_start_b_finish_a:
    print(count_ab + min(count_finish_a, count_start_b))
elif max(count_finish_a, count_start_b) > 0 and count_start_b_finish_a:
    print(count_ab + count_start_b_finish_a + min(count_finish_a, count_start_b))
elif count_start_b_finish_a:
    print(count_ab + count_start_b_finish_a - 1)

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n;
	cin>>n;
	long long cnt=0;
	long long k=0;
	while(cnt<=0 || cnt%360!=0){
		cnt+=n;
		k++;
	}

	cout<<k<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[5000]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

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

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }

int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    int a, b, n, m;
    while (cin >> a >> b >> n >> m) {
        const int MOD = 998244353;
        vector<vector<ll>> f(n + 2, vector<ll>(m + 2, 0));
        f[a][b] = 1;
        auto addmod = [&](ll& x, const ll d) {
            x += d;
            if (x >= MOD) {
                x -= MOD;
            }
            if (x < 0) {
                x += MOD;
            }
        };
        for (int i = a; i <= n; ++i) {
            for (int j = b; j <= m; ++j) {
                if (i == a && j == b) {
                    continue;
                }
                addmod(f[i][j], f[i - 1][j] * j % MOD);
                addmod(f[i][j], f[i][j - 1] * i % MOD);
                addmod(f[i][j], -f[i - 1][j - 1] * (i - 1) * (j - 1) % MOD);
            }
        }
        cout << f[n][m] << "\n";
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 73564
<?php
$n = trim(fgets(STDIN));
$list = explode(' ', trim(fgets(STDIN)));

function chmin($main, $compare) {
    if ($main > $compare) {
        $mian = $compare;
    }
}
$dp = array_fill(0, $n, INF);
$dp[0] = 0;
for ($i = 0; $i < $n - 1; $i++) {
    if ($i < $n - 2) {
        $dp[$i + 2] = min($dp[$i + 2], $dp[$i] + abs($list[$i + 2] - $list[$i]));
    }
    $dp[$i + 1] = min($dp[$i + 1], $dp[$i] + abs($list[$i + 1] - $list[$i]));
}

echo $dp[$n - 1];



Measured memory_bytes: 16884
while True:
    a=input();t={};s=""
    if a==0:break
    for i in range(a):
        q=raw_input().split()
        t[q[0]]=q[1]
    for j in range(input()):
        q=raw_input().strip()
        if q in t: s+=t[q]
        else: s+=q
    print s

Measured memory_bytes: 7372
/* Complete Binary Tree */
#include <stdio.h>
#define MAX 250

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

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

    for(i=0; i<n; i++){
        printf("node %d: key = %d, ", i+1, a[i]);

        if(i){
            printf("parent key = %d, ", a[(i+1)/2-1]);
        }
        if(2*i+1 < n){
            printf("left key = %d, ", a[2*i+1]);
        }
        if(2*i+2 < n){
            printf("right key = %d, ", a[2*i+2]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
a, b, c = input().split()
k = int(input())

for _ in range(k):
  if int(a) >= int(b):
    b = int(b) * 2
  else:
    c = int(c) * 2
    
if int(a) < int(b) and int(b) < int(c):
  print("Yes")
else:
  print("No")

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

using namespace std;

const int MAX = 1e5 + 10;
int n;
int q, k;
vector<pair<int, long long>> G[MAX];
long long minDist[MAX];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;;
    scanf("%d%d%d", &a, &b, &c);
    a--;b--;
    G[a].emplace_back(make_pair(b, c));
    G[b].emplace_back(make_pair(a, c));
  }
  scanf("%d%d", &q, &k);
  k--;
  fill(minDist, minDist + MAX, 1e18);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
  pq.push({0, k});
  minDist[k] = 0;
  while (!pq.empty()) {
    auto now = pq.top(); pq.pop();
    for (auto nxt : G[now.second]) {
      const long long nxtCost = now.first + nxt.second;
      if (minDist[nxt.first] <= nxtCost) {
        continue;
      }
      minDist[nxt.first] = nxtCost;
      pq.push({nxtCost, nxt.first});
    }
  }
  for (int i = 0; i < q; i++) {
    cerr << "problem " << i + 1 << " solved" << endl;
    int x, y;
    scanf("%d%d", &x, &y);
    x--;y--;
    cout << minDist[x] + minDist[y] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 11120
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    X = list(map(int, readline().rstrip().split()))

    if N >= M:
        print(0)
        return

    X.sort()
    X = [abs(X[i+1]-X[i]) for i in range(M-1)]
    X.sort()
    ans = sum(X)
    for i in range(N-1):
        ans -= X[-i-1]
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  char buff[10];
  scanf("%d",&n);
  for(int cas=0;cas<n;cas++){
    cin >> buff;
    sort(buff,buff+8);
    //cout << buff << endl;
    int maxs,mins;
    maxs = mins = 0;
    for(int i=0;i<8;i++){
      maxs*= 10;
      mins*= 10;
      maxs+= buff[7-i];
      mins+= buff[i];
    }
    cout << maxs-mins << endl;
  }
  return 0;
}

Measured memory_bytes: 3088