akhauriyash/Code-Regression huggingface dataset:
import sys
def I():
    return int(sys.stdin.readline().rstrip())

def MI():
    return map(int, sys.stdin.readline().rstrip().split())


def main():
    N = I()
    dist = [[100] * (N + 1) for _ in range(N + 1)]  # 2点間の最短距離
    edges = {}

    for i in range(N - 1):
        a, b = MI()
        dist[a][b] = 1
        dist[b][a] = 1
        edges[(a, b)] = i
        edges[(b, a)] = i

    for i in range(1, N + 1):
        dist[i][i] = 0

    for k in range(1, N + 1):
        for i in range(1, N + 1):
            for j in range(1, N + 1):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    M = I()
    A = []  # uとvを結ぶ経路上にある辺の集合
    for _ in range(M):
        u, v = MI()
        B = set()
        while True:
            if dist[u][v] == 1:
                B.add(edges[(u, v)])
                break
            else:
                for i in range(1, N + 1):
                    if dist[u][i] == dist[u][v] - 1 and dist[i][v] == 1:
                        B.add(edges[(i, v)])
                        v = i
                        break
        A.append(B)

    # 包除原理

    ans = 0
    for i in range(2 ** M):
        C = set()
        a = 0
        for j in range(M):
            if (i >> j) & 1:
                C |= A[j]
                a += 1
        l = len(C)
        a %= 2
        ans += (-1) ** a * 2 ** (N - 1 - l)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74276
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}


pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: u32 = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

use std::f64::consts::PI;

fn solve() {
    let (a,b,h,m) = read!(f64,f64,f64,f64);
    let tha = 2.0*PI*(h/12.0 + m/12.0/60.0);
    let thb = 2.0*PI*m/60.0;
    let val = a*a + b*b - 2.0*a*b*((tha-thb).cos());
    println!("{}", val.sqrt());
}

fn run() {
    solve();
}

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

using namespace std;


int main() {
	int n, sh, lh;
	double degreeOfSh, degreeOflh, result;
	char c;

	cin >> n;
	while (n--) {
		cin >> sh >> c >> lh;
		//cout << sh << ends << lh << endl;
		degreeOfSh = sh * 30 + lh*0.5;
		degreeOflh = lh * 6;
		//cout << degreeOfSh << ends << degreeOflh << endl;
		result = min(fabs(degreeOfSh - degreeOflh), 360 - fabs(degreeOfSh - degreeOflh));
		if (result < 30) {
			cout << "alert" << endl;
		}
		else if (result >= 90 && result <= 270) {
			cout << "safe" << endl;
		}
		else {
			cout << "warning" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3092
using System;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n1 = int.Parse(input);
            input = Console.ReadLine();
            int n2 = int.Parse(input);
            input = Console.ReadLine();
            int n3 = int.Parse(input);
            input = Console.ReadLine();
            int total = int.Parse(input);

            int cnt = 0;
            int sum = 0;

            for (int i = 0; i <= n1; i++)
            {
                sum = 500 * i;
                for (int j = 0; j <= n2; j++)
                {
                    if (sum > total)
                    {
                        break;
                    }
                    sum = 500 * i + 100 * j;
                    for (int m = 0; m <= n3; m++)
                    {
                        if (sum > total)
                        {
                            break;
                        }
                        sum = 500 * i + 100 * j + 50 * m;
                        if (sum == total)
                        {
                            cnt++;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(cnt);
        }
        }
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m[3];
    cin>>m[0]>>m[1]>>m[2];
    if(m[0]<m[1]) swap(m[0], m[1]);
    if(m[1]<m[2]) swap(m[1], m[2]);
    if(m[0]<m[1]) swap(m[0], m[1]);
    for(int i=3; i<10; i++){
        int t;
        cin>>t;
        if(t>m[2]){
            int p=2;
            while(p>0&&t>m[p-1]){
                m[p]=m[p-1];
                --p;
            }
            m[p]=t;
        }
    }
    for(int i=0; i<3; i++){
        cout<<m[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3216
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
 
int prime[100000+310];
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}
 
int main(){
	makep(100300);
	ll n,p;
	while(scanf("%lld%lld",&n,&p),~n){
		n++;
		ll crr=0;
		while(p>0){
			rep(i,0,crr/2+1)if(!prime[n+i]&&!prime[n+crr-i])p--;
			if(p>0)crr++;
		}
		printf("%lld\n",n+n+crr);
	}
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0);
const int32_t mod = 1e9+7;
const int32_t maxn=5e3+5;
int inf=1e18;

int n,k,p[maxn],c[maxn],res=-inf;
vi ans[maxn];

void go1(){
    rep(i,0,n){
        int cur=i,pre=0;
        rep(j,0,n){
            if(cur==i and j) break;
            ans[i].pb(c[p[cur]]+pre);
            pre=ans[i][j];
            //cout<<cur<<' ';
            cur=p[cur];
        }
        //cout<<sz(ans[i])<<'\n';
    }
    rep(i,0,n){
        int t=min(k,sz(ans[i]));
        rep(j,0,t){
            res=max({res,ans[i][j]});
            if(j>=(k%sz(ans[i]))) res=max(res,ans[i][j]+(max((k/sz(ans[i]))-1,0LL))*ans[i].back());
            else res=max(res,ans[i][j]+((k/sz(ans[i])))*ans[i].back());

            //cout<<i<<' '<<j<<' '<<res<<'\n';
        }
    }
}

void solve(){
    cin>>n>>k;
    rep(i,0,n) cin>>p[i],p[i]--;
    rep(i,0,n) cin>>c[i];    
    go1();
    cout<<res;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 218860
n = int(input())
li = list(map(int, input().split()))
total = sum(li)

sum_ = 0
min_ = float('inf')
for i in range(n-1):
    sum_ += li[i]
    diff = abs(total - 2*sum_)
    if diff < min_:
        min_ = diff
print(min_)

Measured memory_bytes: 24812
n = int(input())
a = [int(_) for _ in input().split()]
new_a_plus = [a[i] for i in range(n)]
new_a_minus = [a[i] for i in range(n)]

count_plus = 0
now_total_plus = 0

for i in range(0, n):
    if i % 2 == 0:
        if now_total_plus + a[i] <= 0:
            new_a_plus[i] = - now_total_plus + 1
            count_plus += new_a_plus[i] - a[i]
    else:
        if now_total_plus + a[i] >= 0:
            new_a_plus[i] = - now_total_plus - 1
            count_plus += a[i] - new_a_plus[i]
    now_total_plus += new_a_plus[i]

count_minus = 0
now_total_minus = 0

for i in range(0, n):
    if i % 2 == 0:
        if now_total_minus + a[i] >= 0:
            new_a_minus[i] = - now_total_minus - 1
            count_minus += a[i] - new_a_minus[i]
    else:
        if now_total_minus + a[i] <= 0:
            new_a_minus[i] = - now_total_minus + 1
            count_minus += new_a_minus[i] - a[i]
    now_total_minus += new_a_minus[i]

print(min(count_plus, count_minus))

Measured memory_bytes: 14212
//#include <math.h>
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
using namespace std;

int main(void){
    int  N;
    cin >> N;
    set<string> st;
    for(int i=0;i<N;i++){
        string S;
        cin >>S;
        st.insert(S);
    }
    cout << st.size() <<endl;
    return 0;
}


Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc158/abc158_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

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

  int ans = -1;
  repi(x, 1, 2000) {
    int ax = x * 0.08;
    int bx = x * 0.1;
    if (ax == a && bx == b) {
      ans = x;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
c=0
l2=[0]*9
for i in l:
  if 1<=i and i<=399:
    if l2[0]==0:
      c+=1
      l2[0]=1
  elif 400<=i and i<=799:
    if l2[1]==0:
      c+=1
      l2[1]=1
  elif 800<=i and i<=1199:
    if l2[2]==0:
      c+=1
      l2[2]=1
  elif 1200<=i and i<=1599:
    if l2[3]==0:
      c+=1
      l2[3]=1
  elif 1600<=i and i<=1999:
    if l2[4]==0:
      c+=1
      l2[4]=1
  elif 2000<=i and i<=2399:
    if l2[5]==0:
      c+=1
      l2[5]=1
  elif 2400<=i and i<=2799:
    if l2[6]==0:
      c+=1
      l2[6]=1
  elif 2800<=i and i<=3199:
    if l2[7]==0:
      c+=1
      l2[7]=1
  else:
    c+=1
    l2[8]+=1
if c==9:
  print(8,8)
else:
  if l2[8]!=0:
    if l2[8]==c:
      print(1,min(c,8))
    else:
      print(c-l2[8],c)
  else:
    print(c,c)

Measured memory_bytes: 3064
def f(n, a):
    x = sorted(set(a))
    n_sub_half = (n * (n + 1)) // 2 // 2
    n1 = n * 2 + 1
    li = 0
    ri = len(x)
    while ri > li + 1:
        i = (li + ri) // 2
        xi = x[i]
        cnt = [0] * n1
        cs = 0
        cnt[cs] = 1
        judge = 0
        s = 0
        for ak in a:
            if ak >= xi:
                cs += 1
                s += cnt[cs] + 1
            else:
                cs -= 1
                s -= cnt[cs + 1] - 1
            cnt[cs] += 1
            judge += s
            if judge >= n_sub_half:
                li = i
                break
        else:
            ri = i
    return x[li]

n = int(input())
ar = [int(i) for i in input().strip().split(" ")]
print(f(n,ar))





Measured memory_bytes: 124588
#include <iostream>
#include <climits>
#include <vector>
#include <queue>

#define MAX_V 1024
using namespace std;

void get_map();
void check();
struct edge
{
  int to;
  int weight;
};


const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;

int main()
{
  get_map();
  check();
  //for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
	{
	  //if(i==j)
	    {
	      if(graph[start][j]<INF/2 && graph[j][j]<0)
		{
		  cout << "NEGATIVE CYCLE" <<endl;
		  return 0;
		}
	    }
	}
    }
  
    for(int i=0;i<vertex;i++)
      {
	if(graph[start][i]>=INF/2)
	  {
	    cout << "INF" << endl;
	  }
	else
	  {
	cout << graph[start][i] << endl;
	  }
      }
  return 0;
}

inline int fastmin(int a, int b)
{
  return (((a-b)>>31)&(a-b))+b;
}

int mymin(int a, int b) 
{
	return a<b?a:b;
}

void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
  
  for(int k=0;k<vertex;k++)//v=4
    {
      for(int i=0;i<vertex;i++)
	{
	  int gik= graph[i][k];
	  for(int j=0;j<vertex;j++)
	    {
	      //if(graph[i][k] !=INF && graph[k][j]!=INF)
		{
	      graph[i][j]= mymin(graph[i][j], gik+graph[k][j]);
		}
	    }
	}
    }
  
}

void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
  
  fill(graph[0], graph[vertex], INF);
  
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
      {
	if(i==j)
	  {
	    graph[i][j]=0;
	  }
	/*else
	  {
	    graph[i][j]=INF;
	    }*/
      }
    }

  /*for(int i=0;i<vertex;i++)
    {
      dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }

  /*  for(int i=0;i<numofedge;i++)
    {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
   }
  */  

  /*  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
	{
	  cout << graph[i][j] << " ";
	}
      cout << endl;
      }*/
  // dist[start]=0;
  
  /*  cout << vertex << endl;
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
	{
	  cout << graph[i][j] << " ";
	}  
      cout << endl;    
      }*/
  

}

Measured memory_bytes: 5300
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define ll long long

int N, K;
ll x[51], y[51];
int main()
{
	cin >> N >> K;
	REP(i, 0, N) {
		cin >> x[i] >> y[i];
	}

	ll mnArea = 4e18;
	REP(i, 0, N) {
		REP(j, 0, N) {
			REP(k, 0, N) {
				REP(l, 0, N) {
					ll mnx = min(min(min(x[i], x[j]), x[k]), x[l]);
					ll mny = min(min(min(y[i], y[j]), y[k]), y[l]);
					ll mxx = max(max(max(x[i], x[j]), x[k]), x[l]);
					ll mxy = max(max(max(y[i], y[j]), y[k]), y[l]);
					ll rect = (mxx - mnx)*(mxy - mny);
					
					int cnt = 0;
					REP(m, 0, N) {
						if (mnx <= x[m] && mny <= y[m] && mxx >= x[m] && mxy >= y[m]) cnt++;
					}

					if (cnt >= K && rect > 0) {
						mnArea = min(mnArea, rect);
					}
				}
			}
		}
	}

	cout << mnArea << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
long long a[105],b[105];

int main() {
	int n,p,i,c,x;
	scanf("%d%d",&n,&p);
	a[0]=0;b[0]=1;
	for (i=1;i<=n;i++) {
		scanf("%d",&x);
		if (x%2) {
			a[i]=b[i-1]+a[i-1];
			b[i]=a[i-1]+b[i-1];
		} else {
			a[i]=a[i-1]*2;
			b[i]=b[i-1]*2;
		}
	}
	if (p) cout << a[n]; else cout << b[n];
}

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

using namespace std;

int main(void) {

	int a, b, c, d, minn, maxn, ans;

	cin >> a >> b >> c >> d;

	minn = max(a, c);
	maxn = min(b, d);

	ans = max(0, maxn - minn);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int sum=0;
  for(int i=0;i<N;i=i+2){
    sum=sum+a.at(i);
  }
  for(int i=1;i<N;i=i+2){
    sum=sum-a.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
//ABC099B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int a, b;
	cin >> a >> b;
	long long int tall = (1+b-a)*(b-a)/2;
	long long int ans = tall-b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//プライオリティーキュー
#include "bits/stdc++.h"
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける



int main()
{
  int n,x;
  cin>>n;
  vector<int> a(n);
  vector<int> xnum(n);//xnum(x)は縦になんこあるか
  vector<int> ynum(n);//ynum(y)は横になんこあるか

  int b;
  REP(i,n){
    cin>>b;
    b--;
    a[b]++;//iカードが何枚あるか
  }
  sort(a.begin(), a.end(),greater<int>());

  REP(i,n){
    xnum[i]=a[i];
  }

  int t=xnum[0];
  REP(i,n){
    if (xnum[i]<t){
      for(int j=xnum[i];j<t;j++){
        ynum[j]=i;
      }
      t=xnum[i];
    }
  }
  
  if (0<t){
    for(int j=0;j<t;j++){
      ynum[j]=n;
    }
  }


  vector<int> ans(n);
  int leftuse=0;//穴埋めに自由に使える面積
  int h=0;//答えとなる高さ
  int s=0;//顕さんに使う面積
  for (int i = n-1; i >=0; i--)
  {
    for(;;){
      if (h==n){
        break;
      }

      if ( (i+1)*h <= s+leftuse ){
        s+=min(ynum[h],i+1);
        h++;
      }else{
        break;
      }
    }

    ans[i]=h-1;

    s-=min(xnum[i],h);
    leftuse+=xnum[i];
  }
  

  ans[0]=n;

/*
  REP(i,n){
    cout<<xnum[i]<<endl;
  }
  cout<<endl;
  REP(i,n){
    cout<<ynum[i]<<endl;
  }
  cout<<endl;
  */
  REP(i,n){
    cout<<ans[i]<<endl;
  }



  return 0;
}


Measured memory_bytes: 5504
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int a[200],n,m;
vector<vector<int> > b;
int fi(int p,int q){
  if(b[p][q]>=0)
    return b[p][q];
  int sm=fi(p+1,q);
  if(q+a[p]<=m)
    sm=(sm+fi(p+1,q+a[p]))%1000000007;
  return b[p][q]=sm;
}
int main(){
  int i;
  //int n,m;
  cin>>n>>m;
  //int a[200];
  for(i=0;i<n;++i)
    cin>>a[i];
  sort(a,a+n);
  int sm=0,tm=0;
  for(i=0;i<n;++i){
    //vector<vector<int> > b;
    b.assign(n+1,vector<int>(m+1,-1));
    fill(&b[n][0],&b[n][0]+m-a[i]+1,0);
    fill(&b[n][0]+m-a[i]+1,&b[n][0]+m+1,1);
    sm=(sm+fi(i+1,tm))%1000000007;
    tm+=a[i];
    if(tm>m)
      break;
  }
  if(tm<=m)
    sm=(sm+1)%1000000007;
  cout<<sm<<endl;
  return 0;
}

Measured memory_bytes: 8768
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main()
{
    string s,res;
    cin >> s;
    res = "Yes";
    for(int i = 0; i < s.size(); ++i)
    {
        if(i % 2 == 0 && s[i] != 'h')res = "No";
        if(i % 2 == 1 && s[i] != 'i')res = "No";
    }
    if(s.size() %2 == 1)res = "No";

    cout << res << endl;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

using Int = long long;
//BEGIN CUT HERE
template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T> > > & G){
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;
    int n=G.size();
    vector<T> d(n,INF);
    vector<int> b(n,-1);
    priority_queue<P,vector<P>,greater<P> > q;
    d[s]=0;
    q.emplace(d[s],s);
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.first;
            T c=e.second;
            if(d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                q.emplace(d[u],u);
            }
        }
    }
    return d;
}
//END CUT HERE



int main(){
    ll n,m;
    cin>>n>>m;
    using P = pair<int, Int>;
    vector<vector<P>> edge(3*n);
    for(int i=0;i<m;i++){
        ll u,v;
        cin>>u>>v;
        u--; v--;
        for(int j=0;j<3;j++){
            edge[j*n+u].push_back({(j+1)%3*n+v,1});
        }
    }
    ll s,t;
    cin>>s>>t;
    s--; t--;
    ll ans=dijkstra(s,edge)[t];
    cout<<(ans>1e9?-1:ans/3)<<endl;
    
    return 0;
}


Measured memory_bytes: 20224
#include<stdio.h>
int main(void)
{
	int A,B,S,Y,X,Z;
	scanf("%d%d",&A,&B);
	S=A%3;
	Y=B%3;
	X=A+B;
	Z=X%3;
	if(S==0||Y==0||Z==0){
		printf("Possible\n");
	}
	else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

X, N = map(int, input().split())
P = list(map(int, input().split()))

if N == 0:
    print(X)
    quit()

abs_ = 200
answers = []

# 答えは0 から 101の値をとる
for i in range(102):
    if i in P:
        continue

    tmp_abs = abs(X - i)
    if tmp_abs == abs_:
        answers.append(i)
    if tmp_abs < abs_:
        answers = [i]
        abs_ = tmp_abs
ans = min(answers)
print(ans)

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

int x,y,d,a,b,X[2],Y[2];

int main(){
	while(cin>>x>>y>>d,x||y||d){
		for(int i=0;i<2;i++){
			X[i]=0;Y[i]=0;
			i?a=d:a=0;i?b=0:b=d;
			while(a!=b){
				if(a<b){a+=x;X[i]++;} 
				else{b+=y;Y[i]++;}
			}
		}
		if(X[0]+Y[0]>X[1]+Y[1]||(X[0]+Y[0]==X[1]+Y[1]&&x*X[0]+y*Y[0]>x*X[1]+y*Y[1]))X[0]=X[1],Y[0]=Y[1];
		for(int i=0;i<100000;i++)if(d-i*x>=0&&(d-i*x)%y==0&&(X[0]+Y[0]>i+(d-i*x)/y||(X[0]+Y[0]==i+(d-i*x)/y&&x*X[0]+y*Y[0]>d)))X[0]=i,Y[0]=(d-i*x)/y;
		cout<<X[0]<<" "<<Y[0]<<endl;
	}
}

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

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (j-1);i >= 0;i--)
#define _dep(i,j,N) for(int i = (j);i >= 0;i--)
#define ALL(x) x.begin(),x.end()
#define pb push_back

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

template<typename T>
ostream& operator<<(ostream &os,const vector<T> &vi){
    _for(i,0,vi.size()) os << vi[i] <<" ";
    os << endl;
    return os;
}
template<typename T>
ostream& operator<<(ostream &os,const set<T> &si){
    for(auto &a:si){
        os << a << " ";
    }
    os << endl;
    return os;
}
template<typename T1,typename T2>
ostream& operator<<(ostream &os,const map<T1,T2> mi){
    for(auto &a:mi){
        os << a.first<<" " << a.second <<endl;
    }
    return os;
}

const int maxn = 1e5+5;
int N,M,cnt;
vector<int> G[maxn];
map<int,int> mp;
int topo[maxn];
int vis[maxn];
int ans[maxn];

void dfs(int u){
    vis[u] = 1;
    for(auto a:G[u]){
        if(!vis[a]) dfs(a);
    }
    topo[cnt--] = u;
}

void dfs2(int u,int pre){
    vis[u] = 1;
    ans[u] = pre;
    _for(i,0,G[u].size()){
        if(!vis[G[u][i]]) dfs2(G[u][i],u);
    }
}

struct Cmp{
    bool operator()(const int &a,const int &b)const{
        int k = mp[a];
        int k2 = mp[b];
        return k < k2;
    }
};

int main()
{
    scanf("%d %d",&N,&M);
    _for(i,0,N+M-1){
        int a,b;
        scanf("%d %d",&a,&b);
        G[a].pb(b);
    }
    cnt = N;
    _rep(i,1,N){
        if(!vis[i])
            dfs(i);
    }
    _rep(i,1,N){
        mp[topo[i]] = i;
    }

    _rep(i,1,N){
        sort(ALL(G[i]),Cmp());
    }


    memset(vis,0,sizeof(vis));
    cnt = 1;
    dfs2(topo[1],0);

    _rep(i,1,N){
        printf("%d\n",ans[i]);
    }

    return 0;
}

Measured memory_bytes: 16768
#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 ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define bits(n) __builtin_popcount(n)

void solve()
{
    int n;
    cin >> n;
    if (n == 0)
        cout << "1";
    else
    {
        cout << "0";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3576
class SegmentTree():
    def __init__(self, n, op, e):
        self.n = n
        self.op = op
        self.e = e
        self.log = (n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [e] * (2 * self.size)

    def update(self, k):
        self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])

    def build(self, arr):
        #assert len(arr) <= self.n
        for i in range(self.n):
            self.d[self.size + i] = arr[i]
        for i in range(1, self.size)[::-1]:
            self.update(i)

    def set(self, p, x):
        #assert 0 <= p < self.n
        p += self.size
        self.d[p] = x
        for i in range(1, self.log + 1):
            self.update(p >> i)

    def get(self, p):
        #assert 0 <= p < self.n
        return self.d[p + self.size]

    def prod(self, l, r):
        #assert 0 <= l <= r <= self.n
        sml = smr = self.e
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                sml = self.op(sml, self.d[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.d[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        return self.d[1]

    def max_right(self, l, f):
        #assert 0 <= l <= self.n
        #assert f(self.e)
        if l == self.n: return self.n
        l += self.size
        sm = self.e
        while True:
            while l % 2 == 0: l >>= 1
            if not f(self.op(sm, self.d[l])):
                while l < self.size:
                    l = 2 * l
                    if f(self.op(sm, self.d[l])):
                        sm = self.op(sm, self.d[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.d[l])
            l += 1
            if (l & -l) == l: break
        return self.n

    def min_left(self, r, f):
        #assert 0 <= r <= self.n
        #assert f(self.e)
        if r == 0: return 0
        r += self.size
        sm = self.e
        while True:
            r -= 1
            while r > 1 and (r % 2): r >>= 1
            if not f(self.op(self.d[r], sm)):
                while r < self.size:
                    r = 2 * r + 1
                    if f(self.op(self.d[r], sm)):
                        sm = self.op(self.d[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.d[r], sm)
            if (r & -r) == r: break
        return 0

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
A = tuple(map(int, input().split()))

st = SegmentTree(N, max, 0)
st.build(A)
res = []

for _ in range(Q):
    t, x, y = map(int, input().split())
    if t == 1:
        st.set(x - 1, y)
    elif t == 2:
        res.append(st.prod(x - 1, y))
    else:
        res.append(st.max_right(x - 1, lambda z: z < y) + 1)

print('\n'.join(map(str, res)))

Measured memory_bytes: 117784
S = input()
S = S[::-1]
#print(S)

mod = 10**9+7

dp = [0]*13
dp[0] = 1
for i in range(len(S)-1,-1,-1):
	ch = int(S[i]) if S[i]!='?' else -1
	temp = [0]*13
	for d in range(10):
		if ch!=-1 and ch!=d:
			continue
		for m in range(13):
			temp[(10*m+d)%13] += dp[m]
	for m in range(13):
		temp[m] %= mod
	dp = temp
print(dp[5])


Measured memory_bytes: 44012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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;
}

int D;
VI c(26);
VVI s;
VI t;
VI best;
ll sc;
set<int> days[26];

const double TIME_LIMIT = 1.8;
clock_t time_start;

inline uint32_t rnd(void) {
    static uint32_t y = 2463534242;
    y = y ^ (y << 13);
    y = y ^ (y >> 17);
    return y = y ^ (y << 5);
}

void read_input() {
    cin >> D;
    for (int i = 0; i < 26; i++) cin >> c[i];
    s = VVI(D, VI(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) cin >> s[i][j];
    }
}

void init() {}

void init_by_input() {
    t = VI(D);
    for (int i = 0; i < D; i++) {
        cin >> t[i];
        t[i]--;
    }
    for (int i = 0; i < 26; i++) days[i].insert(-1);
    for (int i = 0; i < D; i++) {
        days[t[i]].insert(i);
    }
    for (int i = 0; i < 26; i++) days[i].insert(D);
}

void init_by_greedy() {
    t = VI(D);
    ll sum_sc = 0;
    set<int> se[26];
    for (int i = 0; i < 26; i++) se[i].insert(-1);
    for (int i = 0; i < D; i++) {
        ll dif = 0;
        for (int j = 0; j < 26; j++) {
            dif -= c[j] * (i - *se[j].rbegin());
        }
        sum_sc += dif;
        ll dm = -inf;
        int fl = -1;
        for (int j = 0; j < 26; j++) {
            if (chmax(dm, s[i][j] + c[j] * (i - *se[j].rbegin()))) fl = j;
        }
        cin >> fl;
        fl--;
        dm = s[i][fl] + c[fl] * (i - *se[fl].rbegin());
        t[i] = fl;
        sum_sc += dm;
        se[fl].insert(i);
        cout << sum_sc << endl;
    }
}

ll calc_score() {
    ll plus = 0;
    ll minus = 0;
    for (int i = 0; i < D; i++) {
        plus += s[i][t[i]];
    }
    for (int i = 0; i < 26; i++) {
        for (auto it = ++days[i].begin(); it != days[i].end(); ++it) {
            int lapse = *it - (*--it);
            minus += c[i] * lapse * (lapse - 1) / 2;
            ++it;
        }
    }
    return plus - minus;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    time_start = clock();
    read_input();
    // init_by_input();
    init_by_greedy();
    //cout << calc_score() << endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;


int main()
{
    vector<string> days = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
    string input;
    cin >> input;
    for (int i=0; i<days.size(); i++){
        if(input==days[i]){
            cout<<7-i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100];
const int maxn =1e5+10;
int a[maxn],b[maxn];
#define LL long long
int main(){
    LL x;
    while(~scanf("%lld",&x)){
        int f=0;
        for(LL i=0;i<10000;i++){
            for(LL j=-10000;j<i;j++){
                LL tp = i*i*i*i*i - j*j*j*j*j;
                if(tp == x){
                    printf("%lld %lld\n",i,j);
                    f=1;
                    break;
                }
            }
            if(f){
                break;
            }
        }

    }
    return 0;
}



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

int divisor(int a);

int main()
{
	int n, i, j=0;
	
	scanf("%d", &n);
	
	for(i=1; i<=n; i++)
		if(divisor(i)==8) j++;
		
	printf("%d\n", j);
	
	return 0;
}
	

	
int divisor(int a)
{
	int i, j=0;
	if(a%2)
		for(i=1; i<=a; i++) 
			if(a%i==0) j++;
	
	return j;
}		
	
	
	
	
	
	

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <numeric>
#include <limits>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
const int V = 10;
struct edge { int to, cost; };
std::vector<edge>v[100];
typedef std::pair<int, int>p;

int main() {
	int a, b;
	std::cin >> a >> b;
	int ans = a*b;
	if (ans % 2 == 0) {
		std::cout << "Even" << std::endl;
	}
	else {
		std::cout << "Odd" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBingo solver = new BBingo();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBingo {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[][] bingo = new int[3][3];
            boolean[][] open = new boolean[3][3];

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    bingo[i][j] = in.nextInt();
                    open[i][j] = false;
                }
            }

            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                int now = in.nextInt();
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 3; k++) {
                        if (bingo[j][k] == now) {
                            open[j][k] = true;
                        }
                    }
                }
            }

            // よこ
            for (int i = 0; i < 3; i++) {
                boolean f = true;
                for (int j = 0; j < 3; j++) {
                    f = f && open[i][j];
                }
                if (f) {
                    out.println("Yes");
                    return;
                }
            }

            for (int i = 0; i < 3; i++) {
                boolean f = true;
                for (int j = 0; j < 3; j++) {
                    f = f && open[j][i];
                }
                if (f) {
                    out.println("Yes");
                    return;
                }
            }

            if (open[0][0] && open[1][1] && open[2][2]) {
                out.println("Yes");
                return;
            }

            if (open[2][0] && open[1][1] && open[0][2]) {
                out.println("Yes");
                return;
            }

            out.println("No");


        }

    }
}



Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, t, a[5000], b[5000], dp[5000][2];

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> t;
	rep(i, 1, n){
		cin >> a[i] >> b[i];
	}
	memset(dp, 0, sizeof(dp));
	
	rep(i, 1, n){
		rrep(j, t-1, 0){
			if(j+a[i] < t){
				dp[j+a[i]][0] = max(dp[j][0]+b[i], dp[j+a[i]][0]);
				dp[j+a[i]][1] = max(dp[j][1]+b[i], dp[j+a[i]][1]);
			}
			dp[j][1] = max(dp[j][0]+b[i], dp[j][1]);
		}
	}
	print(dp[t-1][1])
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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 pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void yes(bool c) { if (c)print("Yes"); else print("No"); };

void solve() {
	int N, M; cin >> N >> M;
	vector<bool>used(N);
	int mx = (N - 1) / 2;
	vector<pii>ans;
	int idx = 0;
	for (int d = mx; d > 0; d -= 2) {
		ans.push_back({ idx,idx + d });
		idx++;
	}
	idx = mx + 1;
	for (int d = mx - 1; d > 0; d -= 2) {
		ans.push_back({ idx,idx + d });
		idx++;
	}
	REP(i, M) {
		cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
		solve();
}



Measured memory_bytes: 5288
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <ios>
#include <algorithm>

using namespace std;


int main(){
    unsigned int n;
    char s;
    cin >> n;
    vector<char> data(n);
    for (unsigned int i = 0; i < n; ++i) {
        cin >> s;
        data.at(i) = s;
    }

    if (count(data.begin(), data.end(), 'R') > count(data.begin(), data.end(), 'B')) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, K;
  cin >> N >> K;

  int ans = 1;
  while(N > K-1){
    ans++;
    N /= K;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import copy
n,m,x=[int(_) for _ in input().split()]
Cmat=[[int(_) for _ in input().split()] for i in range(n)]
lista=[]
money=[]

visited=0
def dfs(lista,visited):
    global x
    global money
    skill=[0]*m
    total=0
    for i,j in enumerate(lista):
        for index,ja in enumerate(Cmat[j]):
            if index==0:
                total+=ja
            else:
                skill[index-1]+=ja
    if lista and all([i>=x for i in skill]):
        #print(total)
        money.append(total)    
    elif visited<n:
        dfs(lista+[visited],visited+1)
        dfs(lista,visited+1)

dfs(lista,visited)
if money:
    print(min(money))
else:
    print(-1)

Measured memory_bytes: 69564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B) {
    if(A == C) {
      cout << "No";
    }
    else {
      cout << "Yes";
    }
  }
  else if(A == C) {
    if(B == C) {
      cout << "No";
    }
    else {
      cout << "Yes";
    }
  }
  else if(C == B) {
    if(A == C) {
      cout << "No";
    }
    else {
      cout << "Yes";
    }
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
#define pii pair < int , int >
#define vi vector < int >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define vll vector < long long int >
#define sll set < long long int >
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9+7;

int main()
{
	//fastIO;
	ll n,i;
    cin>>n>>i;
    cout<<n+1-i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll n;
    cin >> n;
    ll ans = 10000000000000;
    for (ll a=1 ;a*a<=n;a++) {
        ll b = n/a;
        if ( a*b == n) {
        ans = min(ans,a+b-2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    e = ""
    for j in range(l):
        if ((i >> j) & 1):
            e += s[j] + "+"
        else:
            e += s[j] + "-"
    if eval(e[:-1]) == 7:
        print(e[:-1]+'=7')
        break

Measured memory_bytes: 3060
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
#define fi first
#define se second
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(b >= a) cout << "unsafe\n";
    else cout<<"safe\n";
    return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
long long dp[3000][3000][2], cs[3000];
int a[3000];
long long calc(int l, int r, bool turn)
{

    int t = a[l];
    if(l==r) return t;

    if(dp[l][r][turn] != -1) return dp[l][r][turn];

    long long seg = cs[r] - (l?cs[l-1]:0);
    long long A = seg - calc(l+1, r, turn^1), b = seg - calc(l, r-1, turn^1);
    dp[l][r][turn] = max(A, b);
    return dp[l][r][turn];


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

    for (int i = 0; i < 3000; ++i) {
        memset(dp[i], -1, sizeof(dp[i]));
    }
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cs[i] = a[i] + cs[i- bool(i)];
    }
    cout << 2*calc(0, n-1, 1) - cs[n-1];
    return 0;
}

Measured memory_bytes: 141184