akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll maxn=500500;
typedef pair<ll,ll>q;
q pos[100005];
int main()
{
    ll n,c,d;
    cin>>n;
    for(ll i=0; i<n; i++)
    {
        cin>>c>>d;
        pos[i].first=c+d;
        pos[i].second=c-d;
    }
    sort(pos,pos+n);
    ll mn=-100000000000,cnt=0;
    for(ll i=0; i<n; i++)
    {
        if(pos[i].second>=mn)
        {
            cnt++;
            mn=pos[i].first;
        }
    }
    cout<<cnt<<endl;




}
/*
2

6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45

6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
*/


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var temp = Console.ReadLine().Split(' ').ToList();
            var list = temp.Select(ln => long.Parse(ln)).ToList();

            long unit_sum = n * (n + 1) / 2;
            if (list.Sum() % unit_sum != 0) { Console.WriteLine("NO"); }
            else
            {
                int n_addition = (int)(list.Sum() / unit_sum);

                var diff = new List<int>();
                for (int i = 0; i < list.Count - 1; i++)
                {
                    diff.Add((int)(list[i + 1] - list[i]));
                }
                diff.Add((int)(list[0] - list[list.Count - 1]));

                var diff2 = diff.Select(ln => ln - n_addition);

                if (diff2.All(ln => (ln % n == 0) && (ln <= 0)) && diff2.Sum() == -n * n_addition) { Console.WriteLine("YES"); }
                else { Console.WriteLine("NO"); }
            }
        }
    }
}


Measured memory_bytes: 15704
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
#include <cstdint>

int main() {
	char x, y;
	cin >> x >> y;
	if (x < y)cout << "<" << endl;
	else if (x > y)cout << ">" << endl;
	else cout << "=" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	
	int sum = A + B + C, max = (A < B)? ((B < C)? C: B): (C < A)? A: C;
	if ((sum - max) % 2 == 0) printf("%d\n", (max * 3 - sum) / 2);
	else printf("%d\n", (max * 3 - sum + 3) / 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000, unknown = 1e9 + 100;

vector<pair<int,int>> g[MAXN];
int cur[MAXN];

bool dfs(int v) {
  bool ok = 1;
  for (auto P : g[v]) {
    int u = P.first, d = P.second;
    if (cur[u] == unknown) cur[u] = cur[v] + d, ok &= dfs(u);
    else {
      if (cur[u] != cur[v] + d) ok = 0;
    }
  }
  return ok;
}
int main() {
  int N, M, u, v, d; scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) scanf("%d%d%d", &u, &v, &d), --u, --v, g[u].push_back({v, d}), g[v].push_back({u, -d});
  fill(cur, cur + N, unknown);
  bool ok = 1;
  for (int i = 0; i < N; ++i) 
    if (cur[i] == unknown) 
      cur[i] = 0, ok &= dfs(i);
  puts(ok? "Yes": "No");
}



Measured memory_bytes: 12032
import java.util.Scanner;



public class Main {

	public static long MOD = 1_000_000_007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long a = n-k+1;//(n-k+1)Ci
		long b = 1;//(k-1)C(i-1)
		
		for (int i=1;i<=k;i++) {
			System.out.println((a*b)%MOD);
			a=div(a*(n-k+1-i)%MOD, i+1);
			b=div(b*(k-i)%MOD, i);
		}
		
		
	}
	
	static long pow (long x, long y) {
		if (y==0) {
			return 1;
		} else if (y%2==0) {
			long tmp = pow(x,y/2);
			return (tmp*tmp%MOD);
		} else {
			long tmp = pow(x,y/2);
			return (tmp*tmp%MOD)*x%MOD;
		}
	}
	static long div (long x, long y){
		return x*pow(y, MOD-2)%MOD;
	}
}






Measured memory_bytes: 22228
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&m);
  m%=26;
  scanf("%s",s);
  n = strlen(s);
  rep(i,n){
    if(s[i]+m-'A'>=26) s[i]+=m-26;
    else s[i]+=m;
  }
  printf("%s",s);
  return 0;
}



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

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

	int a;
	cin >> a;
	if (a < 30) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3620
from itertools import combinations


n, a, b, c = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))

dp_a = [-1] * (2 ** n)
dp_b = [-1] * (2 ** n)
dp_c = [-1] * (2 ** n)

for i in range(1, n-1):
    for j in combinations(range(n), i):
        indices = [1 << k for k in j]
        index = sum(indices)
        if i == 1:
            dp_a[index] = abs(l[j[0]] - a)
            dp_b[index] = abs(l[j[0]] - b)
            dp_c[index] = abs(l[j[0]] - c)
        else:
            dp_a[index] = min([dp_a[index - indices[k]] for k in range(i)])
            dp_a[index] = min(dp_a[index], abs(sum([l[k] for k in j]) - a) + 10 * (i-1))

            dp_b[index] = min([dp_b[index - indices[k]] for k in range(i)])
            dp_b[index] = min(dp_b[index], abs(sum([l[k] for k in j]) - b) + 10 * (i - 1))

            dp_c[index] = min([dp_c[index - indices[k]] for k in range(i)])
            dp_c[index] = min(dp_c[index], abs(sum([l[k] for k in j]) - c) + 10 * (i - 1))

ans = 10 ** 10
for i in range(1, 2 ** n):
    for j in range(1, 2 ** n):
        if i | j != i + j:
            continue
        for k in range(1, 2 ** n):
            if i + j + k == 2 ** n - 1 and i | j | k == 2 ** n - 1:
                ans = min(ans, dp_a[i] + dp_b[j] + dp_c[k])

print(ans)

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

const int MAXN=1e5+10;
const int inf=1e9+2137;

int dp[MAXN];
int h[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=2;i<=n;i++)
        dp[i]=inf;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=k;j++)
            if(i+j<=n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    cout<<dp[n];
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
    input! {
        n: usize, p: usize,
        s: Chars
    };

    let s = s
        .into_iter()
        .map(|ch| ch.to_digit(10).unwrap() as usize)
        .collect::<Vec<_>>();

    if p == 2 || p == 5 {
        let mut res = 0_usize;
        for i in 0..n {
            if s[i] % p == 0 {
                res += i + 1;
            }
        }
        println!("{}", res);
        return;
    }

    let mut cusum = Vec::new();
    cusum.push(0);
    let mut ten_factor = 1_usize;
    for i in (0..n).rev() {
        let x = s[i];
        let sum = (cusum.last().unwrap() + (ten_factor * x) % p) % p;
        cusum.push(sum);
        ten_factor = (ten_factor * 10) % p;
    }
    let mut map = HashMap::new();
    for s in cusum {
        *map.entry(s).or_insert(0_usize) += 1;
    }
    let mut res = 0_usize;
    for (_, c) in map {
        if c < 2 {
            continue;
        }
        res += c * (c - 1) / 2;
    }
    println!("{}", res);
}


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

int main(){
  int n,m,y=0;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for(int i=0;i<m;i++)
    cin >> s.at(i) >> c.at(i);
  
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      if(s.at(i)==s.at(j)&&c.at(i)!=c.at(j))
        y++;
    }
  }
  
  if(n!=1){
    for(int i=0;i<m;i++){
      if(s.at(i)==1&&c.at(i)==0)
        y++;
    }
  }
  
  if(y!=0){
    cout << -1 << endl;
  }
  
  else{
  int k=0;
  
  for(int i=n;i>0;i--){
    k*=10;
    int x;
    if(k==0&&n!=1)
      x=1;
    else
      x=0;
    
    for(int j=0;j<m;j++){
      if(s.at(j)==n+1-i){
        x=c.at(j);
      }
    }
    k+=x;
  }
  cout << k << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 a, b, c;
  cin >> a >> b >> c;
  set<i64> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  if(st.size() == 2){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
int N;
int a[100];
int b[100];
typedef bitset<64> B;
bool check(B mask) {
	bool ret = true;
	for (int i : range(N)) {
		B bit(0);
		bit[a[i]] = true;
		queue<int> que;
		que.push(a[i]);
		while (que.size()) {
			int v = que.front(); que.pop();
			for (int j : range(1, 51))if(mask[j]) {
				int u = v % j;
				if (bit[u] == false) {
					bit[u] = true;
					que.push(u);
				}
			}
		}
		ret &= bit[b[i]];
	}
	return ret;
}

int main() {
	cin >> N;
	for (int i : range(N))cin >> a[i];
	for (int i : range(N))cin >> b[i];
	B mask((1ll << 51) - 2);
	for (int i = 50; i > 0; i--) {
		mask[i] = false;
		if (check(mask) == false)mask[i] = true;
	}
	if (check(mask))cout << mask.to_ullong() << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" <<"\n";
    }else{
        cout << "ABC" <<"\n";
    }
	return 0;
}

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

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout<<(#x)<<" >> "<<(x)<<endl

using namespace std;

ll fastpow(ll angka,ll pangkat,ll MOD){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka)%MOD;
		angka=(angka*angka)%MOD;
		pangkat=pangkat>>1;
	}
	return res;
}

ll fastpow(ll angka,ll pangkat){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka);
		angka=(angka*angka);
		pangkat=pangkat>>1;
	}
	return res;
}

ll gcd(ll angka1,ll angka2){
	while(angka2){
		swap(angka1,angka2);
		angka2=angka2%angka1;
	}
	return angka1;
}

ll lcm(ll angka1,ll angka2){
	return (angka1/gcd(angka1,angka2))*angka2;
}

const ll mod=1000000007;

unordered_map<int,int>parent;
int getParent(int x){
	if(parent[x]==-1) return parent[x]=x;
	if(parent[x]==x) return x;
	return parent[x]=getParent(parent[x]);
}


void solve(){
	
	int n,m;
	cin>>n>>m;
	
	for(int i=1;i<=n;i++) parent[i]=i;
	
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		if(getParent(a)!=getParent(b)){
			parent[getParent(a)]=getParent(b);
		}
	}
	int maxVal=0;
	unordered_map<int,int>um;
	for(int i=1;i<=n;i++){
		um[getParent(i)]++;
		maxVal=max(maxVal,um[getParent(i)]);
	}
	cout<<maxVal<<endl;
}

int main(){
	
	fastio();

	int t=1;
//	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 20932
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val X = sc.nextInt()
  val count = X / 100 % 100
  val mod = X % 100
  val matched = for {
    a <- 0 to count if a * 5 <= mod
    b <- 0 to count - a if a * 5 + b * 4 <= mod
    c <- 0 to count - (a + b) if a * 5 + b * 4 + c * 3 <= mod
    d <- 0 to count - (a + b + c) if a * 5 + b * 4 + c * 3 + d * 2 <= mod
    e <- 0 to count - (a + b + c + d) if a * 5 + b * 4 + c * 3 + d * 2 + e * 1 <= mod
    f <- 0 to count - (a + b + c + d + e) if (a * 5 + b * 4 + c * 3 + d * 2 + e * 1 + f * 0) == mod
  } yield ()
  println(if (matched.isEmpty) 0 else 1)
}


Measured memory_bytes: 62328
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            checked
            {
                var n = cin.ReadInt;
                var a = cin.ReadIntArray(n);
                var cnt = 0;
                for (int i = 0; i < n; ++i)
                {
                    while (a[i] % 2 == 0)
                    {
                        a[i] /= 2;
                        cnt++;
                    }
                }
                WriteLine(cnt);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadIntArrays(long N, out int[] A, out int[] B, out int[] C) { A = new int[N]; B = new int[N]; C = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; C[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/
int h, w, n;

bool check(int x, int y)
{
	return 1 <= x and x <= w and 1 <= y and y <= h;
}

signed main()
{
	cin >> h >> w >> n;

	int sx, sy;
	cin >> sy >> sx;

	string s, t;
	cin >> s >> t;
	
	int x1 = sx, y1 = sy;
	int x2 = sx, y2 = sy;

	rep(i, 0, n){
		x1 += s[i] == 'R';
		if(!check(x1, sy)){
			cout << "NO" << endl;
			return 0;
		}
		x1 = max(1LL, x1-(t[i]=='L'));

		x2 -= s[i] == 'L';
		if(!check(x2, sy)){
			cout << "NO" << endl;
			return 0;
		}
		x2 = min(w, x2+(t[i]=='R'));

		y1 += s[i] == 'D';
		if(!check(sx, y1)){
			cout << "NO" << endl;
			return 0;
		}
		y1 = max(1LL, y1-(t[i]=='U'));

		y2 -= s[i] == 'U';
		if(!check(sx, y2)){
			cout << "NO" << endl;
			return 0;
		}
		y2 = min(h, y2+(t[i]=='D'));
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
bitset< 4000001> dp;
int main()
{
    int arr[2000];
    int n;
    cin>>n;
    int i;
    for(i=0;i<n;i++)
        cin>>arr[i];
    
    if(n==1){cout<<arr[0];return 0;}
    
    int pre=arr[0];
    
    for(i=1;i<n;i++)pre=pre+arr[i];
    pre++;
    dp[0]=1;
    int sum=pre/2;
    int ans=1e9;
    
    for(i=0;i<n;i++)
    {  
        
            dp  |= (dp<<arr[i]);
            
    }
     for(i=sum;;i++)if(dp[i]){
    cout<<i;return 0;}
}


Measured memory_bytes: 1664
// #define LOCAL
// #define CPP_IO

#pragma region

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;

#define f first
#define s second

#ifdef LOCAL
#define debug cout
#else
#define debug \
    if (0) cout
#endif

#define DUMP(a) debug << #a " = " << (a) << "\n";
#define DUMP2(a, b) debug << #a " = " << (a) << " " #b " = " << (b) << "\n";
#define DUMP3(a, b, c) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << "\n";
#define DUMP4(a, b, c, d) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << " " #d " = " << (d) << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
#ifdef CPP_IO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
#endif
    solve();
}

#pragma endregion

const ll MOD = 1e9 + 7;

int n, occ[26];
ll dp[26];
void solve() {
    scanf("%d", &n);
    getchar();
    for (int i = 0; i < n; ++i) {
        char c = getchar();
        ++occ[c - 'a'];
    }
    dp[0] = occ[0];
    for (int i = 1; i < 26; ++i) {
        dp[i] = dp[i - 1] + occ[i] + 1LL * occ[i] * (dp[i - 1]) % MOD;
        dp[i] %= MOD;
    }
    printf("%lld\n", dp[25]);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
# include <bits/stdc++.h>
using namespace std;
int main() {
    long long N;
    string S;
    cin >>N;
    cin >>S;
    long long sum[300001];
    sum[0]=0;
    for (int i = 0; i < N; i++) {
        if(S[i]=='W'){
            sum[i+1]=sum[i]-1;
        }else{
            sum[i+1]=sum[i]+1;
        }
    }
    long long res=0;
    long long tmp;
    long long index=0;
    for (int i = 0; i < N; i++) {
        tmp=sum[i]-(sum[N]-sum[i+1]);
        if(tmp>res){
            res = tmp;
            index=i;
        }
    }
    // std::cout << index << std::endl;
    res =0;
    for (int i = 0; i < N; i++) {
        if(S[i]=='W'){
            if(i<index){
                res++;
            }
        }else{
            if(i>index){
                res++;
            }
        }
    }
    std::cout << res << std::endl;
    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  map<int, int> R;
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    R[a]++, R[b]++;
  }
  for(int i=0;i<N;i++) cout << R[i+1] << endl; 
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;


	while (cin >> n && n != 0) {
		int min_ = 1000000000; // 答えの最小値
		int min_num = 1; // 答えの町
		int cost[100][100];
		int max_ = 0; // 町がどれだけあるか
		int from, to, time;

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				cost[i][j] = 100000000;
			}
		}
		for (int i = 0; i < 100; i++) {
			cost[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			cin >> from >> to >> time;
			cost[from][to] = time;
			cost[to][from] = time;
			max_ = max(max(from, to), max_);
		}
		for (int k = 0; k <= max_; k++) {
			for (int i = 0; i <= max_; i++) {
				for (int j = 0; j <= max_; j++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		// 答えを求める
		for (int i = 0; i <= max_; i++) {
			int total = 0;
			for (int j = 0; j <= max_; j++) {
				total += cost[i][j];
			}
			if (total < min_) {
				min_ = total;
				min_num = i;
			}
		}
		cout << min_num << " " << min_ << endl;
  }
	return 0;
}

Measured memory_bytes: 1200
S = input()
L = len(S)
now = S[0]
ok = True
ans = 10**18
for i in range(1, L):
    if S[i] != now:
        now = S[i]
        ans = min(ans, max(i, L-i))
        ok = False
if ok:
    print(L)
else:
    print(ans)


Measured memory_bytes: 9120
#include <stdio.h>
int a, b, c, d;
int main(void){
  int s, t;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  s = a + b;
  t = c + d;
  printf(s > t ? "Left\n" : s < t ? "Right\n" : "Balanced\n");
  return 0;
}

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

int main(void){
	int n,i,j,k;
	vector<int> N;

	cin >> n;
	for(i=0;i<n;i++){
		cin >> k;
		N.push_back(k);
	}
	for(j=0;j<n;j++){
		if(j==n-1) cout << N.at(j) << endl;
		else cout << N.at(j) << " ";
	}
	for(i=1;i<n;i++){
		for(j=0;j<i;j++){
			if(N.at(i)<N.at(j)){
				N.insert(N.begin()+j,N.at(i));
				N.erase(N.begin()+i+1);
				break;
			}
		}
		for(j=0;j<n;j++){
			if(j==n-1) cout << N.at(j) << endl;
			else cout << N.at(j) << " ";
		}
	}
	return 0;
}

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

ll N;
vector<string> P, Q;

int main() { 
    cin >> N;
    P.resize(N);
    Q.resize(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    string X[N];
    for (int i = 1; i <= N; i++) X[i - 1] = to_string(i);
    ll a = 0, b = 0, out = 0, cnt=0;
    string s, p, q;
    do {
      s ="";
      p ="";
      q = "";
      cnt++;
      for (int i = 0; i < N; i++) {
        s += X[i];
        p += P[i];
        q += Q[i];
      }
      if(s==p) a = cnt;
      if (s == q) b = cnt;
    } while (next_permutation(X, X + N));
    
    out = abs(a - b);
    cout << out << endl;
    return 0;
}

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

int main() {
  int D,N;
  cin >> D >> N;
  if (N == 100)
    N++;
  if (D == 1)
    N *= 100;
  else if (D == 2)
    N *= 10000;
  cout << N << endl;
}

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

int main() {
    int N;
    int flag = -1;
    cin >> N;
    if (N < 4) {
        cout << "No" <<endl;
        flag = 0;
    }
    for (int i = 0; i <= 26; ++i) {
        for (int j = 0; j <= 15; ++j) {
                int total = 4 * i + j * 7; // 合計金額
            if (total == N) {
                cout << "Yes" << endl;
                flag = 1;
                break;
            }
        }
        if(flag == 1) break;
    }
    if(flag == -1) cout << "No" << endl;
}



Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<algorithm>
using namespace std;
int Query(int ans)
{
	char ret[20];
	printf("%d\n", ans);
	fflush(stdout);
	scanf("%s", ret);
	if(ret[0] == 'V') return 2;
	return ret[0] == 'M' ? 1 : 0;
}
int n;
int main()
{
	scanf("%d",&n);
	int res0=Query(0);
	if(res0==2) return 0;
	int l=0,r=n-1;
	while(true)
	{
		int mid=(l+r)>>1;
		int res_mid=Query(mid);
		if(res_mid==2) return 0;
        if(res_mid!=res0)
		{
			if(mid%2) l=mid+1;
			else r=mid;
		}
		else
		{
			if(mid%2) r=mid;
			else l=mid+1;
		}
	}
	Query(r);
	return 0;
}


Measured memory_bytes: 760
#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);
    }
    vector<int> vec(N);
    vec[0]=0;
    vec[1]=A[0]-1;
    for(int i=2;i<N;i++){
        vec[i]=A[vec[i-1]]-1;
    }
    int count=0;
    int press=0;
    for(int i=0;i<N;i++){
        if(vec[i]==1){
            count+=1;
            press=i;
            break;
        }
    }
    if(count==0){
        cout << -1 <<endl;
    }
    else{
        cout << press <<endl;
    }
    
}

Measured memory_bytes: 1024
# 出力：E869120 の持っている 1 円硬貨と 500 円硬貨だけで, ちょうど N 円を支払うことができるならば Yes, そうでないならば No を出力しなさい.

# 支払金額
n = gets.to_i
# 500円は無限
# 持っている1円の枚数
a = gets.to_i

if n % 500 <= a
    puts("Yes")
else
    puts("No")
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

    int l = 0; 
    int r = INF;
    for (int i = 0; i < m; i++) {
        int x,y; cin >>x>>y;
        l = max(l, x);
        r = min(r, y);
    }

    if (l <= r) {
        cout << r-l+1 << endl;
    } else {
        cout << 0 << endl;
    }
    
    
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,a,ans=-1;
    cin>>n>>a;
    int m=n+1;
    map<int,int>ma;
    for(int i=0;i<a;i++){
        int x;
        cin>>x;
        ma[x]++;
    }
    for(int i=0;i<=101;i++){
        if(ma.find(i)==ma.end()){
            if(abs(i-n)<m){
                m=abs(i-n);
                ans=i;
            }
        }
    }
    cout<<ans;
}

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

int power(int n, int k){
	int res = n;
	k--;
	while(k){
		k--;
		res *= n;
	}
	return res;
}

int main() {
	
	int n, m;
	cin >> n >> m;
	int ans = 0;
	ans += 100 * (n - m);
	ans += 1900 * m;
	ans *= power(2, m);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class B{
  static void Main(){
    char[] S = Console.ReadLine().ToCharArray();
    char[] T = Console.ReadLine().ToCharArray();
    int count = 0;
    for (int i = 0; i < S.Length; i++){
      if (S[i] != T[i]) count++;
    }
    Console.WriteLine(count);
  }
}

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

int n,m;
vector<int> adj[100005];
stack<int> s;
bool visited[100005];

void dfs(int v){
	visited[v]=true;
	for(auto it:adj[v]){
		if(!visited[it]){
		dfs(it);
	    }
	}
	s.push(v);
}

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
	  int x,y;
	  cin>>x>>y;
	  x--;
	  y--;
	  adj[x].push_back(y);
	}
	
	memset(visited,false,sizeof(visited));
	for(int i=0;i<n;i++){
		if(!visited[i])
		dfs(i);
	}
	
	int dist[n]={0};
	
	while(!s.empty()){
		int u=s.top();
		s.pop();
		for(auto it:adj[u]){
			if(dist[it]<dist[u]+1)
			dist[it]=dist[u]+1;
		}
	}
	cout<<*max_element(dist,dist+n)<<endl;
	
}

Measured memory_bytes: 8320
n = int(input())
l = list(map(int, input().split()))
now = l[0]

oddSum = 0
oddOp = 0
for i in range(n):
  oddSum += l[i]
  if not i % 2 == 0 and oddSum <= 0:
    oddOp += abs(oddSum) + 1
    oddSum = 1
  elif i % 2 == 0 and oddSum >= 0:
    oddOp += abs(oddSum) + 1
    oddSum = -1

evenSum = 0
evenOp = 0
for i in range(n):
  evenSum += l[i]
  if i % 2 == 0 and evenSum <= 0:
    evenOp += abs(evenSum) + 1
    evenSum = 1
  elif not i % 2 == 0 and evenSum >= 0:
    evenOp += abs(evenSum) + 1
    evenSum = -1

print(min(oddOp, evenOp))

Measured memory_bytes: 14648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,n,w[1005],v[1005],dp[10005]={0};
	cin>>m>>n;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(int i=1;i<=10000;i++)dp[i]=1e9; 
	//cout<<dp[6]<<endl;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=w[i];j<=10000;j++){
		//	if(dp[j-w[i]]!=1e9)
			dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	int ans=1e9;
	for(int j=m;j<=10000;j++)
		ans=min(ans,dp[j]);
	cout<<ans<<endl;
	return 0;
} 

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


int main(){
  int N,M;
  cin >> N >> M;
  int sum = 0;
  rep(i,M){
    int A;
    cin >> A;
    sum += A;
  }
  
  if(N-sum>=0){
    cout << N-sum << endl;
  }
  else{
    cout << -1 << endl;
  }
    
  
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef double Weight;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Matrix mat(15, Array(15));
vector<vector<Weight> > best(1<<15,vector<Weight>(15, INF));
vector<vector<int> >    prev(1<<15,vector<int>(15));

int main() {
  int n;
  cin >> n;
  
  int a[n], l[n], m[n];
  REP(i,n)
    cin >> a[i] >> l[i] >> m[i];

  REP(i,n)
    REP(j,n)
    mat[i][j] = abs(l[j]-l[i]);

  int N = 1<<n;

  REP(i,n) best[1<<i][i] = 0;
  REP(S,N) {
    int we = 0;
    REP(i,n) // ツ個サツ催敖づ個重ツつウツづーツ計ツ算
      if (S&(1<<i))
        we += m[i];
    we = 70 + 20 * we;
    REP(i,n)
      if (S&(1<<i))
        REP(j,n) {
          if (best[S|(1<<j)][j] > best[S][i] + mat[i][j] / 2000.0 * we) {
            best[S|(1<<j)][j] = best[S][i] + mat[i][j] / 2000.0 * we;
            prev[S|(1<<j)][j] = i;
          }
        }
  }

  vector<int> path;
  int t = min_element(ALL(best[N-1])) - best[N-1].begin(); // ツ可スツ氾板姪堋づ個陳クツ点ツづ終ツづュツづゥツづ個つェツ暗ェツ氾板短ツつュツづ按づゥツつゥ

  int S = N-1;
  int count = 0;
  while(S) {
    path.push_back(t);
    int tmp = prev[S][t];
    S ^= (1<<t);
    t = tmp;
    count++;
  }
  reverse(ALL(path));

  REP(i, path.size()) {
    if (i)
      cout << " ";
    cout << a[path[i]];
  }
  cout << endl;
}

Measured memory_bytes: 7792
import java.util.*;

class Main {
  public static final int mod = 1000000007;
  public static final int fmax = 1000007;
  public static long fac[] = new long[fmax];
  public static long inv[] = new long[fmax];
  public static long finv[] = new long[fmax];
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int y = Integer.parseInt(sc.next());
    
    int u = 0;
    int v = 0;
    int ai = 0;
    int aj = 0;
    boolean flg = false;
    int k = 0;
    
    NCRinit();
    
    if((x+y)%3 == 0){
      k = (x+y)/3;
    } else {
      System.out.println("0");
      return;
    }
    
    for(int i=0; i<x; i++){
      u = 2*i;
      v = i;
      if(u==x-(k-i) && v==y-2*(k-i)){
        flg = true;
        ai = i;
        aj = k-i;
      }
      if(flg) break;
    }
    
    if(ai < 0 || aj < 0 || !flg){
      System.out.println("0");
      return;
    }
    
    long ans = ncr(ai+aj, ai);
    
    System.out.println(ans);
    
  }
  
  // テーブルを作る前処理
  public static void NCRinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < fmax; i++){
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod%i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  // 二項係数計算
  public static long ncr(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
  
}


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

int main() {
  int n,m;cin>>n>>m;
  vector<int> h(n);
  vector<bool>vec(n,true);
  rep(i,n)cin>>h[i];
  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    if(h[a]<=h[b])vec[a]=false;
    if(h[b]<=h[a])vec[b]=false;
  }
  int cnt=0;
  rep(i,n){
    if(vec[i])cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3700
#include <iostream>

using namespace std;
using ll = long long;

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

  ll s{0};
  for (auto i = 1; i<=n; ++i) {
    if(i%3 && i%5) s+= i;
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3592
import re
a, b = map(int, re.split('(..)', input())[1::2])

if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int mod = 1e9 + 7;
const int maxN = 2e6 + 7;

inline int pls(int x, int y) { return (x + y) % mod; }
inline int mns(int x, int y) { return pls(x, mod - y); }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline void Add(int &x, int y) { x = pls(x, y); }
inline void Mul(int &x, int y) { x = mul(x, y); }
inline void Minus(int &x, int y) { x = mns(x, y); }

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline int sgn(int x) { return (x & 1) ? -1 : 1; }

int fac[maxN], ifac[maxN], iv[maxN];

struct rec {
	int x[2], y[2];
}A, B, C;

inline int binom(int x, int y) { return (y <= x) ? mul(fac[x], mul(ifac[y], ifac[x-y])) : 0; }

inline int ways(int x, int y, int u, int v) {
	return binom(u-x+v-y, u-x);
}

void init() {
	iv[1] = 1; For (i, 2, maxN) iv[i] = mul(iv[mod % i], mod - mod / i);
	fac[0] = 1; For (i, 1, maxN) fac[i] = mul(fac[i-1], i);
	ifac[0] = 1; For (i, 1, maxN) ifac[i] = mul(ifac[i-1], iv[i]);
}

void solve2() {
	int ans = 0;
	rep (ax, 0, 1) rep (ay, 0, 1) rep (cx, 0, 1) rep (cy, 0, 1) {
		int f  = sgn(ax ^ ay) * sgn(cx ^ cy), res = 0;

		rep (i, B.x[0], B.x[1]) Add(res, mul(mul(ways(A.x[ax], A.y[ay], i, B.y[1]), ways(i, B.y[1]+1, C.x[cx], C.y[cy])), B.y[1]+i+1));
		rep (i, B.x[0], B.x[1]) Minus(res, mul(mul(ways(A.x[ax], A.y[ay], i, B.y[0]-1), ways(i, B.y[0], C.x[cx], C.y[cy])), B.y[0]+i));
		rep (i, B.y[0], B.y[1]) Add(res, mul(mul(ways(A.x[ax], A.y[ay], B.x[1], i), ways(B.x[1]+1, i, C.x[cx], C.y[cy])), B.x[1]+i+1));
		rep (i, B.y[0], B.y[1]) Minus(res, mul(mul(ways(A.x[ax], A.y[ay], B.x[0]-1, i), ways(B.x[0], i, C.x[cx], C.y[cy])), B.x[0]+i));
		
		f == 1 ? Add(ans, res) : Minus(ans, res);
	}

	printf("%d\n", ans);
}

int main() {

	init();

	A.x[0] = ri(), A.x[1] = ri(), B.x[0] = ri(), B.x[1] = ri(), C.x[0] = ri(), C.x[1] = ri();
	A.y[0] = ri(), A.y[1] = ri(), B.y[0] = ri(), B.y[1] = ri(), C.y[0] = ri(), C.y[1] = ri();

	-- A.x[0], -- A.y[0];
	++ C.x[1], ++ C.y[1];

	solve2();
	return 0;
}

Measured memory_bytes: 23552
# S.find()の部分を高速化する
from collections import defaultdict
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()
    T = readline().strip()

    S_idx = defaultdict(list)
    for i, s in enumerate(S):
        S_idx[s].append(i)
    
    rep = 0
    last_idx = -1
    for t in T:
        t_idx_list = S_idx[t]
        if t_idx_list:
            t_idx = bisect_right(t_idx_list, last_idx)
            if t_idx < len(t_idx_list):
                last_idx = t_idx_list[t_idx]
            else:
                last_idx = t_idx_list[0]
                rep += 1
        else:
            print(-1)
            exit()
    
    ans = len(S) * rep + last_idx + 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7924
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, arr[maxn][3], dp[maxn][3];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < 3; j++)
            cin >> arr[i][j];
    for(int j = 0; j < 3; j++)
        dp[1][j] = arr[1][j];
    for(int i = 2; i <= n; i++)
        for(int now = 0; now < 3; now++)
            for(int pr = 0; pr < 3; pr++)
                if(pr != now) dp[i][now] = max(dp[i][now], dp[i - 1][pr] + arr[i][now]);
    cout << *max_element(dp[n], dp[n] + 3) << "\n";
    return 0;
}


Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

const int MX=200005;
char s[MX];
int p[2][MX];

int f(int n)
{
    int cnt=0;
    while(n){
        n%=__builtin_popcount(n);
        cnt++;
    }
    return cnt;
}

int main()
{
    int n,x1=0,x2=0,y=0;
    scanf("%d %s",&n,s);
    for(int i=0;i<n;i++) y+=s[i]-'0';
    p[0][0]=p[1][0]=1;
    for(int i=1;i<=200000;i++){
        p[0][i]=p[0][i-1]<<1;
        p[1][i]=p[1][i-1]<<1;
        p[0][i]%=y+1;
        if(y==1) p[1][i]=0;
        else p[1][i]%=y-1;
    }
    for(int i=0,j=n-1;i<n;i++,j--){
        if(s[j]-'0'){
            x1+=p[0][i];
            x2+=p[1][i];
            if(x1>=y+1) x1-=y+1;
            if(x2>=y-1) x2-=y-1;
        }
    }
    for(int i=0,j=n-1;i<n;i++,j--){
        if(s[i]-'0'){
            int z=(x2<p[1][j])?(x2-p[1][j]+y-1):(x2-p[1][j]);
            if(y==1) printf("0\n");
            else printf("%d\n",f(z)+1);
        }
        else{
            int z=(x1+p[0][j]>=y+1)?(x1+p[0][j]-y-1):(x1+p[0][j]);
            printf("%d\n",f(z)+1);
        }
    }
    return 0;
}

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

        using namespace std;
        #define sd(x) scanf("%d",&x);
        #define sdl(x) scanf("%lld",&x);
        #define pr(x) printf("%d\n",x);
        #define prl(x) printf("%lld\n",x);
    
    long long int mod=1000000007;

    long long int gcd(long long int a,long long int b)
    {
        if (b<a)return gcd(b,a);
        else if (b%a==0)return a;
        else return gcd(b%a,a);

    }

    long long fast_exp(long long a,long long n,long long mod1)
    {

    if (n==0)return 1;
    else if (n==1)return a;
    if (n%2==0)return fast_exp((a*a)%mod1,n/2,mod1);
    else return (a*fast_exp((a*a)%mod1,n/2,mod1))%mod1;
    }
    bool is_square(long long  a)
    {
    long long int b=sqrt(a);
    if (b*b==a)return true;
    else return false;
    }
    long long n_fact[1000001];
    void calc_fact(int n) // calculates the factorial % mod and stores in n_fact upto n 
    {
        n_fact[0]=1;
        for (int c(1);c<=n;c++)
            n_fact[c]=(c*n_fact[c-1])%mod;
        return ;
    }
    long long calc_inverse_mod(long long x,long long mod)
    {
        return fast_exp(x,mod-2,mod);

    }
    bool n_primes[100001]={false};
    void calc_primes(int n)
    {
        for (int c(2);c<=100000;c++)
        {
            if (n_primes[c]==true)continue;
            for (int c1(c+c);c1<=100000;c1=c1+c)
                n_primes[c1]=true;
        }
        return ;
    }
bool is_palindrome(string a)
{
    string b=a;
    reverse(b.begin(),b.end());
    if (b==a)
        return true;
    else return false;
}
    int main ()
    {
    
        ios_base::sync_with_stdio(false);
        int t;
        //cin >> t;
        t=1;
        for (int tt=0;tt<t;tt++)
        {
            int n;
            cin >> n;
            vector<int>arr;
            unordered_map<int,int> arr_1;

            for (int c=0;c<n;c++)
            {
                int a;
                cin >> a;
                arr.push_back(a);
                arr_1[a]++;
            }

            unordered_map<int,int> arr2;

            long long total=0;
            for (int c=0;c<n;c++)
            {
                if (arr2[arr[c]]==1)
                    continue;
                long long a=arr_1[arr[c]];
                total+=(a*(a-1))/2;
                arr2[arr[c]]=1;
            }
            
            for (int c=0;c<n;c++)
            {
                long long a,b;
                a=arr_1[arr[c]];
                if (a==0||a==1)
                    b=0;
                else b=((a-1)*(a-2))/2;
                a=(a*(a-1))/2;
            
                cout << total-a+b << endl;
            }



            
        }
        


        
            
        
    return 0;




        
    }


Measured memory_bytes: 15292
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,a,b;
    cin>>n>>a>>b;
    long long ans=a*(n/(a+b));//有多少行
    if(n%(a+b)>=a)ans+=a;
    else ans+=n%(a+b);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N,M = [int(x) for x in input().split()]
cnt =[0]*(M+1)
for i in range(N):
  A = [int(x) for x in input().split()]
  K = A[0]
  for j in range(1,K+1):
    cnt[A[j]] += 1
ans = 0
for i in range(M+1):
  if cnt[i]==N:
    ans+=1
print(ans)

Measured memory_bytes: 3064
import sys
from scipy.special import comb


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')
MOD = 10**9 + 7

n = I()
ans = pow(10, n) % MOD
ans = (ans - pow(9, n)) % MOD
ans = (ans - pow(9, n)) % MOD
ans = (ans + pow(8, n)) % MOD
print(ans)


Measured memory_bytes: 43440
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	public void run()
	{
		Scanner file = new Scanner(System.in);
		int L = file.nextInt();
		int[] ints = new int[L+2];//sentinal first and last
		int[][] pred = new int[][]{{0},{0,1},{0,1,2},{2,3},{0,1,2,3,4}};
		for(int i = 0;i<L;i++)
			ints[i+1] = file.nextInt();
		long[][] dp = new long[L+2][5];
		for(long[] in:dp)
			Arrays.fill(in, Long.MAX_VALUE/2);
		dp[0][0] = 0;
		for(int i = 1;i<dp.length;i++)
		{
			for(int j = 0;j<dp[0].length;j++)
			{
				long minPred = Long.MAX_VALUE/2;
				for(int k:pred[j])
					minPred = Math.min(minPred,dp[i-1][k]);
				if(j==0 || j == 4)
				{
					dp[i][j] = Math.min(dp[i][j], minPred + ints[i]);
				}else if(j == 1 || j == 3)
				{//even start or even end
					if(ints[i] == 0)
						dp[i][j] = Math.min(dp[i][j], minPred + 2);
					else
						dp[i][j] = Math.min(dp[i][j], minPred + ints[i] % 2);
				}else if(j == 2)
				{//odd
					if(ints[i]%2==0)
						dp[i][j] = Math.min(dp[i][j], minPred + 1);
					else
						dp[i][j] = Math.min(dp[i][j], minPred);
				}
			}
		}
		//for(long[] in:dp)
			//System.out.println(Arrays.toString(in));
		System.out.println(dp[dp.length-1][4]);
	}
	
}


Measured memory_bytes: 96772
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll n,m,i;
  cin>>n>>m;
  ll arr[m];
  for(i=0; i<m; i++)
    cin>>arr[i];
    if(n>=m)
    {
      cout<<0;
      return 0;
    }
  ll val=n-1;
  sort(arr, arr+m);
  ll prefix[m-1];
  for(i=1; i<m; i++)
  {
    prefix[i-1]=arr[i]-arr[i-1];
  }
  // for(i=0; i<m-1; i++)
  //   cout<<prefix[i]<<" ";
  //   cout<<'\n';
  sort(prefix,prefix+(m-1));
  ll var=m-1-val;
  ll sum=0;
  for(i=0; i<var; i++)
    sum+=prefix[i];
  cout<<sum;

  return 0;
}

Measured memory_bytes: 5120