akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
char s[200003];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1),ans=len,pos=0;
	for(int i=1;i<=len;i++){
		if(s[i]=='S'){
			pos++;
		}else if(s[i]=='T'){
			if(pos){
				pos--;
				ans-=2;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())
p = [int(i) for i in input().split()]
q = [0] * N
for i in range(N):
    q[i] = i + 1
count = 0
for i in range(N):
    if(p[i] != q[i]):
        count += 1
if(count == 0 or count == 2):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int A;
  int B;
  int C;
  int N;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  if(B+C<=A){
    printf("0");
  }
  if(B+C>A){
    N=C-(A-B);
    printf("%d",N);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

void mybuild_tree(vector<long long int>& mytree, const vector<long long int>& data, int index, int l, int r) {
    if (l == r) {
        mytree[index] = data[l];
    } else {
        int m = (l + r) / 2;
        mybuild_tree(mytree, data, index * 2 + 1, l, m);
        mybuild_tree(mytree, data, index * 2 + 2, m + 1, r);
        mytree[index] = mytree[index * 2 + 1] + mytree[index * 2 + 2];
    }
}

void myupdate_tree(vector<long long int>& mytree, int index, int l, int r, int target_l, int target_r, int val) {
    if (r < target_l || target_r < l) return;
    if (l == r && l >= target_l && r <= target_r) {
        mytree[index] += val;
        return;
    }

    int m = (l + r) / 2;
    myupdate_tree(mytree, index * 2 + 1, l, m, target_l, target_r, val);
    myupdate_tree(mytree, index * 2 + 2, m + 1, r, target_l, target_r, val);
    mytree[index] = mytree[index * 2 + 1] + mytree[index * 2 + 2];   
}

long long int myquery_tree(vector<long long int>& mytree, int index, int l, int r, int target_l, int target_r) {
    if (r < target_l || l > target_r) return 0;
    if (l >= target_l && r <= target_r) return mytree[index];

    int m = (l + r) / 2;
    long long int res =  myquery_tree(mytree, index * 2 + 1, l, m, target_l, target_r) + myquery_tree(mytree, index * 2 + 2, m + 1, r, target_l, target_r);
    return res;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<long long int> mytree(4 * n + 1, 0);
    vector<long long int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    mybuild_tree(mytree, v, 0, 0, n - 1);

    for (int i = 0; i < q; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0) {
            myupdate_tree(mytree, 0, 0, n - 1, x, x, y);
        } else {
            cout << myquery_tree(mytree, 0, 0, n - 1, x, y - 1) << endl;
        }
    }
}




Measured memory_bytes: 23888
n,d = map(int,input().split())
ll = [list(map(int,input().split())) for _ in range(n)]

cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        sm = 0
        for p, q in zip(ll[i], ll[j]):
            sm += (p - q) ** 2
        if int(sm**.5)**2==sm:
            cnt += 1
print(cnt)


Measured memory_bytes: 38256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
signed main(){
    int q;cin>>q;
    rep(i,0,q){
        int a,b;cin>>a>>b;
        if(abs(a-b)<=1){
            cout<<(min(a,b)-1)*2<<endl;
        }else{
            int l=0,r=pow(10,10);
            while(r-l>1){
                int mid=(r+l)/2;
                if(mid*mid>=a*b)r=mid;
                else l=mid;
            }
            if(l*(l+1)>=a*b)cout<<(l-1)*2<<endl;
            else cout<<l*2-1<<endl;
        }
    }return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  int max = 0;
  int count = 0;
  for (int j = 0; j < N; j++) {
    if(j != (N-1)){
     if (H.at(j) >= H.at(j+1)){
       count++;
     } else {
       if (count > max ){max = count;}
       count = 0;
     }
    } else {
       if (count > max ){max = count;}
      
    }
  }

  cout << max << endl;
}


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

int main(){
  string s, t;
  cin >> s >> t;
  
  int sl = s.size();
  int tl = t.size();
  vector<vector<int>> dp(tl+1, vector<int>(sl+1, 0));
  
  for(int i = 1; i < tl+1; i++){
    for(int j = 1; j < sl+1; j++){
      dp.at(i).at(j) = max(dp.at(i-1).at(j), dp.at(i).at(j-1));
      if(s.at(j-1) == t.at(i-1))
        dp.at(i).at(j) = max(dp.at(i-1).at(j-1)+1, dp.at(i).at(j));
    }
  }
  
  string ans = "";
  int cnt = dp.at(tl).at(sl);
  while(sl > 0 && tl > 0){
    if(dp.at(tl).at(sl) == dp.at(tl-1).at(sl)){
      tl--;
      continue;
    }
    if(dp.at(tl).at(sl) == dp.at(tl).at(sl-1)){
      sl--;
      continue;
    }
    ans = s.at(sl-1) + ans;
    tl--;
    sl--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 38848
import math

pi = 3.141592653589
a, b, deg = map(float, input().split())

deg = deg*pi/180
cosdeg = math.cos(deg)
sindeg = math.sin(deg)

S = a*b*sindeg/2
L = a+b+math.sqrt(a**2+b**2-2*a*b*cosdeg)
h = b*sindeg

print(f"{S:.6f}")
print(f"{L:.6f}")
print(f"{h:.6f}")


Measured memory_bytes: 5684
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 998244353;

int main() {
  int N,M;cin >> N >> M;
  vector<vint> g(N);
  repeat(i,M){
    int a,b;cin >> a >> b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int Q;cin >> Q;
  vint v(Q),d(Q),c(Q);
  repeat(q,Q){
    cin >> v[q] >> d[q] >> c[q];v[q]--;
  }
  vint ans(N,0);
  vint vd(N,-1);
  for(int q=Q-1;q>=0;q--){
    queue<Pii> que;
    que.push({v[q],d[q]});
    while(!que.empty()){
      Pii p = que.front();
      que.pop();
      if(vd[p.first]>=p.second) continue;
      vd[p.first] = p.second;
      if(ans[p.first]==0) ans[p.first] = c[q];
      for(int u:g[p.first]){
        que.push({u,p.second-1});
      }
    }
  }
  repeat(i,N){
    cout << ans[i] << endl;
  }
  return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)

int main() {
  int n,b;
  cin>>n;
  long long ans=0;
  vector<int> a(n+1);
  rep(i,n+1){
    cin>>a[i];
    ans+=a[i];
  }
  rep(i,n){
    cin>>b;
    if(a[i]>=b) a[i]-=b;
    else {
      a[i+1]-=b-a[i];
      if(a[i+1]<0) a[i+1]=0;
      a[i]=0;
    }
    ans-=a[i];
  }
  ans-=a[n];
  cout<<ans;
  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		int m = fs.nextInt();
		long k = fs.nextLong();
		
		TreeSet<Long> aSet = new TreeSet<>();
		TreeSet<Long> bSet = new TreeSet<>();
		
		HashMap<Long, Integer> aIndex = new HashMap<>();
		HashMap<Long, Integer> bIndex = new HashMap<>();
		
		for(int i = 0; i < n; i++) {
			long last;
			if(i == 0) {
				last = fs.nextLong();
			}else {
				last = aSet.last() + fs.nextLong();
			}
			
			aSet.add(last);
			aIndex.put(last, i);
		}
		
		for(int i = 0; i < m; i++) {
			long last;
			if(i == 0) {
				last = fs.nextLong();
			}else {
				last = bSet.last() + fs.nextLong();
			}
			
			bSet.add(last);
			bIndex.put(last, i);
		}
		
		int ans = 0;
		for(Long aVal : aSet) {
			if(aVal > k) {
				continue;
			}
			
			long rest = k - aVal;
			Long bFloor = bSet.floor(rest);
			
			if(bFloor == null) {
				ans = Math.max(ans, aIndex.get(aVal)+1);
			}else {
				ans = Math.max(ans, aIndex.get(aVal)+1+bIndex.get(bFloor)+1);
			}
		}
		
		
		Long aFloor = aSet.floor(k);
		if(aFloor != null) {
			ans = Math.max(ans, aIndex.get(aFloor)+1);
		}
		
		Long bFloor = bSet.floor(k);
		if(bFloor != null) {
			ans = Math.max(ans, bIndex.get(bFloor)+1);
		}
		
		System.out.println(ans);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

int main(void){
    // Your code here!
   int N;
   string S;
   cin >> N >> S;
   int r = 0, b = 0;
   for(int i = 0; i < N; i++){
       if(S.at(i) == 'R') r++;
       else b++;
   }
   
   if(r > b) cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 256
/* Alohomora */
            #include<bits/stdc++.h>
            #define ll         long long
            #define fl(i,n)    for(i=0;i<n;i++)
            #define fld(i,a,b) for(i=a;i>b;i--)
            #define fli(i,a,n) for(i=a;i<n;i++)
            #define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
            #define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
            #define pb         push_back
            #define mp         make_pair
            #define mod        1000000007 
            #define all(x) 	   x.begin(),x.end()	
            #define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
            #define bada 1000000000000000005
            using namespace std;
            ll fac(ll n){ if(n==0){return 1;}return (n*fac(n-1))%mod;}
            ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
            ll inverse(ll a){return power(a,mod-2);}
            ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
            ll a[2000000];
            void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){a[i]=i;for(j=i*i;j<1000001;j+=i){a[j]=i;}}}}
            vector<ll>v1;
            bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
            { 
                return (a.second < b.second);
            } 
            void comp()
            {
            	 ll i,j,k,n,m,q;
            	 cin>>n>>m>>k;
            	 vector<int>v1;
            	 fl(i,m)
            	 {
            	 	v1.pb(k);
            	 }
            	 if(k==1000000000)
            	 {
            	 	fl(i,n-m)
            	 	{
            	 		v1.pb(1);
            	 	}
            	 }
            	 else
            	 {
            	 	fl(i,n-m)
            	 	{
            	 		v1.pb(k+1);
            	 	}
            	 }
            	 fl(i,n)
            	 {
            	 	cout<<v1[i]<<" "; 
            	 }
            } 
            int main()
            {
            	speedup;
            	ll i=0,t;
            	ll n;
            	//cin>>t;
            	t=1;
            	while(t--)
            	{
            	 comp();
            	}
            }

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

using namespace std;

typedef long long ll;

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

	int N;
	cin >> N;

	vector<int> D(N);
	rep(i, N) cin >> D[i];

	if(N == 1){
		cout << D[0] << endl;
		return 0;
	}

	vector<int> c(13, 0);
	c[0]++;
	rep(i, N) c[D[i]]++;

	for(int i = 1; i < 12; i++){
		if(c[i] >= 3){
			cout << 0 << endl;
			return 0;
		}
	}

	if(c[12] >= 2 || c[0] >= 2){
		cout << 0 << endl;
		return 0;
	}

	vector<int> t;
	vector<int> d;

	if(c[0] == 1) t.push_back(12);

	for(int i = 1; i < 12; i++){
		if(c[i] == 2){
			t.push_back(12+i);
			t.push_back(12-i);
		}else if(c[i] == 1){
			d.push_back(i);
		}
	}

	if(c[12] == 1) t.push_back(24);

	int k = (int) d.size();
	int ans = 0;

	// cout << k << endl;

	for(int i = 0; i < (1 << k); i++){
		for(int j = 0; j < k; j++){
			if((i >> j) & 1){
				t.push_back(12-d[j]);
			}else{
				t.push_back(12+d[j]);
			}
		}

		sort(t.begin(), t.end());
		int s = t[1] - t[0];
		int l = (int) t.size();
		for(int j = 1; j < l; j++){
			s = min(s, t[j] - t[j-1]);
		}

		s = min(s, 24 - t[l-1] + t[0]);
		// cout << i << "," << s << endl;
		ans = max(ans, s);

		for(int j = 0; j < k; j++){
			if((i >> j) & 1){
				t.erase(lower_bound(t.begin(), t.end(), 12-d[j]));
			}else{
				t.erase(lower_bound(t.begin(), t.end(), 12+d[j]));
			}
		}

	}

	cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  string a,b;cin>>a>>b;
  int acc = n;
  for(int i = 0; n > i; i++){
    bool ok = true;
    for(int j = 0; n-i > j; j++){
      if(b[j]!=a[i+j]){
        ok = false;
        break;
      }
    }
    if(ok){
      cout << i+n << endl;
      return 0;
    }
  }
  cout << n*2 << endl;
}

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

using namespace std;

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

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

  sort(a, a + n);

  int max = a[n - 1];
  int min = a[0];

  cout << abs(max - min) << endl;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"8 3"# => r#"2.6666666667"#,
r#"99 1"# => r#"99.0000000000"#,
r#"1 100"# => r#"0.0100000000"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        t: usize,
        x: usize
    }

    (t as f64 / x as f64).to_string()
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int ans = 0;
    for (int i = 0; i < m; i++){
      ans = ans + scan.nextInt();
    }
    if (ans <=n){
      System.out.println(n - ans);
    }else{
      System.out.println(-1);
    }
  }
}


Measured memory_bytes: 45884
#include <bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
struct Parser
{
    int number(State &begin)
    {
        int ret = 0;
        while(isdigit(*begin))
        {
            ret *= 10;
            ret += (*begin - '0');
            begin++;
        }
        return ret;
    }
    int factor(State &begin)
    {
        if(*begin == '(')
        {
            begin++;
            int ret = expression(begin);
            begin++;
            return ret;
        }
        else return number(begin);
    }
    int term(State &begin)
    {
        int ret = factor(begin);
        while(1)
        {
            if(*begin == '*')
            {
                begin++;
                ret *= factor(begin);
            }
            else if(*begin == '/')
            {
                begin++;
                ret /= factor(begin);
            }
            else break;
        }
        return ret;
    }
    int expression(State &begin)
    {
        int ret = term(begin);
        while(1)
        {
            if(*begin == '+')
            {
                begin++;
                ret += term(begin);
            }
            else if(*begin == '-')
            {
                begin++;
                ret -= term(begin);
            }
            else break;
        }
        return ret;
    }
};
signed main()
{
    int N; cin >> N;
    for(int i = 0; i < N; i++)
    {
        Parser ps;
        string s; cin >> s;
        State begin = s.begin();
        int ans = ps.expression(begin);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break

    ans = 0
    n += 1
    for i in range(1, n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                if i + j + k == x:
                    ans += 1
    print(ans)



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll n;
  cin>>n;

  auto is_prime = [](ll x){
    for(ll p=2;p*p<=x;++p){
      if(x%p==0)return false;
    }
    return true;
  };

  for(ll x=n;;++x){
    if(is_prime(x)){
      cout<<x<<endl;
      return 0;
    }
  }

}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()  
#define sz(x) int(x.size()) 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=63;
const int mxn=5e5+5;
bool DEBUG=0;

struct BIT{
	vi bit;
	int N;
	void init(int n){
		N=n;
		bit.assign(n+1,0);
	}
	void add(int pos, int val){
		while(pos<=N){
			bit[pos]+=val;
			pos+=pos&-pos;
		}
	}
	int query(int pos){
		int res=0;
		while(pos){
			res+=bit[pos];
			pos-=pos&-pos;
		}
		return res;
	}
	int sum(int le, int ri){
		if(le!=1)return query(ri)-query(le-1);
		else return query(ri);
	}
}bit;

vector<ii>qry[mxn];
int ans[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,q;
    cin>>n>>q;
    bit.init(n);
    vi prev;
    prev.resize(n+1);
    int c[n];
    for(int i=1; i<=n; i++){
		cin>>c[i];
	}
	for(int i=0; i<q; i++){
		int le, ri;
		cin>>le>>ri;
		qry[ri].eb(le,i);
	}
	for(int i=1; i<=n; i++){
		if(prev[c[i]])bit.add(prev[c[i]],-1);
		bit.add(i,1);
		prev[c[i]]=i;
		for(ii x:qry[i]){
			ans[x.se]=bit.sum(x.fi,i);
		}
	}
	for(int i=0; i<q; i++){
		cout<<ans[i]<<"\n";
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 33156
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
//const ll MOD=1e9+7;
const ll MOD=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

#define MAX 400000
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void fact() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++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;
    }
}

// 二項係数計算
long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll N;
    cin >> N;
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    ll K;
    cin >> K;
    ll ans=0;
    //A,i個
    for(ll i=0;i<=N;++i){
        if(llabs(K-i*A)%B!=0)continue;
        else {
            ll j=(K-i*A)/B;
            ans+=comb(N,i)*comb(N,j)%MOD;
            ans%=MOD;
        }
    }
    prt(ans)


    return 0;
}



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

int main( int argc, char *argv[] )
{
int N;
int Y;
int a;
int b;
int c;
int G;
int H;
int P;
int Q;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> Y;
	Y /= 1000;

	G = Y - N;
	H = Y - 5 * N;

	a = 0;
	P = G - 9 * a;
	Q = 5 * a - H;
	while( P >= 0 )
	{
		if( Q >= 0 && P % 4 == 0 && Q % 4 == 0 )
		{
			b = P / 4;
			c = Q / 4;
			cout << a << " " << b << " " << c << endl;
			
			return 0;
		}

		a++;
		P = G - 9 * a;
		Q = 5 * a - H;
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
//typedef vector<vector<P> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//入力
ll n;
vector<ll>d;

//途中で使う
vector<bool>kakutei;
vector<int>num;
vector<int>v;


int main(){
    cin >> n;
    d.resize(n);
    rep(i,n)cin>>d[i];
    num.resize(15,0);
    kakutei.resize(50,false);
    kakutei[0]=true;
    kakutei[24]=true;
    kakutei[48]=true;
    ll c = 0;
    rep(i,n){
        num[d[i]]++;
    }
    if(num[0]>0){
        cout << 0 << endl;
        return 0;
    }
    rep(i,15){
        if(num[i]>=3){
            cout << 0 << endl;
            return 0;
        }
        if(num[i]==2){
            kakutei[i]=true;
            kakutei[24-i]=true;
            kakutei[i+24]=true;
            kakutei[48-i]=true;
            continue;
        }
        if(num[i]==0)continue;
        v.push_back(i);
    }
    int l = v.size();
    for(int bit=0;bit<(1<<l);bit++){
        vector<bool>kari(50,false);
        rep(i,l){
            if((bit>>i)&1){
                kari[v[i]]=true;
                kari[v[i]+24]=true;
            }
            else{
                kari[24-v[i]]=true;
                kari[48-v[i]]=true;
            }
        }
        int last = 0;
        ll now = INF;
        rep(i,50){
            if(i==0)continue;
            if(kakutei[i]||kari[i]){
                chmin(now,i-last);
                last=i;
            }

        }
        chmax(c,now);
    }

    cout << c << endl;
    return 0;
}

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

int mod=1e9+7;
int main() {
	int N;
	scanf("%d",&N);
	long long n=N;
	for(int i=2;i<N;i++){
		n*=i;
		n%=mod;
	}
	printf("%lld",n);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <unordered_map>
using namespace std;

int main(){
    string str;
    int w;
    int i = 0;
    
    cin >> str >> w;
    
    int len = str.length();
    
    while(i*w < len){
        cout << str[i*w];
        i++;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt();
			int x = scanner.nextInt(), y = scanner.nextInt();
			int max = Math.max(x, y);
			max = (1 == (max & 1)) ? max + 1 : max;
			System.out.println(IntStream.rangeClosed(0, max)
					.map(i -> i * 2 * c + Math.max(x - i, 0) * a + Math.max(y - i, 0) * b).min().getAsInt());
		}
	}
}


Measured memory_bytes: 28116
#include <stdio.h>

int main(void) {
    char S[100];
    scanf("%s", S);

    if (S[0] == 'S') {
        printf("Cloudy\n");
    } else if (S[0] == 'C') {
        printf("Rainy\n");
    } else {
        printf("Sunny\n");
    }

    return 0;
}

Measured memory_bytes: 128
N = int(input())
D = list(map(int, input().split()))

Problems = D[:]
Problems = sorted(Problems)
#print(Problems)
abc = Problems[N // 2 -1]
arc = Problems[N // 2]

#print(abc, arc)

if abc == arc:
    print(0)
else:
    print(arc-abc)

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

using Float = long double;

const Float kPi = acos(-1.0);

Float Sqr(Float x) {
  return x * x;
}

int main() {
  Float a, b, h, m;
  cin >> a >> b >> h >> m;

  Float ang1 = 2.0 * kPi * (h * 60 + m) / (12.0 * 60.0);
  Float ang2 = 2.0 * kPi * m / 60.0;

  Float x1 = a * cos(ang1);
  Float y1 = a * sin(ang1);

  Float x2 = b * cos(ang2);
  Float y2 = b * sin(ang2);

  cout << setprecision(15) << fixed << sqrt(Sqr(x1 - x2) + Sqr(y1 - y2)) << endl;
}

Measured memory_bytes: 4172
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String ABCD = sc.next();
		sc.close();

		ArrayList<Integer> abcdList = new ArrayList<>();

		for(int i = 0; i < 4; i++) {
			abcdList.add(Integer.parseInt(ABCD.substring(i,i+1)));
		}

		Map<Integer, String> Mappp = new HashMap<>();
		Mappp.put(0, "+");
		Mappp.put(1, "-");

		String answer = "";

		for(int a = 0; a < 2; a++) {
			//aが2番目
			for(int b = 0; b < 2; b++) {
				//bが2番目
				for(int c = 0; c < 2; c++) {
					int ans = abcdList.get(0);
					if(a==0) {
						ans += abcdList.get(1);
					}else {
						ans -= abcdList.get(1);
					}

					if(b==0) {
						ans += abcdList.get(2);
					}else {
						ans -= abcdList.get(2);
					}

					if(c==0) {
						ans += abcdList.get(3);
					}else {
						ans -= abcdList.get(3);
					}

					if(ans == 7 && answer.equals("")) {
						answer += abcdList.get(0).toString() + Mappp.get(a);
						answer += abcdList.get(1).toString() + Mappp.get(b);
						answer += abcdList.get(2).toString() + Mappp.get(c);
						answer += abcdList.get(3).toString() + "=7" ;
						break;
					}
				}
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 21844
(defun readseq (num)
  (loop 
    as i 
    below num 
    collect (read)
  )
)

(defun ismonoinc (l)
  (or 
    (< (first l) (second l) (third l))
    (> (first l) (second l) (third l))
  )
)

(defun createordinaryseq (n seq)
  (loop 
    as i below (- n 2) 
    collect (ismonoinc (list (first seq) (second seq) (third seq)))
    do (setq seq (cdr seq))
  )
)
    
(let* (
    (n (read))
    (seq (readseq n))
  )
  (princ (count T (createordinaryseq n seq)))
)

Measured memory_bytes: 14948
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  int n=s.size();

  int ans_l=-1, ans_r=-1;
  rep(j,n-1){
    if(s[j]==s[j+1]){
      ans_l=j+1;
      ans_r=j+2;
      prt2(ans_l, ans_r);
      return 0;
    }
  }

  rep(j,n-2){
    if(s[j]==s[j+2]){
      ans_l=j+1;
      ans_r=j+3;
      prt2(ans_l, ans_r);
      return 0;
    }
  }

  prt2(ans_l, ans_r);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll ans=0;
	while(a%2==0&&b%2==0&&c%2==0){
		ll A=a/2,B=b/2,C=c/2;
		ans++;
		a=A+B,b=B+C,c=C+A;
		if(a==b&&b==c&&c==a){
			cout << -1;
			return 0;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    std::cin >> N;
    if(N<=9){
        std::cout << N << std::endl;
    }
    else if(N<=99){
        std::cout << 9 << std::endl;
    }
    else if(N<=999){
        std::cout << N-90 << std::endl;
    }
    else if(N<=9999){
        std::cout << 909 << std::endl;
    }
    else if(N<=99999){
        std::cout << N-9090 << std::endl;
    }
    else{std::cout << 90909 << std::endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,c;
    cin>>n>>c;
    vector<vector<ll> > d(50,vector<ll>(50)),a(600,vector<ll>(600));
    FOR(i,1,c+1){
      FOR(j,1,c+1){
        cin>>d[i][j];
      }
    }
    FOR(i,1,n+1){
      FOR(j,1,n+1){
        cin>>a[i][j];
      }
    }
    vector<ll> a0(c+1,0),a1(c+1,0),a2(c+1,0);
    FOR(i,1,c+1){
      FOR(j,1,n+1){
        FOR(k,1,n+1){
          if((j+k)%3==0){
            a0[i]+=d[a[j][k]][i];
          }else if((j+k)%3==1){
            a1[i]+=d[a[j][k]][i];
          }else{
            a2[i]+=d[a[j][k]][i];
          }
        }
      }
    }
    ll ans=mod;
    FOR(i,1,c+1){
      FOR(j,1,c+1){
        if(i==j){
          continue;
        }
        FOR(k,1,c+1){
          if(k==i||k==j){
            continue;
          }
          if(ans>a0[i]+a1[j]+a2[k]){
            ans=a0[i]+a1[j]+a2[k];
          }
        }
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3072
import java.util.*;

class Main{
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      int     N = scan.nextInt();
      int     A = scan.nextInt();
      int     B = scan.nextInt();
      long    sum = 0, mod = 0;
      long    n = 0;

      for(long j = 1; j <= N; j++){
          n = j;
          for(long i = 1; i <= 6; i++){
              mod += n % 10;
              n    = n / 10;
              }
          if(mod >= A && mod <= B){
             sum += j;
             }
          //System.out.println(j + "" + sum);
          mod = 0;
          }
      System.out.println(sum);
   }
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int read(){
	int f=1,x=0; char c=getchar();
	while (c>'9' || c<'0') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
	return f*x;
}
int a,b;
int main(){
	cin>>a>>b;
	if(b>=a)cout<<a<<endl;
	else cout<<a-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        string A;
        cin >> A;

        A[5] = ' ';
        A[13] = ' ';

        cout << A << endl;

        return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){if(p==1){return a;}long x=Modpow(a,p/2,m);x=(x*x)%m;return (p&1l)!=0? (x*a)%m:x;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       StringBuilder sb=new StringBuilder();
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt();
        int[] arr=new int[n];
        long mod=(long)1e9+7;
        Map<Integer,Integer>map=new HashMap<>();
        for(int i=0;i<n;i++){arr[i]=s.nextInt();}
        	long res=0;
        for(int i=0;i<n;i++){
        	int tmp=arr[i];
        	for(int j=2;j*j<=arr[i];j++){
        		if(tmp%j==0){
        			int count=0;
        		while(tmp%j==0){count++;tmp/=j;}
        		map.put(j,Math.max(map.getOrDefault(j,0),count));
        		}
        	}
        	if(tmp!=1){map.put(tmp,Math.max(map.getOrDefault(tmp,0),1));}
        }
        long lcm=1;
        for(int x:map.keySet()){
        	lcm=Modmul(lcm,Modpow(x,map.get(x),mod),mod);
        }
        for(int i=0;i<n;i++){
        	res=(res+Modmul(lcm,ModInv(arr[i],mod),mod))%mod;
        }
       out.write(res+"");
        out.flush();
  }
}


Measured memory_bytes: 33136
def euclid(a, b):
    mod = a % b
    if mod != 0:
        b = euclid(b, mod)
    return b
N = int(input())
A = [int(a) for a in input().split()]
gcd_lis = [A[0]]
gcd = A[0]
for a in A[1:]:
    gcd = euclid(gcd, a)
    gcd_lis.append(gcd)
inv_gcd_lis = [A[-1]]
gcd = A[-1]
for a in A[::-1][1:]:
    gcd = euclid(gcd, a)
    inv_gcd_lis.append(gcd)
inv_gcd_lis = inv_gcd_lis[::-1]
maximam = 0
for index in range(N):
    if index == 0:
        gcd = inv_gcd_lis[1]
    elif index == N - 1:
        gcd = gcd_lis[N-2]
    else:
        gcd = euclid(gcd_lis[index - 1], inv_gcd_lis[index + 1])
    maximam = max(gcd, maximam)
print(maximam)

Measured memory_bytes: 14428
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	target = 1
	broke = 0
	for i in range(len(A)):
		if A[i] == target:
			target += 1
		else:
			broke += 1
	if broke < N:
		print(broke)
	else:
		print(-1)

main()

Measured memory_bytes: 32304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nn 65536*8
ll a[nn];ll sa[nn];
ll b[nn];ll n;ll mod;
map<ll,ll> m;
pair<ll,ll> range[nn];
ll rf[nn];
ll modi(ll x)
{
	return (x%mod+mod)%mod;
}
int tot=0;
struct travellerspride{
	ll tree[nn*2+10];
	int llc[nn*2+10],rrc[nn*2+10];
	ll tag[nn];ll nul=-1e17;int all;
	#define lc llc[id]
	#define rc rrc[id]
	void up(int id)
	{
		tree[id]=min(tree[lc],tree[rc]);
	}
	void set(int id,ll y)
	{
		tree[id]=y;
		tag[id]=y;
	}
	void down(int id)
	{
		if(tag[id]>nul)
		{
			set(lc,tag[id]);
			set(rc,tag[id]);
		}
		tag[id]=nul;
	}
	#define mid (l+r)/2
	void build(int l,int r,int &id)
	{
		if(!id) id=++all;
		tag[id]=nul;
		if(l==r)
		{
			if(l>tot) tree[id]=0-rf[l-tot];
			else tree[id]=0-rf[l];
			return ;
		}
		build(l,mid,lc);build(mid+1,r,rc);
		up(id);
	}
	ll query(int a,int b,int l,int r,int id)
	{
		if(l>=a and r<=b)
			return tree[id];
		down(id);
		if(b<=mid) return query(a,b,l,mid,lc);
		else if(a>mid) return query(a,b,mid+1,r,rc);
		else return min(query(a,b,l,mid,lc),query(a,b,mid+1,r,rc));
	}
	void update(int a,int b,int l,int r,int id,ll y)
	{
		if(a>b) return ;
		if(l>=a and r<=b)
		{
			set(id,y);
			return ;
		}
		down(id);
		if(a<=mid) update(a,b,l,mid,lc,y);
		if(b>mid) update(a,b,mid+1,r,rc,y);
		up(id);
	}
	ll query(int l,int r,int id)
	{
		if(l==r)
		{
			if(l>tot) return tree[id]+rf[l-tot];
			else return tree[id]+rf[l];
		}
		down(id);
		return min(query(l,mid,lc),query(mid+1,r,rc));
	}
	
}trcyx;


int main()
{
	scanf("%lld%lld",&n,&mod);
	set<ll> s;
	for(int i=0;i<n;i++) 
	{
		scanf("%lld%lld",&a[i],&b[i]);
		if(b[i]==1 and a[i]*2>mod)
		{
			puts("-1");
			exit(0);
		}
		if(i)a[i]+=a[i-1];//aishouldnotbe modded
		if(2==b[i]) continue;
		ll r=-2*a[i],l=0;if(i) l=-2*a[i-1];//this range is what we can stay
		l=modi(l),r=modi(r);
		range[i]=make_pair(l,r);
		s.insert(l);s.insert(r);
	}
	for(set<ll>::iterator it=s.begin();it!=s.end();it++)
		m[*it]=++tot,rf[tot]=*it;
	int rt=0;ll totot=tot+tot;
	trcyx.build(1,totot,rt);
	for(int i=0;i<n;i++)
	{
		ll l=range[i].first,r=range[i].second;
		l=m[l],r=m[r];if(l>r) r+=tot;//thus we can have real ranges
		if(b[i]==1)
		{
			ll fl=trcyx.query(1,l,1,totot,rt)+rf[l];
			fl=min(fl,trcyx.query(l,totot,1,totot,rt)+rf[l]+mod);
			trcyx.update(l,l,1,totot,rt,fl-rf[l]);
			trcyx.update(l+tot,l+tot,1,totot,rt,fl-rf[l]);
			//these poins are same
			l=range[i].first,r=range[i].second;
			l=m[l],r=m[r];
			if(l<=r)
			{
				trcyx.update(r+1,tot,1,totot,rt,1e17);
				trcyx.update(1,l-1,1,totot,rt,1e17);
				
				trcyx.update(r+1+tot,totot,1,totot,rt,1e17);
				trcyx.update(1+tot,l-1+tot,1,totot,rt,1e17);
			}
			else
			{
				trcyx.update(r+1,l-1,1,totot,rt,1e17);
				
				trcyx.update(r+1+tot,l-1+tot,1,totot,rt,1e17);
			}
			//thus these ranges are mpossible
		}
	}
	cout<<trcyx.query(1,totot,rt)+a[n-1]*2;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vector<vi> grid(2, vi(n));
  vector<vi> dp(2, vi(n));
  rep(i, 2) rep(j, n) std::cin >> grid[i][j];
  rep(i, 2) rep(j, n) {
    dp[i][j] = grid[i][j];
    if (i > 0) chmax(dp[i][j], dp[i-1][j]+grid[i][j]);
    if (j > 0) chmax(dp[i][j], dp[i][j-1]+grid[i][j]);
  }
  std::cout << dp[1][n-1] << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

struct info {
  int group;
  int pos;
  int left = 0;
  int right = 0;
};

int
main()
{
 
  string s; cin >> s;
  int N = s.size();
  vector<int> arr(0);
  rep(i, 0, N){
    if(s[i] == 'R') arr.push_back(1);
    else arr.push_back(0);
  }

  int group = 0;
  int pos = 0;
  bool leftflag = false;
  vector<pair<int, int>> grouplen(N);
  vector<info> infos(N);
  rep(i, 0, N){
    if(arr[i] == 1){
      if(leftflag == true){
        group += 1;
        pos = 0;
        leftflag = false;
      }
      infos[i].pos = pos++; 
      infos[i].group = group;
      grouplen[group].first += 1;
    } else if (arr[i] == 0 && leftflag == true){
      infos[i].group = group;
      infos[i].left += infos[i - 1].left + 1;
      grouplen[group].second += 1;
    } else {
      grouplen[group].first += 1;
      infos[i].group = group;
      leftflag = true;
    }
  }
  vector<int> ans(N);

  int sum = 0;
  for(auto x: grouplen){
    int all = x.first + x.second;
    rep(i, 0, all){
      int si = grouplen[infos[i + sum].group].first - 2;
      if(arr[i + sum] == 1){
        int move = 100000 - (si - infos[i + sum].pos);
        if(move % 2 == 0) ans[sum + si] += 1;
        else ans[sum + si + 1] += 1;

      } else {
        si += 1;
        int move = 100000 - infos[i + sum].left;
        if(move % 2 == 0) ans[sum + si] += 1;
        else ans[sum + si - 1] += 1;
      }
    }
    sum += x.first + x.second;
  }
   
  for(auto x: ans){
    cout << x << " ";
  }
  cout << endl;

}

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

int main() {
    ll N;
    cin >> N;
    int ans = 0;

    for(ll i=2;i*i<=(N-1);++i){
        if((N-1)%i != 0) continue; 
        ++ans;
        if(i*i != (N-1)) ++ans;
    }
    if(N>2)++ans;
    for(ll i=2;i*i<=N;++i){
        ll tmpN = N; 
        if(N%i != 0) continue;
        while(tmpN%i==0) tmpN/=i;
        if(tmpN%i == 1) ++ans;
    }
    ++ans;
    cout << ans << endl;
}


Measured memory_bytes: 256