akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
#mod_a = [i%(10**9 + 7) for i in a]
res = 0
sum_a = sum(a)
b = 0
t = 0
for i in range(0, len(a)-1):
  t = a[i]
  b += a[i]
  res += (sum_a - b)*t%(10**9 + 7)
print(res%(10**9 + 7))



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

int main() {
    ll mod=1e9+7;
    string L;
    cin>>L;
    vector<vector<ll>> dp(L.size(),vector<ll>(2));
    dp[L.size()-1][0]=1;
    dp[L.size()-1][1]=2;
    rep(i,L.size()-1){
        ll p=L.size()-2-i;
        if(L[i+1]=='0'){
            dp[p][0]=dp[p+1][0]*3;
            dp[p][1]=dp[p+1][1];
        }else{
            dp[p][0]=dp[p+1][0]*3+dp[p+1][1];
            dp[p][1]=dp[p+1][1]*2;
        }
        dp[p][0]=(dp[p][0]+mod)%mod;
        dp[p][1]=(dp[p][1]+mod)%mod;
    }
    cout<<(dp[0][0]+dp[0][1]+mod)%mod<<endl;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

    static int ANS = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        int[] an = new int[N];
        boolean[] hasPushed = new boolean[N];
        for (int i = 0; i < N; i++) {
            an[i] = Integer.parseInt(sc.next());
        }

        boolean canComp = true;
        int next = 0;
        for (int i = 0; i < N; i++) {
            if (hasPushed[next]) {
                // 既に押したボタンの場合はループしているので終了する
                canComp = false;
                break;
            }
            next = push(an, next, hasPushed);

            if (next == 1) {
                // ボタン2に到達したので終わる
                break;
            }
        }
        System.out.println(canComp ? ANS : -1);
    }

    private static int push(int[] an, int next, boolean[] hasPushed) {
        ANS++;
        hasPushed[next] = true;
        return an[next] - 1;
    }
}


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



int main() {
	int x,y;
	cin >> x >> y;
	if (x == 2 || y == 2) {
		cout << "No" << endl;
		return 0;
	}
	else if (x == 4 || x == 6 || x == 9 || x == 11) {
		if (y == 4 || y == 6 || y == 9 || y == 11) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (y == 4 || y == 6 || y == 9 || y == 11) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

result = 0
count = 0
last = 0
for a in A:
    if a == last:
        count += 1
    else:
        result += count // 2
        count = 1
        last = a
else:
    result += count // 2
    
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

long long dp[1001][101][10];
bool used[101];

long long solve(int s, int upper, int n) {
    if (n == 0) {
        return s == 0 ? 1 : 0;
    }
    if (upper < 0) {
        return 0;
    }
    if (0 <= dp[s][upper][n]) {
        return dp[s][upper][n];
    }
    long long ret = 0;
    for (int i=upper; i>=0; --i) {
        if ( ! used[i] && 0 <= s-i) {
            used[i] = true;
            ret += solve(s-i, i-1, n-1);
            used[i] = false;
        }
    }
    return dp[s][upper][n] = ret;
}

int main() {
    int n, s;
    for (int i=0; i<1001; ++i) {
        for (int j=0; j<101; ++j) {
            for (int k=0; k<10; ++k) {
                dp[i][j][k] = -1;
            }
        }
    }
    memset(used, false, sizeof used);
    while (cin >> n >> s, n) {
        cout << solve(s, 100, n) << endl;
    }
    return 0;
}

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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
    int a,b,c;
    int ans=0;
    cin>>a>>b>>c;
    int m;

    while(a!=b||b!=c){
        m=max(max(a,b),c);
        if(m>a){
            ans+=(m-a)/2;
            a=m-(m-a)%2;
        }
        if(m>b){
            ans+=(m-b)/2;
            b=m-(m-b)%2;
        }
        if(m>c){
            ans+=(m-c)/2;
            c=m-(m-c)%2;
        }

        if(a==b&&b==c)break;
        if(a==b){a++;b++;ans++;}
        else if(b==c){b++;c++;ans++;}
        else {a++;c++;ans++;}
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s = in.nextLine().trim();
        int n = s.length();
        for(int i=0;i<n;i++) out.write("x");out.write("\n");
        
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 20820
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

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

ll func(ll x){
  return (x+1)*x/2;
}

int main()
{
  ll x;
  cin >> x;
  ll ans;

  for(ll i = 1; i < 100000; i++){
    if(func(i) >= x){
      ans = i;
      break;
    }
  }

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

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

using namespace std;

#define ll long long




void solve() {

	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(10);
	cout << (w * h) / 2.0 << " ";
	if(x == w / 2.0 && y == h / 2.0) {
		cout << 1;
	}
	else {
		cout << 0;
	}

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3744
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    sort(a, a+N, greater<int>());
    int tmp = N - 1;
    rep(i, N) {
        if (tmp != a[i]) {
            cout << 0 << endl;
            return 0;
        }
        if (i % 2 == 1) tmp -= 2;
    }
    int ans = 1;
    rep(i, N/2) ans = (ans * 2) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
vector<p> v;
priority_queue<int> q;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=0;i<n;i++){
        int temp1, temp2;
        cin >>temp1>>temp2;
        v.push_back(make_pair(temp1,temp2));
    }
    sort(ALL(v));
    ll ans=0;
    int  nowz=0;
    for(int i=1;i<=m;i++){
        while(v[nowz].first<=i&&nowz<v.size()){
            q.push(v[nowz].second);
            nowz++;
        }
        if(!q.empty()){
        ans+=q.top();
        q.pop();
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    string s="NO";
    while(cin>>a>>b>>c){
        for(int i=1;i<=b;i++){
            if((a*i)%b==c){
                s="YES";
                break;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
//typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n,m;cin>>n>>m;
  int ans = min((int)n,m/(int)2);
  m -= n*2;
  ans += max((int)0,m/(int)4);
  cout << ans << endl;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

vector<vector<int> > G;

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    deque<int> path;
    vector<bool> visited(n, false);
    path.push_front(0);
    visited[0] = true;
    path.push_back(G[0].back());
    visited[G[0].back()] = true;

    bool updated;
    int end_point;
    while (true) {
        updated = false;
        end_point = path.front();
        rep(i, G[end_point].size()) {
            if (! visited[G[end_point][i]]) {
                visited[G[end_point][i]] = true;
                path.push_front(G[end_point][i]);
                updated = true;
                break;
            }
        }
        if (! updated) break;
    }

    while (true) {
        updated = false;
        end_point = path.back();
        rep(i, G[end_point].size()) {
            if (! visited[G[end_point][i]]) {
                visited[G[end_point][i]] = true;
                path.push_back(G[end_point][i]);
                updated = true;
                break;
            }
        }
        if (! updated ) break;
    }

    cout << path.size() << endl;
    stl_rep(itr, path) {
        cout << *itr + 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 6784
import itertools


N = int(input())
P = tuple(int(i) for i in input().split())
Q = tuple(int(i) for i in input().split())


for i, n in enumerate(itertools.permutations(range(1, N+1), N)):
    if n == P:
        a = i
    if n == Q:
        b = i

ans = abs(b - a)
print(ans)


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

using namespace std;

struct Knapsack {
    int weight, value;
    Knapsack () : weight(-1) , value(-1) {}
    Knapsack (int w, int v) : weight(w), value(v) {}
};

long long getMaxValue (vector <Knapsack> &knapsack, int capacity) {
    if (knapsack.empty()) {
        return 0;
    }
    int n = knapsack.size();
    vector <long long> dp(capacity + 1);
    
    for (int i = 0; i < n; ++i) {
        int currWeight = knapsack[i].weight;
        int currValue = knapsack[i].value;
        vector <long long> curr(capacity + 1);
        for (int c = 1; c <= capacity; ++c) {
            if (c >= currWeight) {
                curr[c] = max(dp[c - currWeight] + currValue, dp[c]);
            } else {
                curr[c] = dp[c];
            }
        }
        dp = curr;
    }
    return dp.back();
}

int  main () {
    int n = 0, capacity = 0;
    scanf("%d%d", &n, &capacity);
    vector <Knapsack> knapsack;
    for (int i = 0; i < n; ++i) {
        int w, v;
        scanf("%d%d", &w, &v);
        knapsack.emplace_back(Knapsack{w, v});
    }
    printf("%llu\n", getMaxValue(knapsack, capacity));
    return 0;
}

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

int main(){ 
    int n,t,a;
    cin>>n>>t>>a;
    double c=1000000;
    int d=0;
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        c=min(c,abs(a-t+b[i]*0.006));
    }
    for(int i=0;i<n;i++){
        if(abs(c-abs(a-t+b[i]*0.006))<0.01){
        d=i;
        }
    }
    cout <<d+1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{	
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ma = max({a,b,c});
	cout << a+b+c-ma+ma*pow(2,k) << endl;
	return 0;
}

Measured memory_bytes: 512
<?php
$param =array(trim(fgets(STDIN)), trim(fgets(STDIN)), trim(fgets(STDIN)), trim(fgets(STDIN)));
$amount = 0;
$stay = $param[1];
if ($stay > $param[0]) {
    $stay = $param[0];
}
for ($i = 0; $i < $stay; $i++) {
    $amount += $param[2];
}
for ($i = $param[1]; $i < $param[0]; $i++) {
    $amount += $param[3];
}
echo $amount;

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

// ABC141Eをローリングハッシュで解く
// 高速版

struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<ll> hash1, hash2, power1, power2;

	RollingHash(const string &S) {
		int n = (int)S.size();
		hash1.assign(n+1, 0);
		hash2.assign(n+1, 0);
		power1.assign(n+1, 1);
		power2.assign(n+1, 1);
		for(int i=0;i<n;i++) {
			hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i+1] = (power1[i] * base1) % mod1;
			power2[i+1] = (power2[i] * base2) % mod2;
		}
	}

	// get hash of S[left: right) (0から見る)
	inline pair<ll,ll> get(int l, int r) const {
		ll res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
		if(res1 < 0) res1 += mod1;
		ll res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
		if(res2 < 0) res2 += mod2;
		return {res1, res2};
	}

	// S[a:]とS[b:]のLCP(最長共通接頭辞)を求める
	inline int getLCP(int a, int b) const {
		int len = min((int)hash1.size() - a ,(int)hash1.size() - b);
		int low = 0, high = len;
		while(high - low > 1) {
			int mid = (high + low) >> 1;
			if(get(a, a + mid) == get(b, b + mid)) low = mid;
			else high = mid;
		}
		return low;
	}
};

signed main() {
	int N; string S;
	cin >> N >> S;
	RollingHash rh(S);

	// 二分探索判定
	auto check = [&](int d) -> bool {
		map<pair<ll,ll>,int> mp;
		for(int i=0;i+d<=N;i++) {
			auto p = rh.get(i, i+d);
			if(mp.count(p)) {
				if(i - mp[p] >= d) return true;
			}
			else mp[p] = i;
		}
		return false;
	};
	
	int left = 0, right = N / 2 + 1;
	while(right - left > 1) {
		int mid = (left + right) >> 1;
		if(check(mid)) left = mid;
		else right = mid;
	}
	cout << left << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<pll> ab(n);
    for(int i = 0; i < n; i++){
        cin >> ab[i].second >> ab[i].first;
    }
    sort(all(ab));
    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += ab[i].second;
        if(sum > ab[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;

}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main{
	int x;
	public void solve(){
		Scanner sc = new Scanner(System.in);
		x=sc.nextInt();
		System.out.println(x*x*x);
	}
	public static void main (String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int> >

template <class X> void print(X Target){ cout << Target << '\n'; }

char route(char x, int po)
{
  char res = x;

  switch (x){
    case 'A':
      res = po ? 'Y' : 'X';
      break;
    case 'B':
      res = po ? 'X' : 'Y';
      break;
    case 'W':
      res = po ? 'Y' : 'B';
      break;
    case 'X':
      res = po ? 'Z' : '_';
      break;
    case 'Y':
      res = po ? '_' : 'X';
      break;
    case 'Z':
      res = po ? 'B' : 'W';
      break;
  }

  return (res);
}

signed main()
{
  ios::sync_with_stdio(false);
  char p[101];
  
  while (cin >> p, p[0] != '#'){
    char ans = route('A', p[0] - '0');
    for (int i = 1; p[i] != '\0'; i++) ans = route(ans, p[i] - '0');
    print(ans == 'B' ? "Yes" : "No");
  }

  return (0);
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <utility>
#include <unordered_set>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

class UnionFind {
public:
  vector<int> data; // sizeとparを同時に管理する
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  void unite(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px != py) {
      if (data[py] < data[px]) swap(px, py);
      data[px] += data[py]; data[py] = px;
    }
  }

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

  int size(int x) {
    return -data[find(x)];
  }

  int count() {
    // 連結成分の個数
    unordered_set<int> pars;
    for (int i = 0; i < data.size(); ++i) {
      pars.insert(find(i));
    }
    return pars.size();
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> la(n);
  for (int &a: la) cin >> a;
  UnionFind uf(n);

  /* dataとsizeの確認. data[i]が負の点はroot */
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }
  int l = uf.count();
  if (l == 1) {
    cout << 0 << endl;
    return 0;
  }
  if ((l-1)*2 > n) {
    cout << "Impossible" << endl;
    return 0;
  }

  map<int, vector<int>> best;
  for (int i = 0; i < n; ++i) { 
    int par = uf.find(i);
    best[par].push_back(la[i]);
  }
  ll ans = 0;
  vector<int> remain;
  for (auto it: best) {
    int par = it.first;
    sort(best[par].begin(), best[par].end());
    ans += best[par][0];
    for (int i = 1; i < best[par].size(); ++i) {
      remain.push_back(best[par][i]);
    }
  }
  sort(remain.begin(), remain.end());
  for (int i = 0; i < l-2; ++i) {
    ans += remain[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 7076
package main

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

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type node struct {
	score    int
	children []int
	parent   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sp := strings.Split(sc.Text(), " ")
	N, _ := strconv.Atoi(sp[0])
	Q, _ := strconv.Atoi(sp[1])

	tree := make([]node, N+1)
	for i := 0; i < N-1; i++ {
		sc.Scan()
		sp := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(sp[0])
		b, _ := strconv.Atoi(sp[1])
		tree[a].children = append(tree[a].children, b)
		tree[b].children = append(tree[b].children, a)
	}
	for i := 0; i < Q; i++ {
		sc.Scan()
		sp := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(sp[0])
		b, _ := strconv.Atoi(sp[1])
		tree[a].score += b
	}
	ans := make([]int, N+1)
	queue := []int{1}
	for len(queue) > 0 {
		q := queue[0]
		queue = queue[1:]
		node := tree[q]

		ans[q] = ans[node.parent] + node.score
		for _, n := range node.children {
			if n == node.parent {
				continue
			}
			tree[n].parent = q
			queue = append(queue, n)

		}
	}
	for i := 1; i <= N; i++ {
		fmt.Print(ans[i], " ")
	}
	fmt.Println()
}


Measured memory_bytes: 31360
N = int(input())

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

last = H[0] - 1
for i in range(N):
    h = H[i];
    if i==0:
        continue
    if h == last:
        last = h
    elif h >= last + 1:
        last = h - 1
    else:
        print('No')
        exit()

print('Yes')
    



Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x( N ), y( M );
    for( auto &a : x )
    {
        cin >> a;
    }
    for( auto &b : y )
    {
        cin >> b;
    }
    x.emplace_back( X );
    y.emplace_back( Y );
    int xmax = *max_element( ALL( x ) ), ymin = *min_element( ALL( y ) );
    cout << ( xmax < ymin ? "No War" : "War" ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;


bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

struct tree {
	queue<lli> leaf;
	lli num;
};

Tree t[200001];

void dfs(lli n, lli num) {
	t[n].num += num;
	while (!t[n].leaf.empty()) {
		dfs(t[n].leaf.front(), t[n].num);
		t[n].leaf.pop();
	}

}
int main() {
	lli n,k,ans=0;
	cin >> n >> k;
	rep0(i,n){
		lli temp;
		cin >> temp;
		if(temp>=k)ans++;
		}
		cout << ans;
}


Measured memory_bytes: 136192
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;
int main() {
    int N;
    cin >> N;
    int P[50];
    rep(i, 0, N) { cin >> P[i]; }
    int count = 0;
    rep(i, 0, N) {
        if(P[i] != i + 1) {
            count++;
        }
    }
    if(count == 0 || count == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

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

  map<string, ll> m;

  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;

    m[s]++;
  }

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

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

    cout << (a-1)*(b-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = (int)2e5+5;
int cnt[N];
int ara[N];
ll bal[N];

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        ara[ i ] = x;
        cnt[ x ]++;
    }
    ll ans = 0LL;
    for(int i = 1; i < N; i++){
        ans+=(1LL * cnt[i] * (cnt[i]-1) / 2);
    }
    for(int i = 1; i <= n; i++){
        int x = ara[i];
        ll t = max( 0LL ,1LL * cnt[x] * (cnt[x]-1) / 2 );
        ll tt = max(0LL , 1LL * (cnt[x] - 1 )  * (cnt[x]-2) / 2 );
        bal[ i ] = ans - (t-tt);
    }
    for(int i = 1; i <= n; i++){
        cout << bal[i] << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int a, b, c;
    cin>>a>>b>>c;
    if ((a == 5 && b == 5 && c == 7) ||
        (a == 5 && b == 7 && c == 5) ||
        (a == 7 && b == 5 && c == 5)) {
            cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif


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

#endif

void solve(){
    int N;
    cin >> N;
    
    int ans = (N+1)/2;
    cout << ans << endl;
}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


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

int main() {
  int n,t;
  cin >> n;
  t = 0;
  vector<int> w(n);
  vector<int> s(n-1);
  for(int i=0;i<n;i++){
    cin >> w.at(i);
    t += w.at(i);
  }
  
  for(int i=0;i<n-1;i++){
    int k=0;
    for(int j=0;j<=i;j++){
      k += w.at(j);
    }
    s.at(i) = max(t - 2*k, 2*k -t);
  }
  
  sort(s.begin(), s.end());
  cout << s.at(0) << endl;
}


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	string s;
	cin >> s;
	cout << ((s[2] == s[3] && s[4] == s[5]) ? "Yes\n" : "No\n");
}

int main() {
	IOS;
	//io_set();
	ll tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

int dx[] = { 0, 1, 0, -1};
int dy[] = {-1, 0, 1,  0};

int main()
{
  std::string S;
  std::cin >> S;
  int i = 0, j = S.size() - 1;
  auto func = [&S](int i , int j)
  {
    bool ans = true;
    while(i < j)
    {
      if(S[i] != S[j])
      {
        ans = false;
        break;
      }
      ++i;--j;
    }
    return ans;
  };
  bool ans = func(0, S.size()-1);
  ans &= func(0, (S.size()-1)/2-1);
  ans &= func((S.size()+3)/2-1, S.size() - 1);
  std::cout << (ans ? "Yes" : "No") << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
	
	char A[1200]={0}, B[1200]={0};
	char C[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
	char D[] = {"abcdefghijklmnopqrstuvwxyz"};
	
	gets(A);
	
	for(int i = 0; i < 1200; i++){
		for(int j = 0; j < 26; j++){
			if(A[i] == C[j]){
				B[i] = D[j];
				break;
			}
			else if(A[i] == D[j]){
				B[i] = C[j];
				break;
			}
			else{
				//printf("%c = %c \n",B[i], A[j]);
				B[i] = A[i];
			}
		}
	}
	printf("%s\n", B);
  	return 0;
}

Measured memory_bytes: 920
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    int sum2 = 0;
    rep(i,n){
        sum2 += a[i];
        if(sum2*2 >= sum){
            cout << min(abs(sum-sum2*2),abs(sum-sum2*2+a[i]*2)) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

const int mm = (int)(1e5) + 5;
int ac[mm][3], dp[mm][3];
signed main()
{
    int n;
    sl(n);
    fin(i, n) slll(ac[i][0], ac[i][1], ac[i][2]);

    ford(i, n) {
        fin(p, 3) fin(o, 3) if (p != o) {
            chmax(dp[i][p], dp[i+1][o] + ac[i][o]);
        }
    }

    pl(max(max(dp[0][0], dp[0][1]), dp[0][2]));
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> s(n+1, 0);
    rep(i, m){
        int l, r;
        scanf("%d%d", &l, &r);
        ++s[l-1];
        --s[r];
    }
    partial_sum(s.begin(), s.end(), s.begin());
    int ans = 0;
    rep(i, n)if(s[i] == m) ++ans;
    printf("%d\n", ans);
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
        public static void main(String[] args){
                try(Scanner sc = new Scanner(System.in)){
                        int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
                        if(A <= C && C <= B){
                                System.out.println("Yes");
                        }else{
                                System.out.println("No");
                        }
                }
        }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
         int i,r1=0,r2=0,r3=0;
         string s,a,y;
         cin>>s;
         a=s;
         reverse(s.begin(),s.end());
         if(a==s)r1=1;
         string x="";
         for(i=0;i<(a.size()-1)/2;i++)
         {
                  x=x+a[i];
         }
         y=x;
         reverse(x.begin(),x.end());
         if(y==x)r2=1;
         string b="";
         for(i=((a.size()+3)/2)-1;i<a.size();i++)
         {
                 b=b+a[i];
         }
         string c=b;
         reverse(b.begin(),b.end());
         if(c==b)r3=1;
         if(r1==1&&r2==1&&r3==1)cout<<"Yes"<<endl;
         else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const long long NR=210000;
long long a[NR],n;
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	long long l=1,r=1,tmp=0,sum=0;
	while(r<=n)
	{
		while((a[r]^tmp)==(a[r]+tmp)&&r<=n)
		{
			tmp^=a[r];
			r++;
		}
		if(r!=n+1)
		{
			sum+=r-l;
		}
		else
		{
			sum+=(r-l)*(r-l+1)/2;
		}
		tmp^=a[l];
		l++;
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(void)
{
  int n, m;
  cin >> n >> m;
  int i;
  int si, ci;
  vector<int> ansv;
  for (i = 0; i < n; i++) ansv.push_back(-1);
  for (i = 0; i < m; i++) {
    cin >> si >> ci;
    if (ansv[si - 1] == -1 | ansv[si - 1] == ci) ansv[si - 1] = ci;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    if (ansv[0] == -1) ansv[0] = 0;
  }
  else {
    if (ansv[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ansv[0] == -1) ansv[0] = 1;
  }
  for (i = 1; i < n; i++) if (ansv[i] == -1) ansv[i] = 0;
  int ansi = 0;
  for (i = 0; i < n; i++) {
    ansi += ansv[i] * pow(10 , n - i - 1);
  }
  cout << ansi << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


double toRad( double deg ) {
    return deg / 180.0 * M_PI;
}

double sq( double x ) {
    return x * x;
}

int solve( double a, double b, double c, double d ) {
    a = toRad(a), b = toRad(b), c = toRad(c), d = toRad(d);
    double R = 6378.1;
    double P[2][3];
    P[0][0] = R * cos(a) * cos(b);
    P[0][1] = R * cos(a) * sin(b);
    P[0][2] = R * sin(a);
    P[1][0] = R * cos(c) * cos(d);
    P[1][1] = R * cos(c) * sin(d);
    P[1][2] = R * sin(c);
    double D = sqrt( sq( P[0][0] - P[1][0] ) + sq( P[0][1] - P[1][1] ) + sq( P[0][2] - P[1][2] ) );
    double a0 = ( sq(R) + sq(R) - sq(D) ) / ( 2 * sq(R) );
    double a1 = acos(a0);
    return (int)( 1e-9 + 0.5 + M_PI * R * ( a1 / M_PI ) );
}

int main() {
    double a, b, c, d;
    while ( cin >> a >> b >> c >> d ) {
        if ( a == -1 && b == -1 && c == -1 && d == -1 ) break;
        cout << solve( a, b, c, d ) << endl;
    }
    return 0;
}

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

long long n,h,a[200200];

int main(){
	cin >> h >> n;
  long long sum = 0;
  for(int i = 0; i < n; i++){
  	cin >> a[i];
    sum += a[i];
  }
  if(sum >= h) cout << "Yes";
  else cout << "No";
}

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

int main() {
  int x, y;
  cin >> x >>y;
  vector<int> vec(13);
  vec = {0,1,3,1,2,1,2,1,1,2,1,2,1};

  if (vec.at(x) == vec.at(y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


}

Measured memory_bytes: 3628
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
prev = 40

for i in range(n):
    ans += bl[al[i]-1]
    if al[i] - prev == 1:
        ans += cl[prev-1]

    prev = al[i]

print(ans)


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var D = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var M = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dict = new Dictionary<int, int>();
            for (var i = 0; i < N; i++) {
               if (dict.ContainsKey(D[i])) {
                  dict[D[i]]++;
               } else {
                  dict[D[i]] = 1;
               }
            }
            
            for (var i = 0; i < M; i++) {
               if (dict.ContainsKey(T[i])) {
                  if (dict[T[i]] == 0) {
                     Console.WriteLine("NO");
                     return;
                  }
                  dict[T[i]]--;
               } else {
                  Console.WriteLine("NO");
                  return;
               }
            }
            
            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 52856
#include<bits/stdc++.h>
#define N 100005
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
using namespace std;
int A,B,M,a[N],b[N],c[N],mina,minb;
int minn(int a, int b){
    if (a<b) return a; else return b;
}
int main(){
 //   //freopen("B.inp","r",stdin);
  //  freopen("B.out","w",stdout);
    cin>>A>>B>>M;
    mina=10*N; minb=10*N;
    FOR(i,1,A) cin>>a[i],mina=minn(mina,a[i]);
    FOR(i,1,B) cin>>b[i],minb=minn(minb,b[i]);
    int res=mina+minb;
    FOR(i,1,M){
        int x,y,c;
        cin>>x>>y>>c;
        res=minn(res,a[x]+b[y]-c);
    }
    cout<<res;
}


Measured memory_bytes: 1024