akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans, x, y, ct, c, d, z;
	cin >> n;
	vector<pair<int, int>> a(n);
	set<pair<int, int>> s;
	for (i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		s.insert(a[i]);
	}

	ans = n;
	sort(a.begin(), a.end());
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			x = a[i].first - a[j].first;
			for (c = 0; c < n; c++) {
				for (d = c + 1; d < n; d++) {
					y = a[c].second - a[d].second;
					if ((x == 0) && (y == 0)) continue;

					ct = 0;
					for (z = 0; z < n; z++) {
						if (s.find({ a[z].first - x, a[z].second - y }) != s.end()) ct++;
					}
					ans = min(ans, n - ct);
				}
			}
		}
	}
	cout << ans << "\n";




	return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v;
    for (int i = 0; i < H; i++){
        string str;
        cin >> str;
        v.push_back(str);
    }
    vector<string> answer(H, "");
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            int tmp = 0;
            if (v.at(i).at(j) == '.'){
                if (i > 0 && v.at(i - 1).at(j) == '#') tmp++;
                if (i < H - 1 && v.at(i + 1).at(j) == '#') tmp++;
                if (j > 0 && v.at(i).at(j - 1) == '#') tmp++;
                if (j < W - 1 && v.at(i).at(j + 1) == '#') tmp++;
                if (i > 0 && j > 0 && v.at(i - 1).at(j - 1) == '#') tmp++;
                if (i > 0 && j < W - 1 && v.at(i - 1).at(j + 1) == '#') tmp++;
                if (i < H - 1 && j > 0 && v.at(i + 1).at(j - 1) == '#') tmp++;
                if (i < H - 1 && j < W - 1 && v.at(i + 1).at(j + 1) == '#') tmp++;
                answer.at(i) += to_string(tmp);
            }
            else{
                answer.at(i) += "#";
            }
        }
    }
    for (int i = 0; i < H; i++){
        cout << answer.at(i) << endl;
}
}

Measured memory_bytes: 3660
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
p_min = []
for i in range(10):
    p = c[i]
    for j in range(10):
        pp = p
        for k in range(10):
            for l in range(10):
                pp[k] = min(pp[k], p[l] + c[l][k])
        p = pp
    p_min.append(p[1])
a = [list(map(int, input().split())) for _ in range(h)]
ans = 0
for i in range(10):
    count = 0
    for j in range(h):
        count += a[j].count(i)
    ans += count * p_min[i]
print(ans)

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

int main() {
  int N;
  cin >> N;
  long long ans = 1;
  bool ngFlg = false;
  for(int index = 0 ;index < N; index++ ) {
  	long long A;
 	cin >> A;
    if(A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if(ngFlg || 1000000000000000000/ans < A) {
	  ngFlg = true;
    }
  	ans *= A;
  }
  if(ngFlg) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll price = 700;

  rep(i, 3) price += S[i] == 'o' ? 100 : 0;

  cout << price << endl;
  
  return 0;
}


Measured memory_bytes: 256
//ツ禿アツ青蚤,bツつェツ禿シツ療債つウツづェツつスツづつォツ、a+bツづ個個青板づーツ出ツ療債つケツづヲ
//ツ禿シツ療債づ個終ツづュツづィツづ孔OFツづ表ツつウツづェツづゥ

#include<iostream>
using namespace std;

int CountDigit(int x)
{
	int digit = 0;
	while(x)
	{
		x/=10;
		digit++;
	}
	return digit;
}

int main(void)
{
	int a, b;
	while(cin >> a >> b)
	{
		cout << CountDigit(a+b) << endl;
	}
	return 0;
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int A = a*n;
    if(A > b) cout << b << endl;
    else cout << A << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << N * (N - 1) / 2ll << endl;
    solve();
    return 0;
}


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

int main()
{
  int k, n;
  cin >> k >> n;
  int s[k];
  for (int i = 0; i < k;i++){
    cin >> s[i];
  }
  sort(s, s + k, greater<int>());
  int sum = 0;
  for (int i = 0; i < n;i++){
      sum += s[i]; 
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
w, h, x, y = map(int, input().split())

if x == 0 or x == w or y == 0 or y == h:
  print(w * h / 2, 0)
else:
  ans = 1 if min(x, w - x) * h == min(y, h - y) * w else 0
  print(w * h / 2, ans)
  

Measured memory_bytes: 2940
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int n, t;
	cin >> n >> t;

	int mini = 10000;
	for (int i = 0; i < n; i++) {
		int c, time;
		cin >> c >> time;
		if (time <= t && mini > c) {
			mini = c;
		}
	}
	if (mini == 10000)
		COUT("TLE");
	else
		COUT(mini);

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] surface =  br.readLine().split(" ");
   String[] order = br.readLine().split("");
 
   Dise dice1 = new Dise();
   dice1.setSurface(surface);
   dice1.SetDice(1, 2 , 3);
   dice1.RollDice(order);
  System.out.println( dice1.surface[dice1.Top]);
 
  }
}
 
 
class Dise{
 
    int[] surface = new int [6];
    int Top,Bottom,Right,Left,Front,Back;
 
 
    void setSurface(String[] SurfaceString){
 
        for(int i = 0; i < 6; i++){
 
            surface[i] = Integer.parseInt( SurfaceString[i] );
 
        }
 
    }
 
    void SetDice(int top, int front, int right){
       Top  = top - 1;
       Front = front - 1;
       Right = right - 1;
       Bottom = 5- (top - 1);
       Back = 5- (front - 1);
       Left = 5- (right - 1);
    }//SetDice
 
    void RollDice(String[] RollString){
        for(int i = 0; i < RollString.length ; i++){
 
            if( RollString[i].equals("W") ){
 
                Bottom = Left;
                Left = Top;
                Top = 5 - Bottom;
                Right = 5 - Left;
 
            }else if( RollString[i].equals("S")){
 
                Bottom = Front;
                Front = Top;
                Top = 5 - Bottom;
                Back = 5 - Front;
 
            }else if( RollString[i].equals("E")){
 
                Bottom = Right;
                Right = Top;
                Top = 5 - Bottom;
                Left = 5 - Right;
 
            }else{
 
                Bottom = Back;
                Back = Top;
                Top = 5 - Bottom;
                Front = 5 - Back;
 
            }
        }
 
        
    }//RollDice
 
}

Measured memory_bytes: 24444
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int l,n;
  cin>>n>>l;
  string s[n];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  string s1=s[0];
  for(int i=1;i<n;i++){
    s1+=s[i];
  }
  cout<<s1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int n, h;
    cin >> n >> h;

    vector<int> a, b;
    a.reserve(100000);
    b.reserve(100000);

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }

    // vector<int> c(a), d(b);

    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());

    int i = 0, sum = 0;
    for (; a[0] < b[i] && sum < h; ++i) {
        sum += b[i];
    }

    if (h - sum > 0) {
        i += (h - sum) / a[0] + ((h - sum) % a[0] != 0 ? 1 : 0);
    }

    out(i);

    int ttttttt;
    cin >> ttttttt;
}

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

int n;
int planA(int a){
    return a*n;
}

int planB(int b){
    return b;
}

int main (){
    int a, b;
    cin >> n >> a >> b;
    if(planA(a)<=planB(b)){
        cout << planA(a);
    }else{
        cout << planB(b);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, x, y;
		N = sc.nextInt();

		x = 800 * N;
		y = 200 * (N / 15);

		System.out.print(x - y);
	}
}

Measured memory_bytes: 21460
#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(){
    int n;
    cin >> n;
    int a[n+1];
    for(int i = 1;i <= n;i++)cin >> a[i];
    
    int ans = 0;
    for(int i = 1;i <= n;i++){
        if(i == a[a[i]])ans++;
    }
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 640
const main = stdin => {
  const input = stdin.trim().split('\n')

  const [A, B, K] = input[0].split(' ').map(x => parseInt(x))
  const answers = []
  for (let i = 1; i <= Math.min(A, B); i++) {
    if (A % i === 0 && B % i === 0) {
      answers.push(i)
    }
  }

  console.log(answers[answers.length - K])
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30400
#include<bits/stdc++.h>
using namespace std ; 
typedef long long int ll;
#define forn(i,e) for(ll i=0; i<e; i++)
#define fors(i , s ,e) for(ll i = s ; i < e ; i++)
#define endl "\n"
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PB push_back 
#define MP make_pair
#define F first
#define S second


int main()
{
string s , q ; cin >> s >> q ; 
ll c = 0 ; 
forn(i,s.size())
{
	if(s[i] != q[i])
	c++ ;
}
cout << c << endl ; 
}
  



Measured memory_bytes: 3912
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n, k;

  cin >> n >> k;

  vector<int> iv;
  int ans = 0;

  // vectorの初期化
  for (int i = 0; i <= n; i++) iv.push_back(0);

  for (int i = 1; i <= n; i++) {
    int x; cin >> x;
    iv[x] += 1;
  }

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


  // 0ではないivの要素の先頭のindexを探す
  int start;
  for (int i = 1; i <= n; i++) {
    if (iv[i] != 0) {
      start = i;
      break;
    }
  }

  if ((n - start + 1) > k) for (int i = start; i < n + 1 - k; i++) ans += iv[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int x, y; cin >> x >> y;
  	int flg = 0;
  	for(int a=0; a<=100; a++){
      for(int b=0; b<=100; b++){
      	if(a+b==x && 2*a+4*b==y) flg++;
      }
    }
  	if(flg==0) cout << "No" << endl;
  	else cout << "Yes" << endl;
    return 0;
}

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

//vector <long long> v[1000001];

//stack <long long> s, s2;

//queue <long long> s;

long long int  x[3000][3000], y[10000], m=0, szu, wy;
//char s[10000000];

int main()
{
    long long int d, e, f, i, j, q, t, n, k, a, b, c, w, p, aa, bb, cc, dd, nn, kk;
    t=1;
 //   scanf("%lld", &t);
    for(q=1; q<=t; q++)
    {
        for(i=0; i<=2000; i++)
        {
            x[0][i]=1;
        }
        for(i=1; i<=2000; i++)
        {
            x[i][0]=1;
            for(j=1; j<=2000; j++)
            {
                x[i][j]=x[i-1][j]+x[i][j-1];
                x[i][j]%=1000000007;
            }
        }
        scanf("%lld", &n);

        w=0;
        a=0;

        for(i=2; i<=n; i++)
        {
            if(i%3==0)
            {
                w+=x[a][n-i];
                a++;
                w=w%1000000007;
            }
        }

        printf("%lld\n", w);
    }
    return(0);
}



Measured memory_bytes: 43080
S = input()
N = len(S)
for i in range(N-1):
    if S[i] == S[i+1]:
        print(i+1, i+2)
        exit()
for i in range(N-2):
    if S[i] == S[i+2]:
        print(i+1, i+3)
        exit()
print(-1, -1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,W;
    cin >> N >> W;
    vector<P> item(N);
    REP(i,N)cin >> item[i].F >> item[i].S;
    vector<vector<ll>> dp(N+1,vector<ll>(W+1));
    REP(i,N){
        REP(l,W+1){
            chmax(dp[i+1][l],dp[i][l]);
            if(l + item[i].F <= W){
                chmax(dp[i+1][l+item[i].F],dp[i][l] + item[i].S);
            }
        }
    }
    ll maxa = 0;
    REP(i,W+1)chmax(maxa,dp[N][i]);
    cout << maxa << "\n";
}

Measured memory_bytes: 83136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  if(n % 2 == 0)
    out(n);
  else
    out(n * 2);
  memi;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[30];
string s;
int main()
{
	int i,j,k,n,m,x,y,z,w,q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		cin>>s;
		a[s[0]-'A']++;
	}
	ll ans;//march
	x=a['M'-'A'];
	y=a[0];
	z=a['R'-'A'];
	w=a[2];
	q=a['H'-'A'];
	ans=1ll*x*y*z+1ll*x*y*w+1ll*x*y*q+1ll*x*z*w+1ll*x*z*q+1ll*x*w*q+1ll*y*z*w+1ll*y*z*q+1ll*y*w*q+1ll*z*w*q;
	printf("%lld",ans);
	return 0;
}

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

int main(){
while(1){
	int d,n,m,in;
	vector<int> D;
	int ans=0;

	scanf("%d",&d); if(d==0)break;
	scanf("%d%d",&n,&m);
	D.push_back(0);; D.push_back(d);
	for(int i=0;i<n-1;i++){
		scanf("%d",&in);
		D.push_back(in);
	}
	sort(D.begin(),D.end());
	for(int i=0;i<m;i++){
		int ret=1000000001;
		scanf("%d",&in);
		int t=lower_bound(D.begin(),D.end(),in)-D.begin();
		ret=min(ret,D[t]-in);
		if(t>0)ret=min(ret,in-D[t-1]);
		ans+=ret;
	}

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

Measured memory_bytes: 1704
# 1
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_a
if False:
    N,K=map(int,input().split())
    print('YES' if N-K-(K-1)>=0 else 'NO')

# 2
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b
if False:
    N=int(input())
    S=input()
    print('Yes' if S.count('R')>S.count('B') else 'No')

# 3
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_a
if True:
    print('Yes' if len(set(input().split()))==1 else 'No')


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;

int k,x;

int main() {
	scanf("%d %d",&k,&x);
	int i=max(-1000000,x-k+1);
	printf("%d",i);
	for(i+=1;i<=min(1000000,x+k-1);i++)
		printf(" %d",i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<math.h>
#include<utility>

using namespace std;
stack<int> st;


void DFS(vector <vector<int> > &graph,vector<int> &vis,int i){
	if(vis[i])
		return;
	vis[i]=1;
	for(int j=0;j<graph[i].size();j++)
		if(!vis[graph[i][j]])
			DFS(graph,vis,graph[i][j]);
	st.push(i);
}

int main(){
	int n,m,a,b;
	cin>>n>>m;
	vector<int> vis(n+1,0);
	vector <vector<int> > graph(n+1);
	for(int i=0;i<m;i++){
		cin>>a>>b;
		graph[a].push_back(b);
	}

	//to find topological order(result will be stored in stack)
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			DFS(graph,vis,i);
		}
	}


	//start relaxing nodes in topological order
	vector<int> dp(n+1,0);
	while(!st.empty()){
		int top = st.top();
		st.pop();
		for(int i=0;i<graph[top].size();i++){
			if(dp[graph[top][i]]<dp[top]+1)
				dp[graph[top][i]]=dp[top]+1;
		}
	}

	//to find maximum distance to a point in dp
	int maxe = 0;
	for(int i=1;i<n+1;i++){
		maxe = max(maxe,dp[i]);
	}
	cout<<maxe;
}

Measured memory_bytes: 8960
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, m, a[1024][1024], b[1024][1024], x[1024], y[1024];
inline int f(int i, int j) { return (a[i][j]+b[i][j]+x[i]+y[j]) % 2; }

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) rep (j, m) scanf("%d", a[i]+j);
    rep (k, n-1) {
        int c = 0;
        rep (i, m) c += f(k, i) != f(k+1, i);
        rep (i, m) if ((f(k, i)==f(k+1, i)) == c%2) b[k+1][i]++, y[i]++;
        x[k+1] = c;
    }
    int s = 0;
    rep (i, m) if (f(0, i)) s++;
    rep (i, m) if (f(0, i) == s%2) rep (k, n) b[k][i]++;
    rep (i, n) rep (j, m) printf("%d%c", b[i][j]%2, "\n "[j+1<m]);
    return 0;
}

Measured memory_bytes: 9224
// AOJ 2119: Finding the Top RPS Player
// 2017.10.7 bal4u@uu

#include <stdio.h>
#include <string.h>

int dp[25];

int main()
{
	int t, n, m, i, s, cnt;

	t = 0; while (scanf("%d%d", &n, &m) && n > 0) {
		memset(dp, 0, sizeof(dp));
		dp[0] = n, cnt = 0;
		while (1) {
			s = 0;
			for (i = m; i >= 0; i--) {
				if (dp[i] >= 2) {
					dp[i+1] += dp[i] >> 1;
					s += dp[i] >> 1;
					dp[i] &= 1;
				}
			}
			dp[0] += s, cnt++;
			if (dp[m]) break;
		}
		printf("Case %d: %d\n", ++t, cnt);
	}
	return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N;
	cin >> N;
    ll A[100], B[100], C[100];

	rep(i, N)
		cin >> A[i];
	rep(i, N)
		cin >> B[i];
	rep(i, N-1)
		cin >> C[i];
	ll Ans = 0;

	Ans = B[A[0]- 1];
	rep1(i, N) {
		Ans += B[A[i] - 1];
		if (A[i - 1] + 1 == A[i])
			Ans += C[A[i] - 2];
	}
	cout << Ans << END;
	return 0;
}


Measured memory_bytes: 256
// atcoder-alloy.rs --- AtCoder Alloy
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        h: u32,
        w: u32,
        alloy: [(u32, u32); n],
    };

    let ans = alloy.into_iter().filter(|&(a, b)| h <= a && w <= b).count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int s[11];
int main(){
	scanf("%d%d%d",&s[1],&s[2],&s[3]);
	sort(s+1,s+4);
	if(s[3]-s[2]==s[2]-s[1]) printf("YES");
	else printf("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(ll i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}


int t[100000][3];
ll dp[100000][3];
int n,k;

ll slv(int i,int pv){
	if(i >= n) return 0;
	ll & ret = dp[i][pv];
	if(ret != -1) return ret ;
	ret = 0;
	rep(j,3){
		if(pv != j) ret = max(ret,t[i][j] + slv(i+1,j));
	}	
	return ret;
}

int main(){
	FAST
	cin >> n;
	rep(i,n) cin >> t[i][0] >> t[i][1] >> t[i][2];
	memset(dp,-1,sizeof(dp));
	cout << max(slv(0,0),max(slv(0,1),slv(0,2))) << endl;
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  cin >> N;
  if (N.at(1) == '7' || N.at(0) == '7' || N.at(2) == '7')
    cout << "Yes";
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,o,t;
  cin>>n;
  string w[n];
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  for(int i=0;i<n;i++){
    if(i==0){
       o=w[i][w[i].size()-1];
      continue;
    }
    else if(i==n-1){
      if(w[i][0]!=o){
        cout<<"No"<<endl;
        return 0;
      }
    }
    else{
      if(w[i][0]!=o){
        cout<<"No"<<endl;
        return 0;
      }
      o=w[i][w[i].size()-1];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(w[i]==w[j]&&i!=j){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

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

int h[100010];
ll cost[100010];

int main() {
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];

  for (int i = 0; i < n; i++) cost[i] = 10000000000;
  cost[0] = 0;

  for (int i = 1; i < n; i++) {
    for (int j = i; (i - j <= k) && 0 <= j; j--) {
      cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j]));
    }
  }

  cout << cost[n - 1] << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int N, H, W;
    int a[1200], b[1200];
    cin >> N >> H >> W;
    for (int i = 0; i < N; ++i)
        cin >> a[i] >> b[i];

    int count = 0;
    for (int i = 0; i < N; ++i)
    {
        if (H <= a[i] & W <= b[i])
            ++count;
    }
    
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//リストのノード（スタック内の各データ）の定義
typedef  struct stack{
  char elem;
  struct node *next;
}node;

//スタックにデータを追加
void push(node **first,char elem){
  //追加する分の領域を確保
  node *new = calloc(1,sizeof(node));
  if(new == NULL) exit(1);
  new->elem = elem;
  new->next = *first;
  *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
  char elem;
  node *tmp = *first;
  if(tmp == NULL) exit(1);
  elem = tmp->elem;
  *first = tmp->next;
  //取り出したノードのメモリを解放
  free(tmp);
  return elem;
}
    
int main(void){
  char string[100001];
  node *cube = NULL;//最初のノードの指す先
  int i,count = 0;
  scanf("%s",string);
  for(i=0;i<strlen(string);i++){
    if(cube == NULL){
      push(&cube,string[i]);
    }
    else if(string[i] == cube->elem){
      push(&cube,string[i]);
    }
    else{
      pop(&cube);
      count += 2;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 4888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll x,t;
	cin>>x>>t;
	cout<<max(0ll,x-t);
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

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

int main(){
    double a,b;
    cin >> a >> b;
    double cnt = 10*b-1;
    bool ans = false;
    while(cnt != 100*b){
        if((cnt*2/25 >= a && cnt*2/25 < a+1) && (cnt/10 >= b && cnt/10 < b+1)){
            cout << cnt;
            ans = true;
            break;
        }
        cnt++;
    }
    if(!ans) cout << "-1";
    return 0;
}

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

int main (){
  int k;
  cin >>k;
  ll sum = 0;
  for (int i = 1;i<=k;i++){
    for (int j = 1;j<=k;j++){
      for (int h = 1;h<=k;h++){
        ll a = gcd(i,j);
        sum += gcd(a,h);
      }
    }
  }
  cout << sum <<endl;
}

Measured memory_bytes: 3620
def maxSum(a, b, c, k):
  currentSum = 0
  currentSum += min(a, k)
  k -= a
  if k <= 0:
    return currentSum
  k -= min(b, k)
  if k <=0:
    return currentSum
  currentSum -= min(c, k)
  return currentSum

a, b, c, k = map(int, input().split())
print(maxSum(a, b, c, k))

Measured memory_bytes: 61672
from math import ceil

S = input().strip()
L = len(S)
ans = [0] * L
for i in range(L):
    if S[i] == 'R' and S[i + 1] == 'L':
        ans[i] = 1
        ans[i+1] = 1
# Rだけ考える
cnt = 0
for i in range(L-1):
    if S[i] == 'R' and S[i+1] == 'L':
        ans[i] += cnt//2
        ans[i+1] += ceil(cnt/2)
        cnt = 0
    else:
        if S[i] == 'R':
            cnt += 1
# Lだけ考える
cnt = 0
for i in range(L-1):
    if S[-i-1] == 'L' and S[-i-2] == 'R':
        ans[-i-1] += cnt//2
        ans[-i-2] += ceil(cnt/2)
        cnt = 0
    else:
        if S[-i-1] == 'L':
            cnt += 1

print(' '.join([str(a) for a in ans]))



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

int a, b;
int main() {
	cin>>a>>b;
	if (a==b){
		cout<<"Draw"<<endl;
	}
	else if (a==1){
		cout<<"Alice"<<endl;
	}
	else if (b==1){
		cout<<"Bob"<<endl;
	}
	else if (b>a){
		cout<<"Bob"<<endl;
	}
	else {
		cout<<"Alice"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String S = stdin.readLine();
        String T = stdin.readLine();

        int tLen = T.length();
        int change = tLen;

        for(int i = 0; i+tLen <= S.length(); i++) {
            String s1 = S.substring(i, i+tLen);
            int tempLen = check(s1, T);
            if(tempLen < change)
                change = tempLen;
        }

        System.out.println(change);
        return;
    }

    public static int check(String S, String T){
        int change = 0;
        for (int i = 0; i < S.length(); i++) {
            String temp1 = S.substring(i, i + 1);
            String temp2 = T.substring(i, i + 1);
            if (!temp1.equals(temp2)) {
                change++;
            }
        }
        return change;
    }
}


Measured memory_bytes: 49440
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;
	cin >> n;
	vector<pair<int, int> > r(n), b(n);
	for(int i=0; i<n; i++)
		cin >> r[i].first >> r[i].second;
	for(int i=0; i<n; i++)
		cin >> b[i].first >> b[i].second;
	sort(b.begin(), b.end());
	int ans=0;
	for(int i=0; i<n; i++){
		int tmp=-1;
		for(int j=0; j<n; j++){
			if(r[j].first<b[i].first && r[j].second<b[i].second){
				if(tmp==-1)
					tmp=j;
				else if(r[j].second>r[tmp].second)
					tmp=j;
			}
		}
		if(tmp!=-1){
			r[tmp].second=n*2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	if(A <= 8 && B <= 8) System.out.println("Yay!");
    	else System.out.println(":(");
    }

}


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

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

    int l,r;
    l = s / 100;
    r = s % 100;

    if (l <=12 && 1 <= l) {
        if (r <= 12 && 1 <= r ) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else if (r <= 12 && 1 <= r) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        ArrayDeque<Character> dq = new ArrayDeque<>();
        for(int i =0; S.length() > i; i++){
            char c = S.charAt(i);
            if(c == 'B' && dq.isEmpty() == false){
                dq.removeFirst();
            }else if(c == 'B' && dq.isEmpty()){
            }else{
                dq.addFirst(c);
            }
        }
        while(dq.isEmpty() == false){
            System.out.print(dq.removeLast());
        }

    }

}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int c[15][15],n,m,k,vis[15];
bool check(int x){
	for(int i = 1;i <= m;i++) vis[i] = 0;
	for(int i = 0;i < n;i++){
		if(x & (1 << i)){
			for(int j = 1;j <= m;j++){
				vis[j] += c[i][j];
			}
		}
	}
	for(int i = 1;i <= m;i++){
		if(vis[i] < k) return 0;
	}
	return 1;
}
int gao(int x){
	int res = 0;
	for(int i = 0;i < n;i++){
		if(x & (1 << i)) res += c[i][0]; 
	}
	return res;
}
void solve(){
	int ans = inf;
	for(int i = 0;i < (1 << n);i++){
		if(check(i)){
			ans = min(ans,gao(i));
		}
	}
	if(ans == inf) cout << -1 << endl;
	else cout << ans << endl;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	for(int i = 0;i < n;i++){
		for(int j = 0;j <= m;j++){
			cin >> c[i][j];
		}
	}
	solve();
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3660
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(x int) int {
	if x < 0 {
		return -1 * x
	} else {
		return x
	}
}

func min(a ...int) int {
	min := 1000000000
	for _, x := range a {
		if min > x {
			min = x
		}
	}
	return min
}

func main() {
	sc.Split(bufio.ScanWords)

	n, A, B, C := nextInt(), nextInt(), nextInt(), nextInt()
	l := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = nextInt()
	}

	var dfs func(cur, a, b, c int) int
	dfs = func(cur, a, b, c int) int {
		if cur == n {
			if min(a, b, c) == 0 {
				return 1000000000
			}
			return abs(A-a) + abs(B-b) + abs(C-c) - 30
		}

		cand1 := dfs(cur+1, a, b, c)
		cand2 := dfs(cur+1, a+l[cur], b, c) + 10
		cand3 := dfs(cur+1, a, b+l[cur], c) + 10
		cand4 := dfs(cur+1, a, b, c+l[cur]) + 10
		return min(cand1, cand2, cand3, cand4)
	}

	fmt.Println(dfs(0, 0, 0, 0))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
typedef pair<int,int> P;
const int M=1e5+10;
int n,m,dis[M];
vector<int> G[M];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0,x,y;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    queue<P> q;
    q.push(P(1,0));
    while(!q.empty())
    {
        P tmp=q.front();q.pop();
        int u=tmp.first,d=tmp.second;
        if(dis[u]) continue;
        dis[u]=d;
        for(int i=0;i<G[u].size();i++)
            if(G[u][i]>1)
                q.push(P(G[u][i],u));
    }
    for(int i=2;i<=n;i++)
        if(!dis[i])
            return printf("No\n")*0;
    puts("Yes");
    for(int i=2;i<=n;i++)
        printf("%d\n",dis[i]);
    return 0;
}


Measured memory_bytes: 11512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: u32,
    };
    println!(
        "{}",
        if n % n
            .to_string()
            .chars()
            .map(|c| c.to_digit(10).unwrap())
            .sum::<u32>()
            == 0
        {
            "Yes"
        } else {
            "No"
        }
    );
}


Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<vector<int>> dp(1<<n, vector<int>(51, inf));
    dp[0][0] = 0;

    for(int bit=0; bit<(1<<n); bit++){
        for(int pre=0; pre<=50; pre++){
            if(dp[bit][pre] == inf) continue;

            int bcnt = __builtin_popcount(bit);
            int cost = 0;
            for(int i=0; i<n; i++){
                if(bit & (1 << i)) continue;
                int val = (abs(bcnt - i) % 2 == 0 ? a[i] : b[i]);

                if(val >= pre){
                    chmin(dp[bit | (1 << i)][val], dp[bit][pre] + cost);
                }

                cost++;
            }
        }
    }

    int ans = inf;
    for(int i=0; i<=50; i++){
        chmin(ans, dp[(1 << n) - 1][i]);
    }

    cout << (ans == inf ? -1 : ans) << endl;

    return 0;
}

Measured memory_bytes: 63744
S = gets.chomp

array = S.scan(/(<+|>+)/).flatten

number = array.map do |a|
  if a[0] == "<" then
    next (0..a.size).to_a
  end

  next a.size.downto(0).to_a
end

i = 0
result = []
while i < number.size do
  n = number[i]
  if i >= 1 && number[i].size <= number[i-1].size then
    n = n[1..-1]
  end

  if i < number.size - 1 && number[i].size < number[i+1].size then
    n = n[0..-2]
  end
  result << n

  i += 1
end

puts result.flatten.inject(0) {|sum, x| sum + x}

Measured memory_bytes: 79628
#include <bits/stdc++.h>
#include <queue>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    string s;
    cin >> s;
    int n = s.length();
    ll dp[200010][2] = {}; //最後の部分の文字数で分ける
    rep(i, 200010) rep(j, 2) dp[i][j] = 0;

    rep(i, n) {
        //1 -> 1
        if (i == 0 || (i >= 1 && s[i - 1] != s[i])) {
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + 1);
        }

        //2 -> 1
        dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + 1);

        //1 -> 2
        if (i >= 1) {
            dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][0] + 1);
        }

        //2 -> 2
        if (i >= 3 && (s[i - 3] != s[i - 1] || s[i - 2] != s[i])) {
            dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][1] + 1);
        }
    }

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



Measured memory_bytes: 3732
#include <stdio.h>
int main()
{
    int n,l,i,j;
    char s[101][101],tmp[101];
    scanf("%d%d",&n,&l);
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    for(i=1;i<n;i++){
    for(j=1;j<n;j++){
      if(strcmp(s[j-1], s[j])>0){
        strcpy(tmp, s[j-1]);
        strcpy(s[j-1],s[j]);
        strcpy(s[j], tmp);
      }
    }
  }

    for(i=0;i<n;i++){
        printf("%s",s[i]);
    }
        return 0;
}


Measured memory_bytes: 128
N = int(input())
s = input()
numE = s.count("E")
numW = 0
ans = 10**10
for i in range(N):
    if s[i] == 'W':
        ans = min(ans, numE + numW)
        numW += 1
    else:
        numE -= 1
        ans= min(ans, numE+numW)

print(ans)


Measured memory_bytes: 3708
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;


int main() {
	int A, B, M, ans = INT_MAX;
	cin >> A >> B >> M;
	vector<int> alist(A), blist(B);
	for (int i = 0; i < A; i++) cin >> alist[i];
	for (int i = 0; i < B; i++) cin >> blist[i];
	for (int i = 0; i < M; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		ans = min(ans, alist[x - 1] + blist[y - 1] - c);
	}
	ans = min(ans, *min_element(alist.begin(), alist.end()) + *min_element(blist.begin(), blist.end()));
	cout << ans << endl;

}

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

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

struct UnionFind {
    vector<ll> parent;
    vector<ll> usize;
 
    UnionFind(int n) : parent(n), usize(n, 1LL){
        rep(i, n)parent[i]=i;
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }
    
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
 
        if(x == y)return false;
 
        if(parent[x] > parent[y]) swap(x, y);

        usize[x] += usize[y];
        parent[y] = x;
 
        return true;
    }
    
    int size(int x) {
        return usize[root(x)];
    }
};

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

    vector<ll> p(n);
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }

    UnionFind utree(n);
    
    rep(i, m){
        ll x, y;
        cin >> x >> y;
        x--, y--;

        utree.merge(x, y);
    }

    ll ans = 0;
    rep(i, n)if(utree.issame(i, p[i]))ans++;
    
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	string S;
	long long K;

	cin >> S;
	cin >> K;

	int p = 0;

	for (int i = 0; i < K; i++) {
		p = i;
		if (S[i] > '1') {
			break;
		}
	}

	cout << S[p] << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int h, w;
	while(cin >> h >> w && (h || w)) {
		vector<vector<int> > v(h);
		rep(i,h) {
			vector<int> va(w);
			v[i] = va;
		}
		rep(i,h) {
			string s;
			cin >> s;
			rep(j,w) {
				if(s[j] == '.') v[i][j] = 1;
			}
		}
		rep(i,h) {
			rep2(j,1,w) {
				if(v[i][j] > 0) v[i][j] += v[i][j-1];
			}
		}
		int max = 0;
		rep(i,h) {
			rep(j,w) {
				if(v[i][j] != 0) {
					int buf = v[i][j];
					int cur = buf;
					for(int k = i-1; k >= 0 && v[k][j] != 0; --k) {
						if(cur > v[k][j]) cur = v[k][j];
						if(buf < cur * (i-k+1)) buf = cur * (i-k+1);
					}
					if(max < buf) max = buf;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 2140
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
    int n , m , K;
    cin >> n >> m >> K;
    bool ans = false;
    rep(i,0,n+1) rep(j,0,m+1) ans |= i * j + (n - i) * (m - j) == K;
    puts(ans ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256