akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  {
    for(int j=0;j<vertex;j++) {
      if(graph[start][j]<INF/2 && graph[j][j]<0) {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
      }
    }
  }
  
  for(int i=0;i<vertex;i++) {
    if(graph[start][i]>=INF/2) {
      cout << "INF" << endl;
    } else {
      cout << graph[start][i] << endl;
    }
  }
  return 0;
}
 
inline int fastmin(int a, int b) {
  return (((a-b)>>31)&(a-b))+b;
}
 
int mymin(int a, int b)  {
  int t;
  if (a < b) {
    t = a;
  } else {
    t = b;
  }
  return t;
}
 
void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
   
  for(int k=0;k<vertex;k++)//v=4
    {
      for(int i=0;i<vertex;i++)
        {
          int gik= graph[i][k];
          for(int j=0;j<vertex;j++)
            {
              //if(graph[i][k] !=INF && graph[k][j]!=INF)
              {
                graph[i][j]= mymin(graph[i][j], gik+graph[k][j]);
              }
            }
        }
    }
   
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
        {
          if(i==j)
            {
              graph[i][j]=0;
            }
          /*else
            {
            graph[i][j]=INF;
            }*/
        }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
    dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
      {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
      }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
      for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }  
      cout << endl;    
      }*/
   
 
}

Measured memory_bytes: 5300
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	int d = sc.nextInt();
        int ab = Math.abs(a - b);
        int bc = Math.abs(b - c);
        int ac = Math.abs(a - c);
      	if(ac <= d){
            System.out.println("Yes");   
        }else if(ab <= d && bc <= d){
            System.out.println("Yes");   
        }else{
            System.out.println("No");   
        }


    }
}

Measured memory_bytes: 35496
#include<bits/stdc++.h>
using namespace std;
  int main(){
    while(1){
      int a,b;
      string op;
      cin>>a>>op>>b;
      if(op=="?") break;

      int ans;
      if(op=="+") ans=a+b;
      if(op=="-") ans=a-b;
      if(op=="*") ans=a*b;
      if(op=="/") ans=a/b;

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


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

int main(){
  int a[5],k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      if(a[j]-a[i]>k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> x(n), y(n);
    for(ll i=0;i<n;++i){
        cin>>x[i]>>y[i];
    }
    if(n == 1){
        cout<<1<<endl;
        return 0;
    }
    
    vector<vector<ll>> p(n, vector<ll> (n, INF)), q(n, vector<ll> (n, INF));
    for(ll i=0;i<n;++i){
        for(ll j=i+1;j<n;++j){
            p[i][j] = x[j] - x[i];
            q[i][j] = y[j] - y[i];
            p[j][i] = x[i] - x[j];
            q[j][i] = y[i] - y[j];
        }
    }

    ll ans = INF;
    for(ll i=0;i<n;++i){
        for(ll j=i+1;j<n;++j){
            ll sum = n;
            for(ll k=0;k<n;++k){
                for(ll l=0;l<n;++l){
                    if(x[k] == x[l] + p[i][j] and y[k] == y[l] + q[i][j]){
                        sum--;
                    }
                }
            }
            ans = min(ans, sum);
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;

    const int acTime = 100;
    const int tleTime = 1900;

    double EV = (tleTime * m + acTime * (n - m)) * pow(2, m);

    cout << EV << endl;

    return 0;
}

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

using namespace std;

int n,m,h,k;

inline long long sumk(int *score, int k){
	long long ret = 0;
	for(int i=0;i<k;i++) ret += score[i];
	return ret;
}

int main(){
	
	while(cin >> n >> m >> h >> k){
		if(!(n|m|h|k)) break;
		
		bool edge[h-1][n-1];
		int point[n];
		int score[n];
		int work[n];
		long long ret = 1e+15;
		set<pair<int,int> > cand;
		fill((bool *)edge, (bool *)edge + (n-1)*(h-1), false);
		
		for(int i=0;i<n;i++){
			cin >> point[i];
			work[i] = i;
		}
		for(int i=0;i<m;i++){
			int x,y;
			cin >> x >> y;
			edge[y-1][x-1] = true;
		}
		for(int i=0;i<h-1;i++){
			for(int j=0;j<n-1;j++){
				if(edge[i][j]){
					cand.insert(make_pair(work[j], work[j+1]));
					swap(work[j], work[j+1]);
				}
			}
		}
		for(int i=0;i<n;i++){
			score[work[i]] = point[i];
		}
		ret = min(ret, sumk(score, k));
		
		set<pair<int,int> >::iterator it = cand.begin();
		while(it != cand.end()){
			swap(score[(*it).first], score[(*it).second]);
			ret = min(ret, sumk(score,k));
			swap(score[(*it).first], score[(*it).second]);
			++it;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
 char s[10];
 scanf("%s", s);
 if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
 else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
 else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
 else printf("No\n");

    return 0;
}


Measured memory_bytes: 256
S = raw_input()
T = raw_input()
d = dict()
d2 = dict()
ret = True
for s, t in zip(S, T):
    if s in d and d[s] != t:
        ret = False
        break
    if t in d2 and d2[t] != s:
        ret = False
        break
    d[s] = t
    d2[t] = s
        
print 'Yes' if ret else 'No'

Measured memory_bytes: 18940
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N;
unsigned int p[65001], j[65001];

int main(){
    while(std::cin >> N, N){
        unsigned int sum = 0;

        FOR(i, 1, N+1){
            std::cin >> p[i];
        
            sum += p[i];
        }

        FOR(i, 1, N){
            std::cin >> j[i];

            sum += j[i];
        }

        std::sort(j+1, j+N);

        FOR(i, 1, N){
            j[i] += j[i-1];
        }

        unsigned int res = 0;
        FOR(k, 1, N+1){
            res = std::max(res, (sum-j[k-1]) * k);
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1676
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;
string dice[6][3];

inline bool ok(char c){
  return c == '*';
}

bool check(int f, int x, int y){
  if (x == -1) {
    REP(i, 3) if (ok(dice[f][i][y])) return true;
    return false;
  }
  
  if (y == -1) {
    REP(i, 3) if (ok(dice[f][x][i])) return true;
    return false;
  }
  assert(false);
}

int main(){
  ios::sync_with_stdio(false);
  
  while (cin >> dice[0][0] && dice[0][0] != "#"){
    cin >> dice[0][1] >> dice[0][2];
    REP2(i, 1, 6) REP(j, 3){
      cin >> dice[i][j];
    }

    int res = 3;
    
    if (check(0, 2, -1) && check(2, 2, -1)) res = min(res, 0);
    if (check(0, -1, 2) && check(2, -1, 0)) res = min(res, 1);
    if (check(0, -1, 0) && check(2, -1, 2)) res = min(res, 1);
    if (check(0, 0, -1) && check(2, 0, -1)) res = min(res, 2);

    if (check(4, 0, -1) && check(5, 2, -1)) res = min(res, 1);
    if (check(5, 0, -1) && check(4, 2, -1)) res = min(res, 1);
    if (check(4, -1, 0) && check(5, -1, 0)) res = min(res, 2);
    if (check(4, -1, 2) && check(5, -1, 2)) res = min(res, 2);

    if (check(1, -1, 0) && check(3, -1, 2)) res = min(res, 2);
    if (check(3, -1, 0) && check(1, -1, 2)) res = min(res, 2);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef pair<int, int> P;
 
struct station
{
    station(int to, int cost, int time)
    {
        this->to = to;
        this->cost = cost;
        this->time = time;
    }

    int to;
    int cost;
    int time;
};

void dijkstra(int from, int mode);

vector<station> route[1000];
int mini[1000];
int n, m;

int main()
{
    while (scanf("%d %d", &n, &m) * n != 0){
        for (int i = 0; i < m; i++){
            route[i].clear();
        }
        for (int i = 0; i < n; i++){
            int a, b;
            int cost, time;
             
            scanf("%d %d %d %d", &a, &b, &cost, &time);
            a--, b--;
            route[a].push_back(station(b, cost, time));
            route[b].push_back(station(a, cost, time));
        }
        
        int k;
        scanf("%d", &k);
        while (k-- > 0){
            int p, q, r;
            scanf("%d %d %d", &p, &q, &r);
            p--, q--;
            mini[p] = 0;
            dijkstra(p, r);
            printf("%d\n", mini[q]);
        }
    }
    
    return 0;
}
 
void dijkstra(int from, int mode)
{
	priority_queue<P, vector<P>, greater<P> > que;
	
	fill(mini, mini + m, 1000000000);
	mini[from] = 0;
	que.push(P(0, from));
	
	while (!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		
		if (mini[v] < p.first){
			continue;
		}
		for (int i = 0; i < route[v].size(); i++){
			station s = route[v][i];
			if (mode == 0 && mini[s.to] > mini[v] + s.cost){
				mini[s.to] = mini[v] + s.cost;
				que.push(P(mini[s.to], s.to));
			}
			else if (mode == 1 && mini[s.to] > mini[v] + s.time){
				mini[s.to] = mini[v] + s.time;
				que.push(P(mini[s.to], s.to));
			}
		}
	}
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> s;
  ll len = s.size();
  ll cnt = 0;
  RFOR(i, 0, len) {
    if (s[i] == 'A') ans += cnt;
    else if (s[i] == 'B') {
      cnt = 0;
    }
    else {
      if (i&&s[i - 1] == 'B') {
        cnt++;
        i--;
      }
      else {
        cnt = 0;
      }
    }
  }
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

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

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

    while(n > 1000) {
        n -= 1000;
    }
    cout << 1000 - n << endl;
    return 0;
}

Measured memory_bytes: 3228
n,m = map(int,input().split())
l = [0]*m
r = [0]*m
ans = 0
for i in range(m):
    l[i],r[i] = map(int,input().split())

Min = max(l)
Max = min(r)
for i in range(n):
    if Min<=i+1<=Max:
        ans += 1
print(ans)

Measured memory_bytes: 10868
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e16 + 7;
const int MOD = 1e9 + 7;

int main() {

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	vector<ll> x(a), y(b), z(c);
	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
	}

	for (int i = 0; i < b; i++)
	{
		cin >> y[i];
	}

	for (int i = 0; i < c; i++)
	{
		cin >> z[i];
	}

	vector<ll> vec;
	for (int i = 0; i < a; i++)
	{
		for (int j = 0; j < b; j++)
		{
			vec.push_back(x[i] + y[j]);
		}
	}

	sort(vec.rbegin(), vec.rend());

	ll siz = vec.size();

	vector<ll> ans;

	for (int i = 0; i < min(siz,k); i++)
	{
		//上からk個と組み合わせる
		for (int j = 0; j < c; j++)
		{
			ans.push_back(vec[i] + z[j]);
		}
	}

	sort(ans.rbegin(), ans.rend());
	siz = ans.size();
	for (int i = 0; i < min(k,siz); i++)
	{
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 43368
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	s := scanString()

	cnt := 0
	for i := 0; i < n; i++ {
		if s[i] == ')' {
			cnt--
		} else {
			for j := 0; j < -cnt; j++ {
				fmt.Fprint(wr, "(")
			}
			cnt = max(0,cnt)
			cnt++
		}
		// debug(string(s[i]),cnt)
	}

	for i := 0; i < -cnt; i++ {
		fmt.Fprint(wr, "(")
	}
	fmt.Fprint(wr, s)
	for i := 0; i < cnt; i++ {
		fmt.Fprint(wr, ")")
	}
	fmt.Fprintln(wr)

}


Measured memory_bytes: 640
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
  static void Main()
  {
    string s = Console.ReadLine();
    long answer = 0;
    long answerPlus = 0;
    long multiplyMemo = 1;

    for(long i = 0; i < (1 << s.Length-1); i++)//bit全探索
    {
      answerPlus = s[(int)(s.Length-1)] - '0';//一の位
      multiplyMemo = 1;
      for(long checkDigit = 0; checkDigit < s.Length-1; checkDigit++)//右からcheckDigit桁目を見る
      {
        if((i & (1<<(int)checkDigit)) != 0)//右からcheckDigit番目が1ならば
        {
          multiplyMemo *= 10;
        }else//右からcheckDigit番目が0ならば
        {
          multiplyMemo = 1;
        }
        answerPlus += (s[(int)(s.Length-2-checkDigit)] - '0') * multiplyMemo;
      }
      answer += answerPlus;
      //Console.WriteLine(answerPlus);
    }
  
    Console.WriteLine(answer);
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    string a,b;
    cin >> a >>b;
    bool f=false;
    if(a.size()>b.size()) cout<<"GREATER"<<endl;
    else if(a.size()<b.size()) cout <<"LESS"<<endl;
    else{
        for(int i=0;i<b.size();i++){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                f=true;
                break;
            }else if(a[i]<b[i]){
                cout <<"LESS"<<endl;
                f=true;
                break;
            }
        }
        if(f==false) cout <<"EQUAL" <<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ", 3);
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);

        System.out.println(Math.min(c, b / a));
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> >g(n + 2);
    vector<int>vis(n + 2, 0);
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    queue<int>q;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            vis[i] = 1;
            cnt++;
            q.push(i);
            while(!q.empty()){
                int u = q.front();
                q.pop();
                for(int j = 0; j < g[u].size(); j++){
                    int v = g[u][j];
                    if(vis[v] == 0){
                        vis[v] = 1;
                        q.push(v);
                    }
                }
            }
        }
    }
    cout << cnt - 1;
    return 0;
}

Measured memory_bytes: 8804
using System;

class Program{
    static void Main(){
        var sep = ' ';
        var nzw_input = Console.ReadLine().Split(sep);
        var n = int.Parse(nzw_input[0]);
        var w = int.Parse(nzw_input[2]);
        
        var a_str = Console.ReadLine().Split(sep);
        var a = new int[n+1];
        for(int i = 0; i < n; i++)
            a[i+1] = int.Parse(a_str[i]);
        
        if(n == 1){
            Console.WriteLine(Math.Abs(a[1] - w));
            return;
        }
        
        a[0] = w;
        var dp = new DP(n);
        Console.WriteLine(dp.ActionX(a, 1, 0));
    }
}
 
public class DP{
    int[,] actionXMemo;
    int[,] actionYMemo;
    public DP(int n){
        actionXMemo = new int[n+1, n+1];
        actionYMemo = new int[n+1, n+1];
        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < n + 1; j++){
                actionXMemo[i, j] = -1;
                actionYMemo[i, j] = -1;
            }
        }
    }
    public int ActionX(int[] arr, int left_i, int w_idx){
        if(actionXMemo[left_i, w_idx] != -1)
            return actionXMemo[left_i, w_idx];
        
        var max_abs = Math.Abs(arr[arr.Length - 1] - arr[w_idx]);
        for(int i = left_i; i < arr.Length - 1; i++){
            var diff = ActionY(arr, i + 1, i);
            if(diff > max_abs)
                max_abs = diff;
        }
        actionXMemo[left_i, w_idx] = max_abs;
        return max_abs;
    }
    
    public int ActionY(int[] arr, int left_i, int z_idx){
        if(actionYMemo[left_i, z_idx] != -1)
            return actionYMemo[left_i, z_idx];
        var min_abs = Math.Abs(arr[arr.Length - 1] - arr[z_idx]);
        for(int i = left_i; i < arr.Length - 1; i++){
            var diff = ActionX(arr, i + 1, i);
            if(diff < min_abs)
                min_abs = diff;
        }
        actionYMemo[left_i, z_idx] = min_abs;
        return min_abs;
    }
}

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

#define int long long

const int MAX_DIGIT = 50;
int dp[100][2]; // dp[i][j]: 上からi桁目までみたとき、jはi桁目までで確定してるかどうか

signed main() {
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  fill(dp[0], dp[100], -1);
  dp[MAX_DIGIT][0] = 0; // 初期状態。上位桁から決めていき、最初はマスク値がK以下か確定していない状態

  for (int digit = MAX_DIGIT-1; digit >= 0; digit--) {
    int mask = 1LL << digit; // 上からdigit桁目を立てたマスク

    // Aでもともと上からdigit桁目にビットが立っているものの個数
    int num = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] & mask) {
        num++;
      }
    }

    // マスク値の上からdigit桁目を0, 1にしたときのスコア
    int score0 = mask * num; // 上からdigit桁目のマスクビットを立てない時のスコア
    int score1 = mask * (N - num); // 上からdigit桁目のマスクビットを立てる時のスコア

    // 1 -> 1(マスク値がK以下に確定した状態 -> マスク値がK以下に確定した状態）
    // マスク値がK以下であることは確定しているので、上からdigit桁以降のビットは立てても立てなくても良い
    // なので、ビットを立てたときと立ててないときのスコアの大きい方を採用する
    if (dp[digit+1][1] != -1) {
      dp[digit][1] = max(dp[digit][1], max(dp[digit+1][1] + score0, dp[digit+1][1] + score1));
    }

    // 0 -> 1(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定した状態)
    // Kの立っている上からdigit桁目を引っ込めることでマスク値がK以下に確定する。なのでscore0を採用する
    if (dp[digit+1][0] != 1) {
      if (K & mask) { // Kの上からdigit桁目が立っていたら引っ込める
        dp[digit][1] = max(dp[digit][1], dp[digit+1][0] + score0);
      }
    }

    // 0 -> 0(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定していない状態)
    // Kの上からdigit桁目をそのままにするということ
    // なので、Kの上からdigit桁目が0ならscore0を採用し、 Kの上からdigit桁目が1ならscore1を採用する
    if (dp[digit+1][0] != -1) {
      if (K & mask) { // Kの上からdigit桁目が立ってる
        dp[digit][0] = max(dp[digit][0], dp[digit+1][0] + score1);
      } else { // Kの上からdigit桁目が立ってない
        dp[digit][0] = max(dp[digit][0], dp[digit+1][0] + score0);
      }
    }
  }

  cout << max(dp[0][1], dp[0][0]) << endl;

  return 0;
}


Measured memory_bytes: 1024
/*alurquiza*/
//https://matcomgrader.com/problem/9623/dictionary-search/
//Segment Tree + binary search
#include <bits/stdc++.h>

using namespace::std;

typedef long long LL;
const int MOD = 1e9 + 7;

LL pot(int base,int exp){
	if(exp == 1)
		return base;
	if(exp % 2 == 0){
		LL aux = pot(base,exp / 2);
		return aux * aux % MOD;
	}
	return pot(base,exp - 1) * base % MOD;
}

// long long fact(int ini,int fin){
// 	LL r = 1;
// 	while(ini <= fin)
// 		r = r * ini++ % MOD;
// 	return r;
// }

LL C(int N,int K,std::vector<LL> &F){
	return F[N] * pot(F[K],MOD - 2) % MOD * pot(F[N - K],MOD - 2) % MOD;
}

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

	// freopen("milkvisits.in","r",stdin);
	// freopen("milkvisits.out","w",stdout);

	int N,K;
	cin >> N >> K;

	K = min(K,N - 1);

	std::vector<LL> F(N + 1);
	F[0] = 1;
	for(int i = 1;i <= N;i++)
		F[i] = F[i - 1] * i % MOD;

	long long sol = 0;
	for(int i = N - K;i <= N;i++){
		sol += C(N,i,F) * C(N - 1,i - 1,F) % MOD;
		sol %= MOD;
	}

	cout << sol << '\n';

	return 0;
}

//g++ -std=c++11 -Wall DS.cpp -o main

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

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

	VI H(N);
	rbf(h, H) cin >> h;

	int cnt = 0, max = 0;

	rep(i, N - 1) {
		if (H[i] >= H[i + 1]) cnt++;
		else {
			if (cnt > max) max = cnt;
			cnt = 0;
		}
	}

	if (cnt > max) max = cnt;
	COL(max);

	return 0;
}

Measured memory_bytes: 640
import collections

N = int(input())
S = []
for i in range(N):
    S.append(input())
count = collections.Counter(S)

print("AC x " + str(count["AC"]))
print("WA x "+ str(count["WA"]))
print("TLE x "+ str(count["TLE"]))
print("RE x "+ str(count["RE"]))

Measured memory_bytes: 16572
N, M = map(int, input().split())
ac_cnt_tmp = [0] * N
wa_cnt_tmp = [0] * N

AC, WA = 0, 0
for _ in range(M):
  p_str, s = map(str, input().split())
  p = int(p_str)
  if ac_cnt_tmp[p-1] == 1:
    continue
  if s == "WA":
    wa_cnt_tmp[p-1] += 1
  elif s == "AC":
    ac_cnt_tmp[p-1] = 1
    AC += 1
    WA += wa_cnt_tmp[p-1]
    
print(AC, WA)

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,a[22][22];
int dp[1<<22];
void solve(){
    cin>>n;
    rep(i,0,n){
        rep(j,0,n){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    rep(i,1,1<<n){
        int d=__builtin_popcount(i)-1;
        rep(j,0,n){
            if((i>>j)&1 and a[d][j]) dp[i]=(dp[i]+dp[i^(1<<j)])%hell;
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int x;
  cin >> x;
  cout << (x ^ 1);
  return 0;
}




Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
const int Max = 1e6;

int main(){
	char a[Max], b[Max];
	int A, B, flag = 0;
	gets(a);
	gets(b);
	if(strlen(a) > strlen(b)) flag = -1;
	if(strlen(a) < strlen(b)) flag = 1;
	if(strlen(a) == strlen(b)){
		 for(int i = 0; i < strlen(a); i++){
		 	 A = a[i], B = b[i];
		 	 if(A > B) { flag = -1; break; }
		 	 if(A < B) { flag = 1; break; }
		 }
	}
	if(flag == -1) printf("GREATER\n");
	if(flag == 0) printf("EQUAL\n");
	if(flag == 1) printf("LESS\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
  int N;
  int counter = 0;
  cin >> N;
  int a[N];
  for(int i=0;i < N;i++)
  {
    cin >> a[i];
  }
  for(int j = 0;j < N;j++)
  {
    if(a[j] != j+1)
    {
      counter++;
    }
  }
  if(counter <=2)
  {
    cout << "YES" << endl;
  }
  else
  {
     cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3052
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	x := scanInt()

	a := 100
	for i := 0; ; i++ {
		a = int(float64(a)*1.01)
		if a >= x {
			fmt.Fprintln(wr, i+1)
			return
		}
	}
}

func pow(a, n int) int {
	res := 1

	for n > 0 {
		if n&1 == 1 {
			res *= a
		}
		a *= a
		n >>= 1
	}
	return res
}


Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	string s;
	cin >> s;
	int nowA = 0;
	ll ans = 0;
	rep(i, s.length()){
		if(s[i]=='A') nowA++;
		else if(s.substr(i, 2)=="BC"){
			ans += nowA;
			i++;
		}else nowA = 0;
	}
	cout << ans << endl;
}

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

int main()
{
    int ac = 0;
    int n, q; 
    string str;
    cin >> n >> q >> str;
    vector<int> cnt(n);
    cnt[0] = 0;
    for(int i = 1; i < n; i++){
        if(str[i - 1] == 'A' && str[i] == 'C') ac++;
        cnt[i] = ac;
    }

    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << cnt[r-1] - cnt[l-1] << endl;
    }
}

Measured memory_bytes: 1408
k, a, b = [int(s) for s in input().split()]

if b - a <= 1:
    print(k+1)
else:
    ans = 1
    rest = k

    if a > 1:
        ans += a - 1
        rest -= a - 1

    if rest % 2 == 0:
        ans += (rest // 2) * (b - a)
    else:
        ans += (rest // 2) * (b - a) + 1
    print(ans)
        


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(s):
    # implement process
    pass

def main():
    # input
    s = input()
    flag = len(set(s)) == 2 and s.count(s[0]) == 2
    ans = "Yes" if flag else "No"
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
AACD
"""
_EXPECTED = """\
Yes
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9096
#include <stdio.h>
int main(void){
    int a, b, c, d, i, j;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if(a % d == 0){
        i = (a / d);
    }else{
        i = (a / d + 1);
    }
    if(c % b == 0){
        j = (c / b);
    }else{
        j = (c / b + 1); 
    }
    if(i >= j){
        printf("Yes");
    }else{
        printf("No");
    }
}


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

int main(){
	int n,cnt=0,cnt1=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]=='W')
			cnt++;
	for(int i=n-1;i>=n-cnt;i--)
		if(s[i]=='R')
			cnt1++;
	printf("%d\n",cnt1);
	return 0;
}

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

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

    int n,k;
    cin >> n >> k;

    int dp[n];

    dp[0] = 0;

    int arr[n];

    for(int i = 0; i<n; i++){
        cin >> arr[i];
    }

    dp[1] = abs(arr[1] - arr[0]);

    for(int i = 2; i<=n; i++){
        
        dp[i] = INT_MAX;

        for(int j = 1; j<=k; j++){

            if(i-j < 0){
                break;
            }

            dp[i] = min(dp[i], abs(arr[i] - arr[i-j]) + dp[i-j]);
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

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

using Point = complex<double>;
inline void print(Point a) { printf("%.8lf %.8lf\n", real(a), imag(a)); }
constexpr Point to_rotate() { return Point(cos(acos(-1.0) / 3.0), sin(acos(-1.0) / 3.0));}
void recursion(Point l, Point r, int depth) {
    if(depth == 0) return;
    Point base = (r - l) / 3.0;
    Point a(l + base), b(l + base * 2.0);
    Point c = to_rotate() * (b - a) + a;
    recursion(l, a, depth - 1);
    print(a);
    recursion(a, c, depth - 1);
    print(c);
    recursion(c, b, depth - 1);
    print(b);
    recursion(b, r, depth - 1);
}
int main() {
    int n;
    scanf("%d", &n);
    Point a(0.0, 0.0), b(100.0, 0.0);
    print(a);
    recursion(a, b, n);
    print(b);
    return 0;
}

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

int main() {
	int n, l;
	cin >> n >> l;
	if (l <= 0 && 0 <= l + n - 1)cout << (l+l+n-1)*n/2 << endl;
	else if(l+n-1<0) cout << (l + l + n - 1) * n / 2 -(l+n-1)<< endl;
	else if (0 < l)cout << (l + l + n - 1) * n / 2 - l << endl;

	//l ~ l+n-1
}

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

typedef long long ll;

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

ll a,b,c,d;
ll gb;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b>>c>>d;
    gb=c*d/gcd(c,d);
    ll aa=a-(a/c+a/d-a/gb);
    ll bb=b-(b/c+b/d-b/gb);
    cout<<bb-aa+(a%c&&a%d)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	if(x<0)putchar('-'),x=-x;
	int y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
ll n,m,mod=1e9+7,dp[1005][1005];
char a[1005][1005];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			a[i][j]=getchar();
			while(a[i][j]=='\n' or a[i][j]=='\r')a[i][j]=getchar();
		}
	dp[0][1]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(a[i][j]=='.')
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	print(dp[n][m]);
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <numeric>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<int>a(h+1,1<<30);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        a[x] = min(a[x],y);
    }
    int pos = 1;
    for(int i = 2; i <= h; i++){
        if(a[i]<=pos){
            cout << i-1 << endl;
            return 0;
        }
        if(a[i] != pos+1){
            pos++;
        }
    }
    cout << h << endl;
    return 0;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
char k[3] = {'R', 'U', 'D'};
char g[3] = {'L', 'U', 'D'};
int main()
{
    string s;cin >> s;
    rep(i,sz(s))
    {
        if((i+1)%2==1)
        {
            bool flag = false;
            for (auto &&c : k)
            {
                if(s[i]==c)
                {
                    flag = true;
                }
            }
            if(!flag)
            {
                cout << "No" << endl;
                return 0;
            }
            
        }
        if ((i + 1) % 2 == 0)
        {
            bool flag = false;
            for (auto &&c : g)
            {
                if (s[i] == c)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3596
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,a,b = Is()
if abs(a-b)%2==0:
    print("Alice")
else:
    print("Borys")

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

using namespace std;

const int N = 100010;

int n, k, h[N], f[N];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", h + i);
  }
  for (int i = n - 1; i > 0; --i) {
    f[i] = abs(h[i + 1] - h[i]) + f[i + 1];
    for (int j = 1; j <= k and i + j <= n; ++j) {
      f[i] = min(f[i], abs(h[i + j] - h[i]) + f[i + j]);
    } 
  }
  cout << f[1] << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;int main(){int N,o=0,n,c,p,t,a=0,b=0;cin>>N;int A[N],B[N],s=N-1,X[N];A[0]=1;B[0]=1;char x;for(int i=0;i<N;i++){cin>>x;X[i]=x-48;o+=X[i];}for(int i=1;i<N;i++)A[i]=A[i-1]*2%(o+1);if(o>1)for(int i=1;i<N;i++)B[i]=B[i-1]*2%(o-1);else for(int i=0;i<N;i++)B[i]=0;for(int i=0;i<N;i++){b+=B[s-i]*X[i];a+=A[s-i]*X[i];if(b>2*(o-1))b+=1-o;if(a>2*(o+1))a-=o+1;}for(int i=0;i<N;i++){c=0;if(X[i]){p=o-1;n=b-B[s-i];}else{p=o+1;n=a+A[s-i];}if(p==0)n=0;else if(n==0)c=1;while(n){n=n%p;t=n;p=0;while(t){if(t%2==1)p++;t=t/2;}c++;}cout<<c<<endl;}}


Measured memory_bytes: 5920
package main

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

const mod = 998244353
const facNum = 300001
const INF = 1001001001

func main() {
	sc := newScanner(os.Stdin)
	S,W := sc.i(), sc.i()
	if W >=S {
		fmt.Println("unsafe")
		
	}else {
		fmt.Println("safe")
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}


Measured memory_bytes: 1756
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let v: Vec<i32> = read_vec();
    let (n, y) = (v[0], v[1]);
    let mut found = false;
    'outer: for i in 0..n+1 {
        for j in 0..n-i+1 {
            let z = y - (10000 * i + 5000 * j);
            if z % 1000 == 0 && z / 1000 == n - (i + j) {
                println!("{} {} {}", i, j, n - i - j);
                found = true;
                break 'outer;
            }
        }
    }
    if !found {
        println!("{} {} {}", -1, -1, -1);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll H, N;
  cin >> H >> N;
  Vl A(N);
  REP(i, N) {
    cin >> A.at(i);
    H -= A.at(i);
  }
  if (H <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def root(x):
    if par[x] == x:
        return x
    else:
        r = root(par[x])
        weight[x] += weight[par[x]]
        par[x] = r
        return r

def union(x,y,w):
    rx = root(x)
    ry = root(y)
    if rank[rx] < rank[ry]:
        par[rx] = ry
        weight[rx] = w - weight[x] + weight[y]
    else:
        par[ry] = rx
        weight[ry] = - w - weight[y] + weight[x]
        if rank[rx] == rank[ry]:
            rank[rx] += 1
def same(x,y):
    return root(x) == root(y)

def diff(x,y):
    return weight[x] - weight[y]

n,q = LI()
par = [i for i in range(n)]
weight = [0]*n
rank = [0]*n
for _ in range(q):
    lst = LI()
    if lst[0] == 0:
        x,y,z = lst[1:4]
        if not same(x,y):
            union(x,y,z)
    else:
        x,y = lst[1:3]
        if not same(x,y):
            print('?')
        else:
            print(diff(x,y))



Measured memory_bytes: 12980
#include <bits/stdc++.h>
using std::vector;
using std::string;

int main() {
	std::ios::sync_with_stdio(false);
	int n, m, A, B;
	std::cin >> n >> m >> A >> B;
	vector<string> s(n, string(m, '0'));
	for (int i = 0; i < B; i++)
		for (int j = A; j < m; j++)
			s[i][j] = '1';
	for (int j = 0; j < A; j++)
		for (int i = B; i < n; i++)
			s[i][j] = '1';
	for (int i = 0; i < n; i++)
		std::cout << s[i] << "\n";
 	return 0;
}

Measured memory_bytes: 2304