akhauriyash/Code-Regression huggingface dataset:
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

const int N = 1<<18;
mat dp(N,vec(2,0));

void solve(int x, int y){
  vec a = {dp[x][0],dp[x][1],dp[y][0],dp[y][1]};
  sort(a.rbegin(),a.rend());
  a.resize(2);
  dp[y] = a;
}

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

  int n;
  cin >> n;

  vector<int> a(1<<n);
  REP(i,1<<n) cin >> a[i], dp[i][0] = a[i];
  
  REP(i,n){
    REP(j,1<<n){
      if(j&(1<<i)) continue;
      solve(j,j|(1<<i));
    }
  }

  int mx = 0;
  FOR(i,1,1<<n){
    mx = max(mx,dp[i][0]+dp[i][1]);
    cout << mx << "\n";
  }

  return 0;
}

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

#define rep(i, a, n) for(int i=(a);i<(n);++i)
#define per(i, a, n) for(int i=(a);i>(n);--i)
#define pb emplace_back
#define mp make_pair
#define lowbit(x) (x & -x)

typedef long long LL;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 2e5 + 10;

int n;
char s[N];

int cal(){
	int ret = 0;
	int L = 0;
	per(i, n-1, -1){
		if(s[i] == 'R'){
			while(L < i && s[L] == 'R')	L++;
			if(L < i){
				swap(s[i], s[L]);
				ret++;
				L += 1;
			} else {
				break;
			}
		}
	}
	return ret;
}

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

	int ans = 0;
	rep(i, 0, n){
		if(s[i] == 'W'){
			rep(j, i, n){
				if(s[j] == 'W')	ans++;
			}
			break;
		}
	}
	ans = min(ans, cal());
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 4016
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        int sum = 0;
        for (int i = 0 ; i < 3; i++){
            sum+= in.nextInt();
        }
        out.pl(sum>=22 ? "bust" : "win");
        out.close();
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32960
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=int(input());e=[[]for _ in[0]*-~n];q=[(1,0)];f=[-1]*n\n"
"while n>1:v,w,c=map(int,input().split());e[v]+=(w,c),;e[w]+=(v,c),;n-=1\n"
"while q:\n"
" v,c=q.pop();f[v-1]=c%2\n"
" for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0)\n"
"print(*f)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 40616
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main() {
  string s,t;
  cin >> s >> t;
  sort(ALL(s));
  sort(ALL(t), greater<>());
  if(s<t) yes();
  else no();
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		while (true) {
			int w = sc.nextInt(), h = sc.nextInt();
			if (w == 0 && h == 0) break;
			String[] rows = new String[h];
			for (int i = 0; i < h; i++)
				rows[i] = sc.next();
			BigInteger[][] dp = new BigInteger[h+1][w+1];
			for (int i = 0 ; i <= h; i++)
				for (int j = 0; j <= w; j++)
					dp[i][j] = BigInteger.ZERO;
			
			BigInteger res = BigInteger.ZERO;
			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (Character.isDigit(rows[i-1].charAt(j-1))) {
						dp[i][j] = (((dp[i-1][j].compareTo(dp[i][j-1]) > 0) ? dp[i-1][j] : dp[i][j-1]).multiply(BigInteger.TEN)).add(new BigInteger(""+rows[i-1].charAt(j-1)));
						res = (dp[i][j].compareTo(res) > 0) ? dp[i][j] : res;
					}
				}
			}
			out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

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

    if(s == "SUN") day = 7;
    else if(s == "MON") day = 6;
    else if(s == "TUE") day = 5;
    else if(s == "WED") day = 4;
    else if(s == "THU") day = 3;
    else if(s == "FRI") day = 2;
    else if(s == "SAT") day = 1;

    std::cout << day << std::endl;
    return 0;
}

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

using namespace std;

const long long INF = LONG_LONG_MAX;
const int maxsum = (int) (1e5 + 1);
const long long mod = (long long) (1e9 + 7);


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    string s, t;
    int n;
    cin >> n;
    vector<long double> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<long double> dp(n + 1);
    dp[0] = 1.0;
    for (int i = 1; i <= n; ++i) {
        for (int j = n; j > 0; --j) {
            dp[j] = dp[j] * (1.0 - p[i - 1]) + dp[j - 1] * p[i - 1];
        }
        dp[0] *= (1.0 - p[i - 1]);
    }
    long double ans = 0;
    for (int i = (n + 1) / 2; i < n + 1; ++i) {
        ans += dp[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a,b,h,m; cin >> a >> b >> h >> m;
    double pi = 3.14159265358979323846;
    double k;

    if(h == 0 && m == 0){
        cout << abs(a-b) << endl;
    }
    else{
        k = abs(h*30+(m*6/12)-m*6);
        if(k > 180){
            k = 360-k;
        }
    
        //ラジアン
        double ww = k*pi/180;
        double c = cos(ww);//cosの値ゲット
        double ans = a*a + b*b - 2*a*b*c;
        cout << fixed << setprecision(20) << pow(ans,0.5)<< endl;
    }
    return 0;
}

Measured memory_bytes: 4308
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        Sieve sieve = new Sieve(1000002);
        boolean joukenA = true;
        Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            Map<Integer, Integer> map = sieve.factorMap(array[i]);
            
            for (Integer key : map.keySet()) {
                if (set.contains(key)) {
                    joukenA = false;
                    break;
                } else {
                    set.add(key);
                }
            }
        }
        
        
        boolean joukenB = false;
        long tmp = array[0];
        for (int i = 1; i < n; i++) {
            tmp = gcd(tmp, array[i]);
        }
        if (tmp == 1) joukenB = true;
        
        String ans = "not coprime";
        if (joukenA) {
            ans = "pairwise coprime";
        } else {
            if (joukenB) {
                ans = "setwise coprime";
            }
        }
        System.out.println(ans);
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) return a;
        
        return gcd(b, a % b);
    }
}

class Sieve {
    int[] minFactor;    // 最小の素因数

    Sieve(int n) {
        minFactor = new int[n + 1];
        Arrays.fill(minFactor, -1);
        
        for (int i = 2; i <= n; i++) {
            // 素数でないなら篩をかけない
            if (minFactor[i] != -1) continue;
            
            minFactor[i] = i;
            
            // 自分の倍数の最小の素因数を自分とする
            // (但し未確定の数に限る)
            for (int j = 2; i * j <= n; j++) {
                if (minFactor[i * j] == -1) {
                    minFactor[i * j] = i;
                }
            }
        }
    }
    
    boolean isPrime(int x) {
        if (minFactor[x] == x) {
            return true;
        }
        
        return false;
    }
    
    // nの素因数のリスト (60 => [2, 2, 3, 5])
    List<Integer> factorList(int x) {
        List<Integer> res = new ArrayList<Integer>();
        
        while (x != 1) {
            res.add(minFactor[x]);
            x /= minFactor[x];
        }
        
        return res;
    }
    
    // nの素因数の頻度 (60 => (2 => 2, 3 => 1, 5 => 1)
    Map<Integer, Integer> factorMap(int x) {
        Map<Integer, Integer> res = new HashMap<Integer, Integer>();
        
        List<Integer> factorList = factorList(x);
        
        for (Integer f : factorList) {
            int count = res.getOrDefault(f, 0);
            res.put(f, ++count);
        }
        
        // for (int i = 1; i <= x; i++) {
        //     if (!res.containsKey(i)) {
        //         res.put(i, 0);
        //     }
        // }
        
        return res;
    }
}

Measured memory_bytes: 70324
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int k = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        int c = 1;
        for (int i = 0 ; i < s.length - 1; i++) {
            if (s[i] == s[i + 1]) {
                c++;
            } else {
                list.add(c);
                c = 1;
            }
        }
        list.add(c);
        long d = 0;
        if (list.size() == 1) {
            long f = (long ) list.get(0) * k;
            System.out.println(f/2);
            return;
         }

        if (s[0] != s[s.length-1]) {
            for (int i = 0 ; i < list.size() ; i++) {
                long e = (long) list.get(i) / 2;
                d += e * k;
            }
        } else {
            for (int i = 1 ; i < list.size() - 1 ; i++) {
                long e = (long) list.get(i) / 2;
                d += e * k;
            }
            long f =( (long) list.get(0) + (long) list.get(list.size() - 1)) / 2;
            d += f * (k - 1) + (long) list.get(0) / 2 + (long) list.get(list.size()-1)/2;
        }

        System.out.println(d);

    }

}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int ans=0;
	for(int i=0; i<N; ++i) ans += L+i;
	int mn=L, mx=L+N-1;
	if(0<mn) ans -= mn;
	if(mx<0) ans -= mx;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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 (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,x,y;
    cin >> n >> x >> y;
    vector<vector<ll> > g(n);
    rep(i, n - 1){
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
    queue<ll> q;
    vector<ll> ans(n - 1);
    rep(i, n){
        vector<ll> dist(n, -1);
        q.push(i);
        dist[i] = 0;
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            for(auto to : g[now]){
                if(dist[to] != -1) continue;
                dist[to] = dist[now] + 1;
                q.push(to);
                ans[dist[to] - 1]++;
            }
        }
    }
    rep(i, n - 1)  print(ans[i] / 2);



}




//queue<pint>().swap(q); キュー内を全て削除
//priority_queue<ll, vector<ll>, greater<ll> > que;
//auto dp=make_v<int>(4,h,w);
//vector<vector<ll>> g;
//g.assign(n, vector<ll>()); g.resize(n);でも大丈夫っぽい
//fill_v(dp,0);

Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr ll LL_INF = 1e15;

ll dist1[200][200], dist2[200][200];
ll dp[1000][200];

/*
 * 2 <= N <= 200
 * 1 <= M <= 10000
 * 1 <= xi, yi <= N
 * 1 <= ti <= 1000
 * 1 <= R <= 1000
 * 1 <= zi <= N
 */

int main(void) {
    while (true) {
        int i, j, k, n, m;
        scanf("%d%d",&n,&m);
        if (n == 0 && m == 0) break;
        REP (i,n) REP (j,n) {
            dist1[i][j] = i == j ? 0 : LL_INF;
            dist2[i][j] = i == j ? 0 : LL_INF;
        }
        REP (i,m) {
            int x, y, t;
            char sl;
            scanf("%d %d %d %c",&x,&y,&t,&sl);
            x--; y--;
            if (sl == 'S') {
                dist1[x][y] = min<ll>(dist1[x][y],t);
                dist1[y][x] = dist1[x][y];
            }
            else {
                dist2[x][y] = min<ll>(dist2[x][y],t);
                dist2[y][x] = dist2[x][y];
            }
        }
        REP (k,n) REP (i,n) REP (j,n) {
            dist1[i][j] = min(dist1[i][j],dist1[i][k] + dist1[k][j]);
            dist2[i][j] = min(dist2[i][j],dist2[i][k] + dist2[k][j]);
        }
        int r;
        scanf("%d",&r);
        int pre;
        scanf("%d",&pre);
        pre--;
        REP (i,r) REP (j,n) dp[i][j] = LL_INF;
        dp[0][pre] = 0;
        REP (i,r-1) {
            int x;
            scanf("%d",&x);
            x--;
            REP (j,n) {
                dp[i+1][j] = min(dp[i+1][j],dp[i][j] + dist2[pre][x]);
                REP (k,n) dp[i+1][j] = min(dp[i+1][j],dp[i][k] + dist2[pre][k] + dist1[k][j] + dist2[j][x]);
            }
            pre = x;
        }
        ll ans = LL_INF;
        REP (j,n) ans = min(ans,dp[r-1][j]);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 5276
def solve():
    n = int(input())
    buttons = [int(input()) for _ in range(n)]
    c = 1
    now = buttons[0]  # button1
    while now != 2 and c < n:
        c += 1
        now = buttons[now - 1]
    return c if c < n else -1


if __name__ == "__main__":
    print(solve())


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

struct RSQ {
	using type = int;
	static const type id() { return 0; }
	static type op(const type& l, const type & r) { return l + r; }
};

const int PMAX = 3000000;

template <typename M>
class PersistentSegmentTree {
	using T = typename M::type;
	struct node {
		T val;
		node *l, *r;
		node() {}
		node(T val) : val(val), l(nullptr), r(nullptr) {}
		void init(T v, node *left, node *right) {
			val = v;
			l = left;
			r = right;
		}
	};
	const int n;
	vector<node> pool;
	int it;
	vector<node*> root;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node *new_node(int val = 0, node *l = nullptr, node *r = nullptr) {
		pool[it].init(val, l, r);
		return &pool[it++];
	}
	node *fix(node *x, int p, T val, int lb, int ub) {
		if (p < lb || ub <= p) return x;
		if (lb + 1 == ub) return new_node(val);
		if (x == nullptr) x = new_node(M::id());
		else x = new_node(x->val, x->l, x->r);
		int c = (lb + ub) / 2;
		x->l = fix(x->l, p, val, lb, c);
		x->r = fix(x->r, p, val, c, ub);
		x->val = M::op(x->l == nullptr ? M::id() : x->l->val, x->r == nullptr ? M::id() : x->r->val);
		return x;
	}
	T sub(node *x, int l, int r, int lb, int ub) {
		if (x == nullptr || ub <= l || r <= lb) return M::id();
		if (l <= lb && ub <= r) return x->val;
		int c = (lb + ub) / 2;
		return M::op(sub(x->l, l, r, lb, c), sub(x->r, l, r, c, ub));
	}
public:
	PersistentSegmentTree(int n_) : n(size(n_)), pool(PMAX), it(0) {
		root.push_back(nullptr);
	}
	void update(int p, T val, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		root.push_back(fix(root[rt], p, val, 0, n));
	}
	T find(int l, int r, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		return sub(root[rt], l, r + 1, 0, n);
	}
	int getversion() {
		return root.size() - 1;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	PersistentSegmentTree<RSQ> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x - 1, y - 1));
		}
		else {
			st.update(x - 1, st.find(x - 1, x - 1) + y);
		}
	}
	return 0;
}

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

typedef long long ll;

const int MAXN = 1e5 + 7;

int main(){
    int a, b;
    cin >> a >> b;
    if((a+b)%2 != 0)    cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;    
    return 0;
}

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

using namespace std;

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

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

  int NumOfZero = 0, NumOfOne = 0;
  rep(i, 0, s.length())
  {
    if (s[i] == '0') ++NumOfZero;
    else ++NumOfOne;
  }
  
  cout << (NumOfOne < NumOfZero ? NumOfOne : NumOfZero) * 2 << endl;
}

Measured memory_bytes: 512
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 200050;
template<typename T>
inline void read(T&x)
{
	T f = 1,c = 0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
	x = f*c;
}
int n,fa[N],ch[N][2];
ll v[N],dep[N];
void DFS(int u)
{
	if(!ch[u][0])return ;
	dep[ch[u][0]]=dep[u]+v[ch[u][0]],DFS(ch[u][0]);
	dep[ch[u][1]]=dep[u]+v[ch[u][1]],DFS(ch[u][1]);
}
struct Pair
{
	ll x,y;
	Pair(){}
	Pair(ll x,ll y):x(x),y(y){}
}g1[N],g2[N],g[N];
vector<Pair>ve[N];
ll mid;
int Merge(int len)
{
	int i = 1,j = len,k = 0;
	while(i<=len&&j>=1)
	{
		if(g1[i].x<=g2[j].x)g[++k]=g1[i++];
		else g[++k]=g2[j--];
	}
	while(i<=len)g[++k]=g1[i++];
	while(j>=1)g[++k]=g2[j--];
	return k;
}
void dfs(int u)
{
	if(!ch[u][0]){ve[u].push_back(Pair(dep[u],dep[u]));return ;}
	int ls = ch[u][0],rs = ch[u][1];
	dfs(ls),dfs(rs);int k=0;
	if(ve[ls].size()>ve[rs].size())swap(ls,rs);
	for(int i=0,j=-1,l1=ve[ls].size(),l2=ve[rs].size();i<l1;i++)
	{
		while(j<l2-1&&ve[ls][i].y+ve[rs][j+1].x-2ll*dep[u]<=mid)j++;
		if(~j)g1[++k]=Pair(ve[ls][i].x,ve[rs][j].y),g2[k]=Pair(ve[rs][j].y,ve[ls][i].x);
	}
	int len = Merge(k);
	for(int i=1;i<=len;i++)
		if(i==1||g[i].y<g[i-1].y)
			ve[u].push_back(g[i]);
}
bool check()
{
	for(int i=1;i<=n;i++)
		ve[i].clear();
	dfs(1);
	return (int)ve[1].size()>0;
}
int main()
{
	read(n);
	for(int i=2;i<=n;i++)
	{
		read(fa[i]),read(v[i]);
		if(!ch[fa[i]][0])ch[fa[i]][0]=i;
		else ch[fa[i]][1]=i;
	}
	DFS(1);
	ll l = 0,r = 200000ll*n,ans = r;
	while(l<=r)
	{
		mid = (l+r)>>1;
		if(check())ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 41460
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;
        long[] A = new long[n];
        long[] B = new long[n];
        for(int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(sc.next());
            B[i] = Integer.parseInt(sc.next());
        }
        for(int i = n-1; i >= 0; i--) res += (B[i] - (res + A[i]) % B[i]) % B[i];
        System.out.println(res);
    }
}


Measured memory_bytes: 53232
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
ll gcd(ll a, ll b)
{
    if(b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
    return (gcd(a,b)/a)*b;
}
int main()
{
    int n,a;
    cin>>n>>a;
    cout<<n*n - a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009

int main(){
    long n,m;
    cin>>n>>m;
    vector<long> data;
    for (long i=0; i<n; i++){
        long p;
        cin>>p;
        data.push_back(p);
    }
    sort(data.begin(),data.end());
    
    vector<long> num;
    for (long i=0; i<=n-m; i++){
        long p=data[i+m-1]-data[i];
        num.push_back(p);
    }
    
    sort(num.begin(),num.end());
    
    cout<<num[0]<<endl;
}

Measured memory_bytes: 2548
#include<iostream> 
#include<stdio.h>
#include<string>
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {

	
	int x, y;
	cin >> x >> y;
	bool can = true;

	if (y % 2 != 0) can = false;

	int res = y - 4 * x;
	if (res > 0) can = false;

	int ans = y - 2*x;
	if (ans < 0) can = false;

	cout << (can ? "Yes" : "No") << endl;
	return 0;
}

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

int main(){
   int n;
   cin >> n;
   int dp[n],h[n];
   memset(dp,0,sizeof dp);
   for(int i = 0; i < n; ++i){
      cin >> h[i];
   }
   dp[0] = 0;
   dp[1] = abs(h[1]-h[0]);
   for(int i = 2; i < n; ++i){
      dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
   }

   cout << dp[n-1];
}

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

#define putchar_unlocked putchar

char T[550005];

// Based on editorial solution
int D[13][550005]; // one digit at a time, with digit 0 representing the ones place
int W[13][550005];
int lastUpdated[13][550005];

inline void putInt(int i){
    if(i==0){putchar_unlocked('0');}
    else{
    int x[11];
    int count1=0;
    while(i>0){
        x[count1++]=i%10;
        i/=10;
    }
    for(int j=count1-1;j>=0;j--){
        putchar_unlocked(48+x[j]);
    }
    }
    putchar_unlocked(' ');
}

int N;

inline void update(int n, int indx, int cntS){
    if((cntS&1) != (lastUpdated[n][indx]&1)){
        // conduct salsa
        if(D[n][indx]){D[n][indx] = 3-D[n][indx];}
    }
    // update the lastUpdated index
    lastUpdated[n][indx] = cntS;
}

int pow3[16];

int main(){
    scanf("%d", &N);

    scanf(" %s", T);

    int M = strlen(T);

    pow3[0] = 1;
    for(int i = 1; i <= N; i ++){
        pow3[i] = pow3[i-1]*3;
    }

    int pow3N = pow3[N];

    //printf("ok");
    memset(W, 0, sizeof(W));
    for(int n = 1; n <= N; n ++){
        //printf("ok");
        for(int j = 0; j < pow3[N]; j ++){
            D[n][j] = (j%pow3[n])/pow3[n-1];
            //printf("D[%d][%d]=%d\n", n, j, D[n][j]);
        }
        W[n][0] = pow3[n]-1;
    }


    memset(lastUpdated, 0, sizeof(lastUpdated));
    int cntS2 = 0;
    for(int n = 1; n <= N; n ++){
        int cntS = 0;
        for(int i = 0; i < M; i ++){
            int indx0 = W[n-1][i];
            int indx1 = W[n-1][i]+pow3[n-1];
            int indx2 = W[n-1][i]+(pow3[n-1]<<1);

            if(indx1 >= pow3[n]){indx1 -= pow3[n];}
            if(indx2 >= pow3[n]){indx2 -= pow3[n];}

            update(n, indx0, cntS+(T[i]=='S'));
            update(n, indx1, cntS+(T[i]=='S'));
            update(n, indx2, cntS+(T[i]=='S'));
            if(D[n][indx0] == 2){
                W[n][i] = indx0;
            }else if(D[n][indx1] == 2){
                W[n][i] = indx1;
            }else{
                W[n][i] = indx2;
            }

            if(T[i] == 'R'){
                D[n][indx0] = (D[n][indx0]+1);
                D[n][indx1] = (D[n][indx1]+1);
                D[n][indx2] = (D[n][indx2]+1);
                if(D[n][indx0] == 3){D[n][indx0] = 0;}
                if(D[n][indx1] == 3){D[n][indx1] = 0;}
                if(D[n][indx2] == 3){D[n][indx2] = 0;}
                lastUpdated[n][indx0] = cntS;
                lastUpdated[n][indx1] = cntS;
                lastUpdated[n][indx2] = cntS;
            }else if(T[i] == 'S'){
                cntS ++;
            }

            //printf("W[%d][%d]=%d\n", n, i+1, W[n][i+1]);
        }

        cntS2 = cntS;
    }

    for(int n = 1; n <= N; n ++){
        for(int i = 0; i < pow3[n]; i ++){
            update(n, i, cntS2);
        }
    }

    for(int i = 0; i < pow3[N]; i ++){
        int temp = 0;
        for(int n = 1; n <= N; n ++){
            temp += D[n][i%pow3[n]]*pow3[n-1];
        }
        putInt(temp);
    }

    return 0;
}


Measured memory_bytes: 85148
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
   ll N;
   cin>>N;
   ll ans=0;
   for(ll i=0;i<N;i++) {
       ll l,r;
       cin>>l>>r;
       ans+=r-l+1;
   }
   cout<<ans<<endl;
   
   }

Measured memory_bytes: 3636
def larger(x, y):
	if x > y: return x
	else: return y

N, W = map(int, raw_input().split())
dp = []
for i in range(0, N+1):
	lst = []
	for j in range(0, W+1):
		lst.append(0)
	dp.append(lst)
items = []
for i in range(0, N):
	items.append(map(int, raw_input().split()))
weight = W
for i in range(0, N):
	for w in range(0, W+1):
		if items[i][1] <= w:
			dp[i+1][w] = larger(dp[i][w-items[i][1]]+items[i][0], dp[i][w])
		else: dp[i+1][w] = dp[i][w]

print dp[N][W]


Measured memory_bytes: 22380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            for(int k = j; k < n; k++){
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]){
                    if(l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]){
                        ans++;
                        //cout << i+1 << " " << j+1 << " " << k+1 << endl;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, t = 0;
  string s;
  cin >> n;
  vector<int> v(n);
  vector<string> w(n);
  for(int i = 0; i < n; ++i) cin >> w[i] >> v[i];
  cin >> s;
  bool b = 0;
  for(int i = 0; i < n; ++i){
    if(b) t += v[i];
    else if(w[i] == s) b = 1;
  }
  cout << t << endl;
}


Measured memory_bytes: 256
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        [0, i) の合計
        :param int i:
        """
        ret = 0
        while i > 0:
            ret += self._bit[i - 1]
            i -= i & -i
        return ret

    def __len__(self):
        return self._size


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
N += 1

if N == 1:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()

# # TODO: 繰り返しをなくす
# def test():
#     d = 0
#     ok = True
#     for i in range(N):
#         for _ in range(A[i]):
#             # i より前で cap が 0 以上で一番前のところから取る
#             if d > i:
#                 ok = False
#                 break
#             cap[d] -= 1
#             cap[d + 1:i] += 1
#             counts[d + 1: i + 1] += 1
#             while d < len(cap) and d < 70 and cap[d] <= 0:
#                 d += 1
#         print(counts, cap, d, ok)
#     print(counts.sum())
#     return counts.sum()


# cap = np.ones(N, dtype=int)
# cap[-1] = 0
# # counts = [1] * N
# counts = np.ones(N, dtype=int)


bit = BinaryIndexedTree(size=N + 10)
bit.add(0, 1)
bit.add(N - 1, -1)
A[-1] -= 1

d = 0
ok = True
ans = N
for i in range(N):
    while A[i] > 0:
        # i より前で cap が 0 以上で一番前のところから取る
        if d >= i:
            ok = False
            break
        # a = min(A[i], cap[d])
        a = min(A[i], bit.sum(d + 1))
        A[i] -= a

        # cap[d] -= a
        bit.add(d, -a)
        bit.add(d + 1, a)
        # cap[d + 1:i] += a
        bit.add(d + 1, a)
        bit.add(i, -a)

        # counts[d + 1: i + 1] += a
        ans += a * (i - d)
        while d < N and bit.sum(d + 1) <= 0:
            d += 1

    if not ok:
        break
    # for i in range(len(bit)):
    #     print(bit.sum(i + 1), end=' ')
    # print()
    # print(counts, cap, d, ok)
    # print()
if ok:
    print(ans)
else:
    print(-1)
exit()
# print(counts.sum(), ans)
# test()


Measured memory_bytes: 86504
#include <cstdio>

using namespace std;

int main() {
    int n, t, x = -1e9, i;
    long long ans = 0;
    
    scanf("%d %d", &n, &t);
    
    for (i = 0; i < n; i++) {
        int y;
        
        scanf("%d", &y);
        
        if (y < x + t) ans -= t - y + x;
        ans += t;
        x = y;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


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

int main() {
    int N, distance = 0, i, tmp;
    cin >> N;
    vector < int > vec;
    vec.push_back(0);
    for(i = 0; i < N; i++) {
        cin >> tmp;
        vec.push_back(tmp);
    }
    vec.push_back(0);
    for(i = 1; i <= N + 1; i++)
        distance += abs(vec[i] - vec[i - 1]);

    for(i = 1; i <= N; i++) {
        tmp = distance;
        tmp -= abs(vec[i] - vec[i - 1]) + abs(vec[i] - vec[i + 1]);
        tmp += abs(vec[i - 1] - vec[i + 1]);
        cout << tmp << "\n";
    }
    return 0;
}




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

int main(){
  int s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


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

int main() {
  int A;
  int B;
  cin >> A >> B;
  if (A + B >= A - B && A + B >= A * B) {
    cout << A + B << endl;
  } else if (A - B >= A + B && A - B >= A * B) {
    cout << A - B << endl;
  } else {
    cout << A * B << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    int cnt = 0;
    if(A == 5 && B == 5 && C == 7){
        printf("YES\n");
        return 0;
    }
    if(A == 5 && B == 7 && C == 5){
        printf("YES\n");
        return 0;
    }
    if(A == 7 && B == 5 && C == 5){
        printf("YES\n");
        return 0;
    }
    printf("NO\n");
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A, B = [], []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())

res = False
for sy in range(N - M + 1):
    for sx in range(N - M + 1):
        ok = True
        for dy in range(M):
            y = sy + dy
            a = A[y][sx:sx + M]
            ok = ok and a == B[dy]
        res = res or ok
print("Yes" if res else "No")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

def main(N,M,visited,queue):
    ans = "IMPOSSIBLE"

    for i in queue:
        if visited[i-1] == True:
            ans = "POSSIBLE"
            break
            
    print(ans)

if __name__ == '__main__':
    N, M = map(int, input().split())
    visited,queue = [False]*N, []
    for i in range(M):
        a, b = map(int, input().split())
        if(a==1):
            visited[b-1] = True
        elif(b==N):
            queue.append(a)
    main(N,M,visited,queue)

Measured memory_bytes: 8660
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,t) for(int i = (s); i < (t); i++)

int N, K;

int main()
{
    scanf("%d", &N);
    for(int i = 0; i*4 <= N; i++) {
        if((N-4*i)%7==0) {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");

    return 0;
}


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

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define ll long long

using namespace std;
main(){
  int X;
  scanf("%d",&X);
  printf("%d",(X/500)*1000+((X%500)/5)*5);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    int n,a,bef=-1,cnt=0;
    cin>>n;
    int ans=0;
    lol(i,n){
	cin>>a;
	if(a!=bef){
	    ans+=cnt/2;
	    bef=a,cnt=0;
	}
	cnt++;
    }
    ans+=cnt/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys,queue,math,copy
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]
N = int(input())
A = LI()


c =[0,0,0]
cnt = [0 for _ in range(N)]
for i in range(N):
    cnt[i] = c.count(A[i])
    if cnt[i] == 0:
        print (0)
        exit (0)
    for j in range(3):
        if c[j] == A[i]:
            c[j] += 1
            break
ans = 1
for i in range(N):
    ans = (ans * cnt[i]) % MOD
print (ans)

Measured memory_bytes: 57516
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextStrArray();
  one = Math.sqrt(myconv(myconv(one,0),1));
  if(one % 1 == 0){
     myout("Yes");
  }else{
     myout("No");
  }
}

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

int main() {
    string s; cin >> s;
    bool flag = true;

    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                flag = false;
                break;
            }
        } else {
            if (s[i] == 'R') {
                flag = false;
                break;
            }
        }
    }

    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
k,n=map(int,input().split())
a=list(map(int,input().split()))
ans=10**9
for i in range(n):
    bef=i-1
    af=i+1
    aa=0
    bb=0
    if bef<0:
        aa=a[-1]-a[0]
    else:
        aa=k-(a[i]-a[bef])
    if n-1<af:
        bb=a[-1]-a[0]
    else:
        bb=a[i]+abs(k-a[af])
    if aa<ans:
        ans=aa
    if bb<ans:
        ans=bb
print(ans)

Measured memory_bytes: 77772
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

  int R; cin>>R;
  cout << fixed << setprecision(15) <<  2*R*M_PI<< endl;

  return 0;
}


Measured memory_bytes: 3804
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const R = 100000000

var sc = bufio.NewScanner(os.Stdin)

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func prim() int {
	var u, Minimum, sum int
	var d, p, color [101]int

	for i := 0; i < n; i++ {
		d[i] = R
		p[i] = -1
		color[i] = 0
	}
	d[0] = 0

	for {
		Minimum = R
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != R {
				if d[j] > A[u][j] {
					d[j] = A[u][j]
					p[j] = u
					color[j] = 1
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		if p[i] != -1 {
			sum += A[i][p[i]]
		}
	}
	return sum
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			e := nextInt()
			if e == -1 {
				A[i][j] = R
			} else {
				A[i][j] = e
			}
		}
	}
	fmt.Println(prim())
}



Measured memory_bytes: 1180
/*
 * coder: @SumitRaut
 */
#include <bits/stdc++.h>

using namespace std;

inline void solve() {
    string st;
    cin>>st;
    cout<<st<<(st.back()=='s'?"es\n":"s\n");
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        solve();
    return 0;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

using namespace std;

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

	int n;
	cin >> n;

	int nn = n;
	int res = 999;
	//	while (nn > 0) {
	//		int mod = nn % 10;
	//		int tmp = mod * 111;
	//		if (tmp >= n)
	//			res = min(res, tmp);
	//		nn /= 10;
	//	}
	int i = 1;
	while (1) {
		if (111 * i >= n) {
			res = 111 * i;
			break;
		}
		i++;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int k,a,b;cin>>k>>a>>b;

  rep(i,a,b+1){
    if(i%k==0){
      cout<<"OK"<<ENDL;
      return 0;
    }
  }
  cout<<"NG"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int n;
double x, x2, x3, x4, y, y2, y3, y4;

int main() {
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x, &y, &x2, &y2, &x3, &y3, &x4, &y4 );
		if ( fabs( ( x2 - x ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y ) ) < EPS ) {
			printf( "YES\n" );
		}
		else {
			printf( "NO\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 1204