akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
  
class Main {
    public static void main(String[] args) {
         
        Scanner sc = new Scanner(System.in);
        DiceCtrl dc = new DiceCtrl();
 
        for(int i = 0; i < 6; i++) {
            dc.numList[i] = sc.nextInt();
        }
         
        String ctrl = sc.next();
        char[] ctrlList = ctrl.toCharArray();
         
        for(int i = 0; i < ctrlList.length; i++) {
            switch(ctrlList[i]) {
                case 'E' :
                    dc.ctrlE();
                    break;
                case 'N' :
                    dc.ctrlN();
                    break;
                case 'S' :
                    dc.ctrlS();
                    break;
                case 'W' :
                    dc.ctrlW();
                    break;
            }
        }
        System.out.println(dc.numList[0]);
    }
}
class DiceCtrl {
    public int[] numList = new int[6];
    private int tmp = 0;
     
    void ctrlE() {
        tmp = numList[0];
        numList[0] = numList[3];
        numList[3] = numList[5];
        numList[5] = numList[2];
        numList[2] = tmp;
    }
    void ctrlN() {
        tmp = numList[0];
        numList[0] = numList[1];
        numList[1] = numList[5];
        numList[5] = numList[4];
        numList[4] = tmp;
    }
    void ctrlS() {
        tmp = numList[0];
        numList[0] = numList[4];
        numList[4] = numList[5];
        numList[5] = numList[1];
        numList[1] = tmp;
    }
    void ctrlW() {
        tmp = numList[0];
        numList[0] = numList[2];
        numList[2] = numList[5];
        numList[5] = numList[3];
        numList[3] = tmp;
    }
}



Measured memory_bytes: 26424
#数字の数を求めるためのリストを作成する
num_list = [0 for i in range(101)]

#"EOFError"がくるまで入力を繰り返し、入力の番号のインデックスを1ふやす
try:
    while True:
        num_list[int(input())] += 1
except EOFError:
    
    #最瀕値の数が出てきた数を変数に代入し最瀕値であれば出力する
    i = max(num_list)
    for j in range(1,101):
        if num_list[j] == i:print(j)


Measured memory_bytes: 5596
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws NumberFormatException, IOException{
		int firstinput;
		int secondinput;
		int length;
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			firstinput = scan.nextInt();
			secondinput = scan.nextInt();
			length = String.valueOf((firstinput + secondinput)).length();
			System.out.println(length);
		}

	}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

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

    double stranica = l / 3.00;

    cout << fixed << setprecision(12) << pow(stranica, 3.00) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
#define mod 2019
#define ll long long  
int main(){
	ios;
	ll l,r,a=0;
	cin>>l>>r;
	int r1=r%mod,l1=l%mod;
	
	if((r/mod)-(l/mod)>=1)
		cout<<0<<"\n";
	else {
		int mi=2019;
		for(int i =l1;i<r1;i++){
			for(int j=i+1;j<=r1;j++)
				mi=min(mi,i*j%2019);
		} 
		cout<<mi<<"\n";
	}
	 
	return 0;
	 
}



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

using namespace std;

typedef long long ll;

struct union_find{
    vector<ll> par;
    vector<ll> chs;
    union_find(int N){
        par.resize(N);
        chs.resize(N);
        for(int i=0;i<N;i++) par[i] = i;
        for(int i=0;i<N;i++) chs[i] = 1;
    }
    ll root(ll x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(ll x,ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        chs[ry] += chs[rx];
    }
    bool same(ll x,ll y){
        return root(x) == root(y);
    }
    ll size(ll x){
        return chs[root(x)];
    }
};

ll p[100000];

int main(){
    ll N,M;
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> p[i];
    ll a,b;
    union_find uf(N);
    for(int i=0;i<M;i++){
        cin >> a >> b;
        uf.unite(a-1,b-1);
    }
    ll c = 0;
    for(int i=0;i<N;i++){
        if(uf.same(i,p[i]-1)) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 2560
import sys
import numba

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

@numba.njit
def main(N):
    x = 0
    for a in range(1, N+1):
        for b in range(1, N//a+1):
            x += a*b
    return x

N = int(read())
print(main(N))


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

int main() {
	int x;
	string s, p;
	cin >> s ;
	cin >> p;

	s += s;

	for (int i = 0;i < s.length() / 2;i++) {
		if (s[i] == p[0]) {
			x = 0;
			for (int j = 0;j < p.length();j++) {
				if (s[i + j] != p[j]) { break; }
				x++;
			}

			if (x == p.length()) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1188
#include<cstdio>

int main(){
  int h,w;
  while(1){
    scanf("%d %d",&h,&w);
    if(h == 0 && w == 0) break;
    for(int i = 0; i < h;i++){
      for(int u = 0; u < w;u++){
	printf("#");
      }
      printf("\n");
    }
     printf("\n");
  }
  return 0;
}

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

int main() {
  string s, t;
  cin >>s >>t;
  int ret = 1001;

  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int tmp = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i+j] != t[j]) tmp++;
    }
    ret = min(ret, tmp);
  }

  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3588
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var a=arr.shift().split(" ").map(Number);
var min=Infinity;
var ans=-1;
for(var i=0;i<n;i++){
   if(min>a[i]){
      ans=i;
      min=a[i];
   }
}
console.log(ans+1);


Measured memory_bytes: 27816
// Solution to https://codeforces.com/contest/1078/problem/C
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;

struct result {
    long long black = 1, white = 1;

    long long either() const {
        return (black + white) % MOD;
    }
};

int N;
vector<vector<int>> adj;

const result &extend(const result &root) {
    return root;
}

result attach(const result &root, const result &child) {
    result answer;
    answer.black = root.black * child.white % MOD;
    answer.white = root.white * child.either() % MOD;
    return answer;
}

result dfs(int node, int parent) {
    result answer;

    for (int neighbor : adj[node])
        if (neighbor != parent) {
            result child = dfs(neighbor, node);
            answer = attach(answer, extend(child));
        }

    return answer;
}

int main() {
    scanf("%d", &N);
    adj.assign(N, {});

    for (int i = 0; i < N - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    printf("%lld\n", dfs(0, -1).either());
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std; 
#define int      long long int
#define MOD      1000000007
#define pb       push_back
#define pf		 push_front
#define vi       vector<int>
#define mi  	 map<int,int>
#define umi		 unordered_map<int,int>
#define pii      pair<int,int>
#define ff 		 first
#define ss 		 second
#define inf		 1e18
#define case	int t;cin>>t;while(t--)	
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void pre()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
	{pre();
	 //case
	 {int n;
	  cin>>n;
	  int dp[n][n],a[n];
	  for(int i=0;i<n;i++)
	  	cin>>a[i];
	  for(int j=0;j<n;j++)
	  	{for(int i=j;i>=0;i--)
	  		{if(i==j)
	  			dp[i][i]=a[i];
	  		 else
	  		 	dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);	
	  		}
	  	}
	  cout<<dp[0][n-1];		

	 }
 		return 0;
	}

Measured memory_bytes: 70400
package main

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

func main() {
	N := nextInt()
	M := nextInt()

	an := make([]int, 0, N)
	bn := make([]int, 0, N)
	for i := 0; i < N; i++ {
		an = append(an, nextInt())
		bn = append(bn, nextInt())
	}

	cm := make([]int, 0, M)
	dm := make([]int, 0, M)
	for i := 0; i < M; i++ {
		cm = append(cm, nextInt())
		dm = append(dm, nextInt())
	}

	keys := make([]int, 0, N)
	for i := 0; i < N; i++ {
		result, k := 0, 0
		for j := 0; j < M; j++ {
			r := abs(an[i]-cm[j]) + abs(bn[i]-dm[j])
			if k == 0 || r < result {
				result = r
				k = j + 1
			}
		}

		keys = append(keys, k)
	}

	for _, k := range keys {
		fmt.Println(k)
	}
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// ---------- Util.


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

int N, P[200010];

void input()
{
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> P[i];
    }
}

int main()
{
    input();

    int ans = 0;

    int min = INT_MAX;

    for (int i = 1; i <= N; ++i) {
        if (min > P[i]) {
            min = P[i];
            ++ans;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
def f(a, c):
  b = [a.count(e) for e in a]
  if a!=b:
    b, c=f(b, c+1)
  return b, c

while int(raw_input())!=0:
  a = map(int, raw_input().split())
  a, c = f(a,0)
  print c
  print " ".join(map(str, a))

Measured memory_bytes: 4204
import itertools

def main():
    D,G=map(int,input().split())
    P=[]
    C=[]
    PC = []
    for i in range(D):
        p,c=map(int,input().split())
        PC.append([100*(i+1),p,c,(100*(i+1)*p+c)/p])
        P.append(p)
        C.append(c)
    res = 100000
    for i in itertools.permutations(range(D)):
        tp = G
        tn = 0
        for j in i:
            if tp <= (j+1)*100*P[j]:
                tn += (tp+(j+1)*100-1) // ((j+1)*100)
                break
            else:
                tp -= (j+1)*100*P[j]
                tn += P[j]
                tp -= C[j]
                if tp <= 0:break
        res = min(res,tn)

    return res

print(main())



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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    rep(i,n){
        if(a[a[i]]==i) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

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

int main() {
    ll L, R;
    cin >> L >> R;
    R = min(R, L + 4038);
    int ans = 2018;
    for (ll i = L; i <= R; i++) {
        for (ll j = i + 1; j <= R; j++) {
            int tmp = i*j % 2019;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(ll i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll A, B;
	cin >> A >> B;
	// [0,B]で立っている個数を各位ごとにみた後で
	// [0,A-1]で立っている個数を引いて上げればいい
	A--;
	vector<ll> bit(65,0);
	rep(i,63) {
		if(i == 0) {
			bit[i] += (B + 1) / 2;
			continue;
		}
		ll k = pow(2,i);
		bit[i] += k * (B / (k * 2));
		if ( B % (k * 2) != 0) {
			ll tmp = (B + 1)  % (k * 2);
			tmp -= k;
			tmp = max(tmp,(ll)0);
			bit[i] += tmp;
		}
	}
	rep(i,63) {
		if(i == 0) {
			bit[i] -= (A + 1) / 2;
			continue;
		}
		ll k = pow(2,i);
		bit[i] -= k * (A / (k * 2));
		if ( A % (k * 2) != 0) {
			ll tmp = (A + 1)  % (k * 2);
			tmp -= k;
			tmp = max(tmp,(ll)0);
			bit[i] -= tmp;
		}
	}
	ll ans = 0;
	rep(i,63) {
		if(bit[i] % 2 == 1){
			ans += pow(2,i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

class UFTree {
private:
	static const int	UFTREE_NODE_NUM = 100001;
	int mNode[UFTREE_NODE_NUM];
	int mRank[UFTREE_NODE_NUM];

public:
	void init(int n)
	{
		for (int i = 0; i < n; i++) {
			mNode[i] = i;
			mRank[i] = 0;
		}
	}

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

	void unite(int x, int y)
	{
		int idxX = find(x);
		int idxY = find(y);

		if (idxX == idxY) {
			return;
		}

		if (mRank[idxX] > mRank[idxY]) {
			mNode[idxY] = idxX;
		}
		else {
			mNode[idxX] = idxY;
			if (mRank[idxX] == mRank[idxY]) {
				mRank[idxY]++;
			}
		}
	}

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

UFTree tree;

int main()
{
	int N, M;
	cin >> N >> M;

	tree.init(N);
	for (auto i = 0; i < M; ++i)
	{
		int x, y, z;
		cin >> x >> y >> z;
		tree.unite(x - 1, y - 1);
	}

	set<int> exist;
	for (auto i = 0; i < N; ++i)
	{
		auto root = tree.find(i);
		exist.insert(root);
	}

	cout << exist.size() << endl;

	return 0;
}


Measured memory_bytes: 5760
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<vector<long long int>>matrix_product(vector<vector<long long int>>v, vector<vector<long long int>>w) {
	vector<vector<long long int>>ret(v.size(), vector<long long int>(w.front().size()));
	for (int i = 0; i < ret.size(); i++) {
		for (int j = 0; j < ret[i].size(); j++) {
			for (int k = 0; k < w.size(); k++) {
				ret[i][j] += v[i][k] * w[k][j];
				ret[i][j] %= M;
			}
		}
	}
	return ret;
}

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

	int a, b, c;
	while (cin >> N >> M >> a >> b >> c >> T, N) {
		vector<int>v(N);
		for (auto &i : v)cin >> i;
		vector<vector<long long int>>by(N, vector<long long int>(N));
		for (int i = 0; i < N; i++)by[i][i] = 1;
		vector<vector<long long int>>box(N, vector<long long int>(N));
		for (int i = 0; i < N; i++) {
			if (i) {
				box[i][i - 1] = a;
			}
			box[i][i] = b;
			if (i + 1 < N)box[i][i + 1] = c;
		}
		for (int i = 0; i < 30; i++) {
			if ((T >> i) & 1) {
				by = matrix_product(box, by);
			}
			box = matrix_product(box, box);
		}
		vector<vector<long long int>>ans(N, vector<long long int>(1));
		for (int i = 0; i < N; i++) {
			ans[i][0] = v[i];
		}
		ans = matrix_product(by, ans);
		for (int i = 0; i < N; i++) {
			if (i)cout << " ";
			cout << ans[i][0];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3208
fun main(args: Array<String>) = yorukatsu9a()

fun yorukatsu9a() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }

    var answer = 0

    for (i in 1..n) {
        val digitSum = i.toString().map { Character.getNumericValue(it) }.sum()
        if (digitSum in a..b) answer += i
    }

    println(answer)
}


Measured memory_bytes: 41188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long int64;
const int kMaxN = 1e5+10;

int MSB(int64 n) {
	for (int i = 41; i >= 0; --i) {
		if ((n>>i)&1) {
			return i;
		}
	}
	return -1;
}

void solve() {

	int64 n;
	cin >> n;

	int start = 41;
	vector<int> v;

	int msb = MSB(n);
	v.push_back(100);
	for (int i = 40; i >= 1; --i) {
		v.push_back(i);
	}
	for (int i = 41; i <= 40 + msb; ++i) {
		v.push_back(i);
	}

	int start1 = 1;

	v.push_back(41);
	int start2 = 42;

	for (int i = msb-1; i >= 0; --i) {
		if ((n>>i)&1) {
			v.push_back(start1);
			++start1;
		}
		v.push_back(start2);
		++start2;
	}

	v.push_back(100);

	cout << v.size() << "\n";
	for (auto el : v) {
		cout << el << " ";
	}
}

void reset() {
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		solve();
		reset();
	}
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
   
   int x,y,z,p;
   std::cin >> x;
   y=x/500;
   y=y*1000;
   z=x%500;
   z=z/5;
   p=y+z*5;

   std::cout << p << std::endl; 

return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
tmp = N
ans = []
# print("--------")
for i in range(len(bin(N))):
    # print(tmp % -2**(i+1), -2**(i+1))
    # print(tmp % 2**(i+1), 2**(i+1))
    k = tmp % -2**(i+1)
    # print("--------")
    if k == - 2**i:
        ans.append(1)
        tmp -= (-2)**i
    else:
        ans.append(0)
#print("".join(map(str, ans[::-1])))
tmp = 0
id = len(ans)
for i in range(len(ans)):
    if ans[i]:
        tmp += (-2)**i
    # print(tmp)
    if tmp == N:
        id = i+1
        break


ans = ans[:id]

print("".join(map(str, ans[::-1])))


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    string s;
    cin >> s;
//    string t[4] = {"KIHBR","KIHABR","KIHBAR","KIHABAR"};
    string u[] = {"KIH","B","R"};
    vector<string> t;
    for(int i = 0 ; i < 1 << 4; i++){
        string tmp;
        for(int j = 0; j < 4;j++){
            if(i >> j & 1){
                tmp += "A";
            }
            if(j < 3) tmp += u[j];
        }
        t.push_back(tmp);
    }

    rep(i,0,t.size()){
//        if(s.find(t[i]));
//        cout << (int)s.find(t[i]) << endl;
        if(s == t[i]){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
 cin.tie(NULL);
	ll n;
	cin>>n;
	string str;
	while(n>0)
	{
	   // a=97 z=122
	    int a=n%26;
	    if(a==0)
	    {
	        a=26;
	        str+=122;
	    }
	    else
	    str+=96+a;
	    n=n-a;
	    n/=26;
	}
	reverse(str.begin(),str.end());
	cout<<str<<"\n";
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    long x = sc.nextLong();
    int i = 0;
    double m = 100;
    while(m < x) {
      m *= 1.01;
      m = Math.floor(m);
      ++i;
    }
    System.out.println(i);
  }
}

class FastScanner {
  private final InputStream in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  public FastScanner(InputStream source) {
    in = source;
  }

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

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

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

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    return hasNextByte();
  }

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

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

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 32680
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

MOD = 10**9+7

xx = [x[i + 1] - x[i] for i in range(n - 1)]
yy = [y[i + 1] - y[i] for i in range(m - 1)]

print(sum(xx[i] * (i + 1) * (n - 1 - i) for i in range(n - 1)) *
      sum(yy[i] * (i + 1) * (m - 1 - i) for i in range(m - 1)) % MOD)

Measured memory_bytes: 25000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<vector<pair<ll,ll>>>a(100010);
ll ch[100010];
void dep(ll now,ll p,ll noc){
	if(a[now].size()==1&&a[now][0].first==p){
		return;
	}
	for(ll i=0;i<a[now].size();i++){
		ll next=a[now][i].first;
		if(ch[next]!=-1){
			continue;
		}
		ll wei=a[now][i].second;
		if(wei%2==0){
			ch[next]=noc;
			dep(next,now,noc);
		}
		else{
			ll nexc=abs(noc-1);
			ch[next]=nexc;
			dep(next,now,nexc);
		}
	}
}
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n-1;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		x--;y--;
		a[x].push_back(make_pair(y,z));
		a[y].push_back(make_pair(x,z));
	}
	for(ll i=0;i<n;i++){
		ch[i]=-1;
	}
	ch[0]=0;
	dep(0,-1,0);
	for(ll i=0;i<n;i++){
		cout <<ch[i]<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 11008
//
// Created by tattsun on 2017/02/11.
//
#include <iostream>
#include <vector>

using namespace std;

enum Color : int {
    None,
    Black,
    White,
};


Color char_to_color(char i) {
    if(i == '#') return Color::Black;
    return Color::White;
}

int n, m;
Color a[50][50], b[50][50];

bool _solve(int y, int x) {
    for(int i=0; i<m; i++) {
        for(int j=0; j<m; j++) {
            Color p = a[i+y][j+x];
            Color q = b[i][j];
            if(p != q)
                return false;
        }
    }
    return true;
}

bool solve() {
    for(int i=0; i<n-m+1; i++) {
        for(int j=0; j<n-m+1; j++) {
            if(_solve(i,j)) return true;
        }
    }
    return false;
}

int main() {
    for(int i=0; i<50; i++) {
        for(int j=0; j<50; j++) {
            a[i][j] = Color::None;
            b[i][j] = Color::None;
        }
    }

    cin >> n >> m;

    string cs;
    for(int i=0; i<n; i++) {
        cin >> cs;
        for(int j=0; j<n; j++) {
            a[i][j] = char_to_color(cs[j]);
        }
    }
    for(int i=0; i<m; i++) {
        cin >> cs;
        for(int j=0; j<m; j++) {
            b[i][j] = char_to_color(cs[j]);
        }
    }

    if(solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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 = sc.nextInt();
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		sb.append(s);
		int left=0;
		int right=0;
		for(char i:s.toCharArray()){
			if(i=='('){
				left++;
			}else{
				right++;
				if(left>0){
					right--;
					left--;
				}
			}
		}
		for(int i = 0; i<left; i++){
			sb.append(")");
		}
		for(int i = 0; i<right; i++){
			sb.insert(0,"(");
		}
			System.out.println(sb);
	}
}

Measured memory_bytes: 22612
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        
        if (a <= b) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 35660
#include<bits/stdc++.h>
#define N 100100
#define M 200100
using namespace std;
int a[M],b[M],c[M];
vector<int> g[M+N];
int dis[M+N];
int f[M];
int pre[1001000];
int find(int x){
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
} 
void uni(int x,int y){
	int fx=find(x),fy=find(y);
	if(fx!=fy) f[fx]=fy;
}
int main(){
	int n,m;
	memset(dis,-1,sizeof(dis));
	memset(pre,-1,sizeof(pre));
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		g[a[i]+m].push_back(i);
		g[b[i]+m].push_back(i);
		f[i]=i;
	}
	for(int i=m+1;i<=m+n;i++){
		for(int j=0;j<g[i].size();j++){
			int x=g[i][j];
			if(pre[c[x]]>=0) uni(pre[c[x]],x);
			pre[c[x]]=x;
		}
		for(int j=0;j<g[i].size();j++){
			int x=g[i][j];
			pre[c[x]]=-1;
		}
	}
	for(int i=0;i<m;i++){
		g[find(i)].push_back(a[i]+m);
		g[find(i)].push_back(b[i]+m);
	}
	for(int i=m+1;i<=m+n;i++){
		for(int j=0;j<g[i].size();j++){
			g[i][j]=find(g[i][j]);
		}
	}
	queue<int> q;
	q.push(m+1);
	dis[m+1]=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0;i<g[u].size();i++){
			if(dis[g[u][i]]<0){
				dis[g[u][i]]=dis[u]+1;
				q.push(g[u][i]);
			}
		}
	}
	if(dis[m+n]<0) printf("%d\n",-1);
	else printf("%d\n",dis[m+n]/2);
	return 0;
}

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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());
            int z;

            switch (x + y)
            {
                case 3: z = 3; break;
                case 4: z = 2; break;
                case 5: z = 1; break;
                default: z = 0; break;
            }
            Console.WriteLine(z);
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long int curh=-1;
  long long int res=0;
  for(int i=0;i<n;i++){
    long long int temp;
    cin>>temp;
    if(curh<temp){
      curh=temp;
    }
    else if(curh>temp){
      res+=(curh-temp);
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3580
n, m = map(int, input().split())
a = {int(input()) for _ in range(m)}
law = 10 ** 9 + 7

prepre = 0
pre = 1
for floor in range(1, n+1):
    if floor in a:
        prepre = pre
        pre = 0
    else:
        pre = (prepre + pre) % law
        prepre = (pre - prepre) % law
print(pre)

Measured memory_bytes: 11884
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct Node {
    int key;
    Node *next;
    Node *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur=nil->next;
    while (cur!=nil && cur->key!=key) {
        cur=cur->next;
    }
    return cur;
}
void init() {
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
void printList() {
    Node *cur=nil->next;
    int isf=0;
    while (true) {
        if (cur==nil) {
            break;
        }
        if (isf++>0) {
            printf(" ");
        }
        printf("%d",cur->key);
        cur=cur->next;
    }
    printf("\n");
}
void deleteNode(Node *t) {
    if (t==nil) {
        return ;
    }
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
void deleteFirst() {
    deleteNode(nil->next);
}
void deleteLast() {
    deleteNode(nil->prev);
}
void deleteKey(int key) {
    deleteNode(listSearch(key));
}
void insert(int key) {
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
int main() {
    int n;
    cin >> n;
    init();
    char com[20];
    int key;
    int np=0, size=0, nd=0;
    for (int i=0; i<n; i++) {
        scanf("%s %d",com,&key);
        if (com[0]=='i') {
            insert(key);
            np++;
            size++;
        } else if (com[0]=='d') {
            if (strlen(com)>6) {
                if (com[6]=='F') {
                    deleteFirst();
                } else if (com[6]=='L') {
                    deleteLast();
                }
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}

Measured memory_bytes: 34404
def main():
    N = input()
    M = list(map(int,input().split()))
    
    mult = 1
    
    if 0 in M:
        print(0)
        return
    
    for a in M:
        mult *= a
        if mult>10**18:
            print(-1)
            return
        
    print(mult)
    
main()

Measured memory_bytes: 21608
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    string s;
    cin>>s;
    int n = s.size();
    ll dp[2][2020]={};
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<2019;j++){
            dp[(i+1)%2][j] = 0;
        }
        dp[(i+1)%2][s[i]-'0']++;
        for(int j=0;j<2019;j++){
            dp[(i+1)%2][(j*10+(s[i]-'0')) % 2019] += dp[i%2][j];
        }
        ans += dp[(i+1)%2][0];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3808
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b, c; cin >> a >> b >> c;
	cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 384
# coding=UTF-8
from collections import deque
from collections import Counter
from operator import itemgetter
from bisect import bisect_left, bisect
from decimal import *
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)


def main():
    s = input()
    t = input()
    cnt=0
    for i in range(len(s)):
        if s[i] != t[i]:
            cnt+=1

    print(cnt)



if __name__ == '__main__':
    main()


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

using namespace std;

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

  int a, b, c, x;
  int res = 0;
  cin >> a >> b >> c >> x;
  x /= 50;
  for (int i = 0; i <= a; ++i) 
    for (int j = 0; j <= b; ++j) 
      for (int k = 0; k <= c; ++k) 
        if (i*10 + j*2 + k == x)
          res++;
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}


int main()
{
  string s;
  int n;
  while(cin >> n,n)
  {
    vector<int> dp(n*n,0);
    REP(i,n)
    {
      cin>>s;
      REP(j,n) if(s[j]=='.') dp[i*n+j] = 1;
    }
    FOR(i,1,n-1) FOR(j,1,n-1) if(dp[i*n+j])
      dp[i*n+j]=min({dp[(i-1)*n+j],dp[(i-1)*n+(j-1)],dp[i*n+(j-1)]})+1;
    cout << *max_element(dp.begin(),dp.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 7056
n = gets.to_i
p = gets.chomp.split(" ").map(&:to_i)

count = 0
for j in 1..n-2
  if p[j-1]<p[j] && p[j]<p[j+1]
    count += 1
  elsif p[j-1]>p[j] && p[j]>p[j+1]
    count += 1
  else
    count += 0
  end
end
puts count



Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){
    long int a[100000],s,l=0;
    cin>>s;
    a[0]=s;
    while(1){
        if(a[l]%2==0){
            a[l+1]=a[l]/2;
        }
        else if(a[l]%2!=0){
            a[l+1]=(3*a[l])+1;
        }
        for(int i=0;i<l;i++){
            for(int j=0;j<l;j++){
                if(a[i]==a[j]&&i<j){
                    cout<<j+1<<endl;
                    return 0;
                }
            }
        }
        l++;
    }
    return 0;
}


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

int main(){
  int n; cin >> n;
  int edge[n][n];
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      edge[i][j] = 0;
    }
    int u, k; cin >> u >> k;
    for(int j=0; j<k; j++){
      int v; cin >> v;
      edge[u-1][v-1] = 1;
    }
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<n-1; j++){
      cout << edge[i][j] << " " << flush;
    }
    cout << edge[i][n-1] << endl;
  }
}


Measured memory_bytes: 3140
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	string str;
	cin >> str;
	
	int n = str.length();
	bool f = true;
	
	if (n < 6) f = false;
	
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if ('0' <= str[i] && str[i] <= '9') cnt++;
	}
	if (cnt < 1) f = false;
	
	cnt = 0;
	for (int i = 0; i < n; i++){
		if ('a' <= str[i] && str[i] <= 'z') cnt++;
	}
	if (cnt < 1) f = false;
	
	cnt = 0;
	for (int i = 0; i < n; i++){
		if ('A' <= str[i] && str[i] <= 'Z') cnt++;
	}
	if (cnt < 1) f = false;
	
	if (f){
		cout << "VALID" << endl;
	}
	else {
		cout << "INVALID" << endl;
	}
	
	return 0;
}

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

using namespace std;
int main()
{
	long long n, a, b,mince=1000000000000000000;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		mince = (b - a) / 2;
	}
	else {
		long long fr = min(min(a, b) - 1, n - max(a, b));
		mince = min((n - min(a, b)), (max(a, b) - 1));
		mince-=(mince - fr-1)/2;
	}
	cout << mince;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = set([])

n = [0] * 10 ** 5
ac, wa = 0, 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if p not in a:
        if s == "WA":
            n[p] += 1
        else:
            a.add(p)
            ac += 1
            wa += n[p]
print(ac, wa)

Measured memory_bytes: 12780
#include<iostream>
using namespace std;
int main(){
    long long n , m,k;
    cin >> n >> m >> k;
    
    if(4*n*m<(k-n-m)*(k-n-m) && k > n+m){
        cout << "Yes";
    }else{
        cout << "No";
    }
  return 0;
}


Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc113/tasks/abc113_b"

def main():
    input()
    t, a = list(map(int, input().split()))
    syuto = list(map(int, input().split()))
    tempture = []
    for s in syuto:
        tempture.append(abs(a - (t - s * 0.006)))
    print(tempture.index(min(tempture))+1)


if __name__ == '__main__':
    main()

    

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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a<=b){
        for(int i=0;i<b;i++) cout << a;
    }
    else{
        for(int i=0;i<a;i++) cout << b;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;
vector<int> G[SIZE];
int d[SIZE];
int L;
ll K;

void dfs(int v,int l){
	d[v] = l;
	rep(i,0,G[v].size()){
		int to = G[v][i];
		if(d[to] == -1)dfs(to,l+1);
	}
}

int V,MINV;

void rdfs(int v,int k){
	int minv,m=INF,mi;
	rep(i,0,G[v].size()){
		if(m > d[G[v][i]]){
			m = d[G[v][i]];
			minv = G[v][i];
		}
	}
	if(k+1 == L){ // 切る
		V = v,MINV = minv;
		//vとminvの辺を切る
		rep(i,0,G[v].size()) if(G[v][i]==minv)G[v].erase(G[v].begin()+i);
		rep(i,0,G[minv].size()) if(G[minv][i]==v)G[minv].erase(G[minv].begin()+i);
		return;
	}
	//進む
	rdfs(minv,k+1);
}

bool used[SIZE];

int cnt;

void dfs2(int v){
	used[v] = true;
	cnt++;
	rep(i,0,G[v].size())if(!used[G[v][i]]){
		dfs2(G[v][i]);
	}
}



int main()
{
	cin >> N;
	int a,b;
	rep(i,0,N-1){
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	fill(d,d+N+1,-1);
	dfs(1,0);
	L = (d[N]+1)/2;
	//rep(i,1,N+1)cout << d[i] << endl;
	rdfs(N,0);

	int f,s;
	cnt = 0;
	dfs2(1);
	f = cnt;
	cnt = 0;
	dfs2(N);
	s = cnt;
	if(f > s)puts("Fennec");
	else puts("Snuke");

	return 0;
}


Measured memory_bytes: 10880
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long L = scanner.nextLong();
        long R = scanner.nextLong();

        long N = 2019 *3;

        N = Math.min(L + N, R);

        ArrayList<Long> mods = new ArrayList<>();

        for(long i=L; i<=N; i++){
            mods.add(i % 2019L);
        }

        Collections.sort(mods);

        long ans = Long.MAX_VALUE;

        N = mods.size();

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                ans = Math.min(ans, (mods.get(i) * mods.get(j)) % 2019);
            }
        }


        System.out.println(ans);

    }
}

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int N;
ll dp[100010][3];
ll a[100010][3];

int main() {
  cin >> N;
  rep(i,N)rep(j,3) cin >> a[i][j];
  rep(i,N)rep(j,3)rep(k,3){
    if (j == k) continue;
    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
  }

  ll ans = 0;

  rep(i,3) ans = max(ans, dp[N][i]);

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



Measured memory_bytes: 8304
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  3005
ll dp[N][N];
ll n;
string s;
void solve()
{
	cin>>n;
	cin>>s;
	dp[1][1]=1;
	rep(len,2,n+1)
	{
		rep(i,1,len+1)
		{
			if(s[len-2]=='<')
			{
				dp[len][i]=(dp[len][i]+dp[len-1][i-1])%hell;
			}
			else
			{
				dp[len][i]=(dp[len][i]+dp[len-1][len-1]-dp[len-1][i-1]+hell)%hell;	
			}
		}
		// rep(i,1,len+1)
		// cout<<dp[len][i]<<" ";
		// cout<<endl;
		rep(i,1,len+1)
		dp[len][i]=(dp[len][i-1]+dp[len][i])%hell;
	}
	cout<<dp[n][n]<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 69120
#include<iostream>
using namespace std;
int main(){
  int dp[1001][1001];
  int n,W;
  int v[1000],w[1000];
  int num=0;
  while(cin>> W,W){
    num++;
    cin>> n;
    for(int i=0;i<W+1;i++){
      dp[0][i]=0;
    }

    for(int i=0;i<n;i++){
      char c;
      cin>> v[i]>> c>> w[i];
    }

    for(int i=1;i<=n;i++){
      for(int j=1;j<=W;j++){
	if(j<w[i-1]){
	  dp[i][j]=dp[i-1][j];
	}else{
	  dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
	}
      }
    }

    int mv=0,mw;
    for(int j=0;j<=W;j++){
      if(mv<dp[n][j]){
	mv=dp[n][j];
	mw=j;
      }
    }
    /*for(int i=0;i<=n;i++){
      for(int j=0;j<=W;j++){
	cout<< dp[i][j];
      }
      cout<< endl<< endl;
    }
    */
    cout<< "Case "<< num<< ":"<< endl;
    cout<< mv<< endl;
    cout<< mw<< endl;
  }
}

Measured memory_bytes: 5080
(n, a) = list(map(int, input().split()))
x = list(map(int, input().split()))
plus = []
minus = []
zero = 0
for i in range(n):
    x[i] -= a
    if x[i] > 0:
        plus.append(x[i])
    elif x[i] < 0:
        minus.append(x[i])
    else:
        zero += 1


map_plus = {}
map_minus = {}

for i in plus:
    tmp_map = map_plus.copy()
    if i in map_plus:
        tmp_map[i] += 1
    else:
        tmp_map[i] = 1
    for j in map_plus:
        if j + i in map_plus:
            tmp_map[j + i] += map_plus[j]
        else:
            tmp_map[j + i] = map_plus[j]
    map_plus = tmp_map

for i in minus:
    tmp_map = map_minus.copy()
    if i in map_minus:
        tmp_map[i] += 1
    else:
        tmp_map[i] = 1
    for j in map_minus:
        if j + i in map_minus:
            tmp_map[j + i] += map_minus[j]
        else:
            tmp_map[j + i] = map_minus[j]
    map_minus = tmp_map

count = 1
for i in map_minus:
    if i * -1 in map_plus:
        count += map_minus[i] * map_plus[i * -1]

print(count * 2 ** zero - 1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a; cin >> a;
  vector<int> p(a);
  int money=0;
  int x=0;
  for (int i=0;i<a;i++) {
    cin >> p[i];
   x=max(x,p[i]);
  }
  for(int i=0;i<a;i++) {
    money+=p[i];
  }
  money-=x/2;
  cout << money << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string s,t;
    cin>>s>>t;
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << '\n';
  return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.size() > k)
    {
        for (int i = 0; i < k; i++)
        {
            cout << s[i];
        }
        cout << "...\n";
    }
    else
    {
        cout << s << "\n";
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

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

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

using namespace std;

int n;
string w[50];
int limit[] = {5,7,5,7,7};

int main() {
  while( cin >> n, n ) {
    rep(i,n) cin >> w[i];
    rep(i,n) {
      int index = 0;
      int sum = 0;
      REP(j,i,n) {
	sum += (int)w[j].size();
	if( sum == limit[index] ) {
	  ++index;
	  sum = 0;
	  if( index >= 5 ) {
	    cout << i+1 << endl;
	    goto Fin;
	  }
	} else if( sum > limit[index] ) {
	  break;
	}
      }
    }
    Fin:;
  }
  return 0;
}

Measured memory_bytes: 1208