akhauriyash/Code-Regression huggingface dataset:
package main

import (
  "fmt"
  "math"
)

func main() {
  var N, W int
  fmt.Scanf("%d %d\n", &N, &W)
  w, v := make([]int, N), make([]int, N)
  for i:=0;i<N;i++ {
    fmt.Scanf("%d %d\n", &w[i], &v[i])
  }
  fmt.Println(solve(N, W, w, v))
}

// dp[i][v] = max(dp[i-1][v], dp[i-1][v-v[i]]+w[i])
func solve(n, W int, w, vv []int) int {
  dp := make([][]int, n+1)
  // 注意初始化条件
  V := n*1000
  for i := range dp {
    dp[i] = make([]int, V+1)
  }
  for v:=1;v<=V;v++ {
    dp[0][v] = math.MaxInt32
  }
  // 特别注意不足的情况的处理
  for i:=1;i<=n;i++ {
    for v:=0;v<=V;v++ {
      if v < vv[i-1] {
        dp[i][v] = dp[i-1][v]
      } else {
        dp[i][v] = min(dp[i-1][v], dp[i-1][v-vv[i-1]]+w[i-1])
      }
    }
  }
  // 注意返回结果的条件
  res := 0
  for v:=0;v<=V;v++ {
    if dp[n][v]<=W {
      res = v
    }
  }
  return res
}

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

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

int main() {
  int n, m;
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; i++) {
    s += "*";
  }
  for (int i = 0; i < m; i++) {
    int p;
    char c;
    cin >> p >> c;
    if (s.at(p-1) == '*') {
      s.at(p-1) = c;
      continue;
    } else if (s.at(p-1) == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0 ; i < n; i++) {
    if (i == 0 && s.at(i) == '*' && s.size() > 1) {
      s.at(i) = '1';
    } else if (s.at(i) == '*') {
      s.at(i) = '0';
    }
  }
  if (s.at(0) == '0' && s.size() != 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll a, b, k;
   cin >> a >> b >> k;
   ll taka = max(a - k, 0LL);
   ll aoki = max(b + min(a - k, 0LL), 0LL);
   cout << taka << " " << aoki << endl;
   return 0;
}


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

int main(){
    string o,e;
    cin >> o >> e;
    int a = o.size();
    int b = e.size();
    rep(i,b){
        cout << o[i] << e[i];
    }
    if(a>b)cout << o[a-1];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let a: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let b: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let c: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let d: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let e: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let k: usize = buf.trim().parse().unwrap();

    if e - a > k {
        println!(":(");
    } else {
        println!("Yay!");
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807
#define array(N, t) (t*)calloc(N, sizeof(t))

/**
 * suppose 1 is R, 0 is W
 *
 * A: 1 -> 0
 * B: 0 -> 1
 *
 * [1]
 * |10101010
 * |00000000
 * A: 4
 * B: 0
 *
 * ↓
 * A: -1
 * B: +-0
 * ↓
 *
 * [2]
 * 1|0101010
 * 1|0000000
 * A: 3
 * B: 0
 *
 * ↓
 * A: +-0
 * B: +1
 * ↓
 *
 * [3]
 * 10|101010
 * 11|000000
 * A: 3
 * B: 1
 *
 * ↓
 * A: -1
 * B: +-0
 * ↓
 *
 * [4]
 * 101|01010
 * 111|00000
 * A: 2
 * B: 1
 *
 * ↓
 * A: +-0
 * B: +1
 * ↓
 *
 * [5]
 * 1010|1010
 * 1111|0000
 * A: 2
 * B: 2
 *
 * ...
 *
 * There are N + 1 places where you can put divider
 */
int main() {
  int N;
  scanf("%d", &N);

  char * C = array(N + 1, char);
  scanf("%s", C);

  int A = 0, B = 0;

  // Initialize
  // put the divider on the leftmost
  // increment A
  rep(i, N) {
    if (C[i] == 'R') {
      A += 1;
    }
  }

  int ans = A;

  // move the divider to the right in increments of one tick
  // but the condition (2 <= N, 200000 >= N) does not allow O(N^2)
  // Notice that moving the divider only increases or decreases operation-A or operation-B by plus or minus one
  // if C[i] is "R" then --A and if C[i] is "W" then ++B
  rep(i, N) {
    if (C[i] == 'R') {
      A -= 1;
    } else {
      B += 1;
    }
    // MAX
    int max = 0;
    if (A > B) {
      max = A;
    } else {
      max = B;
    }

    // MIN
    int min = 0;
    if (ans > max) {
      min = max;
    } else {
      min = ans;
    }
    ans = min;
  }

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

  free(C);
  return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int nxt[100010][26];

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

    string s, t;
    cin >> s >> t;
    int als[26] = {}, alt[26] = {};
    rep(i, s.size()) als[s[i] - 'a']++;
    rep(i, t.size()) alt[t[i] - 'a']++;
    rep(i, 26) if (als[i] == 0 && alt[i] != 0)
    {
        cout << -1 << endl;
        return 0;
    }
    int fir[26];
    rep(i, 26) fir[i] = -1;
    rep(i, s.size()) rep(j, 26) nxt[i][j] = -1;
    rep(i, s.size())
    {
        int now = s[i] - 'a';
        if (fir[now] == -1)
            fir[now] = i;
    }
    for (int i = s.size() - 2; i >= 0; i--)
    {
        rep(j, 26) nxt[i][j] = nxt[i + 1][j];
        nxt[i][s[i + 1] - 'a'] = i + 1;
    }
    int now = fir[t[0] - 'a'], ans = now + 1;
    Rep(i, 1, t.size())
    {
        int p = t[i] - 'a';
        if (nxt[now][p] == -1)
        {
            ans += s.size() - now;
            now = fir[p];
            ans += now;
        }
        else
        {
            ans += nxt[now][p] - now;
            now = nxt[now][p];
        }
    }
    cout << ans << endl;
}

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

int     main() {
        long N;
        cin >>N;
        long S=0;
        vector<vector<long>> P(N, vector<long>(3, 0));
        for (long i=0; i<N; i++) {
                for (long j=0; j<3; j++) {
                        cin >>P.at(i).at(j);
                        S=max(S, P.at(i).at(2));
                }
        }
        long h=S;
        long x, y;
        while(true) {
                for (long x=0; x<=100; x++) {
                        for (long y=0; y<=100; y++) {
                                long j;
                                bool Pass=true;
                                for (j=0; j<P.size(); j++) {
                                        long HH=max(h-abs(P.at(j).at(0)-x)-abs(P.at(j).at(1)-y), (long)0);
                                        if (HH != P.at(j).at(2)) {
                                                Pass=false;
                                        }
                                }
                                if (Pass) {
                                        cout <<x <<" " <<y <<" " <<h <<endl;
                                        return 0;
                                }
                        }
                }
                h++;
        }
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<ll,ll>;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

void solve(){
	int n;
	cin>>n;
	vector<int>a(1e5);
	rep(i,n){
		int x;
		cin>>x;
		x--;
		a[x]++;
	}
	int v=0;
	int sum=0;
	rep(i,1e5){
		if(a[i]){
			++v;
			a[i]%=2;
			if(a[i]==0)a[i]=2;
		}
		sum+=a[i];
	}
	int ans=0;
	if((sum-v)%2==0)ans=v;
	else ans=v-1;
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
int maxdepth;
map<VI,int> mp;

void Rev(int l,int r,vector<int> &v){
  for(int i=0;i<=10;i++){
    if(l+i>=r-i)break;
    swap(v[l+i],v[r-i]);
  }
  return;
}

void bfs(vector<int> v,int depth){
  if(depth>maxdepth)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        if(mp[v1]>depth){
          mp[v1] = depth;
          bfs(v1,depth+1);
        }
      }else if(mp[v1]==0){
        mp[v1] = depth;
        bfs(v1,depth+1);
      }
    }
  }
  return;
}

void bfs2(vector<int> v,int depth,int &ans){
  if(depth>maxdepth)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        ans = min(ans,mp[v1]+depth);
        bfs2(v1,depth+1,ans);
      }else if(mp[v1]==0){
        bfs2(v1,depth+1,ans);
      }
    }
  }
  return;
}



int main(){
  int n;
  cin >>n;
  maxdepth = 4;
  VI a(n);
  rep(i,n)cin>>a[i];
  mp[a]=0;
  bfs(a,1);
  VI b(n);
  rep(i,n)b[i]=i+1;
  if(a==b){
    cout << 0 << endl;
    return 0;
  }
  int ans = 10000;
  if(mp[b]!=0){
    cout << mp[b] << endl;
    return 0;
  }
  bfs2(b,1,ans);
  if(ans==10000){
    cout << n-1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

map<int, int> mp;

int findPower(int i, int k)
{
    int t = i, cnt = 0;

    while (t < k)
    {
	if (mp.find(t) != mp.end())
	{
	    cnt += mp[t];
	    break;
	}
	t *= 2;
	++cnt;
    }

    mp[i] = cnt;
    return cnt;
}

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

    // power of 2
    vector<int> p2(31);

    p2[0] = 1;
    for (int i=1; i<p2.size(); ++i)	p2[i] = p2[i-1] * 2;

    long double b = 0.0;
    for (int i=n; i>=1; --i)
    {
	int p = findPower(i, k);
	p = p2[p];
	b += (long double)1/p;
    }
	cout << fixed ; cout << setprecision(15);
    cout << ((long double)1/n) * b << '\n';
    return 0;
}


Measured memory_bytes: 4992
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		//long H[] = new long[N];
		ArrayList<Long> list = new ArrayList<Long>();
		for(int i=0;i<N;i++) {
			list.add(sc.nextLong());
		}
		if(K>=N) {
			System.out.println(0);
			System.exit(0);
		}
		
		list.sort(Comparator.reverseOrder());
		
		
		
		for(int j=0;j<K;j++) {
		    list.set(j,(long)0);
		}
		long souwa2 = 0;
		for(int k=0;k<N;k++) {
			long a = list.get(k);
			souwa2 += a;
		}
		System.out.println(souwa2);
					
		}
}

Measured memory_bytes: 93976
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// name.order_of_key (val): returns the no. of values strictly less than val
// *name.find_by_order (k): returns the kth largest element iterator.(0-based)

#define INF32 INT_MAX
#define INF64 LLONG_MAX
#define fir first
#define sec second
#define pr_nl cout<<'\n' 
#define nl '\n' 
#define pb push_back
#define MP make_pair
#define lcm(a,b) ((a*b)/gcd(a,b))
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define fast_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

clock_t strt, ed;
double cpu_time_used;
const ld pi=acos(-1);
long long int MOD = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */


long long int fact(int n);
ll power(ll a,ll b);
const int N=(int)2e5+5;
long long dp[N][3],a[N],b[N],c[N],n;
int main()
{
	fast_IO;strt = clock();	
    cin>>n;
    fr(i,1,n) cin>>a[i]>>b[i]>>c[i];
    fr(i,1,n){
     //       trace(dp[i-1][0],dp[i-1][1],dp[i-1][2]);
            dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
            dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
            dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
   //         trace(dp[i][0],dp[i][1],dp[i][2]);
    };
    long long ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<nl;
	

	

	



	ed = clock();cpu_time_used = ((double) (ed - strt)) / CLOCKS_PER_SEC;trace(cpu_time_used);
	return 0;
}
long long int fact(int n)
{
	return((n==0||n==1)?1:(n*fact(n-1)));
}
ll power(ll a,ll b)
{
	ll r=1;
	while(b){
		if(b & 01) r=(r*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return r;
}


Measured memory_bytes: 7680
def min(a,b); a < b ? a : b; end
N = gets.to_i
R = Array.new(10, 0)
A = gets.split.map(&:to_i)
A.each do |a|
  R[min(a / 400, 8)] += 1
end
m = 8.times.count{|r| R[r] > 0 }
puts "#{m > 0 ? m : 1} #{m+R[8]}"

Measured memory_bytes: 1788
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
    [a, b, c] <- map (toUpper . head) <$> readString
    putStrLn $ [a, b, c]



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

int main()
{
  int n;

  cin >> n;

  // vector<int> a(n);

  // rep(i, n)
  // {
  //   cin >> a.at(i);
  // }

  int sum = 0;

  while(n>=1000){
    n -= 1000;
  }

  if(n == 0){
    cout << 0;
    return 0;
  }

  cout << 1000 - n;
}


Measured memory_bytes: 3620
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int h,w,n;
char m[1001][1001];
int dx[4]={0,0,-1,1};//四个方向;
int dy[4]={-1,1,0,0};
bool bj[1001][1001];
int start_x;
int start_y;
int total;
int cnt;
struct Node{
    int x,y;
    int time;
};
bool pd(int a,int b)  //判断是否在矩?范?内;
{
    if(a>=0&&a<h&&b>=0&&b<w)
        return true;
    return false;
}
void BFS(int a)
{
    memset(bj,false,sizeof(bj));
    int i;
    Node start;
   // char nl='0'+a;//?个?酪厂;
    start.x=start_x;
    start.y=start_y;
    start.time=0;
    cnt=0;
    bj[start.x][start.y]=true;
    queue<Node> Q;
    Q.push(start);//起点入?

    while(!Q.empty())
    {
       Node q1;
       q1=Q.front();
       Q.pop();
       if((int)(m[q1.x][q1.y]-'0')==a)
        {
            total+=q1.time;
            start_x=q1.x;
            start_y=q1.y;
            //cout<<q1.time<<endl;
           return ;
        }
       for(i=0;i<4;i++)
       {
           Node q2;
           q2.x=q1.x+dx[i];
           q2.y=q1.y+dy[i];
           if(pd(q2.x,q2.y))
           {
               if(m[q2.x][q2.y]!='X'&&!bj[q2.x][q2.y])
               {
                      //q2.time++;
                       //total++;
                       q2.time=q1.time+1;
                      // cout<<q2.time<<endl;
                    if(!bj[q2.x][q2.y]){

                       bj[q2.x][q2.y]=true;
                        Q.push(q2);
                    }
                }
           }
       }
    }

}
int main()
{

       cin>>h>>w>>n;

        int i,j;
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                cin>>m[i][j];
                if(m[i][j]=='S')
                {
                    start_x=i;
                    start_y=j;
                   // start.time=0;
                }
            }
        }
        total=0;
        for(i=1;i<=n;i++)
            BFS(i);
        cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 4996
#include <stdio.h>

int main(void){
	int a, b, c, temp;
	int n = 0;
	int i;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}
	
	for(i = a; i <= b; i++){
		if(c%i == 0){
			n++;
		}
		
	}
	
	printf("%d\n", n);
	
	return(0);
	
}

Measured memory_bytes: 596
s=input()
S=len(s)
ans=[]

for i in range(S):
    if s[i]=="0":
        ans+="0"
    elif s[i]=="1":
        ans+="1"
    elif s[i]=="B":
        if len(ans)>=1:
            ans.pop()


print("".join(ans))

Measured memory_bytes: 9116
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>


int main() {
	int n; std::cin >> n;
	std::vector<int> terms(1, 0); std::cin >> terms[0];
	std::vector<std::string> ops;
	long long int result{ terms[0] };
	for (auto i = 1; i < n; i++) {
		std::string op; int value; std::cin >> op >> value;
		ops.push_back(op);
		terms.push_back(value);
		if (op == "+") {
			result += value;
		}
		else {
			result -= value;
		}
	}
	std::vector<long long int> sum_back(n + 1, 0);
	for (int i = 1; i <= n; ++i) {
		sum_back[n - i] = terms[n - i] + sum_back[n - i + 1];
	}
	int prev_minus = std::distance(ops.begin(), std::find(ops.begin(), ops.end(), "-"));
	if (prev_minus == ops.size()) {
		std::cout << sum_back.front() << '\n';
		return 0;
	}
	long long int prev_sum = std::accumulate(terms.begin(), std::next(terms.begin(), prev_minus + 1), 0LL, [](const long long int acc, const int t) {return acc + t; });
	while (prev_minus < ops.size()) {
		const int next_minus = std::distance(ops.begin(), std::find(std::next(ops.begin(), prev_minus + 1), ops.end(), "-"));
		if (next_minus < ops.size()) {
			const auto sum = std::accumulate(std::next(terms.begin(), prev_minus + 1), std::next(terms.begin(), next_minus + 1), 0LL, [](const long long int acc, const int t) {return acc + t; });
			const auto all_sum = prev_sum - sum + sum_back[next_minus + 1];
			result = std::max(result, all_sum);
			prev_sum += sum - (terms[prev_minus + 1] << 1);
		}
		prev_minus = next_minus;
	}
	std::cout << result << std::endl;
}


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

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

    int counter = 0;
    int now_light = 1;
    while(counter <= N){
        now_light = a[now_light];
        counter++;
        if(now_light == 2){
            cout << counter << endl;
            return 0;
        }
    }

    cout << "-1" << endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int a, b;
    char op;
    
    while(true){
        cin >> a >> op >> b;
     
        if(op=='?'){
            break;
        }
        switch(op){
            case '+':
            cout << a + b << endl;
            break;
            
            case '-':
            cout << a - b << endl;
            break;
            
            case '*':
            cout << a * b << endl;
            break;
            
            case '/':
            cout << a / b << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	int n, q, cnt = 0;
	cin >> n;
	vector<int> s(n);
	REP(i, n) {
		cin >> s[i];
	}
	cin >> q;
	vector<int> t(q);
	REP(i, q) {
		cin >> t[i];
	}
	sort(ALL(s));
	sort(ALL(t));
	REP(i, q) {
		if (binary_search(s.begin(), s.end(), t[i]))cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3364
class Point
  attr_accessor :x, :y
  def initialize(x, y) @x = x; @y = y; end 
end

def c(p1, p2, p) (p2.y - p1.y) * (p.x - p1.x) - (p2.x - p1.x)* (p.y - p1.y)  end 

while s = gets
  p = s.split(',').map(&:to_f)
  a, b, c, d = 4.times.map { Point.new(p.shift, p.shift) }
  puts c(a, c, b) * c(a, c, d) < 0 && c(b, d, a) * c(b, d, c) < 0 ? 'YES' : 'NO'
end

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

struct Edge {
	int from, to;
	Edge(int f, int t) : from(f), to(t) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;
vector<int> tarjan(const Graph& g) {
	int n = g.size(), idx = 0, k = 0, s = 0;
	vector<int>ord(n, -1), low(n), onS(n), cmp(n), stk(n);
	function<void(int)>dfs;
	dfs = [&](int v) {
		ord[v] = low[v] = idx++;
		stk[s++] = v;
		onS[v] = true;
		for (auto &e : g[v]) {
			int w = e.to;
			if (ord[w] == -1) {
				dfs(w);
				low[v] = min(low[v], low[w]);
			}
			else if (onS[w]) {
				low[v] = min(low[v], ord[w]);
			}
		}
		if (low[v] == ord[v]) {
			while (1) {
				int w = stk[--s];
				onS[w] = false;
				cmp[w] = k;
				if (w == v)break;
			}
			++k;
		}
	};
	for (int v = 0; v<n; ++v)
		if (ord[v] == -1)dfs(v);
	return cmp;
}

int main()
{
	cin.sync_with_stdio(false);
	int V, E, Q;
	cin >> V >> E;
	Graph G(V);
	for (int i = 0, s, t; i < E; i++) {
		cin >> s >> t;
		G[s].emplace_back(s, t);
	}
	auto ta = tarjan(G);
	cin >> Q;
	for (int i = 0, u, v; i < Q; i++) {
		cin >> u >> v;
		printf("%d\n", (ta[u] == ta[v]));
	}
	return 0;
}

Measured memory_bytes: 4576
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)>(q)?(q):(p))
int i,j,k,l,m;
int xa,xb,ya,yb;
int maxx,minx,maxy,miny;
int x,y;
int cnt;
int N,K;
int point[51][2];
long long int menseki;
long long int answer=5000000000000000000;


int main(){
    scanf("%d%d",&N,&K);
    //printf("%lld\n",answer);
    for (i=0;i<N;i++){
        scanf("%d%d",&x,&y);
        point[i][0]=x;
        point[i][1]=y;
    }
    /*
    for (i=0;i<N;i++){
        //printf("%d %d\n",point[i][0],point[i][1]);
    }
     */
    for (i=0;i<N;i++){
        for (j=i;j<N;j++){
            xa=point[i][0];
            xb=point[j][0];
            minx=min(xa,xb);
            maxx=max(xa,xb);
            for (k=0;k<N;k++){
                for (l=k;l<N;l++){
                    ya=point[k][1];
                    yb=point[l][1];
                    miny=min(ya,yb);
                    maxy=max(ya,yb);
                    cnt=0;
                    menseki=(long long int)(maxx-minx)*(maxy-miny);
                    //printf("%d %d %d %d %lld\n",maxx,minx,maxy,miny,menseki);
                    for (m=0;m<N;m++){
                        x=point[m][0];
                        y=point[m][1];
                        if ((minx<=x)&&(x<=maxx)&&(miny<=y)&&(y<=maxy)) cnt++;
                        
                    }
                    //printf("%d %d\n",cnt,K);
                    if (cnt>=K) answer=min(answer,menseki);
                    //printf("%lld\n",answer);
                }
            }
        }
    }
    printf("%lld",answer);
    return 0;
}


Measured memory_bytes: 1688
#include<iostream>

using namespace std;

long long int pri[100000];

int main()
{
  fill(pri,pri+100000,1);
  for(int i=2;i<100000;i++)
    {
      if(pri[i]==0)
	continue;
      for(int j=i+i;j<100000;j+=i)
	{
	  pri[j]=0;
	}
    }
  int n;
  for(;cin>>n;)
    {
      int a,b,c;
      for(int i=1;;i++)
	{
	  if(pri[i]==0)
	    continue;
	  else
	    {
	      c=a;
	      a=b;
	      b=i;
	      if(i>n)
		break;
	    }	  
	}
      if(a!=n)
	cout<<a<<" "<<b<<endl;
      else
	cout<<c<<" "<<b<<endl;
    }

}

Measured memory_bytes: 1940
mod = 10 ** 9 + 7
N, M = map(int, input().split())
F = [0, 1]
fib_minus1 = 1
fib_minus2 = 0
for i in range(N):
	fib = (fib_minus1 + fib_minus2) % mod
	F.append(fib)
	fib_minus2 = fib_minus1
	fib_minus1 = fib
x = 1
a = -1
for i in range(M):
	b = int(input())
	x = (x * F[b - a - 1]) % mod
	a = b
x = (x * F[N - a]) % mod
print(x)

Measured memory_bytes: 7212
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<string, int> M;
    for(int i=0; i<n; i++){
        string s;
        cin >>  s;
        M[s]++;
    }
    int maxv = 0;
    for(auto& it : M){
        if((it.second)>maxv){
            maxv = it.second;
        }
    }
    for(auto it = M.begin(); it!=M.end(); it++){
        if(it->second == maxv){
            cout << it->first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19156
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int ans = 700;
  rep(i,3) {
    char c;
    cin >> c;
    if(c=='o') ans+=100;
  }
  cout << ans << endl;

  return 0;
}


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


int main() {

  string S;
  cin >> S;

  string ans = "Good";
  for(int i=0; i<3; i++){
    if(S.at(i) == S.at(i+1)) ans = "Bad";
  }

  cout << ans << endl;

  


}


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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int dp[100001];

int solve(){
  int n,m;cin>>n>>m;
  vector<int> a(m);
  vector<int> b(n+1, 0);
  rep(i, m) {
    cin>>a[i];
    b[a[i]] = 1;
  }
  dump(a);
  dump(b);

  dp[0] = 1;
  rep(i, 1, n+1){
    if (b[i]==0){
      if (i>=2)dp[i] += dp[i-2];
      dp[i] += dp[i-1];
      dp[i] %= MOD;
    }
  }
  dump_1d(dp, n+1);
  cout << dp[n] << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

/*
    NTL_1_C Least Common Multiple
*/
ll lcm[MAX_N];

// long version
long long int GCD(long long int x, long long int y){
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

long long int LCM(int n){
    ll res = lcm[0];
    for (int i = 1; i < n; i++){
        ll g = GCD(res, lcm[i]);
        res = res * lcm[i] / g;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    rep(i,n)cin >> lcm[i];
    sort(lcm, lcm+n);

    int ans = LCM(n);

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



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll gcd(ll x,ll y){
  if(x%y==0)return y;
  else return gcd(y,x%y);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(0,c-(a-b)) << endl;
}


Measured memory_bytes: 256
/*
*   Copyright (C) 2015 All rights reserved.
*   
*   filename: 9019.cpp
*   author: doublehh
*   e-mail: sserdoublehh@foxmail.com
*   create time: 2015-06-08
*   last modified: 2015-06-08 16:08:16
*/
#include<bits/stdc++.h>
using namespace std;

const int maxn = 40, maxm = 400;
int n, m, s, t;
int u[maxm], v[maxm];
string w[maxm];
string d[maxn];

void init()
{
	for (int i = 0; i < n; i++)
		d[i] = "-";
	for (int i = 0; i < m; i++)
		cin >> u[i] >> v[i] >> w[i];
}

string solve()
{
	d[t] = "";
	for (int clk = 0; ; )
	{
		bool flag = false;
		for (int i = 0; i < m; i++) if (d[v[i]] != "-")
		{
			if (d[u[i]] == "-" || d[u[i]] > w[i] + d[v[i]])
			{
				flag = true;
				d[u[i]] = w[i] + d[v[i]];
				if (clk >= n - 1 && u[i] == s) return "NO";
			}
		}
		if (!flag || ++clk > 6 * n) break;
	}
	return d[s] == "-"? "NO": d[s];
}

int main()
{
	while (cin >> n >> m >> s >> t)
	{
		if (!n && !m && !s && !t) break;
		init();
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1704
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC085D()
{
	int N;
	ll H;
	cin >> N >> H;
	vector<ll> a(N), b(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	auto nB = distance(b.begin(), lower_bound(b.begin(), b.end(), a.front(), greater<ll>()));

	for (int i = 0; i < nB; ++i)
	{
		H -= b[i];
		if (H <= 0)
		{
			cout << i + 1 << endl;
			return;
		}
	}
	ll ct = H / a.front();
	if (ct * a.front() < H)
		++ct;
	cout << ct + nB << endl;
}
int main()
{
	ABC085D();
	return 0;
}

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

const int MAX_N = 100010;

int a[MAX_N];
int imos[3*MAX_N];

signed main(void){ 
  
  int n,m; cin >> n >> m;
  for(int i = 0; i < n; i++){ cin >> a[i];}
  
  int origin = 0; //お気に入りボタンがない時の、かかる操作回数を記録
  
  for(int i = 0; i < n-1; i++){ 
    int s = a[i]; int t = a[i+1];
    if( s > t ){ t += m;}
    origin += (t-s);
    imos[s+2]++; imos[t+1] -= (t-s); imos[t+2] += (t-s-1);
  }
  
  for(int k = 0; k < 2; k++){ 
    for(int i = 1; i < 3*MAX_N; i++){ 
      imos[i] += imos[i-1];
    }
  }
  
  int save = 0;
  
  for(int x = 0; x <= 2*MAX_N; x++){ 
    save = max( save, imos[x]+imos[x+m] );
  }
  
  cout << origin-save << endl;
  
  return 0;
} 
  

Measured memory_bytes: 3328
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    n,m = map(int,input().split())
    ans = n*(n-1)//2
    ans+=m*(m-1)//2
    print(ans)





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef vector<int> vi;

bool tarjan(vi e[], int x, int p[], bool st[], int disc[], int &dn, vi &t) {
    int dmax = -1, dmaxp = -1;
    for (int y : e[x]) {
        if (st[y] && disc[y] > dmax) {
            dmax = disc[y];
            dmaxp = y;
        }
    }

    disc[x] = dn++;
    st[x] = true;

    if (dmaxp != -1) {
        int y = dmaxp;
        while (y != x) {
            t.push_back(y);

            int dmax = -1, dmaxz = -1;
            for (int z : e[y]) {
                if (st[z] && disc[z] > dmax) {
                    dmax = disc[z];
                    dmaxz = z;
                }
            }
            y = dmaxz;
        }
        t.push_back(x);
        return true;
    }

    for (int y : e[x]) {
        if (p[y] != -2) {
            continue;
        }
        p[y] = x;
        bool f = tarjan(e, y, p, st, disc, dn, t);
        if (f) {
            return true;
        }
    }

    st[x] = false;
    return false;
}

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }

    int p[n];
    fill(p, p+n, -2);
    bool st[n];
    memset(st, false, sizeof(st));
    int disc[n];
    fill(disc, disc+n, -1);
    int dn = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] == -2) {
            p[i] = -1;
            vi t;
            if (tarjan(e, i, p, st, disc, dn, t)) {
                cout << t.size() << endl;
                for (int j = t.size() - 1; j >= 0; j--) {
                    cout << t[j] + 1 << endl;
                }
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


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

string st;
int A[200005], N;
int memo[200005][3];

int dp(int now, int last) {
  if(now == N) return 0;
  if(memo[now][last] != -1) return memo[now][last];
  if(A[now] == -1) {
    int D = 0, P = 0;
    //coba D
    D = 1 + dp(now + 1, 0) + (last == 1);
    //cona P
    P = dp(now + 1, 1);
    return memo[now][last] = max(D, P);
  }else if(A[now] == 0) {
    return memo[now][last] = dp(now + 1, 0) + (last == 1) + 1;
  }else return memo[now][last] = dp(now + 1, 1);
}

void trace(int now, int last) {
  if(now == N) return;
  if(A[now] == -1) {
    int D = 0, P = 0;
    //coba D
    D = 1 + dp(now + 1, 0) + (last == 1);
    //cona P
    P = dp(now + 1, 1);
    if(D > P) {
      cout << 'D';
      trace(now + 1, 0);
    }else {
      cout << 'P';
      trace(now + 1, 1);
    }
  }else if(A[now] == 0) {
    cout << 'D';
    trace(now + 1, 0);
  }else {
    cout << 'P';
    trace(now + 1, 1);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  memset(memo, -1, sizeof(memo));
  cin >> st;
  N = st.size();
  for(int i = 0; i < N; i++) {
    if(st[i] == '?') {
      A[i] = -1;
    }else if(st[i] == 'P') {
      A[i] = 1;
    }else A[i] = 0;
  }
  dp(0, 0);
  trace(0, 0);
}

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

int main(){
    int h, w;
    cin >> h >> w;
    int c[10][10];
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
        }
    }

    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    int cnt = 0;
    rep(i, h){
        rep(j, w){
            int a;
            cin >> a;
            if(a!=-1) cnt += c[a][1];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    string s;
    cin>>s;
    int a=0;
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            a++;
            if(s[i]=='0')
                s[i]='1';
            else
                s[i]='0';
        }
    }
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  cout << n * 800 - (int)(n/15) * 200 << endl;
  return 0;
}


Measured memory_bytes: 256
c[5004],d[5004],m,t,u,i,f="%d\n";main(x){for(scanf("%d%*d",c);i<*c;scanf(f,++i+c));for(;~scanf(f,&x);)for(u=i=t=0;i++<*c;t=d[i],d[i]=m<u?m=u:u)u=x-c[i]?u:t+1;m=!printf(f,m);}

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


int n,c;
int a[30];
int b[30];
int memo[32][65536];

int changeBit(int num[]){
  int n = 0;
  int p = 1;
  for(int i = 0;i < 16;i++){
    n += num[15-i] * p;
    p *= 2;
  }
  return n;
}

int check(int bit1,int bit2){
  int tmp1,tmp2;
  int ttmp = 1;
  int ans = 0;
  for(int i = 0;i < 16;i++){
    tmp1 = bit1 & ttmp;
    tmp2 = bit2 & ttmp;
    if(tmp1 == tmp2 && tmp1 != 0) ans++;
    ttmp = (ttmp << 1);
  }
  return ans;
}

int dfs(int i,int bit){
  if(memo[i][bit] != -1) return memo[i][bit];
  if(i == n) return 0;

  int btmp = bit;
  bit |= a[i];

  int ans = dfs(i+1,bit);
  for(int j = 0;j < c;j++){
    ans = max(ans,dfs(i+1,bit & (~b[j])) + check(bit,b[j]));
  }

  return memo[i][btmp] = ans;
}

int main(){
  while(1){
    cin >> n >> c;
    if(n == 0 && c == 0) break;
    for(int i = 0;i < 32;i++) for(int j = 0;j < 65536;j++) memo[i][j] = -1;

    int num[16];
    for(int i = 0;i < n;i++){
      for(int j = 0;j < 16;j++) cin >> num[j];
      a[i] = changeBit(num);
    }

    for(int i = 0;i < c;i++){
      for(int j = 0;j < 16;j++) cin >> num[j];
      b[i] = changeBit(num);
    }


    cout << dfs(0,0) << endl;
  }

  return 0;
}







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

int main () {
  int N;
  cin >> N;
  
  int a, ans[N];
  for (int i = 0; i < N; i++) {
    scanf("%d",&a);
    ans[a-1] = i+1;
  }
  for (int i = 0; i < N; i++) {
    printf("%d ",ans[i]);
  }
  printf(" ");
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	int ans = -1;
	FOR(i, 1, 512345) {
		double p = i;
		p *= 1.08;
		if ((int)p == N) {
			ans = i;
			break;
		}
	}
	
	if (ans == -1) puts(":(");
	else cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# B String Palindrome

def check(S, N):
  for i in range((N-1)//2):
    if S[i] != S[-(1+i)]:
      print("No")
      exit()

def ot_check(S, N):
  for i in range(N//2):
    if S[i] != S[-(1+i)]:
      print("No")
      exit()

S = input()
N = len(S)

SS = S[0:(N-1)//2]
NN = len(SS)

SSS = S[((N+3)//2)-1:]
NNN = len(SSS)

check(S, N)
if len(SS)%2 == 0:
  ot_check(SS, NN)
else:
  check(SS, NN)
if len(SSS)%2 == 0:
  ot_check(SSS, NNN)
else:
  check(SSS, NNN)

print("Yes")




Measured memory_bytes: 9068