akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll P = 998244353;
ll f(ll b, ll n) {if (n <= 0) return 1; auto p = f(b, n / 2); return p * p % P * (n % 2 ? b : 1) % P;}
ll ms[200001];
int main()
  {int N, M, K, ans = 0; cin >> N >> M >> K;
  ms[0] = 1; for (int r = 1; r <= K; ++r) ms[r] = ms[r - 1] * (N - 1 - r + 1) % P * f(r, P - 2) % P;
  for (int k = 0; k <= K; ++k) ans = (ans + ms[k] * M % P * f(M - 1, N - k - 1) % P) % P;
  cout << ans << endl;}

Measured memory_bytes: 5192
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;


namespace AtCoder
{
    class Program
    {
        static long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static List<long> Slist() { return ReadLine().Trim().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            var N = Sarray();
            var Bi = Sarray();
            var Ai = new long[Bi.Length + 1];
            Ai[0] = Bi[0];
            for (var i = 0; i < Bi.Length ; ++i)
            {
                Ai[i] = Math.Min(Bi[i], Ai[i]);
                Ai[i + 1] = Bi[i];
            }
            WriteLine(Ai.Sum());
        }
    }
}


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

using namespace std;

const int N = 4010;

int a[N];
int b[N][N];
int n;
int x;

int main() {
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  for (int i = 0; i < n; i++) {
    b[i][i] = a[i];
    for (int j = i; j < n + n - 1; j++) {
      b[i][j + 1] = min(b[i][j], a[j + 1]);
    }
  }
  long long ans = 9e18;
  for (int sp = 0; sp < n; sp++) {
    long long cur = 1ll * x * sp;
    for (int i = 0; i < n; i++) {
      cur += b[i][i + sp];
    }
    ans = min(ans, cur);
  }
  printf("%lld\n", ans);
  return 0;
}


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

int N, M;
ll MAX = 0;
vector<tuple<ll, ll, ll>> cakeFac;

int main(){
  cin >> N >> M;
  cakeFac.resize(N);

  ll x, y, z;
  for(int i = 0; i < N; i++){ cin >> x >> y >> z; cakeFac[i] = make_tuple(x, y, z); }

  for(int i = 0; i < 8; i++){
    int s[3];
    vector<ll> tmpval(N, 0);  //符号を固定した際のデータ
    ll tmpsum = 0;
    for(int j = 0; j < 3; j++){ if((i >> j) & 1) s[j] = 1; else s[j] = -1; }  //各要素の符号方向の決定
    for(int k = 0; k < N; k++)
      tmpval[k] = s[0] * get<0>(cakeFac[k]) + s[1] * get<1>(cakeFac[k]) + s[2] * get<2>(cakeFac[k]);
    sort(tmpval.begin(), tmpval.end()); reverse(tmpval.begin(), tmpval.end());
    for(int l = 0; l < M; l++) tmpsum += tmpval[l];
    MAX = max(MAX, tmpsum);
  }

  cout << MAX << endl;
  return 0;
}
    


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

int main() {
	int H, W; cin >> H >> W;
	vector<string>s(H+2);
	for (int i = 1; i <= H; i++) {
		cin >> s[i];
		s[i].push_back('.');
		reverse(s[i].begin(), s[i].end());
		s[i].push_back('.');
		reverse(s[i].begin(), s[i].end());
	}
	s[0] = string(W + 2, '.');
	s[H+1] = string(W + 2, '.');

	bool flag = true;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (s[i][j] == '#') {
				if (s[i - 1][j] == '.' && s[i][j + 1] == '.' && s[i + 1][j] == '.' && s[i][j - 1] == '.')flag = false;
			}
		}
	}

	cout << (flag ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static List<Integer> list = new ArrayList<>();//生成した数列を格納するためのリスト
    static long max = 0;
    static long d_sum = 0;
    static Scanner sc = new Scanner(System.in);  
    static int N = sc.nextInt();
    static int M = sc.nextInt();
    static int Q = sc.nextInt();
    static int A[][]=new int[Q+1][5];
    
    
    //main関数の定義
    public static void main(String[] args) {
        for(int i=1;i<=Q;i++){
            for(int k=1;k<=4;k++){
                A[i][k]=sc.nextInt();
            }
        }       
        dfs(list, N, M, Q);
        System.out.println(max);
    }
    
    //main関数から呼ばれる関数を定義する
    static void dfs(List<Integer> list, int N, int M, int Q){

        if(list.size()==N){
            //終了時に実施する処理はこちら
            d_sum=0;    
            for(int i=1;i<=Q;i++){
                if (
                list.get(A[i][2]-1)-list.get(A[i][1]-1) ==                    
                A[i][3]
                )
                {
                    d_sum = d_sum+A[i][4];
                }   
            }
            max=Math.max(max,d_sum);
            return;
            }
            else{
                int prev_last = ((list.size()==0) ? 1 : list.get(list.size()-1));
                //
                for(int i=prev_last;i<=M;i++){
                    list.add(i);
                    dfs(list, N, M, Q);
                    list.remove(list.size()-1);
                }
            }           
        //}

    }
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  bool r = false;
  for (int i = 0; i < Q; i++)
  {
    int query;
    cin >> query;
    if (query == 1)
    {
      if (!r)
        r = true;
      else
        r = false;
    }
    else
    {
      int F;
      string C;
      cin >> F >> C;
      if (F == 1)
      {
        if (r)
          S.push_back(C[0]);
        else
        {
          S.insert(0, C);
        }
      }
      else
      {
        if (r)
          S.insert(0, (string)C);
        else
          S.push_back(C[0]);
      }
    }
  }
  if (r)
    reverse(S.begin(), S.end());
  cout << S << endl;
  return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long X){
    i64 cur = 100;
    rep(i, 10000000000){
        cur += cur / 100;
        if(cur >= X){
            cout << i + 1 << endl;
            break;
        }
    }
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int N;
const int MAX_N = 3010;

int main() {
  cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_N, 0));
  rep(i, N) dp[i][i] = 0;
  // dp[i][j]...[i,j) が残っている時から出発して両者最善を尽くした結果のX-Yの値
  for (int len=1; len<=N; len++){
    for (int i=0; i+len<=N; i++){
      int j = i + len;
      // j-iが残りの石の個数
      if ((N-len) % 2 == 0){
        // 取った石が偶数個なので今の局面が先手番
        dp[i][j] = max(dp[i+1][j] + A[i], dp[i][j-1] + A[j-1]);
      }else{
        // 今の局面が後手番
        dp[i][j] = min(dp[i+1][j] - A[i], dp[i][j-1] - A[j-1]);
      }
    }
  }
  cout <<dp[0][N] <<endl;
}


Measured memory_bytes: 71168
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void)
{
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	ll answer = 50000000000LL;

	for (ll i = 0; i <= 1000000; i++) {
		ll cost = c * i * 2;

		cost += max((x - i) * a, 0LL);
		cost += max((y - i) * b, 0LL);

		CHMIN(answer, cost);

	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
S = input()

def rev(anim):
    if anim == 'S':
        return 'W'
    else:
        return 'S'

def check(comb, ans):
    if comb[1] == 'S':
        if ans == 'o':
            return comb[0] == comb[2]
        else:
            return comb[0] != comb[2]
    else:
        if ans == 'o':
            return comb[0] != comb[2]
        else:
            return comb[0] == comb[2]

import sys
for T in ('SS', 'SW', 'WS', 'WW'):
    for i in range(2, n):
        ans = S[i-1]
        anim = T[i-1]
        prev = T[i-2]
        if ans == 'o':
            if anim == 'S':
                T += prev
            else:
                T += rev(prev)
        else:
            if anim == 'S':
                T += rev(prev)
            else:
                T += prev
    comb1 = T[n-2]+T[n-1]+T[0]
    ans1 = S[n-1]
    comb2 = T[n-1]+T[0]+T[1]
    ans2 = S[0]
    if check(comb1, ans1) and check(comb2, ans2):
        print(T)
        sys.exit(0)
print(-1)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int n, k;
      cin >> n >> k;
      vector<int> a(n);
      for(int i = 0;i < n;i++) cin >> a[i];
      sort(a.begin(), a.end());
      int ans = 0;
      for(int i = 0;i < k;i++) ans += a[n-i-1];
      cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[][] sw=new int[N][2];
		long cnt=0;
		for(int i=0; i<N; i++) {
			sw[i][0]=sc.nextInt();
			sw[i][1]=sc.nextInt();
		}
		for(int i=N-1; i>=0; i--) {
			if((cnt+sw[i][0])%sw[i][1]==0) {
				//
			}
			else {
				cnt+=sw[i][1]-(cnt+sw[i][0])%sw[i][1];
			}
		}
		System.out.println(cnt);
	}
	static class SC {

		private BufferedReader reader = null;

		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 46960
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <list>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define _DEBUG
#define vec vector
#define pb push_back
#define en '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef long double ld;
typedef unsigned int ui;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vi2;
typedef vector<vector<ll>> vll2;
typedef vector<vector<ll>> matrix;
typedef vec<vec<vec<int>>> vi3;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

const int inf = 2e9;
const ll linf = 5000000000000000000;
const ld LDINF = 2e18;
template<typename T> void print(vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cout << a[i] << ' ';
    cout << en;
}

template<typename T> void print(deque<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cout << a[i] << ' ';
    cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
    for (int i = 0; i < a.size(); i++)
    {
        for (int j = 0; j < a[i].size(); j++)
            cout << a[i][j];
        cout << en;
    }
}

template <typename T> void input(vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < a[i].size(); j++)
            cin >> a[i][j];
}

ll mod = 998244353;


void solve(){
    int k;
    string str;
    cin >> k >> str;
    if(k >= str.length()){
        cout << str;
    }
    else{
        for(int i = 0; i < k; i++){
            cout << str[i];
        }
        cout << "...";
    }
    
    
}




int main()
{
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
#endif
    int tst = 1;
   // cin >> tst;
    while(tst--)
        solve();
    
}


Measured memory_bytes: 3632
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
//#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
//#include <array>
#include <valarray>
#include <stdio.h>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

int main() {
	string s;
	getline(cin, s);
	vector<int> ary(10000000,0);
	for (int i = 0; i < (int)s.length(); ++i) {
		ary[(int)s[i]]++;
	}
	bool flag = true;
	for (int i = 97; i <= 122; ++i) {
		if (ary[i] % 2 == 1) {
			flag = false; break;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}
}

Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
char s[MaxN];
int l,mn;
int nxt[MaxN][26];
int dp[MaxN],go[MaxN],ch[MaxN];
int main() {
    scanf("%s",s+1);l=strlen(s+1);
    mn=1;
    for (int i=1;i<=l;++i) if (!nxt[0][s[i]-'a']) nxt[0][s[i]-'a']=i;
    for (int i=0;i<26;++i) if (!nxt[0][i]) nxt[0][i]=l+1;
    for (int i=1;i<=l;++i) {
        for (int j=0;j<26;++j) nxt[i][j]=nxt[i-1][j];
        nxt[i][s[i]-'a']++;
        while (nxt[i][s[i]-'a']<=l && s[nxt[i][s[i]-'a']]!=s[i]) nxt[i][s[i]-'a']++;
    }
    memset(dp,0x3f,sizeof dp);memset(go,0xff,sizeof go);memset(ch,'z'+1,sizeof ch);
    dp[l+1]=0;
    for (int i=l;i>=0;--i) {
        for (int j=0;j<26;++j) {
            int t=nxt[i][j];
            if (dp[t]+1==dp[i] && j+'a'<ch[i]) {
                ch[i]=j+'a';
                go[i]=t;
            } else if (dp[t]+1<dp[i]) {
                dp[i]=dp[t]+1;
                ch[i]=j+'a';
                go[i]=t;
            }
        }
    }
    int p=0;
    while (p!=l+1) {
        putchar(ch[p]);
        p=go[p];
    }
    return 0;
}

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

int main(){
    int a, b, c, variance=3;
    cin >> a >> b >> c;
    if(a==c) variance--;
    else if(a==b) variance--;
    else if(b==c) variance--;
    if(a==b && b==c) variance--;
    cout << variance << endl;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

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

    int n;
    cin >> n;

    vector<int> x(n), y(n);
    vector<int> xtoi(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
        xtoi[x[i]] = i;
    }

    map<int, int> memo;
    UnionFind uf(n);
    for (int xx = n - 1; xx >= 0; --xx) {
        int i = xtoi[xx];
        int lasti = i;
        for (auto it = memo.lower_bound(y[i]); it != memo.end(); ) {
            uf.unite(i, it->second);
            lasti = it->second;
            it = memo.erase(it);
        }
        memo[y[lasti]] = lasti;
    }

    for (int i = 0; i < n; i++) {
        cout << uf.size(i) << newl;
    }

    return 0;
}

Measured memory_bytes: 6552
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = max(x, y);
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
//const int INF = 1 << 30;//10^9
const ll INF = INFL;
//ll MOD = 1000000007;
ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll get_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

//素因数列挙
vector<ll> MakePrimeList(ll x) {
    vector<ll> res;
    for(ll k=2; k*k<=x; k++) {
        if(x % k == 0) {
            res.pb(k);
            while(x % k == 0) x /= k;
        }
    }
    if(x > 1) res.push_back(x);
    return res;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


int main(){
  ll A, B;
  cin >> A >> B;
  cout << max(0LL, A - 2 * B) << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	int i,x,y;
	x=1;
	int z[10000];
	for(i=0;x!=0;i++){
		scanf("%d",&x);
		z[i]=x;
	}
	for(y=0;y<i-1;y++){
		printf("Case %d: %d\n",y+1,z[y]);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

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

    int opt = pow(2,n);

    vector<int> vals(opt, numeric_limits<int>::max());
    for(int i=0; i < m; i++) {
        int a,b;
        cin >> a >> b;

        int ind = 0;
        for(int j=0; j < b; j++) {
            int val;
            cin >> val;
            ind |= 1<<(val-1);
        }

        vals[ind] = min(a, vals[ind]);
    }

    for(int cnt=0; cnt < 13; cnt++) {
        for(int i=0; i < opt; i++) {
            for(int j=0; j < opt; j++) {
                if(vals[i] == numeric_limits<int>::max() || vals[j] == numeric_limits<int>::max()) continue;
                if(i == j) continue;
                vals[i|j] = min(vals[i|j], vals[i] + vals[j]);
            }
        }
    }

    if(vals[opt-1] == numeric_limits<int>::max()) cout << -1;
    else cout << vals[opt-1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
 using namespace std;
 int main(){
 	priority_queue<long long int> pq;
 	long long int n,m;
 	cin>>n>>m;
 	for(int i=0;i<n;i++){
 		ll h;
 		cin>>h;
 		pq.push(h);
	 }
	 for(int i=0;i<m;i++){
	 	ll k;
	 	k=pq.top();
	 	  pq.pop();
	 	  k/=2;
	 	  pq.push(k);
	 }
	 ll sum=0;
	  while(!pq.empty()){
	   	sum+=pq.top();
	   	pq.pop();
	  }
	cout<<sum;
 }

Measured memory_bytes: 1400
a = [1 , 3 , 5 ,7 ,8 , 10 , 12]
a1 = [4,6,9,11]
a2 = [2]
x , y = map(int ,raw_input().split())
if x in a and y in a:
	print 'Yes'
elif x in a1 and y in a1:
	print 'Yes'
elif x in a2 and y in a2:
	print 'Yes'
else:
	print 'No'


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}






ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};

struct UnionFind {
    vector<int>d;
    UnionFind(int n=0):d(n,-1){}
    int find(int x){
        if((d[x])<0)return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x,int y){
        x =find(x);y=find(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return find(x)==find(y);};
    int size(int x){return -d[find(x)];};
};

int deg[100005];
vector<int> to[100005];





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint f(int n) {
    if(n==0)return 1;
    mint x=f(2/n);
    x*=x;
    if(n%2==1)x*=2;
    return x;
}

mint choose(int n,int a){
    mint x =1,y=1;
    rep(i,a){
      x*=n-i;
      y*=a+i;
    }
    return x/y;
}
const ll m=1000005;

int main()
{
 ll n;
 cin>>n;
 vector<ll>a(n);
 rep(i,n)cin>>a[i];
 sort(a.rbegin(),a.rend());
 ll m=0;
 ll sum=0;
 ll tmp=0;
 rep(i,n){
     if(i==0){
         continue;
     }
     sum+=a[m];
     if(i==1){
         m++;
         continue;
     }
     tmp++;
     if(tmp==2){
         m++;
         tmp=0;
     }
 }
 cout<<sum<<endl;
}
 




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

using namespace std;

priority_queue<int> q;
int a,b,c;
long long int sum;

int main() {
    while (cin>>a>>b>>c) {
        sum = 0;
        q.push(a);
        q.push(b);
        q.push(c);

        a = q.top();
        q.pop();
        b = q.top();
        q.pop();
        c = q.top();
        q.pop();

        sum = (a-b)+(b-c);
        cout<<sum<<endl;
    }
    return 0;
}


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

void Main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (x < d) {
        if (k % 2 == 0) {
            cout << abs(x) << endl;
        } else {
            cout << abs(x - d) << endl;
        }
    } else {
        ll y;
        y = x / d;
        if (k < y) {
            cout << abs(x - k*d) << endl;
            return;
        }
        k -= y;
        x -= y * d;
        if (k % 2 == 0) {
            cout << abs(x) << endl;
        } else {
            cout << abs(x - d) << endl;
        }
    }
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

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

int32_t main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans1, ans2, ans3, ans4;
    
    ans1 = b * d;
    ans2 = c * a;
    ans3 = a * d;
    ans4  = b * c;
    
    cout << max(ans1, max(ans2, max(ans3, ans4)));
    
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;

int main(){
    int n;
    double w, s = 0;
    cin >> n >> w;
    priority_queue<pair<double, double> > p;
    rep(i,n){
        double v, u;
        cin >> v >> u;
        p.push(make_pair(v/u, u));
    }

    while(!p.empty() && w > 0){
        double pv = p.top().first, pw = p.top().second;
        if(pw < w){
            s += pv * pw;
            w -= pw;
        }else{
            s += pv * w;
            w = 0;
        }
        p.pop();
    }
    printf("%.10f\n", s);
    return 0;
}


Measured memory_bytes: 5052
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {

	int n, a[100005];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if ( a[a[i]-1] == i+1) {
			cnt++;
		}
	}

	cout << cnt/2 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> vec;
bool isprime(int i){
    if(i==2) return true;
    if(i%2==0) return false;
    else{
        for(int j=3;j<=sqrt(i);j+=2){
            if(i%j==0) return false;
        }
        return true;
    }
}
int check(int n,int i,int p){
    if(p%i!=0) return 0;
    int sum=0;
    int rec=1;
    while(1){
        if(i==0 || p%i!=0) break;
        p/=i;
        sum++;
    }
    //cout<<i<<" "<<sum<<endl;
    if(sum<n) return 0;
    for(int j=0;j<sum/n;j++) rec*=i;
    //cout<<sum/n<<endl;
    return rec;
}
signed main(){
    for(int i=2;i<=1000000;i++){
        if(isprime(i)) vec.push_back(i);
    }
    int n,p;
    int ans=1;
    int tmp;
    cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    for(int i=0;i<vec.size();i++){
        if(p<vec[i]) break;
        tmp=check(n,vec[i],p);
        //cout<<tmp<<endl;
        if(tmp) ans*=tmp;
    }
    cout<<ans<<endl;
    
    return 0;
}



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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 2019;

int add(int a, int b) {
	a += b;
	while(a <= 0) a += MOD;
	return a % MOD;
}

int mul(int a, int b) {
	return 1ll * a * b % MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    reverse(all(s));
    int sm = 0, p = 1;
    map<int, int> mp;
    ++mp[0];
    REP(i, 0, sz(s)) {
    	sm = add(sm, mul(s[i] - '0', p));
    	++mp[sm];
    	p = mul(p, 10);
    }
    int res = 0;
    for(auto it: mp) {
    	res += 1ll * it.ss * (it.ss - 1)/2;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3756
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    uf.union(a,b)
ans=set()
for i in range(1,n+1):
    
    ans.add(uf.find(uf.par[i]))
print(len(ans)-1)

Measured memory_bytes: 19036
#include<bits/stdc++.h>
#define C char
#define D double
#define F float
#define LL long long
#define ULLI unsigned long long int
#define LLI long long int
#define LLD long long double
#define LD long double
#define S string
#define PI (2.0*acos(0.0))
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define READ 		freopen("input.txt","r",stdin)
#define WRITE  		freopen("output.txt","w",stdout)
using namespace std;

int main()
{
    LL n,y,z;
    cin>>n;
    S s;
    cin>>s;
    LL x = s.size();
    for(int i=0;i <x; i++)
    {
        if(s[i]+n>90)
        {
            y = s[i]+n;
            z = y-90;
            s[i]='A'+(z-1);
        }
        else
        {
            s[i]=s[i]+n;
        }
    }
    cout<<s;
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define inf 1e18
#define pi acos(-1.0)
#define mod 998244353

int main(void)
{
    fastio;

    ll n,a,b,l,r;
    cin >> n >> a >> b;
    l=(n-1)*a+b;
    r=(n-1)*b+a;

    if(n==1&&a!=b)cout << "0";
    else if(a>b)cout << "0";
    else
    {
        cout << r-l+1;
    }

    return 0;
}


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

int SSS(string a,string b){
	int p=0;
	if(a.size()>=b.size()){
		for(int i=0;i<=a.size()-b.size();i++){
			if(a.substr(i,b.size())==b){
				return b.size();
			}
		}
	}
	for(int i=1;i<=b.size();i++){
		if(i>a.size()){break;}
		if(a.substr(a.size()-i,a.size())==b.substr(0,i)){p=max(p,i);}
	}
	return p;
}

int hantei(int c){if(c==26){return -1;}if(c==27){return 2;}if(c==36){return -1;}if(c==40){return 9;}if(c==43){return -3;}return 0;}

string S[15];
int n;
int x[15][15];
int dp[15][32768];
int s,minx,d;

int main(){
	while(true){
		d++;
		s=hantei(d);minx=0;
		cin>>n;
		if(n==0){break;}
		for(int i=0;i<n;i++){
			cin>>S[i];
			s+=S[i].size();
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j){x[i][j]=0;}
				else{x[i][j]=SSS(S[i],S[j]);}
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<(1<<n);j++){
				dp[i][j]=-1;
			}
		}
		for(int i=0;i<n;i++){
			dp[i][(1<<i)]=0;
		}
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<n;j++){
				if(dp[j][i]>=0){
					for(int k=0;k<n;k++){
						if((i/(1<<k))%2==0){
							dp[k][i+(1<<k)]=max(dp[k][i+(1<<k)],dp[j][i]+x[j][k]);
						}
					}
				}
			}
		}
		for(int i=0;i<n;i++){
			minx=max(minx,dp[i][(1<<n)-1]);
		}
		cout<<s-minx<<endl;
	}
}

Measured memory_bytes: 2168
#include <iostream>

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[n];
		for(int i=0;i<n;i++)
			card[i]=n-i;

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				cut(card,p,c);
		}

		cout << card[0] << endl;
	}

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p-1+i];

	for(int i=0;i<p;i++)
		card[p+c-2-i]=card[p-2-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

Measured memory_bytes: 1160
#include<iostream>
#include <cmath>
using namespace std;
int Preime_number(int x);


int main() {

	int n, num, ans;
	ans = 0;

	cin >> n;

	while (n) {
		cin >> num;
		if (Preime_number(num))	ans++;
		n--;
	}

	cout << ans << endl;

	return 0;

}

int Preime_number(int x) {

	int limitnumber = sqrt(x);

	for (int i = 2; i <= limitnumber; i++)
	{
		if (x%i == 0) return 0;
	}

	return 1;
}





Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, ans;
  ans = 0;
  int cnt = 0;
  cin >> a;
  vector<int> vec(101);
  for (int i = 0; i < a; i++) {
    cin >> vec.at(i);
  }
  for (int i = 1; i <= a; i++) {
    if (vec.at(i) == vec.at(i - 1)) {
      cnt++;
    }
    else {
      ans += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
list = [input() for i in range(H)]
del_H = []
del_W = []

for h in range(H):
    if list[h] == '.'*W:
        del_H.append(h)

for w in range(W):
    list_C = []
    for h in range(H):
        list_C.append(list[h][w])
        if ''.join(list_C) == '.'*H:
            del_W.append(w)

list_new = []

for h in range(H):
    list_join = []
    if h in del_H:
        continue
    for w in range(W):
        if w in del_W:
            continue
        list_join.append(list[h][w])
    join_w = ''.join(list_join)
    list_new.append(join_w)

for i in list_new:
    print(i)

Measured memory_bytes: 3064
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */


#include <cstdint>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>

constexpr int32_t kMaxNumberOfVertices = 10000;
constexpr int32_t kInvalidIndex = -1;

void CallTopologicalSort(std::istream &input_stream);

struct Vertex {
  bool explored{false};
  std::vector<int32_t> next;
};

class TopologicalSort {
 public:
  TopologicalSort();
  ~TopologicalSort();
  void ConfigureVertices(const int32_t number_of_vertices);
  void AddVertex(const int32_t from_index, const int32_t to_index);
  void Sort();
  void Print();

 private:
  void Dfs(std::vector<int32_t> chain);
  int32_t GetUnexploredVertexIndex() const;

 private:
  int32_t number_of_vertices_;
  Vertex vertices_[kMaxNumberOfVertices];
  std::vector<int32_t> chain_;
  std::list<int32_t> sorted_result_;
};

void CallTopologicalSort(std::istream &input_stream) {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  TopologicalSort *topological_sort = new TopologicalSort();
  int32_t number_of_vertices, number_of_edges;
  input_stream >> number_of_vertices >> number_of_edges;
  topological_sort->ConfigureVertices(number_of_vertices);
  for (int32_t i = 0; i < number_of_edges; ++i) {
    int32_t vertex_from, vertex_to;
    input_stream >> vertex_from >> vertex_to;
    topological_sort->AddVertex(vertex_from, vertex_to);
  }
  topological_sort->Sort();
  topological_sort->Print();
  delete topological_sort;
}

TopologicalSort::TopologicalSort() : number_of_vertices_(0) {}

TopologicalSort::~TopologicalSort() {}

void TopologicalSort::ConfigureVertices(const int32_t number_of_vertices) {
  number_of_vertices_ = number_of_vertices;
}

void TopologicalSort::AddVertex(const int32_t from_index, const int32_t to_index) {
  vertices_[from_index].next.push_back(to_index);
}

void TopologicalSort::Sort() {
  sorted_result_.clear();
  chain_.clear();

  while (true) {
    const int32_t start_index = GetUnexploredVertexIndex();
    if (start_index == kInvalidIndex) {
      break;
    }
    chain_.push_back(start_index);
    Dfs(chain_);
  }
}

int32_t TopologicalSort::GetUnexploredVertexIndex() const {
  int32_t unexplored = kInvalidIndex;
  for (int32_t i = 0; i < number_of_vertices_; ++i) {
    if (!vertices_[i].explored) {
      unexplored = i;
      break;
    }
  }
  return unexplored;
}

void TopologicalSort::Dfs(std::vector<int32_t> chain) {
  const int32_t target = chain.back();
  vertices_[target].explored = true;
  for (const int32_t next_index : vertices_[target].next) {
    if (vertices_[next_index].explored) {
      // DO NOTHING
    } else {
      chain.push_back(next_index);
      Dfs(chain);
      chain.pop_back();
    }
  }
  sorted_result_.push_front(target);
}

void TopologicalSort::Print() {
  for (std::list<int32_t>::iterator itr = sorted_result_.begin(); itr != sorted_result_.end(); ++itr) {
    std::cout << *itr << std::endl;
  }
}

int main() {
  try {
    CallTopologicalSort(std::cin);
  } catch (...) {
    std::cerr << "ERROR: main()" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3788
//Author: Heltion
//Date: 2019-05-04 
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 1200;
char A[maxn][maxn];
bool vis[maxn][maxn];
int d[maxn][maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int H, W;
	cin >> H >> W;
	for(int i = 0; i < H; i += 1) cin >> A[i];
	queue<pair<int, int>> q;
	for(int i = 0; i < H; i += 1)
		for(int j = 0; j < W; j += 1)
			if(A[i][j] == '#'){
				vis[i][j] = true;
				q.push(make_pair(i, j));
			}
	int ans = 0;
	while(not q.empty()){
		int i = q.front().first, j = q.front().second;
		ans = max(ans, d[i][j]);
		q.pop();
		if(i and not vis[i - 1][j]){
			q.push(make_pair(i - 1, j));
			d[i - 1][j] = d[i][j] + 1;
			vis[i - 1][j] = true;
		}
		if(i + 1 < H and not vis[i + 1][j]){
			q.push(make_pair(i + 1, j));
			d[i + 1][j] = d[i][j] + 1;
			vis[i + 1][j] = true;
		}
		if(j and not vis[i][j - 1]){
			q.push(make_pair(i, j - 1));
			d[i][j - 1] = d[i][j] + 1;
			vis[i][j - 1] = true;
		}
		if(j + 1 < W and not vis[i][j + 1]){
			q.push(make_pair(i, j + 1));
			d[i][j + 1] = d[i][j] + 1;
			vis[i][j + 1] = true;
		}
	}
	cout << ans;
	return 0;
} 

Measured memory_bytes: 13568
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    W,H,x,y = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    half=(W*H/2)
    if W==x*2 and H==y*2:
        print(half,1)
    else:
        print(half,0)




if __name__ == "__main__":
    main()

Measured memory_bytes: 77500
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		String f = t.substring(0,1);
		TreeSet<String> ts = new TreeSet<>();
		int lt = s.length() - t.length() + 1;//roop回数

		for(int i = 0;i < lt; i++) {
			if(s.substring(i, i + 1).equals("?") || s.substring(i, i + 1).equals(f)) {//一文字ずつ切り出し
				for(int m = 0; m < t.length(); m++) {//t - 1繰り返す
					if(s.substring(i + m, i + m + 1).equals("?") || s.substring(i + m, i + m + 1).equals(t.substring(m , m + 1))) {
						if(m == t.length() - 1) {
							String ans = s.substring(0, i) + t;
							ans += s.substring(ans.length());
							ans = ans.replaceAll("\\?", "a");
							ts.add(ans);
						}
					} else {
						break;
					}
				}
			}
		}
		if(ts.size() <= 0) {
			System.out.println("UNRESTORABLE");
		} else {
			System.out.println(ts.first());
		}
	}
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF=1<<30;

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

int main() {
  int N,C;
  cin>>N>>C;
  vector<vector<int>> col(C,vector<int>(C));
  vector<map<int,int>> grid(3);
  rep(i,C){
    rep(j,C){
      cin>>col[i][j];
    }
  }
  rep(i,N){
    rep(j,N) {
      int x;
      cin>>x;
      grid[(i+j)%3][x-1]++;
    }
  }
  vector<vector<int>> cha;
  rep(i,C){
    rep(j,C){
      rep(k,C){
        cha.push_back({i,j,k});
      }
    }
  }
  int ans=INF;
  for(auto x:cha){
    if(x[0]==x[1]||x[1]==x[2]||x[2]==x[0])continue;
    int t=0;
    rep(i,3){
      for(auto y:grid[i]){
        t+=col.at(y.first).at(x[i])*y.second;
      }
    }
    chmin(ans,t);
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 1720