akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-


from copy import deepcopy

def main():
  n, k = map(int, input().split())
  xs   = list(map(int, input().split()))
  k_bin = list(bin(k)[2:])
  keta = len(k_bin)
  li = []
  _xs = deepcopy(xs)
  for i in range(keta):

    tmp = []
    count = 0
    for x in _xs:
      if x%2 == 1:
        count += 1
        tmp += [int((x-1)/2)]
      else:
        tmp += [int((x)/2)]
    _xs = tmp

    li += ['0' if count >= n/2 else '1']
  li = li[::-1]

  ans_picklist = []
  for i in range(keta):
    if k_bin[i] == '0':
      continue
    kouho = int('0b' + ''.join(k_bin[:i]) + '0' + ''.join(li[i+1:]), 0)
    ans_picklist += [(kouho, sum([kouho^x for x in xs]))]
  kouho = int('0b'+''.join(k_bin), 0)
  ans_picklist += [(kouho, sum([kouho^x for x in xs]))]
  ans_picklist.sort(key=lambda x:x[1])
  print(ans_picklist[-1][1])


if __name__=='__main__':
  main()

Measured memory_bytes: 16372
function main(input) {
    const nums = input.split(" ");
    var count5 = 0, count7 = 0;
    
    nums.forEach( num => {
        if(num == 5) {
            count5 += 1;
        }
        if(num == 7) {
            count7 += 1;
        }
    })
    console.log(count5 == 2 && count7 == 1 ? "YES" : "NO");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
# abc132_a.py
# https://atcoder.jp/contests/abc132/tasks/abc132_a

# A - Fifty-Fifty /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 長さ 4の英大文字からなる文字列 S が与えられます。 
# S がちょうど 2 種類の文字からなり、かつ現れる各文字はちょうど 2回ずつ現れているかどうかを判定してください。

# 制約
#     Sの長さは 4である
#     Sは英大文字からなる

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S

# 出力
# Sがちょうど 2 種類の文字からなり、かつ現れる各文字はちょうど 2回ずつ現れているなら Yes を、そうでないなら No を出力せよ。

# 入力例 1
# ASSA

# 出力例 1
# Yes

# Sは A と S からなり、A と S はそれぞれ 2回ずつ現れます。

# 入力例 2
# STOP

# 出力例 2
# No

# 入力例 3
# FFEE

# 出力例 3
# Yes

# 入力例 4
# FREE

# 出力例 4
# No


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[0]
    # N = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    values = list()
    for i in range(4):
        values.append(S[i])

    values.sort()

    result = 'Yes'
    if values[0] != values[1]:
        result = 'No'
    if values[1] == values[2]:
        result = 'No'
    if values[2] != values[3]:
        result = 'No'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['ASSA']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['STOP']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['FFEE']
        lines_export = ['Yes']
    if pattern == 4:
        lines_input = ['FREE']
        lines_export = ['No']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#include <iostream>
#include <string>
#include <locale>
#include <algorithm>
#include <cctype>
#include <math.h>
#include <cstring>
#include <stdio.h>
#include <vector>
#include <bits/stdc++.h>
#include <sstream>

using namespace std;


main(){
    int n, k;
    string s;

    cin >> n >> s >> k;

    for (int i = 0; i<n; i++){
        if(s[i] != s[k-1]) s[i] = '*';
    }

    cout << s;

}

/*

    for (int i = 0; i<n; i++){

    }

*/


Measured memory_bytes: 764
/***************************************** START OF TEMPLATE *********************************************/
#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  newl           cout<<"\n";
#define  f              first
#define  s              second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)         s="#"+s+"#";
#define  sqr(v)         v*v;
#define  all(x)         (x).begin(),(x).end()
#define  alll(x, n)     x+1, x+n+1
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  mset1d(a,n,v)  foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v)foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  INP(a,n)       foo(i,1,n) cin>>a[i];
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    
#define  debm(a)        for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  debp(a,n)      foo(i,1,n)cout<<"{"<<a[i].f<<","<<a[i].s<<"}, ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b;newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c;newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll a[10]={8,7,6,5,4,3,2,1,0,0};


/***************************************** FUNCTION IMPLEMENTATIONS **************************************/



/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    int x;  
    cin>>x;
    cout<<a[(x-400)/200];
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
    MAIN(i);
    }
}

Measured memory_bytes: 8340
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int h, w;
	cin >> h >> w;

	char grid[h][w];

	forn(i,h) forn(j,w) cin >> grid[i][j];

	ll dp[h+1][w+1];
	forn(i,h+1) forn(j,w+1) dp[i][j] = 0;

	dp[0][1] = 1;
	dp[1][1] = 1;

	forn(i,h) forn(j,w){
		if(grid[i][j] == '.') dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1])%MOD;
	}

	cout << dp[h][w];



}


Measured memory_bytes: 9088
#include <stdio.h>
#include <math.h>


int main(){


  double a,b,C,S,L,h,d;

 scanf("%lf%lf%lf",&a,&b,&C);

 d = (acos(-1.0)*C)/180.0;
 S = a*b*sin(d)/2.0;
 L = a+b+sqrt(a*a+b*b-2*a*b*cos(d));
 h = b*sin(d);

 

 printf("%lf\n%lf\n%lf\n",S,L,h);

 return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int a = 0;
    for (int i = 9; i > 0; i--) {
      if (N % i == 0) {
        a = N / i;
        break;
      }
    }
    if (a == 0) {
      System.out.println("No");
      return;
    }
    int b = 0;
    for (int i = 9; i > 0; i--) {
      if (a % i == 0) {
        b = a / i;
        break;
      }
    }
    if (b == 1) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}


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

int main(){
    
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i=0; i<n; i++){
        cin >> t.at(i);
    }
    sort(t.begin(),t.end());

    int bus=1;
    int count=0;
    int time=t.at(0);
    for(int i=0; i<n; i++){
//        cout << t.at(i) << ' ' << time << endl;
        if(count==c || (t.at(i)-time) >k){
            bus++;
            time=t.at(i);
            count=1;
        }
        else count++;
    }
    cout << bus << endl;
}

Measured memory_bytes: 3788
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, A[110], cnt = 0;

void print(int n, int A[]) {
    REP(i, n) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
}

void bubbleSort(int n, int A[]) {
    int flag = 1;
    while (flag) {
        flag = 0;
        for (int j = n - 1; j > 0; j--) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                cnt++;
            }
        }
    }
    print(n, A);
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    bubbleSort(n, A);
}


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

using namespace std;

typedef long long ll;

const int maxn=1e2+5;

vector<pair<int,int> > a[maxn];
int n;

int check(int x){
	for(int i=1;i<=n;i++){
		for(auto it:a[i]){
			if((1<<i-1)&x){
				if(it.second==0){
					if((1<<it.first-1)&x) return 0;
				}
				else{
					if(((1<<it.first-1)&x)==0) return 0;
				}
			}
		}
	}
	return 1;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		for(int j=0;j<t;j++){
			int x,y;
			scanf("%d%d",&x,&y);
			a[i].push_back({x,y});
		}
	} 
	int N=1<<n;
	int ans=0;
	for(int i=0;i<N;i++){
		int tmp=0;
		for(int j=0;j<n;j++){
			if((1<<j)&i) tmp++;
		}
		if(check(i)){
//			printf("%d\n",i);
			ans=max(ans,tmp);
		}
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int largo, ancho;
char c;
int modulo = 1000000000 + 7;
char tablero[1005][1005];
int dp[1005][1005];

void inicializar()
{
    for(int i = 0; i < largo; i++)
    {
        for(int j = 0; j < ancho; j++)
        {
            dp[i][j] = -1;
        }
    }
}

int solucion_recursiva(int inicio_x, int inicio_y, int fin_x, int fin_y)
{
    if(inicio_x > fin_x || inicio_y > fin_y || tablero[inicio_x][inicio_y] == '#')
        return 0;
    else if(inicio_x == fin_x && inicio_y == fin_y)
        return 1;
    else
    {
        int camino1 = solucion_recursiva(inicio_x + 1, inicio_y, fin_x, fin_y);
        int camino2 = solucion_recursiva(inicio_x, inicio_y + 1, fin_x, fin_y);

        return ((camino1 % modulo) + (camino2 % modulo)) % modulo;
    }
}

int memorizando(int inicio_x, int inicio_y, int fin_x, int fin_y)
{
    if(inicio_x > fin_x || inicio_y > fin_y || tablero[inicio_x][inicio_y] == '#')
        return 0;
    else if(inicio_x == fin_x && inicio_y == fin_y)
        return 1;
    else
    {
        if(dp[inicio_x][inicio_y] == -1)
        {
            int camino1 = memorizando(inicio_x + 1, inicio_y, fin_x, fin_y);
            int camino2 = memorizando(inicio_x, inicio_y + 1, fin_x, fin_y);

            dp[inicio_x][inicio_y] = (((camino1 % modulo) + (camino2 % modulo)) % modulo);
        }
        return dp[inicio_x][inicio_y];
    }
}

int solucion_dinamica()
{
    inicializar();
    int resp = memorizando(0, 0, largo - 1, ancho - 1);
    return resp;
}

int main()
{
    cin >> largo >> ancho;

    for(int i = 0; i < largo; i++)
    {
        for(int j = 0; j < ancho; j++)
        {
            cin >> c;
            tablero[i][j] = c;
        }
    }

    //int resp_recursiva = solucion_recursiva(0, 0, largo - 1, ancho - 1);
    int resp_dinamica = solucion_dinamica();

    cout << resp_dinamica << endl;
}



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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int k = 1;
    int c = b;
    while (c) {
        k *= 10;
        c /= 10;
    }
    int d = a * k + b;
    if ((int)sqrt(d) == sqrt(d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

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

    int h, w;
    const int mod = 1e9+7;
    cin >> h >> w;

    vector<vector<int>> grid(h+1, vector<int>(w+1, 0));
    grid[1][1] = 1;
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= w; j++) {
            if (s[j-1] == '.') {
                grid[i][j] = max(grid[i][j], grid[i-1][j] + grid[i][j-1]) % mod;
            }
        }
    }
    // for (int i = 1; i <= h; i++) {
    //     for (int j = 1; j <= w; j++) {
    //         cout << grid[i][j] << ' ';
    //     }
    //     cout << "\n";
    // }
    cout << grid[h][w];

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int d;
    cin>>d;
    map<int,string> mp;
    mp[25]="Christmas";
    mp[24]="Christmas Eve";
    mp[23]="Christmas Eve Eve";
    mp[22]="Christmas Eve Eve Eve";
    cout<<mp[d]<<endl;
}

Measured memory_bytes: 256
using System;

namespace ABC104B
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();


            Console.WriteLine(hoge(S));
        }

        static string hoge(string S)
        {
            if (!S.StartsWith("A"))
            {
                return "WA";
            }

            if (char.IsUpper(S[1]))
            {
                return "WA";
            }

            bool large = false;
            int max = S.Length - 1;
            for (int i = 2; i < max; ++i)
            {
                var v = S[i];
                if (char.IsUpper(v))
                {
                    if (!large)
                    {
                        if (v == 'C')
                        {
                            large = true;
                        } else
                        {
                            return "WA";
                        }
                    }
                    else
                    {
                        return "WA";
                    }
                }
            }

            if (!large || char.IsUpper(S[max]))
            {
                return "WA";
            }

            return "AC";
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); ++i)
#define REP0(i, n) for (long long i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (long long i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

long long modpow(long long a, long long b, long long mod)
{  // a^b % mod を log(b) で計算する
    if (b == 0)
        return 1;

    if (b % 2 == 0)
    {
        long long d = modpow(a, b / 2, mod) % mod;
        return (d * d) % mod;
    }
    else if (b % 2 == 1)
    {
        return (a * modpow(a, b - 1, mod)) % mod;
    }
};

const LL mod = 1000000007;

void solve()
{
    int n, a, b;
    cin >> n >> a >> b;
    LL ans = modpow(2, n, mod);

    LL N = 1;
    LL K = 1;
    REP0 (i, a)
    {
        N *= n - i;
        N %= mod;
    }
    REP1 (i, a)
    {
        K *= i;
        K %= mod;
    }

    LL K_inv = modpow(K, mod - 2, mod);

    ans -= (N * K_inv) % mod;
    ans %= mod;
    ans += (ans < 0 ? mod : 0);

    N = 1;
    K = 1;
    REP0 (i, b)
    {
        N *= n - i;
        N %= mod;
    }
    REP1 (i, b)
    {
        K *= i;
        K %= mod;
    }

    K_inv = modpow(K, mod - 2, mod);

    ans -= (N * K_inv) % mod;
    ans %= mod;
    ans += (ans < 0 ? mod : 0);

    cout << ans - 1 << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  ll n = 0;

  cin >> n;

  ll ans = 0;

  for(ll a = 1; a <= n; a++) ans += (n - 1) / a;

  cout << ans;

  return 0;
}
/*

*/


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

using namespace std;

long long r, c, k, v[3004][3004], dp[3004][3004][3];

long long cal(int i, int j, int cnt){
    if(cnt == 3)    return cal(i+1, j, 0);
    if(i >= r || j >= c)    return 0;
    long long& ret = dp[i][j][cnt];
    if(ret != -1)   return ret;
    ret = max(cal(i+1, j, 0), cal(i, j+1, cnt));
    if(v[i][j]) ret = max(ret, max(v[i][j] + cal(i, j+1, cnt+1), v[i][j] + cal(i+1, j, 0)));
    return ret;

}

void solve(){
    cin>>r>>c>>k;
    memset(v, 0, sizeof(v));
    for(int i = 0; i < k; i++){
        int R, C, V;
        cin>>R>>C>>V;
        v[R-1][C-1] = V;
    }
    memset(dp, -1, sizeof(dp));
    cout<<cal(0, 0, 0);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TC;
    //cin>>TC;
    TC=1;
    while(TC--){
        solve();
    }
}

Measured memory_bytes: 286192
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	string S;
	int K;

	cin >> K >> S;
	if (S.length() > K) {
		REP(i,K) {
			cout << S[i];
		}
		cout << "..." << endl;
	}
	else {
		cout << S << endl;
	}

	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    double i,n,d,a,b,count=0;
    cin>>n>>d;

    for(i=0;i<n;i++)
        {
            cin>>a>>b;
            if(sqrt(a*a+b*b) <= d)
                count++;
        }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2123;
ll a[MAXN], b[MAXN], c[MAXN];
int main() {
    int x,y,z,n,k;
    scanf("%d %d %d %d", &x, &y, &z, &k);
    for (int i = 0; i<x; ++i) {
        scanf("%lld", a+i);
        a[i] = -a[i];
    }
    for (int i = 0; i<y; ++i) {
        scanf("%lld", b+i);
        b[i] = -b[i];
    }
    for (int i = 0; i<z; ++i) {
        scanf("%lld", c+i);
        c[i] = -c[i];
    }
    sort(a, a+x);
    sort(b, b+y);
    sort(c, c+z);
    set<tuple<ll, int, int, int> > s;
    s.emplace(a[0]+b[0]+c[0], 0, 0, 0);
    vi output;
    ll m;
    int xx = x, yy = y, zz = z;
    while (k>0) {
        tie(m, x, y, z) = *s.begin();
        s.erase(s.begin());
        output.push_back(-m);
        if (x+1 < xx) s.emplace(m-a[x]+a[x+1], x+1,y, z);
        if (y+1 < yy) s.emplace(m-b[y]+b[y+1], x, y+1, z);
        if (z+1 < zz) s.emplace(m-c[z]+c[z+1], x, y, z+1);
        k--;
    }
    for (auto i : output) {
        printf("%lld\n", i);
    }
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
#define int long long
signed main(){

	int N;
	cin>>N;
	set<int> tes;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		tes.insert(a);
	}
	if(tes.size()==N)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    int a, b, tmp;
    cin >> a >> b;
    int A[1000];
    A[0] = 1;
    for(int i = 1; i < 499500; i++){
        A[i] = A[i - 1] + i + 1;
        if(A[i] - A[i - 1] == b - a){
            tmp = A[i] - b;
            break;
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long int ll;
 
 
 ll N = 1000005;
const ll mod = 998244353;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);

 




int main(){
   
    ll n;
    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    ll curr = n/10, cnt = n/10;
    ll a = 50;
    while(curr!=0){
        curr = n/a;
        cnt += curr;
        a = a*5;
    }
    
    cout<<cnt<<endl;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
string str_calc(string str){
  string str2=str;
  sort(str.begin(),str.end(),greater<int>());
  sort(str2.begin(),str2.end());
  int point=0;
  string ansstr="";
  char cc[str.size()];
  for(int i=str.size()-1;i>=0;i--){
    if(str[i]<str2[i]){
      str[i-1]--;
      cc[i]=(str[i]-str2[i]+10)+'0';
    }else{
      cc[i]=(str[i]-str2[i])+'0';
    }
  }
  for(int i=0;i<str.size();i++){
    ansstr.pb(cc[i]);
  }
  return ansstr;
}
bool check(string str,string str2){
  bool flag=true;
  for(int i=0;i<str.size();i++){
    if(str[i]!=str2[i]){
      flag=false;
      break;
    }
  }
  return flag;
}
int main(){
  string str;
  int n;
  while(cin>>str>>n,n){
    if(str.size()!=n){
      int num=str.size();
      reverse(str.begin(),str.end());
      for(int i=0;i<n-num;i++)
	str.pb('0');
      reverse(str.begin(),str.end());
    }
    //cout<<str<<endl;
    bool flag=false;
    for(int i=0;i<str.size();i++)
      if(str[i]!='0')
	flag=true;
    if(flag){
    vector<string>vs;
    vs.pb(str);
    int ans=-1,ans2=-1;
    for(int i=1;i<=20;i++){
      str=str_calc(str);
      for(int j=0;j<vs.size();j++){
	//cout<<str<<" "<<vs[j]<<" "<<j<<endl;
	if(check(str,vs[j])){
	  ans=j;ans2=i-j;
	  break;
	}
      }
      vs.pb(str);
      if(ans>=0)break;
    }
    reverse(str.begin(),str.end());
    while(str[str.size()-1]=='0'){
      str=str.substr(0,str.size()-1);
    }
    if(str=="")str="0";
    reverse(str.begin(),str.end());
    cout<<ans<<" "<<str<<" "<<ans2<<endl;
  }else{
      cout<<0<<" "<<str<<" "<<1<<endl;}
  }
  return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> s(h); for (auto&& e : s) cin >> e;
  V<> l(h, w), r(h, -1);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) if (s[i][j] == 'B') {
      l[i] = min(l[i], j);
      r[i] = max(r[i], j);
    }
  }
  int res = 0;
  for (int i = 0; i < h; ++i) if (s[i].find('B') != string::npos) {
    for (int x = 0; x < h; ++x) if (s[x].find('B') != string::npos) {
      res = max(res, abs(i - x) + abs(l[i] - r[x]));
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 3768
N,D = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
    d = (XY[i][0]**2 + XY[i][1]**2)**0.5
    if d <= D:
        cnt += 1
print(cnt)



Measured memory_bytes: 45760
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<intt,intt>
#define mp make_pair
typedef long long intt;
using namespace std;
int main()
{
  intt a,b;
  cin>>a>>b;
  int ans=0;
   while(a>0)
    ans++,a/=b;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
    int not_end=1;
    int m,f,r;

    while(not_end){
        scanf("%d",&m);
        scanf("%d",&f);
        scanf("%d",&r);

        if(m==-1&&f==-1&&r==-1){
            not_end=0;
        }

        if(not_end){
            if(m==-1||f==-1){
                printf("F\n");
            }else if(m+f>=80){
                printf("A\n");
            }else if(m+f>=65){
                printf("B\n");
            }else if(m+f>=50){
                printf("C\n");
            }else if(m+f>=30){
                if(r>=50){
                   printf("C\n");
                }else{
                    printf("D\n");
                }
            }else{
                printf("F\n");
            }
        }

    }

    return 0;
}


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

#define ll long long
#define INF 10000000000000000
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0);              
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll res = INF;
    ll r = x / d;
    if (k <= r)
    {
        res = min(res, x - k * d);
    }
    else if(k == r+1) {
        res = min(res, k * d - x);
    }
    else if(k % 2 == r % 2) {
        res = min(res, x - r * d);
    }
    else if (k%2 == (r+1)%2)
    {
        res = min(res, (r+1) * d - x);
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3640
//													\[T]/ Praise
//													 (*)  The
//													 / \  Sun



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

typedef long long ll;
typedef long double dbl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<long long> vl;
typedef vector< pair<int, int> > vii;
#define mp make_pair
#define pb push_back
#define invec(a, n) for(ll i = 0; i < n; i++) {cin >> a[i];}
#define rep(n) for(ll i = 0; i < n; i++)
#define fr(i,j,k) for(ll i = j; i < k; i++)
#define FR(i,j,k) for(ll i = j; i >= 0; i--)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define INF 1000000
#define xx first
#define yy second

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

int main()
{

	int n, W;
	cin >> n >> W;

	vector<pll> a(n);

	fr(i,0,n)
	{
		ll x, y;
		cin >> x >> y;
		a[i] = mp(x, y);
	}

	ll dp[n+1][W+1] = {0};

	fr(i,0,n+1)
		fr(j,0,W+1)
			dp[i][j] = 0;

	fr(i,1,n+1)
	{
		fr(j,0,W+1)
		{
			if(j >= a[i-1].xx)
				dp[i][j] = max(dp[i-1][j], dp[i-1][j - a[i-1].xx] + a[i-1].yy);
			else
				dp[i][j] = dp[i-1][j];
		}
	}

	// fr(i,0,n+1)
	// {
	// 	fr(j,0,W+1)
	// 		cout << dp[i][j] << "\t ";
	// 	cout << "\n";
	// }
	cout << dp[n][W];
}


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

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

    int ans = 0;
    rep(i, S.size() / 2){
        if (S[i] != S[S.size() - 1 - i]){
            ans++;
        }
    }

    cout << ans << endl;
}

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


int main() {
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int> v;
    for(int i=0;i<s.size()-1;i++){
        if(s.substr(i,2)=="AC"){
            v.push_back(i);
        }
    }
    for(int i=0;i<q;i++){
        int l,r,ans=0;
        cin>>l>>r;
        l--;
        r-=2;
        auto p1=lower_bound(v.begin(),v.end(),l);
        auto p2=upper_bound(v.begin(),v.end(),r);
        ans=distance(p1,p2);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<string> use(m);
  for(int i = 0;i < m;i++)cin >> use[i];
  vector<ll> cost = {0,2,5,5,4,5,6,3,7,6};
  vector<string> dp(n + 1);
  for(int i = 0;i < n + 1;i++)dp[i] = "";
  for(int i = 1;i < n + 1;i++){
    for(int j = 0;j < m;j++){
      if(i - cost[stoi(use[j])] == 0){
        //if(i == 6)cout << dp[i].size() << use[j].size() << endl;
        if(dp[i].size() < use[j].size())dp[i] = use[j];
        else if(dp[i].size() == use[j].size())dp[i] = max(dp[i],use[j]);
      }
      else if(i - cost[stoi(use[j])] > 0 && dp[i - cost[stoi(use[j])]] != ""){
        string memo;
        memo = dp[i - cost[stoi(use[j])]];
        memo = use[j] + memo;
        if(dp[i].size() < memo.size())dp[i] = memo;
        else if(dp[i].size() == memo.size())dp[i] = max(dp[i],memo);
        //dp[i] = max(dp[i],memo);
      }
      //if(i == 6)cout << "6の時" << dp[i] << endl;
    }
  }
  //cout << max(to_string(66),to_string(444)) << endl;
  //for(int i = 0;i < n + 1;i++)cout << i << " " << dp[i] << endl;
  cout << dp[n] << endl;
}

Measured memory_bytes: 32384
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int dfs(int N){
    if(N<=5)return mp[N]=N;
    else{
        if(mp[N]>0)return mp[N];
        else{
            int tmp=1e9;
            for(int i=1;i<=N;i*=6)tmp=min(tmp,dfs(N-i)+1);
            for(int i=1;i<=N;i*=9)tmp=min(tmp,dfs(N-i)+1);
            return mp[N]=tmp;
        }
    }
}
int main(){
    int n;
    cin >> n;
    cout << dfs(n) << endl;
}

Measured memory_bytes: 12800
import java.util.*;
import java.math.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	String str = br.readLine();
      	if(str.contains("7"))
    		System.out.println("Yes");
      	else
          	System.out.println("No");
    
    }

}


Measured memory_bytes: 32536
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 


long long int N,Ma,Mb,a[100],b[100],c[100],res=0;
long long int cost[405][405]={};
string S;
int main()
{
    cout << fixed << setprecision(18);
    cin>>S;
    for(long long int i = 0; i < 4; i++){
        if(S[i]=='2'){res++;}
    }
    cout<<res<<endl;
}    


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
int p[100001];

int main(){
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>p[i];
    }
    int cnt=0;
    for (int i=1;i<=n;i++) {
        if (p[i]==i) {
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);    
    int n,x,y;
    cin>>n>>x>>y;

    vi ans(n+1);
    FOR(i,1,n){
        FOR(j,i+1,n+1){
            int idx=min(j-i, abs(x-i)+1+abs(y-j));//1…X-Y間の移動
            ans[idx]++;
        }
    }
 
    REP(i,n-1){
        cout<<ans[i+1]<<endl;
    }
    return 0;
}

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


int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]){
                now+=d[i];
            }
        }
        ans=max(now,ans);
        return;
    }

    A.push_back(A.back());
    while(A.back()<=m){
        dfs(A);
        A.back()++;
    }
    return;
}

int main() {
    cin>>n>>m>>q;
    a=b=c=d=vector<int> (q);
    ans=0;
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(vector<int> (1,1));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
B = list(map(int, input().split()))
maxSumA = 0
for i in range(N - 1):
    if i == 0:
        maxSumA += B[i]
    else:
        maxSumA += min(B[i - 1], B[i])
maxSumA += B[N - 2]
print(maxSumA)

Measured memory_bytes: 3060
// SeeAlso: https://atcoder.jp/contests/abc058/tasks/abc058_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 50
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

string O,E;

int main() {
    cin >> O;
    cin >> E;

    int counter = O.length() + E.length();
    string ans = "";
    REP(i, counter) {
        if(i%2==0) {
            ans += O[i/2];
        } else {
            ans += E[i/2];
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
char a[1010][1010];
int f[1010][1010],n,m;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	f[0][0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i-1][j]=='.')
				f[i][j]+=f[i-1][j]%mod;
			if(a[i][j-1]=='.')
				f[i][j]+=f[i][j-1]%mod;
			f[i][j]%=mod;
		}
	}
	cout<<f[n-1][m-1]%mod<<endl;
	return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
using namespace std;
const int inf = 0x7f7f7f;
const int max_r = 10;
const int max_c = 10000;
bitset<max_c> a[max_r]; 
int r, c, ans;
void dfs(int k) {
	if(k == r) {
		int result = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				if(a[i][j]) sum++;
			}
			result +=max(sum, r - sum);
		}
		ans = max(ans, result);
		return;
	}
	dfs(k+1);
	a[k].flip();
	dfs(k+1);
}
int main()
{
//ios::sync_with_stdio(false);
#ifdef LOCAL
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
	while(cin >> r >> c && r && c) {
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				bool tmp;
				cin >> tmp;
				a[i][j] = tmp;
			}
		}
		ans = 0;
		dfs(0);
		cout << ans << endl;
	}
}




Measured memory_bytes: 3128
#include <iostream>
using namespace std;
int main()
{
	int a , b , c , d , e;
	cin >> a;
	b = a / 3600;
	c = a % 3600;
	d = c / 60;
	e = c % 60;
	cout << b << ":" << d << ":" << e << endl; 


}

Measured memory_bytes: 1164
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    if N == 1:
        print(abs(A[0] - W))
    else:
        print(max(abs(A[-1] - W), abs(A[-1] - A[-2])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4080
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};

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

    int N;
    cin>>N;
    vector<int> A[20];
    A[0].resize(1<<N);
    for(int i=0;i<(1<<N);i++){
        cin>>A[0][i];
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<(int)A[i].size();j+=2){
            int x=A[i][j],y=A[i][j+1];
            if(x==y) A[i+1].push_back(x);
            else if(x<y) A[i+1].push_back(y-x);
            else A[i+1].push_back(x-y);
        }
    }
    cout<<A[N][0]<<endl;
}


Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {

  ll N;
  cin>>N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++) {
cin>>A[i];
  }
  
 vector<ll> r(N+1);
  r[0]=0;
 ll sum=0;
  for(ll i=0;i<N;i++) {
sum+=A[i];
    r[i+1]=sum;
  }
  
  vector<vector<ll>> dp(N+1,vector<ll> (N+1,0));
  
  for(ll i=2;i<=N;i++) {
for(ll j=0;j+i<N+1;j++) {
ll p=r[j+i]-r[j];
  ll s=100000000000000007;
  for(ll h=j+1;h<j+i;h++) {
    s=min(s,dp[j][h]+dp[h][j+i]);
  }
  dp[j][j+i]=p+s;
}
  }
  
  cout<<dp[0][N]<<endl;
}

  
  
  
  
  

Measured memory_bytes: 4888
#include <bits/stdc++.h>
#define fi first
#define se second
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define Ford(i, a, b) for(int i = (a); i >=(b); --i)
#define endl '\n'
#define debug(a) cout << a << endl
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
 
const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
 
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;

ll test;
ll k, n;
ll res = 0, sum = 0, ans = 0, kd, hkd;


void FastIn(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void ReadIn(){
    cin >> n >> k;
    cout << min(n, min(n - ((n / k)  * k), abs(n - ((n / k) + 1) * k)));
}
int main(){
    FastIn();
    ReadIn();
}
    

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n=sc.nextInt(),m=sc.nextInt();
    long sum=0;
    for(long i=0;i<m;i++)sum+=sc.nextLong();
    System.out.println(Math.max(n-sum, -1));
    
  }
}


Measured memory_bytes: 46500