akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdlib.h>
#include<string>
#include<queue>

#define MAX 1000000

using namespace std;

struct task
{
	string name;
	int time;
};

int main()
{
	int n, q, current = 0;
	queue<task> que;
	task t;
	cin >> n >> q;
	
	for (int i = 0; i < n; i++)
	{
		cin >> t.name >> t.time;
		que.push(t);
	}
	 
 	while (!que.empty())
 	{
	 	if (que.front().time <= q)
	 	{
	 		current += que.front().time;
	 		cout << que.front().name << ' ' << current << endl;
	 	}
	 	else
	 	{
	 		current += q;
	 		que.front().time -= q;
	 		que.push(que.front());
	 	}
	 	que.pop();
	}
}


Measured memory_bytes: 6328
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = list(map(int, input().split()))
a.sort()
max = max(a)
min = getNearestValue(a,max/2)

if max == min:
    print(max, getNearestValue(a[:n-1], max / 2))
else:
    print(max,getNearestValue(a,max/2))


Measured memory_bytes: 31720
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
int del[200004],cur;
int n,K,d[200004];
pair<int,int>p[20]; 
int fr(int r,int l){
	if(r<1)return 0;
	if(l<1)l=1;
	return (d[r]-d[l-1]+MOD)%MOD;
}
int main(){
	cin>>n>>K;
	for(int i=0;i<K;i++)cin>>p[i].first>>p[i].second;
	sort(p,p+K);
	for(int i=1;i<K;i++){
		if(p[i-1].second>=p[i].first)p[i].first=p[i].second+1;
	}
	d[1]=1;
	for(int i=2;i<=n;i++){
		d[i]=d[i-1];
		for(int j=0;j<K;j++)if(p[j].first<=p[j].second)
			d[i]=(d[i]+fr(i-p[j].first,i-p[j].second))%MOD;
	}
	cout<<(d[n]-d[n-1]+MOD)%MOD;
}

Measured memory_bytes: 4384
#include<stdio.h>
int max ( int a, int b) {
	if ( a > b) return a;
	return b;
}
int min ( int a, int b) {
	if ( a < b) return a;
	return b;
}
int main() {
	int n, R[200000+10];
	scanf("%d",&n);
	for ( int i = 1; i <= n; i++) {
		scanf("%d", &R[i]);
	}
	int maxv = -2000000000;
	int minv = R[1];
	for ( int i = 2 ; i <= n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
		
	}
	printf("%d\n", maxv);
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int w, h, n, x, y, a;
bool mp[111][111];

int main() {
	cin >> w >> h >> n;
	rep(q,n) {
		cin >> x >> y >> a;
		if (a==1) rep(i,x) rep(j,h) mp[i][j] = true;
		else if (a==2) reps(i,x,w) rep(j,h) mp[i][j] = true;
		else if (a==3) rep(i,w) rep(j,y) mp[i][j] = true;
		else rep(i,w) reps(j,y,h) mp[i][j] = true;
	}
	int ans = 0;
	rep(i,w) rep(j,h) if (!mp[i][j]) ans++;
	cout << ans << ln;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	long long i, N, a[5 + 1], min = 1000000000000001, cnt;

	scanf("%lld", &N);
	for (i = 0; i < 5; i++) {
		scanf("%lld", &a[i]);
		if (min > a[i])
			min = a[i];
	}

	printf("%lld", (N <= min) ? 5 : N / min + ((N % min) != 0) + 4);

	return 0;
}


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

int main() {
	int N;	//個数
  	cin >> N;
	int i;
  	int b = 1000;
  for (i = 0; N > i; i++) {
    int A;
    cin >> A;
    int j, k;
    k = A;
    
    for (j = 0; k % 2 == 0; j++) {
    k /= 2;
    }	//for finish
    if (j <= b)
      b = j;
  }//for finish
  cout << b << endl;
}

Measured memory_bytes: 256
from bisect import bisect_right
import sys
input=sys.stdin.readline


class LazySegTree():
    def __init__(self, N):
        self.INF = 2**31-1
        self.LV = (N-1).bit_length()
        self.N0 = 2**self.LV
        self.data = [0]*(2*self.N0)
        self.lazy = [0]*(2*self.N0)

    def gindex(self, l, r):
        L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()

        m = []
        for i in range(self.LV):
            if rc <= i:
                m.append(R)
            if L < R and lc <= i:
                m.append(L)
            L >>= 1; R >>= 1
        
        return m
    
    # 遅延伝搬処理
    def propagates(self, ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if not v:
                continue
            self.lazy[2*i-1] += v; self.lazy[2*i] += v
            self.data[2*i-1] += v; self.data[2*i] += v
            self.lazy[i-1] = 0

    # 区間[l, r)にxを加算
    def update(self, l, r, x):
        ids = self.gindex(l, r)
        self.propagates(ids)

        L = self.N0 + l; R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] += x; self.data[R-1] += x
            if L & 1:
                self.lazy[L-1] += x; self.data[L-1] += x
                L += 1
            L >>= 1; R >>= 1
        for i in ids:
            self.data[i-1] = max(self.data[2*i-1], self.data[2*i])
    
    # 区間[l, r)内の最小値を求める
    def query(self, l, r):
        self.propagates(self.gindex(l, r))
        L = self.N0 + l; R = self.N0 + r

        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

    def set_list(self, l, N):
        for i in range(N):
            self.data[i+self.N0-1] = l[i]
        for i in range(self.N0-1)[::-1]:
            self.data[i] = max(self.data[2*i+1], self.data[2*i+2])


def solve():
    N, D, A = map(int, input().split())
    tree = LazySegTree(N)

    m, l = zip(*sorted(tuple(map(int, input().split())) for _ in range(N)))
    tree.set_list(l, N)

    ans = 0
    for i, j in enumerate(m):
        v = tree.query(i, i+1)
        if v>0:
            c = (v+A-1)//A
            ans += c
            pos = bisect_right(m, j+2*D)
            tree.update(i, pos, -c*A)

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 115056
#include <string>
#include <vector>
#include <iostream>

using namespace std;

int W, H; vector<string> M;

const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { -1, 0, 1, 0 };

vector<vector<bool> > ok;

void rec(int x, int y)
{
	ok[y][x] = true;

	if (M[y][x] != '.')
	{
		return;
	}

	for (int dir = 0; dir < 4; dir++)
	{
		int tx = x + dx[dir];
		int ty = y + dy[dir];

		if (0 <= tx && tx < W && 0 <= ty && ty < H && ok[ty][tx] == false)
		{
			rec(tx, ty);
		}
	}
}

int main()
{
	while (true)
	{
		cin >> W >> H;

		if (W == 0 && H == 0) { break; }

		M = vector<string>(H);

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

		int b = 0, w = 0;

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (M[i][j] == '.')
				{
					ok = vector<vector<bool> >(H, vector<bool>(W, false));

					rec(j, i);

					int br = 0, wr = 0;

					for (int k = 0; k < H; k++)
					{
						for (int l = 0; l < W; l++)
						{
							if (M[k][l] == 'W' && ok[k][l] == true)
							{
								wr++;
							}

							if (M[k][l] == 'B' && ok[k][l] == true)
							{
								br++;
							}
						}
					}

					if (wr != 0 && br == 0) { w++; }
					if (br != 0 && wr == 0) { b++; }
				}
			}
		}

		cout << b << ' ' << w << endl;
	}

	return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define ll long long
#define UP(a,b,i) for(int i=(a);i<=(b);i++)
#define DOWN(a,b,i) for(int i=(a);i>=(b);i--)
#define rep(a,b,i) UP(a,b-1,i)
int ma=0x80000000;
int mi=0x7fffffff;
const ll zfc=0xffffffff;
const ll mod=1e9+7;
using namespace std;
inline void input(ll &x)
{
    x=0;
    int f=1;
    char ch=getchar();
    while(!isdigit(ch))
	{
		if(ch=='-')f=-f;
		ch=getchar();
	}
    while(isdigit(ch))
	{
		x=x*10+(ch-'0');
		ch=getchar();
	}
    x*=f;
}
inline void output(ll x)
{
	if(x<0)
    {
        x=-x;
        putchar('-');
    }
    if(x/10>0)output(x/10);
    putchar(x%10+'0');
}
#define I(n) cin>>(n);
#define O(n) cout<<(n);
#define Enter() cout<<endl;
ll z;
string st;
int main()
{
	cin>>st;
	rep(0,st.size(),i)
	if(st[i]!=st[i+1])z++;
	O(z-1);
	Enter();
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll n,k,m=0;
  cin>>n>>k;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=min(k,n);i>0;i--){
    for(int j=0;j<=i;j++){
      ll c=0;
      priority_queue<ll> p;
      ll l=j,r=i-j;
      for(int s=0;s<l;s++){
        c+=a[s];
        p.push(-a[s]);
      }
      for(int s=n-1;s>=n-r;s--){
        c+=a[s];
        p.push(-a[s]);
      }
      for(int t=0;t<k-i;t++){
        if(!p.empty()){
          if(p.top()>=0){
            c-=-p.top();
            p.pop();
          }
        }
      }
      m=max(c,m);
    }
  }
  cout<<m;
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    System.out.println(n == 1 ? 0 : 1);
  }
}


Measured memory_bytes: 27084
n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

from0 = edge[0]
flag = 'IMPOSSIBLE'
for i in from0:
    if n-1 in edge[i]:
        flag = 'POSSIBLE'
print(flag)

Measured memory_bytes: 38320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

bool hoge[300000];
vector<int> primes;

void make_prime(){
	rep(i,300000)hoge[i]=true;
	for(int i=1; i*7-1<300000; i++){
		if( hoge[i*7-1] ){
			primes.push_back(i*7-1);
			for(int j=2*(i*7-1); j<300000; j+=(i*7-1))hoge[j]=false;
		}
		if( i*7+1<300000 && hoge[i*7+1] ){
			primes.push_back(i*7+1);
			for(int j=2*(i*7+1); j<300000; j+=(i*7+1))hoge[j]=false;
		}
	}
}
int main(){
	int n;
	make_prime();
	sort(all(primes));
	while(scanf("%d",&n),n!=1){
		printf("%d:",n);
		for(int i=0; i<primes.size() && primes[i]<=n; i++)if( n%primes[i]==0 ){
			printf(" %d",primes[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1480
#include <stdio.h>
#include <string.h>

int main(void)
{
    size_t n, m;
    scanf("%zu %zu", &n, &m);
    char a[n + 1][n + 1];
    for (size_t i = 0; i < n; ++i) {
        scanf("%s", a[i]);
    }
    for (size_t i = 0; i < m; ++i) {
        char b[m + 1];
        scanf("%s", b);
        if (strstr(a[i], b) == NULL) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())
lst = [list(input().split()) for _ in range(m)]

ans = [''] * 3
for [s, c] in lst:
    s = int(s) - 1
    if ans[s] in ['', c]:
        ans[s] = c 
    else:
        print(-1)
        exit()


if n == 1:
    if m == 0:
        print(0)
        exit()
    else:
        ans = ans[0]
        print(ans)
        exit()

if n == 2 and m == 0:
    print(10)
    exit()

if n == 3 and m == 0:
    print(100)
    exit()

if ans[0] == '0':
    print(-1)
    exit()

if ans[0] == '':
    ans[0] = '1'

if ans[1] == '':
    ans[1] = '0'

if ans[2] == '':
    ans[2] = '0'

if n == 2:
    ans.pop()
ans = ''.join(ans)
print(ans)

Measured memory_bytes: 3064
/*
    f[i][j] number of split to pair use n-j vertex with subtree i
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 5100;
const int base = 1e9+7;

int n,fact[2*maxn];
ll num[maxn];
vector<int> g[maxn];

ll pw (ll a,ll n) {
    if (n==0) return 1ll;
    if (n==1) return a;
    ll tmp = pw(a,n/2);
    tmp = (tmp*tmp)%base;
    if (n%2==0) return tmp;
    return (tmp*a)%base;
}

ll Get(int n) {
    return fact[n] * pw(pw(2,n/2),base-2) % base * pw(fact[n/2],base-2) % base;
}

vector<ll> visit(int u,int pa) {
    vector<ll> f = {0,1};
    for (auto v : g[u])
        if (v!=pa) {
            //cout<<u<<" "<<v<<endl;
            auto tmp = visit(v,u);
            //for (auto inf : tmp) cout<<inf<<" ";
           // cout<<endl;
            vector<ll> now(f.size() + tmp.size());
            for (int i=1;i<f.size();i++)
                for (int j=1;j<tmp.size();j++) {
                    now[i+j] = (now[i+j] + f[i] * tmp[j] % base) % base;
                    if (j%2==0) now[i] = (now[i] - f[i]*tmp[j] % base*num[j]%base + base) % base;
                }
            f = now;
        }
    return f;
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    fact[0]=1;
    for (int i=1;i<2*maxn;i++) fact[i] = (fact[i-1] * 1ll*i) % base;
    for (int i=2;i<=n;i+=2) num[i] = Get(i);
    for (int i=1;i<n;i++) {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    auto f = visit(1,0);
    ll ans=0;
    for (int i=2;i<f.size();i+=2)
        ans = (ans + f[i] * num[i] % base) % base;
    cout<<ans<<endl;
}



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

using namespace std;

int main(){
    string n;
    cin >> n;
    int fn=0;
    for(int i=0;i<n.size();i++){
        fn += n[i] - '0';
    }
    int x = atoi(n.c_str());
    if(x%fn==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		String A[]=new String [N];
		int a=0;
		for(int i=0;i<N;i++) {
			A[i]=sc.next();
			if(A[i].equals("Y")) {
				a=1;
			}
		}
		if(a==0) {
			System.out.println("Three");
		}else {
			System.out.println("Four");
		}
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstring>
namespace Luangao
{
	const int N=510;
	bool got(){for(char c;;)if((c=getchar())=='#')return 1;else if(c=='.')return 0;}
	bool A[N][N],B[N][N];
	int n,m;
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)A[i][1]=B[i][m]=1;
		for(int i=1;i<=n;i+=2)
			for(int j=2;j<m;j++)
				A[i][j]=1;
		for(int i=2;i<=n;i+=2)
			for(int j=2;j<m;j++)
				B[i][j]=1;

		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				bool x=got();
				if(x)A[i][j]=B[i][j]=1;
			}
	}
	void solve()
	{
		initialize();
		for(int i=1;i<=n;i++,printf("\n"))
			for(int j=1;j<=m;j++)printf("%c",A[i][j]?'#':'.');
		printf("\n");
		for(int i=1;i<=n;i++,printf("\n"))
			for(int j=1;j<=m;j++)printf("%c",B[i][j]?'#':'.');
	}
}
int main()
{
	Luangao::solve();
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
int main(void){
    int i,a[5], mini=9,flag=0,x,y,z;
    
    for(i=0; i<5; i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0; i<5; i++){
            x=a[i]%10;
        if((x<mini)&&(x!=0)){
            mini=x;
            y=a[i];
        }
    }
    mini=0;
    x=0;
    i=0;
    while(1){
        if(i>4)
            break;
            
        if((a[i]==y)&&(flag==0)){
            flag=1;
            i++;
        }
        
        else{
                z = a[i] % 10;
                if(z==0)
                    x=x+a[i];
                else
                    x=x+a[i] + 10 - z;

                       
                i++;
        }
    }

     printf("%d\n",x+y);
      
     return 0;
}


Measured memory_bytes: 128
function Main(input) {
    const s = input.trim();
    const end = s.slice(-1);

    if(end === "s") {
        console.log(`${s}es`);
    } else {
        console.log(`${s}s`);
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}

signed main()
{
	ll n=read(),a=read(),b=read();
	if(a>b)swap(a,b);
	if(a%2==b%2)cout<<(b-a)/2;
	else{
		ll t1=a+(b-a-1)/2;
		ll t2=n-b+1+(b-a-1)/2;
		cout<<min(t1,t2);
	}
	return 0; 
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

cumulatives = [0] * (N + 1)

for i in range(N):
  # 右隣にCが来るAの数を数える
  if S[i:i + 2] == 'AC':
    cumulatives[i + 1] = cumulatives[i] + 1
  else:
    cumulatives[i + 1] = cumulatives[i]

for _ in range(Q):  
  l, r = map(lambda x: int(x) - 1, input().split())  # index 合わせる  
  print(cumulatives[r] - cumulatives[l])

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

int     main() {
        int N;
        long C;
        cin >>N >>C;
        vector<long> x(N+1, 0);
        vector<long> v(N+1, 0);
        for (int i=1; i<=N; i++)
                cin >>x.at(i) >>v.at(i);
        long S1=0;
        long S2=0;
        long X=0;
        long V=0;
        vector<long> L1(N+1, 0);
        vector<long> L2(N+1, 0);
        for (int i=0; i<=N; i++) {
                X =x.at(i);
                V +=v.at(i);
                S1=max(S1, V-X);
                S2=max(S2, V-X-X);
                L1.at(i)=S1;
                L2.at(i)=S2;
        }
        S1=0;
        S2=0;
        X=0;
        V=0;
        vector<long> R1(N+2, 0);
        vector<long> R2(N+2, 0);
        for (int i=N; i>=1; i--) {
                X =C-x.at(i);
                V +=v.at(i);
                S1=max(S1, V-X);
                S2=max(S2, V-X-X);
                R1.at(i)=S1;
                R2.at(i)=S2;
        }
        long S=0;
        for (int i=0; i<=N; i++) {
                S=max(S, L1.at(i)+R2.at(i+1));
                S=max(S, L2.at(i)+R1.at(i+1));
        }
        cout <<S <<endl;
        return 0;
};

Measured memory_bytes: 4992
#pragma GCC optimize("O3")

#include<bits/stdc++.h>
#define sp " "
#define endl "\n"
#define MAX 10e9
#define MAXN 100001
#define mod 1000000007
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll,ll>>
#define vpc vector<pair<char,char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll,pair<ll, ll>>
#define clr(x) memset(x,0,sizeof(x))
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define google cout << "Case #" << ++it << ": " << ans << endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long int ll;

ll it = 0, ans = 0;

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (auto i=2; i<MAXN; i++)
  		spf[i] = i;
  	for (auto i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (auto i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (auto j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
	return;
}

vl getFactorization(ll x)
{
    vl ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}


void check()
{
	ll n, x = 0;
	cin >> n;
	vl a(n), b(n);
	for(int i=0;i<n;i++) cin >> a[i], x^=a[i];
	for(int i=0;i<n;i++) {
		cout << (x^a[i]) << sp;
	}
    return ;
}

int32_t main()
{
    fastio
    ll t = 1;
    // cin >> t;
    while(t--)
        check();
    return 0;
}


Measured memory_bytes: 6268
#include <stdio.h>
int main (){
	int h,w;
	for (int i=1; ; i++){
		scanf ("%d %d",&h,&w);
		if (h==0 && w==0){
			break;
		}
		for (int j=1;j<=h;j++){
			for (int k=1;k<=w;k++){
				printf ("#");
			}
			printf ("\n");
		}
		printf ("\n");
	}
	return 0;
}


Measured memory_bytes: 1968
#include<iostream>
#include<string>
using namespace std;
int main()
{
	// 整数の入力
	int a,b;
	cin >> a >> b;

	if (a % 2 == 0 || b % 2 == 0) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 50

int main() {
	static int dd[N];
	int n, i, sum, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &dd[i]);
	sum = 0;
	for (i = 0; i < n; i++)
		sum += dd[i];
	ans = 0;
	for (i = 0; i < n; i++)
		ans += dd[i] * (sum - dd[i]);
	printf("%d\n", ans / 2);
	return 0;
}


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

int n, a[204], ans;

int main()
{
    cin >> n;
    for(int i = 0; i < 2 * n; i++){
        cin >> a[i];
    }
    sort(a, a + 2 * n);
    for(int i = 0; i < 2 * n; i += 2){
        ans += a[i];
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (b <= a) {
			System.out.println("delicious");
		} else if (b-a <= x) {
			System.out.println("safe");
		} else {
			System.out.println("dangerous");
		}
		sc.close();
	}
}


Measured memory_bytes: 21588
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

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

int main(){
    IOS;
    make2(ll,n,m);
    if(2*n>=m){
        cout<<m/2<<endl;
    }
    else{
        cout<<n+(m-2*n)/4<<endl;
    }



    return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  int cnt = 0;
  rep(i, n) {
    int tmp = sum / (4 * m);
    if(sum % (4 * m) != 0 && a.at(i) > tmp) cnt++;
    else if(sum % (4 * m) == 0 && a.at(i) >= tmp) cnt++;
  }
  if(cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
    

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
template<class T> void chmax(T &a, const T &b){if(a<b) a=b;}
template<class T> void chmin(T &a, const T &b){if(b<a) a=b;}
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1400;
vv(int, dp, MAX, MAX, 0);
vv(int, G, MAX, MAX, 0);
int getLargestSquare(int H, int W) {
	int maxWidth = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			dp[i][j] = (G[i][j] + 1) % 2;
			maxWidth |= dp[i][j];
		}
	}
	rep(i, 1, H) {
		rep(j, 1, W) {
			if(G[i][j]) dp[i][j] = 0;
			else {
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	}
	return maxWidth * maxWidth;
}
int main() {
	int H, W; cin >> H >> W;
	rep(i, 0, H) rep(j, 0, W) cin >> G[i][j];
	P(getLargestSquare(H, W));
	return 0;
}

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

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

int main() {
  int n, y;
  cin >> n >> y;
  trep(i, n) {
    trep(j, n - i) {
      if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

I int lowbit(cr x) {return x & -x;}

int main() {
	reg n = read(), ans = 0, lst = 0;
	fo(i, 1, n) {
		reg x = read(), s1 = 0, s2 = 0;
		if(lowbit(x) != x) s1 = 1;
		while(x > 1) s2++, x >>= 1;
		ans += s1 + s2;
		reg cc = _min(s2, lst);
		ans -= cc, lst -= cc;
		if(lst > 0 && s1 > 0) ans--, s1--;
		lst = s1 + s2;
	} pr2(ans);
	return 0;
}



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

void bfs(int);

static const int Q = 100;
static const int W = (1<<21);

int n,M[Q][Q],d[Q];

int main(){
  int u,k,v;

  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}
    

void bfs(int s){
  queue<int> q;
  q.push(s);

  for(int i=0;i<n;i++){
    d[i]=W;
  }
  d[s]=0;

  int u;
  while(!q.empty()){
    u=q.front();
    q.pop();

    for(int v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v]!=W)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }

  for(int i=0;i<n;i++){
    cout << i+1 << " " << ((d[i]==W)?(-1):d[i]) << endl;
  }
}




Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        B*=2;
        if (B>A) {
            System.out.println(0);
        } else {
            System.out.println(A-B);
        }
    }
}

Measured memory_bytes: 20820
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
ans=1
c=a.count(0)
if c>0:
    print(0)
    exit()
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)
        


Measured memory_bytes: 23764
#ABC104C
d,g = list(map(int,input().split()))
p = [0]*d
c = [0]*d
for i in range(d):
    p[i],c[i] = list(map(int,input().split()))

#bit全探索
ans = float('inf')
for i in range(2**d):
    s = 0
    num = 0
    rest_max = -1
    for j in range(d):
        if (i>>j) & 1:
            s += 100*(j+1)*p[j] + c[j]
            num += p[j]
        else:
            rest_max = j #全完でない最高得点の問題
    if s<g and rest_max >= 0:
        r = 100*(rest_max+1)
        need = ((g-s)+r-1)//r #(g-s)/rの繰り上げ
        if need >= p[rest_max]:
            continue
        num += need
    ans = min(ans,num)
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

vector<string> split(const string &str, char sep)
{
  vector<string> v;
  auto first = str.begin();
  while( first != str.end() ) {
    auto last = first;
    while( last != str.end() && *last != sep ) ++last;
    v.push_back(std::string(first, last));
    if( last != str.end() ) ++last;
    first = last;
  }
  return v;
}

signed main(void)
{
  string s;
  while(getline(cin, s)) {
    vector<string> v = split(s, ' ');
    stack<double> st;
    //for(string i: v) cout << i << " "; cout << endl;
    for(string i: v) {
      if(i == "-") {
        double a = st.top(); st.pop();
        double b = st.top(); st.pop();
        st.push(b-a);
      } else if(i == "+") {
        double a = st.top(); st.pop();
        double b = st.top(); st.pop();
        st.push(a+b);
      } else if(i == "*") {
        double a = st.top(); st.pop();
        double b = st.top(); st.pop();
        st.push(a*b);
      } else if(i == "/") {
        double a = st.top(); st.pop();
        double b = st.top(); st.pop();
        st.push(b/a);
      } else {
        st.push(stoi(i));
      }
      //cout << st.top() << endl;
    }
    cout << fixed << setprecision(15) << st.top() << endl;
  }

  return 0;
}

Measured memory_bytes: 3176
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
from collections import defaultdict
ns = defaultdict(set)
for i in range(n-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    ns[u].add((w, v))
    ns[v].add((w, u))
    
q = [(0,0)]
ans = [None]*n
ans[0] = 0
while q:
    d,u = q.pop()
    for w,v in ns[u]:
        if ans[v] is None:
            val = (w+d)%2
            q.append((val, v))
            ans[v] = val
write("\n".join(map(str, ans)))

Measured memory_bytes: 92376
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BCountBalls {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, a, b; cin >> n >> a >> b;
      ll ret = (n/(a+b))*a;
      ll k = n%(a+b);
      cout << ret + min(k, a) << endl;
    }
};

signed main() {
  BCountBalls solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

mod = 998244353

dp = [[-1 for i in range(d+1)] for j in range(c+1)]
for i in range(a+1):
    for j in range(b+1):
        dp[i][j] = 1
def doubling(n, m, modulo=0):
    y = 1
    base = n
    tmp = m
    while tmp:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y
for i in range(b, d):
    dp[a][i+1] = dp[a][i] * a
    dp[a][i+1] %= mod
for i in range(a, c):
    dp[i+1][b] = dp[i][b] * b
    dp[i+1][b] %= mod
for i in range(a+1, c+1):
    for j in range(b+1, d+1):
        dp[i][j] = j*dp[i-1][j] + i*dp[i][j-1] - (i-1)*(j-1)*dp[i-1][j-1]
        dp[i][j] %= mod

print(dp[c][d])

Measured memory_bytes: 153072
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int n;
        cin >> n;
        int ans = -1;
        if (n == 0) ans = 1;
        else if (n == 1) ans = 2;
        else if (n == 2) ans = 1;
        else if (n > 2) ans = 0;
        
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



Measured memory_bytes: 3164
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
#from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


h,w=mdata()
ch,cw=mdata()
dh,dw=mdata()
ch,cw,dh,dw=ch-1,cw-1,dh-1,dw-1
S=[data() for i in range(h)]
steps=[(0,1),(1,0),(-1,0),(0,-1)]
dist=[[INF]*w for i in range(h)]
dist[ch][cw]=0

queue = deque()
queue.append((ch, cw))
while queue:
    u, v = queue.popleft()
    d=dist[u][v]
    for i in range(-2, 3):
        for j in range(-2, 3):
            if 0 <= u + i < h and 0 <= v + j < w and S[u + i][v + j] == '.':
                if (i,j) in steps:
                    if d < dist[u+i][v+j]:
                        dist[u+i][v+j] = d
                        queue.appendleft((u+i,v+j))
                else:
                    if 1 + d < dist[u + i][v + j]:
                        dist[u + i][v + j] = 1 + d
                        queue.append((u + i, v + j))


if dist[dh][dw]!=INF:
    out(dist[dh][dw])
else:
    out(-1)


Measured memory_bytes: 112004
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	int m1,m2,d1,d2;
	cin>>m1>>d1;
	cin>>m2>>d2;
	if(m1<m2)cout<<"1"<<endl;
	else cout<<"0"<<endl;
	return 0;

}



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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<int>> books(N, vector<int>(M + 1, 0));
  rep(i, N) {
    rep(j, M + 1) {
      cin >> books.at(i).at(j);
    }
  }

  // Exhaustive Search
  int ans = -1;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> cart(tmp);  // 0: don't buy, 1: buy
    vector<int> sum(M + 1, 0);

    rep(i, N) {
      if (cart.test(i)) continue;
      rep(j, M + 1) {
        sum.at(j) += books.at(i).at(j);
      }
    }

    bool flag = true;
    rep(j, M + 1) {
      if (j == 0) continue;
      if (sum.at(j) < X) {
        flag = false;
        break;
      }
    }
    if (!flag) continue;

    if (ans < 0)
      ans = sum.at(0);
    else
      ans = min(ans, sum.at(0));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3572
from sys import exit

N = int(input())

# 動的計画法
dp = [[[[0 for i in range(4)] for j in range(4)] for k in range(4)] for length in range(N + 1)]

# A = 0, C = 1, G = 2, T = 3
for i in range(4):
    for j in range(4):
        for k in range(4):
            dp[3][i][j][k] = 1

# AGC, GAC, ACGは禁止
dp[3][0][2][1] = 0
dp[3][2][0][1] = 0
dp[3][0][1][2] = 0

for length in range(4, N + 1):
    # 最後から3ばんめ
    for c1 in range(4):
        # 最後から2ばんめ
        for c2 in range(4):
            # 最後から1ばんめ
            for c3 in range(4):
                # 追加する文字
                for s in range(4):
                    if [c2, c3, s] not in ([0, 2, 1], [2, 0, 1], [0, 1, 2]):
                        if [c1, c3, s] != [0, 2, 1] and [c1, c2, s] != [0, 2, 1]:
                            dp[length][c2][c3][s] += dp[length - 1][c1][c2][c3]

ans = 0

for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE



ll n;
cin>>n;
ve <ll> v(n);
FOR(i,0,n)
cin>>v[i];
ll ans=0;
FOR(i,0,n){
	FOR(j,i+1,n)
	FOR(k,j+1,n){
		ve <ll> z={v[i],v[j],v[k]};
		srt(z);
		if(z[0]!=z[1]&&z[1]!=z[2]&&z[0]!=z[2]&&z[2]<z[0]+z[1])
			ans++;
	}
}
cout<<ans;



return 0;
 }
 

Measured memory_bytes: 3656
def d_static_sushi(N, C, Sushi):
    sushi_pos_cw = [row[0] for row in Sushi]
    sushi_pos_ccw = [abs(row[0] - C) for row in Sushi][::-1]
    sushi_value_cw = [row[1] for row in Sushi]
    sushi_value_ccw = sushi_value_cw[::-1]

    # 時計回り
    f1,g1,f2,g2=[],[],[],[]
    s1,s2=0,0
    for i in range(N):
        s1+=sushi_value_cw[i]-sushi_pos_cw[i]
        f1.append(s1)
        g1.append(s1)
        s1+=sushi_pos_cw[i]
        s2+=sushi_value_ccw[i]-sushi_pos_ccw[i]
        f2.append(s2)
        g2.append(s2)
        s2+=sushi_pos_ccw[i]
    for i in range(1,N):
        if g1[i]<g1[i-1]:
            g1[i]=g1[i-1]
        if g2[i]<g2[i-1]:
            g2[i]=g2[i-1]
    # print(f1,g1,f2,g2)
    # f1 = [sum(sushi_value_cw[:i + 1]) - sushi_pos_cw[i] for i in range(N)]
    # g1 = [max(f1[:i + 1]) for i in range(N)]
    # #反時計回り
    # f2 = [sum(sushi_value_ccw[:i + 1]) - sushi_pos_ccw[i] for i in range(N)]
    # g2 = [max(f2[:i + 1]) for i in range(N)]
    # print(f1,g1,f2,g2)
    tmp1 = 0
    for b in range(N + 1):  # b:反時計回りに歩いて食べる寿司の個数
        if b == 0:
            cal = g1[N - 1]
        elif b == N:
            cal = f2[b - 1]
        else:
            cal = g1[N - b - 1] + f2[b - 1] - sushi_pos_ccw[b - 1]
        tmp1 = max(tmp1, cal)

    tmp2 = 0
    for a in range(N + 1):  # a:時計回りに歩いて食べる寿司の個数
        if a == 0:
            cal = g2[N - 1]
        elif a == N:
            cal = f1[a - 1]
        else:
            cal = g2[N - a - 1] + f1[a - 1] - sushi_pos_cw[a - 1]
        tmp2 = max(tmp2, cal)
    ans = max(tmp1, tmp2)
    return ans

N,C = [int(i) for i in input().split()]
Sushi = [[int(i) for i in input().split()] for j in range(N)]
print(d_static_sushi(N, C, Sushi))

Measured memory_bytes: 92120
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define pf(a)           printf("%lld\n", a)
#define sf(a)           scanf("%lld", &a)
#define line(a)         getline(cin,(a))
#define ll              long long int
#define MAX             2134567891
#define MID(l,r)        (l+r)>>1
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define per(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define T_C(t)          printf("Case %lld: ",t)
#define TC(t)           printf("Case %lld:\n",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define MOD             1000000007///10^9
#define p6              1000007 ///10^6->6 zero after 1 **
#define hlw             printf("hlw\n");
#define SN              4*p6
#define NN              111
#define N               p6

ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;
long long nCr(int n, int r) {
    if(n<r)return 0;
    if(n==r)return 1;
    if(r==1)return n;
    return nCr(n-1,r)+nCr(n-1,r-1);
}
int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    //cout<<nCr(3,2);
    cin>>n;
    rep(i,n)
    {
        cin>>a;
        y[i]=a;
        x[a]++;
    }
    rep(i,n)
    {
        if(x[i])
            ans+=nCr(x[i],2);
        //cout<<x[i]<<" "<<ans<<endl;
    }
    //cout<<ans<<endl;
    rep(i,n)
    {
        cout<<ans-x[y[i]]+1<<endl;
    }
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)

const int N = 5003;
struct dt {
  int s, w;
  bool operator < (const dt& o) const {
    return s+w < o.s+o.w;
  }
} a[N];

int n;
ll dp[N][N];

int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  memset(dp, 63, sizeof dp);
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    scanf("%d %d", &a[i].s, &a[i].w);
  }
  sort(a+1, a+1+n);
  dp[0][0] = 0;
  // ofstream out;
  for(int i = 1; i <= n; ++i) {
    // out.open("out_" + to_string(i));
    for(int j = 0; j <= n; ++j) {
      dp[i][j] = dp[i-1][j];
      if(j && dp[i-1][j-1] <= a[i].s) {
        dp[i][j] = min(dp[i-1][j-1] + a[i].w, dp[i][j]);
      }
      // if(dp[i][j] <= 1000000) out << j << ' ' << dp[i][j] << endl;
    }
    // out.close();
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(dp[n][i] != 4557430888798830399LL) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 195840
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n < 105) cout << 0 << endl;
  else if (n < 135) cout << 1 << endl;
  else if (n < 165) cout << 2 << endl;
  else if (n < 189) cout << 3 << endl;
  else if (n < 195) cout << 4 << endl;
  else cout << 5 << endl;
  return 0;
}

Measured memory_bytes: 3524