akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var list = Console.ReadLine().Split(' ');
        var ps = new int[n];
        for (int i = 0; i < ps.Length; ++i)
            ps[i] = int.Parse(list[i]);

        int need = 0;
        for (int i = 0; i < ps.Length; ++i)
        {
            if (ps[i] != i + 1)
            {
                ++need;
                if (need > 2)
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
        }

        Console.WriteLine("YES");
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());

        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());

        if(b==1) {
            System.out.println(0);
        }
        else if(b<=a) {
            System.out.println(1);
        }
        else {
            b-=a;
            if(b%(a-1) == 0) {
                System.out.println(b/(a-1) + 1);
            }
            else {
                System.out.println(b/(a-1) + 2);
            }
        }
    }
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
int p[200010];
int main(){
	int n,k;
	double x,y;
	cin>>n>>k;
	y=k;
	for(int i=1;i<=n;i++) cin>>p[i];
	for(int i=1;i<=k;i++) y+=p[i];
	x=y;
	for(int i=1;i+k<=n;i++){
		y+=p[i+k]-p[i];
		x=max(x,y);
	}
	printf("%lf",x/2);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = input().split()
for i in range(0,N):
	a[i] = int(a[i])
a.sort()
t = 0
flag = 1
sum_a = 0
for i in range(0,N-1):
	sum_a += a[i]
	if sum_a*2 < a[i+1]:
		t = i+1

			
print(N-t)

Measured memory_bytes: 11372
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	string s = "ABC" , s1;
	cin >> s1;
	if(s1 == s)cout << "ARC" << endl;
	else cout << s << endl;
	return 0;
}

Measured memory_bytes: 3596
n = int(input())
h = [0] + list(map(int,input().split())) + [0]
check = 0
while True:
    checkcheck = check
    c = False
    for i in range(n+1):
        if h[i] == 0 and h[i+1] != 0 and c == False:
            check += 1
            c = True
        if h[i] != 0:
            h[i] -= 1
        if h[i+1] == 0:
            c = False
    if check == checkcheck:break
print(check)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#define int long long
#define re(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin,v.end()
using namespace std;
typedef pair<int,int>P;
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int n,m;
vector<P>v[100090];
int ans,x,y;

signed main(){
  cin>>n>>m;
  int a[n];
  UnionFind U(n+10);
  re(i,n)cin>>a[i];
  re(i,m){
    cin>>x>>y;
    x--;y--;
    U.unite(x,y);
  }
  re(i,n){
    v[U.find(i)].push_back(P(i,a[i]));
  }
  re(i,n+10){
    set<int>st;
    re(j,v[i].size()){
      st.insert(v[i][j].first+1);
      st.insert(v[i][j].second);
    }
    int x=v[i].size()*2;
    ans+=(x-st.size());
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9460
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	x := make([]int, n+1)
	for i := 0; i < m; i++ {
		l, r := iScan()-1, iScan()
		x[l]++
		x[r]--
	}
	for i := 1; i < n+1; i++ {
		x[i] += x[i-1]
	}
	ans := 0
	for _, v := range x {
		if v == m {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main() {

  int A;
  cin >> A;

  int B;
  cin >> B; 

  if((A + B) % 2 == 0){
      cout << (A + B) / 2 << endl;
  }

  else{
      cout << "IMPOSSIBLE" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    double l;
    cin>>l;
    cout << fixed << setprecision(10);
    double w = l/3;
    cout<<w*w*w<<endl;
}

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

using namespace std;

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

int N, A[200005];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  ll sum = 0, xor2 = 0, res = 0;
  int j = 1;
  for (int i = 1; i <= N; i++) {
    while ((sum + A[i]) != (xor2 ^ A[i])) {
      sum -= A[j];
      xor2 ^= A[j];
      j++;
    }
    sum += A[i];
    xor2 ^= A[i];
    res += i - j + 1;
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	char ch;
	cin>>ch;
	if(ch>='a'&&ch<='z')
		cout<<'a';
	else 
		cout<<'A';
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const int INF=1e9;
const ll MOD=1e9+7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]>rank[ry]) par[ry]=rx;
        else par[rx]=ry;
        if(rank[rx]==rank[ry]) rank[ry]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    int cnt(int n){
        int res=0;
        for(int i=0;i<n;++i){
            if(root(i)==i) res++;
        }
        return res;
    }
};

ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
int main(){
    int N;cin>>N;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        mp[a]++;
    }
    int ans=0;
    for(auto it:mp){
        if(it.second%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <cmath>
using namespace std;

class Xor128 {
	unsigned static int x, y, z, w;
public:
	Xor128() {
		x = 31103110, y = 123456789, z = 521288629, w = 88675123;
	}

	unsigned int rand()
	{
		unsigned int t;
		t = (x ^ (x << 11)); x = y; y = z; z = w;
		return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
	}
};
unsigned int Xor128::x, Xor128::y, Xor128::z, Xor128::w;
Xor128 xor128;

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

	vector<long long>A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
		
	/*N = 1000;
	A.resize(N);
	for (int i = 0; i < N; i++)A[i] = (int)xor128.rand();*/

	long long ans = -1e18;

	long long tmp1,tmp2;

	tmp1 = 0;
	for (int i = 0; i < N; i += 2)if(A[i]>0)tmp1 += A[i];
	tmp2 = 0;
	for (int i = 1; i < N; i += 2)if (A[i]>0)tmp2 += A[i];

	long long tmp = max(tmp1, tmp2);
	bool mode = tmp1 >= tmp2;

	if (tmp == 0) {
		int max_value = -1e9-1;
		int target;
		for (int i = 0; i < N; i++) {
			if (max_value < A[i]) {
				max_value = A[i];
				target = i;
			}
		}

		cout << max_value << endl;
		cout << N - 1 << endl;
		for (int i = 0; i < N - 1 - target; i++)cout << N - i << endl;
		for (int i = 0; i < target; i++)cout << 1 << endl;
	}
	else {
		cout << tmp << endl;
		vector<int>ans;
		if (mode && N % 2 == 0) {
			ans.push_back(N);
			A.pop_back();
			N--;
		}
		else if (mode == false) {
			if (N % 2) {
				ans.push_back(N);
				A.pop_back();
				N--;
			}
			ans.push_back(1);
			A.erase(A.begin());
			N--;
		}

		int cnt;
		cnt = 0;
		while(1) {
			if (A.back() > 0 && cnt % 2 == 0)break;
			ans.push_back(A.size());
			A.pop_back();
			N--;
			cnt++;
		}
		cnt = 0;
		while (1) {
			if (A.front() > 0 && cnt % 2 == 0)break;
			ans.push_back(1);
			A.erase(A.begin());
			N--;
			cnt++;
		}

		for (int i = 0; i < N; i += 2) {
			if (A[i] < 0) {
				ans.push_back(i + 1);
				A[i] = A[i - 1] + A[i + 1];
				A.erase(A.begin() + i + 1);
				A.erase(A.begin() + i - 1);

				i -= 2;
				N -= 2;
			}
		}
		for (int i = 0; i < N / 2; i++)ans.push_back(2);
		//cerr << A.size() << " " << N << endl;
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//AtCoder ABC118 B - Foods Loved by Everyone
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N,M; cin>>N>>M;
    unordered_map<ll,ll> fnmap;
    for(ll i=0;i<N;++i){
        ll k; cin>>k;
        for(ll ai=0;ai<k;++ai){
            ll a; cin>>a;
            ++fnmap[a];
        }
    }
    ll ans=0;
    for(const auto& fn:fnmap){
        if(fn.second==N) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int a,b ;
	cin >> a >> b ;
	cout << a*(a-1)/2+b*(b-1)/2 ;
	cout << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<vector<int>> seen(1005,vector<int>(1005,100000000));
vector<string> v(1005);
int now=0;
int h,w;
queue<tuple<int,int,int>> q;

void dfs(int x,int y,int z){
    bool b=1;
    if(seen[x][y]<z) b=0;
    if(b)seen[x][y]=z;
    if(b)rep(dir,4){
        int nh=x+dx[dir];
        int nw=y+dy[dir];
        if (nh < 0 || nh >= h || nw < 0 || nw >= w) continue;
        if (v[nh][nw] == '#') continue;
        if (seen[nh][nw]==z) continue;
        dfs(nh, nw,z);
    }
    if(b)rep(i,5)rep(j,5){
        int nh=x+i-2;
        int nw=y+j-2;
        if (nh < 0 || nh >= h || nw < 0 || nw >= w) continue;
        if (v[nh][nw] == '#') continue;
        if(seen[nh][nw]>=z+1){
            seen[nh][nw]=min(seen[nh][nw],z+1);
            q.push(make_tuple(nh,nw,z+1));
        }
    }
}

int main(){

  cin >> h >> w;
  P s,g;
  cin >> s.first >> s.second >> g.first >> g.second;
  
  rep(i,h) cin >> v[i];
  s.first--;s.second--;g.first--;g.second--;
  q.push(make_tuple(s.first,s.second,0));
  while(!q.empty()){
      tuple<int,int,int> tu=q.front();q.pop();
      dfs(get<0>(tu),get<1>(tu),get<2>(tu));
  }
 if(seen[g.first][g.second]!=100000000)cout << seen[g.first][g.second] << endl;
 else cout << -1 << endl;
  

}


Measured memory_bytes: 9872
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

#include <complex>
typedef complex<double> Point;
const double EPS = 1e-8;

// 入力ストリームから実数二つをとって Point へ
istream& operator >> ( istream &s, Point &a )
{
	double r, i;
	s >> r >> i;
	a = Point( r, i );
	return s;
}

// 外積（クロス積）
double cross( const Point &a, const Point &b )
{
	return a.real() * b.imag() - a.imag() * b.real();
}

// CCW 関数　a -> b -> c と進むとき、反時計回りなら 1, 直進なら 0, 時計回りなら -1
// include : cross
int ccw( const Point &a, const Point &b, const Point &c )
{
	if ( cross( ( b - a ), ( c - a ) ) < -EPS )
	{
		return -1;
	}
	else if ( EPS < cross( ( b - a ), ( c - a ) ) )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

// 点 p が多角形 qs の内部にあるか ( Winding Number Algorithm) :TODO
// include : ccw
bool point_in_polygon( const Point &p, const vector<Point> &qs )
{
	const int N = qs.size();
	
	int wn = 0;
	for ( int i = 0; i < N; ++i )
	{
		const Point &s = qs[i], &t = qs[ ( i + 1 ) % N ];
		if ( s.imag() - EPS <= t.imag() && s.imag() - EPS < p.imag() && p.imag() + EPS < t.imag() ) // 上向きの辺
		{
			wn += ccw( s, p, t ) == -1;
		}
		else if ( t.imag() - EPS <= s.imag() && t.imag() - EPS < p.imag() && p.imag() + EPS < s.imag() )
		{
			wn -= ccw( t, p, s ) == -1;
		}
	}
	return wn;
};

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

	int n;
	cin >> n;
	REP( i, 0, n )
	{
		vector<Point> tri( 3 );
		REP( j, 0, 3 )
		{
			cin >> tri[j];
		}
		Point s, t;
		cin >> s >> t;

		cout << ( point_in_polygon( s, tri ) ^ point_in_polygon( t, tri ) ? "OK" : "NG" ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<climits>
#include<vector>

#define INF (1<<29)
#define all(c) (c).begin(),(c).end()

using namespace std;

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

vector<int>res;
bool check(int n,int mx){
  for(int i=mx;i>0;i--){
    if(n>=i){
      n-=i;
      res.push_back(i);
    }
  }
  return n==0;
}

int main(void){

  int n;
  cin >> n;

  int l=0,r=2*n;
  vector<int>ans;
  while(r-l>1){
    res.clear();
    int m = (r+l)/2;
    if(check(n,m)){
      r=m;
      ans=res;
    }
    else l=m;
  }
  int size = ans.size();
  for(int i=size-1;i>=0;i--)
    cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k,a[N],x[N],dp[N],ji,ans;
int main()
{
	cin>>n>>k;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)a[i+1]=s[i]-'0';
	for(int i=1;i<=n;i++)x[i]=a[i]^a[i-1];
	for(int i=1;i<=n;i++)dp[i]=dp[i-1]+x[i];
	for(int i=1;i<=n;i++)
	{
		ji^=x[i];
		int lc=(upper_bound(dp+1,dp+n+1,k*2-(!ji)+dp[i])-dp);
		ans=max(ans,lc-i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1664
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(" "))))

M = np.zeros((100, A.shape[0]))

for i in range(100):
    M[i, :] = A - (i + 1)

t = M * M


t1 = np.sum(t, axis=1)


print(int(np.min(t1)))

Measured memory_bytes: 12512
use std::io;
use std::collections::{VecDeque};

#[cfg(test)]
mod tests;

fn main() {
    // a();
    b();
    // c();
    // d();
}

fn a() {
    let mut buf = String::new();
    let handle = io::stdin();
    handle.read_line(&mut buf).unwrap();
    let n: isize = buf.trim().parse().unwrap();
    match n {
        3 | 5 | 7 => {
            println!("{}", "YES");
        },
        _ => {
            println!("{}", "NO");
        },
    }
}

fn b() { 
    let mut buf = String::new();
    let handle = io::stdin();
    handle.read_line(&mut buf).unwrap();
    let mut stock: VecDeque<u32> = buf.trim().chars()
        .map(|a| a.to_digit(10).unwrap()).collect();
    let mut num: VecDeque<isize> = VecDeque::with_capacity(3);
    for _ in 0..2 {
        let temp = stock.pop_front().unwrap(); 
        num.push_back(temp as isize);
    }
    let ideal_num = 753;
    let mut min_diff = 1000;
    for n in stock {
        num.push_back(n as isize);
        let dog_num = num[0] * 100 + num[1] * 10 + num[2];
        let diff = abs(ideal_num - dog_num);
        if min_diff > diff {
            min_diff = diff;
        }
        num.pop_front();
    }
    println!("{}", min_diff);
}

fn abs(n: isize) -> isize {
    if n >= 0 {
        n
    } else {
        -n
    }
}

fn c() { 
}
fn d() { 
}

Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for(int i=0;i<n;i++){
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        long[][] dp = new long[n+1][W+1];
        for(int i=1;i<=W;i++){
            for(int j=1;j<=n;j++){
                if(w[j-1]<=i){
                    dp[j][i] = Math.max(dp[j][i], Math.max(dp[j-1][i], v[j-1]+dp[j-1][i-w[j-1]]));
                }
                else{
                    dp[j][i] = dp[j-1][i];
                }
            }
        }
        System.out.println(dp[n][W]);
    }
}

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

using namespace std;

int main() {
  string s;
  cin>>s;
  if(s=="RRR"){
    cout<<3<<endl;
  }
  else if(s=="RRS"||s=="SRR"){
    cout<<2<<endl;
  }
  else if(s=="SSS"){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }


  
}


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

using namespace std;

int main(){

    int A,B;
    int i = 0;
    int sum = 1;

    cin >> A >> B;

    while(sum<B){
        
        sum += A-1;
        i++;
    }

    cout << i << endl;

    return 0;
}

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

using namespace std;

int n, k, a[100005], ans;

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort (a + 1, a + n + 1);
	ans = 1e9;
	for (int i = 1; i <= n - k + 1; i++) ans = min(ans, a[i + k - 1] - a[i]);
	cout << ans << endl;
	return 0;
}

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

const int INF = 100000; 

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

    int cnt = s.size() - 2;

    cout << s[0] << cnt << s[s.size()-1] << endl;

    return 0;
}


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

int N;
vector<long long int> A,B;
vector<pair<long long int, int>> dp;
long long int ans;

int main(){
     cin >> N;
     A.resize(N); B.resize(N); dp.resize(N);
     for (int i=0; i<N; ++i){
             cin >> A[i] >> B[i];
             dp[i] = make_pair(A[i] + B[i],i);
     }
     sort(dp.begin(),dp.end());
     reverse(dp.begin(),dp.end());
     for (int i=0; i<N; ++i){
             if(i%2 == 0) ans += A[dp[i].second];
             else ans -= B[dp[i].second];
     }


     cout << ans << endl;

     return 0;
}



Measured memory_bytes: 3328
from operator import itemgetter

N = int(input())
ab = []
for i in range(N):
    a, b = [int(v) for v in input().split()]
    ab.append((a + b, a, b))

ab.sort(reverse=True, key=itemgetter(0))

takahashi = 0
aoki = 0
for i in range(N):
    if i % 2 == 0:
        takahashi += ab[i][1]
    else:
        aoki += ab[i][2]

print(takahashi - aoki)

Measured memory_bytes: 22164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using vil=vector<int>;
using vii=vector<vil>;
using ll=long long;
main(){
    // cin
    int n,m;
    cin>>n>>m;
    vii l(n);
    rep(i,m){
        int k;
        cin>>k;
        rep(j,k){
            int s;
            cin>>s;
            s--;
            l.at(s).push_back(i);
        }
    }
    vil p(m);
    rep(i,m){
        cin>>p.at(i);
    }
    int ans=0;
    rep(bit,1<<n){
        vil t(m,0);
        rep(i,n){
            if(bit&(1<<i)){
                for(auto j:l.at(i)){
                    t.at(j)++;
                }
            }
        }
        bool flag=true;
        rep(i,m){
            if(t.at(i)%2!=p.at(i)){
                flag=false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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


using namespace std;


const int MAXN = 100 * 1000;






int n, a[MAXN];



int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
	    int b;
		cin >> b;
		a[i] -= b;
	}
	if (accumulate(a, a + n, 0ll) < 0)
		return cout << -1, 0;
	sort(a, a + n);
	multiset<int> s;
	s.insert(a, a + n);
	int x = 0, ans = 0;
	while (*s.begin() < 0) {
		x += *(--s.end());
		s.erase((--s.end()));
		s.insert(0);
		ans++;
		while (*s.begin() < 0 && (x + *s.begin()) >= 0) {
			x += *s.begin();
			s.erase(s.begin());
			s.insert(0);
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 1234567
int n,m;
const int MOD=998244353;
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
	ll x=1;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
inline ll rt(int a,int b)
{
	return fac[a+b]*rfac[a]%MOD*rfac[b]%MOD;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<SZ;++i) fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i)
		rfac[i-1]=rfac[i]*i%MOD;
	cin>>n>>m;
	if(n>m) swap(n,m);
	//灰线为y=x+m-n
	int px1,py1,px2,py2; ll cv1,cv2,cv=0,ans=0;
	//考虑对角线x+y=g和x+y=g+1的关系 
	for(int g=m+n-1;g>=0;--g)
	{
		{
		int r=max(g+n-m+1,0),y,u=min(g,n);
		if(r&1) y=(r+1)/2;
		else y=r/2;
		int a=y,b=g-y;
		if(y==u) cv1=rt(y,g-y)*rt(n-y,m-1-(g-y))%MOD;
		else if(px1==a)
			cv1-=(rt(px1,py1)-rt(a,b))*rt(n-px1,m-1-py1)%MOD;
		else
			cv1+=rt(a,b)*(rt(n-a,m-1-b)-rt(n-px1,m-1-py1))%MOD;
		px1=a; py1=b; cv1%=MOD;
		}
		{
		int r=g+n-m+1,y,d=max(g-m,0);
		if(r&1) y=(r-1)/2;
		else y=r/2; --y;
		if(d>y) cv2=0;
		else
		{
		int a=y,b=g-y;
		if(y==d) cv2=rt(y,g-y)*rt(n-1-y,m-(g-y))%MOD;
		else if(px2!=a)
			cv2-=(rt(px2,py2)-rt(a,b))*rt(n-1-px2,m-py2)%MOD;
		else
			cv2+=rt(a,b)*(rt(n-1-a,m-b)-rt(n-1-px2,m-py2))%MOD;
		px2=a; py2=b; cv2%=MOD;
		}
		}
		cv+=cv1+cv2; cv%=MOD;
		ans+=cv*qp(m+n-g,MOD-2)%MOD;
	}
	ans=ans%MOD*qp(rt(n,m),MOD-2)%MOD;
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}


Measured memory_bytes: 19584
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<int> v(n+1,0),dp(n+1,n+1),m(1<<26,n+1);
  for(int i=0;i<n;i++)
    v[i+1]=v[i]^(1<<(s[i]-'a'));
  dp[0]=0;
  for(int i=0;i<=n;i++){
    int b=v[i];
    m[b]=min(m[b],dp[i]);
    dp[i]=min(dp[i],m[b]+1);
    for(int j=0;j<26;j++)
      dp[i]=min(dp[i],m[b^(1<<j)]+1);
    m[b]=min(m[b],dp[i]);
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 264324
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

BC = []

for i in range(M):
    BC.append(list(map(int, input().split())))

BC.sort(key=lambda x: x[1],reverse=True)

bc = 0
a = 0
ans = 0
for i in range(N):
    if (bc < M) and (BC[bc][1] >= A[a]):
        ans += BC[bc][1]
        BC[bc][0] -= 1
        if BC[bc][0] == 0:
            bc += 1
    else:
        ans += A[a]
        a += 1

print(ans)

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

int findSumOfDigits(int n){
  int total;
  while(n>0)total+=n%10,n/=10;
  return total;
}

int main(){
  int N,total,findsum;
  cin >> N;
  total = 0;
  findsum = findSumOfDigits(N);
  if(N%findsum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  int D, G;
  int sum[11] = {}, p[11] = {}, c[11] = {}, dp[1001] = {};
  int i;
  cin >> D >> G;
  for(i = 1; i <= D; i++) {
    cin >> p[i] >> c[i];
  }
  for(i = 1; i <= D; i++) {
    sum[i] = sum[i - 1] + p[i];
  }
  for(i = 1; i <= D; i++) {
    for(int j = sum[i]; j > 0; j--) {
      for(int k = 1; k <= p[i] && k <= j; k++) {
        dp[j] = max(dp[j], dp[j - k] + k * 100 * i + (k == p[i]) * c[i]);
      }
    }
  }
  for(i = 1; dp[i] < G; i++) ;
  cout << i;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

ll dp[110][2][5];

int main() {
    string n; cin >> n;
    int K; cin >> K;
    int len = n.size();

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;

    rep(i,len) {
        int d = n[i]-'0';
        rep(j,2) rep(k,K+1) for (int l = 0; l <= (j ? 9 : d); l++) {
            if (l != 0) dp[i+1][j||(l<d)][k+1] += dp[i][j][k];
            else dp[i+1][j||(l<d)][k] += dp[i][j][k];
        }
    }
    cout << dp[len][1][K]+dp[len][0][K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x=0,cnt=0,i;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(i=0;i<a;i++){
		cnt++;
		if(b<cnt){
			x+=d;
		}
		else{
			x+=c;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->



int main()
{

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


  int n;
  cin>>n;

  ll ans = 1;

  for(int i=1; i<=n ;i++)
  {
    ans = (ans*i)%maxm;
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 3560
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100][100],d,f,g,h,i,j;
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				s[i][a]=0;
				s[a][i]=0;
				scanf("%d",&s[i][j]);
			}
		}
		s[a][a]=0;
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				s[i][a]+=s[i][j];
				s[a][i]+=s[j][i];
			}
			s[a][a]+=s[i][a];
		}
		for(i=0;i<=a;i++){
			for(j=0;j<=a;j++){
				printf("%5d",s[i][j]);
	//			if(j!=a)	printf(" ");	
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main(){
	int a , b , c;
	int d = 1;
	while(cin >> a >> b){
		d = 1;
		c = a + b;
		while(1){
			if (c / 10 >= 1){
				c = c / 10;
				d++;
			}else{
				break;
			}
		}
		cout << d << endl;
	}
	return 0;
}

Measured memory_bytes: 0
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int bp(int a, int b, int m) {
    if (b == 0) return 1;
    int x = bp(a, b / 2, m);
    x = x * x % m;
    x *= max(1ll, (b % 2) * a);
    return x % m;
}
void solve() {
    int n;
    cin >> n;
    int M = 1e9 + 7;
    int ans = bp(10, n, M);
    vi fact(n + 1);
    vi rfact(n + 1);
    fact[0] = 1;
    rep(i,1, n+ 1)fact[i] = fact[i - 1] * i % M;
    rep(i,1, n+ 1)rfact[i] = bp(fact[i], M - 2, M);
    rep(i, 1, n) {
        ans -= bp(8, n - i, M) * fact[n] %M* rfact[i]% M* rfact[n - i] % M * 2;
        ans = (ans % M + M) % M;
    }
    ans -= bp(8, n, M);
    ans -= 2;
    put((ans + M * 10) % M);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 18276
#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int inf=1000000000000000;
std::vector<int> w,s,v;
struct nod
{
	int wt;int so;int va;
};
bool cmp(nod & n1, nod & n2)
{
	return ((n1.so-n2.wt)<(n2.so-n1.wt));
}
int pre=0;
std::vector<std::vector<int>> dp;
int f(int ix, int rem)
{
	if(ix==0){return 0;}
	if(rem==inf)
	{
		return MAX((v[ix]+dp[ix-1][s[ix]]),f(ix-1,inf));
	}
	int poss1=0;
	if((rem-w[ix])>=0){poss1=(v[ix]+dp[ix-1][MIN((rem-w[ix]),s[ix])]);}
	dp[ix][rem]=MAX(poss1,dp[ix-1][rem]);
	return dp[ix][rem];
}
int solve()
{
	int n;cin>>n;
	w.pb(0);s.pb(0);v.pb(0);
	std::vector<nod> inp(n);
	REP(i,0,n-1)
	{
		cin>>(inp[i].wt)>>(inp[i].so)>>(inp[i].va);
	}
	sort(inp.begin(),inp.end(),cmp);
	dp.resize(n+1,std::vector<int>(10005,0));
	for(auto it:inp){w.pb(it.wt);s.pb(it.so);v.pb(it.va);}
	REP(i,1,n)
	{
		REP(j,0,10002)
		{
			f(i,j);
		}
		f(i,inf);
	}
	cout<<f(n,inf)<<"\n";
}
signed main(){
	//speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

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

int main() {
    vector<int> vec(3);
    rep(i, 3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    if (vec[0] + vec[1] == vec[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long f[100005] , s[100005] , th[100005];
long long mem[100005][4];
long long sol(){
	for(int i = 1; i <=3 ; i++){
		mem[i][0] = mem[0][i] = 0;
	}
	for(int i = 1 ; i <= n; i++){
		mem[i][1] = max(mem[i-1][3] + f[i] , mem[i-1][2] +f[i]);
		mem[i][2] = max(mem[i-1][1] + s[i] , mem[i-1][3] + s[i]);
		mem[i][3] = max(mem[i-1][2] + th[i] , mem[i-1][1] +th[i]);
	}
	return max(mem[n][1] , max(mem[n][2],mem[n][3]));
}
int main()
{
	cin>>n;
	for(int i = 1; i  <= n ; i++){
		cin>>f[i]>>s[i]>>th[i];
	}
	cout<<sol();
	return 0;
}



Measured memory_bytes: 5760
def main():
    n, k = list(map(int, input().split()))
    V = list(map(int, input().split()))
    ans = -1
    for i in range(c := min(n, k) + 1):
        for j in range(c - i):
            A = V[:i] + V[-j:] if j != 0 else V[:i]
            A.sort(reverse = True)
            r = k - (i + j)
            for _ in range(r):
                if len(A) == 0:
                    break
                if (a := A.pop()) >= 0:
                    A.append(a)
                    break
            ans = max(ans, sum(A))
    print(ans)



if __name__ == '__main__':
    main()


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

#define pb push_back

using namespace std;

int n, x;
int used[2000005];
vector <int> ans;

int main () {
    cin >> n >> x;
    if (n == 2 && x == 2) {
        cout << "Yes\n" << 1 << '\n' << 2 << '\n' << 3;
        exit (0); 
    }
    if (x == 1 || x == n * 2 - 1) {
        cout << "No";
        exit (0);
    }cout << "Yes\n";
    used[1] = used[n * 2 - 1] = used[x] = 1;
    int cnt = 0;
    for (int i = 2;i < n * 2;i ++) {
        if (!used[i]) {
            cnt ++;
            cout << i << ' ';
            if (cnt == n - 2) {
                cout << 1 << ' ' << x << ' ' << n * 2 - 1 << ' ';
           }
        }
    }
}


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

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

    S = S + T.at(T.size() - 1);
    if (S == T) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 3596
#define r(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#include <fstream>
#define f first
#define endl "\n"
#define s second
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
char _;
ll N;
string ans;
int mod(const int input, const int ceil) {
    return input >= ceil ? input % ceil : input;
}

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

    while(N>0){
        N--;
        ans+= (char)((N%26)+'a');
        N/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;

    return 0;
}


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

int main(){
	int max1 = 0, max2 = 0, max3 = 0, height;
	while(cin >> height) {
		if (height > max1) {
			max3 = max2;
			max2 = max1;
			max1 = height;
		}
		else if (height > max2) {
			max3 = max2;
			max2 = height;
		}
		else if (height > max3)
			max3 = height;
	}
	cout << max1 << endl;
	cout << max2 << endl;
	cout << max3 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	vector<P> v;
	rep(i, n) {
		int x, l; cin >> x >> l;
		v.push_back({ x + l,x - l });
	}
	sort(v.begin(), v.end());
	int ans = 0;
	int ri = -mod;
	rep(i, v.size()) {
		if (v[i].second < ri)continue;
		ri = v[i].first; ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }

    long ans = 0;
    for (int i = 0; i < N; i++)
    {
        sum -= A[i];
        if (sum < 0) sum += mod;

        ans += A[i] * sum;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    if (n % 2 == 1) {
        cout << "No" << endl;
        return;
    }
    REP(i, n) {
        if (i % 2 == 0) {
            if (s[i] != 'h') {
                cout << "No" << endl;
                return;
            }
        } else {
            if (s[i] != 'i') {
                cout << "No" << endl;
                return;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
fn main() {
    // 最終目標は
    // 0101...　もしくは 101010...
    // なのだから、そこからのビットの差異の少ないほうが答え。

    let input: String = read();
    let mut a = 0;
    let mut b = 0;

    for (i, c) in input.chars().enumerate() {
        if i % 2 == 0 {
            if c == '0' {
                a += 1;
            } else {
                b += 1;
            }
        } else {
            if c == '0' {
                b += 1;
            } else {
                a += 1;
            }
        }
        
    }

    let ans = if a >= b { b } else { a };

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352