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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	int m4 = 0;
	int m2 = 0;
	int m1 = 0;
	for (int i = 0; i < n; i++) {
		if (a.at(i) % 4 == 0)m4++;
		else {
			if (a.at(i) % 2 == 0)m2++;
			else m1++;
		}
	}
	if (n / 2 <= m4)cout << "Yes" << endl;
	else if (n - (m4*2)<=m2)cout << "Yes" << endl;
	else cout << "No" << endl;

	/*
	m1 m4 m1 m4 m1 m4 m1
	(m1<=m4)
	m4がn/2個あった場合 x m4 x m4 x m4...
	
	m4少々でm2がある程度あった場合
	x m4 x m4 x m4 m2 m2 m2 m2 
	(m1<=m4)

	m2だけの場合　m2 m2 m2 m2 m2 m2 m2
	*/
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    vector<vector<int>> G(n);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    bool ok = 0;
    for (int i = 0; i < n; ++i) {
        bool flg1 = 0,flg2 = 0;
        for(int x : G[i]){
            if(x == 0) flg1 = 1;
            if(x == n-1) flg2 = 1;
        }
        if(flg1&&flg2) ok = 1;
    }
    if(ok) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 13552
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  vi b(n+1), w(n+1);
  rep(i,n){
    b[i+1] += b[i];
    if(s[i] == '#') b[i+1]++;
  }
  for(int i = n-1; 0 <= i; i--){
    w[i] += w[i+1];
    if(s[i] == '.') w[i]++;
  }
  int ans = INF;
  rep(i,n) chmin(ans,w[i+1]+b[i]);
  cout << ans;
  cout << "\n";
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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<int> A(3);

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

    sort(A.begin(), A.end());

    cout << abs(A[1]-A[0]) + abs(A[2]-A[1]) << endl;


    return 0;
}


Measured memory_bytes: 892
import sys
flush = sys.stdout.flush

d = {"M":0, "F":1}
def check(i):
    print(i)
    flush()
    s = input()
    if s[0] == "V":
        exit()
    return d[s[0]]

n = int(input())
left = 0
right = n-1
ls = check(left)
rs = check(right)

while right-left > 1:
    mid = (right+left)//2
    c = check(mid)
    if (c+mid-left)%2 == ls:
        left = mid
        ls = c
    else:
        right = mid

Measured memory_bytes: 39104
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int n;

typedef struct Point
{
    double x;
    double y;
} P;

void KochCurve(P p1, P p2, int i)
{
    if (i == n)
    {
        printf("%.8lf %.8lf\n", p1.x, p1.y);
        return;
    }
    else
    {
        P s, u, t;
        s.x = p1.x + (p2.x - p1.x) / 3;
        s.y = p1.y + (p2.y - p1.y) / 3;
        t.x = p1.x + (p2.x - p1.x) * 2 / 3;
        t.y = p1.y + (p2.y - p1.y) * 2 / 3;
        u.x = s.x + (p2.x - p1.x) / 6 - (p2.y - p1.y) * sqrt(3.0) / 6;
        u.y = s.y + (p2.x - p1.x) * sqrt(3.0) / 6 + (p2.y - p1.y) / 6;
        KochCurve(p1, s, i + 1);
        KochCurve(s, u, i + 1);
        KochCurve(u, t, i + 1);
        KochCurve(t, p2, i + 1);
    }
}

int main()
{
    cin >> n;
    P p1, p2;
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;
    KochCurve(p1, p2, 0);
    printf("%.8lf %.8lf\n", p2.x, p2.y);
    return 0;
}


Measured memory_bytes: 3152
function main(input){
  const arr=input.trim().split("");

  const hunya=arr.filter(function(a){
    return a !==arr[0];
  })
  const hunyahunya=hunya.filter(function(a){
    return a !== hunya[0];
  })
  if(hunyahunya.length==0 && hunya.length==2){
    console.log("Yes");
  }else{
    console.log("No");
  }

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vll a(X), b(Y), c(Z);
    for(auto& e : a) cin >> e;
    for(auto& e : b) cin >> e;
    for(auto& e : c) cin >> e;

    vll ab;
    for(auto& e1 : a){
        for(auto& e2 : b){
            ab.emplace_back(e1 + e2);
        }
    }

    sort(_all(ab), greater<ll>());
    using Elem = tuple<ll, int, int>;
    priority_queue<Elem> q;
    rep(j, Z){
        q.push(Elem(ab[0] + c[j], 0, j));
    }

    rep(_, K){
        ll cur;
        int i, j; tie(cur, i, j) = q.top();
        q.pop();

        cout << cur << endl;

        int ni = i + 1;
        if(ni < ab.size()){
            q.push(Elem(ab[ni] + c[j], ni, j));
        }
    }

    return 0;
}


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

int main() {
    int H, W;
    while (cin >> H >> W) {
        if (H == 0 && W == 0) {
            return 0;
        }
        for (int i = 1; i <= H; i++) {
            if (i % 2 == 1) {
                for (int j = 1; j <= W; j++) {
                    if (j % 2 == 1) {
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                }
                cout << endl;
            } else {
                for (int k = 1; k <= W; k++) {
                    if (k % 2 == 1) {
                        cout << ".";
                    } else {
                        cout << "#";
                    }
                }
                cout << endl;
            }
        }
        cout << endl;
    }
}


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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    set<string> pin;
    map<char, int> left, right;
    int n;
    string s;
    cin >> n >> s;
    left[s[0]]++;
    for (int i = 1; i < n; i++)
        right[s[i]]++;
    for (int i = 1; i < n - 1; i++) {
        right[s[i]]--;
        for (auto x : left) {
            for (auto y : right) {
                if (x.second && y.second) {
                    string t = "";
                    t.push_back(x.first);
                    t.push_back(s[i]);
                    t.push_back(y.first);
                    pin.insert(t);
                }
            }
        }
        left[s[i]]++;
    }
    cout << pin.size();
}

Measured memory_bytes: 384
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

#define mod 104857601
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)

const double eps = 0.000000001;
#define ll long long
#define leps 1e-18
#define mkp make_pair
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) begin(v), end(v)
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

// Utils
random_device rd;
mt19937 mt(rd());

const int N_ = 100001;
vector<int> primes;
int *least_prime;
void cieve() {
  least_prime = new int[N_];
  fill(least_prime, least_prime + N_, -1);

  for (int i = 2; i < N_; i++) {
    if (least_prime[i] == -1) {
      least_prime[i] = i;
      primes.pb(i);
    }
    for (auto &c: primes) {
      if (c * i >= N_ || c > least_prime[i]) break;
      least_prime[c * i] = c;
    }
  }
}

template<typename NType>
NType gcd(NType a, NType b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template<typename NType>
NType lcm(NType a, NType b) { return a / gcd(a, b) * b; }
template<typename NType>
NType phi(NType n_) {
  NType ans = n_;
  for (NType i = 2; i * i <= n_; i++) {
    if (n_ % i == 0) {
      while (n_ % i == 0) n_ /= i;
      ans -= ans / i;
    }
  }
  if (n_ > 1) ans -= ans / n_;
  return ans;
}

int binpow(ll a, int n, const int M = mod) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      res = (a * res) % M;
      n--;
    } else {
      a = (a * a) % M;
      n >>= 1;
    }
  }
  ((res %= M) += M) %= M;
  return res;
}
// End of Utils

//ofstream cout("/Users/user/Desktop/test.txt");

void solve(int T) {
  int K;
  cin >> K;

  int tmp = 7;
  int cnt = 1;
  while(tmp % K != 0){
    if(cnt > 10 * K) {
      cout << -1 << endl;
      return;
    }
    cnt ++;
    tmp *= 10;
    tmp += 7;
    ((tmp %= K) += K)%= K;

  }
  cout << cnt;
}

#define MULTIPLE_TEST 0
#define PRECALC_CIEVE 0
int main(int argc, char const *argv[]){
  if (PRECALC_CIEVE) cieve();
  int t{1};
  if (MULTIPLE_TEST) scanf("%d\n", &t);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int i = 1;
  while (t-- > 0) {
    solve(i++);
  }
}


Measured memory_bytes: 3656
import java.util.*

fun main(args: Array<String>) {
    val (N, u, v) = readLine()!!.split(" ").map{it.toInt()}
    val A = Array(N - 1) {0}
    val B = Array(N - 1) {0}

    val g = Graph(N, 0, 1e8.toInt()) {a,b -> a + b}

    for (i in A.indices) {
        val (a, b) = readLine()!!.split(" ").map{it.toInt()}
        A[i] = a
        B[i] = b
        g.edges[a - 1].add(Edge(a - 1, b - 1, 1))
        g.edges[b - 1].add(Edge(b - 1, a - 1, 1))
    }

    val da = dijkstra(g, v - 1).first
    val dc = dijkstra(g, u - 1).first

    var res = 0
    for (i in g.edges.indices) {
        if (da[i] <= dc[i]) {
            continue
        }
        if (g.edges[i].size > 1) {
            continue
        }

        res = Math.max(res, da[i] - 1)
    }

    println(res)
}

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

private inline fun <reified T: Comparable<T>>dijkstra(g: Graph<T>, s: Int): Pair<Array<T>, Array<Int>> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}

    val Q = PriorityQueue<Edge<T>>()

    dist[s] = g.zero
    Q.add(Edge(-2, s, g.zero))

    while(Q.isNotEmpty()) {
        val e = Q.peek()
        val v = e.to
        Q.poll()

        if (prev[v] != -1) continue
        prev[v] = e.from
        for (i in g.edges[v]) {
            val d = g.plus(dist[v], i.weight)
            if (dist[i.to] > d) {
                dist[i.to] = d
                Q.add(Edge(i.from, i.to, d))
            }
        }
    }

    return Pair(dist, prev)
}


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

int main() {
  int n;
  cin >> n;
  vector<char> arare(n);
  for (int i = 0; i < n; i++) {
    cin >> arare.at(i);
  }
  bool tmp = false;
  for (int x : arare) {
    if (x == 'Y') {
      tmp = true;
    }
  }
  if (tmp) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int[][][] room = new int[4][][];
		for (int i = 0; i < 4; i++) {
			room[i] = new int[3][];
			for (int j = 0; j < 3; j++) {
				room[i][j] = new int[10];
			}
		}
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			room[b - 1][f - 1][r - 1] += v;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + room[i][j][k]);
				}
				System.out.println();
			}
			if (i != 3) System.out.println("####################");
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
  int n;
  double t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  double min = 1e9, ans = 0;
  int min_index = 0;
  for(int i = 0; i < n; i++){
    ans = abs((t - h[i] * 0.006) - a);
    if(ans < min){
      min = ans;
      min_index = i + 1;
    }
  }
  cout << min_index << endl;
  return 0;
}

Measured memory_bytes: 3776
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <map>
#define SIZE 1005
#define MX 130

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,D;
		scanf("%d %d",&n,&D);
		printf("%d\n",127*(n-1)+(n%2==1?D:127-D));
	}
	return 0;
}


Measured memory_bytes: 128
# https://atcoder.jp/contests/abc089/tasks/abc089_d

def calc(x):
    if x<D+1:
        mv[x]=0
        return 0
    else:
        p = d[x][0]
        q = d[x][1]
        r = d[x-D][0]
        s = d[x-D][1]
        tmp = abs(p-r)+abs(q-s)
        ret= tmp+calc(x-D)
        mv[x]=ret
        return ret
####################################################################
import sys 
sys.setrecursionlimit(10**5)
H,W,D= map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q=int(input())

d=dict()
z=0
for a in A:
    for b in a:
        p = z//W
        q = z%W
        d[b]=(p,q)
        z+=1
        
mv=[0]*(H*W+1)
for i in range(D):
    calc(H*W-i)
    #print(H*W-i,calc(H*W-i))    
#print(mv)

L=[0]*Q
R=[0]*Q
for _ in range(Q):
    L,R=map(int,input().split())
    print(mv[R]-mv[L])

Measured memory_bytes: 105880
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0, count1 = 0;
  vector<pair<string, pair<lli, lli>>> pr;
  vlli d;
  rep(i, 0, 9)
  {
    cin >> a;
    d.pb(a);
    ans += a;
  }

  if (ans == 3 * (d[0] + d[4] + d[8]))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    string s;
    cin>>s;

    for(int i = 0; i<s.size(); i+=2)
    cout<<s[i];
    cout<<endl;






    return 0;
}


Measured memory_bytes: 592
# find a cycle
def find_cycle(g):
    n = len(g)
    used = [0]*n #0:not yet 1: visiting 2: visited
    for v in range(n): #各点でDFS
        if used[v] == 2: continue
        #初期化
        stack = [v]
        hist =[] #履歴
        while stack:
            v = stack[-1]
            if used[v] == 1:
                used[v] = 2 #帰りがけの状態に
                stack.pop()
                hist.pop()
                continue
            hist.append(v)
            used[v] = 1 #行きがけの状態に
            for c in g[v]:
                if used[c] == 2: continue
                elif used[c] == 1: # cを始点とするサイクル発見！
                    return hist[hist.index(c):]
                else:
                    stack.append(c)
    return None

def find_minimal_cycle(g,cycle):
    n = len(g)
    is_in_cycle = [0]*n #サイクルに使われているか
    nxt = [-1]*n #次の頂点
    
    l = len(cycle)
    for i,c in enumerate(cycle):
        is_in_cycle[c] = 1
        nxt[c] = cycle[i+1-l]

    # 極小サイクルを求める
    for v in cycle:
        if is_in_cycle[v]:
            for c in g[v]:
                if is_in_cycle[c] == 1: #もしショートカット v -> c があれば
                    v0 = nxt[v] #以下サイクルのうち v から c までを削除
                    while v0 != c: 
                        is_in_cycle[v0] = 0 
                        v0 = nxt[v0] 
                    nxt[v] = c # nxt を繋ぎ直す
    
    #極小サイクルの出力
    i = is_in_cycle.index(1)
    v = nxt[i]
    hist = [i] #履歴
    while v != i:
        hist.append(v)
        v = nxt[v]
    return hist
    
    

#########################################################

##########################################################
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
 
for _ in range(m):
    a,b = [int(i)-1 for i in readline().split()]
    g[a].append(b)

cycle = find_cycle(g)

if cycle == None: print(-1)
else:
    res = find_minimal_cycle(g,cycle)
    print(len(res))
    for i in res:
        print(i+1)








Measured memory_bytes: 3316
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

INF = 10**5

DP = [INF] * ((10**5)+10)
# DP = [None] * ((10**5)+10)
# DP = [None] * (N+1)
DP[0] = 0

for i in range(1, N):
    a = []
    for j in range(1, K+1):
        if 0 <= i-j < N:
            v = DP[i-j] + abs(H[i-j] - H[i])
            a.append(v)
    DP[i] = min(a)


# print(DP)
print(DP[N-1])

Measured memory_bytes: 52448
#include <iostream>

#define MAX_N 100

int field[2][MAX_N];
int N;

void solve() {
    int row_0, row_1;
    int res = 0;

    row_0 = field[0][0];
    row_1 = 0;
    for (int i=0; i<N; i++) row_1 += field[1][i];
    
    res = row_0 + row_1;
    for (int j=1; j<N; j++) {
        row_0 = row_0 + field[0][j];
        row_1 = row_1 - field[1][j-1];
        res = std::max(res, row_0 + row_1);
    }
    std::cout << res << std::endl;
}

int main() {
    std::cin >> N;
    for (int i=0; i<2; i++) {
        for (int j=0; j<N; j++) std::cin >> field[i][j];
    }
    solve();
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define read(x) scanf("%lld",&x)
using namespace std;
const int maxn=1e5+5;
typedef long long LL;
LL n,m;
const LL mod=1e9+7;
LL inv[maxn];
LL a[maxn];
LL sum[maxn];
void INV() {
    inv[1]=1;
    for(int i=2;i<=n;i++) {
        inv[i]=1LL*(mod-mod/i)*(inv[mod%i])%mod;
    }
}
int main() {
    read(n);
    INV();
    for(int i=1;i<=n;i++) {
        read(a[i]);
    }
    for(int i=1;i<=n;i++) {
        sum[i]=sum[i-1]+inv[i];
        sum[i]%=mod;
    }
    LL ji=1;
    for(int i=1;i<=n;i++) {
        ji*=i;
        ji%=mod;
    }
    LL ans=0;
    for(int i=1;i<=n;i++) {
        ans+=((sum[i]-1)*a[i])%mod+(sum[n-i+1]*a[i])%mod;
        ans%=mod;
    }
    ans*=ji;
    ans%=mod;
    printf("%lld\n",ans);
}


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

int main(){
    string S;
    cin >> S;
    if(S[1] == 'S'){
        if(S[0] == 'R' || S[2] == 'R'){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else{
        if(S[0] == 'R' && S[2] == 'R'){
            cout << 3 << endl;
        }
        else if(S[0] == 'R' || S[2] == 'R'){
            cout << 2 << endl;
        }
        else{
            cout << 1 << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Globalization;

class Program
 {



    static void Main(string[] args)
    {
        string nyuryoku;
        string[] card = new string[2];
        int[] score = new int[2];
        nyuryoku = Console.ReadLine();
        int count = int.Parse(nyuryoku);

        for (int i = 0; i < count; i++)
        {
            nyuryoku = Console.ReadLine();
            card = nyuryoku.Split(' ');
            if (card[0].Length == card[1].Length)
            {
                for (int k = 0; k < card[0].Length; k++)
                {
                    if (card[0][k] > card[1][k])
                    {
                        score[0] = score[0] + 3;
                        break;
                    }
                    else if (card[0][k] < card[1][k])
                    {
                        score[1] = score[1] + 3;
                        break;
                    }
                    else if (k == (card[0].Length - 1))
                    {
                        score[0] = score[0] + 1;
                        score[1] = score[1] + 1;
                    }
                }
            }
            else
            {
                if (card[0].Length > card[1].Length)
                {
                    for (int j = 0; j < card[1].Length; j++)
                    {
                        if (card[0][j] == card[1][j])
                        {
                            if (j == (card[1].Length - 1))
                                score[0] = score[0] + 3;
                            continue;
                        }
                        else if (card[0][j] > card[1][j])
                        {
                            score[0] = score[0] + 3;
                            break;
                        }
                        else
                        {
                            score[1] = score[1] + 3;
                            break;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < card[0].Length; j++)
                    {
                        if (card[0][j] == card[1][j])
                        {
                            if (j == (card[0].Length - 1))
                                score[1] = score[1] + 3;
                            continue;
                        }
                        else if (card[0][j] > card[1][j])
                        {
                            score[0] = score[0] + 3;
                            break;
                        }
                        else
                        {
                            score[1] = score[1] + 3;
                            break;
                        }
                    }

                }
            
            
            }

        }
        Console.WriteLine("{0} {1}",score[0],score[1]);    
    
    }
 }



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

int n;
int x[10], y[10];

double dist(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j]; 
  return pow(dx * dx + dy * dy, 0.5);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  double sum = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) v[i] = i;
  do {
    for (int i = 0; i < n-1; i++) sum += dist(v[i], v[i+1]);
  } while(next_permutation(v.begin(), v.end()));
  int f = 1;
  for(int i = 2; i <=n; i++) f *= i;
  cout << fixed << setprecision(10) << sum / f << 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;

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
// constexpr ll mod = 1e9 + 7;

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

    if(S.size()==6 && S[2]==S[3] && S[4]==S[5]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
p = 998244353
N, M, K = map(int, input().split())

ans = 0
cmb = 1
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb
    ans %= p
    cmb *= (N - 1 - k) * pow(k + 1, p - 2, p)
    cmb %= p
print(ans)


Measured memory_bytes: 9180
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] lengths = new int[n];
		
		for (int i = 0; i < n; i++) {
			lengths[i] = sc.nextInt();
		}
		
		sc.close();
		
		// now we need a way of sorting through all of the sticks
		int ans = 0;
		
		for (int i = 0; i < k; i++) {
			int temp = 0;
			for (int j = 0; j < n; j++) {
				if (lengths[j] >= lengths[temp]) {
					temp = j;
					// we also need a way of removing the maximum here
				}
			}
			ans += lengths[temp];
			lengths[temp] = 0;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  ll N;
  cin >> N;
  map<string, ll> mp;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    mp[S]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

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

string s, r = "yuiophjklnm";

int main(){
	while (cin >> s && s != "#") {
		bool t, f = true;
		int c = 0;
		for (int i = 0; i < s.size(); i++) {
			t = false;
			for (int j = 0; j < r.size(); j++) {
				if (s[i] == r[j]) {
					t = true;
					break;
				}
			}
			if (i == 0) {
				f = t;
			}
			else {
				if ((t || f) && (!t || !f)) {
					c++;
					f = !f;
				}
			}
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
n = [int(e) for e in input().split(" ")]
d = [False] * n[0]
for i in range(n[1] * 2):
    raw = [int(e) for e in input().split(" ")]
    if((i+1) % 2 == 0):
        for e_r in raw:
            d[e_r - 1] = True
    else:
        pass
else:
    print(d.count(False))

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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n+1);
    for(int i=0; i<n+1; i++) cin >> v[i];
    long long ans = 0;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        int m = min(t, v[i] + v[i+1]);
        ans += m;
        v[i+1] = v[i+1] - max(0, m - v[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = (int)1e2 + 10;

int n;
int a[MAXN][MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int u,k; scanf("%d%d",&u,&k);
        for(int j=1;j<=k;j++){
            int v; scanf("%d",&v);
            a[u][v]=1;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d",a[i][1]);
        for(int j=2;j<=n;j++) printf(" %d",a[i][j]);
        printf("\n");
    }
}

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



Measured memory_bytes: 2780
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;

const int MAXN = (int)1e5 + 5;
vector<pair<int, int>> adjList[MAXN];
map<int, int> mp;

int getColor(int u) {
    return mp[u];
}

void setColor(int u, int color) {
    mp[u] = color;
}

void dfs(int u, int par, bool odd) {
    setColor(u, odd);
    for (auto p : adjList[u]) {
        int v = p.first;
        int w = p.second;
        if (v == par)
            continue;
        dfs(v, u, (odd + (w & 1)) % 2);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> edges;
    for (int i = 1; i < n; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        adjList[u].push_back({v, w});
        adjList[v].push_back({u, w});
        edges.push_back({u, v});
    }


    dfs(1, 0, 0);

    for (int i = 1; i <= n; ++i) {
        cout << getColor(i) << '\n';
    }




    return 0;
}

Measured memory_bytes: 17496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    ll a, b ,c;
    cin >> a >> b >> c;
    if (a == b && b == c && a % 2 == 0){
        cout << -1 << endl;
        return 0;
    }

    ll cnt = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        ll ha = a / 2;
        ll hb = b / 2;
        ll hc = c / 2;
        a = hb + hc;
        b = hc + ha;
        c = ha + hb;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include<functional>  
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n;
int ans;
int ii;
int a[100050];
int read()
{
	int s=0,t=1; char ch;
	while (ch<'0'||ch>'9') {if (ch=='-') t=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {s=s*10+ch-'0';ch=getchar();}
	return s*t;
}
int main()
{
	int p;
	n=read();
	for (int i=1;i<=n;i++) 
	  a[i]=read();
	  ii=1;
	while (ii<=n) {
		p=0;
	  if (a[ii]==ii&&a[ii+1]==ii+1) {
	  ans++;ii+=2;p=1;}
	  if (a[ii]==ii&&a[ii+1]!=ii+1&&p==0) ans++;
	  if (p==0)ii++;
	}
	out(ans);
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		char[] wk = next().toCharArray();
		for (int i = 1; i < wk.length; i++) {
			if (wk[i]==wk[i-1]) {
				out.println("Bad");
				return;
			}
		}
		out.println("Good");
	}

	private void solveB() {
		int n = nextInt();

		out.println("");
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21204
n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
a.sort!
bc=m.times.map{gets.split.map(&:to_i)}
bc.sort_by!{|b,c|c}
bc.reverse!

ans=0
itr=0
a.each do |ai|
  if itr<m && bc[itr][1]>ai
    ans+=bc[itr][1]
    bc[itr][0]-=1
  else
    ans+=ai
  end
  if itr<m && bc[itr][0]==0
    itr+=1
  end
end

puts ans
      

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

#define M 1046527
#define L 14

char H[M][L]; // ハッシュテーブル

int getChar(char ch){
  if( ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
}

// 文字列から数値へ変換
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  i = 0;
  while(1){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
    i++;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  i = 0;
  while(1){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
    i++;
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i=0; i < M; i++) H[i][0] = '\0';
  
  scanf("%d", &n);
  
  for(i=0; i < n; i++){
    scanf("%s %s", com, str);
    if(com[0] == 'i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16068
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[3];
    scanf("%d %d %d",a,a+1,a+2);
    sort(a,a+3);
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
    
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);
	
	int a,b,c,d, n, hitung = 0;
	while(scanf("%d", &n) != EOF){
		hitung = 0;
		for (a=0; a<=9; a++)
			for (b=0; b<=9; b++)
				for (c=0; c<=9; c++)
					for (d=0; d<=9; d++)
						if (a+b+c+d == n)hitung++;
		printf("%d\n", hitung);
	}
	

	return 0;
}

Measured memory_bytes: 3232
using System;

namespace AGC029A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "";
            int whiteCount = 0;
            long swapCount = 0;

            s = Console.ReadLine();

            for(int i = 0; i < s.Length; ++i)
            {
                if(s[i] == 'W')
                {
                    swapCount += i - whiteCount;
                    ++whiteCount;
                }
            }

            Console.WriteLine(swapCount);
        }
    }
}

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

def main():

	while True:
		H,W = map(int,raw_input().split())
		if H == W == 0:
			break
		a = ''
		b = '#'
		for i in xrange(W):
			a += '#'
		for i in xrange(W-2):
			b += '.'
		b += '#'
		print(a)
		for i in xrange(H-2):
			print(b)
		print(a)
		print('')

if __name__ == "__main__":

	main()


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

int main(){
    bool cards[4][14];
    int n,rank;
    char suit;

    for(int s=0;s<4;s++)
        for(int r=1;r<=13;r++)
            cards[s][r]=0;
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>suit>>rank;
        if(suit=='S')cards[0][rank]=1;
        if(suit=='H')cards[1][rank]=1;
        if(suit=='C')cards[2][rank]=1;
        if(suit=='D')cards[3][rank]=1;
    }

    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            if(cards[s][r])continue;
            if(s==0)suit='S';
            if(s==1)suit='H';
            if(s==2)suit='C';
            if(s==3)suit='D';
            cout<<suit<<" "<<r<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3080
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    S = in_s() + "T"
    N = len(S)

    X, Y = in_nn()

    x_num = []
    y_num = []

    f = False
    first = True

    cnt = 0
    for i in range(N):
        if S[i] == "T":

            if cnt > 0:
                if f:
                    if first:
                        Y -= cnt
                    else:
                        y_num.append(cnt)
                else:
                    if first:
                        X -= cnt
                    else:
                        x_num.append(cnt)
            cnt = 0
            f = not f
            first = False
        else:
            cnt += 1

    x_ok = False
    y_ok = False

    if len(x_num) == 0:
        if X == 0:
            x_ok = True
    else:
        dp_x = [False] * N
        dp_x[0] = True
        for tx in x_num:
            for i in range(N - 1, -1, -1):
                if i + tx < N and dp_x[i]:
                    dp_x[i + tx] = True

        xsum = sum(x_num)
        for i in range(N):
            if dp_x[i]:
                if abs(i - abs(xsum - i)) == abs(X):
                    x_ok = True

    if len(y_num) == 0:
        if Y == 0:
            y_ok = True
    else:
        dp_y = [False] * N
        dp_y[0] = True
        for ty in y_num:
            for i in range(N - 1, -1, -1):
                if i + ty < N and dp_y[i]:
                    dp_y[i + ty] = True

        ysum = sum(y_num)
        for i in range(N):
            if dp_y[i]:
                if abs(i - abs(ysum - i)) == abs(Y):
                    y_ok = True

    # print(X, Y)
    # print(x_num)
    # print(y_num)

    if x_ok and y_ok:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 74236
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m; cin >> n >> m;
    vec<vec<ll>> g(n);
    rep(i,m){
        ll a,b; cin >> a >> b; --a; --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    vec<ll>dist(n,-1);
    queue<ll> que; que.push(0);
    while(!que.empty()){
        ll i = que.front();
        que.pop();
        for(auto x : g[i]){
            if(dist[x] != -1)continue;
            dist[x] = i;
            que.push(x);
        }
    }
    cout << "Yes" << endl;
    for(ll i = 1;i<n;i++)cout << dist[i]+1 << endl;
}

Measured memory_bytes: 12796
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    string s;   cin >> s;
    if (s == "RRR")
        cout << 3 << endl;
    else if (s == "RRS" || s == "SRR")
        cout << 2 << endl;
    else if (s == "SSS")
        cout << 0 << endl;
    else 
        cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <map>

using namespace std;


int *ms;
int n, m;

bool *dp;
bool *data;

bool search(int m){
	if(m == 0) return true;
	else if(m < 0) return false;
	else if(dp[m]) return data[m];

	for(int i=0;i<n;i++){
		if(m%ms[i] == 0){
			return dp[m] = data[m] = true;
		}else if(search(m-ms[i])){
			return dp[m] = data[m] = true;
		}
	}
	
	dp[m] = true;
	return data[m]=false;
}

int isprime(int p){
	if(p%2==0) return 0;
	for(int i=3;i*i<p;i++){
		if(p%i==0) return 0;
	}
	return 1;
}

int main(){
	while(1){
		scanf("%d%d", &n,&m);
		
		if(n==0) break;
		
		int i;
		dp = new bool[m+1];
		data = new bool[m+1];
		for(i=0;i<=m;i++) dp[i] = false;
		
		ms = new int[n];
		for(i=0;i<n;i++) scanf("%d", ms+i);
		
		int flag = 1;
		for(i=m;i>=0;i--){
			if(search(i) && isprime(i)){
				printf("%d\n", i);
				flag = 0;
				break;
			}
		}
		if(flag) puts("NA");
		
		delete dp;
		delete data;
		delete ms;
	}
}

Measured memory_bytes: 4480
import sys
from heapq import heappush, heappop, heapreplace

def solve():
    file_input = sys.stdin
    N, R, L = map(int, file_input.readline().split())
    
    pq = [[0, i, 0] for i in range(1, N + 1)]
    m = dict(zip(range(1, N + 1), pq))
    
    pre_t = 0
    for line in file_input:
        d, t, x = map(int, line.split())
        team = pq[0]
        team[2] += t - pre_t
        pre_t = t
        
        if team[1] == d:
            team[0] -= x
            if x < 0:
                heapreplace(pq, team)
        else:
            scored_team = m[d][:]
            scored_team[0] -= x
            heappush(pq, scored_team)
            m[d][2] = -1
            m[d] = scored_team
        
        while pq[0][2] == -1:
            heappop(pq)
    pq[0][2] += L - pre_t
    ans_team = max(pq, key = lambda x: (x[2], -x[1]))
    print(ans_team[1])

solve()


Measured memory_bytes: 89508
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read () =
  match List.map int_of_string (split_on_char ' ' (read_line ())) with
  | [x; y] -> (x, y)
  | _ -> exit 1

let () =
  let (n, w) = read () in
  let z = (100*n + 1) in
  let t = Array.make z (w + 1) in
  t.(0) <- 0;
  for i = 0 to n - 1 do
    let (vi, wi) = read () in
    for j = z - 1 downto vi do
      if t.(j) > t.(j-vi) + wi then t.(j) <- t.(j-vi) + wi
    done
  done;
  let rec print i =
    if i < 0 then exit 1
    else if t.(i) <= w then Printf.printf "%d\n" i
    else print (i - 1) in
  print (z - 1)

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

int main() {
    int N; cin >> N;
    long long sum = 0;
    vector<int> a(3*N);
    for (int i = 0; i < 3*N; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    for (int i = N; i < 3*N-1; i+=2) {
        sum += a.at(i);
    }
    cout << sum << endl;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

int a[5][5];

void solve() {
  for (int i = 1; i <= 3; i++)
  for (int j = 1; j <= 3; j++) {
    cin >> a[i][j];
  }
  for (int i = 2; i <= 3; i++)
  for (int j = 2; j <= 3; j++) {
    if (a[i][j] != a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}


signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3640