akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc104/tasks/abc104_d

#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ld long double
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()

void solve() {
    
}

const int maxn = 100500;
const int MOD = (int)1e9+7;

int a[maxn], b[maxn], c[maxn], q[maxn];
int totq = 0;

int pows[maxn];

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

    pows[0] = 1;
    for(int i = 1; i < maxn; i++) {
        pows[i] = (pows[i-1]*3) % MOD;
    }

    string s;
    cin >> s;

    int n = s.size();

    s = "."+s;

    for(int i = 1; i <= n; i++) {
        if(s[i] == 'A') a[i]++;
        else if(s[i] == 'B') b[i]++;
        else if(s[i] == 'C') c[i]++;
        else q[i]++;
    }    

    for(int i = 1; i <= n; i++) {
        a[i] += a[i-1];
        b[i] += b[i-1];
        c[i] += c[i-1];
        q[i] += q[i-1];
    }

    totq = q[n];

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'A' or s[i] == 'C') continue;

        int rem = 0;
        if(s[i] == '?') rem = 1;

        int ab = a[i-1];
        int qb = q[i-1];

        int ca = c[n]-c[i];
        int qa = q[n]-q[i];

        // ABC ?BC AB? ?B?
        ans += (((ab * ca) % MOD) * (pows[totq-rem])) % MOD;
        ans %= MOD;

        ans += (((qb * ca) % MOD) * (pows[totq-rem-1])) % MOD;
        ans %= MOD;

        ans += (((ab * qa) % MOD) * (pows[totq-rem-1])) % MOD;
        ans %= MOD;

        ans += (((qb * qa) % MOD) * (pows[totq-rem-2])) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}

/*

*/

// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?


Measured memory_bytes: 7656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 
map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

vector<ll> factorize(ll n) {
  vector<ll> ret;
  stack<ll> back;
  back.push(n);
  for (ll i=2; i*i<=n; i++) {
    if (n%i == 0) {
      if (i*i == n) {
        ret.push_back(i);
        break;
      }
      ret.push_back(i);
      back.push(n/i);
    }
  }
  while (back.size()) {
    ret.push_back(back.top());
    back.pop();
  }
  return ret;
}

int main() {
  ll n; cin >> n;
  ll ans =0;
  auto n_factors = prime_factor(n-1);
  vector<ll> n_minus = factorize(n);
  ll foo = 1;
  for (auto it: n_factors) {
    foo*=(it.second + 1);
  }
  foo--;
  ans += foo;
  for (ll fac: n_minus) {
    ll n2 = n;
    while (n2 % fac == 0) n2 /= fac;
    if (n2 == 1) {
      ans++; continue;
    }
    if (n2 % fac == 1) ans++;
  } 
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	cout << 0 << endl;
	cout.flush();
	string ansl;
	cin >> ansl;
	if (ansl == "Vacant") return 0;
	int l = 0, r = n;
	string ansm;
	while (l <= r) {
		int m = (l+r)/2;
		cout << m << endl;
		cout.flush();
		cin >> ansm;
		if (ansm == "Vacant") return 0;
		if ((m-l+1) & 1) {
			if (ansl == ansm) {
				l = m;
				ansl = ansm;	
			} 
			else r = m;
		}
		else {
			if (ansl != ansm) {
				l = m;
				ansl = ansm;	
			} 
			else r = m;
		}
	}
}

Measured memory_bytes: 852
#include <stdio.h>
//#include <string.h>

int main(void){
  
  int n,k = 0;
  char s[50];
  scanf("%d %d", &n, &k);
  scanf("%s", s);
  
  if(s[k-1]=='A') s[k-1]='a';
  else if(s[k-1]=='B') s[k-1]='b';
  else if(s[k-1]=='C') s[k-1]='c';
  
  printf("%s", s);

  return 0;
}

  

Measured memory_bytes: 1732
using System;

namespace MyApp
{
    class Contest
    {
        public static int Main()
        {
            string[] ar = Console.ReadLine().Split(' ');
            string[] g = Console.ReadLine().Split(' ');
            int n = int.Parse(ar[0]);
            int[] t = new int[n];
            for(int i = 0; i < n; ++i)
            {
                t[i] = int.Parse(g[i]);
            }
            int count = 0;
            while(true)
            {   
                bool x = false;
                for(int i = 0; i < n; ++i)
                {
                    if(t[i] % 2 != 0)
                    {
                        x = true;
                        break;
                    }
                    t[i] = t[i] / 2;
                }

                if(x)
                {
                    break;
                }
                count++;
            }

            Console.WriteLine(count);

            return 0;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int



#if 1
const int MOD = 998244353;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}
#endif

#if 0
int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
#endif

using namespace std;



int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <int> a(n), b(n);
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(i = 0; i < n; i++) {
        cin >> b[i];
    }

    vector <int> orda(n), ordb(n);
    iota(orda.begin(), orda.end(), 0);
    iota(ordb.begin(), ordb.end(), 0);

    sort(orda.begin(), orda.end(), [&](const int &x, const int &y) {
                return a[x] > a[y];
         });
    sort(ordb.begin(), ordb.end(), [&](const int &x, const int &y) {
                return b[x] > b[y];
         });

    bool ok = 0;
    for(i = 0; i < n; i++) {
        if(a[orda[i]] > b[ordb[i]]) {
            cout << "No";
            return 0;
        }
        if(i + 1 < n && a[orda[i]] <= b[ordb[i + 1]]) {
            ok = 1;
        }
    }

    if(ok) {
        cout << "Yes";
        return 0;
    }

    vector <bool> vis(n);
    vector <int> p(n);
    for(i = 0; i < n; i++) {
        p[orda[i]] = ordb[i];
    }

    int pos = orda[0];
    while(vis[pos] == 0) {
        vis[pos] = 1;
        pos = p[pos];
    }

    if(count(vis.begin(), vis.end(), 1) == n) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }

    return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] cArr = sc.next().toCharArray();
        int r = 0;
        int b = 0;

        for (char c : cArr) {
            if (c == 'R') r++;
            if (c == 'B') b++;
        }

        if (r > b) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)
signed main(){std::ios::sync_with_stdio(false);std::cin.tie(0);
int2(a, b);
vector<string> ans(0);
rep(i, 20) {
string up="", down="";
rep(j, 50){ if(a>1){
up += ".#";
down += "##";
a--;
}else{
up += "##";
down += "##";
} }
ans.pb(up); ans.pb(down);
if(a==1) break;
}

rep(i, 20) {
string up="", down="";
rep(j, 50){ if(b>1){
up += "..";
down += "#.";
b--;
}else{
up += "..";
down += "..";
} }
ans.pb(up); ans.pb(down);
if(b==1) break;
}
cout << ans.size()<<" "<<ans[0].size()
<<endl;
rep(i, ans.size())cout<<ans[i]<<endl;return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;


int main(void) {
    int N;
    cin >> N;
    vector<long>H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int cnt = 0;
    int Max = 0;
    for(int i = 0; i < N - 1; i++) {
        if(H[i] >= H[i+1]) {
            cnt++;
        } else {
            if(cnt > Max) {
                Max = cnt;
            }
            cnt = 0;
        }
    }

    if(cnt > 0) {
        if(cnt > Max) {
            Max = cnt;
        }
    }
    cout << Max << endl;
    return 0;
}

Measured memory_bytes: 1024
# input
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)
l, r, ans = 0, 0, 0

while r < N:
    if A[r] <= A[l] + 2:
        if r - l + 1 > ans:
            ans = r - l + 1
        r += 1
    else:
        l += 1

print(ans)

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

void solve()
{
    int A,B;
    cin>>A>>B;
    if((2*B)<=A)
    cout<<abs((2*B)-A)<<endl;
    else
    cout<<0<<endl;
}


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e18;
int main(){
	int N;cin>>N;
	long sum=0;long a;long A[N];
	rep(i,0,N){
		cin>>a; sum+=a;
		A[i]=sum;
	}
	long ans=sum;
	rep(i,0,N){
		ans=min(ans,abs(sum-2*A[i]));
	}cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;
  cin >> str;

  bool start = false;
  uint32_t indexA = 0;
  uint32_t indexZ = 0;
  for (uint32_t i = 0; i < str.size(); i++) {
    if (!start && (str[i] == 'A')) {
      start = true;
      indexA = i;
    }

    if (start) {
      if (str[i] == 'Z') {
        indexZ = i;
      }
    }
  }

  cout << indexZ - indexA + 1 << endl;

  return 0;
}


Measured memory_bytes: 640
using System;
class P
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');

            while (str[1] != "?")
            {
                int a = int.Parse(str[0]);
                int b = int.Parse(str[2]);

                switch (str[1])
                {
                    case "+":
                        Console.WriteLine(a + b);
                        break;
                    case "-":
                        Console.WriteLine(a - b);
                        break;
                    case "*":
                        Console.WriteLine(a * b);
                        break;
                    case "/":
                        Console.WriteLine(a / b);
                        break;
                }
                str = Console.ReadLine().Split(' ');
            }
    }
}


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

int main(void){
  int a,b,c,d,ans1,ans2;
  cin >> a >> b >> c >> d;
  ans1 = a + b;
  ans2 = c + d;
  
  if(ans1 > ans2){
    cout << "Left" << endl;
  }else if(ans1 < ans2){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

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

int n;
int l[105];
int ans;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &l[i]);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (l[i] == l[j]) continue;
			for (int k = j + 1; k < n; k++) {
				if (l[i] == l[k] || l[j] == l[k]) continue;
				int a = l[i], b = l[j], c = l[k];
				if (a < b) swap(a, b);
				if (b < c) swap(b, c);
				if (a < b) swap(a, b);
				if (b + c > a && b - c < a) ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[][] c = {{},
            {'.', ',', '!', '?', ' '},
            {'a', 'b', 'c'},
            {'d', 'e', 'f'},
            {'g', 'h', 'i'},
            {'j', 'k', 'l'},
            {'m', 'n', 'o'},
            {'p', 'q', 'r', 's'},
            {'t', 'u', 'v'},
            {'w', 'x', 'y', 'z'}};
        
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            StringBuffer ans = new StringBuffer();
            int count = 0; // 確定ボタンを押すまでに他のボタンを押した回数
            int num = 0; // 何番のボタンを押したか (1-9)
            for (int j = 0; j < s.length(); j++) {
                int tmp = s.charAt(j) - '0';
                if (tmp == 0) {
                    if (count > 0) {
                        ans.append(c[num][(count-1)%c[num].length]);
                    }
                    count = 0;
                    num = 0;
                } else {
                    count++;
                    num = tmp;
                }
            }
            System.out.println(ans);
        }
    }
}

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

int main() {
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  
  	string s; cin>>s;
  	int n; cin>>n;
  	deque<char> dq;
  	for (char c : s) dq.push_back(c);
  
  	bool flipped = 0;
 	while (n--) {
      	int ti; cin>>ti;
      	if (ti == 1) flipped ^= 1;
      	else {
        	int fi; cin>>fi; char c; cin>>c; fi--;
          	if (fi^flipped)
              dq.push_back(c);
          	else dq.push_front(c);
        }
    }
  	if (flipped)
      	for (int i = dq.size()-1; i >= 0; i--)
          	cout << dq[i];
  	else for (int i = 0; i < dq.size(); i++)
      	cout << dq[i];
  cout << endl;
  	return 0;
}

Measured memory_bytes: 976
def main():
    A, B, C, X, Y = map(int, input().split())

    case1 = A * X + B * Y
    case2 = C * 2 * max(X, Y)
    if X < Y:
        case3 = C * X * 2 + B * (Y - X)
    else:
        case3 = C * Y * 2 + A * (X - Y)
    ans = min(case1, case2, case3)

    print(ans)

main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC074_b
int main() {
	int N, K;
	cin >> N >> K;

	int sum = 0;
	rep(i, N) {
		int x;
		cin >> x;
		sum += min(2*x, abs(x - K) * 2);
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
char v[LIM][LIM];
int main() {
  ll h, w;
  cin >> h >> w;
  string s;
  for (int y = 0; y < h; y++) {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      v[y][i] = s[i];
    }
  }
  int right = 0;
  int down = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (v[y][x] == '#') {
        int yy = y + 1;
        int xx = x + 1;
          if (xx < w && v[y][xx] == '#') {
            right++;
          }
          if (yy < h && v[yy][x] == '#') {
            down++;
          }
      }
    }
  }
  if (right == w - 1 && down == h - 1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


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

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<long long> s(A), t(B);
    for (int i=0; i<A; ++i) cin >> s[i];
    for (int i=0; i<B; ++i) cin >> t[i];

    long long x;
    for (int i=0; i<Q; ++i) {
        cin >> x;

        long long s1, s2, t1, t2;
        int j;
        j = lower_bound(s.begin(), s.end(), x) - s.begin();
        if (j == (int)s.size()) {
            s1 = s[j-1];
            s2 = 1e12;
        } else {
            s1 = (j == 0) ? -1e12 : s[j-1];
            s2 = s[j];
        }

        j = lower_bound(t.begin(), t.end(), x) - t.begin();
        if (j == (int)t.size()) {
            t1 = t[j-1];
            t2 = 1e12;
        } else {
            t1 = (j == 0) ? -1e12 : t[j-1];
            t2 = t[j];
        }

        long long ans = min({
            max(abs(s1-x), abs(t1-x)),
            max(abs(s2-x), abs(t2-x)),
            abs(s1-x) + abs(t2-x) + min(abs(s1-x), abs(t2-x)),
            abs(t1-x) + abs(s2-x) + min(abs(t1-x), abs(s2-x))
        });

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
n = int(input())
xy = []
for _ in range(n):
  x, y, h = map(int, input().split())
  xy.append((x, y, h))

def check(cx, cy):
  x, y, h = xy[0]
  ch = h + abs(cx - x) + abs(cy - y)
  if h > 0:
    ch0 = [ch]
  else:
    ch0 = [i for i in range(1, ch+1)]
  
  for (x, y, h) in xy[1:]:
    ch = h + abs(cx - x) + abs(cy - y)
    if h > 0:
      ch0 = [i for i in ch0 if i == ch]
    else:
      ch0 = [i for i in ch0 if i <= ch]
    
    if len(ch0) == 0:
      return False
  return ch0[0]

for cx in range(101):
  for cy in range(101):
    ch = check(cx, cy)
    if ch:
      print(' '.join( map(str, [cx, cy, ch]) ))
      exit()



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, d);
  out((n + 2 * d) / (2 * d + 1));
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 26;

int n, m;
int f[N][M];
char s[N], t[N];

int main()
{
	scanf("%s%s", s, t);
	n = strlen(s), m = strlen(t);
	
	memset(f, -1, sizeof f);
	for (int i = n - 1; i >= 0; i -- )
	{
		int c = s[i] - 'a';
		for (int j = 0; j < M; j ++ ) f[i][j] = f[i + 1][j];
		f[i][c] = i;
	}
	
	int a = 0, b = 0;
	for (int i = 0; i < m; i ++ )
	{
		int c = t[i] - 'a';
		if (f[0][c] == -1)
		{
			puts("-1");
			exit(0);
		}
		if (f[b][c] == -1) a ++ , b = 0;
		b = f[b][c] + 1;
	}
	printf("%lld\n", (LL)a * n + (LL)b);
	return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  long t=0;
  for(int i=0;i<n-2;i++)
    for(int j=i+1;j<n-1;j++){
      int up=lower_bound(v.begin()+j+1,v.end(),v[i]+v[j])-v.begin();
      t+=up-(j+1);
      //if(v[i]+v[j]>=v[up])t++;
    }
  cout<<t;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define pb push_back
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 60; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------

signed main() {
	int a, b, k;
	cin >> a >> b >> k;
	if (a >= k) cout << a - k << " " << b << endl;
	else cout << 0 << " " << max(0ll,b - (k - a)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans = 0;
    FOR(r, 0, 3001) FOR(g, 0, 3001) {
        ll tmp = N - r * R - g * G;
        if(tmp % B == 0 && tmp / B >= 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end(), greater<int>());
  ll v1 = -1;
  REP(i,A.size()-1){
    if(A[i]==A[i+1]){
      if(v1==-1){
        v1 = A[i];
      }else{
        cout << v1 * A[i] << endl;
        return 0;
      }
      i++;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 1024
from bisect import bisect_right, insort_right
N = int(input())
A = [int(input()) for _ in range(N)][::-1]
res = [A[0]]
for a in A[1:]:
    idx = bisect_right(res, a)
    if idx == len(res):
        res.append(a)
    else:
        if res[idx] == a:
            insort_right(res, a)   
        else:
            res[idx] = a
print(len(res))
    


Measured memory_bytes: 14380
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

vector<int> es[100010];

int dfs(int now, int par) {
	int ret = 0LL;
	for(auto& to : es[now]) {
		if(to == par) continue;
		ret ^= (dfs(to, now) + 1);
	}
	return ret;
}


int main(){
	int n;
	cin >> n;
	rep(i, n-1) {
		int x, y;
		cin >> x >> y;
		x--;y--;
		es[x].pb(y);
		es[y].pb(x);
	}
	cout << (dfs(0, -1) ? "Alice": "Bob") << endl;
	return 0;
}

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

void solve(int R, int C, int *a){
    int ans = 0;
    for(int bit = 0; bit < (1<<R); bit++){
        int temp = 0;
        int b[R][C];
        for(int i = 0; i < R; i++){
            for(int j = 0; j < C; j++)
                b[i][j] = ((bit & (1<<i)) ? (1 - *(a + i * C + j)) : *(a + i * C + j));
        }
        for(int j = 0; j < C; j++){
            int A = 0;
            for(int i = 0; i < R; i++) A += b[i][j];
            temp += max(A, R - A);
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return;
}

int main(){
    int R, C;
    while(cin >> R){
        if(R == 0) return 0;
        cin >> C;
        int a[R][C];
        for(int i = 0; i < R; i++){
            for(int j = 0; j < C; j++) cin >> a[i][j];
        }
        solve(R, C, &a[0][0]);
    }
}


Measured memory_bytes: 3840
#include <vector>
#include <iostream>
using namespace std;
int col[1001000];
vector<pair<int, int> > adj[100100];

void dfs(int i, int p, int c) {
    col[i] = c;
    for (auto e : adj[i]) {
        int j = e.first, w = e.second;
        if (j != p) dfs(j, i, c^w);
    }
}

int main() {
    int n; cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--; w %= 2;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }
    dfs(0, -1, 0);
    for (int i = 0; i < n; i++) cout << col[i] << endl;
}


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }

    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (ll)(upper_bound(begin(a), end(a), b[i] - 1) - begin(a)) * (end(c) - upper_bound(begin(c), end(c), b[i]));
    }

    cout << ans << endl;
}


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

int main(void)
{
    string S;
    cin >> S;

    string ans = "Good";
    if (S[0] == S[1])
        ans = "Bad";
    else if (S[1] == S[2])
        ans = "Bad";
    else if (S[2] == S[3])
        ans = "Bad";

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

void dfs(int u, int p, vector<vector<int>> const& g, vector<vector<int>> &dp) {
    dp[0][u] = 1;
    dp[1][u] = 1;
    for (auto v : g[u]) {
        if (v != p) {
            dfs(v, u, g, dp);
            dp[0][u] = (1LL * dp[0][u] * ((dp[1][v] + dp[0][v]) % mod)) % mod;
            dp[1][u] = (1LL * dp[1][u] * dp[0][v]) % mod;
        }
    }
}

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<vector<int>> dp(2, vector<int>(n, 0));

    dfs(0, -1, g, dp);
    cout << (dp[0][0] + dp[1][0]) % mod;
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

ll solve(int N, int K, vi& t, vi& d){
  map<int, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  vi winner, looser;
  for (auto p: sushi_list){
    vi q=p.second;
    sort(q.begin(), q.end());
    int w=q.back();
    winner.push_back(w);
    q.pop_back();
    looser.insert(looser.begin(), q.begin(), q.end());
  }

  sort(winner.begin(), winner.end(), greater<int>());
  sort(looser.begin(), looser.end(), greater<int>());

  int W=winner.size();
  int L=looser.size();

  vl winner_cumsum(W+1);
  vl looser_cumsum(L+1);
  winner_cumsum[0]=0;
  looser_cumsum[0]=0;

  for (int i=0;i<W;++i){
    winner_cumsum[i+1]=winner_cumsum[i]+winner[i];
  }

  for (int i=0;i<L;++i){
    looser_cumsum[i+1]=looser_cumsum[i]+looser[i];
  }

  ll best=0;

  for (int n_unique=1;n_unique<=W;++n_unique){
    if(n_unique<=K&&(K-n_unique<=L)){
      ll tmp=winner_cumsum[n_unique]+looser_cumsum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }

  return best;
}

int main(){
  int N, K;cin>>N>>K;
  vi t, d;
  for (int i=0;i<N;i++){
    int t_, d_;cin>>t_>>d_;
    t.push_back(t_);
    d.push_back(d_);
  }

  ll ans=solve(N, K, t, d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13300
#
# abc126 f
#


def main():
    s = input()
    a = int(s[:2])
    b = int(s[2:])
    if b == 0:
        if a > 12 or a == 0:
            print("NA")
        else:
            print("MMYY")
    elif b > 12:
        if a > 12 or a == 0:
            print("NA")
        else:
            print("MMYY")
    else:
        if a > 12 or a == 0:
            print("YYMM")
        else:
            print("AMBIGUOUS")


if __name__ == '__main__':
    main()


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

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

void main()
{
	auto A = RD!long;
	auto B = RD!long;

	if (A == 1 && B == 1)
	{
		writeln(1, " ", 2);
		writeln(".#");
		return;
	}

	long diff = abs(A - B);
	auto eq   = min(A, B) * 2; 

	long x = min(100, eq), y = eq / 100;

	auto c1 = A > B ? '.' : '#';
	auto c2 = A > B ? '#' : '.';
	stderr.writeln(c1, c2);
	stderr.writeln(x, " ", y);

	writeln(100, " ", 100);
	auto last = new long[](100);
	foreach (i; 0..y)
	{
		foreach (j; 0..100)
		{
			if (j >= x)
				write(c1);
			else
			{
				last[j] = (i + j) % 2 == 0 ? 1 : 0;
				write((i + j) % 2 == 0 ? c1 : c2);
			}
		}
		writeln();
	}

	if (eq % 100 != 0)
	{
		foreach (j; 0..100)
		{
			if (j >= eq % 100)
				write(c1);
			else
			{
				last[j] = (y + j) % 2 == 0 ? 1 : 0;
				write((y + j) % 2 == 0 ? c1 : c2);
			}
		}
		writeln();
	}

	y += eq % 100 == 0 ? 0 : 1;
	write(y % 2 == 0 ? [c2, c1] : [c1, c2]);
	foreach (j; 2..100)
	{
		write(c1);
	}
	writeln();
	foreach (j; 0..100)
	{
		write(c2);
	}
	writeln();
	stderr.writeln(diff);
	long cnt;
	foreach (e; last) if (e == 1) ++cnt;
	cnt += y % 2 == 1 ? -1 : 0;
	--cnt;
	diff += cnt;
	stderr.writeln(diff);
	foreach (i; y+2..100)
	{
		foreach (j; 0..100)
		{
			if (j == 0 || j == 99)
			{
				write(c2);
				continue;
			}
			if (diff != 0 && (i + j) % 3 == 0)
			{
				--diff;
				write(c1);
			}
			else
				write(c2);
		}
		writeln();
	}
	if (diff > 0) foreach (i; 0..100_000_000) stderr.writeln(i);

	stdout.flush();
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  int n, k;
  cin >> n >> k;
  vector<int> vec(n, 0);
  rep(i, k){
    int d;
    cin >> d;
    rep(j, d){
      int m;
      cin >> m;
      vec[m - 1] = m;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(vec[i] == 0){
      ans++;
    }   
  }
  cout << ans << endl;

}


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

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    rep(i,k) {
        cout << s << ' ';
    }
    rep(i,n-k) {
        if (s == 1000000000) cout << 1 << ' ';
        else cout << s+1 << ' ';
    }
    return 0;
}

Measured memory_bytes: 1280
// AOJ 1038 Dr. Nakamura's Lab.
// 2019.4.3 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char uchar;
typedef struct { uchar pos[7]; int step; } Q;
Q que[250000]; int top, end;
char encode[128];

char map[12][12]; int H, W;
int mv[4][2] = { {-1,0}, {0,1}, {1,0}, {0,-1} };

// 数値のハッシュ関数
#define HASHSIZ 2000081
long long hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int insert(uchar *pos)
{
	int i;
	long long x;
	long long *p;

	x = 0; for (i = 0; i < 7; i++) x = (x << 8) | pos[i];
	p = hash + (int)(x % HASHSIZ);
	while (*p) {
		if (*p == x) return 0;
		if (++p == hashend) p = hash;
	}
	*p = x;
	return 1;
}

int bfs(uchar goal, uchar *init)
{
	int i, j, r, c, nr, nc, ic, step;
	uchar pos[7], npos[7], np;

	top = 0, end = 1;
	memcpy(que[0].pos, init, 7), que[0].step = 0;
	while (top != end) {
		memcpy(pos, que[top].pos, 7), step = que[top].step, top++;
		if (pos[0] == goal) return step;

		if (!insert(pos)) continue;   // 同一状態がすでにあった

		r = pos[0] >> 4, c = pos[0] & 0xf;
		for (i = 0; i < 4; i++) {
			memcpy(npos, pos, 7);
			nr = r + mv[i][0], nc = c + mv[i][1], np = (nr << 4) | nc;
			if (map[nr][nc] == '#') continue;
			if (pos[1] == np || pos[2] == np || pos[3] == np) continue;
			for (ic = 4; ic < 7; ic++) if (pos[ic] == np) break;
			if (ic < 7) {  // 移動先がコンテナ
				uchar cr = nr + mv[i][0], cc = nc + mv[i][1];
				uchar cp0 = np, cp = (cr << 4) | cc;
				if (map[cr][cc] == '#') continue;    // コンテナの先が壁か別のコンテナ？
				if (pos[4] == cp || pos[5] == cp || pos[6] == cp) continue;

				while (1) {
					for (j = 1; j < 7; j++) if (pos[j] == cp) break;
					if (j < 7) break;
					cr += mv[i][0], cc += mv[i][1], cp0 = cp, cp = (cr << 4) | cc; // 移動し続ける
					if (map[cr][cc] != '.') break;
				}
				if (j < 4) npos[j] = npos[ic] = 0;    // コンテナとパネルが消滅
				else npos[ic] = cp0;
				que[end].step = step;
			}
			else npos[0] = np, que[end].step = step + 1;
			memcpy(que[end].pos, npos, 7);
			end++;
		}
	}
	return -1;
}

int main()
{
	int k, r, c, nc, np;
	uchar goal, pos[7], p;

	memset(encode, -1, sizeof(encode));
	encode['@'] = 0, encode['w'] = 1, encode['c'] = 4, encode['E'] = 10;
	while (scanf("%d%d", &H, &W) && H) {
		memset(hash, 0, sizeof(hash));
		memset(pos, 0, 7);
		np = nc = 0;
		for (r = 0; r < H; r++) {
			scanf("%s", map[r]);
			for (c = 0; c < W; c++) {
				if ((k = encode[map[r][c]]) < 0) continue;
				p = (r << 4) | c;
				if (k == 0) pos[k] = p;              // Dr.中村 
				else if (k < 4) pos[k + np++] = p;   // パネル
				else if (k < 7) pos[k + nc++] = p;   // コンテナ
				else goal = p;                       // 出口
				map[r][c] = '.';
			}
		}
		printf("%d\n", bfs(goal, pos));
	}
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  
  int a[110];
  for(int i=0;i<N;++i){
    cin>>a[i];
  }
  
  int Max=0;
  int Min=1000000000;
  for(int i=0;i<N;++i){
    Max=max(Max,a[i]);
    Min=min(Min,a[i]);
  }
  
  
  cout<<Max-Min<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<map>
#include<deque>
#include<list>
#include<forward_list>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define ll long long
#define v vector<ll>
const ll w = (1e9 + 7);
using namespace std;
void fireman()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
struct great {
	//descending order
	bool operator()(int x, int y)
	{
		return x < y;
	}
};


struct small {
	//asecending order
	bool operator()(int x, int y)
	{
		return x > y;
	}
};

bool prime(ll x)
{
	bool b = true;
	if (x == 2)
	{
		return true;
	}
	else if (x == 1 || x % 2 == 0)
	{
		return false;
	}
	for (int i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0)
		{
			return false;
		}
	}
	return true;
}
bool great1(int a, int b)
{
	//descending order 
	return a > b;
}
bool small1(int a, int b)
{
	//asecending order 
	return a < b;
}
/*int sum_range(ll i, ll j, ll k, ll l, vector<vector<ll>>& S) {
	return S[k][l] - S[k][j - 1] - S[i - 1][l] + S[i - 1][j - 1];
}*/

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
	return a / gcd(a, b) * b;
}
int modpow(ll a, ll b, ll c)//fast_power log(n)
{
	if (b == 0)
		return 1 % c;
	ll u = modpow(a, b / 2, c);
	u = (u * u) % c;
	if (b & 1)
		u = (u * a) % c;
	return u;
}

int main()
{
	fireman();
	ll x;
	cin >> x;
	ll* arr = new ll[x];
	for (int i = 0; i < x; i++)
	{
		cin >> arr[i];
	}
	int z = 0;
	for (int i = 0; i < x; i+=2)
	{
		if (arr[i] % 2 == 1)
		{
			z++;
		}
	}
	cout << z << endl;
	
}


Measured memory_bytes: 3572
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A2,B2=map(str, stdin.readline().split())
A=int(A2)
tmp=list(B2)


B1=int(tmp[0])
B2=int(tmp[2])
B3=int(tmp[3])

ans=0
ans+=B1*A
ans+=(A*B2)//10
ans+=(A*B3)//100
if(10<=(((A*B2)%10)+(((A*B3)%100)//10))):
    ans+=1

print(ans)


Measured memory_bytes: 10468
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

constexpr int MAX_HW = 1000;
constexpr int INF = 1000 * 1000;

constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int H, W;
int dis[MAX_HW][MAX_HW];

int main(){

	std::cin >> H >> W;

	int black = 0, all = H * W;

	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			char input;
			std::cin >> input;

			if(input == '#'){
				dis[i][j] = 0;
			}
			else{
				dis[i][j] = INF;
			}
		}
	}

	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){

			int min = INF;

			for(int k = 0; k < 4; ++k){
				int nh = i + dx[k], nw = j + dy[k];

				if(nh >= 0 && nw >= 0 && nh < H && nw < W){
					min = std::min(min, dis[nh][nw]);
				}
			}

			dis[i][j] = std::min(dis[i][j], min + 1);
		}
	}

	for(int i = H - 1; i >= 0; --i){
		for(int j = W - 1; j >= 0; --j){

			int min = INF;

			for(int k = 0; k < 4; ++k){
				int nh = i + dx[k], nw = j + dy[k];

				if(nh >= 0 && nw >= 0 && nh < H && nw < W){
					min = std::min(min, dis[nh][nw]);
				}
			}

			dis[i][j] = std::min(dis[i][j], min + 1);
		}
	}

	int ans = 0;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			ans = std::max(ans, dis[i][j]);
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n; cin>>n;
	long long int arr[n];
	long long int ans = 0;
	long long int count = 0;
	for(int i = 0; i<n; i++){
		cin >> arr[i];
	}
	sort(arr, arr+n, greater<long long int>());
	ans=ans+arr[0];
	count++;
	for(int i = 1; i<n; i++){
		for(int j = 0; j<2; j++){
			if(count==n-1){
				break;
			}
			count++;
			ans=ans+arr[i];
		}
		if(count==n-1){
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 5204
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
bool check(string s) {
	rep(i, 1, s.size()) {
		if (s[i] != s[i - 1])return false;
		
	}
	return true;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int ans = s.size() ;
	rep(i, 0, s.size()) {

		string t(s);
		int cnt(0);
		while (check(t) == false) {
			cnt++;
			string u;
			rep(j, 0, t.size() - 1) {
				if (t[j] == s[i]) {
					u.push_back(t[j]);
				}
				else if (t[j + 1] == s[i]) {
					u.push_back(t[j + 1]);
				}
				else u.push_back(t[j + 1]);
			}
			t = u;
		}
		chmin(ans, cnt);

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

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  ll K, N;
  cin >> K >> N;
 vector<ll> a(N);
  REP(i,N) cin >> a[i];
  a.PB(K+a[0]);
 priority_queue<ll> op;
  REP(i,N) op.push(a[i+1] - a[i]);
  cout << K - op.top();
}

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

int main(){
    int n,m,h,a,b;
    scanf("%d %d",&n,&m);
    vector<vector<int>> graph(n);
    vector<int> hs;
    for(int i=0;i<n;i++){
        scanf("%d",&h);
        hs.push_back(h);
    }
    for(int i=0;i<m;i++) {
        scanf("%d %d",&a,&b);
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    int res = 0;
    for(int i=0;i<n;i++) {
        bool highest = true;
        for(int neigh : graph[i]) {
            if(hs[neigh] >= hs[i]) {
                highest = false;
                break;
            }
        }
        if(highest) res++;
    }
    printf("%d\n", res);
}


Measured memory_bytes: 8776