akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,M;
  cin>>N;
  map<string,int> A;
  rep(i,0,N){
    string S;
    cin>>S;
    if(A.count(S))
      A.at(S)++;
    else
      A[S]=1;
    }
  cin>>M;
  rep(i,0,M){
    string S;
    cin>>S;
    if(A.count(S))
      A.at(S)--;
    }
  int ans=0;
  for(auto p:A){
    int X=p.second;
    ans=max(ans,X);
    }
  cout<<ans;
  }


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
  
int main(void){
int N=0, M=0;
  scanf("%d%d",&N,&M);
int A[M], rem=N;
  for(int i=0;i<M;i++){
    scanf("%d",&A[i]);
    rem = rem - A[i];
  }
  if(rem>=0)
    printf("%d",rem);
  else
    printf("-1");
  return 0;
}

Measured memory_bytes: 1764
#include <iostream>
#include<bits/stdc++.h>
#define inf 1e9
using namespace std;
void cp(string s1,string s2,int k){
    int l=s2.length();
int dp[k+1][l+1];
for(int i=0;i<=k;i++)
dp[i][0]=0;
for(int i=0;i<=l;i++)
dp[0][i]=0;
for(int i=1;i<=k;i++){
    for(int j=1;j<=l;j++)
    {
        if(s1[i-1]==s2[j-1])
        dp[i][j]=1+dp[i-1][j-1];
        else
        dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    }

}
int index= dp[k][l];
char lcs[index+1];
lcs[index]='\0';
int i=k,j=l;
while(i>0 && j>0){
    if(s1[i-1]==s2[j-1]){
        lcs[index-1]=s1[i-1];
        i--;j--;index--;

    }
    else if(dp[i-1][j]>dp[i][j-1])
    i--;
    else
    j--;
}
cout<<lcs;
    }
    

int main() {
    string s1,s2;
    cin>>s1;
    cin>>s2;
    int k=s1.length();

    cp(s1,s2,k);
}


Measured memory_bytes: 38812
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
//#include<queue>
//#include<utility>
using namespace std;

int main(){
    long long N,K;
    cin >> N >> K;
    vector<long long> A(N),F(N);
    //priority_queue<pair <long long, long long> > que;
    long long AFmax=0;

    for(long long i=0; i<N; i++){
        cin >> A[i];
    }
    for(long long i=0; i<N; i++){
        cin >> F[i];
    }

    sort(A.begin(),A.end());
    sort(F.begin(),F.end());
    for(long long i=0; i<N; i++){
        long long AFtmp = A[i]*F[N-i-1];
        AFmax = max(AFmax,AFtmp);
    }

    long long AFinf=0;
    while(AFinf < AFmax){
        long long AF = (long long) (AFinf + AFmax)/2;
        long long Ksum=0;
        bool flag=true;
        for(long long i=0; i<N; i++){
            long long AFtmp = A[i]*F[N-i-1];
            if(AFtmp > AF){
                Ksum += (long long) (ceil(  (double) (AFtmp-AF)/F[N-i-1] ));
                //cout << "i AFtmp AFtmp-AF F[N-i-1] Ksum " << i << " " << AFtmp << " " << AFtmp-AF << " " << F[N-i-1] << " " << Ksum << endl;
            }
            if( Ksum > K ){
                flag = false;
                break;
            }
        }
        //cout << "AFinf AFmax AF flag " << AFinf << " " << AFmax << " " << AF << " " << flag << endl; 
        if(flag){
            AFmax = AF;
        }else{
            AFinf = AF+1;
        }
    }

    cout << AFmax << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
ll ans;
void gcd(ll x, ll y)
{
	//printf("%lld %lld\n",x,y );
	if(y==0){
		ans-=x;
		return;
	}
	ans+=2*(x/y)*y;
	gcd(y,x%y);
}
int main()
{
	int i,j,k;
	ll n,x;
	slld(n);
	slld(x);
	ans=n;
	gcd(max(n-x,x),min(n-x,x));
	printf("%lld\n",ans );
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>

#define NN 100
#define SS 1000

using namespace std;
typedef long long int lint;

lint dp[NN + 1][10][SS + 1] = { 0 };

bool AOJ0097()
{
	int n, s;
	cin >> n >> s;
	if (n == 0) return false;
	
	lint sum = 0;
	for (int x = 0; x <= NN; x++) {
		sum += dp[x][n][s];
	}
	cout << sum << endl;

	return true;
}

int main()
{
	
	dp[0][0][0] = 1;
	for (int x = 0; x <= NN; x++) {
		dp[x][1][x] = 1;
	}
	for (int n = 2; n < 10; n++) {
		for (int x = 0; x <= NN; x++) {
			for (int s = x; s <= SS; s++) {
				for (int i = 1; i <= x; i++) {
					dp[x][n][s] += dp[x - i][n - 1][s - x];
				}
			}
		}
	}

	while (AOJ0097()) {

	}
	return 0;
}

Measured memory_bytes: 10060
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

R = get_int

if R < 1200
  puts 'ABC'
elsif R < 2800
  puts 'ARC'
else
  puts 'AGC'
end


Measured memory_bytes: 14324
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n; vector<pair<ll,pair<ll,ll>>> vc;
bool comp(const pair<ll,pair<ll,ll>>&a,const pair<ll,pair<ll,ll>>&b){
	return (a.fs+a.sc.fs)<(b.fs+b.sc.fs);
} 
ll dp[1005][20005];
ll maxval(ll i,ll wt){
	if(i==n) return 0;

	if(dp[i][wt]!=-1){
		return dp[i][wt];
	}
	ll an=maxval(i+1,wt);
	if(vc[i].sc.fs>=wt){
		an=max(an,maxval(i+1,wt+vc[i].fs)+vc[i].sc.sc);
	}
	return dp[i][wt]=an;
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	ll a,b,c;
	for(i=1;i<=n;i++){
		cin>>a>>b>>c;
		vc.ps({a,{b,c}});
	}
	sort(all(vc),comp);

	ll an=maxval(0,0);
	cout<<an;
	return 0;
}

Measured memory_bytes: 157440
import java.lang.Math.abs
import java.math.BigInteger

fun main(args: Array<String>) {

    repeat(readLine()!!.toInt()) {
        val sp = readLine()!!.split(" ")

        val n = sp[0].toLong()
        val (a, b, c, d) = sp.drop(1).map { it.toInt() }

        val t = Task(n, a.big, b.big, c.big, d.big)

        println(t.solve(n))
        //  println(t.solutions)
    }
}

data class Task(val n: Long, val a: BigInteger, val b: BigInteger, val c: BigInteger, val d: BigInteger) {
    val solutions = mutableMapOf<Long, BigInteger>()

    var pre = false
    fun solve(n: Long): BigInteger {
        if (solutions.containsKey(n)) return solutions[n]!!

        if (n == 0L) return BigInteger.ZERO
        if (n == 1L) return d

        val variants = mutableListOf<BigInteger>()
        variants.add(n.big * d)
        for (i in -1..1) if ((n + i) > 0 && (n + i) % 2 == 0L) {
            variants.add(abs(i) * d + solve((n + i) / 2) + a)
        }

        for (i in -2..2) if ((n + i) > 0 && (n + i) % 3 == 0L) {
            variants.add(abs(i) * d + solve((n + i) / 3) + b)
        }

        for (i in -5..5) if ((n + i) > 0 && (n + i) % 5 == 0L) {
            variants.add(abs(i) * d + solve((n + i) / 5) + c)
        }


        val ans = variants.min()!!

        solutions[n] = ans
        return ans
    }


}

private val Long.big: BigInteger
    get() = BigInteger.valueOf(this)

private val Int.big: BigInteger
    get() = this.toLong().big

private operator fun Int.times(big: BigInteger): BigInteger {
    return big.multiply(this.big)
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;
  
  if(left > right){
    cout << "Left" << endl;
  }
  else if(left == right){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	string n;
	cin >> n;
	if(n[0] == '7'){
		cout << "Yes" << endl;
	}
	else if(n[1] == '7'){
		cout << "Yes" << endl;
	}
	else if(n[2] == '7'){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e9
inline int read()
{
	int x=0;
	bool pos=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')
			pos=0;
	for(;isdigit(ch);ch=getchar())
		x=x*10+ch-'0';
	return pos?x:-x;
}
int x[11]={0,2,5,5,4,5,6,3,7,6};
int a[11],m,N;
const int MAXN=1e4+10;
int f[11][MAXN];
int n;
int dfs(int i,int j)
{
	if(f[i][j]!=-1)
		return f[i][j];
	if(j==0)
		return 1;
	if(j<0)
		return -inf;
	f[i][j]=-inf;
	for(int k=1;k<=m;++k)
		{
			if(j>=x[a[k]])
				f[i][j]=max(f[i][j],1+dfs(i,j-x[a[k]]));
		}
	return f[i][j];
}
bool better(int i,int j,int k)
{
	if(i-x[a[j]]<0)
		return false;
	if(!k)
		return true;
	if(f[a[j]][i-x[a[j]]]>f[a[k]][i-x[a[k]]])
		return true;
	if(f[a[j]][i-x[a[j]]]==f[a[k]][i-x[a[k]]] && a[j]>a[k])
		return true;
	return false;
}
int main()
{
	n=read(),m=read();
	memset(f,-1,sizeof f);
	for(int i=1;i<=m;++i)
		a[i]=read();
	int i,j,k;
	for(int i=1;i<=m;++i)
		dfs(a[i],n-x[a[i]]);
	for(i=n;i;)
		{
			k=0;
			for(j=1;j<=m;++j)
				if(better(i,j,k))
					k=j;
			i-=x[a[k]];
			putchar(a[k]+'0');
		}
	return 0;
}

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

int main(){
  int A,B;
  bool b = 1,c = 0;
  string S;
  cin >> A >> B >> S;
  for(int i=0;i<S.size();++i){
    if(i!=A&&S.at(i)=='-'){
      b = 0; break;
    }
    if(i==A&&S.at(i)=='-'){
      c = 1;
    }
  }
  if(b&&c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    cout << (abs(x - y) <= 1 ? "Brown" : "Alice" ) << "\n";
    return 0;
}


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

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

int main(void){

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

    int tmp[] = {a, b, c};
    vector<int> x(tmp, end(tmp));
    sort(x.begin(), x.end());

    int ans = 0;
    if(x[2]%2 == 0){ // 偶数
        if(x[0]%2 == 1 && x[1]%2 == 1){
            x[0]=x[0]+1;
            x[1]=x[1]+1;
            ans++;
        }else if(x[0]%2 == 0 && x[1]%2 == 1){
            x[0]=x[0]+1;
            x[2]=x[2]+1;
            ans++;
        }else if(x[0]%2 == 1 && x[1]%2 == 0){
            x[1]=x[1]+1;
            x[2]=x[2]+1;
            ans++;
        }
    }else{
        if(x[0]%2 == 0 && x[1]%2 == 0){
            x[0]=x[0]+1;
            x[1]=x[1]+1;
            ans++;
        }else if(x[0]%2 == 0 && x[1]%2 == 1){
            x[1]=x[1]+1;
            x[2]=x[2]+1;
            ans++;
        }else if(x[0]%2 == 1 && x[1]%2 == 0){
            x[0]=x[0]+1;
            x[2]=x[2]+1;
            ans++;
        }
    }
    // cout << x[0] << " " << x[1] << " " << x[2] << endl;
    ans += (2*x[2]-x[0]-x[1])/2;
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N,x;
  int ans = 0;
  bool flag = false;
  
  cin >> N >> x;
  vector<int> vec(N);
  for(int i=0;i<N;++i){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N-1;++i){
    if(x - vec.at(i) >= 0){
      x -= vec.at(i);
      ans += 1;
    }else{
      flag = true;
    }
    if(flag) break;
  }
  if(!flag && vec.at(N-1) == x) ans += 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
using System;

namespace AOJ.Volume0
{
    public class Ball
    {
        public static void Main()
        {
            int cnt = int.Parse(Console.ReadLine());
            for (int i = 0; i < cnt; i++)
            {
                var input = Console.ReadLine().Split(' ');

                int left = 0;
                int right = 0;
                bool check = true;
                for (int j = 0; j < 10; j++)
                {
                    int ball = int.Parse(input[j]);
                    if (left == 0 && right == 0) { left = ball; }
                    else
                    {
                        if (left < ball && right < ball)
                        {
                            if (left < right) { right = ball; }
                            else { left = ball; }
                        }
                        else if (left < ball) { left = ball; }
                        else if (right < ball) { right = ball; }
                        else
                        {
                            check = false;
                            break;
                        }
                    }
                }
                if (check) { Console.WriteLine("YES"); }
                else { Console.WriteLine("NO"); }
            }
        }
    }
}

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

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl

void solve() {
  ll n, m;
  cin >> n >> m;
  ll sm = 0;
  for (ll i = 0; i < m; i++) {
    ll temp;
    cin >> temp;
    sm += temp;
  }
  if (n < sm) {
    cout << -1 << '\n';
    return;
  }
  cout << (n - sm) << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	set<int> p[2], h[2];
	b = a; sort(b.begin(), b.end());
	for(int i = 0; i < n; i++){
		p[i&1].insert(a[i]);
		h[i&1].insert(b[i]);
	}
	int ans = 0;
	for(int i = 0; i < 2; i++){
		for(int v : p[i]){
			ans += h[i ^ 1].count(v);
		}
	}
	cout << ans / 2 << endl;
	return 0;
}


Measured memory_bytes: 10368
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

                
def resolve():
    N=int(input())
    b=sorted(list(pin()))
    ans=10000000
    for i in range(-100,101):
        temp=sum(map(lambda x:pow((i-x),2),b))
        ans=min(ans,temp)
    print(ans)
        #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2
4 8"""
        output = """8"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
1 1 3"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3
4 2 5"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """4
-100 -100 -100 -100"""
        output = """0"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 84972
M, D = map(int, input().split())
c = 0
for m in range(1,M+1):
  for d in range(22, D+1):
    dl = list(str(d))
    if int(dl[0]) != 0 and int(dl[0]) != 1 and int(dl[1]) != 0 and int(dl[1]) != 1:
      if int(dl[0]) * int(dl[1]) == m:
        c += 1
      
print(c)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Your code here!
    int A,B,C,D,E,F;
    int water,salt;
    double max = -1;
    
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    
    for(int i = 0; i <= 30; i++){
        for(int j = 0; j <= 30; j++){
            int tmp_water = 100*A*i + 100*B*j;
            if(tmp_water > F){
                break;
            }
            for(int z = 0; z <= 3000; z += C){
                for(int k = 0; k <= 3000; k += D){
                    if(z + k > (F - tmp_water) || (tmp_water/100)*E < z + k){
                        break;
                    }
                    double tmp = (100*(z+k))/((double)tmp_water + z + k);
                    if(tmp > max){
                        max = tmp;
                        water = tmp_water;
                        salt = z + k;
                    }
                }
            }
        }
    }
    
    printf("%d %d\n",water + salt,salt);
}


Measured memory_bytes: 1724
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool sortbysecdesc(const pair<string,ll> &a,const pair<string,ll> &b)
{
       return a.second>b.second;
}
int main() {
	int n;cin>>n;
	int arr[n];
	loop(n,i,0)cin>>arr[i];
	int cnt=0,res=0;
	loop(n,i,1){
		if(arr[i]>arr[i-1])res=max(res,cnt),cnt=0;
		else cnt++;
	}
	res=max(res,cnt);
	cout<<res<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
const ll mod = 1000'000'007;
const ll maxn = 123456;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    n *= 4;
    h = min(h, q * 2);
    s = min(s, h * 2);
    d = min(d, s * 2);
    ll ans = d * (n / 8);
    n %= 8;
    ans += s * (n / 4);
    n %= 4;
    ans += h * (n / 2);
    n %= 2;
    ans += q * (n / 1);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int min(int a,int b){
  if(b<a)return b;
  return a;
}
int main(){
  string s;
  int a=0;
  int b=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')a++;
    else b++;
  }
  int ans=2*min(a,b);
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;
    bool ok = true;
    auto cango = [&](int from, int to) -> bool {
        int i = from;
        for (;;) {
            if (i == to) {
                return true;
            }
            if (i > to) {
                return false;
            }
            if (s[i+1] == '.') {
                i++;
            }
            else if (i+2 <= to && s[i+2] == '.') {
                i += 2;
            }
            else {
                return false;
            }
        }
    };
    if (c > d) {
        bool canswap = false;
        for (int i=b-1; i+1<=c; i++) {
            if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
                ok &= cango(a, i);
                ok &= cango(b, i+1);
                a = i+2;
                b = i+1;
                canswap = true;
                break;
            }
        }
        ok &= canswap;
    }
    ok &= cango(a, c);
    ok &= cango(b, d);
    cout << (ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 592
import sys

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, read().split())
    adj = [list() for _ in range(n)]
    for _ in range(m):
        a, b = map(int, read().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    loop = True
    bridge = 0
    while loop:
        loop = False
        for i, ai in enumerate(adj):
            if len(ai) == 1:
                adj[i] = []
                adj[ai[0]].remove(i)
                bridge += 1
                loop = True
    print(bridge)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>

#define INF 100000000
using namespace std;

int n,W;
int mv[110][1000000];
int main(){
  scanf("%d%d", &n, &W);
  map<long long int, long long int>dp;
  dp[0] = 0;
  long long int ans = 0;
  for(int i = 0; i < n; i++){
    long long int w,v;
    scanf("%lld%lld", &w, &v);
    auto memo = dp;
    for(auto x : memo){
      if(x.first + w <= W){
        dp[x.first + w] = max(dp[x.first + w], x.second + v);
        ans = max(ans, dp[x.first + w]);
      }
    }
  }
  printf("%lld\n", ans);
}



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

using namespace std;


#define PI 3.14159265
#define int long long

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
 
 
int binpow(int a, int n){
 
	int res = 1;
	
	while(n){
		if(n & 1)
			res *= a;
		
		a *= a;
		n >>= 1;
 
		a %= MOD;
		res %= MOD;
	}
 
 
	return res;
}
 
int MMI(int a){
	return binpow(a, MOD - 2);
}


int lcm(int a, int b, int gcd){
	return (((a * b) % MOD) * MMI(gcd)) % MOD;
}


main(){

	
	int n; cin >> n;

	vector <int> a(n);

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

	map <int, int> current;

	// int t = a[0];

	// for(int i = 2; i * i <= t; i++){
	// 	if(t % i == 0){
	// 		while(t % i == 0){
	// 			t /= i;
	// 			current[i]++;
	// 		}
	// 	}
	// }

	// if(t != 1) current[t]++;



	int LCM = 1;

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

		map <int, int> GCD;

		int temp = a[i];

		for(int j = 2; j * j <= temp; j++){
			if(temp % j == 0){
				while(temp % j == 0){
					temp /= j;
					GCD[j]++;
				}
			}
		}

		if(temp != 1) GCD[temp]++;

		int gcd = 1;

		for(auto it : GCD){
			for(int j = 0; j < min(it.second, current[it.first]); j++){
				gcd *= it.first;
				gcd %= MOD;
			}
			
			current[it.first] = max(current[it.first], it.second);
		}

		LCM = lcm(LCM, a[i], gcd);
	}


	int ans = 0;

	for(int i = 0; i < n; i++){
		ans += (LCM * MMI(a[i])) % MOD;
		ans %= MOD;
	}


	cout << ans << endl;

	
	return 0;
}

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

int main() {
  int a, n;
  cin >> a >> n;
  vector<int> vec(n);
  for(int i = 0;i < n;i++) {
    cin >> vec.at(i);
    a = a - vec.at(i);
  }
  if(a <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3772
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    vi a(n), b(n);
    for (int i = 0; i < n; ++i) {
        a[i] = (i + 1) * 30000;
        b[i] = (n - i) * 30000;
    }
    for (int i = 0; i < n; ++i) {
        a[p[i]] += i;
        b[p[i]] += i;
    }
    print(a);
    print(b);
    return 0;
}

Measured memory_bytes: 896
#include<iostream> 
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define c(a) cout<<a<<" ";
int main(){c("1407 38");int t=2;r(i,38){c(1);r(j,37){c(t);t++;}}r(i,37){r(j,37){c(i+2)r(l,37)c(37*l+39+(j+i*l)%37)}}}

Measured memory_bytes: 3552
// abc135_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#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 << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll K;
    ll X, Y;
    cin >> K;
    cin >> X >> Y;

    ll x = abs(X);
    ll y = abs(Y);
    if (x < y) swap(x, y);

    if ((x + y) % 2 == 1 && K % 2 == 0){
        print(-1);
        return 0;
    }

    vector<P> ans;

    ll a=0, b=0;

    // 距離が2K以下になるまで進む
    while((abs(x - a) + abs(y - b)) > 2 * K){
        if(a + K <= x){
            a += K;
        } else {
            b += (K + a - x);
            a = x;
        }
        ans.emplace_back(a, b);
    }

    // 残りが奇数だといけないので調整が必要
    if ((abs(x - a) + abs(y - b)) % 2 == 1){
        if(a + K <= x){
            a += K;
        } else {
            b += (K + a - x);
            a = x;
        }
        ans.emplace_back(a, b);
    }

    // この時点でたどり着いている可能性も
    if (abs(x - a) + abs(y - b) != 0){

        // 半分まで行って、そこから寄り道
        // 寄り道から帰ってきて半分進む
        ll half = (abs(x - a) + abs(y - b)) / 2;

        if (b > y) // y方向に行き過ぎてしまったら、（正負の管理が面倒なので分岐）
        {
            b -= half;
            a += K - half;
            ans.emplace_back(a, b);
            a -= K - half;
            b -= half;
            ans.emplace_back(a, b);
        }
        else {
            bool y_flag;
            if (a + half <= x) {
                a += half;
                b -= K - half;
                y_flag = true;
            } else {
                b += (half + a - x);
                a = x;
                a += K - half;
                y_flag = false;
            }
            ans.emplace_back(a, b);

            if (y_flag) {
                b += K - half;
            } else {
                a -= K - half;
            }

            if (a + half <= x) {
                a += half;
            } else {
                b += (half + a - x);
                a = x;
            }
            ans.emplace_back(a, b);
        }
    }

    print(ans.size());
    for (auto p: ans){
        ll a = p.first;
        ll b = p.second;

        if (abs(X) < abs(Y)) swap(a, b);
        if (X < 0) a *= -1;
        if (Y < 0) b *= -1;

        print(a, b);
    }

    return 0;
}




Measured memory_bytes: 5484
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_H=300,MAX_W=300;
ll H,W,K;
string s[MAX_H];
ll a[MAX_H][MAX_W];
void cp(ll i,ll j){
	REP(k,W){
		a[i][k]=a[j][k];
	}
}
ll cnt=1;
bool flg[MAX_W];
ll dfs(ll i,ll k){
	flg[k]=true;
	if(a[i][k]!=-1){
		return a[i][k];
	}
	if(s[i][k]=='#'){
		a[i][k]=cnt++;
	}else if(k>0&&a[i][k-1]!=-1){
		a[i][k]=dfs(i,k-1);
	}else{
		a[i][k]=dfs(i,k+1);
	}
	return a[i][k];
}
void slv(ll i){
	memset(flg,false,sizeof(flg));
	REP(k,W){
		if(!flg[k]){
			dfs(i,k);
		}
	}
}
bool chk(ll i){
	REP(k,W){
		if(s[i][k]=='#')return true;
	}
	return false;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>H>>W>>K;
	REP(i,H)cin>>s[i];
	memset(a,-1,sizeof(a));
	ll st;
	REP(i,H)REP(j,W){
		if(s[i][j]=='#'){
			st=i;
		}
	}
	slv(st);
	for(ll i=st-1;i>=0;i--){
		if(chk(i)){
			slv(i);
		}else{
			cp(i,i+1);
		}
	}
	FOR(i,st+1,H){
		if(chk(i)){
			slv(i);
		}else{
			cp(i,i-1);
		}
	}
	REP(i,H){
		REP(j,W){
			if(j)cout<<' ';
			cout<<a[i][j];
		}
		cout<<endl;
	}
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b+c || b==a+c || c==a+b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

csum = [0 for _ in range(N+1)]
for i in range(N):
  csum[i+1] = csum[i] + A[i]

B = []
for i in range(1,N+1):
  for j in range(i,N+1):
    B.append(csum[j]-csum[i-1])
#print(B)

ans = 0
BB = B 
for i in range(41,-1,-1):
  BB_ = []
  for b in BB:
    if (b>>i)&1 == 1:
      BB_.append(b)
  if len(BB_) >= K:
    ans += (1<<i)
    BB = BB_
print(ans)


Measured memory_bytes: 66044
#include<bits/stdc++.h>
using namespace std;
int main()
{
 #define int long long
 int n,w;
 cin>>n>>w;
 int val[n],weight[n]; 
 for(int i=0;i<n;i++)
 {
   cin>>weight[i]>>val[i];
 }
  int knapsack[n+1][w+1];
  for(int i=0;i<=n;i++)
    for(int j=0;j<=w;j++)
    {
      if(i==0 or j==0)
        knapsack[i][j]=0;
      else
      {
        if(j<weight[i-1])
          knapsack[i][j]=knapsack[i-1][j];
        else
        {
         knapsack[i][j]=max(knapsack[i-1][j],val[i-1]+knapsack[i-1][j-weight[i-1]]); 
        }
      }
    }
  //for(int i=0;i<=n;i++)
  //{
  //	for(int j=0;j<=w;j++)
  //	{
  //		cout<<knapsack[i][j]<<" ";
  //	}
  //	cout<<"\n";
  //}
  cout<<knapsack[n][w];                                                             
}  


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

lower = max(X)
upper = min(Y)
ans ='War'
  
for z_i in range(x+1,y+1):
  if lower < z_i <= upper:
    ans ='No War'
    
print(ans)

Measured memory_bytes: 3064
import fileinput
for n in fileinput.input():
    n = int(n)
    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                for l in range(10):
                    if i + j + k + l == n:
                        cnt += 1
    print(cnt)

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

using namespace std;

class Node {
public:
	int key;
	Node *left;
	Node *right;

	Node(int key) {
		this->key = key;
		left = right = NULL;
	}
};

Node* insert(Node *pRoot,Node *z) {
	Node *y = NULL;
	Node *x = pRoot;

	while (x != NULL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	if (y == NULL) {
		pRoot = z;
	}
	else if (z->key < y->key) {
		y->left = z;
	}
	else {
		y->right = z;
	}

	return pRoot;
}

void printInOrder(Node *pCur) {

	if (pCur == NULL) {
		return;
	}
	printInOrder(pCur->left);
	cout << " " << pCur->key;
	printInOrder(pCur->right);
}

void printPreOrder(Node *pCur) {

	if (pCur == NULL) {
		return;
	}
	cout << " " << pCur->key;
	printPreOrder(pCur->left);
	printPreOrder(pCur->right);
}

void free(Node *p) {

	if (p == NULL) {
		return;
	}
	if (p->left != NULL) {
		p = p->left;
	}
	if (p->right != NULL) {
		p = p->right;
	}

	delete p;
	p = NULL;
}

int main() {
	int m, z;
	string cmd;
	Node *pRoot = NULL;

	cin >> m;
	for (int i = 0; i < m; ++i) {
		cin >> cmd;
		if (cmd == "insert") {
			cin >> z;
			Node *pNode = new Node(z);
			pRoot = insert(pRoot, pNode);
		}
		else {
			printInOrder(pRoot);
			cout << endl;
			printPreOrder(pRoot);
			cout << endl;
		}
	}
	free(pRoot);

	return 0;
}


Measured memory_bytes: 18768
import itertools
import math
import sys
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
approved = True
for i in a:
    if i % 2 == 0 and i % 3 != 0 and i % 5 != 0:
        approved = False
        break
if approved:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3316
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,a[300000];
map<ll,ll> m;
int main(){
    cin >> n;
    a[0] = 0;
    REP(i,n) {
        cin >> a[i + 1];
    }
    REP(i,n) {
        a[i + 1] += a[i];
    }

    REP(i,n + 1) {
        if(m.find(a[i]) == m.end()) {
            m[a[i]] = 1;
        }else{
            m[a[i]]++;
        }
    }

    ll ans = 0;
    for(auto v : m) {
        if(v.second > 1) {
            ans += v.second * (v.second - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14336
import java.util.*;
import java.lang.*;

public class Main {
    
    static int s;
    static int[] a;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        s = sc.nextInt();
        a = new int[10000000];
        int i = 0;
        boolean issame = false;
        
        while(true) {
            if (i == 0) {
                a[i] = s;
            } else {
                if (a[i-1] % 2 == 0) {
                    a[i] = a[i-1] / 2;
                } else {
                    a[i] = 3 * a[i - 1] + 1;
                }
            }
            //System.out.println(a[i]);
            for (int k = 0; k < i; k++) {
                if (a[k] == a[i]) {
                    issame = true;
                    break;
                }
            }
            if (issame) {
                break;
            }
            i++;
        }

        System.out.println(i + 1);
    }

}

Measured memory_bytes: 62676
#include <iostream>
#include <climits>
#include <array>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define MODULE 1000000007
#define MP make_pair

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9
const int MAXN = 100001;

/*struct edge {   //structとclassの違いは，メンバが初期状態でpublicとなっているかprivateとなっているか
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];*/


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

//-----Template---------
int n,k,x,y;
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>x>>y;
    int res=0;
    if(n<=k){
        res=x*n;
    }else{
        res=x*k+(n-k)*y;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

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

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	map<int,int> even,odd;
	for(int i = 0; i < n; i++){
		if(i%2==0) odd[v[i]]++;
		else even[v[i]]++;
	}

	int even_1=0,even_2=0,odd_1=0,odd_2=0;
	int e1=0,e2=0,o1=0,o2=0;
	int cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			even_1 = itr->first;
		}
	}
	e1 = cnt;
	cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt && itr->first != even_1){
			cnt = itr->second;
			even_2 = itr->first;
		}
	}
	e2 = cnt;

	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			odd_1 = itr->first;
		}
	}
	o1= cnt;
	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt && itr->first != odd_1){
			cnt = itr->second;
			odd_2 = itr->first;
		}
	}
	o2=cnt;

	//cout << "ev1 = " << even_1 << " ev2 = " << even_2 << endl;
	//cout << "odd1 = " << odd_1 << " odd2 = " << odd_2 << endl;

	if(even_1 == odd_1){
		cout << min(n/2-e1+n/2-o2, n/2-e2+n/2-o1) << endl;
	}else{
		cout << n/2-e1 + n/2-o1 << endl;
	}

	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using namespace std;

using lli = long long int;
using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N, M;
lli ans = 1;
lli Cnb;

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

	cin >> N >> M;
	if(N > M){
		if(N-M > 1){
			ans = 0;
		}else{
			for(int i = 2; i <= N; i++){
				ans = (ans*i) % 1000000007;
			}
			for(int i = 2; i <= M; i++){
				ans = (ans*i) % 1000000007;
			}
			if(N==M){
				ans = (ans*2) % 1000000007;
			}
		}
	}else{
		if(M-N > 1){
			ans = 0;
		}else{
			for(int i = 2; i <= M; i++){
				ans = (ans*i) % 1000000007;
			}
			for(int i = 2; i <= N; i++){
				ans = (ans*i) % 1000000007;
			}
			if(N==M){
				ans = (ans*2) % 1000000007;
			}
		}
	}

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


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

using namespace std;

#define LIMIT 100
typedef pair<int, int> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  int a[52] = {0};

  int ma = INT_MIN, mi = INT_MAX;
  int imax, imin;

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > ma){
      ma = a[i];
      imax = i;
    }
    if(a[i] < mi){
      mi = a[i];
      imin = i ;
    }
  }

  if(abs(ma) > abs(mi)){
    std::cout << 2*n-1 << std::endl;
    for (int i = 0; i < n; ++i) {
      printf("%d %d\n", imax+1, i+1);
      a[i] += a[imax];
    }
    for (int i = 1; i < n; ++i) {
      printf("%d %d\n", i, i+1);
      a[i] += a[i-1];
    }
  }
  else {
    std::cout << 2*n-1 << std::endl;
    for (int i = 0; i < n; ++i) {
      printf("%d %d\n", imin+1, i+1);
      a[i] += a[imin];
    }
    for (int i = n-2; i >= 0; --i) {
      printf("%d %d\n", i+2, i+1);
      a[i] += a[i+1];
    }
  }

  //for (int i = 0; i < n; ++i) { cout << a[i] << " \n"[i==n-1];}



  return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

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

    int last = tmp.back();
    for (int i = last; i < m + 1; i++)
    {
        vector<int> tt = tmp;
        tt.push_back(i);
        dfs(tt);
    }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> tmp(1, 1);
    dfs(tmp);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
#define int long long
#define ff first
#define ss second
#define _lmax 1e14
#define pb push_back
#define all(v) v.begin(),v.end()
void print(int a)                  {              cout<<a<<'\t'<<'\n';                      }
void print(int a,int b)                {          cout<<a<<'\t'<<b<<'\t'<<'\n';             }
void print(int a,int b,int  c)             {      cout<<a<<'\t'<<b<<'\t'<<c<<'\n';          }
void print(int a,int  b,int  c,int  d)         {  cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\n'; }
void print(int a,int  b,int  c,int  d,int  e)     { cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\t'<<e<<'\n';}
void print(vector<int> &a)                        { for(auto i:a)  cout<<i<<" ";   nl;      }
void print(string s)                              { cout<<s;nl;                             }

void solve()
{
    int n;  cin>>n;
    int a[n][3];
    for(int i=0 ; i<n ; i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];

    int dp[n][3],ans=max({a[0][0] , a[0][1] , a[0][2]});
    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],
        ans = max({dp[i][0] , dp[i][1] , dp[i][2]});
    print(ans);
}

int32_t main()
{
   // ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    // int t;  cin>>t; while(t--)
    solve();
}/*

   vector<int> a = {157,26,9,-5782,0,5,17,-642,318,9,70,9,3210,-39,821,94,72,8,9,53,12,3,23};







*/


















Measured memory_bytes: 8260
import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
tree = [[] for _ in range(N)]
for _ in range(N - 1):
	a, b = list(map(int, input().split()))
	a -= 1
	b -= 1
	tree[a].append(b)
	tree[b].append(a)

que = deque()
que.append(0)
max_length = 0
max_loc = 0
length_list = [100000000]*N
length_list[0] = 0
while len(que) > 0:
	node = que.popleft()
	for node_next in tree[node]:
		if length_list[node_next] > length_list[node]:
			length_list[node_next] = length_list[node] + 1
			if max_length < length_list[node_next]:
				max_length = length_list[node_next]
				max_loc =node_next
			que.append(node_next)

que = deque()
que.append(max_loc)
max_length = 0
length_list = [100000000]*N
length_list[max_loc] = 0
while len(que) > 0:
	node = que.popleft()
	for node_next in tree[node]:
		if length_list[node_next] > length_list[node]:
			length_list[node_next] = length_list[node] + 1
			max_length = max(max_length, length_list[node_next])
			que.append(node_next)
max_length += 1

if max_length % 3 == 2:
	print("Second")
else:
	print("First")

Measured memory_bytes: 116424
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	vector<int>v;
	if (S[0] == '0')v.push_back(0);
	char now;
	int cnt = 1;
	rep(i, N - 1) {
		if (S[i] == S[i + 1])cnt++;
		else {
			v.push_back(cnt);
			cnt = 1;
		}
	}
	v.push_back(cnt);
	if (S[N - 1] == '0')v.push_back(0);
	vector<int>d(v.size() + 1, 0);
	rep(i, v.size())d[i + 1] = d[i] + v[i];
	int left = 1;
	int right = 2 * K + 1;
	int ans = -INF;
	while (right <= d.size()) {
		ans = max(ans, d[right] - d[left - 1]);
		left += 2;
		right += 2;
	}
	if (ans == -INF)ans = N;
	cout << ans << endl;
}

Measured memory_bytes: 2164
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    int ans = 0;
    for (int a = 0; a <= k; ++a) {
        for (int b = 0; b <= k; ++b) {
            if ((a + b) > k || (a + b) > n)
                continue;

            vector<int> t;
            for (int i = 0; i < a; ++i) {
                t.push_back(v[i]);
            }

            for (int i = 0; i < b; ++i) {
                t.push_back(v[n - 1 - i]);
            }

            sort(t.begin(), t.end());
            int valueSum = 0;
            for (int i = 0; i < t.size(); ++i) {
                if (i < (k - a - b) && t[i] < 0)
                    continue;

                valueSum += t[i];
            }

            ans = max(valueSum, ans);
        }
    }

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

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
    int a[1000];
    int b[1000];
    int n;
    int m;
    int x;
    bool yes(int v)
    {
         for (int i=1;i<=m;i++)
             if (v==b[i]) return true;
         return false;
     }    
int main(){
    cin>>n>>m>>x;
    for (int i=1;i<=m;i++)
        cin>>b[i];
    int cnt=0;
    int ccnt=0;
    for (int i=x+1;i<=n;i++)
    {
        if (yes(i)) cnt++;
    }
    for (int i=x-1;i>0;i--)
    {
        if (yes(i)) ccnt++;
    }
    cout<<min(cnt,ccnt)<<endl;
    return 0;
} 

Measured memory_bytes: 256