akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h;
  long long count = 0;
  long prev = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (i == 0) {
      prev = x;
    } else {
      if (prev <= x) {
        prev = x;
      } else {
        count += prev - x;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    int a,b;
    char op;

    while(1)
    {
        cin >> a >> op >> b;
        if(op == '+')
        {
            cout << a+b << endl;
        }
        else if(op == '-')
        {
            cout << a-b << endl;
        }
        else if(op == '*')
        {
            cout << a*b << endl;
        }
        else if(op == '/')
        {
            cout << a/b << endl;
        }
        else if(op == '?')
        {
            break;
        }
        else
        {
            /* code */
        }
    }   
    return 0;
}


Measured memory_bytes: 3096
#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++)

int main(){
    int N;
    cin >> N;
    int a[N];
    long long H[N];
    rep(i, N){
        cin >> H[i];
        a[i] = 0;
    }
    int j = 0;
    a[0] = 0;
    rep(i, N-1){
        if(H[i] < H[i+1]){
            j++;
            a[j] = i+1;
        }
    }
    a[j+1] = N;
    priority_queue<int> que;
    rep(i, j+1){
        que.push(a[i+1] - a[i] - 1);
    }
    cout << que.top() << endl;
}

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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

template<class T>
inline bool change_max(T&a, const T&b){
  if(b > a){
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool change_min(T&a, const T&b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}


int main(){
  int n; cin >> n;
  vector<int> v(n), idx(n);
  
  for(int&e:v){
    cin >> e;
    e--;
  }
  for(int i = 0; i < n; ++i){
    idx[v[i]] = i;
  }

  set<int> st;

  ll ans = 0;
  for(int i = n-1; i >= 0; --i){
    st.insert(idx[i]);
    ll a = -1, b = -1, c = n, d = n;
    auto it = st.find(idx[i]);

    ll x = *it;
    if(it != st.begin()){
      it--;
      b = *it;
      if(it != st.begin()){
	it--;
	a = *it;
      }
    }
    it = st.find(idx[i]);
    it++;
    if(it != st.end()){
      c = *it;
      it++;
      if(it != st.end()){
	d = *it;
      }
    }
    
    cerr << a << ' ' << b << ' ' << idx[i] << ' ' << c << ' ' << d << endl;

    ans += ((b - a) * (c - idx[i]) + (idx[i] - b) * (d - c)) * (i + 1);
  }

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


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

int main() {
  string s;
  cin >> s;
  while(true){
    if(s.at(0) == s.at(1) && s.at(1) == s.at(2) && s.at(2) == s.at(0)){
      cout << s << endl;
      break;
    }
    int x = stoi(s);
    x++;
    s = to_string(x);
    }
 }


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[n];
        int[][] bc = new int[m][2];
        long sum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        Arrays.sort(a);
        for (int i = 0; i < m; i++) {
            bc[i][0] = scanner.nextInt();
            bc[i][1] = scanner.nextInt();
        }

        Arrays.sort(bc, (t, b) -> Integer.compare(t[1], b[1]));

        int k = 0;
        for (int i = m-1; i >= 0; i--) {
            if(k>a.length-1){
                break;
            }
            if(a[k] >= bc[i][1]){
                break;
            }
            for (int j = 0; j < bc[i][0]; j++) {
                if (a[k] < bc[i][1]) {

                    a[k++] = bc[i][1];
                    if(k>a.length-1){
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        for(int i = 0 ; i < n ; i++){
            sum+=a[i];
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 97960
#include<bits/stdc++.h>
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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

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

ll f(ll A, ll B, ll C){
    ll ans = B/C - A/C;
    if(A%C==0){
        ans++;
    }
    return ans;
}


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

    // input
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    if(C>D) swap(C, D);

    ll all = B-A+1;

    ll c_de_wareru = f(A, B, C);
    ll d_de_wareru = f(A, B, D);

    // pn(all);
    // pn(c_de_wareru);
    // pn(d_de_wareru);

    ll E = lcm(C, D);
    ll c_d_de_wareru = f(A, B, E);

    // if(D%C==0){
    //     c_d_de_wareru = c_de_wareru;
    // }else{
    //     ll E = C*D;
    //     c_d_de_wareru = 
    //     // pn(E);
    //     // pn(c_d_de_wareru);
    // }

    ll ans = all - c_de_wareru - d_de_wareru + c_d_de_wareru;
    p(ans);


    
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	ll n, k, x = 0, y = 0;

	cin >> n >> k;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 1) {
		rep(i2, i + 1, n)if (a[i] > a[i2])x++;
	}
	rep(i, 0, n){
		rep(i2, 0, n) {
			if (a[i] > a[i2])y++;
		}
	}
	printf("%lld\n", ((y * ((k - 1) * k / 2 % mod)) % mod + x * k % mod) % mod);
	return 0;
}


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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


int main() {

	int n;
	cin >> n;
	int c[n - 1], s[n - 1], f[n - 1];
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	rep(sx , n - 1) {
		ll sec = 0;
		for(int i = sx; i < n - 1; i++) {
			if (sec <= s[i]) {
				sec = s[i] + c[i];
				continue;
			}
			ll next = sec % f[i];
			if (next != 0) {
				next = f[i] - sec % f[i];
			}
			sec += next + c[i];
		}
		cout << sec << endl;
	}
	cout << 0 << endl;


	return 0;
}

Measured memory_bytes: 888
// problem: "https://atcoder.jp/contests/abc150/tasks/abc150_d"

#include<bits/stdc++.h>
#define ll unsigned long long

using namespace std;

ll GCD(ll a,ll b)
{
    if(a < b)
        return GCD(b,a);

    if(b == 0)
        return a;

    return GCD(b,a%b);
}

ll LCM(vector<ll>&V,ll i,ll lcm)
{
    return (V[i]*lcm) / GCD(V[i],lcm);      // define
}

ll SCM(vector<ll>&V,ll n,ll m)
{
    ll i;
    for(i=0;i!=n;i++)
        V[i] = V[i]/2;


    ll lcm = V[0],l;
    for(i=0;i!=n;i++)
    {
        l = LCM(V,i,lcm);     // define

        if((l/lcm)%2 == 0 || (l/V[i])%2 == 0 || l > m)
            return 0;

        lcm = l;
    }

    ll M = (m-(m%lcm))/lcm;

    return M/2 + M%2;
}

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

    vector<ll>V;
    ll i,x;
    for(i=0;i!=n;i++)
    {
        cin>>x;
        V.push_back(x);

        if(x%2 == 1)
        {
            cout<<0;
            exit(0);
        }
    }

    cout<<SCM(V,n,m);       //define

    return 0;
}


Measured memory_bytes: 1400
while(1):
    n, r = map(int, input().split())
    if n == r == 0:
        break
    N = [n-i for i in range(n)]
    for i in range(r):
        p, c = map(int, input().split())
        N = N[p-1:p-1+c] + N[:p-1] + N[p-1+c:]
    print(N[0])


Measured memory_bytes: 5620
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static CompareInfo ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        private static int Compare(string a, string b) { return ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal); }

        static long Solve(int N, int K)
        {
            long sum = 0;
            for (int i = K; i <= N + 1; ++i)
            {
                long min = Math.BigMul(i - 1, i) / 2;
                long max = Math.BigMul(N * 2 - i + 1, i) / 2;
                sum += max - min + 1;
                sum %= 1000000007;
            }
            return sum;
        }

        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1]));
        }
    }
}


Measured memory_bytes: 27548
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N,K;
	cin >> N >> K;
	vl A(N);
	FOR(i,0,N)cin >> A[i];
	ll ans = 0;
	ll counter[60] = {0};
	FOR(i,0,N){
		FOR(j,0,60){
			if(A[i]&((ll)1<<j)){
				counter[j]++;
			}
		}
	}
	REP(i,0,60){
		if((ll)((ll)1<<i) > K){
			ans += counter[i] * ((ll)((ll)1<<i));
		}
		else{
			if(N-counter[i] > counter[i]){
				ans += (N - counter[i]) * ((ll)((ll)1<<i));
				K -= (ll)((ll)1 << i);
			}
			else{
				ans += counter[i] * ((ll)((ll)1<<i));
			}
		}
	}
	cout << ans << endl;
}

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

int main(void) {
    int N, ans=0;
    string S;
    cin >> N >> S;

    for(int i=0; i<10; i++){
      for(int j=0; j<10; j++){
        for(int k=0; k<10; k++){
          bool i_flag = true;
          bool j_flag = true;
          bool k_flag = true;
          for(int l=0; l<N; l++){
            if(i_flag){
              if(S[l]-'0'==i){
                i_flag = false;
              }
            }
            else{
              if(j_flag){
                if(S[l]-'0'==j)
                  j_flag = false;
              }
              else{
                if(k_flag){
                  if(S[l]-'0'==k){                
                    k_flag = false;
                    ans++;
                    break;
                  }
                }
              }
            }
          }
         }
      }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		
		
		int n = Integer.parseInt(sc.readLine());
		
		//
		LinkedList<Integer> ll = new LinkedList<Integer>();
		
		for(int i=0;i<n;i++)
		{
				String[] str = sc.readLine().split(" ");

				
				if(str[0].equals("insert"))
				{
					ll.addFirst(Integer.parseInt(str[1]));
				}
				
				if(str[0].equals("delete"))
				{
					int index = ll.indexOf(Integer.parseInt(str[1]));
					if(index!=-1)
						ll.remove(index);
					
				}
				
				if(str[0].equals("deleteFirst"))
				{
					ll.pollFirst();
				}
				
				if(str[0].equals("deleteLast"))
				{
					ll.pollLast();
				}
	
				
			}
			
		
//		for(int i=0;i<ll.size();i++)
//		{
//			if(i==ll.size()-1)
//				out.print(ll.get(i));
//			else
//				out.print(ll.get(i)+" ");
//		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(ll.poll());
		for(Integer s:ll)
		{
			sb.append(" ");
			sb.append(s);
		}
		out.write(sb.toString());
		out.println();
		sc.close();
		out.close();
		
	}
}



Measured memory_bytes: 204760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    string str;
    cin>>n;
    while(n--){
        cin>>str;
        int lev=0,level=0,i,last=0;
        string num;
        for(i=0;i<str.length();i++)
            if(str[i]!='[')
                break;
        level=i;
        vector<vector<int> >vec;
        vector<int>v,las;
        vec.resize(level,v);
        las.resize(level,0);
        for(int i=0;i<str.length();i++){
            if(str[i]=='[')
                lev++;
            else if(str[i]==']'){
                if(lev==level){
                    last = stoi (num);
                    vec[lev-1].push_back(last);
                }
                else{
                    int tem=0;
                    vector<int>te;
                    int temp=0;
                    for(;las[lev-1]<vec[lev].size();las[lev-1]++){
                        te.push_back(vec[lev][las[lev-1]]);
                        temp++;
                    }
                    sort(te.begin(),te.end());
                    for(int ii=0;ii<(temp+1)/2;ii++)
                    {
                        if(lev==level-1)tem+=(te[ii]+1)/2;
                        else tem+=te[ii];
                    }
                    vec[lev-1].push_back(tem);
                }
                num="";
                lev--;
            }
            else
                num+=str[i];
        }
        cout<<vec[0][0]<<endl;
    }
}

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

int main(){
	int dataset,n,cost;
	//bool zaiko[40000];
	bool zaiko[2][40000];
	string books;
	cin >> dataset;
	//int cost;
	for(int i=0;i<dataset; i++){
		cin >> n;
		cin >> books;


		//{ÌÝÉðf[^\¢Éüêé
		zaiko[0][0] = (books[0] == 'Y' ? true: false);
		zaiko[0][n] = (books[2*n-1] == 'Y' ? true: false);
		zaiko[1][0] = (books[2*n] == 'Y' ? true: false);
		zaiko[1][n] = (books[4*n-1] == 'Y' ? true: false);
		//		cout << zan[0][0] << endl;
		for(int j=1;j<n;j++){
			if(books[2*j-1] == 'N' && books[2*j] == 'N'){
				zaiko[0][j] = false;
			}
			else{
				zaiko[0][j] = true;
			}
		}
		for(int j=1;j<n;j++){
			if(books[2*n+2*j-1] == 'N' && books[2*n+2*j] == 'N'){
				zaiko[1][j] = false;
			}
			else{
				zaiko[1][j] = true;
			}
		}
		//±±ÜÅ

		bool flag[2] = {false,false};
		int check = -1;
		cost = n;
		for(int k=0;k<=n;k++){
			//Ðª êÎ«·
			cost += static_cast<int>(zaiko[0][k])+static_cast<int>(zaiko[1][k]);
			
			if(!flag[0]){
				if(zaiko[0][k] || zaiko[1][k]){
					flag[0] = !flag[0];
					if(!zaiko[0][k] && check != k){
						cost++;
						check = k;
					}
				}
			}

			if(!flag[1]){
				if(zaiko[0][n-k] || zaiko[1][n-k]){
					flag[1] = !flag[1];
					if(!zaiko[0][n-k] && check != n-k){
						cost++;
						check = n-k;
					}
				}
			}

		}

		cout << cost << endl;

/*
		for(int j=0;j<n+1;j++){
			cout << zaiko[0][j];
		}
		cout << endl;
		for(int j=0;j<n+1;j++){
			cout << zaiko[1][j];
		}
		cout << endl << endl;*/
		//bool sflag = zaiko[0] || zaiko[2*n];
		//bool eflag = zaiko[2*n-1] || zaiko[4*n-1];


		//for(int j=1;j<n;j++){
		//	if(!sflag){
		//		sflag = int(zaiko[2*j-1] || zaiko[2*j]) + int(zaiko[2*j-1+2*n] || zaiko[2*j+2*n]);
		//	}
		//	if(!eflag){
		//		sflag = int(zaiko[2*j-1] || zaiko[2*j]) + int(zaiko[2*j-1+2*n] || zaiko[2*j+2*n]);
		//	}
		//	if(sflag){
		//		cost += int(zaiko[2*j-1] || zaiko[2*j]) + int(zaiko[2*j-1+2*n] || zaiko[2*j+2*n]);
		//	}
		//	if(!flag){

		//	}

		//}
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int N, M, L;
ll K[2048];
ll SSum[100001];
ll memo[2048][2048];

ll pls(int r, int l)
{
	return ((SSum[r] - SSum[l]) / (ll)L);
}

ll saveSayaka(int l, int r)
{
	int next = max(l, r) + 1;
	
	if (memo[l][r] >= 0){
		return (memo[l][r]);
	}
	
	if (next == N - 1){
		return (pls(K[next], K[l] - 1) + pls(K[next], K[r] - 1));
	}
	
	ll left = saveSayaka(next, r) + pls(K[next], K[l] - 1);
	ll right = saveSayaka(l, next) + pls(K[next], K[r] - 1);
	
	return (memo[l][r] = min(left, right));
}

int main(void)
{
	scanf("%d %d %d", &N, &M, &L);
	
	for (int i = 0; i < N; i++){
		scanf("%d", &K[i]);
	}
	
	for (int i = 0; i < M; i++){
		int s;
		scanf("%d", &s);
		SSum[i + 1] = SSum[i] + s;
	}
	
	sort(K, K + N);
	memset(memo, -1, sizeof(memo));
	
	printf("%lld\n", saveSayaka(0, 0));
}

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

/* -------------------------------- Template -------------------------------- */

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> T inf() { assert(false); }
template<> constexpr int inf<int>() { return 1e9; }
template<> constexpr ll inf<ll>() { return 1e18; }
template<> constexpr ld inf<ld>() { return 1e30; }

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q);
  for (int &i: a) { cin >> i; --i; }
  reverse(ALL(a));

  vector<int> ans;
  set<int> se;
  REP(i,M) se.insert(i);
  for (int i: a) {
    auto it = se.find(i);
    if (it != se.end()) {
      ans.push_back(*it);
      se.erase(it);
    }
  }
  for (int i: se) ans.push_back(i);
  int mi = 1e9;
  while (!ans.empty() && ans.back() < mi) {
    mi = ans.back(); ans.pop_back();
  }
  vector<int> it(M, -1);
  REP(i,ans.size()) it[ans[i]] = i;
  vector<int> res(ans.size(), 0);
  for (int i: a) {
    int id = it[i];
    if (id == -1) continue;
    // cout << id << " " << ans.size() << endl;
    if (id == 0 || res[id-1] > res[id]) ++res[id];
  }
  bool flag = (res.size() == 0 || res.back() >= N);
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 6264
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<ll> le(n), ri(n);
		vector<int> ks(n), one, two;
		ll ans = 0;
		for(int i = 0; i < n; i++) {
			cin >> ks[i] >> le[i] >> ri[i];
			ans += min(le[i], ri[i]);
			if(le[i] > ri[i]) one.push_back(i);
			else if(ri[i] > le[i]) two.push_back(i);
		}

/*		debug(ans);
		debug(one);
		debug(two);
		*/
		auto fn = [&](vector<int> inds) {
			priority_queue<ll, vector<ll>, greater<ll>> pq;
			sort(inds.begin(), inds.end(), [&](int a, int b) {
				return ks[a] < ks[b];
			});
			for(auto i: inds) {
				pq.push(abs(le[i] - ri[i]));
				if(pq.size() > ks[i]) pq.pop();
			}
			while(pq.size()) {
				ans += pq.top();
				pq.pop();
			}
		};
		fn(one);
		for(auto& el: ks) el = n - el;
		fn(two);
		cout << ans << '\n';
	}
}



Measured memory_bytes: 10032
#include <bits/stdc++.h>
#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;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

// ref : https://atcoder.jp/contests/abc159/submissions/11101114

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    string s[10];
    rep(i, h) cin >> s[i];
    int Ans = INF;
    for (int bits = 0; bits < (1<<(h-1)); bits++){
        int ans = 0;
        ans += __builtin_popcount(bits);

        vector<vector<int>> v;
        v.push_back({0});
        rep(i, h - 1){
            if (!(bits & (1 << (i)))) v.back().push_back(i+1);
            else v.push_back({i+1});
        }

        int n = v.size();

        int num[n] = {};

        rep(j, w){
            int now[n] = {};
            rep(i, v.size()){
                for (auto tmp : v[i]){
                    if (s[tmp][j] == '1') now[i]++;
                }
                if (now[i] > k) {
                    ans = INF;
                    j = w;
                    break;
                }
            }
            bool flag = false;
            if (ans == INF) break;
            rep(i, n){
                num[i] += now[i];
                if (num[i] > k) flag = true;
            }
            if (flag){
                ans++;
                rep(i, n) num[i] = 0;
                j--;
            }
        }
        // cout << bits << " " << ans << endl;
        Ans = min(Ans, ans);
    }

    cout << Ans << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect


class SegTree:
    def __init__(self, n):
        self.n = n
        self.s = 1
        while self.s < self.n:
            self.s <<= 1
        self.mins = [1 << 30] * (self.s * 2)

    def update(self, i, val):
        i += self.s
        self.mins[i] = val
        i >>= 1
        while i:
            self.mins[i] = min(self.mins[i * 2], self.mins[i * 2 + 1])
            i >>= 1

    def min(self, l, r):
        l += self.s
        r += self.s
        res = self.mins[0]
        while l <= r:
            if l & 1:
                res = min(res, self.mins[l])
                l += 1
            if not r & 1:
                res = min(res, self.mins[r])
                r -= 1
            l >>= 1
            r >>= 1
        return res


MOD = 998244353
N = int(input())
robots = []
for _ in range(N):
    x, d = map(int, input().split())
    robots.append((-x, -d))
robots.sort()
dp = [0] * (N + 1)
dp[0] = 1
st = SegTree(N)
for i, (x, d) in enumerate(robots):
    lo = bisect.bisect_right(robots, (x + d, 0), hi=i)
    lo = min(lo, st.min(lo, i))
    st.update(i, lo)
    dp[i + 1] += (dp[i] + dp[lo]) % MOD
print(dp[-1])


Measured memory_bytes: 91136
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<functional>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<set>
#include<map>

#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 2e9
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
const double PI = acos(-1);

using namespace std;
ll A[200001];
ll psum[200001];
int main(void) {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//	freopen("input.txt", "r", stdin);

	int N; cin >> N;
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
	    cin >> A[i];
		psum[i] = psum[i - 1] + A[i];
	}
	for (int i = 1; i < N; i++) {
		ans += (A[i] * ((psum[N] - psum[i]) % MOD))%MOD;
		ans %= MOD;
	}
	cout << ans;
}


Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
#define FOR(i,x,y) for(int i=(int)x; i<(int)y; ++i)
#define REP(i,y) FOR(i, 0, y)
constexpr int INF = 1<<30;
int N;
vector<vint> X(18, vint(2));
vint V_(18), V(18), Vb(18);
inline int search(int F){
  if(__builtin_popcount(F)&1) return INF;
  REP(i,N){
    V[i] = X[i][F%2];
    V_[i] = V[i];
    Vb[i] = F%2;
    F>>=1;
  }
  sort(V.begin(), V.begin()+N);
  int ans = 0;
  REP(i,N){
    FOR(j,i,N){
      if(!(V[i]==V_[j] && (j-i+Vb[j])%2==0)) continue;
      ans += j-i;
      for(int k=j-1; k>=i; --k){
        V_[k+1] = V_[k];
        Vb[k+1] = Vb[k]+1;
      }
      goto END;
    }
    return INF;
END:
    continue;
  }
  return ans;
}
int main(){
  cin >> N;
  REP(i,N) cin >> X[i][0];
  REP(i,N) cin >> X[i][1];
  int ans=INF;
  REP(i,1<<N) ans = min(ans, search(i));
  cout << (ans==INF?-1:ans) << endl;
  return 0;
}

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

int main() {
	vector<string> vec;
	string s;
	cin>>s;
	string tem;
     for(int i=0 ; i<s.size(); i++){
     	for(int j=i ; j<s.size() ; j++){
     		tem="";
     		 for(int k=0 ; k<i ; k++)
     		      tem+=s[k];
     	
     	for(int p=j ; p<s.size();p++)tem+=s[p];
     	if(tem=="keyence")return cout<<"YES",0;
     }
     }
   cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
X,A,B = map(int,input().split())
N = int(input())
for i in range(N):
    S = input()
    if S == "nobiro":
        X += A
    elif S == "tidime":
        X += B
    else:
        X = 0
    if X < 0:
        X = 0
print(X)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int X, Y;
  cin >> X >> Y;

  for (int i = 0; i <= X; i++) {
    if ((i * 2 + (X - i) * 4) == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

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


vector<int> memo; 
int rec(int n) {
    if(n==0) return 0;
    if(memo[n] != -1) return memo[n];
    int res = n;
    for(int pow6 = 1;pow6<=n;pow6 *= 6) {
        chmin(res,rec(n-pow6)+1);
    }
    for(int pow9 = 1;pow9<=n;pow9 *= 9) {
        chmin(res,rec(n-pow9)+1);
    }
    return memo[n] = res;
}

int main() {
    int n;
    cin >> n;
    memo.resize(n+10000);
    rep(i,n+10000) memo[i] = -1;
    cout << rec(n) << endl;
}    

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(n >= m){
        dunk(0);
        return 0;
    }
    
    vector<int> x(m);
    vector<int> xbet(m-1);

    rep(i,m) cin >> x[i];
    sort(all(x));


    rep(i,m-1) xbet[i] = x[i+1] - x[i];
    sort(all(xbet));
    reverse(all(xbet));

    rep(i,n-1) xbet[i] = 0;

    ll ans = 0;

    rep(i,m-1) ans += xbet[i];

    dunk(ans);
}


Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
	long long int h,k=1,count=0,i=1;
	cin>>h;
	while(h>1)
	{
			h=h/2;
			k*=2;
			if(k!=2)
			i=i*2;
			count=count+i;	
	}
		if(h==1)
		count=count+k;
		cout<<count;
		return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
#define dd double
#define vi vector<int> 
#define li list<int> 
#define pb push_back
#define sf scanf
#define pf printf
char s[200009];
char st[200009];
 	// int a[29][10];
 	// int b[29][10];
 	// int b[200009];
 	// int c[200009];
int main()
{
	cin >> s;
	cin >> st;
	int n = strlen(s);
	int cn = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] != st[i]) cn++;
	}

	cout << cn << endl;
	return 0;
}

Measured memory_bytes: 4012
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
ll p[1234],c[1234];
int main(){
    std::ios::sync_with_stdio(false);
    ll d,g;
    cin>>d>>g;
    ll i,j;
    rep(i,d){
    	cin>>p[i]>>c[i];
    	c[i]/=100;
    }
    g/=100;
    ll ans=0,mini=inf;
    ll pts=0;
    rep(i,(1<<d)){
    	ans=0;
    	pts=0;
    	rep(j,d){
    		if(i&(1<<j)){
    			ans+=p[j];
    			pts+=p[j]*(j+1);
    			pts+=c[j];
    		}
    	}
    	ll left,solve;
    	fd(j,d-1,0){
    		if(pts>=g)
    			break;
    		if((i&(1<<j))==0){
    			left=g-pts;
    			solve=(left+j)/(j+1);
    			solve=min(solve,p[j]);
    			pts+=solve*(j+1);
    			ans+=solve;
    		}
    	}
    	mini=min(mini,ans);
    }
    cout<<mini<<endl;
    return 0;     
}



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

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
			++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

typedef set <int> SI;
const int TRUE = 1;
const int FALSE = 0;

int solve( int n, VVI bunny, VVI G ) {
    VVI T( n, VI( n, FALSE ) );
    int nb = bunny.size();
    for ( int i = 0; i < nb; ++ i ) {
        VI b = bunny[i];
        for ( VI::iterator it_i = b.begin(); it_i != b.end(); ++ it_i ) {
            for ( VI::iterator it_j = b.begin(); it_j != b.end(); ++ it_j ) {
                if ( it_i == it_j ) continue;
                T[*it_i][*it_j] = TRUE;
            }
        }
    }
    SI S;
    for ( int i = 0; i < n; ++ i ) {
        for ( int j = 0; j < n; ++ j ) {
            if ( G[i][j] && T[i][j] ) {
                S.insert( i );
                S.insert( j );
            }
        }
    }
    return S.size();
}

int main() {
    int n, k;
    while ( cin >> n >> k ) {
        VVI bunny( n );
        for ( int i = 0; i < k; ++ i ) {
            int m;
            cin >> m;
            bunny[i] = VI( m );
            for ( int j = 0; j < m; ++ j ) {
                int b;
                cin >> b;
                b --;
                bunny[i][j] = b;
            }
        }
        int r;
        cin >> r;
        VVI G( n, VI( n, FALSE ) );
        for ( int i = 0; i < r; ++ i ) {
            int p, q;
            cin >> p >> q;
            p --;
            q --;
            G[p][q] = TRUE;
            G[q][p] = TRUE;
        }
        cout << solve( n, bunny, G ) << endl;
    }
	return 0;
}

Measured memory_bytes: 0
use std::io::prelude::BufRead;
use std::io::StdinLock;

pub fn read_line(locked_stdin: &mut StdinLock) -> std::io::Result<String> {
    let mut buf = String::new();
    locked_stdin.read_line(&mut buf).map(|_| buf)
}

pub fn read_to_vec<T: std::str::FromStr>(locked_stdin: &mut StdinLock) -> Vec<T> {
    read_line(locked_stdin).unwrap()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n;
    let a;

    {
        let stdin = std::io::stdin();
        let mut lkin = stdin.lock();
        let mut input = read_to_vec::<usize>(&mut lkin).into_iter();
        n = input.next().unwrap();
        a = read_to_vec::<usize>(&mut lkin);
    }

    let mut left_min = Vec::new();
    let mut right_max = Vec::new();
    left_min.push(0);
    right_max.push(n-1);

    for i in 1..n {
        let mem = left_min[i-1];
        left_min.push(if a[mem] >= a[i] {i} else {mem});
        let mem = right_max[i-1];
        right_max.push(if a[mem] <= a[n-1-i] {n-1-i} else {mem});
    }
    right_max.reverse();

    let data: Vec<_> = (0..n).map(|i|
        ( i, (left_min[i], right_max[i]), a[right_max[i]] - a[left_min[i]] )).collect();
    let &(_, _, max) = data.iter().max_by_key(|d| d.2).unwrap();
    let data: Vec<_> = data.iter().filter_map(|d|
        if max == d.2 {Some((d.0, d.1))} else {None}).collect();

    let mut ans = 0;
    let mut last_max = n;
    let mut last_min = n;
    for d in data.iter() {
        if (last_min, last_max) == d.1 { continue; }
        last_min = (d.1).0;
        last_max = (d.1).1;
        ans += std::cmp::min(
            a[last_min..(last_max+1)].into_iter().filter(|&&apple| apple == a[last_min]).count(),
            a[last_min..(last_max+1)].into_iter().filter(|&&apple| apple == a[last_max]).count()
        )
    }

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


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

#define ff first
#define ss second

const int N = 200 * 1000 + 20;
int n;
map<string, int> mp;
vector<string> ans;

int main() {
	cin >> n;
  	for (int i = 0; i < n; i++) {
		string s;
      	cin >> s;
      	mp[s]++;
    }
  	int cnt = 0;
  	for (auto P: mp)
      	cnt = max(cnt, P.ss);
 	for (auto P: mp)
      	if (P.ss == cnt)
          	ans.push_back(P.ff);
 	sort(ans.begin(), ans.end());
  	for (auto i: ans)
      	cout << i << "\n";
 	return 0;
}

Measured memory_bytes: 26868
//https://www.cnblogs.com/shuitiangong/
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e5+10;
ll arr[maxn];
int main(void) {
    int n;
    scanf("%d", &n);
    ll sum = 0, sign = 1;
    for (int i = 0; i<n; ++i) {
        scanf("%lld", &arr[i]);
        arr[i] *= 2;
        sum += sign*arr[i];
        sign = -sign;
    }
    sum /= 2;
    arr[0] -= sum;
    for (int i = 1; i<n; ++i)
        arr[i] -= arr[i-1];
    for (int i = 0; i<n; ++i)
        printf(i==n-1 ? "%lld\n" : "%lld ", arr[(n-1+i)%n]);
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
long cnt(long n,long p){
	long sum=0;
	while(n){
		sum+=n/p;
		n/=p;
	}return sum;
}
int main(){
	long N;cin>>N;
	if(N==0|N==1){
		cout<<0<<endl;
	}else if(N%2==1){
		cout<<0<<endl;
	}else{
		cout<<min(cnt(N/2,2)+N/2,cnt(N/2,5))<<endl;
	}
}

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

int GCD (int x,int y) {
  if (x > y) swap(x,y);
  if (x == 0) return y;
  else if (y % x == 0) return x;
  else return GCD(y % x,x);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  vector<int> L(N),R(N);
  for(int i = 0; i < N; i++) {
    if (i == 0) {
      L.at(0) = 0;
      R.at(N-1) = 0;
    } else {
      L.at(i) = GCD(L.at(i-1),A.at(i-1));
      R.at(N-1-i) = GCD(A.at(N-i),R.at(N-i));
    }
  }
  int ans = 0;
  for(int i = 0; i < N; i++) ans = max(ans,GCD(L.at(i),R.at(i)));
  
  cout << ans << endl;
}

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

int main() {
  
  string s;
  ll k, ans;
  cin >> s >> k;
  ll L = s.size();
  ll notone = L-1;
  for(ll i = 0; i < L; i++) {
    if(s[i]-'0' != 1) {
      notone = i;
      break;
    }
  }
  if(k < notone+1) ans = 1;
  else ans = s[notone]-'0';
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b){
int c=*a;
*a=*b;
*b=c;
return;
}

int main(void)
{
int w,n;
scanf("%d",&w);
int list[w-1];
for(int i=0;i<w;i++)
list[i]=i+1;
scanf("%d",&n);
for(int i=0;i<n;i++){
int a,b;
scanf("%d,%d",&a,&b);
swap(&list[a-1],&list[b-1]);
}
for(int i=0;i<w;i++){
printf("%d\n",list[i]);
}
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        bool flag=false;
        int four=0,one=0,two=0;
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&a[i]);
            {
                if(a[i]%4==0) four++;
                else if(a[i]%2==0) two++;
                else one++;
            }
        }
        if(one>four+1||(one==four+1&&two!=0)) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main{

    String[] shape = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    int n = sc.nextInt();
	    if(n==0) break;

	    boolean[] hands = new boolean[15];
	    for(int i=0; i<n; i++){
		String s = sc.next();
		for(int j=0; j<15; j++){
		    if(s.equals(shape[j])) hands[j] = true;
		}
	    }

	    boolean[] win = new boolean[15];
	    boolean[] lose = new boolean [15];
	    for(int i=0; i<15; i++){
		if(!hands[i]) continue;
		for(int j=1; j<=7; j++){
		    if(!hands[(i+j)%15])continue;
		    win[i] = true;
		    lose[(i+j)%15] = true;
		}
	    }

	    String winner = "Draw";
	    for(int i=0; i<15; i++){
		if(win[i] && !lose[i]){
		    if(winner.equals("Draw")) winner = shape[i];
		    else {winner = "Draw"; break;}
		}
	    } 

	    System.out.println(winner);
	}
    }

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

Measured memory_bytes: 12000
from collections import Counter

N = input()
A = map(int, raw_input().split())
hist = Counter(A)

def valid():
  if N % 2 == 0:
    for i in range(1,N,2):
      if hist[i] != 2:
        return False
    return True
  else:
    if hist[0] != 1:
      return False
    for i in range(2,N,2):
      if hist[i] != 2:
        return False
    return True

if valid():
  a = N/2
  print 2**a % (10**9+7)
else :
  print 0

Measured memory_bytes: 11444
// Author : Nachiket Kanore
// Institute : PICT, Pune

/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */

#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <memory>
#include <random>
#include <cmath>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
 
 
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const int mod = 1e9+7;
const int inf = 1e18;
const int N = 2e3+20;

int ans;
int like[N][N];

int32_t main(){
    FAST;

    int n,m;    cin >> n >> m;

    rep(i,1,n){

        int k;  cin >> k;
        while(k--){
            int food;   cin >> food;
            like[i][food]++;
        }

    }

    rep(type,1,m){
        int cnt =0 ;
        for(int x=1;x<=n;x++){
            cnt += like[x][type] > 0;
        }
        ans += (cnt == n);
    }

    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, a, b;
    cin >> n >> a >> b;
    a--;b--;
    int c, d;
    cin >> c >> d;
    c--;d--;
    int mx = max(c,d);
    string s; cin >> s;
    int dc = 0, dm = 0;
    int sc = 0, sm = 0;
    bool ans = true;
    FOR(i,a,mx+1){
        if (!((i > a) || (i < c)) && ((i > b) || (i < d))) {
            cerr << i;
            sc = 0;
            continue;
        }
        if (s[i] == '#') {
            sc++;
            sm = max(sm,sc);
            dc = 0;
        } else {
            if (i >= b-1) {
                dc++;
                dm = max(dm,dc);
            }
            sc = 0;
        }
        if (c > d && i == d+1) {
            if (dm <= 2) {
                ans = false;
                break;
            }
        }
        if (sm >= 2) {
            ans = false;
            break;
        }
    }

    ATYN(ans)

    return 0;
}

Measured memory_bytes: 592
var
	N,K,i:Longint;
	s,a,b:Array[0..100000]of int64;
	ans,sum:int64;
function my(d:int64):int64;
begin
	if d>0 then my:=d else my:=0;
end;
begin
	read(N,K);
	for i:=1 to N do read(s[i]);
	a[1]:=s[1];
	b[1]:=my(s[1]);
	for i:=2 to N do begin
		a[i]:=s[i]+a[i-1];
		b[i]:=my(s[i])+b[i-1];
	end;
	ans:=0;
	for i:=0 to N-K do begin
		sum:=my(a[i+K]-a[i]);
		inc(sum,b[i]-b[0]+b[N]-b[i+K]);
		if ans<sum then ans:=sum;
	end;
	writeln(ans);
end.

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 9999999999;
const long long MOD = 1e9 + 7;
const double pi = 3.1415926535897932384626;
const int SIZE = 1 << 17;

int food[35], ans;
int main() {
	int a, b, c;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> c;
		for (int j = 0; j < c; ++j) {
			int d;
			cin >> d;
			++food[d];
		}
	}
	for (int i = 0; i <= 30; ++i) {
		if (food[i] == a) { ++ans; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 384