akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1050
#define mod 1000000007
int head[N],cnt,s[N*2][3],fa[N],v[N*2],as,n,m,s1,s2,is[N*2];
long long su;
struct edge{int t,next,v;}ed[N*2];
void adde(int f,int t,int v){ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;ed[++cnt]=(edge){f,head[t],v};head[t]=cnt;}
int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}
bool cmp(int i,int j){return s[i][2]<s[j][2];}
void dfs(int u,int fa,int t,int v){if(u==t){as=v;return;}for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u,t,max(ed[i].v,v));}
int main()
{
	scanf("%d%d%lld",&n,&m,&su);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)scanf("%d%d%d",&s[i][0],&s[i][1],&s[i][2]),v[i]=i;
	sort(v+1,v+m+1,cmp);
	for(int i=1;i<=m;i++)if(finds(s[v[i]][0])!=finds(s[v[i]][1]))is[v[i]]=1,fa[finds(s[v[i]][0])]=finds(s[v[i]][1]),su-=s[v[i]][2],adde(s[v[i]][0],s[v[i]][1],s[v[i]][2]);
	if(su<0)printf("0");
	else
	{
		for(int i=1;i<=m;i++)if(!is[i])
		{
			as=0;dfs(s[i][0],0,s[i][1],0);
			int tp=s[i][2]-as;
			if(tp==su)s1++;
			if(tp>su)s2++;
		}
		if(su==0)
		{
			int as=0,st1=1,st2=1;
			for(int i=1;i<=m;i++)st1=st1*2%mod;
			for(int i=1;i<=m-n+2-s1;i++)st2=st2*2%mod;
			as=(st1-st2+mod)%mod;
			printf("%d\n",as);
		}
		else
		{
			int as=0,st1=1,st2=1;
			for(int i=1;i<=s1;i++)st1=st1*2%mod;
			for(int i=1;i<=s2;i++)st2=st2*2%mod;
			as=2ll*(st1-1)*st2%mod;
			printf("%d\n",as);
		}
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  int n;
  cin >> n;

  int ans;
  if(n % 2 == 0) ans = n;
  else ans = 2 * n;

  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;

void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    vi cc(26);
    REPS(c, s) cc[(int)(c - 'a')]++;

    auto check = [&](string& str, char ch) -> bool {
        REPS(x, str) if (x != ch) return false;
        return true;
    };

    int ans = INF;
    REP(i, 26) {
        char target = (char)('a' + i);
        if (cc[i] == 0) continue;
        string t = s;
        int cnt = 0;
        while (!check(t, target)) {
            cnt++;
            int m = sz(t);
            string u;
            REP(i, m - 1) {
                if (t[i] == target or t[i + 1] == target) u += target;
                else u += t[i];
            }
            t = u;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    string s;
    cin >> s;
    int state = 0;
    for (char c : s)
    {
        if (state == 0 && c == 'C')
        {
            state++;
        }
        if (state == 1 && c == 'F')
        {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 200000;
int bit[N + 10];
void update(int idx, int val, int lim){
    while(idx <= lim){
        bit[idx] += val;
        idx += idx & -idx;
    }
}
int query(int idx){
    int ans = 0;
    while(idx){
        ans += bit[idx];
        idx -= idx & -idx;
    }
    return ans;
}
bool check(vector<int> a, int x){
    int sum, n = a.size() - 1;
    long long cnt = 0;
    for(int i = 1; i <= n; i++){
        a[i] = (a[i] >= x ? 1 : -1);
    }
    for(int i = 0; i <= 2 * n + 1; i++){
        bit[i] = 0;
    }
    sum = n + 1;
    for(int i = 0; i <= n; i++){
        sum += a[i];
        cnt += query(sum);
        update(sum, 1, 2 * n + 1);
    }
    long long N = 1LL * n * (n + 1) >> 1;
    return (cnt >= N - N / 2);
}
int main(){
    int n, ans = -1;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int low = 1, high = 1e9, mid;
    while(low <= high){
        mid = (low + high) >> 1;
        if(check(a, mid)){
            ans = mid;
            low = mid + 1;
        }else{
            high = mid - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int a,b;
    cin >> a>>b;
    cout << max(a-2*b,0)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;
// bool operator<(P &lhs,P &rhs)
// {
// 	if(lhs.first==rhs.first)
// 		return lhs.second>rhs.second;
// 	else
// 		return lhs.first<rhs.first;
// }
int dp[3001][6001];
P ab[3000];
int main()
{
	int n,t;
	int ans=0;
	cin>>n>>t;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		ab[i]=P(a,b);
	}
	sort(ab,ab+n);
	fill(dp[0],dp[3001],-1);
	dp[0][0]=0;
	for(int i=1;i<n+1;i++)
	{
		for(int j=0;j<6001;j++)
		{
			if(dp[i-1][j]!=-1)
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j]);
				if(j<t)
				{
					dp[i][j+ab[i-1].first]=max(dp[i][j+ab[i-1].first],dp[i-1][j+ab[i-1].first]);
					dp[i][j+ab[i-1].first]=max(dp[i][j+ab[i-1].first],dp[i-1][j]+ab[i-1].second);
				}
			}
		}
	}
	for(int i=0;i<6001;i++)
		ans=max(dp[n][i],ans);
	cout<<ans<<endl;
	return 0;
}

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



int main() {
    string S;
    cin >> S;
    vector<string> add = {"dream", "dreamer", "erase", "eraser"};
    reverse(S.begin(), S.end());
    rep(i,4) reverse(add.at(i).begin(), add.at(i).end());
    int left = 0;
    for (; left < S.size();) {
        rep(i,4) {
            bool ok = true;
            rep(j,add.at(i).size()) {
                if (add.at(i).at(j) != S.at(left + j)) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                left += add.at(i).size();
                break;
            } else if (i == 3) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}



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

int main() {
  string S, T = "ACGT";
  cin >> S;
  S += ' ';
  int ans = 0;
  for (int i = 0, cnt = 0; i < S.size(); i++) {
    if ((int)T.find(S.at(i)) == -1) cnt = 0;
    else cnt++;
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a=I()
  s=S()

  if 3200<=a:
    return s
  return 'red'

# main()
print(main())


Measured memory_bytes: 6864
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		int ans = 0;
		ArrayList<Integer> intList = new ArrayList<Integer>();

		for (int i = 0; i < N;i ++ ){
			intList.add(sc.nextInt());
		}
		 
		 Collections.sort(intList);
		 
		int tyukan = N / 2;
		if(intList.get(tyukan - 1)==intList.get(tyukan)){
		}else{
			ans = intList.get(tyukan) - intList.get(tyukan - 1); 
		}

		System.out.println(ans);

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 57444
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    char a,b,c,d;
    a =S.at(0);
    b =S.at(1);
    c =S.at(2);
    d =S.at(3);
    if(((a==b)&&(c==d)&&(a!=c))||((a==c)&&(b==d)&&(a!=b))||((a==d)&&(b==c)&&(a!=c))){
        cout << "Yes"<<endl;
    }
    else{
        cout << "No"<<endl;
    }
        
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define inf (1e9);
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m),c(m);
    ll g[n][n];
    rep0(i, n)rep0(j, n){
        if(i == j)g[i][j] = 0;
        else g[i][j] = inf;
    }
    
    rep0(i, m){
        cin >> a[i] >> b[i] >> c[i];
        --a[i];
        --b[i];
        g[a[i]][b[i]] = min(g[a[i]][b[i]],c[i]);
        g[b[i]][a[i]] = min(g[b[i]][a[i]],c[i]);
    }
    
    rep0(k,n)rep0(i, n)rep0(j, n)if(g[i][k] + g[k][j] < g[i][j])g[i][j] = g[i][k] + g[k][j];
    ll ans = m;
    rep0(i, m){
        bool f = false;
        rep0(j, n)if(g[j][a[i]]+c[i]==g[j][b[i]]) f = true;
        if(f)--ans;
    }
    pf(ans);
    return 0;
}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

inline int Pow(int a, int k) {
  int s = 1; 
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void preprocess() {
}

void debug() {
  //  44gg
  if (true) {
  
  }
}



void solve() {
  preprocess();
  // 50gg
  int n, m, c; 
  cin >> n >> m >> c;
  int b[m];
  FOR(i, 0, m) {cin >> b[i];}
  int a[n][m];
  FOR(i, 0, n) FOR(j, 0, m) {cin >> a[i][j];}
  int res = 0;
  FOR(i, 0, n) {
    int cur = c;
    FOR(j, 0, m) {cur += a[i][j] * b[j];}
    if (cur > 0) {res++;}
  }
  cout << res << endl;
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

void output() {

}

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--) 
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define  fast   ios_base::sync_with_stdio(false); cin.tie(NULL);
int main(){
    fast;
    long long int n,am=0;
    cin>>n;
    vector<long long int>a;
    for(int i=0;i<n;i++){
        long long int s;
        cin>>s;
        a.push_back(s);
    }
    
    sort(a.begin(),a.end());
    for(long long int i=0;i<n;i++){
        for(long long int j=i+1;j<n;j++){
            for(long long int z=j+1;z<n;z++){
                if((a[i]!=a[z] && a[i] != a[j] && a[j]!=a[z]) && a[i]+a[j]>a[z]){
                    am++;
                    //cout<<a[i]<<" "<<a[j]<<" "<<a[z]<<endl;
                }
            }
        }
    }
    cout<<am;
}

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

int main() {
  int N;
  cin>>N;
  vector<int>d(N);

rep(i,N){
    cin>>d.at(i);
    }

    sort(d.begin(), d.end());
    
    int res,bef;
    res=0;
    bef=0;
    
    rep(i,N){
    if(bef!=d.at(i)){res++;bef=d.at(i);}
    }
    cout<<res<<endl;
}


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s, t; cin >> s >> t;
  vector<string> res;
  bool ok = true;
  REP(i, SZ(s) - SZ(t) + 1) {
    ok = true;
    REP(j, SZ(t)) {
      if(s[i+j] != t[j] && s[i+j] != '?') {
        ok = false;
        break;
      }
    }
    if(ok) {
      string tmps = s;
      REP(j, SZ(tmps)) {
        if(tmps[j] == '?') {
          if(j < i || i+SZ(t)-1 < j) {
            tmps[j] = 'a';
          } else {
            tmps[j] = t[j-i];
          }
        }
      }
      res.pb(tmps);
    }
  }

  if(SZ(res) == 0) {
    cout << "UNRESTORABLE" << endl;
  } else {
    sort(ALL(res));
    cout << res[0] << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

const int N_max=100000;

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int N,M,x,y,cn[100001];
	bool check[100001];

	REP(i,100001){
		cn[i]=1; check[i]=false;
	}
	check[1]=true;
	cn[1]=1;

	cin>>N>>M;
	REP(i,M){
		cin>>x>>y;
		cn[x]--; cn[y]++;
		if(check[x]){
			if(cn[x]==0) check[x]=false;
			check[y]=true;
		}
	}
	int result=0;
	FOR(i,1,N+1) if(check[i]) result++;
	print(result);
	return 0;
}





Measured memory_bytes: 768
def ls_ternary(n, limit):
  ls = ["3"*n]
  while int(ls[-1]) <= limit and len(ls) < 3**n:
    ls.append(ternary_plus(ls[-1], 1))
    
  return ls[:-1]

def ternary_plus(chars, d):
  n = len(chars)
  tg = chars[n-d]
  if tg=='7':
    return ternary_plus(chars[:n-d]+'3'+chars[n-d+1:], d+1)
  else:
    if tg=='3':
      nxt = '5'
    else:
      nxt = '7'
    return chars[:n-d] + nxt + chars[n-d+1:]

s = input()
l = len(s)
hs = []
for i in range(l):
  if i+1<3:
    hs.append(0)
  else:
    hs.append(3**(i+1)-3*(2**(i+1))+3)

if l<3:
  print(0)
elif l==3:
  print(len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s))))))
else:
  a = len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s)))))
  print(a+sum(hs[:l-1]))


Measured memory_bytes: 4692
# coding: utf-8

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sumB = sum(b)
sumC = 0
for i in range(n-1):
    if a[i+1] - a[i] == 1:
        sumC += c[a[i]-1]
        
print(sumB+sumC)

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

int main(){
  string s;
  cin>>s;
  if(s=="SUN") cout<<7<<endl;
  if(s=="MON") cout<<6<<endl;
  if(s=="TUE") cout<<5<<endl;
  if(s=="WED") cout<<4<<endl;
  if(s=="THU") cout<<3<<endl;
  if(s=="FRI") cout<<2<<endl;
  if(s=="SAT") cout<<1<<endl;
}

Measured memory_bytes: 256
base = 127
mask = (1 << 32) - 1

def calc_hash(lstr, pl, tl):
    dl = tl - pl
    tmp = set()

    d = 1
    for _ in range(pl):
        d = (d * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + lstr[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - d * lstr[i] + lstr[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
dic = dict()
a = []
for pp in ps:
    if pp in dic:
        a.append(dic[pp])
        continue
    p = [ord(c) for c in pp]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(19, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
#    print("hb", keys, h[bs])
    a.append(1 if keys.issubset(h[bs]) else 0) #keysがh[bs]に含まれるか
    dic[pp] = a[-1]
print('\n'.join(map(str, a)))




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

int field[1000][1000];

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;

  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      if (s[j] == '#') {
        field[i][j] = -1;
      } else {
        field[i][j] = 0;
      }
    }
  }

  // rep(i, h) { rep(j, w) cout << field[i][j] << " "; cout << endl; }

  queue<P> que[2];
  que[0].push( make_pair(dh, dw) );
  que[1].push( make_pair(dh, dw) );
  field[dh][dw] = 1;
  int phase = 1;
  int currentY, currentX;
  while ( !que[0].empty() || !que[1].empty() ) {

    int queLength = que[0].size();

    while ( !que[0].empty() ) {
      currentY = que[0].front().first; currentX = que[0].front().second;
      que[0].pop();
      if (currentX > 0) {
        // left
        if (field[currentY][currentX - 1] == 0) {
          field[currentY][currentX - 1] = phase;
          que[0].push( make_pair(currentY, currentX - 1) );
          que[1].push( make_pair(currentY, currentX - 1) );
          queLength++;
        }
      }
      if (currentX + 1 < w) {
        // right
        if (field[currentY][currentX + 1] == 0) {
          field[currentY][currentX + 1] = phase;
          que[0].push( make_pair(currentY, currentX + 1) );
          que[1].push( make_pair(currentY, currentX + 1) );
          queLength++;
        }
      }
      if (currentY > 0) {
        // up
        if (field[currentY - 1][currentX] == 0) {
          field[currentY - 1][currentX] = phase;
          que[0].push( make_pair(currentY - 1, currentX) );
          que[1].push( make_pair(currentY - 1, currentX) );
          queLength++;
        }
      }
      if (currentY + 1 < h) {
        // down
        if (field[currentY + 1][currentX] == 0) {
          field[currentY + 1][currentX] = phase;
          que[0].push( make_pair(currentY + 1, currentX) );
          que[1].push( make_pair(currentY + 1, currentX) );
          queLength++;
        }
      }
    }

    phase++;
    rep(_, queLength) {
      int y = que[1].front().first, x = que[1].front().second;
      que[1].pop();
      for (int i = -2; i <= 2; i++) for (int j = -2; j <= 2; j++) {
        int nextY = y + i, nextX = x + j;
        //cout << nextY << " " << nextX << endl;
        if (nextY >= 0 && nextY < h && nextX >= 0 && nextX < w) {
          if ( field[nextY][nextX] == 0 ) {
            //cout << "pushed" << endl;
            field[nextY][nextX] = phase;
            que[0].push( make_pair(nextY, nextX) );
            que[1].push( make_pair(nextY, nextX) );
          }
        }
      }
    }
    //rep(i, h) { rep(j, w) cout << field[i][j] << " "; cout << endl; } cout << endl;

  }

  cout << field[ch][cw] - 1 << endl;
  return 0;
}
/*
*/


Measured memory_bytes: 7488
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#include <string>

using namespace std;

int main(){
    bool fs = true;
    for (; ;) {
        int N;
        cin >> N;
        if (N==0) {
            break;
        }
        if (!fs) cout << endl;
        if (fs) fs = false;
        int mi=100;
        int c10=0,c50=0,c100=0,c500=0;
        vector<int> coin(4);
        cin >> coin[0] >> coin[1] >> coin[2] >> coin[3]; //10 50 100 500
        for (int i=0; i<=coin[0]; i++) {
            for (int j=0; j<=coin[1]; j++) {
                for (int k=0; k<=coin[2]; k++) {
                    for (int l=0; l<=coin[3];l++) {
                        int hoge = i*10+j*50+k*100+l*500-N;
                        int c = hoge/500 + (hoge%500)/100 +(hoge%100)/50 + (hoge%50)/10;
                        int m = coin[0]+coin[1]+coin[2]+coin[3]-i-j-k-l+c;
                        if (l&&hoge/500)  continue;
                        if (k&&hoge%500/100) continue;
                        if (j&&hoge%100/50) continue;
                        if (i&&hoge%50/10) continue;
                        if (hoge >= 0 && mi > m) {
                            mi = m;
                            c10 = i;
                            c50 = j;
                            c100 = k;
                            c500 = l;
                        }
                    }
                }
            }
        }
        if (c10) cout << 10 << " " << c10 << endl;
        if (c50) cout << 50 << " " << c50 << endl;
        if (c100) cout << 100 << " " << c100 << endl;
        if (c500) cout << 500 << " " << c500 << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    string s, t;
    cin >> s >> t;
    cout << t << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; typedef long long  ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
const ll M = ll(1e9 + 7);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{os << "("; os << v.first << ", " << v.second << ")"; return os;}
/***********************************************************************/
ll dp[1000000][4];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    vector<vector<ll>> a;
    for (ll i = 1; i <= n; i++)
    {
        ll x, y, z;
        cin >> x >> y >> z;
        a.push_back({x, y, z});
    }
    dp[0][0] = max(a[0][1], a[0][2]);
    dp[0][1] = max(a[0][0], a[0][2]);
    dp[0][2] = max(a[0][0], a[0][1]);
    for (ll i = 1; i < n; i++)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}

Measured memory_bytes: 9776
#include <bits/stdc++.h>
#define Cout(x)        cout << #x << " " << x << endl
#define ld long double
#define ll long long
#define vll vector<ll>
#define pll pair<ll ,ll >
#define vpll vector< pll >
#define pb push_back
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define fr(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define fr1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define frr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define frab(i,a,b,c) for(ll (i) = a ; (i) < (b) ; (i)+=(c))
#define print(v) for( auto it: v) cout<<it<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll A[300005];
int main()
{
	ios;
 
	ll a, b, c, d, n, m, k,   q;


	cin >> a >> b >> c >> d;
	ll ans = a * d;
	ans = max(ans, b * d);
	ans = max(ans, a * c);
	ans = max(ans, b * c);
	cout << ans << endl;

}


Measured memory_bytes: 3644
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var (
	N int
	A int
	B int
	C int
)

var l []int

func main() {
	sc.Split(bufio.ScanWords)
	N, A, B, C = nextInt(), nextInt(), nextInt(), nextInt()
	// fmt.Scan(&N, &A, &B, &C)
	l = make([]int, N)
	for i := 0; i < N; i++ {
		l[i] = nextInt()
	}

	fmt.Println(dfs(0, 0, 0, 0))

}

func dfs(i, a, b, c int) int {
	// fmt.Println(l)
	if i == N {
		if a == 0 || b == 0 || c == 0 {
			return 1000000000
		}
		return abs(a-A) + abs(b-B) + abs(c-C)
	}

	res := dfs(i+1, a, b, c)

	if a != 0 {
		chmin(&res, dfs(i+1, a+l[i], b, c)+10)
	} else {
		chmin(&res, dfs(i+1, a+l[i], b, c))
	}

	if b != 0 {
		chmin(&res, dfs(i+1, a, b+l[i], c)+10)
	} else {
		chmin(&res, dfs(i+1, a, b+l[i], c))
	}

	if c != 0 {
		chmin(&res, dfs(i+1, a, b, c+l[i])+10)
	} else {
		chmin(&res, dfs(i+1, a, b, c+l[i]))
	}
	return res
}

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func abs(a int) int {
	if a < 0 {
		return -1 * a
	}

	return a
}


Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>

int main(void) {
  char ch;
  while(1) {
    scanf("%c", &ch);
    if (islower(ch)) {
      printf("%c", toupper(ch));
    } else {
      printf("%c", tolower(ch));
    }
    if (ch == '\n') break;
  }
}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char ch; int ret=0; 
	while (cin>>ch)
		ret=(ch=='+'?ret+1:ret-1);
	cout<<ret<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int k = stdin.nextInt();
		
		
		
		
		
		if(n % k == 0)
			System.out.println("0");
		else
			System.out.println("1");
		
	}

}

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

const ll INF = 1e18;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	vector<ll> v(n + 1), pre(n + 1);
	vector< vector<ll> > dp(n + 1, vector<ll>(n + 1, INF));

	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		dp[i][i] = 0;
		pre[i] = pre[i - 1] + v[i];
	}
	for (int i = n; i > 0; i--) {
		for (int j = i; j <= n; j++) {
			for (int k = i; k < j; k++) {
				ll temp = dp[i][k] + dp[k + 1][j] + pre[j] - pre[i - 1];
				dp[i][j] = min(temp, dp[i][j]);

			}
		}
	}
	cout << dp[1][n] << '\n';
	return 0;
}

Measured memory_bytes: 4876
#include<stdio.h>

int main(void)
{
  int N;
  scanf("%d", &N);

  char c[N];
  char dummy;
  scanf("%c", &dummy);
  for(int i=0;i<N;i++){
    scanf("%c", &c[i]);
  }

  int a=0, b=0;
  for(int i=0;i<N;i++){
    if(c[i]=='R')a++;
  }
  int ans = a;
  int now;
  for(int i=0;i<N;i++){
    if(c[i]=='R') a--;
    else b++;

    if(a<b) now = b;
    else now = a;

    if(now<ans) ans = now;
  }

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

  return 0;
}


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

int main()
{
  ll L, R;
  cin >> L >> R;
  if (R * L < 2019) {
    cout << L * (L + 1) << endl;
    return 0;
  }

  ll mn = LLONG_MAX;
  for (ll i = L; i <= R; i++) {
    for (ll j = i + 1; j <= R; j++) {
      if (mn > (i * j) % 2019) {
        mn = (i * j) % 2019;
        if (mn == 0) {
          cout << mn << endl;
          return 0;
        }
      }
    }
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 300;

int n;
int a[MaxN + 5];
typedef pair <int, int> Pi;

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		vector < pair<int, int> > ans;
		int Max = 0, Maxpos = 1;
		for(int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
			if(abs(a[i]) > abs(Max)) {
				Max = a[i];
				Maxpos = i;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(i == Maxpos) continue;
			ans.push_back(Pi(Maxpos, i));
		}
		if(Max > 0) {
			for(int i = 2; i <= n; i++)
				ans.push_back(Pi(i - 1, i));
		}
		else if(Max < 0) {
			for(int i = n - 1; i >= 1; i--)
				ans.push_back(Pi(i + 1, i));
		}
		printf("%d\n", ans.size());
		for(int i = 0; i < ans.size(); i++)
			printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}

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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  int n;
  cin >> n;
  int wild = 0;
  for (int bit = 0; bit < n; bit++) {
    wild |= (1<<bit);
  }
  int cond[n];
  int mask[n];
  int m;
  int x, y;
  for (int i = 0; i < n; i++) {
    cond[i] = wild;
    mask[i] = 0;
    cin >> m;
    for (int j = 0; j < m; j++) {
      cin >> x >> y;
      cond[i] &= ~((y^1)<<(x-1));
      mask[i] |= (1<<(x-1));
    }
  }
  int ans = 0;
  bool sat;
  for (int i = 0; i <= wild; i++) {
    sat = true;
    for (int j = 0; j < n && sat; j++) {
      if (i & (1<<j)) {
        if ((i&mask[j]) != (cond[j]&mask[j])) {
          sat = false;
        }
      }
    }
    if (sat) {
      if (ans < __builtin_popcount(i)) {
        ans =  __builtin_popcount(i);
      }
    }
  }

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


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

using namespace std;

void solve() {
    int n;
    cin >> n;
    map<int, int> odd, even;
    for (int i = 0; i < n; i++) {
        int v; cin >> v;
        if (i % 2 == 0) even[v]++;
        else odd[v]++;
    }

    vector<pair<int, int> > vtodd, vteven;
    for (auto x : odd) vtodd.push_back({x.second, x.first});
    for (auto x : even) vteven.push_back({x.second, x.first});
    sort(vtodd.rbegin(), vtodd.rend());
    sort(vteven.rbegin(), vteven.rend());

    int ans = n;
    for (int i = 0; i < min((int)vtodd.size(), 2); i++) {
        for (int j = 0; j < min((int)vteven.size(), 2); j++) {
            if (vtodd[i].second == vteven[j].second) {
                ans = min(ans, n - vtodd[i].first);
                ans = min(ans, n - vteven[j].first);
            }
            else {
                ans = min(ans, n - vtodd[i].first - vteven[j].first);
            }
        }
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


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

int main(){
    int x;
    cin >> x;
    int memo1 = x / 1000;
    int memo2 = (x / 100) % 10;
    int memo3 = (x % 100) / 10;
    int memo4 = x % 10;
    if(memo1 == memo2 && memo2 == memo3){
        cout << "Yes" << endl;
    }
    else if(memo2 == memo3 && memo3 == memo4){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
n,T=map(int,input().split())
c = [ list(map(int,input().split())) for i in range(n)] 
t = []
for i in range(n):
  if c[i][1] <= T:
    t.append(c[i][0])
if len(t) == 0:
  print('TLE')
else:
  print(min(t))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1000000007;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	cout<<min(a,k)-max(k-a-b,0ll)<<endl;
}


Measured memory_bytes: 3612
n, x = map(int, input().split())
a, p = [1] * (n + 1), [1] * (n + 1)
for i in range(1, n + 1):
    a[i] = 2*a[i - 1] + 3
    p[i] = 2*p[i - 1] + 1
def f(n, x):
    if n == 0:
        return 1 if x else 0
    if x == 1:
        return 0
    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    elif x == a[n - 1] + 2:
        return p[n - 1] + 1
    elif a[n - 1] + 2 < x <= 2*a[n - 1] + 2:
        return p[n - 1] + 1 + f(n - 1, x - (a[n - 1] + 2))
    elif x == 2*a[n - 1] + 3:
        return 2*p[n - 1] + 1
print(f(n, x))

Measured memory_bytes: 3064
from sys import stdin
a,b,c = [int(_) for _ in stdin.readline().rstrip().split()]
if a <= b:
    print('Yes' if c in [i for i in range(a,b+1)] else 'No')
else:
    print('Yes' if c in [i for i in range(b,a+1)[::-1]] else 'No')


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iP = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = ((iA * 3) + iP) / 2;

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
n = int(input())
num_list = list(map(int, input().split()))

a_list = [0]*n
a_list[0] = num_list[0]

for i in range(1, n, 1):
	if i != n-1:
		a_list[i] = min(num_list[i-1], num_list[i])
	else:
		a_list[i] = num_list[-1]

sum = 0
for j in a_list:
	sum += j

print(sum)

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

void solve(){
    int n=0, i=0, x=0, y=0;
    int val=0;

    cin >> n;

    vector<int> p;
    vector<int> m;

    for (i = 0; i < n; i++){
        cin >> x >> y;
        p.push_back(x+y);
        m.push_back(x-y);
    }

    int max1 = *max_element(p.begin(), p.end());
    int min1 = *min_element(p.begin(), p.end());
    int val1 = max1-min1;

    int max2 = *max_element(m.begin(), m.end());
    int min2 = *min_element(m.begin(), m.end());
    int val2 = max2-min2;

    val = max(val1, val2);

    cout << val << "\n";
}

int main(){

    solve();

    return 0;
}

Measured memory_bytes: 5084
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())


from math import ceil


def is_ok(mid):
    remain = k
    for ff, aa in zip(f, a):
        if ff * aa > mid:
            x = ceil(aa - (mid / ff))
            if x <= aa and x <= remain:
                remain -= x
            else:
                return False
    return True


def bs():
    ng, ok = -1, 10 ** 12
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


n, k = map(int, input().split())
a = tuple(sorted(map(int, input().split())))
f = tuple(sorted(map(int, input().split()), reverse=True))
print(bs())


Measured memory_bytes: 121548
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    vector<int> y(m);
    rep(i, m) cin >> y[i];
    
    for (int z = X + 1; z <= Y; z++) {
        bool ok = true;
        rep(i, n) {
            if (x[i] < z) {
            }
            else {
                ok = false;
                break;
            }
        }
        rep(i, m) {
            if (y[i] >= z) {
            }
            else {
                ok = false;
                break;
            }
        }
        if (ok) {
            put("No War")
            return 0;
        }
    }
    
            put("War")
    
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	
	cin >> s;
	
	char x=s[0];
	int ans=0;
	
	for(int i=1; i<s.size(); i++){
		if(s[i]!=x){
			x=s[i];
			ans++;
		}
	}
	
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

string S;

int main() {
	cin >> S;
	int ret = 0;
	int p = S.sz / 2;
	int left = p;
	while (left > -1 && S[p] == S[left])
		left--;
	int right = p;
	while (right < S.sz && S[p] == S[right])
		right++;
	ret = min(right, (int)S.sz - (left + 1));
	cout << ret << endl;
	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    cin.ignore(); /* skip remained '\n' */

    vector<string> s(h);
    for (int i = 0; i < h; i++)
        cin >> s.at(i);

    cout << string(w + 2, '#') << endl;

    for (int i = 0; i < h; i++) {
        cout << "#";
        cout << s.at(i);
        cout << "#" << endl;
    }

    cout << string(w + 2, '#') << endl;
}

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

int main(){
  int a, b;
  cin >> a;
  
  for(int i=0; i<a; i++){
    int x, count=0;
    cin >> x;
    for(int j=1; x%2 == 0; j++){
      x /= 2;
      count = j;
    }
    
    if(i == 0){
      b = count;
    }else if(count < b){
      b = count;
    }
      
  }
  
  cout << b << endl;
  
} 

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [0] + il() + [0]
    mx = max(A)
    mn = min(A)
    sm = 0
    for n in range(1, N + 2):
        sm += abs(A[n - 1] - A[n])

    for n in range(1, N + 1):
        print(sm - (abs(A[n] - A[n - 1]) + abs(A[n] - A[n + 1])) + abs(A[n - 1] - A[n + 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 20348
N, M = map(int, input().split())

pairs = [[] for _ in range(N + 1)]  # pairs[i]:iと直接つながっている部屋のリスト
for _ in range(M):
    input_list = list(map(int, input().split()))
    pairs[input_list[0]].append(input_list[1])
    pairs[input_list[1]].append(input_list[0])

ans = [0 for _ in range(N + 1)]
n_ans = 0   # ansを埋めた回数 -> N-1になったら終了
done = [False for _ in range(N + 1)]  # 探索済リスト
todo = [1]

while n_ans < N - 1:
    for n in todo:
        for m in pairs[n]:
            if not done[m]:
                done[m] = True
                ans[m] = n
                n_ans += 1
                todo.append(m)

print('Yes')
for i in range(2, N + 1):
    print(ans[i])

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

#define int long long

int ans, K, X;

int dfs(vector<vector<int>> & tree, int depth, int now, int per){
  int maximum = depth;

  for(int next : tree[now]){
    maximum = max(maximum, dfs(tree, depth+1, next, now));
    // cout<<now<<" -> "<<next<<endl;
  }
  // cout<<endl;
  //cout<<"K = "<<K<<" per "<<per<<endl;
  //cout<<"now "<<now<<" depth "<<depth<<" maximum "<<maximum<<" <> "<<maximum-depth<<" ans "<<ans<<endl;

  if(now == 0){

  } else if(per == 0){
    if(maximum - depth >= K){
      ans++;
      maximum = depth-1;
    }
  }else{
    if(maximum - depth >= K-1){
      ans++;
      maximum = depth-1;
    }
  }

  //  cout<<"now "<<now<<" depth "<<depth<<" maximum "<<maximum<<" <> "<<maximum-depth<<" ans "<<ans<<endl;

  return maximum;
}

signed main(){

  int N;
  vector<int> a;
  vector<vector<int>> tree;

  cin>>N>>K;

  a.resize(N);
  tree.resize(N);

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

    a[i]--;

    if(!i) {
      if(a[i] != 0) ans++;
      continue;
    }

    tree[a[i]].push_back(i);
    //tree[i].push_back(a[i]);

  }

  dfs(tree, 0, 0, -1);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#define int long long

using namespace std;

const int N = 2e5 + 10;
const int MOD = 1e9 + 7;

int a[N];

signed main() {
	int n;
	cin >> n;
	
	int sum = 0;
	for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];
	
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		sum -= a[i];
		ans += a[i] * (sum % MOD);
		ans %= MOD;
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int cnt[maxn];
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    cin >> n;
    vector<int> V(n);
    for (auto &i : V) {
        cin >> i;
        cnt[i]++;
    }
    int q;
    cin >> q;
    ll sum = accumulate(V.begin(), V.end(), 0LL);
    while (q--) {
        int a, b;
        cin >> a >> b;
        sum += 1LL * (-a + b) * cnt[a];
        cnt[b] += cnt[a];
        cnt[a] = 0;
        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 4004