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

int di[2] = {0,1};
int dj[2] = {1,0};
const int mod = 100000;

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        int dp[h+2][w+2][2][2];
        // initialize
        for(int i = 0; i < h+2; i++)    for(int j = 0; j < w+2; j++)
        for(int k = 0; k < 2; k++)      for(int l = 0; l < 2; l++)  
        dp[i][j][k][l] = 0;

        dp[0][1][0][0] = dp[1][0][1][0] = 1;

        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                for(int k = 0; k < 2; k++){
                    for(int l = 0; l < 2; l++){
                        if(l == 0){
                            dp[i+di[k]][j+dj[k]][k][0] += dp[i][j][k][l];
                            dp[i+di[k]][j+dj[k]][k][0] %= mod;
                            dp[i+di[1-k]][j+dj[1-k]][1-k][1] += dp[i][j][k][l];
                            dp[i+di[1-k]][j+dj[1-k]][1-k][1] %= mod;
                        }else if(l == 1){
                            dp[i+di[k]][j+dj[k]][k][0] += dp[i][j][k][l];
                            dp[i+di[k]][j+dj[k]][k][0] %= mod;
                        }
                    }
                }
            }
        }

        int ans = 0;
        for(int k = 0; k < 2; k++){
            for(int l = 0; l < 2; l++){
                ans = (ans + dp[h-1][w-1][k][l])%mod;
            }
        }
        cout << ans << endl;

    }
    return 0;
}


Measured memory_bytes: 3164
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		int n=gInt();
		int[]a=INTS(n).toArray();
		if(a[0]>0) {
			System.out.println(-1);
			return;
		}
		
		long r=0;
		for(int i:rep(1,n-1)) {
			if(a[i]-a[i-1]==1)
				++r;
			else if(a[i]-a[i-1]>=2) {
				System.out.println(-1);
				return;
			}else
				r+=a[i];
		}
		System.out.println(r);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;
    vector<int> warr(N, 0);
    vector<int> acarr(N, 0);
    
    int ans_ac = 0;
    int ans_pe = 0;
    for (int i = 0; i < M; i++) {
        int id;
        string s;
        cin >> id >> s;
        id--;
        
        if (acarr[id] == 0 && s == "WA") {
            warr[id] += 1;
        }
        if (s == "AC" && acarr[id] == 0) {
            acarr[id] = 1;
        }
    }
  
    for (int j = 0; j < N; j++) {
        if (acarr[j] > 0) {
            ans_ac++;
            ans_pe += warr[j];
        }
    }
  
    cout << ans_ac << " " << ans_pe << endl;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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




struct Segment_tree_min {
	using T = ll;

	ll n;
	vector<T> data;
	const T out = 1e9 + 5;

	inline T vmerge(T l, T r) { return min(l, r); }

	Segment_tree_min(ll n) :n(n) { data.assign(2 * n, out); }

	void update(ll p, T x) {  // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(ll l, ll r) {  // sum on llerval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};

struct Segment_tree_max {
	using T = ll;

	ll n;
	vector<T> data;
	const T out = 0;

	inline T vmerge(T l, T r) { return max(l, r); }

	Segment_tree_max(ll n) :n(n) { data.assign(2 * n, out); }

	void update(ll p, T x) {  // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(ll l, ll r) {  // sum on llerval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};


int main() {

	ll n;
	cin >> n;
	VP v(n);
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		v[i] = { b,a };
	}
	sort(ALL(v));

	Segment_tree_min rmq1(n), rmq2(n);
	Segment_tree_max rmq3(n), rmq4(n);

	REP(i, n) {
		rmq1.update(i, v[i].first);
		rmq3.update(i, v[i].second);
	}

	ll ans = 0;

	REP(i, n) {
		ll cnt = v[i].first - v[i].second + 1;
		rmq1.update(i, INF);
		rmq3.update(i, 0);
		ll a = rmq1.query(0, n) - rmq3.query(0, n) + 1;
		a = max(0LL, a);
		ans = max(ans, a + cnt);
		rmq1.update(i, v[i].first);
		rmq3.update(i, v[i].second);
	}
	REP(i, n - 1) {
		rmq1.update(i, INF);
		rmq3.update(i, 0);
		rmq2.update(i, v[i].first);
		rmq4.update(i, v[i].second);
		ll a = rmq1.query(0, n) - rmq3.query(0, n) + 1;
		ll b = rmq2.query(0, n) - rmq4.query(0, n) + 1;
		a = max(a, 0LL);
		b = max(b, 0LL);
		ans = max(ans, a + b);
	}
	cout << ans << endl;
}


Measured memory_bytes: 7296
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
  char a, b, ans;
  cin >> a >> b;

  if (a == 'H') {
    if (b == 'H') {
      ans = 'H';
    } else {
      ans = 'D';
    }
  } else {
    if (b == 'H') {
      ans = 'D';
    } else {
      ans = 'H';
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


int main() {
	ios::sync_with_stdio(false);


	int A, B, C;
	cin >> A >> B >> C;

	co(B * (C / A));

	Would you please return 0;
}

Measured memory_bytes: 764
lisST = input().split()
S=lisST[0]
T=lisST[1]
lisAB = input().split()
U = input()
A = int(lisAB[0])
B = int(lisAB[1])
if S == U:
    ansA, ansB = A-1, B
elif T == U:
    ansA, ansB = A, B-1
print(ansA, ' ', ansB)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	string a;
	cin >> a;
	int now=0,mx=0;
	for(auto x:a)
	{
		if(x=='A'||x=='C'||x=='G'||x=='T')
			++now;
		else mx=max(mx,now),now=0;
	}
	cout << max(mx,now);
	return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    let mut count = 0;
    let mut kuchi = 1;
    loop {
        if kuchi >= b { break; }

        kuchi += a - 1;
        count += 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


    class ClassMain    {

        public static void Main(String[] args){
            //Console.WriteLine("Hello World!");
            int L;
            while ((L=int.Parse(Console.ReadLine()))!= 0){
                int month = -1;
                for (int i = 0; i < 12; i++) {
                    String[] strs = Console.ReadLine().Split(' ');
                    int M = int.Parse(strs[0]);
                    int N = int.Parse(strs[1]);
                    L -= (M - N);
                    if (L <= 0) {
                        if (month == -1) {
                            month = i + 1;
                        }
                    }
                
                }
                if (month >= 0) { Console.WriteLine(month); }
                else { Console.WriteLine("NA"); }

            }


        }

    }

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c) cout<<"1"<<endl;
  else if(a==b||b==c||c==a) cout<<"2"<<endl;
  else cout<<"3"<<endl;
}


Measured memory_bytes: 256
N, Y = map(int,input().split())
Y //= 1000
for i in range(int(Y//10)+1):
    if N - i < 0:
        break
    for j in range(int(Y - 10 * i // 5)+1):
        if N - i - j < 0:
            break
        if Y - 10 * i - 5 * j == N - i - j:
            print(i, j, N - i - j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  int n,a;
  cin>>n;
  vector<int> b(n);
  Fr(i,n) cin>>a,b[a-1]=i;
  fr(i,n) cout<<b[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int P = 1000000007;

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n;
  scanf("%d", &n);
  vector<vector<int>> g(n + 1);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<bool> vis(n + 1);
  function<pair<int, int>(int)> dfs = [&](int u) {
    vis[u] = true;
    pair<int, int> ret(1, 1);
    for (int v : g[u])
      if (!vis[v]) {
        pair<int, int> cur = dfs(v);
        ret = make_pair(ret.first * (ll)(cur.first + cur.second) % P, ret.second * (ll)cur.first % P);
      }
    return ret;
  };
  pair<int, int> ans = dfs(1);
  printf("%d\n", (ans.first + ans.second) % P);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C,a, b, c, K;
    string ans;
    ans = "No";
    cin >> A >> B >> C >> K;
    a = A;
    for (int i =0; i<=K; i++){
        if (i > 0){
          a *= 2;
        }
        b = B;
        for(int j = 0; i+j <= K; j++){
            if (j > 0){
              b *= 2;
            }
            c = C;
            for(int k = 0; i+j+k <= K; k++){
                if (k > 0){
                  c *= 2;
                }
                if ((a<b) && (b<c)){
                    ans = "Yes";
                }
                
            }
        }
    }

    cout << ans << endl;
}


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

using namespace std;

int main() {
  int K, seven = 0, cnt = 0;
  
  cin >> K;
  
  for (int i = 0; i < K; i++) {
    cnt++;
    seven *= 10;
    seven += 7;
    seven %= K;
    
    if (seven == 0) {
      cout << cnt << endl;
      
      return 0;
    }
  }
  
  cout << "-1" << endl;
  
  return 0;
}

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

int main() {
    int N;
    int mochi = 0;
    int cntm =0;
    cin >> N;
    vector <int> a(N);
    for(int i=0;i<N;++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i=0;i<N;++i){
        if(mochi < a[i]){
            mochi = a[i];
            ++cntm; 
        }
    }
    cout << cntm <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n,m,x;
cin>>n>>m>>x;
ll sum1=0,sum2=0;
ll a;
for(int i=0;i<m;i++){
    cin>>a;
    if(a>x){
        sum2++;
    }else{
        sum1++;
    }
}
cout<<min(sum1,sum2)<<endl;
}












Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int N, M, ans = 0;
	cin >> N >> M;
	ans = min(N, M/2);
	if (!(N > M / 2)) {
		ans += (M - N * 2) / 4;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>
#include <numeric> 

#define ll long long
#define PII pair<ll,pair<ll,ll>>
#define print(arr,s,n) for (int i = s; i < n; ++i) cout<<arr[i]<<" "; cout<<endl;

using namespace std;
int gcd(int a, int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
}

int main()
{ 

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	cout.tie(0);
	long long n;
	cin>>n;
	int ans = 1;
	long long s = n;
	while(s%360!=0)
	{
		// cout<<n<<endl;
		s+=n;
		ans++;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define sp << ' ' << 
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353

int main()
{
    boost;
    ll tt = 1, n, m, k = 0, i, j;
    ll q, l = 0, r = 0, x, y, z, h, a, b, c, d;

    bool poss = true;
    string s;
    // cin >> tt;
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> n >> k;

        vi snukes(n, 0);
        for(i = 0; i < k; i++){
            cin >> d;
            for(j = 0; j < d; j++){
                cin >> a;
                snukes[a - 1] = 1;
            }
        }
        ll ans = 0;
        for(i = 0; i < n; i++){
            if(snukes[i] == 0) ans++;
        }

        cout << ans << nl;
    }   
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

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

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

 ll n;
 string s;
  cin >> n >> s;
  
 ll res=0;
  
  for(char c='0';c<='9';c++){
   for(char d='0';d<='9';d++){
    for(char e='0';e<='9';e++){
      ll p1=-1,p2=-1,p3=-1;
      rep(i,0,n) if(s[i]==c) {
        p1=i;
        break;
      }
       if(p1==-1) continue;
      rep(i,p1+1,n) if(s[i]==d) {
        p2=i;
        break;
      }
       if(p2==-1) continue;
      rep(i,p2+1,n) if(s[i]==e) {
        p3=i;
        break;
      }
      if(p3==-1) continue;
        res++;
    }
   }
  }
  
  
  cout << res << endl;
 
}


Measured memory_bytes: 384
n = int(input())
h = list(map(int,input().split()))

h.append(0)
i = 0
answer = 0
while i < n:
    if h[i] == 0:
        i += 1
    else:
        j = i
        while h[j] != 0:
            j += 1
        min_h = min(h[i:j])
        for k in range(i,j):
            h[k] -= min_h
        answer += min_h

print(answer)


Measured memory_bytes: 3060
import sys

input = sys.stdin.readline

N = int(input())

print('?', *range(1,N+1))
sys.stdout.flush()
reply = input().strip()
nrb = ['.']*(N+1)
nrb[0] = reply
if reply=='Red':
	LC, RC = 'Red', 'Blue'
elif reply=='Blue':
	LC, RC = 'Blue', 'Red'
else:
	sys.exit()

Lind, Rind = 0, N
while Rind-Lind>1:
	mind = (Lind+Rind)//2
	print('?', *range(mind+1,mind+N+1))
	sys.stdout.flush()
	reply = input().strip()
	if reply==LC:
		Lind = mind
	elif reply==RC:
		Rind = mind
	else:
		sys.exit()

rb = ['.']*(2*N)
rb[Lind], rb[Rind+N-1] = LC, RC
inlist, outlist = [], []
for i in range(2*N):
	if Lind<i<Rind+N-1:
		rb[i] = 'in'
		inlist.append(i+1)
	elif i<Lind or Rind+N-1<i:
		rb[i] = 'out'
		outlist.append(i+1)

for i in range(2*N):
	if rb[i]=='in':
		print('?', i+1, *outlist)
		sys.stdout.flush()
		reply = input().strip()
		if reply=='-1': sys.exit()
		rb[i] = reply
	elif rb[i]=='out':
		print('?', i+1, *inlist)
		sys.stdout.flush()
		reply = input().strip()
		if reply=='-1': sys.exit()
		rb[i] = reply

for i in range(2*N):
	if rb[i]=='Red':
		rb[i] = 'R'
	else:
		rb[i] = 'B'

print('! ', *rb, sep='')

Measured memory_bytes: 41028
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

    int v;
    if(n<10) v=n;
    else if(n<100) v=9;
    else if(n<1000) v=n-99+9;
    else if(n<10000) v=900+9;
    else if(n<100000) v=n-9999+900+9;
    else v=90000+900+9;

    cout<<v<<endl;

	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){

  int n,s;
  int plus,sum,ans,memo;
  bool retu[10];

  while(cin >> n >> s){
    if(n==0 && s==0)
      break;
    ans = 0;

    int sub = pow(2,n) - 1;

    for(plus=sub;plus<1024;plus++){
      sum = memo = 0;
      for(int i=9,j=512,a=plus;i>=0;i--,j/=2){
	if(a/j==1){
	  a -= j;
	  retu[i] = true;
	  memo++;
	  sum += i;
	}
	else
	  retu[i] = false;
      }
      if(memo == n)
	if(sum==s)
	  ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
 
int main(void){
  int a,b,c;
  
  do{
    scanf("%d %d %d",&a,&b,&c);
  }while((a < 1 || a > 9)||((b < 1 || b > 9) || (c < 1 || c > 9)));
  
  if((a == b && b != c)||(a == c && b != c)||(b == c && a != b))
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int h, n;cin >> h >> n;
   int sum = 0;
   for(int i = 0;i < n;i++) {
       int x;
       cin >> x;
       sum+=x;
   }
   if(sum>=h) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
    
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Get_AC
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                var nq = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var str = Console.ReadLine();

                var array = Enumerable.Repeat(0, nq[0] + 1).ToArray();
                for (int i = 0; i < nq[0] - 1; i++)
                {
                    if (str[i] == 'A' && str[i + 1] == 'C')
                    {
                        array[i + 1] = array[i] + 1;
                    }
                    else
                    {
                        array[i + 1] = array[i];
                    }
                }
                for (int i = 0; i < nq[1]; i++)
                {
                    var lr = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    Console.WriteLine(array[lr[1] - 1] - array[lr[0] - 1]);
                }
            }
        }

    }

    class SetConsole : IDisposable
    {
        public SetConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        }
        public void Dispose() { Console.Out.Flush(); }
    }
}


Measured memory_bytes: 19520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int t[110], v[110];
int l[110], r[110];

double calc(double x) {
  double res = 1e3;
  for (int i = 0; i < N + 2; i++) {
    double tmp = v[i];
    if (x < l[i]) tmp += abs(l[i] - x);
    else if (x > r[i]) tmp += abs(x - r[i]);
    res = min(res, tmp);
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    l[i] = sum;
    sum += t[i];
    r[i] = sum;
  }
  l[N] = r[N] = 0;
  l[N + 1] = r[N + 1] = sum;
  v[N] = v[N + 1] = 0;
  double ans = 0;
  for (int i = 0; i < 2 * sum; i++) {
    double tmp = i / 2.0;
    ans += (calc(tmp) + calc(tmp + 1 / 2.0)) / 4.0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(10)]
P = [c[:] for c in C]

for k in range(10):
    for i in range(10):
        for j in range(10):
            P[i][j] = min(P[i][j], P[i][k]+P[k][j])

ans = 0
for _ in range(H):
    for a in map(int, input().split()):
        if a!=-1:
            ans += P[a][1]
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include<unordered_map>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define arr2dof vector  vector<vector<int>>dp(N,vector<int>(2, inf));
using namespace std;
const int N = 3e5 + 5, inf = 1e9 + 7, inff = -1e12;
const double ep = 0.0000000001;
const double pi = 3.14159265359;

	
int main()
{
	int n;
	string s;
	map<string, int >mp;
	int d = 0,t=0;
	set<string>v;
		cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		mp[s]++;
		if (mp[s] > d)
			d = mp[s];
		v.insert(s);
	}
	
	for (auto i:v) {
		if (mp[i] == d) {
			cout << i << endl;
		}
	}

			return 0;
}

Measured memory_bytes: 34560
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
 
template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
 
/*============ Header Template ============*/

LL n, s;

LL check(LL x) {
	LL tmp = n, ans = 0;
	while (tmp) {
		ans += tmp % x;
		tmp /= x;
	}
	return ans;
}

int main() {
	read(n), read(s);
	if (n == s) {
		printf("%lld\n", n + 1);
		return 0;
	}
	LL lim, ans;
	for (LL i = 2; i * i <= n; i++) {
		if (check(i) == s) {
			printf("%lld\n", i);
			return 0;
		}
		lim = i;
	}
	// printf("lim = %lld\n", lim);
	LL p = n - s;
	if (p <= 0) {
		printf("-1\n");
		return 0;
	}
	ans = 1LL << 60;
	// printf("%d\n", check(p / 1 + 1));
	for (LL i = 1; i * i <= p; i++) {
		if (p % i == 0) {
			if (i + 1 > lim && check(i + 1) == s) ans = min(ans, i + 1);
			if (p / i + 1 > lim && check(p / i + 1) == s) ans = min(ans, p / i + 1);
		}
	}
	if (ans == (1LL << 60)) printf("-1\n");
	else printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a; cin >> a;
    int ans = 0;
    rep(i,26){
        rep(j,16){
            if(i*4+j*7==a) ans+=1;
        }
    }
    if(ans==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

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


### 木の読み込み tree

n,q = map(int, input().split())
ns = [[] for _ in range(n)]
for _ in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
vals = [0]*n
for _ in range(q):
    p,x = map(int, input().split())
    vals[p-1] += x
ans = [0]*n
done = [False]*n
s = [(0, vals[0])]
done[0] = True
while s:
    u,val = s.pop()
    ans[u] = val
    for v in ns[u]:
        if done[v]:
            continue
        done[v] = True
        s.append((v, val+vals[v]))
write(" ".join(map(str, ans)))

Measured memory_bytes: 139076
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int a,p;
	cin >> a >> p;
	cout << (3*a+p)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
r = defaultdict(int)
s = 0
r[0] += 1
for i in range(N):
    s += A[i]
    s %= M
    r[s] += 1

ans = 0
for rr in r:
    ans += (r[rr] * (r[rr] - 1)) // 2

print(ans)

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<int(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
IL void writeln(ll x,char c,ll y){write(x);pc(c);writeln(y);}
IL void writeln(ll x,char c,ll y,char d,ll z){write(x);pc(c);write(y);pc(d);writeln(z);}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define y1 ____y1
#define markh __markh
#define union _union
const int maxn = 1e5+233;
int n,a[853][maxn];
int  vis[maxn],mark[maxn],cnt[maxn];
void solve(int k){
	puts("Yes");
	printf("%d\n",k+1);
	mem(vis,0);
	Rep(i,1,n) cnt[i]=2;
	for(int i=1;i<=k+1;++i){
		printf("%d ",k);
		mem(mark,true);
		Rep(j,1,n) if(cnt[j]==0) mark[j]=false;
		int res = 0;
		for(int j=1;j<=n;++j){
			if(mark[j]){
				a[i][++a[i][0]] = j;--cnt[j];
				printf("%d ",j);
				if(vis[j]==0) vis[j]=i; else{
					for(int w=1;w<=a[vis[j]][0];++w){
						mark[a[vis[j]][w]] = false;
					}
				}
				if(++res==k) break;
			}
		}
		puts("");
	}
}//k+1个长度为k的元素 
int main(){
	n = read();
	for(int k=1;k*(k+1)<=2*n;++k){
		if(k * (k+1) == 2 * n){
			solve(k);
			return 0;
		}
	}
	puts("No");
	return 0;
}
//长度为k
//k*(k+1)=2*n
/*n = 6
1 2 3
    3 4 5
1     4   6
  2     5 6*/

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

using namespace std;

int s[5001];

int main()
{
    int n;

    while (cin >> n, n) {
        memset(s, 0, sizeof(s));

        for (int i = 1; i <= n; ++i) {
            int a; cin >> a;
            s[i] = a + s[i - 1];
        }

        int ma = -1000000;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

        cout << ma << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	rep(i, n) cin >> v[i];
	rep(i, n) cin >> c[i];
	int ans = 0;
	rep(i, n){
		if(v[i] - c[i] > 0){
			ans += v[i] - c[i];
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    int res = 0;
    string s;

    cin>>s;

    string tmp;
    //0st, 1st
    int a=0,b=0;
    string c;
    REP(i,2)
    {
        tmp = s;
        REP(j,tmp.length())
        {
            c = to_string((i+j + 2) % 2);
            if (tmp.substr(j,1) != c ) 
            {
                tmp.replace(j, 1, c);
                if (i == 0)
                {
                    //0st
                    a++;
                } 
                else
                {
                    //1st
                    b++;
                }
            }

        }
    }
    cout << min(a,b) << endl;
    return 0;
}

Measured memory_bytes: 512
def dijkstra_back(s,t,n,w,cost):
    import heapq
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    q=[]
    heapq.heapify(q)
    heapq.heappush(q,(0,s))
    while q:
        c,v=heapq.heappop(q)
        if d[v]<c:
            continue

        for i in range(len(to[v])):
            k=to[v][i]
            if d[k]>d[v]+cost[v][k]:
                d[k]=d[v]+cost[v][k]
                heapq.heappush(q,(d[k],k))
                prev[k]=v

    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

N,M=map(int,input().split())
fr={i:[] for i in range(1,N+1)}
to={i:[] for i in range(1,N+1)}
cost=[[float('inf') for i in range(0,N+1)] for i in range(0,N+1)]
for i in range(0,M):
    a,b=map(int,input().split())
    cost[a][b]=1
    fr[b].append(a)
    to[a].append(b)



ansc=10**10
ans=[]
for i in range(1,N+1):
    for j in fr[i]:
        test=dijkstra_back(i,j,N+1,M,cost)
        if len(test)==2:
            if cost[i][j]!=float('inf'):
                ansc=2
                ans=test
        elif len(test)<ansc:
            ansc=len(test)
            ans=test

if ansc!=10**10:
    print(ansc)
    for i in range(0,ansc):
        print(ans[i])
else:
    print(-1)

Measured memory_bytes: 123356
sx,sy,tx,ty=map(int,input().split())

tx-=sx
ty-=sy

ans=""

for i in range(tx):
  ans+="R"
for i in range(ty):
  ans+="U"
for i in range(tx):
  ans+="L"
for i in range(ty):
  ans+="D"

ans+="D"
for i in range(tx):
  ans+="R"
ans+="R"

ans+="U"
for i in range(ty):
  ans+="U"
ans+="L"

ans+="U"
for i in range(tx):
  ans+="L"
ans+="L"

ans+="D"
for i in range(ty):
  ans+="D"
ans+="R"

print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n,m,r=map(int,input().split())
    R=list(map(lambda x:int(x)-1,input().split()))
    # Adjacency Matrix
    A=[[INF]*n for _ in range(n)]
    for i in range(n): A[i][i]=0
    for _ in range(m):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        A[a][b]=c
        A[b][a]=c
    # Warshall-Floyd
    from itertools import product
    for k,i,j in product(range(n),repeat=3):
        A[i][j]=min(A[i][j],A[i][k]+A[k][j])
    # calculate
    from itertools import permutations
    per=permutations(R)
    ans=INF
    for R in per:
        score=0
        for i in range(r-1):
            score+=A[R[i]][R[i+1]]
        ans=min(ans,score)
    print(ans)

resolve()

Measured memory_bytes: 58844
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A[100000], B[100000], C[100000];
  cin >> A[0] >> B[0] >> C[0];
  int64_t ans = 0;
  for(int i=0;i<1000;i++){
    if(A[i] % 2 == 1 || B[i] % 2 == 1 || C[i] % 2 == 1){
      break;
    } 
    else{
      A[i+1] = B[i]/2 + C[i]/2;
      B[i+1] = C[i]/2 + A[i]/2;
      C[i+1] = A[i]/2 + B[i]/2;
      ans++;
    }
  }
  if(ans == 1000) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <stdlib.h>
#include <unordered_map>
#define ll long long
using namespace std;
int main() {
    int n,m,mi=10000;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(b<=m){
            mi=min(a,mi);
        }
    }
    if(mi==10000)
        cout<<"TLE";
    else
        cout<<mi;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b;
	cin >> a >> b;
	FOR(i,1,1001){
		if(i*8/100==a && i/10==b){
			cout << i;
			return 0;
		}
	}
	cout << "-1\n";
	return 0;
}



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

using namespace std;
int main()
{
     char a;
     char b[1000];
     int i=-1;
     while((a=getchar())!='\n')
     {
         if(a=='B')
            {if(i>=0)--i;}
        else
         {
             b[++i] = a;
         }
     }
     for(int j=0;j<=i;++j)
     cout<<b[j];
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let mut a = vec![];
    let mut b = vec![];
    let mut c = vec![];
    for _ in 0..M {
        let (x, y): (i64, usize) = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap()
            )
        };
        a.push(x);
        b.push(y);
        let z: Vec<usize> = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect()
        };
        c.push(z);
    }

    const INF: i64 = 1_000_000_000_000;
    let K = 1 << N;
    let mut dp = vec![INF; K];
    fn f(i: usize, dp: &mut Vec<i64>, a: &Vec<i64>, c: &Vec<Vec<usize>>, N: usize, M: usize, K: usize) -> i64 {
        if dp[i] < INF || dp[i] == 2 * INF { dp[i] }
        else if i == 0 {
            dp[i] = 0;
            dp[i]
        }
        else {
            let mut res = INF;
            for j in 0..M {
                let k = c[j].iter().map(|&x| 1 << (x - 1)).sum::<usize>();
                if (0..N).all(|l| ((i >> l) & 1 == 0) || ((k >> l) & 1 == 1)) {
                    res = std::cmp::min(res, a[j]);
                }
            }
            for j in 1..i {
                if (0..N).all(|l| ((i >> l) & 1 == 1) || ((j >> l) & 1 == 0)) {
                    res = std::cmp::min(res, f(j, dp, a, c, N, M, K) + f(i - j, dp, a, c, N, M, K));
                }
            }
            dp[i] = if res == INF { 2 * INF } else { res };
            res
        }
    }
    let opt = f(K - 1, &mut dp, &a, &c, N, M, K);
    let ans = if opt == INF { -1 } else { opt };

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int x3 = x2 - y2 + y1;
    int y3 = y2 + x2 - x1;
    int x4 = x3 - x2 + x1;
    int y4 = y3 + y1 - y2;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}

Measured memory_bytes: 256
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def myAnswer(A:int,B:int,C:int,D:int) -> int:
   divC = B//C - (A - 1)//C 
   divD = B//D - (A - 1)//D
   divCD = B//lcm(C,D) - (A - 1)//lcm(C,D) 
   # print(divC,divD,divCD)
   return (B - A + 1) - (divC + divD - divCD)

def modelAnswer():
   return
def main():
   A,B,C,D = map(int,input().split())
   print(myAnswer(A,B,C,D))

if __name__ == '__main__':
   main()

Measured memory_bytes: 5460
#include <cstdio>
#include <cctype>
#include <string>

class Parser {
public:
  std::string str;
  int idx;
  Parser (std::string str):str(str),idx(0)
  {
  }
  int evalas();
  int evalmd();
  int evalexpr();
  int evalnum();
};

int Parser::evalas() {
  //  printf("evalas begin: idx=%d\n",idx);

  int left = evalmd(), right;
  while(true) {
    switch(str[idx]) {
    case '+':
      idx++;
      right = evalmd();
      left = left+right;
      break;
    case '-':
      idx++;
      right = evalmd();
      left = left-right;
      break;
    default:
      goto hoge;
    }
  }
 hoge:

  //  printf("evalas end: idx=%d\n",idx);
  return left;
}

int Parser::evalmd() {
//  printf("evalmd begin: idx=%d\n",idx);  

  int left = evalexpr(),right;
  while(true) {
    switch(str[idx]) {
    case '*':
      idx++;
      right = evalexpr();
      left = left*right;
      break;
    case '/':
      idx++;
      right = evalexpr();
      left = left/right;
      break;
    default:
      goto hoge;
    }
  }
 hoge:
  //  printf("evalmd end: idx=%d\n",idx);  
  return left;
}

int Parser::evalexpr() {
  //  printf("evalexpr: idx=%d\n",idx);

  int n;
  if (str[idx] == '(') {
    idx++;
    n = evalas();
    idx++;
  } else {
    n = evalnum();
  }
//  printf("returned: %d\n",n);
  return n;
}

int Parser::evalnum() {
  //  printf("evalnum begin: idx=%d\n",idx);

  int ans=0;
  char ch;
  while (isdigit(ch=str[idx])) {
    idx++;
    ans = ans*10+(int)ch-(int)'0';
  }

  //  printf("evalnum　end: idx=%d\n",idx);
  return ans;
}

int main() {
  int time;
  scanf("%d\n",&time);

  while(time--) {
    char str[100];
    fgets(str,100,stdin);
    //    printf("expr: %s\n",str);
    printf("%d\n",Parser(std::string(str)).evalas());
  }
}

Measured memory_bytes: 1068
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 1000001
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

void solve()
{
    lli x;
    cin>>x;
    if(x>=400&&x<=599)
    {
        cout<<8;
    }
    if(x>=600&&x<=799)
    {
        cout<<7;
    }
    if(x>=800&&x<=999)
    {
        cout<<6;
    }
    if(x>=1000&&x<=1199)
    {
        cout<<5;
    }
    if(x>=1200&&x<=1399)
    {
        cout<<4;
    }
    if(x>=1400&&x<=1599)
    {
        cout<<3;
    }
    if(x>=1600&&x<=1799)
    {
        cout<<2;
    }
    if(x>=1800&&x<=1999)
    {
        cout<<1;
    }
}
int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
    
    // test
    {
        solve();
        nl
    }
}
//a+b=a?b+2?(a&b)
//__builtin_popcount(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";




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

int m, k;

int main() {
	cin >> m >> k;
	int sum = 0;
	for(int i = 0; i < (1 << m); ++i) if(i != k) sum ^= i;
	if(!k) {
		for(int i = 0; i < (1 << m); ++i) printf("%d %d ", i, i);
		puts("");
		return 0;
	}
	if(m == 1) {
		if(k >= 1) puts("-1");
		else puts("0 0 1 1");
		return 0;
	}
	if((1 << m) <= k) return puts("-1"), 0;
	printf("%d ", k);
	for(int i = 0; i < (1 << m); ++i) if(i != k) printf("%d ", i);
	printf("%d ", k);
	for(int i = (1 << m) - 1; i >= 0; --i) if(i != k) printf("%d ", i);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, i;
  a=0;
  b=0;
  cin >> N;
  vector<int> light(N);
  for(i=0;i<N;i++) {
    cin >> light.at(i);
  }
  for(i=0;i<N+1;i++) {
    if(light.at(a)==2) {
      b++;
      break;
    }
    else {
      a = light.at(a)-1;
      b++;
    }
    if(i==N) {
      b=-1;
      break;
    }
  }
    cout << b << endl;
    return 0;
  }

Measured memory_bytes: 640