akhauriyash/Code-Regression huggingface dataset:
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
   



int main(){
   IOS

   int n, T;
   cin>>n>>T;

   vector<pii> a(n);
   for(int i = 0; i < n; i++){
      cin>>a[i].first>>a[i].second;
   }
   sort(all(a));

   vi dp((int)1e4);

   
   for(int i = 0; i < n; i++){
      for(int time = T - 1; time >= 0; time--){
         int A = a[i].first;
         int B = a[i].second;
         dp[time + A] = max(dp[time + A], dp[time] + B);
      }
   }

   int mx = 0;
   for(int v : dp){
      mx = max(mx, v);
   }

   cout<<mx<<"\n";
   







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
   if(b&1) res = res * a % mod;
        a = a * a % mod;
   b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;

int main(){
    int n;
    cin >>n;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    ll U = 0;
    rep(i,n) U+=a[i];

    vector<ll> pre(a);
    rep(i,n-1) pre[i+1] += pre[i];

    vector<ll> pq(n);
    for(int i=1; i<n; ++i){

        auto itr = lower_bound(all(pre),(pre[i]+1)/2);
        pq[i] = *itr;

        if(itr != pre.begin()){
            --itr;
            ll P = *itr;
            ll Q = pre[i]-P;

            if(abs(P-Q)< abs(pq[i]-(pre[i]-pq[i]))) pq[i] = P;
        }
    }
    // dbg(pq);

    vector<ll> suf(a);
    for(int i=n-1; i>0; --i) suf[i-1] += suf[i];
    reverse(all(suf));
    // dbg(suf);
    vector<ll> rs(n);
    for(int i=1; i<n; ++i){

        auto itr = lower_bound(all(suf),(suf[i]+1)/2);
        rs[i] = *itr;

        if(itr != suf.begin()){
            --itr;
            ll P = *itr;
            ll Q = suf[i]-P;

            if(abs(P-Q)< abs(rs[i]-(suf[i]-rs[i]))) rs[i] = P;
        }
    }
    reverse(all(rs));
    // dbg(rs);

    ll ans = INF;
    for(int i=2; i<=n-2; ++i){
        ll P = pq[i-1];
        ll Q = pre[i-1]-P;
        ll S = rs[i];
        ll R = U-P-Q-S;

        // printf(" %lld %lld %lld %lld\n",P,Q,R,S);
        ans = min(ans, max({P,Q,R,S})-min({P,Q,R,S}));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8064
x = range(int(input()))
P =[]
s = 0
for i in x:P += [[int(i) for i in input().split()]]
P+=[P[0]]
for i in x:s += P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]
print(s*0.5)

Measured memory_bytes: 7728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll D, T, S;
    cin >> D >> T >> S;
    if((D+S-1)/S <= T){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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


int main()
{
    int n, c1, c2;
    int p1, p2;
    while(std::cin >> n){
        if(n == 0){
            break; 
        }
        p1 = 0;
        p2 = 0;

        for(int i = 0; i < n; ++i){
            std::cin >> c1 >> c2;
            if(c1 == c2){
                p1 += c1;
                p2 += c2;
            }
            else if(c1 > c2){
                p1 += c1 + c2; 
            }
            else {
                p2 += c1 + c2;
            }
        } 
        std::cout << p1 << " " << p2 << std::endl;
    }
}

Measured memory_bytes: 1160
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()




dp = [0]*(k-2)+[1]+[0]
m = 1
while True:
    a = int((k-0.1)//(2**m))
    if a < 1:
        break
    dp[a-1] += 1
    m += 1

b = 0
for i in range(k)[::-1]:
    b += dp[i]
    dp[i] = b

if k == 1:
    dp = [0]

ans = 0
for j in range(n):
    if j < k:
        ans += 1/(2**dp[j])
    else:
        ans += 1

print(ans/n)

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


int main()
{
		ll n ;
		cin >> n ;
		if (n % 11 == 0 ) cout << (n/11)*2 ;
		else
		if ( n % 11 <= 6  ) cout << (n/11)*2 + 1 ;
		else
			cout << (n/11)*2 + 2 ;
		return  0 ;
}


Measured memory_bytes: 256
n,m = map(int,input().split(" "))
if n == 1:
    a,b = 0,10
if n == 2:
    a,b = 10,100
if n == 3:
    a,b = 100,1000
ar = []
for i in range(m):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for i in range(a,b):
    j = str(i)
    count = 0
    for r in ar:
        if j[r[0]-1] != str(r[1]):
            count += 1
            break
    if count == 0:
        print(j)
        exit()
print(-1)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int func(char ch, string s)
{
	char ary[100];
	int len = s.length();
	REP(i, len)
	{
		ary[i] = s.at(i);
	}

	int cnt = 0;
	while (true)
	{
		bool comp = true;
		for (int i = 0; i < len; i++)
		{
			if (ary[i] != ch)
			{
				comp = false;
				break;
			}
		}
		if (comp) break;
		cnt++;

		for (int i = 0; i < len - 1; i++)
		{
			if (ary[i] == ch || ary[i + 1] == ch)
			{
				ary[i] = ch;
			}
			else
			{
				ary[i] = ary[i];
			}
		}
		len--;
	}

	return cnt;
}

signed main()
{
	string s;
	cin >> s;

	int ary[26] = { 0 };

	REP(i, s.length())
	{
		int n = s.at(i) - 'a';
		ary[n]++;
	}

	int min = INT_MAX;
	REP(i, 26)
	{
		if (ary[i] > 0)
		{
			int n = func(i + 'a', s);
			min = MIN(min, n);
		}
	}

	cout << min << endl;
}

Measured memory_bytes: 256
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	S := sc.nextStr()

	if S == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  int a, b, c;

  cin >> a >> b >> c;

  auto n = b / a;
  if (n > c) {
    cout << c << endl;
  } else {
    cout << n << endl;
  }

  return 0;
}


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

using namespace std;

int main() {

    int n, k;
    cin >> n;
    cin >> k;

    int vec[n];
    for(int i=0; i<n; i++)
    {
        int h;
        cin >> h;
        vec[i] = h;
    }

    std::sort(vec, vec + n);

    int ans = 1000000000;
    for(int i=0; i<=n-k; i++)
    {
        ans = min(ans, abs(vec[i+k-1] - vec[i]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
s=require("fs").readFileSync("/dev/stdin","utf8").split('\n')
a = [...Array(s[0] | 0)].map((_, i) => s[i + 1] | 0)
m = Math.max(...a)
console.log(a.map((n, i) => m == n ? m /= 2 : n).reduce((c, n) => c + n))


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

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


	return 0;

}


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

double cross(complex<double> A, complex<double> B){
	return (conj(A)*B).imag();
}

int main(){
	complex<double> Points[3], P;
	while(1){
		double x, y;
		for(int i=0; i<3; i++){
			cin >> x >> y;
			Points[i] = {x, y};
		}
		cin >> x >> y;
		P = {x, y};

		if(!cin)break;

		int sum = 0;
		for(int i=0; i<3; i++){
			sum += cross(Points[(i+1)%3]-Points[i], (P-Points[i])) > 0;
		}
		cout << (sum==0 || sum==3? "YES":"NO") << endl;
	}
	return 0;
}


Measured memory_bytes: 3144
N = int(input())

num_list = []

def pushback(x):
    num_list.append(x)
    
def randomAccess(p):
    print(num_list[p])
    
def popBack():
    num_list.pop()
    
for i in range(N):
    input_num = input().split()
    if input_num[0] == "0":
        pushback(input_num[1])
    elif input_num[0] == "1":
        randomAccess(int(input_num[1]))
    else:
        popBack()


Measured memory_bytes: 19820
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

enum K = 1_000_000_007;

void main() {

    const tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1];

    if (M == 1) {
        writeln(1);
        return;
    }

    const primes = primeFactorize(M);

    const po = primes.values.reduce!max + 1;

    long[][] combiTable = new long[][](N+po,po);
    foreach (i; 0..N+po) {
        foreach (j; 0..po) {
            if (i < j) continue;
            if (j == 0) {
                combiTable[i][j] = 1;
                continue;
            }
            combiTable[i][j] = (combiTable[i-1][j] + combiTable[i-1][j-1]) % K;
        }
    }

    primes.values.map!(c => combiTable[c + N - 1][c] % K).reduce!((a,b) => a * b % K).writeln;
}

long[long] primeFactorize(long x) {
    if (x == 1) return typeof(return).init;
    auto y = 2;
    while (y <= x) {
        if (x % y == 0) {
            auto po = memoize!primeFactorize(x/y);
            po[y]++;
            return po;
        }
        y++;
    }
    assert(false);
}


Measured memory_bytes: 29308
#083c
import sys

A,B,C,D,E,F = map(int, input().split())
#水*100、水*100、砂糖、砂糖

#合計はF以下、溶け残りはダメ
#水100に対してE溶ける → 100E/(100+E) が最大値

#砂糖水の濃度は 100b/(a+b)
#水a,砂糖b

max_conc = 0
total_weight_at_max_conc = 100*A
sugar_weight_at_max_conc = 0

for h in range(0, 1+int(F/(100*A))): #F<=3000,1<=Aより 最大30回ループ
    limit_water = F - (h*100*A)
    
    for i in range(0, 1+int(limit_water/(100*B))):
        limit_total_sugar_by_weight = F - (h*100*A + i*100*B)
        limit_total_sugar_by_conc = (h*100*A + i*100*B)/100*E
        limit_total_sugar = min(limit_total_sugar_by_weight,limit_total_sugar_by_conc)
            
        for j in range(0, 1+int(limit_total_sugar/C)):
            limit_D_sugar_by_weight = F - (h*100*A + i*100*B + j*C)
            limit_D_sugar_by_conc = (h*100*A + i*100*B)/100*E - j*C
            limit_D_sugar = min(limit_D_sugar_by_weight,limit_D_sugar_by_conc) 
            
            k = int(limit_D_sugar/D) #濃度を濃くするために操作Dは限界まで行う。
            
            if h>=0 and i>=0 and j>=0 and k>=0:
                a = h*100*A + i*100*B
                b = j*C + k*D
                total_weight = a + b
                
                #print(h,i,j,k)
                #print(a,b)
                
                if a + b != 0:
                    concentration = 100*b/(a+b)

                    if concentration > max_conc:
                        max_conc = concentration
                        total_weight_at_max_conc = total_weight
                        sugar_weight_at_max_conc = b

                        if max_conc == 100*E/(100+E):
                            print(total_weight_at_max_conc,sugar_weight_at_max_conc)
                            sys.exit()

print(total_weight_at_max_conc,sugar_weight_at_max_conc)

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){

	int X;
	cin >> X;
	if(X == 3 || X == 5 || X == 7) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

#define ff first
#define ss second
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define endl "\n"      // Comment in INTERACTIVE(there just use endl which flushes output , no need of fflush(sdtout)).
//  for counting setbits -> __builtin_popcountll(x)
// for counting zerobits -> __builtin_ctzll(x)
#define fastio() ios_base::sync_with_stdio(false);        cin.tie(NULL); //(unties i/o buffer).
            // DON'T USE SCANF/PRINTF WITH IT (c/c++ -> seperates buffer).

const int mod = 1000000007;
const int inf = 1000000009;
 const int N = (1e5) + 2;
 int arr[N][4];
 int dp[N][4];

int32_t main(){
    fastio();

    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    // #endif

     // ***** AC_chahiye EK BAR MEIN

     // BEGIN CODE HERE
    int n ;
    cin>>n;
    for(int i = 1;i <= n; ++i){
        cin>>arr[i][1]>>arr[i][2]>>arr[i][3];
    }
    dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
    for(int i = 1;i <= n; ++i){
        for(int j = 1;j <= 3 ; ++j){
            int mx = 0;
            for(int k = 1;k <= 3; ++k){
                if(j != k)
                    mx = max(mx,dp[i - 1][k]);
            }
            dp[i][j] = mx + arr[i][j];
        }
    }
    cout<<max({dp[n][1],dp[n][2],dp[n][3]});
    //getch();
}


Measured memory_bytes: 3328
N = int(input())

edges = [ list(map(int, input().split())) for _ in range(N) ]

for cx in range(101):
  for cy in range(101):

    for i in range(N):
      x, y, h = map(int, edges[i])
      if h > 0:
        htop = abs(x-cx) + abs(y-cy) + h

    for i in range(N):
      x, y, h = map(int, edges[i])
      if h == 0:
        if htop - (abs(x-cx) + abs(y-cy)) > 0:
          break
      if h > 0:
        if htop - (abs(x-cx) + abs(y-cy)) != h:
          break
    else:
      print(cx, cy, htop)
      exit()

Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
 
public static void main(String[] args){
 
Scanner x = new Scanner(System.in);
 
int num=x.nextInt();
int length=x.nextInt();
 
String[] arr = new String[num];
 
for(int i = 0;i<num;i++){
arr[i]=x.next();
}
Arrays.sort(arr);
String result="";
for(int i = 0;i<num;i++){
result += arr[i];
}
 
System.out.print(result);
}
 
}

Measured memory_bytes: 13776
#!/usr/bin/env python

n = int(input())
a = list(map(int, input().split()))

n2 = 0 
n4 = 0 
for i in range(n):
    if a[i]%4 == 0:
        n4 += 1
    elif a[i]%2 == 0:
        n2 += 1

ok = True
if n2 == 0:
    if n4 >= n//2:
        ok = True
    else:
        ok = False
else:
    n1 = n-n2-n4
    n1 += 1
    nn = n1+n4
    if n4 >= nn//2:
        ok = True
    else:
        ok = False

if ok: 
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20056
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else {
            if (a < c) {
                    System.out.printf("%d %d %d\n", a, c, b);
                }else{
                System.out.printf("%d %d %d\n", c, a, b);
            }
            }
        } else if (b < a) {
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else {
                if (b < c) {
                    System.out.printf("%d %d %d\n", b, c, a);
                }else {
                    System.out.printf("%d %d %d\n", c, b, a);
                }
            }
        }
    }
}





Measured memory_bytes: 26428
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()

def mdiv(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:

            divisors.append(i)
            if i!=n//i:

                divisors.append(n//i)
    return divisors
#print(mdiv(m))

ans=0
for i in mdiv(m):
    if i<=m//n:
        ans=max(i,ans)
print(ans)

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

int a[100005][4];
int dp[100005][4];
int n;

int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}


/*
void bottomup(){
	int n; cin >> n;	
	vector<int> dp(3);
	
	for(int day=0; day<n; day++){
		vector<int> a(3);
		vector<int> new_dp(3, 0);
		
		for(int i=0; i<n; i++)
			cin >> a[i];
		
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++) {
				if(i!=j) {
					new_dp[j]=max(new_dp[j], dp[i]+a[j]);
				}
			}
		}
		dp = new_dp;	
	}
	cout << max({dp[0], dp[1], dp[2]}) << "\n";
}
*/

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
}

int main(){
//	bottomup();
	solve();
}

Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll func(vvl &G, vector<bool> &used, ll M, ll s) {
  ll c = 0;
  if (s == M)
    c++;
  used[s] = true;
  AUTO(g, G[s]) {
    if (!used[g]) {
      used[g] = true;
      c += func(G, used, M, g);
      if (g >= M)
        c++;
    }
  }
  return c;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vvl G(N + M);
  vector<bool> used(N + M, false);
  REP(i, N) {
    ll k;
    cin >> k;
    REP(j, k) {
      ll l;
      cin >> l;
      l--;
      G[l].push_back(i + M);
      G[i + M].push_back(l);
    }
  }
  // cout << func(G, used, M, M) << endl;
  if (func(G, used, M, M) == N)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    if(n >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 256
void main()
{
    long a, b, c, d;
    rdVals(a, b, c, d);

    long x = abs(a-c), y = abs(b-d);
    long g = gcd(x, y);
    long result = x + y - g;

    result.writeln;
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
using System;
using System.Linq;

namespace DDCC2020
{
    class B
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long[] S = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                S[i + 1] = S[i] + A[i];
            }

            long res = long.MaxValue;
            for (int i = 0; i < N + 1; i++)
            {
                long L = S[i];
                long R = S[N] - S[i];

                res = Math.Min(res, Math.Abs(L - R));
            }
            Console.WriteLine(res);
        }
    }
}


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

namespace ConsoleApp11
{
    class Class50
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = I[0];
            int Y = I[1];
            int count;
            for(int i = 0; i <= N; i++)
            {
                for(int j = 0; j <= N-i; j++)
                {
                    for(int k = N - i - j; k <= N - i - j; k++)
                    {
                        count = 10000 * i + 5000 * j + 1000 * k;
                        if (count == Y) { Console.WriteLine($"{i} {j} {k}");return; }
                    }
                }
            }
            Console.WriteLine($"-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13396
fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };
    let n = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let abs_max = (0..n)
        .map(|i| (a[i].abs(), i))
        .max()
        .map(|(_, i)| i)
        .unwrap();
    let mut b: Vec<i64> = a.iter().map(|&ai| ai + a[abs_max]).collect();

    let all_positive = b.iter().all(|&x| x >= 0);
    println!("{}", 2 * n - 1);
    for i in 0..n {
        println!("{} {}", abs_max + 1, i + 1);
    }
    if all_positive {
        for i in 1..n {
            println!("{} {}", i, i + 1);
            b[i] += b[i - 1];
        }
    } else {
        for i in (1..n).rev() {
            println!("{} {}", i + 1, i);
            b[i - 1] += b[i];
        }
    }
    // eprintln!("{:?}", b);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
a=input()
x=int(a[0]+a[1])
y=int(a[2]+a[3])
if 0<x<13 and 0<y<13:
    print("AMBIGUOUS")
elif 0<x<13 and (y>12 or y==0):
    print("MMYY")
elif (x>12 or x==0) and 0<y<13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
while True:

    N = int(input())
    ans = []

    if N == 0:
        break

    for i in range(N):

        L,P,A,B,C,D,E,F,S,M = input().split()
        P = int(P)
        A = int(A)
        B = int(B)
        C = int(C)
        D = int(D)
        E = int(E)
        F = int(F)
        S = int(S)
        M = int(M)

        time = A+B+C+(D+E)*M
        mon = S * M * F - P

        ans.append([-1 * (mon/time),L])

    ans.sort()

    for i in range(N):
        print (ans[i][1])
    print ("#")

        



Measured memory_bytes: 5624
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    private final static String SPACE = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = 
                    new BufferedReader( new InputStreamReader(System.in));

            String sStr;
            int i=1;
            while ( (sStr  = stdReader.readLine()) != null) {
                int input=Integer.valueOf(sStr);
                if (input==0) {
                    // nothing to do..
                    break;
                } else {
                    System.out.println("Case" + SPACE + i + ":" + SPACE + input  );
                }
                ++i;
            }

            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        } 
    }
}

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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
void printv(vector<T> v)
{
    for (T t : v)
    {
        cout << t << " ";
    }
    cout << '\n';
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;
    vector<pii> p;
    REP(i, N)
    {
        int x, y;
        cin >> x >> y;
        pii t = {x, y};
        p.emplace_back(t);
    }

    int ans = N+1;
    map<pii, int> m;
    REP(i, N)
    {
        int nx = p[i].first;
        int ny = p[i].second;

        REP(j, N)
        {
            if (i == j) continue;
            
            pii t = {(nx-p[j].first),(ny-p[j].second)};
            m[t]++;
        }

        int max_num = 0;
        for (auto x : m) {
            max_num = max(max_num,x.second);
            //cout << i << ": "<< x.second << ": " << x.first.first << "," << x.first.second << endl;
        }

        ans = min(ans,N-max_num);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> road(n);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    road[a-1].push_back(b-1);
    road[b-1].push_back(a-1);
  }
  vector<int> dist(n, -1);
  vector<int> flag(n);
  queue<int> que;
  dist[0] = 0;
  que.push(0);
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(int next_v: road[v]) {
      if(dist[next_v] != -1) { continue; }
      dist[next_v] = dist[v] + 1;
      flag[next_v] = v;
      que.push(next_v);
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++) {
    cout << flag[i]+1 << endl;
  }
}

Measured memory_bytes: 10608
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define ins insert
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll ans,n;
set <ll> s;
set <ll>::iterator it;

inline bool jud(ll x)
{
	ll p=n;
	while(p%x==0)
	{
		ll p2=p/x;
		if(p2%x==1) return true;
		p=p/x;
	}
	return false;
}

int main()
{
	cin>>n; ans=1; s.ins(n);
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(jud(i)) s.ins(i);
			if(i*i!=n&&jud(n/i)) s.ins(n/i);
		}
	}
	for(ll i=1;i*i<=(n-1);i++)
	{
		if((n-1)%i==0)
		{
			if(n%i!=0) s.ins(i);
			if(i*i!=(n-1)&&n%((n-1)/i)!=0) s.ins((n-1)/i);
		}
	}
	it=s.end(); it--;
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int n;
vector< pair<int, int> > input;

int dfs(int* p) {
  int t = input[*p].first + 1;
  char e = (char) input[*p].second;
  int ans = e == '+' ? 0 : e == '*' ? 1 : e;
  for((*p)++; input[*p].first >= t && *p < n;) if(e == '+') ans += dfs(p); else ans *= dfs(p);
  return ans;
}

int main(void) {
  while(cin >> n, n != 0) {
    input.clear();
    REP(i, 0, n) {
      string line; cin >> line;
      int level = 0;
      for(; line[level] == '.'; level++);
      input.push_back(pair<int, int>(level, line[level] == '+' || line[level] == '*' ? line[level] : line[level] - '0'));
    }
    int i = 0;
    cout << dfs(&i) << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
n, m, L = map(int, input().split())
  
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[sum(aaa * bk for aaa, bk in zip(ar,bbb)) for bbb in zip(*b)] for ar in a]
  
for ccc in c:
    print(*ccc)

Measured memory_bytes: 9056
import java.io.*
import java.util.*

fun solve(N: Long){
    println(N*(N-1)/2)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



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

int main(){
  long long int n;
  cin >> n;
  
  if(n%2==0){
    long long int k=0;
    long long int i=10;
    while(i<=n){
      k+=n/i;
      i*=5;
    }
    cout << k << endl;
  }
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
#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);

	long long N, D;
	cin >> N >> D;

	D *= D;
	int result = 0;

	for (int i = 0; i < N; i++)
	{
		long long X, Y;
		cin >> X >> Y;

		X *= X;
		Y *= Y;

		if (X + Y <= D)
		{
			result++;
		}
	}

	cout << result;

	return 0;
}


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

int main() {
    string s; cin >> s;
    stack <ll> st;
    rep(i, s.size()) {
        if (s.at(i) == '0') st.push(0);
        else if (s.at(i) == '1') st.push(1);
        else if (st.size()) st.pop();
    }
    vector <ll> v;
    ll n = st.size();
    rep(i, n) {
        v.push_back(st.top()); st.pop();
    }
    rep(i, v.size()) cout << v.at(v.size()-1-i);
    cout << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=10000005,M=998244353;
int n,A,B,fac[N],inv[N];
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
int f(int x,int y){
	if (x==0&&y==0)return 1;
	if (y>x)return 0;
	return (C(x+y,y)-C(x+y,y-1)+M)%M;
}
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;
}
signed main(){
	scanf("%lld%lld%lld",&n,&A,&B);
	int ans=0;
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M;
	inv[N-1]=ksm(fac[N-1],M-2);
	for (int i=N-2;i;i--)inv[i]=inv[i+1]*(i+1)%M;
	if (A==0&&B==0){
		puts("1");
		return 0;
	}
	for (int k=0;k<B&&n-B-k-1>=0&&A-k>=0;k++)(ans+=C(A-k+n-B-k-1,n-B-k-1)*f(B-1,k)%M)%=M;
	if (n==A+B)(ans+=f(B-1,A))%=M;
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
  ll k; string s; cin >> k >> s;
  string h;
  for(ll i = 0; i<k; i++){
    h+=s[i];
  }
  if(s.size()<=k) cout << s << endl;
  else cout << h << "..." << endl;
    
  return 0;
}






Measured memory_bytes: 3632
def modpow(a, n, mod):
    if n == 0:
        return 1
    else:
        if n % 2 == 0:
            return (modpow((a * a)%mod, n//2, mod)) % mod
        else:
            return ((a%mod) * modpow(a, n-1, mod)) % mod

# modが素であるとする
def modinv(a, mod):
    return modpow(a, mod-2, mod) % mod

def moddiv(a, b, mod):
    return ((a%mod) * modinv(b, mod)) % mod

# nがある程度小さい時(10^7程度)
def modcombination(n, k, mod):
    fact = [1 for _ in range(n+1)]
    inv = [1 for _ in range(n+1)]
    finv = [1 for _ in range(n+1)]

    for i in range(2, n+1):
        fact[i] = (fact[i-1] * i) % mod
        inv[i] = (-inv[mod % i] * (mod // i)) % mod
        finv[i] = (finv[i-1] * inv[i]) % mod
    return fact[n] * (finv[k] * finv[n-k] % mod) % mod

# kが小さい時
def modcombination_smallk(n, k, mod):
    result = 1
    for i in range(k):
        result = (((result * (n-i))%mod) * modinv(i+1, mod))%mod
    return result

n, a, b = [int(i) for i in input().split()]
mod = (10**9)+7
# 全部でn**2(0本は除くかも)
# a本を選ぶ場合の数はnCa
total = modpow(2, n, mod)
tota = modcombination_smallk(n, a, mod)
totb = modcombination_smallk(n, b, mod) 
print((total-tota-totb-1)%mod)

Measured memory_bytes: 77644
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;
 
const int mn=1e6+69;
vector<set<int> > kg(mn);
vector<int> inf(mn);
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int pom=n%1000;
	if(pom==0) cout<<0<<endl;
	else cout<<1000-pom;
}

Measured memory_bytes: 54100
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String S = in.next();
            int A = S.charAt(0) - '0';
            int B = S.charAt(1) - '0';
            int C = S.charAt(2) - '0';
            int D = S.charAt(3) - '0';

            for (int op1 = -1; op1 <= 1; op1 += 2) {
                for (int op2 = -1; op2 <= 1; op2 += 2) {
                    for (int op3 = -1; op3 <= 1; op3 += 2) {
                        if (A + op1 * B + op2 * C + op3 * D == 7) {
                            System.out.println("" + A + (op1 == 1 ? "+" : "-") + B + (op2 == 1 ? "+" : "-") + C + (op3 == 1 ? "+" : "-") + D + "=7");
                            return;
                        }
                    }
                }
            }

        }
    }
}


Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int k,a;
string s;
cin>>k>>s;
a=s.length();
if (a<=k)
{
    cout<<s<<endl;  
}
else
{
    for (int i = 0; i < k; i++)
    {

            cout<<s[i];

    }
    cout<<"..."<<endl;
}

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	if(n%2==0)n--;
	n/=2;
	cout<<n<<endl;
	
	return 0;
}

Measured memory_bytes: 3644
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int a, b;
    cin >> a >> b;

    for (int i = 0; i <= 10000; i++) {
        int x = 8 * i;
        int y = 10 * i;
        if (x / 100 == a && y / 100 == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int main() {
    int n; cin >> n;
    int m = 1<<n;
    multiset<int> ss;
    rep(i, m) {
        int in; cin >> in;
        ss.insert(-in);
    }
    vector<int> v { *ss.begin() };
    ss.erase(ss.begin());
    rep(i, n) {
        for (int j=0; j<(1<<i); ++j) {
            auto it = ss.upper_bound(v[j]); // 引数より大きい最初の要素のイテレータ
            if (it==ss.end()) {
                cout << "No" << endl;
                return 0;
            }
            v.push_back(*it);
            ss.erase(it);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int a,b,count=0;
  cin>>a>>b;
 int c[5];
  for(int i=a;i<=b;i++){
  	c[0]=i/10000,c[4]=i%10;  
  	if(c[0]!=c[4]) continue;
    c[1]=i%10000/1000,c[3]=i%100/10;
    if(c[1]==c[3]) count++;
  }
  cout<<count<<endl;
}

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

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

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

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

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

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

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

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

use std::collections::HashMap;
fn main() {
    input!{
        n: usize,
        a: [i64; n],
    };
    let mut map = HashMap::new();
    for v in a{
        *map.entry(v).or_insert(0) += 1;
        *map.entry(v-1).or_insert(0) += 1;
        *map.entry(v+1).or_insert(0) += 1;
    }

    println!(
        "{}",
        map
        .values()
        .max()
        .unwrap()
    );
}


Measured memory_bytes: 14588