akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.util.Scanner;

/**
 * @author MS14A
 * @version 2017/03/06
 */
public class Main {

    private static final String RESULT_DRAW = "d";

    /**
     * メインメソッド
     *
     * @param args
     */
    public static void main(String[] args) {
        // ローカルテスト用。提出時は"System.in"に修正。
        InputStream input = System.in;
//        File input = new File("D:/Temp/AOJ/0066_TicTacToe.txt");

        try (Scanner scanner = new Scanner(input)) {
            while (scanner.hasNextLine()) {
                System.out.println(judgeWinner(splitLine(scanner.nextLine())));
            }
        } catch (Exception e) {
            // 対応しない。
        }
    }

    private static String[] splitLine(String line) {
        String[] result = new String[line.length()];

        for (int i = 0; i < line.length(); i++) {
            result[i] = String.valueOf(line.charAt(i));
        }

        return result;
    }

    private static String judgeWinner(String[] line) {
        String result = null;
        // 縦のチェック
        result = checkVertical(line);

        if (result != null) {
            return result;
        }

        // 横のチェック
        result = checkHorizontal(line);
        if (result != null) {
            return result;
        }

        // 斜めのチェック
        result = checkDiagonal(line);
        if (result != null) {
            return result;
        }

        return RESULT_DRAW;
    }

    private static String checkVertical(String[] line) {

        for (int i = 0; i < 3; i++) {
            if (!"s".equals(line[i]) && line[i].equals(line[i + 3])
                    && line[i + 3].equals(line[i + 6])) {
                return line[i];
            }
        }

        return null;
    }

    private static String checkHorizontal(String[] line) {

        for (int i = 0; i < 9; i+=3) {
            if (!"s".equals(line[i]) && line[i].equals(line[i + 1])
                    && line[i + 1].equals(line[i + 2])) {
                return line[i];
            }
        }

        return null;
    }

    private static String checkDiagonal(String[] line) {
        if (!"s".equals(line[0]) && line[0].equals(line[4])
                && line[4].equals(line[8])) {
            return line[0];
        }

        if (!"s".equals(line[2]) && line[2].equals(line[4])
                && line[4].equals(line[6])) {
            return line[2];
        }

        return null;
    }
}

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

int main() {
    char c[55][55];
    int H,W,cnt=0;
    cin>>H>>W;
    for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
   for(int i=1;i<=H;i++){
       for(int j=1;j<=W;j++){
           if(c[i][j]=='#' && c[i][j-1] != '#' && c[i-1][j] != '#' && c[i][j+1] != '#' && c[i+1][j] != '#') cnt++;
       }
   }
   if(cnt==0) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 256
num_length = int(input())
num_array = [int(x) for x in input().split()]

def bubbleSort(A, N):
    flag = 1
    exchange_counter = 0
    while flag:
        flag = 0
        for i in range(1, N):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                flag = 1
                exchange_counter += 1
    print(" ".join(map(str, A)))
    print(exchange_counter)

bubbleSort(num_array, num_length)

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N){
    cin >> vec[i];
  }
  
  int count = 0;
  rep(i,N){
    if(vec[i]%2 == 1) count++;
  }
  
  if(count%2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

int max_term(int max, int in1)
{
	if (in1 > max)
	{
		max = in1;
	}
	return max;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, max;

	cin >> A >> B;
	max = -INF; //max
	max = max_term(max, A + B);
	max = max_term(max, A - B);
	max = max_term(max, A * B);

	cout << max << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var ans = 0;
            var chk = A[0];
            var tmp = 1;

            for(var i = 1; i < A.Length; i++)
            {
                if (A[i] == chk)
                {
                    tmp++;
                }else
                {
                    chk = A[i];
                    ans += tmp / 2;
                    tmp = 1;
                }
            }
            if (tmp > 0) ans += tmp / 2;

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
# ABC 132: B – Ordinary Number
n = int(input())
p = [int(s) for s in input().split()]

the_number = 0

for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        the_number += 1

print(the_number)

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

int main(void)
{
    int A,B;

    cin >> A >> B;
    if(A + B >= 10)
        cout << "error" << endl;
    else
        cout << A + B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    vvi v(n,vi(n));
    rep(i,n)rep(j,n)cin>>v[i][j];
    vi dp(1<<n);
    vi val(1<<n);
    rep(i,1<<n)rep(j,n)REP(k,j+1,n)if((i>>j&1)&&(i>>k&1))val[i]+=v[j][k];
    dp[0]=0;
    REP(i,1,1<<n){
        for(int j=i;j>=0;j=(j-1)&i){
            chmax(dp[i],dp[j]+val[i&(~j)]);
            if(j==0)break;
        }
    }
    out(dp[(1<<n)-1]);
}

Measured memory_bytes: 4300
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	auto s = readln.chomp;

	long m;
	foreach (e;s) {
		m += cast(int)(e - '0');
	}
	if (m % 9 == 0) {
		writeln("Yes");
	} else {
		writeln("No");
	}
}


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

typedef long long lint;
typedef long double louble;

#define lf ('\n')

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 103;

int n,val[_];

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty();

	int ans=0;
	for(int l=1,r=1;l<=n;l=r+1)
	{
		r=l;while(val[r+1]==val[l])r++;
		ans+=(r-l+1)/2;
	}
	cout<<ans<<lf;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
  string s;
    while(cin>>n>>s){
        ll ans=0;
      bool l=1;
      if(n%2)
        l=0;
      for(int i=0; i<n/2; ++i){
            if(s[i]!=s[i+n/2])
              l=0;
        }
if(l){
  cout<<"Yes"<<endl;
}
      else{
        cout<<"No"<<endl;
      }
    }
  return 0;
}




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

int main(void)
{

  char x;

  scanf("%c", &x);

  if (x >= 'A' && x <= 'Z') x = 'A';
  else if (x >= 'a' && x <= 'z') x = 'a';

  printf("%c\n", x);

  return 0;

}


Measured memory_bytes: 1672
<?php
// D
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);
// RGBの個数の累積和
$c['R'][0] = $c['G'][0] = $c['B'][0] = 0;
for ($i = 0; $i < $n; $i++) {
    foreach (array_keys($c) as $k) {
        $c[$k][$i + 1] = $c[$k][$i];
        if ($k === $s[$i]) $c[$k][$i + 1]++;
    }
}
$ans = 0;
for ($i = 1; $i < $n - 1; $i++) {
    $s1 = array_pop(array_diff(array_keys($c), [$s[$i]]));
    $s2 = array_pop(array_diff(array_keys($c), [$s[$i], $s1]));
    $ans += $c[$s1][$i] * ($c[$s2][$n] - $c[$s2][$i + 1]);
    $ans += $c[$s2][$i] * ($c[$s1][$n] - $c[$s1][$i + 1]);
    for ($j = 1; $j <= $n; $j++) {
        if ($i - $j < 0 || $i + $j >= $n) break;
        if ($s[$i - $j] !== $s[$i] && $s[$i] !== $s[$i + $j] && $s[$i - $j] !== $s[$i + $j]) $ans--;
    }
}
echo $ans;

Measured memory_bytes: 16400
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	int topped_cnt = 0;
	for (int i = 0; i < 3; i++)
	{
		if (S[i] != 'x') topped_cnt++;
	}

	cout << 700 + topped_cnt * 100;

	return 0;
}


Measured memory_bytes: 3616
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int main() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    x3 = x2 + (y1 - y2);
    printf("%d", x3);
    y3 = y2 - (x1 - x2);
    printf(" %d", y3);
    x4 = x3 + (y2 - y3);
    printf(" %d", x4);
    y4 = y3 - (x2 - x3);
    printf(" %d", y4);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a=0;
	int b=0;

	for (;;)
	{
		b=b+1;

		scanf("%d", &a);


		if (a==0)
		{
			break;
		}

		printf("Case %d: %d\n", b, a);


	}

	return 0;

}

Measured memory_bytes: 596
(let* ((n (read))
    (m (read))
    (a (make-array (list n)))
    (money 0))
    (loop for i below n do
        (setf (aref a i) (list (read) (read)))
    )
    (setf a (sort a #'< :key #'car))
    (loop for i below n while (> m 0) do
        (progn
            (if (>= (second (aref a i)) m)
                (incf money (* (car (aref a i)) m))
                (incf money (* (car (aref a i)) (second (aref a i))))
            )
            (decf m (second (aref a i)))
        )
    )
    (princ money)
)

Measured memory_bytes: 80804
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n,k;
    double ans=0.0,start,tmp;
    cin>>n>>k;
    start=1.0/n;
    //cout<<start<<endl;
    //cout<<pow((1/3.0),3)<<endl;
    int counter=1;
    for(int i = 1;i <= n;i++)
    {
        if(i>=k)
            ans+=start;
        else
        {
            while(1)
            {
                if(i*pow(2,counter-1)<k&&i*pow(2,counter)>=k)
                {
                    tmp=start*pow(0.5,counter);
                    goto end;
                }
                counter++;
            }
        end:;
            ans+=tmp;
        }
        counter=1;
    }
    cout.precision(12);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    a,b,c,n=map(int,input().split())
    res = 0
    l = [a,b,c]
    l.sort()
    for i in range(n // l[2]+1):
        for j in range(n//l[1]+1):
            if n < l[2]*i+l[1]*j:
                break
            if (n - l[2] * i - l[1] * j ) % l[0] == 0:
                res += 1
    print(res)

main()

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

int n, k;

int main() {
	cin >> n >> k;
	if ((1 << n) <= k || (n == 1 && k == 1))
		return cout << -1, 0;
	if (k == 0) {
		for (int i = 0; i < (1 << n); i++)
  			cout << i << ' ' << i << ' ';
  		return 0;
	}
	cout << 0 << ' ';
	for (int i = 1; i < (1 << n); i++)
		if (i != k)
			cout << i << ' ';
	cout << 0 << ' ' << k << ' ';
	for (int i = (1 << n) - 1; i >= 1; i--)
		if (i != k)
			cout << i << ' ';
	cout << k;
}

Measured memory_bytes: 1792
//https://ykmaku.hatenablog.com/entry/2018/06/26/231705

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct union_find{
  vector<int> par,r;

  union_find(int n){
  	par.resize(n);
  	r.resize(n);
  	init(n);
  }

  void init(int n){
    for(int i = 0; i < n; i++) par[i] = i;
    for(int i = 0; i < n; i++) r[i] = 0;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(r[x] < r[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(r[x] == r[y]) r[x]++;
    }
  }

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

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

	vector<pair<int,int> > e(m);

	for(int i = 0; i < m; i++){
		cin >> e[i].first >> e[i].second;
		e[i].first--;
		e[i].second--;
	}

	int ans = 0;
	for(int i = 0; i < m; i++){
		union_find uf(n);

		for(int j = 0; j < m; j++){
			if(i!=j && !uf.same(e[j].first,e[j].second)){
				uf.unite(e[j].first,e[j].second);
			}
		}
		set<int> s;
		for(int j = 0; j < n; j++){
			if(uf.par[j]==j) s.insert(uf.par[j]);
		}
		if(s.size()>1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# 解説を参照済
def candidates(n, answers)
  _candidates = [ %w(S S), %w(S W), %w(W W), %w(W S) ]
  _candidates.each do |animals|
    (1..(n - 2)).each do |i|
      if animals[i - 1] == 'S' && animals[i] == 'S'
        if answers[i] == 'o'
          animals.push 'S'
        else
          animals.push 'W'
        end
      end
      if animals[i - 1] == 'W' && animals[i] == 'S'
        if answers[i] == 'o'
          animals.push 'W'
        else
          animals.push 'S'
        end
      end
      if animals[i - 1] == 'S' && animals[i] == 'W'
        if answers[i] == 'o'
          animals.push 'W'
        else
          animals.push 'S'
        end
      end
      if animals[i - 1] == 'W' && animals[i] == 'W'
        if answers[i] == 'o'
          animals.push 'S'
        else
          animals.push 'W'
        end
      end
    end
  end
end

def f(n, s)
  answers = s.split('')
  _candidates = candidates(n, answers)
  a_n = answers[n - 1]

  ans = _candidates
  list = answers

  ans.each do |ans_seq|
    if (ans_seq[0] == "S" && list[0] == "o") ||
       (ans_seq[0] == "W" && list[0] == "x")
      next unless (ans_seq[1] == ans_seq[n-1])
    else
      next unless (ans_seq[1] != ans_seq[n-1])
    end
 
    if (ans_seq[n-1] == "S" && list[n-1] == "o") ||
       (ans_seq[n-1] == "W" && list[n-1] == "x")
      next unless (ans_seq[0] == ans_seq[n-2])
    else
      next unless (ans_seq[0] != ans_seq[n-2])
    end
    # solve
    return ans_seq.join
  end
  -1

##  require 'pp'
##  pp _candidates.map(&:join)
#  valid_candidate = nil
#  _candidates.each do |candidate|
#    c = candidate[n - 1]
#    c_prev = candidate[n - 2]
#    c_next = candidate[0]
##    puts c
##    puts c_prev
##    puts c_next
#    valid =
#      if c == 'S'
#        if a_n == 'o'
#          c_prev == 'S' && c_next == 'S' || c_prev == 'W' && c_next == 'W'
#        else
#          c_prev == 'S' && c_next == 'W' || c_prev == 'W' && c_next == 'S'
#        end
#      else
#        if a_n == 'o'
#          c_prev == 'S' && c_next == 'W' || c_prev == 'W' && c_next == 'S'
#        else
#          c_prev == 'S' && c_next == 'S' || c_prev == 'W' && c_next == 'W'
#        end
#      end
#    if valid
#      valid_candidate = candidate.join
#      break
#    end
#  end
#  valid_candidate || -1
end

n = STDIN.gets.to_i
s = STDIN.gets
puts f(n, s)


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



int main(){
    while (true)
    {
        int d; int w;
        cin >> d >> w;
        if(d==0&&w==0){break;}
        vector<vector<int>> hyoukous(d,vector<int>(w));
        for(int i=0;i<d;i++){
            for(int j=0;j<w;j++){
                cin >> hyoukous[i][j];
            }
        }
        int ans = 0;

        for(int haba = 3;haba<w+1;haba++){
            for(int tks = 3;tks<d+1;tks++){
                for(int hdr=0;hdr<w-haba+1;hdr++){
                    
                    for(int ue = 0;ue<d-tks+1;ue++){
                        int mx = -1;
                        int mn = 10;
                        for(int a=hdr;a<hdr+haba;a++){
                            if(mn>hyoukous[ue][a])mn = hyoukous[ue][a];
                            if(mn>hyoukous[ue+tks-1][a])mn = hyoukous[ue+tks-1][a];
                        }
                        for(int b=ue;b<ue+tks;b++){
                            if(mn>hyoukous[b][hdr+haba-1])mn = hyoukous[b][hdr+haba-1];
                            if(mn>hyoukous[b][hdr])mn = hyoukous[b][hdr];
                        }

                        for(int c=hdr+1;c<hdr+haba-1;c++){
                            for(int dd=ue+1;dd<ue+tks-1;dd++){
                                if(mx<hyoukous[dd][c])mx = hyoukous[dd][c];
                            }
                        }
                        if(mx<mn){
                            int youryou = 0;
                            for(int c=hdr+1;c<hdr+haba-1;c++){
                            for(int dd=ue+1;dd<ue+tks-1;dd++){
                                youryou += mn - hyoukous[dd][c];
                            }
                        }
                        if(ans<youryou)ans = youryou;
                        }
                    }
                }
            }
        }

        cout << ans << endl;
    }
    
}





Measured memory_bytes: 3124
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        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)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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_imports)]
use std::cmp::*;
trait Each: Iterator {
    fn each<F>(self, mut f: F)
    where
        Self: Sized,
        F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T: Iterator> Each for T {}

fn main() {
    input! {
        s:chars,
        t:chars,
    }
    let (sl, tl) = (s.len(), t.len());
    let mut s = s
        .into_iter()
        .map(|x| x as u8 as usize - 97)
        .collect::<Vec<_>>();
        let mut s_ = s.clone();
    s.append(&mut s_);
    
    let t = t
        .into_iter()
        .map(|x| x as u8 as usize - 97)
        .collect::<Vec<_>>();
    
    
    let mut az = vec![vec![-1; sl*2]; 26];
    for (i, &x) in s.iter().enumerate() {
        az[x][i] = 1;
    }
    for x in 0..26 {
        let mut tmp = 1;
        let mut flag = false;
        for i in (0..sl*2).rev() {
            if az[x][i] == 1 {
                tmp = 1;
                flag = true;
            } else if flag {
                tmp += 1;
                az[x][i] = tmp;
            }
        }
    }
    let mut ans: i64 = 0;
    let mut n: usize = 0;
    for &x in &t {
        if az[x][n] == -1 {
      
            ans = -1;
            break;
        } else {
            ans += az[x][n];
            n = (n + az[x][n] as usize) % sl;
        }
    }
 
    p!(ans);
}


Measured memory_bytes: 63740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(Math.abs(x-a) > Math.abs(x-b)) {
			System.out.println("B");
		}else {
			System.out.println("A");
		}

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int AB, BC, CA;
    cin >> AB >> BC >> CA;
    cout << (AB * BC) / 2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll N;
ll ans = 0;

cin >> N;

vector<ll> L(N);

for(ll i = 0;i<N;++i) cin >> L[i];

ll a,b,c;

a = b = c = 0;

for(ll i = 0;i < N;++i){

    a = L[i];

    for(ll j = i+1;j < N;++j){

        b = L[j];

        for(ll k = j+1;k < N;++k){

            c = L[k];

            if(a == b || b == c || c == a) continue;

            if((a + b > c && a + c > b && b + c > a) && (a > 0 && b > 0 && c > 0))    ++ans;
            
        }
    }
}

cout << ans << endl;

return 0;

}


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

int main() {
  string s;
  cin >> s;
  
  string editer;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'B') {
      if (editer.size()) {
        editer.erase(editer.size() - 1);
      }
    }
    else editer += s.at(i);
  }
  
  cout << editer << endl;
  return 0;
}


Measured memory_bytes: 256
#https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_b

import heapq

k, t = list(map(int, input().split()))
cakes = list(map(lambda x: int(x)*-1, input().split()))
heapq.heapify(cakes)
ans = 0
top_change = True
for i in range(k):
    if top_change:
        first = heapq.heappop(cakes)
        first += 1
        if len(cakes) == 0:
            ans += first*-1
            break
        if first < cakes[0]:
            top_change = False
        else:
            top_change = True
        if first != 0:
            heapq.heappush(cakes, first)
    else:
        first = heapq.heappop(cakes)
        second = heapq.heappop(cakes)
        second += 1
        heapq.heappush(cakes, first)
        if second != 0:
            heapq.heappush(cakes, second)
        top_change = True

print(ans)



Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

//遅延セグメント木
//計算量 初期化:O(N)、区間加算:O(log(N))、区間和:O(log(N))、全体更新:O(N)

template<typename Monoid>
struct Lazy_Segment_Tree{
    Monoid f(Monoid a, Monoid b){
        return a+b;
    }
    const Monoid unit;
    int n;
    vector<Monoid> seg, lazy;
    
    Lazy_Segment_Tree(int N, const Monoid &x) : unit(x){
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, unit);
        lazy.assign(2*n, unit);
    }
    
    void eval(int i, int l, int r){
        if(lazy[i] != unit){
            seg[i] = f(seg[i], lazy[i]);
            if(r-l > 1){
                lazy[2*i] = f(lazy[2*i] ,lazy[i]/2);
                lazy[2*i+1] = f(lazy[2*i+1], lazy[i]/2);
            }
            lazy[i] = unit;
        }
    }
    
    void add(int a, int b, const Monoid &x, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        eval(i, l, r);
        if(a >= r || b <= l) return;
        if(a <= l && r <= b){
            lazy[i] = f(lazy[i], (r-l)*x);
            eval(i, l, r);
        }
        else{
            add(a, b, x, 2*i, l, (l+r)/2);
            add(a, b, x, 2*i+1, (l+r)/2, r);
            seg[i] = f(seg[2*i], seg[2*i+1]);
        }
    }
    
    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        eval(i, l, r);
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return f(vl, vr);
    }
    
    void update(int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        seg[i] = f(seg[i], lazy[i]);
        if(r-l > 1){
            lazy[2*i] = f(lazy[2*i], lazy[i]/2);
            lazy[2*i+1] = f(lazy[2*i+1], lazy[i]/2);
            update(2*i, l, (l+r)/2);
            update(2*i+1, (l+r)/2, r);
        }
        lazy[i] = unit;
    }
    
    Monoid operator [] (int i) const {return seg[n+i];}
    
    void clear(){
        fill(seg.begin(), seg.end(), unit);
        fill(lazy.begin(), lazy.end(), unit);
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    Lazy_Segment_Tree<ll> seg(N, 0);
    while(Q--){
        int q, x, y; cin >> q >> x >> y; x--;
        if(q == 0){
            ll a; cin >> a;
            seg.add(x, y, a);
        }
        else cout << seg.query(x, y) << endl;
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 610;
int result1[MAX_N][MAX_N];
int result2[MAX_N][MAX_N];

void dfs(const int N, int r, int c, const vector<pair<int,int>>& d, int result[MAX_N][MAX_N], const int val) {
  result[r][c] = val;
  for (auto p : d) {
    const int nr = r + p.first;
    const int nc = c + p.second;
    if (0 <= nr && nr < N && 0 <= nc && nc < N && result[nr][nc] == -1) {
      dfs(N, nr, nc, d, result, 1-val);
    }
  }
}

void solve(int N, int D, int result[MAX_N][MAX_N]) {

  vector<pair<int,int>> d;
  REP(r, N) REP(c, N) {
    if (r * r + c * c == D) {
      d.push_back({r, c});
      if (r > 0) d.push_back({-r, c});
      if (c > 0) d.push_back({r, -c});
      if (r > 0 && c > 0) d.push_back({-r, -c});
    }
  }

  REP(r, N) REP(c, N) if (result[r][c] == -1) {
    dfs(N, r, c, d, result, 0);
  }

  return;
  
}

int ans[MAX_N][MAX_N];

int main2() {
  int N = nextInt();
  int D1 = nextInt();
  int D2 = nextInt();

  CLR(result1, -1);
  solve(2*N, D1, result1);

  CLR(result2, -1);
  solve(2*N, D2, result2);

  vector<int> sz(4);
  REP(r, 2*N) REP(c, 2*N) {
    ans[r][c] = result1[r][c] * 2 + result2[r][c];
    sz[ ans[r][c] ]++;
  }

  int cnt = 0;
  int mai = distance(sz.begin(), max_element(ALL(sz)));
  REP(r, 2*N) REP(c, 2*N) {
    if (ans[r][c] == mai && cnt < N*N) {
      printf("%d %d\n", r, c);
      cnt++;
    }
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 33408
#include<stdio.h>
void DFS(int);
void DFSvisit(int);
int a[105][105],color[105],count,time,d[105],f[105],p[105],n;
int main(){
  int i,j,b[105],c,k;
  for(i=0;i<=100;i++){
    d[i]=0;
    f[i]=0;
    for(j=0;j<=100;j++){
      a[i][j]=0;
       
    }
  }
   
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&b[i]);
    scanf("%d",&k);
    for(j=1;j<=k;j++){
      scanf("%d",&c);
      a[b[i]][c]=1;
    }
  }
 
DFS(n);
      for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
      }
return 0;
}
void DFS(int u){
  int i;
  for(i=1;i<=u;i++){
    color[i]=0;
    p[i]=i;
    }
      time=0;
  for(i=1;i<=u;i++){
    if(color[i]==0){
      DFSvisit(i);
    }
  }
}
void DFSvisit(int u)
 {
   int i;
   color[u]=2;
   d[u]= ++time;
   for(i=1;i<=n;i++){
     if(color[i]==0 && a[u][i]==1){
       DFSvisit(i);
     }
   }
   color[u]=1;
   f[u] = ++time;
 }

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

int main()
{
    long long int N , K ;
    cin>>N>>K;
    vector<long long int>arr(N);
    for(int i=0;i<N;i++)
        cin>>arr[i];
    for(int i=K;i<N;i++)
    {
        arr[i]>arr[i-K] ? cout<<"Yes" : cout<<"No" ;
        cout<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 4776
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#p,n,k,b,*a = [int(i) for i in read().split()]

n = int(input())
ans = [i for i in range(1,n+1) if i%3!=0 and i%5!=0]
print(sum(ans))

Measured memory_bytes: 30160
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for(int i = a; i <= b; ++i) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3636
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def insertion_sort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    insertion_sort(A, N)


if __name__ == '__main__':
    main()



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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    string x; cin >> x;
    stack<char> s;
    rep(i, x.length()){
        if(x[i] == 'S') s.push('S');
        else if(s.size() == 0) s.push('T');
        else if(s.top() == 'T') s.push('T');
        else if(s.top() == 'S') s.pop();
    }
    cout << s.size() << endl;
    return 0;
}




Measured memory_bytes: 644
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

constexpr int my_log(int a){
    return 31-__builtin_clz(a);
}

constexpr int getSz(int a){
    return 1<<(my_log((a<<1)-1)+1);
}

const int mxn = 500005, mxs = getSz(mxn);
int n, l, q, st[mxs][26];
pair<int, int> range[mxs];
string s;

void init(){
    l = getSz(n);
    for(int i = 0; i < n; ++i) st[i+l/2][s[i]-'a'] = 1;
    for(int i = 0; i < l; ++i) range[i+l/2] = {i, i};

    for(int i = l/2-1; i > 0; --i){
        for(int j = 0; j < 26; ++j){
            st[i][j] = st[i*2][j] + st[i*2+1][j];
        }
        range[i] = {range[i*2].F, range[i*2+1].S};
    }
}

void update(int ind, char c){
    memset(st[l/2+ind], 0, 26*4);
    st[l/2+ind][c-'a'] = 1;

    int i = (l/2+ind)/2;
    while(i > 0){
        for(int j = 0; j < 26; ++j){
            st[i][j] = st[i*2][j] + st[i*2+1][j];
        }
        i /= 2;
    }
}

array<int, 26> getFull(int l, int r, int ind){
    int rl = range[ind].F, rr = range[ind].S;
    if(rl == l && rr == r){
        array<int, 26> ans = {};
        for(int i = 0; i < 26; ++i) ans[i] = st[ind][i];
        return ans;
    }
    else if(max(l, rl) <= min(r, rr)){
        array<int, 26> ls = getFull(l, min(r, range[ind*2].S), ind*2), rs = getFull(max(l, range[ind*2+1].F), r, ind*2+1);
        for(int i = 0; i < 26; ++i) ls[i] += rs[i];
        return ls;
    }
    else{
        return {};
    }
}

int query(int l, int r){
    auto a = getFull(l, r, 1);
    int ans = 0;
    for(int i = 0; i < 26; ++i){
        ans += a[i] >= 1;
    }
    return ans;
}

void solve(){
    cin >> n >> s >> q;
    init();
    
    for(int i = 0; i < q; ++i){
        int a; cin >> a;
        if(a == 1){
            int b;
            char c;
            cin >> b >> c;
            --b;
            update(b, c);
        }
        else{
            int b, c;
            cin >> b >> c;
            --b, --c;
            cout << query(b, c) << '\n';
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 116080
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  int m=n%10;
  if(m!=1&&m!=3&&m!=9&&m!=7){
    cout<<-1;
    return 0;
  }
  int cnt=1,cur=7;
  while(1){
    while(cur<n)cur=cur*10+7,cnt++;
    if(cur%n==0){
      cout<<cnt<<'\n';return 0;
    }
    cur%=n;
  }
  return 0;
}
//2020.08.02 21:27:30


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

const ll mod = 1000000007;

ll powLL(ll n) {
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
        ans *= 2;
        ans %= mod;
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> digit(60);
    for (ll i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        bitset<60> bs(x);
        for (int j = 0; j < 60; ++j) if (bs.test(j)) digit[j]++;
    }
    ll ans = 0;
    for (int k = 0; k < 60; ++k) ans += digit[k] * (n - digit[k]) % mod * powLL(k) % mod;
    cout << ans % mod << endl;
}


Measured memory_bytes: 256
s = input()
r = input()

s_list = []
for i in range(len(s)):
    new_s = s[i:] + s[0:i]
    s_list.append(new_s)

exist = False


for ss in s_list:
    if r in ss:
        exist = True

if exist:
    print("Yes")
else:
    print("No")


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

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<char> v, v2;

    if (s.size()%2 != 0){
        cout << "No";
    } else {
        for(int i = 0; i < s.size()/2; i++){
            v.push_back(s[i]);
        }
        for(int i = s.size()/2; i < s.size(); i++){
            v2.push_back(s[i]);
        }

        if(v == v2){
            cout << "Yes";
        } else {
            cout << "No";
        }
    }

    


    

}

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  auto c=make_v<Int>(3,3);
  for(Int i=0;i<3;i++)
    for(Int j=0;j<3;j++)
      cin>>c[i][j];
  
  vector<Int> a(3),b(3);
  for(Int i=0;i<3;i++){
    a[i]=b[i]=0;
    for(Int j=0;j<3;j++) a[i]+=c[i][j];
    for(Int j=0;j<3;j++) b[i]+=c[j][i];
  }
  auto check=[](bool x){
    if(!x){
      cout<<"No"<<endl;
      exit(0);
    }
  };
  for(Int i=0;i<3;i++){
    for(Int j=0;j<3;j++){
      check(abs(a[i]-a[j])%3==0);
      check(abs(b[i]-b[j])%3==0);
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


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

using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'R') cnt++;
  }

  if (cnt > (N / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n);
    int x,y,z;
    cin >> x >> y >> z;
    a[0].push_back(x);
    a[0].push_back(y);
    a[0].push_back(z);
    FOR(i,1,n){
        cin >> x >> y >> z;
        int xx = x + max(a[i-1][1],a[i-1][2]);
        int yy = y + max(a[i-1][0],a[i-1][2]);
        int zz = z + max(a[i-1][1],a[i-1][0]);
        a[i].push_back(xx);
        a[i].push_back(yy);
        a[i].push_back(zz);
    }
    int ans = max({a[n-1][0],a[n-1][1],a[n-1][2]});
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 7296
#!/usr/bin/env python3
n, m = map(int, input().split())
v = []
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    v += [(a, b)]
v.sort(key=lambda x: x[0])
for i in v:
    m -= i[1]
    if m >= 0:
        ans += i[0]*i[1]
    else:
        m += i[1]
        ans += m*i[0]
        break
print(ans)


Measured memory_bytes: 18164
#include <stdio.h>
#define MAX 100000
int partition(int, int);

int A[MAX],n;

int main(){
  int i,q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%de", &A[i]);

  q = partition(0, n-1);

  for(i=0; i<n; i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d", A[i]);
    if(i == q) printf("]");
  }
  printf("\n");

  return 0;
}

int partition(int p, int r){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[j] = t;
  return i+1;
}



Measured memory_bytes: 2104
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n = int(input())
    s = input()
    l, r = 0, 0
    for i in s:
        if i == "(":
            r += 1
        else:
            if r != 0:
                r -= 1
            else:
                l += 1
    ans = "("*l + s + ")"*r
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


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

int main(void){
    int n;
    cin >> n;
    
    int x = 0;
    int max = 0;
    char input;
    int i;
    for(i = 1; i <= n; i++){
        cin >> input;
        if(input == 'I'){
            x++;
            if(x > max){
                max = x;
            }
        }else{
            x--;
        }
    }
    
    cout << max << endl;
    
    return 0;
}


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

using namespace std;

// This is the template of Errichto which can be found on https://codeforces.com/submissions/Errichto

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
#define LOCAL 1
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};

int steps(int x)
{
    if(x==0) return 0;
    int ans=0;
    while(x>0)
    {
        ans++;
        int ppc=__builtin_popcount(x);
        x=x%ppc;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ppc=0;
    for(int i=0; i<n; i++)
    {
        if(s[i]=='1') ppc++;
    }
    vector<int> powers_less(n);
    vector<int> powers_more(n);
    int now_less=1;
    int now_more=1;
    for(int i=0; i<n; i++)
    {
        if(ppc-1 != 0)
        {
            powers_less[i]=now_less%(ppc-1);
        }
        powers_more[i]=now_more%(ppc+1);
        if(ppc-1 != 0)
        {
            now_less=(2*now_less)%(ppc-1);
        }
        now_more=(2*now_more)%(ppc+1);
    }
    int complete_mod_less=0;
    int complete_mod_more=0;
    for(int i=0; i<n; i++)
    {
        int mult=s[n-1-i]-'0';
        if(ppc-1 != 0)
        {
            complete_mod_less=(complete_mod_less+mult*powers_less[i])%(ppc-1);
        }
        complete_mod_more=(complete_mod_more+mult*powers_more[i])%(ppc+1);
    }
    vector<int> ans;
    for(int i=0; i<n; i++)
    {
        if(ppc==1)
        {
            if(s[i]=='1') ans.push_back(0);
            else
            {
                int new_rem=(complete_mod_more+powers_more[n-1-i])%(ppc+1);
                ans.push_back(1+steps(new_rem));
            }
        }
        else
        {
            if(s[i]=='1')
            {
                int new_rem=(complete_mod_less-powers_less[n-1-i]+10*(ppc-1))%(ppc-1);
                ans.push_back(1+steps(new_rem));
            }
            else
            {
                int new_rem=(complete_mod_more+powers_more[n-1-i])%(ppc+1);
                ans.push_back(1+steps(new_rem));
            }
        }
    }
    for(int i=0; i<ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6024
n, k = map(int, input().split())

input_list = []
for i in range(n):
    input_list.append(int(input()))

input_list.sort()

ans = float('inf')
ans_index = 0
for i in range(n-k+1):
    h = input_list[i+k-1] - input_list[i]
    ans = min(ans, h)

print(ans)

    

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

int main(){
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      cout << (j == 0 ? "": " ") << c[i][j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3312