akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
    char c;
    vector<int> v1,v2;

    while(cin>>c){
        v1.push_back(c-'0');

        for(int i=0;i<9;i++){
            cin>>c;
            v1.push_back(c-'0');
        }

        cin.ignore();

        do{
            v2.clear();
            for(int i=0;i<v1.size()-1;i++){
                v2.push_back((v1[i]+v1[i+1])%10);
            }
            v1=v2;
        }while(v2.size()>1);

        cout<<v2[0]<<endl;

        v1.clear();
    }

    return 0;
}

Measured memory_bytes: 1196
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	string s; cin>>s;
	if(s == "SUN"){
		cout << 7 << endl;
	}
	if(s == "MON"){
		cout << 6 << endl;
	}
	if(s == "TUE"){
		cout << 5 << endl;
	}
	if(s == "WED"){
		cout << 4 << endl;
	}
	if(s == "THU"){
		cout << 3 << endl;
	}
	if(s == "FRI"){
		cout << 2 << endl;
	}
	if(s == "SAT"){
		cout << 1 << endl;
	}

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        h: usize,
        w: usize,
        t: [chars; h],
    }
    let mut t = t;


    let mut dp = Vec::new();

    for i in 0..h {
        let mut ok = false;
        for j in 0..w {
            if '.' != t[i][j] {
                ok = false;
                break;
            } else {
                ok = true;
            }
        }
        if !ok {
            let mut tmp = Vec::new();
            for j in 0..w {
                tmp.push(t[i][j]);
            }
            dp.push(tmp);
        }
    }

    let mut dp2: Vec<Vec<char>> = Vec::new();

    if !dp.is_empty() {
        for j in 0..dp[0].len() {
            let mut ok = false;
            for i in 0..dp.len() {
                if '.' != dp[i][j] {
                    ok = false;
                    break;
                } else {
                    ok = true;
                }
            }
            if !ok {
                let mut tmp = Vec::new();
                for i in 0..dp.len() {
                    tmp.push(dp[i][j]);
                }
                dp2.push(tmp);
            }
        }
    }

    if !dp2.is_empty() {
        for i in 0..dp2[0].len() {
            for j in 0..dp2.len() {
                print!("{}",dp2[j][i]);
            }
            println!();
        }
    }
}

Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CDiceAndCoin {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            double ans = 0;
            for (int i = 1; i <= n; ++i) {
                double cur = 1;
                int val = i;
                while (val < k) {
                    val *= 2;
                    cur /= 2;
                }
                ans += cur / n;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22100
import scala.collection.mutable.{Map => MMap}
object Main extends App {
  type Score = Long
  type Count = Int
  val in = new java.util.Scanner(System.in)
  val D = in.nextInt
  val G = in.nextLong / 100
  case class Problem(n: Int, bonus: Score)
  val Ps = List.fill(D)(Problem(in.nextInt, in.nextLong / 100))

  val map = MMap[Score, Count](0L -> 0).withDefaultValue(Int.MaxValue)
  def dp(ps: List[Problem], mult: Int): Count = {
    val list = map.toList
    ps match {
      case Nil => map.minBy(cs => if (cs._1 >= G) cs._2 else Int.MaxValue)._2
      case x :: xs =>
        for {
          n <- (1 to x.n)
          sc <- list
        } {
          val (score, count) = sc
          val newScore = score + n * mult + (if (n == x.n) x.bonus else 0L)
          map(newScore) = map(newScore) min (count + n)
        }
        dp(xs, mult + 1)
    }
  }

  println(dp(Ps, 1)) 
}

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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  vector<bool> dp(K + 1, false);
  for (int i = 0; i <= K; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++) {
      if (i - a[j] < 0) break;
      if (!dp[i - a[j]]) {
        flag = true;
        break;
      }
    }
    dp[i] = flag;
  }

  cout << (dp[K] ? "First" : "Second") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	int ans = 1000;
	for (int i = 0; i < N; i++) {
		int Ai;
		cin >> Ai;
		int cnt = 0;
		while (Ai % 2 == 0) {
			Ai /= 2;
			cnt++;
		}
		if (cnt < ans) ans = cnt;
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  map<int64_t,int64_t>tmp;
  int64_t size=s.size();
  vector<int64_t>t(size);
  vector<int64_t>amari(size+100,0);
  amari.at(1)=10;
  for(int64_t i=2;i<=size+99;i++){
    amari.at(i)=amari.at(i-1)*10%2019;
  }
  t.at(0)=(int64_t)s.at(0)-'0';
  tmp[0]=1;
  tmp[t.at(0)]=1;
  for(int64_t i=1;i<size;i++){
    t.at(i)=(t.at(i-1)+amari.at(i)*((int64_t)s.at(i)-'0')%2019)%2019;
    if(tmp.count(t.at(i)))tmp.at(t.at(i))++;
    else tmp[t.at(i)]=1;         
  }
  int64_t ans=0;
  for(auto tmpi:tmp){
    ans+=(tmpi.second*(tmpi.second-1))/2;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 6732
import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
neg_num = len([x for x in A_list if x<0])
zero_num = len([x for x in A_list if x==0])
abs_list = [abs(x) for x in A_list]

ans = np.sum(abs_list)
if neg_num%2==0 or zero_num>0:
    ans = ans
elif neg_num%2!=0:
    ans = ans - 2*min([x for x in abs_list if x!=0])
print(ans)

Measured memory_bytes: 23364
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;


double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    int n;
    cin >> n;

    Point p0, p1, p2;
    double area = 0;

    for(int i=0; i<n; i++){
        if(i==0)
        {
            cin >> p0.x >> p0.y;
            p1.x = p0.x;
            p1.y = p0.y;
        }
        else
        {
            p1.x = p2.x;
            p1.y = p2.y;
        }
        if(i==n-1){
            p2.x = p0.x;
            p2.y = p0.y;
        }
        else{
            cin >> p2.x >> p2.y;
        }

        area += cross(p1,p2);
    }
    area = fabs(area)/2.0;

    std::cout << std::fixed;
    cout << setprecision(1) << area <<"\n";
    return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(int argc, char const* argv[]){
    int a,b,c;cin>>a>>b>>c;
    if(a+b == c || a == b+c || a+c == b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();

		ArrayList<Integer> a = new ArrayList<>(); //スイッチと繋がっている電球の集合
		for(int i=0; i<N; i++) {
			a.add(0);
		}

		for(int i=0; i<M; i++) {
			int k=sc.nextInt();
			for(int j=0; j<k; j++) {
				int s = sc.nextInt();
				s--;
				a.set(s, a.get(s) | (1<<i));
			}
		}

		int p=0;
		for(int i=0; i<M; i++) {
			int x = sc.nextInt();
			p |= (x<<i);
		}

		//押すスイッチの全集合を試す
		int ans = 0;
		for(int s = 0; s < (1<<N); s++) {
			int t=0;//スイッチ押した後の電球の状態
			for(int i=0; i<N; i++) {
				if(((s>>i)&1)==1) {
					//スイッチiを押すと対応する電球が変化する
					t ^= a.get(i);
				}
			}
			if(p==t) {
				ans++;
			}
		}
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1LL << 50;

class edge {
  public:
    ll from, to, cost;
    void init(ll a, ll b, ll c) {
        from = a;
        to = b;
        cost = c;
    }
};

int main() {
input:
    ll n, m;
    cin >> n >> m;
    edge es[m];
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        es[i].init(a - 1, b - 1, -c);
    }

calculate:

    ll d[n];
    rep(i, n) { d[i] = mod; }
    d[0] = 0;

    rep(j, n) {
        bool update = false;
        rep(i, m) {
            edge e = es[i];
            if (d[e.from] != mod && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
                if (j == n - 1 && e.to == n - 1) {
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
        if (!update) {
            break;
        }
    }

    ll ans = -d[n - 1];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int time = sc.nextInt();
        long ans = 1L;
        for (int i = 0; i < time; i++) {
            long mul = sc.nextLong();
            if(Math.log10(mul)+Math.log10(ans) > 18 || mul * ans > 1000000000000000000L){
                ans = -1;
            }else if(mul == 0){
                System.out.println(0);
                return;
            }else if(ans != -1){
                ans *= mul;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 59832
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int X;

void _main() {
    cin >> X;
    FOR (i, 1, X + 1) {
        int rem = X - i * 100;
        if (rem < 0) continue;
        if (rem <= i * 5) {
            cout << 1 << endl;
            return;
        }
    }
    cout << 0 << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
	char s[10];
  	int count =0;
  	gets(s);
  	for(int i=0;i<strlen(s);i++)
    {
      if(s[i]=='o')
      {
        count++;
      }
    }
  cout<<(700+count*100);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N;
    cin >> N;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<pair<int, int>> xy(N);
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        xy[i] = make_pair(x, y);
    }
    sort(ALL(xy));
    int ans = 1000000;
    for (int i = 0; i < N - 1; i++) {
        int xi, yi;
        tie(xi, yi) = xy[i];
        for (int j = i + 1; j < N; j++) {
            int xj, yj;
            tie(xj, yj) = xy[j];
            int p = xj - xi, q = yj - yi;
            set<pair<int, int>> st;
            int tmp = 0;
            REP(k, N) {
                if (st.count(xy[k]) == 0) {
                    tmp++;
                } else {
                    st.erase(xy[k]);
                }
                st.insert(make_pair(xy[k].first + p, xy[k].second + q));
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
int n,m,ans,par[100005];
int find(int v){
	if(par[v]==v)return v;
	return par[v]=find(par[v]);
}
bool same(int v,int u){
	return find(v)==find(u);
}
void unit(int u,int v){
	v=find(v);
	u=find(u);
	par[v]=u;
}
int main(void){
	scanf("%d%d",&n,&m);
	ans=n;
	for(int i=0;i<n;i++)par[i]=i;
	for(int i=0;i<m;i++){
		int a,b,c;;
		scanf("%d%d%d",&a,&b,&c);
		a--,b--;
		if(!same(a,b)){
			ans--;
			unit(a,b);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 640
#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);
  }
  int64_t b = 0;
  for (int i = 1; i < N; i++) {
    if (a.at(i - 1) <= a.at(i)) {
      continue;
    }
    else {
      b += a.at(i - 1) - a.at(i);
      a.at(i) = a.at(i - 1);
    }
  }
  cout << b << endl;
}

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

using namespace std;

const int MAXN = 300 + 10;
const int MOD = 998244353;

string s;
int n;
bool f[MAXN][MAXN][MAXN];
int a[MAXN][MAXN], dp[MAXN][MAXN][MAXN];

void add(int &a, int b) {
    a = (a + b) % MOD;
}

int main() {
    cin >> s;
    n = s.length();
    
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= n; ++j)
            a[i][j] = -1;
            
    f[0][0][0] = true;
    for(int i = 0; i <= s.length(); ++i) {
        int l0 = 0, l1 = 0;
        for(int j = i; j < s.length(); ++j) {
            l0 += (s[j] == '0'); l1 += (s[j] == '1');
        }
        
        for(int sum = s.length(); sum >= 0; --sum)
            for(int n0 = 0; n0 <= sum; ++n0) {
                int n1 = sum - n0;
                if (f[i][n0][n1] == false) continue;
                a[n0 + l0][n1 + l1] = max(a[n0 + l0][n1 + l1], i);
                
                if (sum >= 2) {
                    if (n0 > 0) f[i][n0 - 1][n1] = true;
                    if (n1 > 0) f[i][n0][n1 - 1] = true;
                }
                if (i < s.length() && sum > 0) {
                    f[i + 1][n0][n1] = true;
                    if (n0 > 0) f[i + 1][n0 + (s[i] == '0') - 1][n1 + (s[i] == '1')] = true;
                    if (n1 > 0) f[i + 1][n0 + (s[i] == '0')][n1 + (s[i] == '1') - 1] = true;
                }
                if (i + 1 < s.length()) {
                    f[i + 2][n0 + (s[i] == '0')][n1 + (s[i] == '1')] = true;
                    f[i + 2][n0 + (s[i + 1] == '0')][n1 + (s[i + 1] == '1')] = true;
                }
            }
    }
    
    dp[0][0][s.length()] = 1;
    for(int sum = 0; sum < s.length(); ++sum) {
        for(int n0 = 0; n0 <= sum; ++n0) {
            int n1 = sum - n0;
            for(int i = 0; i <= s.length(); ++i) {
                add(dp[n0 + 1][n1][ i - ((i > 0 && s[i - 1] == '0') ? 1 : 0)], dp[n0][n1][i]);
                add(dp[n0][n1 + 1][ i - ((i > 0 && s[i - 1] == '1') ? 1 : 0)], dp[n0][n1][i]);
            }
        }
    }
    
    int res = 0;
    for(int n0 = 0; n0 <= s.length(); ++n0)
        for(int n1 = 0; n0 + n1 <= s.length(); ++n1) {
            if (a[n0][n1] >= 0) {
                for(int j = 0; j <= a[n0][n1]; ++j) add(res, dp[n0][n1][j]);
            }
        }
        
    cout << res << "\n";
}

Measured memory_bytes: 68216
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

l = list(map(int, input().split()))

l.sort()

if (l[0] == 5 and l[1] == 5 and l[2] == 7):
    print("YES")
else:
    print("NO")



Measured memory_bytes: 9052
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.length();i++)
    {
        char x=s[i];
        for(int j=0;j<n;j++)
        {
            if(x=='Z')
            x='A';
            else
            x++;
        }
        cout<<x;
    }}

Measured memory_bytes: 3648
# どうせ何を喰っても自分のポイントは入るので、
# 高橋くんは青木くんの得られるポイントの最大のやつを,青木くんは高橋くんのvice versa
# 同じポイントならその中でも自分が得られるものが多いほうがいい
# ↑ ぜーーーーーーーーーーーーーーーーーんぜんだめでした

# 解説みた ぜんぜんわからん 無理 

n = int(input())
arr = []
used = [False for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    arr.append([i, a, b])

lis = sorted(arr, key=lambda x: x[1] + x[2], reverse=True)
takp, aokp = 0, 0

c = 0

while c < n:
    if c % 2 == 0:
        # 高橋くんのターン
        takp += lis[c][1]
    else:
        # 青木くんのターン
        aokp += lis[c][2]
    c += 1
print(takp - aokp)


Measured memory_bytes: 29164
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_114
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int x = ReadInt();
            string s = x == 3 || x == 5 || x == 7 ? "YES" : "NO";
            Console.WriteLine(s);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
long long n,a;
int main(){
    cin>>n;
    if(n&1)a=0;
    else if(n<10)a=0;
    else{
        n/=10;
        a+=n;
        while(n>=5){
            n/=5;
            a+=n;
        }
    }
    cout<<a<<endl;
}


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


const int MaxN = 1e5 + 15;
const int MaxK = 20;

vector <int> v[MaxN];
int n;
int color[MaxN];
int jump[MaxN][MaxK];

int cnt[3];

int timer, tin[MaxN], tout[MaxN];

bool isParent(int x, int y)
{
    return tin[x] <= tin[y] && tout[x] >= tout[y];
}

void dfs(int x, int p = 0)
{
    tin[x] = ++timer;
    jump[x][0] = p;
    for(int i = 1; i < MaxK; ++i)
        jump[x][i] = jump[jump[x][i - 1]][i - 1];

    for(int i = 0; i < v[x].size(); ++i)
        if(v[x][i] != p)
            dfs(v[x][i], x);

    tout[x] = timer;
}

int lca(int x, int y)
{
    if(isParent(x, y))
        return x;
    if(isParent(y, x))
        return y;
    for(int i = MaxK - 1; i >= 0; --i)
        if(jump[x][i] && !isParent(jump[x][i], y))
            x = jump[x][i];
    return jump[x][0];
}

void paint(int x, int color, int p = 0)
{
    if(::color[x] && ::color[x] != color)
        return;
    ::color[x] = color;
    ++cnt[color];
    for(int i = 0; i < v[x].size(); ++i)
        if(v[x][i] != p)
            paint(v[x][i], color, x);
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1);
    color[1] = 1;
    color[n] = 2;
    int l = lca(1, n);

    vector <int> order, order1;

    for(int a = 1; a != l; a = jump[a][0])
        order.push_back(a);

    order.push_back(l);
    for(int a = n; a != l; a = jump[a][0])
        order1.push_back(a);

    for(int i = 0; i < order1.size(); ++i)
        order.push_back(order1[order1.size() - 1 - i]);

    for(int step = 1, l = 1, r = order.size() - 2; l <= r; ++step)
    {
        if(step & 1)
        {
            color[order[l]] = 1;
            ++l;
        }else
        {
            color[order[r]] = 2;
            --r;
        }
    }

    paint(1, 1);
    paint(n, 2);

    if(cnt[1] > cnt[2])
        cout << "Fennec\n";
    else
        cout << "Snuke\n";

    return 0;
}


Measured memory_bytes: 22136
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    set<int>st[30];
    vector<char>s(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        st[s[i] - 'a'].insert(i);
    }
    int q;
    cin >> q;
    for(int i = 1; i <= q; i++){
        int t;
        cin >> t;
        if(t == 1){
            int x;
            char ch;
            cin >> x >> ch;
            st[s[x] - 'a'].erase(x);
            st[ch - 'a'].insert(x);
            s[x] = ch;
        }
        else{
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            for(int i = 0; i < 26; i++){
                if(st[i].lower_bound(l) != st[i].upper_bound(r)){
                    cnt++;
                }
            }
            cout << cnt << '\n';
        }
    }
    return 0;
}

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

void solve(long long N, long long K, std::vector<long long>&& xs)
{
    ll ans = 1e9;

    for (ll i = 0; i + K - 1 < N; ++i) {
        auto j = i + K - 1;
        ans = min(ans, abs(xs[j]) + abs(xs[i] - xs[j]));
        ans = min(ans, abs(xs[i]) + abs(xs[i] - xs[j]));
    }

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, K, std::move(x));
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] s = sc.next().toCharArray();
//		String s = sc.next();
		sc.close();
		int cnt=0;
		for (i = 0; i < s.length-2; i++) {
			if(s[i]=='A'
			&& s[i+1]=='B'
			&& s[i+2]=='C') {
				cnt++;
			}
		}
		out.println(cnt);
	}
}


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



void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a==c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int n, i;
        int a[] = new int[1000];
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        for(i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        for( i = n - 1; i >= 0; i--){
            System.out.printf("%d", a[i]);
            if(i !=0){
                System.out.printf(" ");
            }
        }
        System.out.printf("\n");
        scan.close();
    }
}



Measured memory_bytes: 26324
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using namespace boost::icl;

int main() {
	int A, B,C;

	cin >> A >> B>>C;

	cout << max(0, C - (A - B)) << endl;

	return 0;
}


Measured memory_bytes: 256
module B
  sub Main(byval args() as string)
    dim s as string=console.readline()
    dim n,m,l as integer
    dim res as boolean = true
    dim cs as string
    n=s.length
    m=math.floor(n/2)
    if left(s,m)<>strreverse(right(s,m)) then res=false
    l=(n-1)/2
    cs=left(s,l)
    m=math.floor(l/2)
    if res = true andalso left(cs,m)<>strreverse(right(cs,m)) then res= false
    cs=right(s,l)
    if res = true andalso left(cs,m)<>strreverse(right(cs,m)) then res= false
    console.writeline(if(res,"Yes","No"))
  end sub
end module

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

using namespace std;

int main() {
    
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    int da = min(a, k);
    k -= da;
    int db = min(b, k);
    k -= db;
    int dc = min(c, k);
    k -= dc;

    cout <<da - dc << "\n";
    return 0;
}


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

class unionfind{ // 0-indexed
public:
	vector<int> parent;
	vector<int> size;
	int num_of_disjointsets;
	unionfind(int n){
		parent.resize(n, -1);
		size.resize(n, 1);
		num_of_disjointsets = n;
	}

	int find(int x){
		if(parent[x] == -1) return x;
		return parent[x] = find(parent[x]);
	}

	int unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return -1;
		if(size[x] < size[y]){
			parent[x] = y;
			size[y] += size[x];
			size[x] = 0;
			--num_of_disjointsets;
			return y;
		}else{
			parent[y] = x;
			size[x] += size[y];
			size[y] = 0;
			return x;
			--num_of_disjointsets;
		}
	}

	bool united(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for(auto &i:s) cin >> i;
	unionfind uf(h*w);
	typedef pair<int, int> P;
	vector<P> v(h*w, P(0, 0));
	int dx[4] = {0, 0, 1, -1};
	int dy[4] = {1, -1, 0, 0};
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j){
			for(int k=0; k<4; ++k){
				int x = i+dx[k];
				int y = j+dy[k];
				if(0 <= x && x < h && 0 <= y && y < w && s[i][j] != s[x][y])
					uf.unite(i*w+j, x*w+y);
			}
		}
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j){
			int r = uf.find(i*w+j);
			if(s[i][j] == '.') ++v[r].first;
			else ++v[r].second;
		}
	long long ans = 0;
	for(int i=0; i<h*w; ++i){
		ans += (long long)v[i].first * v[i].second;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2944
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
//0->A 1->T 2->G 3->C
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    ll dp[101][4][4][4];
    memset(dp, 0, sizeof(dp));
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                if((i==0&&j==2&&k==3)||(i==0&&j==3&&k==2)||(i==2&&j==0&&k==3))
                    continue;//AGC ACG GAC
                dp[3][i][j][k]=1;
            }
        }
    }
    for(int i=4;i<=n;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    if((j==0&&k==2&&l==3)||(j==0&&k==3&&l==2)||(j==2&&k==0&&l==3))
                        continue;
                    for(int m=0;m<4;m++){
                        if((j==0&&l==2&&m==3)||(j==0&&k==2&&m==3))
                            continue;//A?GC AG?C
                        dp[i][j][k][l]+=dp[i-1][k][l][m];
                    }
                    dp[i][j][k][l]%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for(int j=0;j<4;j++){
        for(int k=0;k<4;k++){
        for(int l=0;l<4;l++){
            if(j==2&&k==0&&l==3)continue;
            if(j==0&&k==2&&l==3)continue;
            if(j==0&&k==3&&l==2)continue;
            ans+=dp[n][j][k][l];
            ans%=MOD;
        }
        }
    }
    
    ans%=MOD;
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


/*  AGC ACG GAC ATGC AGGC ACGC AGAC AGTC AGGC  */


Measured memory_bytes: 256
my $input = get;
 my $in = chomp($input);

 my @data = split('',$in);
 my $ans = 0;
 my $ans_max = 0;

 for @data -> $w {
	if $w eq "R" {
		$ans += 1;
	} else {
		if $ans > $ans_max {
			$ans_max = $ans;
		}
		$ans = 0;
	}
 }

 say $ans_max;


Measured memory_bytes: 87756
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define MAX_P 200010
int fact[MAX_P]; //n! mid p

int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d;
}
int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}
//n! = a p^e -> a mod p
void make_fact()
{
    fact[1] = 1;
    for (int i = 2; i < MAX_P; i++)
    {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    return;
}
int mod_fact(int n, int p, int &e)
{
    e = 0;
    if (n == 0)
        return 1;
    int res = mod_fact(n / p, p, e);
    e += n / p;
    if (n / p % 2 != 0)
        return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}
//nCk mod p
int mod_comb(int n, int k, int p)
{
    if (n < 0 || k < 0 || n < k)
        return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
    if (e1 > e2 + e3)
        return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

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

    int n;
    cin >> n;
    int l, r;
    vector<int> last(n + 1, -1);
    rep(i, n + 1)
    {
        int a;
        cin >> a;
        if (last[a] == -1)
            last[a] = i;
        else
        {
            l = last[a];
            r = i;
        }
    }
    make_fact();
    rep(k, n + 1)
    {
        int ans = (mod_comb(n + 1, k + 1, mod) - mod_comb(l + n - r, k, mod)) % mod;
        ans = (ans + mod) % mod;
        cout << ans << endl;
    }
}

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

struct unionFind{
  vector<long long> par;
  vector<long long> sz;
  
  unionFind(long long n): par(n), sz(n){
    for(long long i=0; i<n; i++) {
      par[i] = i; sz[i] = 1;
    }
  }
  
  long long root(long long x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
  }
  
  bool issame(long long x, long long y){
    long long px = root(x);
    long long py = root(y);
    return px == py;    
  }
  
  void unite(long long x, long long y) {
    long long px = root(x);
    long long py = root(y);
    if(px == py) return;
    if(sz[px] < sz[py]) swap(px, py);
    par[py] = px;
    sz[px] += sz[py];
    return ;
  }  
  long long size(long long x) {
    return sz[root(x)];
  }
};

int main(void){
  long long N, M;
  cin >> N >> M;
  long long A[M]; long long B[M];
  for(long long i=0; i<M; i++) cin >> A[i] >> B[i];
  long long ans[M];
  unionFind uf = unionFind(N);
  long long comb = N*(N-1)/2;
  
  for(long long i=M-1; i>=0; i--){
    ans[i] = comb;
    long long tmpA = A[i]; tmpA--;
    long long tmpB = B[i]; tmpB--;
    if(uf.issame(tmpA, tmpB)) continue;
    comb -= uf.size(tmpA)*uf.size(tmpB);
    uf.unite(tmpA, tmpB);
  }
  for(long long i=0; i<M; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1e9+7
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 100010

ll dx[]={1,-1,0,0};
ll dy[]={0,0,1,-1};
int main(){
    IOS;
 
 	ll h,w,k; cin>>h>>w>>k;
 	ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
 	x1--,y1--,x2--,y2--;
 	ll a[h][w],d[h][w];
 	rep(i,0,h)rep(j,0,w){
 		char c;cin>>c;
 		a[i][j]=(c=='.');
 		d[i][j]=inf;
 	}
 	queue<pii>q;
 	q.push({x1,y1}),d[x1][y1]=0;
 	while(!q.empty()){
 		pii u=q.front(); q.pop();
 		ll x=u.fi,y=u.se;
 		rep(i,0,4)rep(j,1,k+1){
 			ll nx=x+dx[i]*j,ny=y+dy[i]*j;
 			if(nx<0 or ny<0 or nx>=h or ny>=w)continue;
 			if(!a[nx][ny] or d[x][y]+1>d[nx][ny])break;
 			if(d[x][y]+1<d[nx][ny]){
 				d[nx][ny]=d[x][y]+1;
 				q.push({nx,ny});
 			}
 		}
 	}
 	ll ans=d[x2][y2];
 	cout<<((ans==inf)?-1:ans);
    return 0;
}

Measured memory_bytes: 20728
#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[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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,m,x;cin >> n >>m >>x;
    vl p(n);vvl a(n);
    rep(i,n){
        cin >> p[i];
        rep(j,m){
            ll y;cin >> y;
            a[i].pb(y);
        }
    }
    ll ans=INF;
    rep(bit,1<<n){
        vl res(m,0);ll pri=0;
        rep(i,n){
            if(bit&(1<<i)){
                rep(j,m){
                    res[j]+=a[i][j];
                }
                pri+=p[i];
            }
        }
        ll check=1;
        rep(i,m){
            if(res[i]<x)check=false;
        }
        if(check)chmin(ans,pri);
    }
    if(ans!=INF)cout <<ans <<endl;
    else cout << -1 <<endl;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        ll N; cin >> N;
        N += 1;
        vector<int> pops;
        { // get pop pos
            ll NN = N;
            for(int i = 0; NN; i++) {
                if(NN & 1) pops.push_back(i);
                NN >>= 1;
            }
        }        

        
        vector<int> ans;
        int len = pops.back(); pops.pop_back();
        rep(i, len) ans.push_back(i + 1);

        int max_n = len;
        while(pops.size()) {
            ans.insert(ans.begin() + pops.back(), ++max_n);
            pops.pop_back();
        }
        rep(i, max_n) ans.push_back(i + 1);
        cout << ans.size() << endl;
        rep(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

int main()
{
    // std::cout << std::fixed << std::setprecision(5);
    int n; std::cin >> n;
    int t[n];
    int sum = 0;
    for(int i=0; i<n; i++)
    {
        std::cin >> t[i];
        sum += t[i];
    }
    
    int m; std::cin >> m;
    int p[m], x[m];
    for(int i=0; i<m; i++) std::cin >> p[i] >> x[i];

    for(int i=0; i<m; i++)
    {
        int temp = t[p[i]-1] - x[i];
        std::cout << sum - temp << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long LL;
char s[N];
int num[N];
int main(){
	int n,k,sum=0,d=1;LL ans=0;scanf("%d%d%s",&n,&k,s);
	if(k==2||k==5){
		for(int i=0;s[i];i++)if((s[i]-'0')%k==0)ans+=i+1;
		return printf("%lld\n",ans),0;
	}
	num[0]++;
	for(int i=n-1;~i;i--){
		(sum+=(s[i]-'0')*d)%=k,d=d*10%k;
		ans+=num[sum],num[sum]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
int d[2005];
int main()
{
	ios_base::sync_with_stdio(0);
	int n , x , y;
	cin >> n >> x >> y;
	for(int i = 1; i <= n; i++)
	{
		for(int j = i + 1; j <= n; j++)
		{
			d[min(j - i , abs(x - i) + abs(j - y) + 1)]++;
		}
	}
	for(int i = 1; i <= n - 1; i++)
		cout << d[i] << " ";
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 2e5 + 5;
int N, K, L;
vector<int> G[2][MAX_N];
int used[2][MAX_N];

void bfs(int s, int cnt, int num){
    queue<int> q;
    used[num][s] = cnt; q.push(s);

    while(q.size()){
        int u = q.front(); q.pop();
        for(auto v : G[num][u]){
            if(!used[num][v]){
                used[num][v] = cnt;
                q.push(v);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N >> K >> L;
    for(int i=0;i<K;i++){
        int p, q; cin >> p >> q;
        G[0][p].push_back(q); G[0][q].push_back(p);
    }
    for(int i=0;i<L;i++){
        int p, q; cin >> p >> q;
        G[1][p].push_back(q); G[1][q].push_back(p);
    }

    int cnt = 1;
    for(int i=1;i<=N;i++) if(!used[0][i]) bfs(i, cnt++, 0);
    cnt = 1;
    for(int i=1;i<=N;i++) if(!used[1][i]) bfs(i, cnt++, 1);

    map<P, int> c;
    for(int i=1;i<=N;i++) c[P(used[0][i], used[1][i])]++;

    for(int i=1;i<=N;i++) cout << c[P(used[0][i], used[1][i])] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 27940