akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int min(int x,int y,int z){
    int res=min(x,y);
    return min(res,z);
}

int min(int x,int y,int z,int w){
    int res=min(x,y);
    res=min(res,z);
    return min(res,w);
}

int a,b,c,n;
int l[15];
int dfs(int x,int y,int z,int cur){
    if(cur==n+1){
        if(min(x,y,z)<=0)return (int)1e9;
        return abs(a-x)+abs(b-y)+abs(c-z)-30;
    }
    int a1=dfs(x,y,z,cur+1);
    int a2=dfs(x+l[cur],y,z,cur+1)+10;
    int a3=dfs(x,y+l[cur],z,cur+1)+10;
    int a4=dfs(x,y,z+l[cur],cur+1)+10;
    return min(a1,a2,a3,a4);
}

int main()
{
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(int i=1;i<=n;i++)scanf("%d",&l[i]);

    printf("%d\n",dfs(0,0,0,1));

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, c: u64, x: u64
    }
    let mut cnt = 0u64;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                let cost = 500*i+100*j+50*k;
                if cost == x {
                    cnt += 1;
                }
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
n=int(input())
li=list(map(int,input().split()))
ans=[]
for i in range(n):
	cnt=0
	while li[i]%2==0:
		li[i]=li[i]//2
		cnt+=1
	if li[i]%2==1:
		ans.append(cnt)
print(sum(ans))      

Measured memory_bytes: 4148
#include<bits/stdc++.h>
#define ll long long int
#define sz  2010
using namespace std;


set<ll>st;


int main()
{

   ll n,i,j,d,a;

   cin>>n;

   for(i=1;i<=n;i++)
   {
       cin>>a;
       st.insert(a);
   }

   d=st.size();

   if(d==n)cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;


    return 0;
}



Measured memory_bytes: 9600
Scanf.scanf "%d" (fun n ->
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in

    let rec check2 prev i sum =
        if i > 30000 then true else
            if (i + sum) mod 2 = 0 &&
               (i + sum) mod 3 = 0 &&
               gcd i sum <> 1 then (Printf.printf "%d %d\n" prev i; false)
            else check2 prev (i + 1) sum
    in

    let rec check i sum =
        if i mod 2 <> 0 && i mod 3 <> 0 then check (i + 1) sum else
            if check2 i (i + 1) (sum + i) then check (i + 1) sum
    in

    let rec loop i acc sum =
        if acc = n - 2 then check i sum else
        if i mod 2 = 0 || i mod 3 = 0 then (
            let () = Printf.printf "%d " i in
            let acc = acc + 1 in
            let sum = sum + i in
            loop (i + 1) acc sum
        ) else loop (i + 1) acc sum
    in
    loop 2 0 0
)

Measured memory_bytes: 2688
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  
  map<int,int>m;
  vector<string>v;
  vector<string>v1;

  multiset<string>st;
  multiset<string>st2;
  string s;
  sci(n);
  rep(i,1,n)
  {
    cin>>sum;
    m[i]=sum;
  }
  int i=1;
  while(n--)
  {
    i=m[i];
    tot++;
    if(i==2)
    {
      flag=0;
      cout<<tot;
      break;
    }
  }
  if(flag) cout<<-1;



    return 0;
  
  
}

Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;
//emplace_back next_permutation tie get

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;

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

    int mi=2,n,a[100010]={},cur;
    LL ans=0;
    cin >>n;
    REP(i,n){
        cin >> cur;
        if(i==0) ans+=cur-1;
        else if(cur>mi){
            ans+=(cur-1)/mi;
        }else if(cur==mi) mi++;
    }
    cout << ans <<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

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

	ll sum = 0;
	unordered_map<ll, ll> m;
	for(ll i = 0; i < n; i++)
	{
		ll x;
		cin >> x;

		m[x]++;
		sum = sum + x;
	}

	ll q;
	cin >> q;

	for(ll i = 0; i < q; i++)
	{
		ll b, c;
		cin >> b >> c;

		sum = sum - m[b] * b;
		sum = sum + m[b] * c;
		m[c] = m[c] + m[b];
		m[b] = 0;

		cout << sum << endl;
	}
}


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


int main(){
  int n,a[20][20];
  while(cin>>n, n){
    memset(a,0,sizeof(a));
    int x=n/2,y=n/2+1;
    for(int i=1;i<n*n;i++){
      a[y][x]=i;
      x=(x+1)%n;
      y=(y+1)%n;
      while(a[y][x]!=0){x=(x+n-1)%n;y=(y+1)%n;}
    }
    a[y][x]=n*n;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++) printf("%4d",a[i][j]);
      cout<<endl;
    }
  }

  return 0;
}

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

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

    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == 'L') {T = "No"; break;}
        } else {
            if (S[i] == 'R') {T = "No"; break;}
        }
    }

    cout << T << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
using namespace std;

double getChebyshevDistance(vector<double> x, vector<double> y)
{
    assert(x.size() == y.size());
    double max = fabs(x[0] - y[0]);
    int n = x.size();
    for(int i = 1; i < n; ++i){
        max = std::max(fabs(x[i] - y[i]), max);
    }
    return max;
}
double getDistance(vector<double> x, vector<double> y, int p)
{
    if(p == 0) return getChebyshevDistance(x, y);
    assert(x.size() == y.size());
    int n = x.size();
    double sum = 0;
    for(int i = 0; i < n; ++i){
        sum += pow(fabs(x[i] - y[i]), p);
    }
    return pow(sum, 1.0/p);
}

int main()
{
    cout << fixed << setprecision(5);
    
    int n;
    cin >> n;
    
    vector<double> x(n);
    vector<double> y(n);
    
    for(int i = 0; i < n; ++i){
        cin >> x[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> y[i];
    }
    
    cout << getDistance(x, y, 1) << endl;
    cout << getDistance(x, y, 2) << endl;
    cout << getDistance(x, y, 3) << endl;
    cout << getDistance(x, y, 0) << endl;

    return 0;
}

Measured memory_bytes: 3440
import copy
N = input()
T = list(map(int, input().split()))
M = int(input())
time = []
for i in range(M):
    t = copy.copy(T)
    P, X = map(int, input().split())
    t[P-1] = X

    sum = 0
    for j in t:
        sum += j
    time.append(sum)

for s in time:
    print(s)

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> S( H );
	for( int i = 0; i < H; i++ ) {
		cin >> S[i];
	}

	int dy[4] = { 1, -1, 0, 0 };
	int dx[4] = { 0, 0, 1, -1 };
	typedef pair<int, int> P;
	auto f = [&]( P st, P end ) -> int
	{
		typedef tuple<int, int, int> T;
		queue<T> que;
		vector<vector<int>> v( H, vector<int>( W ) );
		que.push( T( 0, st.first, st.second ) );
		v[st.first][st.second] = 1;
		while( !que.empty() ) {
			int d, y, x;
			tie( d, y, x ) = que.front();
			que.pop();
			if( y == end.first && x == end.second ) {
				return d;
			}
			for( int i = 0; i < 4; i++ ) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if( ny < 0 || ny >= H || nx < 0 || nx >= W ) continue;
				if( v[ny][nx] ) continue;
				if( S[ny][nx] == '#' ) continue;
				que.push( T( d + 1, ny, nx ) );
				v[ny][nx] = 1;
			}
		}
		return -1;
	};
	int ans = 0;
	for( int y = 0; y < H; y++ ) {
		for( int x = 0; x < W; x++ ) {
			if( S[y][x] == '#' ) continue;
			for( int y1 = 0; y1 < H; y1++ ) {
				for( int x1 = 0; x1 < W; x1++ ) {
					if( S[y1][x1] == '#' ) continue;
					if( y == y1 && x == x1 ) continue;
					ans = max( ans, f( P( y, x ), P( y1, x1 ) ) );
				}
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k;cin>>n>>k;
  long long arr[n+1]={0};for(int i=1;i<=n;i++)cin>>arr[i];
  
  
  long long dp[n+1]={0};
  for(int i=2;i<=n;i++)
  {
    dp[i]=1000000000000000;
    for(int j=i-1;j>=1 && j>=(i-k);j--)
    {
      dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
    }
  }
  cout<<dp[n];
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define repr(i,n) for(int i = 0; i > n; i--)
#define REP(i,k,n) for (int i = k; i <= n; i++) 
#define REPR(i,k,n) for int i = k; i >= n; i--)

typedef long long int ll;

int main()
{
	ll n, d;
	cin >> n >> d;
	int ans = 0;
	rep(i,n){
		ll x, y;
		cin >> x >> y;
		if(x * x + y * y <= d * d)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
//666yuchen
#include<bits/stdc++.h>
using namespace std;
int gs;
char s,a[15];
int main()
{
  while(cin>>s)
  {
  	if(s=='0'||s=='1')a[++gs]=s;
  	if(s=='B')
  	{
  	  gs--;
  	  if(gs<0)gs=0;
  	}
  }
  for(int i=1;i<=gs;i++)cout<<a[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,asum,bsum,a,b,i;
	while(1){
		cin>>n;
		if(n==0)break;
		asum=0; bsum=0;
		for(i=0;i<n;i++){
			cin>>a>>b;
			if(a==b)asum+=a,bsum+=b;
			if(a>b)asum+=a+b;
			if(b>a)bsum+=a+b;
		}
		cout<<asum<<' '<<bsum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <stack>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;



int main() {

  ll N;
  cin >> N;
  ll ans = 0;

  if( N  > 1 ){
    ans = ( N - 1 ) * ( N - 1 + 1 ) / 2;
  }

  cout << ans << endl;
 
  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut g = vec![vec![]; n];

    for _ in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        g[a].push(b);
        g[b].push(a);
    }

    let mut a_count = vec![0; n];
    let mut b_count = vec![0; n];
    for from in 0..n {
        for &to in g[from].iter() {
            if s[from] == 'A' {
                a_count[to] += 1;
            } else {
                b_count[to] += 1;
            }
        }
    }

    let mut new_unuse = HashSet::new();
    let mut usable = vec![true; n];
    for from in 0..n {
        if a_count[from] == 0 || b_count[from] == 0 {
            usable[from] = false;
            new_unuse.insert(from);
        }
    }

    while !new_unuse.is_empty() {
        let mut unuse = HashSet::new();
        std::mem::swap(&mut unuse, &mut new_unuse);
        for &i in unuse.iter() {
            for &to in g[i].iter() {
                if s[i] == 'A' {
                    a_count[to] -= 1;
                } else {
                    b_count[to] -= 1;
                }
                if (a_count[to] == 0 || b_count[to] == 0) && usable[to] {
                    new_unuse.insert(to);
                    usable[to] = false;
                }
            }
        }
    }
    if usable.iter().any(|&x| x) {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 22780
def acceptable(t, a, b, t_next, a_next, b_next):
    distance = abs(a_next - a) + abs(b_next - b)

    if (t_next - t) < distance:
        return False

    if (t_next - t) % 2 != distance % 2:
        return False

    return True


n = int(input())
t_next, a_next, b_next = 0, 0, 0
for i in range(n):
    t, a, b = t_next, a_next, b_next
    t_next, a_next, b_next = map(int, input().strip().split())

    if not acceptable(t, a, b, t_next, a_next, b_next):
        print('No')
        exit(0)

print('Yes')


Measured memory_bytes: 3064
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(long long i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(long long i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1<<30)-10;


void solve(){
  string S; cin >> S;
  deque<char> deq;
  for(auto c:S) deq.push_back(c);
  Int flag = 0;
  Int Q; cin >> Q;
  rep(q, Q){
    Int t; cin >> t;
    if(t == 1){
      flag = 1 - flag;
      continue;
    }
    Int f; char c;
    cin >> f >> c;
    if(f == 1 && flag == 0 || f == 2 && flag == 1) deq.push_front(c);
    else deq.push_back(c);
  }
  S = "";
  for(auto c: deq) S += string(1, c);
  if(flag) reverse(ALL(S));
  cout << S << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  solve();
  // Failed to predict input format
  return 0;
}


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

using Weight = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src_, int dst_, Weight weight_) :
        src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> stronglyConnectedComponents(const Graph &g){
    int n = g.size(); Graph rg(n);
    for(const Edges &es : g) for(const Edge &e : es) rg[e.dst].eb(e.dst, e.src, e.weight);
    static int S[10010];
    vector<int> cmp(n, -1), added(n), visited(n), ord(n);
    int sz = 0;
    for(int i = 0; i < n; i++)if(!visited[i]){
        int s = 0;
        S[s++] = i;
        while(s){
            int v = S[s-1]; visited[v] = true;
            bool pushed = false;
            for(auto & e : g[v]){
                int dst = e.dst;
                if(!visited[dst]){ S[s++] = dst; pushed = true; }
            }
            if(pushed) continue;
            int t = S[s-1];
            if(!added[t]){ added[t] = true; ord[sz++] = t; }
            --s;
        }
    }
    int k = 0;
    for(int i = 0; i < n; i++){
        int u = ord[n-i-1];
        if(cmp[u] != -1) continue;
        int s = 0; S[s++] = u;
        while(s){
            int v = S[--s]; cmp[v] = k;
            for(auto & e : rg[v]){
                int d = e.dst;
                if(cmp[d] == -1) S[s++] = d;
            }
        }
        ++k;
    }
    return cmp;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    Graph g(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        g[a].eb(a,b,0);
    }
    vector<int> c = stronglyConnectedComponents(g);
    int q; cin >> q;
    rep(i,q){
        int a,b;
        cin >> a >> b;
        cout << (c[a]==c[b]) << '\n';
    }
}

Measured memory_bytes: 4120
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;

v32 topo(vv32& adj){

	int n = adj.size();

	v32 ans;
	v32 in_degree(n,0);

	queue<int> q;

	forn(i,n){
		for(v32::iterator it = adj[i].begin(); it != adj[i].end(); ++it){
			in_degree[*it]++;
		}
	}

	forn(i,n) if(in_degree[i] == 0) q.push(i);

	while(!q.empty()){
		int x = q.front();
		q.pop();
		ans.pb(x);

		for(v32::iterator it = adj[x].begin(); it != adj[x].end(); ++it){
			in_degree[*it] --;
			if(in_degree[*it] == 0) q.push(*it);
		}
	}

	return ans;
}

void makegraph(vv32& adj, int n, int m){
	// n is number of vertices
	// m is number of edges

	adj.resize(n);
	int x, y;

	forn(i,m){
		cin >> x >> y;
		adj[x-1].pb(y-1);
	}
}

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

	int n, m;
	cin >> n >> m;

	vv32 adj;

	makegraph(adj, n, m);

	ll dp[n];
	forn(i,n) dp[i] = 0;

	v32 x = topo(adj);

	forn(i,n){
		for(v32::iterator it = adj[x[i]].begin(); it != adj[x[i]].end(); ++it){
			dp[*it] = max(dp[*it], dp[x[i]]+1);
		}
	}

	ll maxval = 0;

	forn(i,n) maxval = max(maxval, dp[i]);

	cout << maxval;


}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> data(H,vector<char>(W));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        cin >> data.at(i).at(j);
    }
  }
  vector<int> x = { 0, 0, -1, -1, -1, 1, 1, 1};

  vector<int> y = { -1, 1, -1, 0, 1, -1, 0, 1};
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        if (data.at(i).at(j)=='#'){
          continue;
        }
  		int count=0;
  		for(int k=0;k<8;k++){
    		int a=i+y.at(k);
    		int b=j+x.at(k);
    		if (a<0 || a >=H){
      		continue ;
    		}
    		if (b<0 || b >=W){
      		continue;
    		}
    		if (data.at(a).at(b)=='#'){
      		count++;
   		    }	
         }
      vector<char> fig = { '0', '1', '2', '3', '4', '5', '6', '7', '8'};
      
      data.at(i).at(j)=fig.at(count);
    }
  }
      
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << data.at(i).at(j);
      if (j==W-1) cout<<endl;
    }
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
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; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll N,K;
vector<ll> dp;
vector<ll> h;

int main()
{
    cin >> N >> K;
    h.resize(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    dp.resize(N);
    for(int i = 0; i < N; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < N; i++)
    {
        for(int j = 1; j <= K; j++)
        {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            // cout <<"N = " << N << "...."<< "dp["  << i + j << "] = "<< dp[i + j] << endl;
        }
    }
    
    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a[3];
  int ans[4]; // 個数直角鋭角鈍角
  CLR(ans);
  while(cin>>a[0]>>a[1]>>a[2]) {
    sort(a,a+3);
    if(a[2] >= a[1] + a[0]) break;
    ans[0]++;
    if(a[2]*a[2]==a[1]*a[1]+a[0]*a[0]) ans[1]++;
    if(a[2]*a[2]<a[1]*a[1]+a[0]*a[0]) ans[2]++;
    if(a[2]*a[2]>a[1]*a[1]+a[0]*a[0]) ans[3]++;
  }
  FOR(i,0,4) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

ll k;
ll a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void){
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php
    $b = (trim(fgets(STDIN)));

    switch ($b) {
        case 'A':
            // code...
            $ans = "T";
            break;
        
        case 'T':
            $ans = "A";
            // code...
            break;
        
        case 'C':
            $ans = "G";
            // code...
            break;
        
        case 'G':
            $ans = "C";
            // code...
            break;
        
        default:
            // code...
            break;
    }
    echo $ans;
?>

Measured memory_bytes: 16252
#include<bits/stdc++.h>                          
using namespace std;
string s;
int x;
int main(){
    cin>>s;
    if(s[0]=='o') x++;
    if(s[1]=='o') x++;
    if(s[2]=='o') x++;
    cout<<700+x*100;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll n,c,k,ans=0;
    cin>>n>>c>>k;
    vector<ll>t(n);
    for(ll i=0;i<n;i++)cin>>t[i];
    sort(t.begin(),t.end());
    for(ll i=0;i<n;){
        ll beg=t[i];
        ll num=0;
        while(i<n&&num<c){
            if(t[i]<=beg+k){
                i++;
                num++;
            }
            else{
                break;
            }
        }
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1152
def solve(arr, n, sum, currsum)
  if n == arr.size
    currsum == sum
  else
    if solve(arr, n + 1, sum, currsum + arr[n])
      true
    elsif solve(arr, n + 1, sum, currsum)
      true
    else
      false
    end
  end
end

def main
  n = gets.chomp.to_i
  arr = gets.chomp.split(/\s/).collect { |x| x.to_i}
  q = gets.chomp.to_i
  questions = gets.chomp.split(/\s/).collect { |x| x.to_i}
  questions.each do |question|
    if solve(arr, 0, question, 0)
      puts "yes"
    else
      puts "no"
    end
  end
end

main

Measured memory_bytes: 6116
import java.util.Scanner;

public class Main {
	  public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int h = sc.nextInt();
	    int w = sc.nextInt();
	    int count = 0;
	    for(int i = 0; i < n; i++) {
	    	int tmpA = sc.nextInt();
	    	int tmpB = sc.nextInt();
	    	if(tmpA >= h && tmpB >= w) {
	    		count++;
	    	}
	    }
	    System.out.println(count);
	}
}

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int i, int j){ return A[i] > A[j]; });

    static int64_t dp[2001][2001];
    for(int i=0; i<N; i++) for(int j=0; i+j<N; j++){
        int pos = order[i+j];
        chmax(dp[i+1][j], dp[i][j] + A[pos]*abs(pos - i));
        chmax(dp[i][j+1], dp[i][j] + A[pos]*abs(pos - (N-1-j)));
    }
    int64_t ans = 0;
    for(int i=0; i<=N; i++) chmax(ans, dp[i][N-i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26216
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = int(input())
    N = N % 500
    if N > A:
        print('No')
    else:
        print('Yes')
if __name__ == '__main__':
    main()


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll x;
    cin>>x;
    ll ans=0,money=100;
    while(money<x){
        money=money*1.01;
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3620
from collections import defaultdict

N = int(input())
A = [int(input()) for _ in range(N)]
B = A[:]
B.sort()
idx = defaultdict(int)

for i in range(N):
    idx[B[i]] = i

ans = 0

for i in range(0, N, 2):
    if idx[A[i]]%2==1:
        ans += 1

print(ans)

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


int main(){
    int N; cin >> N;
    int h[N];
    rep(i,N) cin >> h[i];
    ll dp[N] = {0};
    dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < N; i++)
    {
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0
 
#define putb push_back
#define f first
#define s second
 
#define putf push_front
#define gainb pop_back
 
#define gainf pop_front
#define len(x) (ll)x.size()
 
typedef double db;
typedef long long ll;
 
const ll ary=1e4+5;
const ll mod=1e9+7;
const ll inf=1e18;
 
using namespace std;
ll n,t;
pair<ll,ll> p[ary];
ll dp[ary];
int main(){
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>p[i].f>>p[i].s;
	}
	sort(p+1,p+n+1);
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=t;j>=1;j--){
			dp[j+p[i].f]=max(dp[j+p[i].f],dp[j]+p[i].s);
		}
	}
	for(int i=1;i<=10000;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 384
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, std::vector<long long> l, std::vector<long long> r){
    LL ans=0;
    REP(i, N){
        ans += r[i] - l[i] + 1;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> l(N);
    std::vector<long long> r(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	double r, pi = 3.141592653589;
	cin >> r;
	printf("%.6lf\n", pi * r * r); 
	cout << " ";
	printf("%.6lf", pi * 2 * r);
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int x, t;
    cin >> x >> t;
    int ans = max(0, x-t);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,s;cin >> n >>s;
    vl a(n);rep(i,n)cin >> a[i];
    vvl dp(n+1,vl(s+1,0));
    dp[0][0]=1;
    rep(i,n){
        rep(j,s+1){
            if(j+a[i]<=s)dp[i+1][j+a[i]]+=dp[i][j],dp[i+1][j+a[i]]%=MOD9;
            dp[i+1][j]+=dp[i][j],dp[i+1][j]%=MOD9;
        }
        dp[i+1][0]++;   
    }
    ll ans=0;
    rep(i,n+1){
        ans+=dp[i][s];
        ans%=MOD9;
    }
    cout << ans <<endl;
}   

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

int main(){
  ll n;cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v.at(i);
  sort(v.begin(),v.end());
  v.push_back(0);
  ll sum = 1,ans = 0;
  rep(i,n){
    if (v.at(i) == v.at(i+1)){
      sum++;
    }
    else {
      ans += sum%2;
      sum = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <iterator>
#define r(i, n) for (int i = 0; i < n; i++)
#define R(i, c, n) for (int i = c; i < n; i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a)            \
  REP(d, a.size())         \
  {                        \
    cout << a[d];          \
    if (d != a.size() - 1) \
      cout << " ";         \
    else                   \
      cout << endl;        \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) \
  sort(ALL(v));   \
  v.erase(unique(ALL(v)), v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

  int n,m,c;
  cin >> n >> m >> c;
  int b[m];
  r(i,m) cin >> b[i];
  int a[n][m];
  r(i,n) r(j,m) cin >> a[i][j];
  int cnt = 0;
  int result;
  r(i,n) {
    result = 0;
    r(j,m) {
      result += b[j] * a[i][j];
    }
    result += c;
    if (result>0) cnt ++;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;


int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = 0;
  if (d < b) ans = 1;
  cout << ans << endl;

  return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> ans1;
	vector<int> ans2;
	
	for(auto &i:A)cin >> i;
	
	sort(A.begin(),A.end());
	
	vector<int> minus;
	int pos=0;
	while(A[pos]<0){
		minus.push_back(A[pos]);
		pos++;
	}
	
	if(pos==0){
		int a=A[0];
		for(int i=0;i<N-2;i++){
			ans1.push_back(a);
			ans2.push_back(A[i+1]);
			a-=A[i+1];
		}
		ans1.push_back(A[N-1]);
		ans2.push_back(a);
		cout << A[N-1]-a << endl;
	}
	else if(pos<N){
		for(;pos<N-1;pos++){
			ans1.push_back(minus[0]);
			ans2.push_back(A[pos]);
			minus[0]-=A[pos];
		}
		for(auto &m:minus){
			ans1.push_back(A[N-1]);
			ans2.push_back(m);
			A[N-1]-=m;
		}
		cout << A[N-1] << endl;
	}
	else{
		reverse(A.begin(),A.end());
		int a=A[0];
		for(int i=0;i<N-1;i++){
			ans1.push_back(a);
			ans2.push_back(A[i+1]);
			a-=A[i+1];
		}
		cout << a << endl;
	}
	
	for(int i=0;i<N-1;i++)cout << ans1[i] << " " << ans2[i] << endl;
	return 0;
}

Measured memory_bytes: 3960
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int t[n], a[n];
    int lb[2][n], ub[2][n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        if (i == 0 || t[i-1] != t[i]) lb[0][i] = ub[0][i] = t[i];
        else lb[0][i] = 1, ub[0][i] = t[i];
    }
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n-1; i >= 0; i--) {
        if (i == n-1 || a[i+1] != a[i]) lb[1][i] = ub[1][i] = a[i];
        else lb[1][i] = 1, ub[1][i] = a[i];
    }
    long long ans = 1;
    const int M = 1000000007;
    for (int i = 0; i < n; i++) {
        int d = min(ub[0][i], ub[1][i]) - max(lb[0][i], lb[1][i]) + 1;
        if (d <= 0) { ans = 0; break; }
        ans = ans * d % M;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String s=next();

        int len,con;
        con=0;
        len=s.length();
        for(int i = 0;i<len/2;i++){
            if(s.charAt(i)!=s.charAt(len-i-1)){
                con+=1;
            }
        }
        print(con);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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 main(){
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    ll ans = -INT64_MAX;
    cin >> a >> b >> c >> d;
    chmax(ans, a*c);
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    cout << ans << endl;
}


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

typedef long long ll; 

const int N = 1200; 
const int INF = 1 << 30; 
const int MOD = 1000000007;

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

inline ll add( ll a, ll b ) { return a + b >= MOD ? a + b - MOD : a + b; } 

int n, m, a[N], b[N], presum[N*N], presuma[N*N], presumb[N*N]; 

int main()
{
//	freopen( "d.in", "r", stdin ); 

	n = read(); m = read(); int maxx = n * m; 
	
	for( int i = 1; i <= n; i ++ )
		a[i] = read(), presuma[ a[i] ] ++;	
	
	for( int i = 1; i <= m; i ++ )
		b[i] = read(), presumb[ b[i] ] ++; 
		
	for( int i = 1; i <= n; i ++ )
		for( int j = 1; j <= m; j ++ )
			presum[ min( a[i], b[j] ) ] ++; 
	
	for( int i = 2; i <= maxx; i ++ )
		presum[i]  += presum[i-1] , 
		presuma[i] += presuma[i-1],
		presumb[i] += presumb[i-1];  

	ll ans = 1;
	for( int i = maxx; i >= 1; i -- )
	{
		int ina = presuma[i] - presuma[i-1], 
			inb = presumb[i] - presumb[i-1];
	
		if( ina > 1 || inb > 1 ) { ans = 0; break; }
		
		if( ina && inb ) continue;
		
		if( ina ) {	ans = ans * ( presumb[maxx] - presumb[i-1] ) % MOD; continue; }
		if( inb ) {	ans = ans * ( presuma[maxx] - presuma[i-1] ) % MOD; continue; }
		
		if( presum[maxx] - presum[i-1] - ( maxx - i ) <= 0 ) { ans = 0; break; }
		
		ans = ans * ( presum[maxx] - presum[i-1] - ( maxx - i ) ) % MOD;
	}
	
	cout << ans << endl;	

	return 0; 
}

Measured memory_bytes: 16640
class Factorial():
    def __init__(self,n,mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n+1)]
        self.inv = [0 for _ in range(n+1)]
        self.factorial[0] = 1
        for i in range(n):
            self.factorial[i+1] = self.factorial[i]*(i+1)%mod
        self.inv[n] = pow(self.factorial[n],mod-2,mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i+1]*(i+1)%mod

    def comb(self,m,k):
        if m-k<0 or k<0: return 0
        return self.factorial[m]*self.inv[k]*self.inv[m-k]%self.mod

MOD = 1000000007

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

F = Factorial(N+1,MOD)

tmp = [None for _ in range(N)]

for i in range(N+1):
    if tmp[A[i]-1] is None:
        tmp[A[i]-1] = i
    else:
        a = tmp[A[i]-1]
        b = i
        break

A = []

for i in range(1,N+2):
    A.append((F.comb(N-1,i)+F.comb(N-1,i-2)+F.comb(N-1,i-1)*2-F.comb(N+a-b,i-1))%MOD)

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

Measured memory_bytes: 27452