akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var M = cin.ReadInt;

            long[] a = new long[N];
            long[] b = new long[N];
            long[] c = new long[M];
            long[] d = new long[M];

            for (int i = 0; i < N; i++){
                a[i] = cin.ReadLong;
                b[i] = cin.ReadLong;
            }
            for (int i = 0; i < M; i++){
                c[i] = cin.ReadLong;
                d[i] = cin.ReadLong;
            }

            long minDist;
            int ans;
            for (int i = 0; i < N; i++){
                minDist = (long)Pow(10, 8) * 5;
                ans = 0;
                for (int j = 0; j < M; j++){
                    long dist = Abs(a[i] - c[j]) + Abs(b[i] - d[j]);
                    if(dist < minDist){
                        minDist = dist;
                        ans = j;
                    }
                }
                WriteLine(ans + 1);
            }

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

ll MOD = 1000000007;

int main()
{
  string s;
  int m;
  cin >> s >> m;
  int n = s.size();
  
  //dp[i文字目(0-indexed)まで見た][非0をj個使った][sより小さいことが確定しているか]
  vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(m+1, vector<ll>(2, 0)));
  
  //初期化
  rep(i,s[0]-'0'+1)
  {
    if(i == 0) dp[0][0][1]++;
    else if(i < s[0]-'0') dp[0][1][1]++;
    else if(i == s[0]-'0') dp[0][1][0]++;
  }
  //rep(i, m+1)cout<<dp[0][i][0]<<" ";cout<<endl; rep(i,m+1)cout<<dp[0][i][1]<<" ";cout<<endl;
  
  for(int i = 0; i+1 < n; i++)
  {
    int c = s[i+1] - '0';
    //k=1からはk=1にしか遷移しない
    //i桁目で0を選んだ時のkの値がs[i]によって変わる(s[i]==0 -> k=0, s[i]!=0 -> k=1)
    if(c==0)
    {
      //よこ（0を選ぶ）
      rep(j, m+1)
      {
        dp[i+1][j][0] += dp[i][j][0];
        dp[i+1][j][1] += dp[i][j][1];
      }
      //ななめ（非0を選ぶ）
      rep(j, m)
      {
        //k=1からの遷移なので1~9すべて選べる
        dp[i+1][j+1][1] += dp[i][j][1] * 9;
      }
    }
    else
    {
      //0をとる
      rep(j, m+1)
      {
        dp[i+1][j][1] += dp[i][j][0];
        dp[i+1][j][1] += dp[i][j][1];
      }
      //非0を選ぶ
      rep(j, m)
      {
        dp[i+1][j+1][1] += dp[i][j][1] * 9;
        //1以上s[i]未満を選ぶ
        dp[i+1][j+1][1] += dp[i][j][0] * (c-1);
        //s[i]と同じ数を選ぶ
        dp[i+1][j+1][0] += dp[i][j][0];
      }
    }
  }
  
  cout << dp[n-1][m][0] + dp[n-1][m][1] << endl;
  
  /*
  rep(i,n){rep(j,m+1)cout<<dp[i][j][1]<<" "; cout<<"\n";}cout<<endl;
  rep(i,n){rep(j,m+1)cout<<dp[i][j][0]<<" "; cout<<"\n";}
  //*/
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n,x,t; cin>>n>>x>>t;
    cout<<((n-1)/x+1)*t<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define mo 1000000007
char s[maxn];
int f[maxn][13];
int main(){
	scanf("%s",s);f[0][0]=1;
	int i;
	for(i=0;s[i];i++){
		if(s[i]=='?'){
			for(int j=0;j<13;j++){
				for(int x=0;x<10;x++){
					(f[i+1][(j*10+x)%13]+=f[i][j])%=mo;
				}
			}
		}
		else{
			int x=s[i]-'0';
			for(int j=0;j<13;j++){
				(f[i+1][(j*10+x)%13]+=f[i][j])%=mo;
			}
		}
	}
	printf("%d\n",f[i][5]);
	return 0;
} 

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    
    int N;
    ll C;
    cin >> N >> C;
    vl x(N),v(N);
    rep(i,N){
        ll a,b;
        cin >> a >> b;
        x[i] = a,v[i] = b;
    }
    vl xr(N);
    rep(i,N){
        if(i == 0) xr[0] = v[i] - x[i];
        else xr[i] = xr[i-1] + v[i] - (x[i] - x[i-1]);
    }
    vl xl(N);
    rev(x);
    rev(v);
    rep(i,N){
        if(i == 0) xl[i] = v[i] - (C - x[i]);
        else xl[i] = xl[i-1] + v[i] + (x[i] - x[i-1]);
    }
    vl A(N,0);
    A[0] = max(A[0], xl[0]);
    reps(i,1,N){
        if(A[i-1] < xl[i]) A[i] = xl[i];
        else A[i] = A[i-1];
    }
    rev(x);
    rev(A);
    
    ll ans = 0;
    ll an = 0;
    rep(i,N){
        an = xr[i];
        ans = max(ans, an);
        if(i==N-1) break;
        an += A[i+1];
        an -= x[i];
        ans = max(ans,an);
        
    }
    ans = max(ans,A[0]);
    vl B(N,0);
    B[0] = max(B[0], xr[0]);
    reps(i,1,N){
        if(B[i-1] < xr[i]) B[i] = xr[i];
        else B[i] = B[i-1];
    }
    rev(B);
    rev(x);
    rep(i,N){
        an = xl[i];
        ans = max(an,ans);
        if(i==N-1) break;
        an += B[i+1];
        an -= (C-x[i]);
        ans = max(ans,an);
        
    }
    ans = max(ans,B[0]);
    
    
    
    out(ans);
    
    


    return 0;
}


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

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    if (x < y) {
      int tmp = x;
      x = y;
      y = tmp;
    }
    int cnt = 0;
    while (y) {
      int r = x % y;
      x = y;
      y = r;
      cnt++;
    }
    cout << x << " " << cnt << "\n";
  }
}


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

//#include <cstdio>

using namespace std;

static int inputArray(int A[], int num) {
  int max = 0;
  for (int i = 0; i < num; i++) {
    cin >> A[i];
    if (A[i] > max) {
      max = A[i];
    } 
  }
  return max;
}

static inline int f(int A[], int num, uint64_t P, int k) {
    int i = 0, v = 0;
    for (uint64_t total = 0; (v < k) && (i < num); i++) {
      total += A[i];
      if (total > P) {
        total = 0;
        i--;
        v++;
      }
    }
    return i;
}

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

  vector<int> w(n);
  inputArray(&w[0], n);

  uint64_t left = 0;
  uint64_t right = 100000 * 10000;
  uint64_t mid;
  int v = 0;
  int count = 0;
  while (1 < right - left) {
    count++;
    mid = (left + right) / 2;
    v = f(&w[0], n, mid, k);
    if (v < n) {
      left = mid;
    } else {
      right = mid;
    }
  }

  cout << right << endl;
  return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
int n;
cin>>n;
int x=n%10;
if(x==2 || x==4 || x==5 || x==7 || x==9)
{
	cout<<"hon";
}
else if(x==6 || x==1 || x==0 || x==1 || x==8)
{
	cout<<"pon";
}
else if(x==3)
{
	cout<<"bon";
}
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;

//A reward for a Carpenter
//???????????£???????????????

// 1???????????????????????°n???n???20??? 
// 2??????????????????????????°m 
// 3????????????1???????????????????????± a1, b1, c1, d1?????´??°;????§??????????????????????
//    a1, b1?????????????????????????????§?????????????????? 
//    c1 ???a1 ?????? b1 ??????????????? (0???1000)
//    d1 ???b1 ?????? a1 ??????????????? (0???1000)
// 4????????????2???????????????????????± a2, b2, c2, d2?????´??°;????§??????????????????????
//   : : 
//   : : 
// ???????????????x1, x2, y1, y2?????´??°;????§?????????????????????? 
// x1?????§??\??????????????????????????? 
// x2?????±??????????±±???????????? 
// y1???????§?????????§??\??????????????£????????? 
// y2?????±?????£???

int n, m;
int root[20][20];
int dp[20][20];

int s, g, y1, y2;
int INF = 9999999;

void print(){
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			cout << root[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void init(){
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			root[i][j] = INF;
		}
	}
}


void WF(){

	for(int k=0 ; k<n ; k++){
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				root[i][j] = min(root[i][j], root[i][k] + root[k][j]);
			}
		}
	}
}

int main(){

	cin >> n;
	cin >> m;

	init();

	for(int i=0 ; i<m ; i++){
		int a, b, c, d;
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		a--;
		b--;

		root[a][b] = c;
		root[b][a] = d;
	}

	scanf("%d,%d,%d,%d", &s,&g,&y1,&y2);
	// cout << s << " " << g << endl;
	s--;
	g--;

	// print();

	WF();
	// print();

	cout << y1-y2-root[s][g]-root[g][s] << endl;


	return 0;
}

Measured memory_bytes: 1244
def E(i,y):
    if i==1:
        return 5*y
    else:
        return (2*i+1)*y

N,X=map(int,input().split())
x=[int(i) for i in input().split()]
a=[0]
for i in range(N):
    a.append(a[-1]+x[i])
ans=10**50
for k in range(1,N+1):
    tmp=(N+k)*X
    for i in range(N//k):
        tmp+=E(i+1,a[N-i*k]-a[N-i*k-k])
        #print(k,i,tmp)
    if N%k!=0:
        tmp+=E(N//k+1,a[N-(N//k)*k])
    #print(tmp)
    if ans>tmp:
        ans=tmp
print(ans)


Measured memory_bytes: 98128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
typedef long long LL;
int main() {
	double a, b, c, d;
	std::cin >> a >> b;
	c = ceil((a + b) / 2);

	std::cout <<c<< std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
		int left = a + b;
		int right = c + d;
		if(left < right){
			System.out.println("Right");
		}else if(left > right){
			System.out.println("Left");
		}else{
			System.out.println("Balanced");
		}
	}

}


Measured memory_bytes: 21972
int main(){
	int N;
  	int Dis = 0;
  	int MinDis = 50000000;
  	int MaxX = 0;

	scanf("%d", &N);
	int X[N];
	for(int i=0; i<N; i++){
		scanf("%d", &X[i]);
      	if(X[i]>MaxX) MaxX = X[i];
    }
	
  	for(int P=0; P<=MaxX; P++){
      	for(int i=0; i<N; i++){
      		Dis += (X[i]-P)*(X[i]-P);
        }
      	if(Dis<MinDis) MinDis = Dis;
      	Dis = 0;
    }  	
  
    printf("%d", MinDis);
  
  return 0;
}

Measured memory_bytes: 128
//============================================================================
// Name        : e.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(m),b(m);
	vector<vector<int>> c(m);
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		for(int j=0;j<b[i];j++){
			int temp;
			cin>>temp;
			c[i].push_back(temp);
		}
	}
	int def=1;
	for(int i=1;i<n;i++){
		def=def*2+1;
	}
	vector<vector<int>> v(m,vector<int>(def+1,1<<30));
	int idx=0;
	for(int i=0;i<b[0];i++){
		idx+=1<<(c[0][i]-1);
	}
	v[0][0]=0;
	v[0][idx]=a[0];
	for(int i=1;i<m;i++){
		idx=0;
		for(int j=0;j<b[i];j++){
			idx+=1<<(c[i][j]-1);
		}
		for(int j=0;j<=def;j++){
			v[i][j|idx]=min(v[i][j|idx],v[i-1][j]+a[i]);
			v[i][j]=min(v[i][j],v[i-1][j]);
		}
	}
//	for(int i=0;i<m;i++){
//		for(int j=0;j<=def;j++){
//			cout<<v[i][j]<<' ';
//		}cout<<endl;
//	}
	if(v[m-1][def]==1<<30){
		cout<<-1<<endl;
	}else{
		cout<<v[m-1][def]<<endl;
	}

	return 0;
}

Measured memory_bytes: 16384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n;
bool done[3003][3003];
ll a[3003],memo[3003][3003];

ll solve(int i, int j){
	int k;
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	k = n-(j-i+1);
	if(k==n){
		memo[i][j] = 0ll;
		return memo[i][j];
	}
	if(k%2){
		memo[i][j] = min(solve(i+1,j)-a[i],solve(i,j-1)-a[j]);
	}else{
		memo[i][j] = max(solve(i+1,j)+a[i],solve(i,j-1)+a[j]);
	}
	return memo[i][j];
}

int main(void){
	int i;
	fill(done[0],done[3003],false);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	cout << (solve(0,n-1)) << endl;
	return 0;
}


Measured memory_bytes: 79744
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer,Integer> map = new HashMap<>();
        boolean[] ok = new boolean[n];
        int ans = 0;
        Arrays.fill(ok,true);

        for(int i = 1;i <= n;i++){
            map.put(i,sc.nextInt());
        }

        for(int i = 0;i < m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(map.get(a) <= map.get(b)){
                ok[a-1] = false;
            }
            if(map.get(a) >= map.get(b)){
                ok[b-1] = false;
            }
        }

        for(int i = 0;i < n;i++){
            if(ok[i]){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 73940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, A;
  cin >> X >> A;
  cout << (X < A ? 0 : 10) << "\n";
}

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;
  string s;
  cin >> s;
  int cnte = 0,cntw = 0;
  rep(i,N) if(s[i] == 'E')cnte++;
  int res = N;
  rep(i,N) {
    if(s[i] == 'E') {
      --cnte;
      res = min(res,cnte + cntw);
    }else{
      res = min(res,cnte + cntw);
      cntw++;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 900
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int q = int.Parse(str[1]);
        var stacks = new Stack<int>[n];
        for(int i=0; i<n; i++){
            stacks[i] = new Stack<int>();
        }
        for(int i=0; i<q; i++){
            var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            switch(line[0]){
                case 0:
                    stacks[line[1]].Push(line[2]);
                    break;
                case 1:
                    if(stacks[line[1]].Count != 0){
                        var top = stacks[line[1]].Pop();
                        Console.WriteLine(top);
                        stacks[line[1]].Push(top);
                    }
                    break;
                case 2:
                    if(stacks[line[1]].Count != 0){
                        stacks[line[1]].Pop();
                    }
                    break;
            }
        }
    }
}



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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;

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

const int SZ=150000;
bool isPrime[SZ];

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

    for(int i=2;i<SZ;i++) isPrime[i]=true;
    for(int i=2;i<SZ;i++){
	if(!isPrime[i]) continue;
	for(int j=i*2;j<SZ;j+=i){
	    isPrime[j]=false;
	}
    }

    while(true)
    {
	int n,p; cin>>n>>p;
	if(n==-1 && p==-1) break;

	vector<int> v;
	for(int i=n+1;;i++){
	    if(isPrime[i]) v.push_back(i);
	    if(v.size()==p) break;
	}
	vector<int> vv;
	REP(i,v.size()){
	    for(int j=i;j<v.size();j++){
		vv.push_back(v[i]+v[j]);
	    }
	}
	sort(vv.begin(),vv.end());
	cout<<vv[p-1]<<endl;
    }


}



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

#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define ll long long
const ll INF = 2LL<<60;

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

    vector<int> d(N);
    rep(i, N) cin >> d[i];

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

    int r = d.size() / 2;
    int l = r - 1;

    cout << d[r] - d[l] << endl;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	int n; std::cin >> n;
	string s, t; std::cin >> s >> t;
	rep(i, n) {
		putchar(s[i]);
		putchar(t[i]);
	}
	std::cout << "\n";
}


Measured memory_bytes: 256
def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    mod = pow(10, 9) + 7

    pos = []
    neg = []
    zero = 0
    for v in A:
        if v > 0: pos.append(v)
        elif v < 0: neg.append(v)
        else: zero += 1

    # zero is needed
    if len(pos) + len(neg) < K:
        return 0

    pos.sort(reverse = True)
    neg.sort()

    cnt_p, cnt_n = 0, 0
    h = []
    for v in pos:
        h.append([v, 1])
    for v in neg:
        h.append([-v, -1])

    h.sort(reverse = True)
    v = 1
    for k in range(K):
        if h[k][1] > 0:
            cnt_p += 1
        else:
            cnt_n += 1

    if cnt_n % 2 == 0: # when positive
        v = 1
        for i in range(cnt_p):
            v *= pos[i]
            v %= mod
        for j in range(cnt_n):
            v *= neg[j]
            v %= mod
        return v
    else: # when negative
        if cnt_p < len(pos) and cnt_n < len(neg) and cnt_p > 0: # both are not full
            # if abs(neg[cnt_n]) / pos[cnt_p-1] < pos[cnt_p] / abs(neg[cnt_n-1]):
            if pos[cnt_p] * pos[cnt_p-1] > abs(neg[cnt_n]) * abs(neg[cnt_n-1]):
                cnt_p += 1
                cnt_n -= 1
            else:
                cnt_p -= 1
                cnt_n += 1
            v = 1
            for i in range(cnt_p):
                v *= pos[i]
                v %= mod
            for j in range(cnt_n):
                v *= neg[j]
                v %= mod
            return v
        elif cnt_p < len(pos) and cnt_n > 0:
            cnt_p += 1
            cnt_n -= 1
            v = 1
            for i in range(cnt_p):
                v *= pos[i]
                v %= mod
            for j in range(cnt_n):
                v *= neg[j]
                v %= mod
            return v
        elif cnt_n < len(neg) and cnt_p > 0:
            cnt_p -= 1
            cnt_n += 1
            for i in range(cnt_p):
                v *= pos[i]
                v %= mod
            for j in range(cnt_n):
                v *= neg[j]
                v %= mod
            return v
        else:
            if zero > 0:
                return 0
            else:
                h.sort()
                v = 1
                for i in range(K):
                    v *= h[i][0] * h[i][1]
                    v %= mod
                return v



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 117696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		//0 origin
		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);
		int x = Integer.parseInt(tmpArray[2]);

		@SuppressWarnings("unchecked")
		ArrayList<Edge> edges[] = new ArrayList[n];

		for(int i = 0; i < n; i++){
			if(edges[i] == null){
				edges[i] = new ArrayList<Edge>();
			}
		}

		for(int i = 0; i < m; i++){
			tmpArray = br.readLine().split(" ");
			int from = Integer.parseInt(tmpArray[0]);
			int to = Integer.parseInt(tmpArray[1]);
			int cost = Integer.parseInt(tmpArray[2]);

			edges[from].add( new Edge(to, cost));
		}

		solve(edges, n, x);
	}


	static void solve(ArrayList<Edge>[] edges,  int n, int x){
		//xからそれぞれのfarmへの帰り道の最短距離
		int[] dist = dijkstra(edges, x, n);

		for(int i = 0; i < n; i++){
			if(dist[i] == INF){
				System.out.println("INF");
			}
			else {
				System.out.println(dist[i]);
			}
		}

	}

	static final int INF = Integer.MAX_VALUE;

	//ダイクストラ法
	static int[] dijkstra(ArrayList<Edge>[] edges, int s, int n){
//		if(n == 1){
//			return new int[]{0};
//		}

		PriorityQueue<Distance> que = new PriorityQueue<Distance>();
		int[] dist = new int[n];

		Arrays.fill(dist, INF);
		dist[s] = 0;
		que.add(new Distance(0, s));

		while(!que.isEmpty()){
			Distance tmpDist = que.poll();
			int tmpV = tmpDist.id;

			if(dist[tmpV] < tmpDist.dist){
				continue;
			}
//			System.out.println(tmpV);
			for(int i = 0; i < edges[tmpV].size() ; i++){
//				System.out.println(i);
				Edge e = (Edge) edges[tmpV].get(i);
				if(dist[e.to] > dist[tmpV] + e.cost){
					dist[e.to] = dist[tmpV] + e.cost;
					que.add(new Distance(dist[e.to], e.to));
				}
			}
		}

		return dist;
	}
}

class Distance implements Comparable<Distance>{
	int dist;
	int id;

	Distance(int dist, int id){
		this.dist = dist;
		this.id = id;
	}

	@Override
	public int compareTo(Distance d) {
		return this.dist - d.dist;
	}
}

class Edge {
	int to;
	int cost;

	Edge(int to, int cost){
		this.to = to;
		this.cost = cost;
	}
}


Measured memory_bytes: 127224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{   ll t=0,c;
	int sum=0,r;
    cin>>t; 
    c=t;
	while(t> 0)
	{
		r=t%10;
		t=t/10;
		sum=sum+r;
	}
	if(c%sum==0)
	cout<<"Yes";
	else
	cout<<"No";
	
	return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string> s(3);
int main() {
    for(int i = 0; i < 3; ++i) {
        cin >> s.at(i);
    }

    cout << (char)(s.at(0).at(0)-32) << (char)(s.at(1).at(0)-32) << (char)(s.at(2).at(0)-32) << endl;
}

Measured memory_bytes: 256
#include <stdio.h> 

 
 int main(){ 
     char number[1001]; 
     int i, sum; 
     while(1){ 
         scanf("%s", number); 
         if(number[0]=='0')break; 
         sum=0; 
         for(i=0;number[i]!='\0';i++){ 
             sum+=number[i]-'0'; 
         } 
         printf("%d\n", sum); 
     } 
 
 
     return 0; 
 } 



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

ll N, all;

ll arr[22][22];
ll mod = 1000*1000*1000+7;
ll dp[(ll)(pow(2,21))][22];
ll solve(ll F, ll M){
	if (F == all && M == N) return 1;
	if (M >= N || F == all) return 0;
	
	if (dp[F][M] != -1) return dp[F][M];
	
	ll ans = 0;
	for(ll f = 0;f<N;f++){
		if (!(F &(1<<f)) && arr[M][f]){
			ans = (ans + solve(F|(1<<f), M+1) % mod) % mod;
		}
	}
	return dp[F][M] = ans % mod;
}


int main(){
	cin>>N;
	for(ll i = 0;i<N;i++)
	for(ll j = 0;j<N;j++)
		cin>>arr[i][j];
	
	all = pow(2,N) - 1;
	memset(dp, -1, sizeof dp);
	
	cout<<solve(0,0)%mod<<endl;
}

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

int main() {
	int n,a[10];
	int max;
	cin >> n;
	for(int i=0; i!=n; i++){
		cin >> a[i];
		if(max < a[i]){
			max = a[i];
		}
	}
	int ticket = 1;
	int ans = 0;
	for(int i=0; i!=n; i++){
		ans += a[i];
		if(a[i] == max){
			if(ticket == 1){
				ans -= a[i] / 2;
				ticket = 0;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

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

using namespace std;
using lint = long long;

vector<int> IsPrime;

int main(void)
{
    lint N, K;
    cin >> N >> K;
    lint R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    lint para = ceil(N / (double)K);
    lint amari = N % K;

   // cout << T.size() << endl;
    lint sum = 0;
    lint dp[100001][3] = {0};
    for(int i = 0; i < K; i++){
        dp[0][0] = 0;
        dp[0][1] = 0;
        dp[0][2] = 0;
        for(int j = 0; j < para; j++){
            if((i+j*K) >= T.size()){
                dp[para][0] = dp[para-1][0];
                dp[para][1] = dp[para-1][1];
                dp[para][2] = dp[para-1][2];
                break;
            };
            lint cr = 0, cs = 0, cp = 0;
            if(T[i+j*K] == 'r') cr = P;
            else if(T[i+j*K] == 's') cs = R;
            else cp = S;
            dp[j+1][0] = max(dp[j][1], dp[j][2]) + cr;
            dp[j+1][1] = max(dp[j][0], dp[j][2]) + cs;
            dp[j+1][2] = max(dp[j][0], dp[j][1]) + cp;
        }
        sum += max({dp[para][0], dp[para][1], dp[para][2]});
    }
    cout << sum << endl;
    return 0;
}

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

int n, arr[25];

int main(void){
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) cin >> arr[i];
    int ohajiki = 32, i = 0;
    while(ohajiki != 0){
      ohajiki -= (ohajiki - 1) % 5;
      cout << ohajiki << endl;
      ohajiki = max(ohajiki - arr[i % n], 0);
      cout << ohajiki << endl;
      i++;
    }
  }
  return 0;
}

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

int main (int argc, char **argv) {
  int a, b;
  char op;
  int x;
  
  while (cin >> a >> op >> b) {
    if (op == '?') break;
    switch (op) {
    case '+': x = a + b; break;
    case '-': x = a - b; break;
    case '*': x = a * b; break;
    case '/': x = a / b; break;
    }
    cout << x << endl;
  }
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    cin.ignore();

    while (n--) {
        string str;
        getline(cin, str);

        size_t pos = 0;
        while ((pos = str.find("Hoshino", pos)) != string::npos) {
            str.replace(pos, 7, "Hoshina");
        }

        cout << str << endl;
    }

    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	ll n,count=0;
	string mem;
	cin >> n;
	vector<string> s;
	for (ll i = 0; i < n; i++) {
		cin >> mem;
		s.push_back(mem);
	}
	sort(s.begin(), s.end());
	for (ll i = 0; i < n - 1; i++) {
		if (s[i] == s[i + 1])count++;
	}
	cout << n - count << endl;
	return 0;
}

Measured memory_bytes: 11660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int N;
	cin>>N;
	int arr[N];
	for(auto &it:arr)
	{
		cin>>it;
	}
	int dp[N];
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for(int i=2;i<N;i++)
	{
		int x=dp[i-2]+abs(arr[i-2]-arr[i]);
		int y=dp[i-1]+abs(arr[i-1]-arr[i]);
		dp[i]=min(x,y);
	}
	cout<<dp[N-1];
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;

int main(){
    std::cin >> s;
    if(s[0] == 'S'){
        printf("Cloudy\n");
    }else if(s[0] == 'C'){
        printf("Rainy\n");
    }else{
        printf("Sunny\n");
    }
}


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

int main(void){
    int h, w;
    cin >> h >> w;
    char pic[h][w];
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            cin >> pic[i][j];
        }
    }
    for (int i=0; i<w+2; i++) cout << '#';
    cout << endl;
    for (int i=0; i<h; i++){
        cout << '#';
        for (int j=0; j<w; j++){
            cout << pic[i][j];
        }
        cout << '#' << endl;
    }
    for (int i=0; i<w+2; i++) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
/*    Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+5;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
vector<int>vp[N];
int a[N];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int mx=a[1];
    int mx1=0;
    int cnt=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]<=mx)
        {
            cnt++;
            mx=a[i];
        }
        else
        {
            mx1=max(mx1,cnt-1);
            cnt=1;
            mx=a[i];
        }

    }
    mx1=max(mx1,cnt-1);
    cout<<mx1<<endl;

    
    
    

        
}


Measured memory_bytes: 5760
import std.stdio, std.math, std.conv, std.algorithm, std.array;

int[] decode(int n) {
  int[] res;
  while(n != 0) {
    int k = n % (-10);
    if (k < 0) {
      k += 10;
      n -= 10;
    }
    n /= -10;
    res ~= k;
  }
  return res.reverse;
}

void main() {
  for(int n; readf("%d\n", &n), n != 0;)
    decode(n).map!(to!(string)).array.join("").writeln;
}

Measured memory_bytes: 1768
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    for(int k = 1; k <= m; k++){
        for(int j = 0; j < n - 1; j++){
            if(a[j] % k > a[j + 1] % k){
                swap(a[j], a[j + 1]);
            }
        }
    }
    for(auto&& i : a){
        cout << i << "\n";
    }
}


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

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>=c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
void output_vector(const vector<T> , bool ,bool ,int ,int );

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);

template<typename T>
istream& operator>>(istream &in,vector<T> &v);


void solve()
{   
    string s,t;
    cin>>s>>t;
    int c=0;
    fr(i,0,len(s)){
        if(s[i]==t[i])
        continue;
        c++;
    }
    cout<<c<<endl;
}

int main()
{   

    FIO;
    // ll test;cin>>test;
    // while(test--)
    solve();
    return 0;
}






template<typename T>
void output_vector(const vector<T> &v, bool debug_print=false,bool add_one = false,int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        (debug_print)?(cerr << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n')):(cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'));
}   

template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<" ":out<<"\n";    
    }
    return out;
}

template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

Measured memory_bytes: 3820
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
double a[101];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  double sum = 0;
  REP(i, n) cin >> a[i], sum+= a[i];

  sort(a, a + n, greater<double>());
  bool f = true;
  double k = sum / (4 * m);
  REP(i, m) {
    if(a[i] < k) {
      f = false; break;
    }
  }

  cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        a.at(i)%=mod;
    }
    vector<ll>retu(n+1);
    for(int i=1;i<=n;i++){
        retu.at(i)=retu.at(i-1)+a.at(i-1);
        retu.at(i)%=mod;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll k = retu.at(n)-retu.at(i+1);
        if(k<0){
            k+=mod;
        }
        ll d = a.at(i)*k;
        d%=mod;
        ans+=d;
        ans%=mod;
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 6416
n = gets.chomp.to_i
array_a = gets.split(" ").map(&:to_i)
array_b = gets.split(" ").map(&:to_i)
array_c = gets.split(" ").map(&:to_i)

satisfaction = 0

n.times do |i|
    satisfaction += array_b[(array_a[i]-1)]
    if array_a[i] + 1 == array_a[i+1]
        satisfaction += array_c[(array_a[i]-1)]
    end
end

puts satisfaction

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	int ans = (n - 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<vector<ll>> dp;
ll dfs(int i, int j, vector<vector<ll>> &v, ll n){
	if(i<0 || i>=n || j<0 || j>=3)
      	return 0;
  	if(dp[i][j]!=-1)
      	return dp[i][j];
  	ll ans = 0;
  	for(int k=0;k<3;k++){
    	if(k!=j){
        	ans=max(ans,v[i][j]+dfs(i+1,k,v,n));
        }
    }
    return dp[i][j]=ans;
}
int main(){
	ll n,a,b,c;
  	cin>>n;
  	vector<vector<ll>> v(n+1,vector<ll>(3));
    for(int i=0;i<n;i++){
    	for(int j=0;j<3;j++){
        	cin>>v[i][j];
        }
    }
  	dp.assign(n+1,vector<ll>(3,-1));
  	ll ans = 0;
  	for(int i=0;i<3;i++){
    	ans=max(ans,dfs(0,i,v,n));
    }
  	cout<<ans<<endl;
  	return 0;
}


Measured memory_bytes: 23544
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <climits>

using namespace std;

long long MOD = 1000000007;

int main(){
	long long n, m;
	cin>>n>>m;
	if(2*n == m)
		cout<<n<<endl;
	else if(2*n > m){
		cout<<m/2<<endl;
	}
	else{
		m -= 2*n;
		m /= 4;
		cout<<n+m<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int n;
    string s;
    cin >> n>> s;
    int dp[n];
    rep(i,n){
        if(s[i]=='A'){
            dp[i]=1;
        }else if(i>0&&dp[i-1]==1&&s[i]=='B'){
            dp[i]=2;
        }else if(i>1&&dp[i-1]==2&&s[i]=='C'){
            dp[i]=3;
        }
    }
    int ans=0;
    rep(i,n){
        if(dp[i]==3){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    int sumi=0;
    int val;
    rep(i,n){
    	cin>>val;
    	while(val%2==0){
    		sumi++;
    		val/=2;
    	}
    }
    cout<<sumi<<endl;	
    return 0;  
    
}



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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  int exp = 1;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a == exp) exp++;
  }
  if (exp == 1) {
    cout << -1 << endl;
  }else {
    cout << N - exp + 1 << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <math.h>


int main(){
  std::string S;
  std::cin >> S;
  if (S=="SUN"){
    printf("7\n");
    return 0;
  } else if (S=="MON"){
    printf("6\n");
    return 0;
  } else if (S=="TUE"){
    printf("5\n");
    return 0;
  } else if (S=="WED"){
    printf("4\n");
    return 0;
  } else if (S=="THU"){
    printf("3\n");
    return 0;
  } else if (S=="FRI"){
    printf("2\n");
    return 0;
  } else if (S=="SAT"){
    printf("1\n");
    return 0;
  }
  return 0;
}

Measured memory_bytes: 888
// Vacation.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
const int G = 1000 * 100 + 10;
int a[G][3];
long long dp[G][3];

int maxx(int x, int y, int z) {
	int max = x;
	if (y > max) max = y;
	if (z > max) max = z;
	return max;
}

int main()
{
	int n;
	cin >> n;
	for (int  i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			cin >> a[i][j];
		}
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (int  i = 1; i < n; i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
		dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + a[i][1];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
	}
	cout << maxx(dp[n-1][0], dp[n-1][1], dp[n-1][2]) << endl;
	return 0;
}



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


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

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (std::to_string(i).length()%2 == 1) ans++;
    }

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

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;

bool solve(){
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) return true;
	return false;
}

int main(){
//	Code goes here
	bool res = solve();
	if(res) cout<<"Yes";
	else cout<<"No";

	return 0;
}

Measured memory_bytes: 256
# すぬけ君の管理する研究室の扉にはロックがかかっており、解錠にはセキュリティコードを入力する必要があります。
# セキュリティコードは 4 桁の数字列です。
# セキュリティコードが「入力しづらい」とは、同じ数字が連続する箇所が存在することを言います。
# 現在のセキュリティコード S が与えられます。
# S が「入力しづらい」なら Bad を、そうでなければ Good を出力してください。

s = gets

result = "Good";
s.length.times do |i|
  if !s[i + 1]
    break
  elsif s[i] == s[i + 1]
    result = "Bad"
    break
  end
end

puts result;

Measured memory_bytes: 1788