akhauriyash/Code-Regression huggingface dataset:
package main

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

var N int
var K int64
var A ints
var F ints

func main() {
	N = nextInt()
	K = nextInt64()

	A = make(ints, N)
	F = make(ints, N)

	for i := 0; i < N; i++ {
		A[i] = nextInt64()
	}
	sort.Sort(sort.Reverse(A))

	for i := 0; i < N; i++ {
		F[i] = nextInt64()
	}
	sort.Sort(F)

	fmt.Println(binarysearch())
}

func binarysearch() int64 {
	l := int64(-1)
	r := int64(math.MaxInt64)

	for l+1 < r {
		m := (r + l) / 2
		if ok(m) {
			r = m
		} else {
			l = m
		}
	}

	return r
}

func ok(n int64) bool {
	k := int64(0)

	for i := 0; i < N; i++ {
		k += max(0, A[i]-n/F[i])
	}

	return k <= K
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

type ints []int64

func (a ints) Len() int           { return len(a) }
func (a ints) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ints) Less(i, j int) bool { return a[i] < a[j] }

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using piii = pair<int,pii>;
piii mp(int a, int b, int c){return piii(a,pii(b,c));}
signed main(){
    int n,m,l,k,a,h;
    while(cin >> n >> m >> l >> k >> a >> h){
        if(n + m + l  + k + a + h == 0)break;
        vector<bool>fre(n,false);
        rep(i,l){
            int v; cin >> v;
            fre[v] = true;
        }
        vector<vector<pii>>edge(n);
        rep(i,k){
            int s,t,c; cin >> s >> t >> c;
            edge[s].push_back(pii(t,c));
            edge[t].push_back(pii(s,c));
        }
        vector<vector<int>>d(n,vector<int>(m+1,INF));
        priority_queue<piii,vector<piii>,greater<piii>>que;
        d[a][m] = 0;
        que.push(mp(0,a,m));
        while(!que.empty()){
            int _d = que.top().first;
            int v = que.top().second.first; int t = que.top().second.second;
            que.pop();
            if(d[v][t] < _d)continue;
            rep(add,m+1){
                int nt = add + t;
                if(nt > m)break;
                rep(i,edge[v].size()){
                    int nv = edge[v][i].first;
                    int cost = edge[v][i].second;
                    if(nt - cost < 0)continue;
                    if(d[nv][nt-cost] > _d + cost + add){
                        d[nv][nt-cost] = _d + cost + add;
                        que.push(mp(d[nv][nt - cost],nv,nt - cost));
                    }
                }
                if(!fre[v])break;
            }
        }
        int ans = INF;
        rep(i,m+1){
            if(d[h][i] != INF){
                cmin(ans, d[h][i]);
            }
        }
        if(ans == INF)cout << "Help!" << endl;
        else cout << ans << endl;
    }
}





Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    int num_minus = 0;
    ll mi = 1LL << 60;
    ll sum = 0;
    for(int i = 0; i < N; i++) {
        if (a[i] < 0) num_minus++;
        chmin(mi, abs(a[i]));
        sum += abs(a[i]);
    }
    if(num_minus % 2 == 0) COUT(sum);
    else COUT(sum - mi * 2);
}

Measured memory_bytes: 1024
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
	long long int i, j, N, K, A[200000], count = 0;

	scanf("%lld %lld", &N, &K);

	for (i = 0; i<N; i++)
		scanf("%lld", &A[i]);


	sort(A, A + N, greater<long long int>());
	for (i = K; i<N; i++)
		count += A[i];

	printf("%lld\n", count);

	return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var a, b, c int64

	fmt.Scan(&a, &b, &c)

	d := c - a - b
	if d < 0 {
		fmt.Println("No")
		return
	}

	if 4*a*b < d*d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll n,ans=1;
	string s;
	in(n);
	
	in(s);

	rep(i, 1, n) {
		if (s[i] != s[i - 1]) {
			ans++;
		}
	}

	outn(ans);

	return 0;

}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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



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

    //0-A, 1-C, 2-G, 3-T
    ll dp[N+1][4][4][4];
    for(int i=0; i<N+1; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                for(int l=0; l<4; l++){
                    dp[i][j][k][l]=0;
                    if(i == 3){
                        if(j == 1 && k == 2 && l == 0) continue;
                        if(j == 1 && k == 0 && l == 2) continue;
                        if(j == 2 && k == 1 && l == 0) continue;
                        dp[i][j][k][l]=1;
                    }
                }
            }
        }
    }


    ll ans=0;
    for(int n=4; n<=N; n++){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                for(int k=0; k<4; k++){
                    for(int l=0; l<4; l++){
                        if(i == 1 && j == 2 && k == 0) continue;
                        if(i == 1 && j == 0 && k == 2) continue;
                        if(i == 1 && k == 2 && l == 0) continue;
                        if(i == 1 && j == 2 && l == 0) continue;
                        if(i == 2 && j == 1 && k == 0) continue;
                        dp[n][i][j][k]=(dp[n][i][j][k]+dp[n-1][j][k][l])%MOD;
                    }
                }
            }
        }
    }
    
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans=(ans+dp[N][i][j][k])%MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>

int p;
int q[500010];
void find(int i){
  int d=i;
	if(2*i  <=p&&q[2*i  ]>q[d])d=2*i;
	if(2*i+1<=p&&q[2*i+1]>q[d])d=2*i+1;
	if(d!=i){
		int t=q[i];
		q[i]=q[d];
		q[d]=t;
		find(d);
	}
}
int main(){
	scanf("%d",&p);
	for(int i=1;i<=p;i++)scanf("%d",q+i);
	for(int i=p;i>0;i--)find(i);
	for(int i=1;i<=p;i++)printf(" %d",q[i]);
	puts("");
}



Measured memory_bytes: 3752
d = [0] * (10**6 + 1)
n = int(input())
for a in map(int, input().split()):
    d[a] += 1
ans = 0
for i in range(1, 10**6 + 1):
    if d[i] == 1:
        ans += 1
    if d[i] > 0:
        for j in range(i, 10**6 + 1, i):
            d[j] = 0
print(ans)


Measured memory_bytes: 32396
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<ll> N(3);
  cin >> N[0] >> N[1] >> N[2];
  if(N[0]%2==0 || N[1]%2==0 || N[2]%2==0) {
    cout << 0 << endl;
  } else {
    sort(N.begin(), N.end());
    cout << N[0]*N[1]<< endl;
  }
}

Measured memory_bytes: 256
use std::io;
use std::collections::BTreeMap;

fn main() {
    let n = read_values::<usize>()[0];
    let mut array = (0..n).map(|_| read_values::<usize>()[0]).collect::<Vec<_>>();
    let mut map = BTreeMap::new();
    for i in 0..n {
        if i % 2 == 0 {
            map.insert(array[i], true);
        } else {
            map.insert(array[i], false);
        }
    }

    array.sort();
    let mut count = 0;
    for i in 0..n {
        if i % 2 != 0 && *map.get(&array[i]).unwrap() {
            count += 1;
        }
    }
    println!("{}", count);
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 8444
#include<iostream>
using namespace std;
int main()
{
	unsigned long int n;
	int *arr;
	int tmp;
	cin>>n;
	arr = new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		arr[tmp-1] = i;
	}
	for(int i=0;i<n;i++)
		cout<<arr[i]+1<<" ";
	return 0;
}

Measured memory_bytes: 1152
/*
 * 直角三角形の面積を求める
 */
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		//変数定義
		int a,b,c;

		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();

		System.out.println(a*b/2);

	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector< vector<int> > g(n);
  vector<int> a(n), b(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
    a[i] = x;
    b[i] = y;
  }
  vector< vector<int> > dist(n, vector<int>(n));
  function<void(int, int, int, int)> dfs = [&](int v, int p, int root, int d) {
    dist[root][v] = d;
    for (int& u : g[v]) {
      if (u == p) {
        continue;
      }
      dfs(u, v, root, d + 1);
    }
  };
  for (int i = 0; i < n; i++) {
    dfs(i, -1, i, 0);
  }
  int ans = n;
  {
    for (int v = 0; v < n; v++) {
      int cnt = 0;
      for (int u = 0; u < n; u++) {
        if (2 * dist[v][u] > k) {
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  {
    for (int ei = 0; ei < n - 1; ei++) {
      int ai = a[ei];
      int bi = b[ei];
      int cnt = 0;
      for (int u = 0; u < n; u++) {
        if (2 * min(dist[ai][u], dist[bi][u]) + 1 > k) {
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 16256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

five_x = 0
hundred_x = 0
fifty_x = 0

five = []
hundred = []
fifty = []
five.append(0)
hundred.append(0)
fifty.append(0)

for i in range(A):
    five_x += 500
    five.append(five_x)
for i in range(B):
    hundred_x += 100
    hundred.append(hundred_x)
for i in range(C):
    fifty_x += 50
    fifty.append(fifty_x)
    
money = []

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            money.append(five[i]+hundred[j]+fifty[k])

cnt = 0

for i in range(len(money)):
    if money[i] == X:
        cnt += 1

print(cnt)


Measured memory_bytes: 8344
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var result = 10000000;
            foreach(var i in Enumerable.Range(0, S.Length-2))
            {
                var sub = int.Parse(S.Substring(i, 3));
                result = Math.Min(result, Math.Abs(sub - 753));
            }
            Console.WriteLine(result);
        } 
    }
}


Measured memory_bytes: 11220
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  if(X == 7 || X == 5 || X == 3) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

int N;
int H[20] = {};
int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> H[i];
    }
    int maximum = 0;
    int num = 0;
    for (int i = 0; i < N; i++){
        if (maximum <= H[i]){
            maximum = H[i];
            num += 1;
        }
    }
    cout << num << endl;
    return 0;
}

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

int n,k;

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

	int A[n];

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

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

	return 0;
}

Measured memory_bytes: 640
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = 10**9+7

    if abs(iN - iM) <= 1:
        iFacM = 1
        for i in range(1,iM+1):
            iFacM *= i
            iFacM %=iD
        if iN == iM:
            print( iFacM * iFacM % iD * 2 % iD )
        else:
            iFacN = 1
            for i in range(1,iN+1):
                iFacN *= i
                iFacN %=iD
            print( iFacM * iFacN % iD  )
    else:
        print(0)
解()


Measured memory_bytes: 3064
dic = {}

while True:
  try:
    s, i = input().split()
    if s in dic:
      dic[s].append(int(i))
    else:
      dic[s] = [int(i)]

  except EOFError:
    break

for k, v in sorted(dic.items()):
  print(k)
  print(*sorted(v))


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        string s,t; cin >> s >> t;
        ll a ,b;  cin >> a >> b;
        string p; cin >> p;
        if(p==s){
            a--;
        }else{
            b--;
        }
        cout << a <<  ' ' << b << endl;
    }
}


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

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

vector<vector<int>> G;
ll n, m, ans = 0;
ll dp[100100];

ll f(int v) {
  if (dp[v] != -1) return dp[v];

  ll res = 0;
  for (auto g : G[v]) res = max(res, f(g) + 1);
  return dp[v] = res;
}

int main() {
  cin >> n >> m;
  G.resize(n);

  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
  }
  rep(i, n) dp[i] = -1;

  rep(i, n) ans = max(ans, f(i));

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

Measured memory_bytes: 11272
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)
  
color = len(tree[1])
for key,arr in sorted(tree.items()):
  if key == 1:
    continue
    
  color = max(len(arr)+1, color)

print(color)

iro = [-1] * (n+1)

for key,arr in sorted(tree.items()):
  my_color = iro[key]
  for i in arr:
    my_color += 1
    iro[i] = my_color % color

for i in b_arr:
  print(iro[i]+1)

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

signed main() {
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n + 1][m + 1];
    memset(dp, 0, sizeof dp);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
    int x = n, y = m;
    string lcs = "";
    while(x > 0 and y > 0) {
        if(s[x - 1] == t[y - 1]) {
            lcs = s[x - 1] + lcs;
    	    x = x - 1, y = y - 1;
        } else if(dp[x - 1][y] > dp[x][y - 1]) {
      	    x = x - 1;
        } else {
    	    y = y - 1;
        }
    }
    cout << lcs << endl;
    return 0;
}

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

using namespace std;


long long f(long long b, long long n) {
    long long ret = 0;
    while (n) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

void run_case() {
//    n / b + (n % b) = s
//    let x = floor(n / b)
//    x + n - x * b = s
//    x - x * b = s - n
//    x * b - x = n - s
//    x ( b- 1 ) = n - s
//    b = (n-s) / x + 1

    long long n, s;
    cin >> n >> s;
    const int N = 1e6;
    if (n == s) {
        cout << n + 1 << endl;
        return;
    }

    if (s > n) {
        cout << -1 << endl;
        return;
    }

    for (int i = 2; i <= N; i++) {
        if (f(i, n) == s) {
            cout << i << endl;
            return;
        }
    }

    for (int x = N; x >= 1; x--) {
        long long b = (n - s) / x + 1;
        if (b >= 2 && f(b, n) == s) {
            cout << b << endl;
            return;
        }
    }

    cout << -1 << endl;

}


int main() {


    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)run_case();


    return 0;
}
 
 
 
 
 
 
 
 


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

vector<FiniteField> MakeFactorialTable(int n) {
  vector<FiniteField> values(n + 1);
  values[0] = 1;
  for (int i = 1; i <= n; i++) {
    values[i] = values[i - 1] * i;
  }
  return values;
}

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

  int n, m;
  cin >> n >> m;
  auto fs = MakeFactorialTable(m);

  FiniteField a = fs[m] / fs[m - n];
  for (int i = 1; i <= n; i++) {
    FiniteField sign = 1;
    if (i % 2) sign = P - 1;
    a += sign * fs[n] / fs[i] / fs[n - i] * fs[m - i] / fs[m - n];
  }

  FiniteField ans = a * fs[m] / fs[m - n];
  cout << ans.Value() << endl;
}

Measured memory_bytes: 7088
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			int n = sc.nextInt();
			int count = 0;
			for(int i=0;i<n;i++){
				String t = sc.next();
				t = t+t;
				if(t.indexOf(s)!=-1) count++;
			}
			System.out.println(count);
		}
	}	
}

Measured memory_bytes: 17220
#include<stdio.h>
char m[13*14];
int erase(p){
	if(m[p]=='1'){
		m[p]--;
		erase(p-1);
		erase(p+1);
		erase(p-13);
		erase(p+13);
	}
}
int main(){
	int i,c;
	while(fread(m+13,1,13*12+1,stdin)>=13*12){
		c=0;
		for(i=13;i<13*13-1;i++){
			if(m[i]=='1') {
				erase(i);
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1000005;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    ll N;
    cin >> N;
    ll sepuluh = 1;
    ll sembilan = 1;
    ll delapan = 1;
    for (int i = 0; i < N; i++) {
        sepuluh = sepuluh*10%MOD;
        sembilan = sembilan*9%MOD;
        delapan = delapan*8%MOD;
    }
    ll ans = ((sepuluh - 2*sembilan + delapan)%MOD + MOD)%MOD;
    cout << ans << "\n";
    
}


Measured memory_bytes: 3596
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *P = map(int, read().split())

    csum = [0]
    csum.extend(accumulate(P))

    ans = 0
    for i in range(N - K + 1):
        if ans < csum[i + K] - csum[i]:
            ans = csum[i + K] - csum[i]

    print((K + ans) / 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 105396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] n = RIntAr();
            Console.WriteLine(n.Distinct().Count() == 1 ? "Yes" : "No");
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main(){
  long long a,b,c,d,e;
  cin >>a>>b>>c;
  if(b>c) cout <<0<<'\n';
  else{
    if(a==1&&b==c) cout <<1<<'\n';
    else{
      if(a==1) cout <<0<<'\n';
      else cout <<(a-2)*(c-b)+1<<'\n';
    }
  }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cassert>
using namespace std;

int xor64(void) {
    static unsigned long long x = 88172645463325252ULL;
    x ^= x<<13;
    x ^= x>> 7;
    x ^= x<<17;
    return int(x&0x7fffffff);
}

int D;
vector<int> C;
vector<vector<int>> S;

struct State
{
    vector<int> T;
    vector<set<int>> X;
    long long score;
    State(): T(D, -1), X(26, set<int>{-1, D})
    {
        score = 0;
        for (int i=0; i<26; i++)
            score -= (long long)C[i]*D*(D+1)/2;
    }

    void add(int d, int t)
    {
        //assert(T[d]==-1);
        //assert(X[t].count(d)==0);

        auto p1 = X[t].lower_bound(d);
        auto p0 = p1;
        p0--;
        score += (long long)C[t]*(d-*p0)*(*p1-d);
        score += S[d][t];
        X[t].insert(d);
        T[d] = t;
    }

    long long add_dry(int d, int t)
    {
        auto p1 = X[t].lower_bound(d);
        auto p0 = p1;
        p0--;
        return (long long)C[t]*(d-*p0)*(*p1-d) + S[d][t];
    }

    void remove(int d)
    {
        //assert(T[d]!=-1);
        //assert(X[T[d]].count(d)>0);

        int t = T[d];
        auto p = X[t].find(d);
        auto p0 = p;
        p0--;
        auto p1 = p;
        p1++;
        score -= (long long)C[t]*(d-*p0)*(*p1-d);
        score -= S[d][t];
        X[t].erase(d);
        T[d] = -1;
    }
};

int main()
{
    cin>>D;
    C = vector<int>(26);
    for (int &c: C)
        cin>>c;
    S = vector<vector<int>>(D, vector<int>(26));
    for (auto &s: S)
        for (auto &x: s)
            cin>>x;

    State state;
    for (int i=0; i<D; i++)
        state.add(i, xor64()%26);

    for (int i=0; i<10000; i++)
    {
        int d = xor64()%D;
        state.remove(d);

        long long m = state.add_dry(d, 0);
        int mt = 0;
        for (int t=1; t<26; t++)
        {
            long long s = state.add_dry(d, t);
            if (s>m)
            {
                m = s;
                mt = t;
            }
        }
        state.add(d, mt);
    }
    for (int t: state.T)
        cout<<t+1<<endl;
}


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

int N;
vector<int> p(9);
vector<int> q(9);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  cin >> N;
  vector<int> array(N);
  for(int i = 0; i < N; i++){
    array.at(i) = i + 1;
  }
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> q.at(i);
  }

  int count = 0;
  int countP = 0;
  int countQ = 0;
  do{
    bool flagP = false;
    bool flagQ = false;
    count++;
    //cout << "count++" <<endl;
    for(int i = 0; i < N; i++){
      //cout << array.at(i);
      if(array.at(i) != p.at(i)){
        flagP = true;
      }
      if(array.at(i) != q.at(i)){
        flagQ = true;
      }

    }
    if(!flagP){
      countP = count;
    }
    if(!flagQ){
      countQ = count;
    }
    //cout <<endl; 
  }while( next_permutation(array.begin(), array.end()));

  //cout << countP << " " << countQ <<endl;

  cout << abs(countP - countQ) <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    cout << 800 * n - (n / 15) * 200 << "\n";
}


Measured memory_bytes: 256
N, K = [int(_) for _ in input().split()]

P = [int(_) for _ in input().split()]

for i in range(N):
    P[i] = int(P[i] * (1 + P[i]) / 2) / P[i]

ans = 0
tmp = 0
for i in range(N):
    tmp += P[i]
    if i < K - 1: continue
    ans = max(tmp, ans)
    tmp -= P[i - K + 1]
print(ans)


Measured memory_bytes: 32176
S=input()
T=input()

l=[]
for i in range(len(S)-len(T)+1):
    f=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            f=False
            break
    if f:
        tmp=S[:i]+T+S[i+len(T):]
        l.append(tmp.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    int kati=0, sum = s.size();
    rep(i, s.size()) {
        if (s[i] == 'o') kati++;
    }
    if ((15-sum)+kati >= 8) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

import static java.lang.Math.max;
import static java.lang.Math.min;


public class Main{

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int w = scanner.nextInt();
        int[] weight = new int[n + 1];
        int[] value = new int[n + 1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            weight[i] = scanner.nextInt();
            value[i] = scanner.nextInt();
            sum += value[i];
        }
        long[] dp = new long[sum + 1];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = 1000000000;
        }
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = sum - value[i]; j >= 0; j--) {
                dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]);
            }
        }
        int max = 0;
        for (int i = 0; i < dp.length; i++) {
            if(dp[i] <= w) {
                max = i;
            }
        }
        System.out.println(max);
    }



}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 100003, M = N << 1;

int n, k;
int a[N], b[N];
int tot, head[N], ver[M], nxt[M];
char s[N];

inline void add(int u, int v)
{
    ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;
}

LL fac5[N];

int main()
{
    n = gi();
    LL now = 1;
    for (int i = 1; i <= 20000; i+=1) 
    {
        now = 1;
        for (int j = 1; j <= 5; j+=1) now *= (i - 7778);
        fac5[i] = now;
    }
    for (int i = -7777; i <= 7777; i+=1)
        for (int j = -7777; j <= 7777; j+=1)
            if (fac5[i + 7778] - fac5[j + 7778] == n)
            {
                printf("%d %d\n", i, j);
                return 0;
            }
    return 0;
}


Measured memory_bytes: 3816
import collections

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

white = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == ".":
            white += 1

dx = [1,0,-1,0]
dy = [0,1,0,-1]
field[0][0] = 0
q = collections.deque([])
q.append((0,0))
while q:
    s = q.popleft()
    y,x = s[0],s[1]
    c = field[y][x]
    if y == h-1 and x == w-1:
        print(white-c-1)
        exit()
    else:
        for i in range(4):
            newy = y + dy[i]
            newx = x + dx[i]
            if 0<= newy < h and 0<= newx < w and field[newy][newx] == ".":
                field[newy][newx] = c+1
                q.append((newy,newx))
print(-1)

Measured memory_bytes: 9408
IDENTIFICATION DIVISION.
PROGRAM-ID. 165B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(20).
01 X          PIC 9(18).
01 Y          PIC 9(18).
01 LEN        PIC 9(02).
01 I          PIC 9(04). 
01 OUT        PIC Z(3)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO INP COUNT LEN.
*>
  IF (LEN <= 18)
    MOVE 0   TO OUT
    MOVE INP TO X
    MOVE 100 TO Y
    MOVE 1   TO I
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3759 OR Y >= X
      COMPUTE Y = Y + Y * 0.01
    END-PERFORM
    COMPUTE OUT = I - 1
  ELSE
    MOVE 3760 TO OUT
  END-IF.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


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

int main(void) {
  int n, m, x, b[512][512] = {};
  cin >> n >> m >> x;
  
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    b[l][r]++;
  }
  
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      b[i][j] += b[i][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      b[i][j] += b[i - 1][j];
  
  for (int i = 0; i < x; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    
    cout << b[q][q] - b[p][q] -  b[q][p] + b[p][p] << endl;
  }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
long double pi =  3.141592653589793238;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int r;cin>>r;
	double ans = double(2*pi*r);
	cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3792
use std::io::*;
use std::io::Write;
use std::str::FromStr;

/// input macro
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
///
/// # Example
///
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! eprintln (
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}

fn main() {
    input! {
        n: u32,
        p: [u32; n],
    }

    let ans = p.windows(3).filter_map(|ijk| {
        let mut ijk = ijk.to_vec();
        let j = ijk[1];
        ijk.sort();
        if ijk[1] == j { Some(()) } else { None }
    }).count();

    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
ll A,B,ans=0;
int main()
{
	scanf("%lld%lld",&A,&B);
	if(A==B)
	{
		printf("1\n");
		return 0;
	}
	int t=59;
	while(!((A>>t&1)^(B>>t&1)))t--;
	A&=(1ll<<(t+1))-1;
	B&=(1ll<<(t+1))-1;
	int r=t-1;
	while(r>=0&&(!(B>>r&1)))r--;
//	cout<<t<<" "<<A<<" "<<B<<" "<<r<<endl;
	ans+=(1ll<<t)-A;
	ans+=(1ll<<(r+1));
	ans+=(1ll<<t)-A;
//	cout<<ans<<endl;
	if(A<=((1ll<<(r+1))-1))ans-=(1ll<<(r+1))-A;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
	string s;
	cin>>s;
	bool ok;
	if(s[0]=='A')
		ok=true;
	else
	{printf("WA\n");return 0;}
	int l=s.length();
	int cn=0;
	for(int i=1;i<l;i++)
	{
		if(isupper(s[i]))
		{
			if(s[i]!='C'||i==l-1||i==1||(cn==1&&s[i]=='C'))
			{printf("WA\n");return 0;}
			else if(s[i]=='C')
			cn++;
		}
	}
	if(cn==1&&ok)
		printf("AC\n");
	else
		printf("WA\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return (a+b)%3;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
/*
int Seg_query(int a,int b,int k,int l,int r){
    cout << a MM b MM k MM l MM r << endl;
    //外からはSeg_query(a,b,0,0,n)で呼ぶ
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}*/

int Seg_query(int a,int b){
    int R=0;
    a+=n;b+=n;
    
    while(a<b){
        if(a%2==1){
            R=Seg_calc(dat[a-1],R);
            a++;
        }
        a/=2;
        if(b%2==1){
            b--;
            R=Seg_calc(R,dat[b-1]);
        }
        b/=2;
    }
    
    
    return R;
}

signed main(void){
    string S,T;
    int Q;
    int A[114514],B[114514],C[114514],D[114514];
    int G[114514],H[114514];
    
    cin >> S >> T;
    cin >> Q;
    REP(i,Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;C[i]--;D[i]--;
    }
    
    //Aを1、Bを2、O(=AB)を0と扱う
    
    //Sをセグる
    Seg_init(S.size());
    REP(i,S.size()){
        Seg_update(i,(S[i]=='A'?1:2));
    }
    REP(i,Q){
        G[i]=Seg_query(A[i],B[i]+1);
    }
    //Tをセグる
    Seg_init(T.size());
    REP(i,T.size()){
        Seg_update(i,(T[i]=='A'?1:2));
    }
    REP(i,Q){
        H[i]=Seg_query(C[i],D[i]+1);
    }
    
    //REP(i,Q){cout << G[i] MM H[i] << endl;}
    
    REP(i,Q){
        if(G[i]==H[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}



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

int main() {
  int N;
  vector<int> A;

  int sum = 0;

  cin >> N;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
    sum += a;
  }
  sort(A.begin(),A.end());

  if(sum % 2 != 0)
    for(int i = 0; i < N; i++) {
      if(A[i] % 2 == 1)	{
        sum = sum - A[i];
        break;
      }
    }
  cout << (sum/2)	<< endl;

  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, D;
    while(cin>>n>>D){
        int cnt = 0;
        D*=D;
        forn(i,n){
            ll x, y; cin>>x>>y;
            if(x*x+y*y<=D)
                ++cnt;
        }
        cout<<cnt<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define N 100
#define INF 1<<21
int G[N][N], n, labels[N], d[N], p[N];

/*
  labels:
  0 unvisited
  1 tmp
  2 included
 */

void prim(){
    int i,u, mincost;
    for(i=0; i<n; i++) {
	labels[i]=0;
	d[i]=INF;
    }
    d[0]=0;
    p[0]= -1;
    
    while (1) {
	/*find the vertex with the minimum weight and return u*/
	mincost = INF;
	for(i=0; i<n; i++) {
	    if(labels[i]!=2 && d[i]<mincost) {
		mincost= d[i];
		u=i;
		    }
	}
	
	if (mincost == INF)break;
	
	labels[u]=2;
	
	/* */
	for(i=0; i<n; i++){
	    if(labels[i]!=2 && G[u][i] != -1){
		if(G[u][i] < d[i]){
		    d[i]=G[u][i];
		    p[i]=u;
		    labels[i]=1;
		}
	    }
	}

	
    }
}

int min(int x, int y){
    return (x>=y) ? y: x;
}

int mincost[N];
int prim2() {
    int i;
    for(i=0; i<n; i++) {
	mincost[i]=INF;
	labels[i]=0;
    }
    mincost[0]=0;
    int res=0;
    while (1){
	int u,v=-1;
	for(u=0; u<n; u++){
	    if(labels[u]==0 && (v == -1 || mincost[u] < mincost[v])) v=u;
	}
	if (v==-1) break;
	labels[v]=1;
	res += mincost[v];
	for(u=0; u<n; u++){
	    if(G[v][u]!=-1)mincost[u] = min(mincost[u], G[v][u]);
	}
    }
    return res;

}

int main(){
    int i,j, sum;
    scanf("%d",&n);
    for(i=0;i<n;i++){
	for(j=0;j<n;j++){
	    scanf("%d",&G[i][j]);
	}
    }
    
    printf("%d\n", prim2());
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,min(200000),ans(0);
  bool flg(true);
  cin >> n;
  
  vector<int> p(n);
  
  for(int i = 0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i = 0;i<n;i++){
    if(min > p.at(i)){
      min = p.at(i);
    }
    if(min < p.at(i))flg = false;
    if(flg){
      ans++;
    }else{
      flg = true;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024