akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	long long n,cnt=1;
	long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i<10||i>99&&i<1000||i>9999&&i<100000)ans++;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Set<Integer> set = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                set.add(x);
            }
            out.println(set.size());

        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

int main() {
  int n; cin >> n;
  vector<long long> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long bi = b[i];
    auto aiter = lower_bound(a.begin(), a.end(), bi);
    auto citer = upper_bound(c.begin(), c.end(), bi);
    ans += distance(a.begin(), aiter) * distance(citer, c.end());
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#define fastIO cin.tie(0);ios_base::sync_with_stdio(false)
#define N 10010
#define ll long long
#define INF 1000000000000000000
//min-cost flow problem
using namespace std;

struct edge {
  ll from, to, cap, flow, cost;
};

ll n, d[2 * N + 5], pre[2 * N + 5], Maxflow = 0, COST = 0;
bool inqueue[2 * N + 5];
vector<edge> Edge;     // store edges
vector<ll> G[2 * N + 10];

inline void addEdge( ll from, ll to, ll cap, ll cost )
{
    Edge.push_back( edge{from, to, cap, 0, cost} );
    Edge.push_back( edge{to, from, 0, 0, -cost} );

    G[from].push_back( Edge.size() - 2 );
    G[to].push_back( Edge.size() - 1 );
}

inline bool bfs( ll s, ll t )
{
    for ( int i = 0; i < 2 * N + 5; ++i )
        d[i] = INF;
    memset( inqueue, 0, sizeof( inqueue ) );

    queue<ll> q;
    q.push( s );

    d[s] = 0, inqueue[s] = true;

    ll now;
    while ( q.empty() == false ) {
        now = q.front();
        q.pop();
        inqueue[now]=false;
        for ( ll i = 0; i < G[now].size(); ++i ) {
            edge& tmp = Edge[G[now][i]];
            if ( tmp.cap > tmp.flow && d[now] + tmp.cost < d[tmp.to] ) {
                d[tmp.to] = d[now] + tmp.cost;
                pre[tmp.to] = G[now][i];

                if ( inqueue[tmp.to] == false ) {  //&& tmp.to!=t  not sure
                    inqueue[tmp.to] = true;
                    q.push( tmp.to );
                }
            }
        }
    }

    return d[t] != INF;
    /*
    if(d[t]==-INF)
        return false;
    else
        return true;
    */
}

inline void calc( ll s, ll t )
{
    ll minflow = INF;
    ll tmpu = t;
    while ( s != tmpu ) { //find minflow
        minflow = min( minflow, Edge[pre[tmpu]].cap - Edge[pre[tmpu]].flow );
        tmpu = Edge[pre[tmpu]].from;
    }

    Maxflow += minflow;
    COST += minflow * d[t];

    while ( s != t ) {
        Edge[pre[t]].flow += minflow;
        Edge[pre[t] ^ 1].flow -= minflow;
        t = Edge[pre[t]].from;
    }
}

inline void init()
{
    cin >> n;

    ll a, b, c;
    for ( int i = 1; i <= n; ++i ) {
        cin >> a >> b >> c;
        addEdge( 0, i, c, 0 );
        addEdge( i, 2 * n + 1, c, -a - b );
        addEdge( i, 2 * n + 2, c, a - b );
        addEdge( i, 2 * n + 3, c, -a + b );
        addEdge( i, 2 * n + 4, c, a + b );
    }
    for ( int i = 1; i <= n; ++i ) {
        cin >> a >> b >> c;
        addEdge( i + n, 2 * n + 5, c, 0 );
        addEdge( 2 * n + 1, i + n, c, a + b );
        addEdge( 2 * n + 2, i + n, c, -a + b );
        addEdge( 2 * n + 3, i + n, c, a - b );
        addEdge( 2 * n + 4, i + n, c, -a - b );
    }
}

inline void solve()
{
    ll s = 0, t = 2 * n + 5;

    while ( bfs( s, t ) == true ) {
        calc( s, t );  //update cost && Maxflow
    }
    cout << -COST << endl;
}

int main()
{
    init();
    solve();
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
  	cin >> n;
  	vector<int> s(n);
  	int d = 0, e = 0;
  	for(int i=0;i<n;i++){
      cin >> s.at(i);
    if(s.at(i)%2==0) d++;
    if(s.at(i) % 2 == 0 && (s.at(i) % 3 == 0 || s.at(i) % 5 == 0)) e++;
    }
  	if(e != d) cout <<"DENIED"<<endl;
  	else cout << "APPROVED" << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
	
		int[] alpha = new int[26];
		String ans = "yes";
		for(char c: s.toCharArray()){
			alpha[c-'a']++;
			if(alpha[c-'a']>1){
				ans = "no";
				break;
			}		
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int H = in.nextInt();
      int W = in.nextInt();
      int h = in.nextInt();
      int w = in.nextInt();

      System.out.println((H - h) * (W - w));
    }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int n,m; cin>>n>>m;
	ote((n-1)*(m-1));
}


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

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const long long int INF=0x3f3f3f3f3f3f;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

typedef struct node
{
	ll x,y,left,up,right,down;
}node;

int main()
{
	vivek_ghosh;
	
	ll a,b;
	cin>>a>>b;
	
	ans = (a+b)/2;
	if(abs(b-ans)==abs(a-ans))
		cout<<ans;
	else
		cout<<"IMPOSSIBLE";
	cout<<endl;
	
	
	return 0;
}







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

#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long

using namespace std ;

const int MAXN = 1001 * 1001 ; 

vector<int> adj[MAXN] ;    
 
vector<pair<int,int>> v ; 

int a[MAXN] ;

bool w[MAXN] ;

int32_t main()
{
	ios::sync_with_stdio(0) ; cin.tie(0) ; 
	int n ; 
	cin >> n ; 
	memset(w,1,sizeof w) ; 
	for(int i = 0 ; i < n ; i ++ ) 
	{
		cin >> a[i] ; 
		v.pb({a[i],i}) ; 
	}
	for(int i = 1 ; i < n ; i ++ ) 
	{
		int x , y ;
		cin >> x >> y ; 
		x -- , y -- ; 
		adj[x].pb(y) ; 
		adj[y].pb(x) ; 
	}

	sort(v.begin(),v.end()) ;  
	
	//cout << v.size() << endl ; 

	for(int k = 0 ; k < n ; k ++ ) 
	{
		int i = v[k].S; 
	//	cout << i << endl ; 
		w[i] = 0 ; 
		for(auto u : adj[i])
		{
			if(a[i]>a[u]&&!w[u])
				w[i] = 1 ; 
		}
	}
	for(int i = 0 ; i < n ; i ++ ) 
		if(w[i])
			cout << i + 1 << ' ' ; 
	cout << '\n' ; 


	
}


Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
#define sz int(1e5+1)
int main()
{
    int N, W; cin >> N >> W;
    int vi,wi;

    
    vector <long long> dp (sz+1, INT_MAX);
    dp[0]=0;
    int sum=0;
    for(int i = 0; i < N; i++){
        cin >> wi >> vi;
        sum+=vi;
        //if(dp[vi]==INT_MAX)dp[vi]=wi;
        for(int j = sz; j >= vi; j--){
            dp[j] = min(dp[j], dp[j-vi]+wi);
        }
    }
    int ans=0;
    for(int i = 1; i <= sum; i++){
        //cout<<dp[i]<<endl;
        if(dp[i]<=W)
            ans=max(i, ans);
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPR(i,a,b) for(int i = b; i >= a; i--)
#define all(a)              a.begin(), a.end()
#define alln(a, n)          (a, a+n)
#define sz(x) (int)(x).size()
#define MAX                 10000007
#define MIN                 -10000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mii             map<int,int>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf 1e18
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<vi> vvi; 
typedef vector<string> vs;
typedef set<int> si;
const int MOD=1e9+7;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b,ll MOD){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2,MOD) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2,MOD);}
ll fact[1],inv[1];
void factorial(ll n){
  fact[0]=1;
  for(ll i=1;i<=n;i++){
    fact[i]=fact[i-1]*i;
    if(fact[i]>=MOD)
      fact[i]%=MOD;
  }
}
ll ncr(ll n,ll r){
  if(n<r||n<0||r<0)
    return 0;
  ll b=inv[n-r];
  ll c=inv[r];
  ll a=fact[n]*b;
  if(a>=MOD)
    a%=MOD;
  a*=c;
  if(a>=MOD)
    a%=MOD;
  return a;
}
vector<char> is_prime(100001, true);
void sieve(ll n){
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                  is_prime[j] = false;
        }
  }    
}     
 
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
      
    int t;
    t=1;
    cout<<fixed<<setprecision(0);
     //  cin>>t;
    while(t--){
            ll n,ans=0;
            cin>>n;
            REP(i,1,n){
              ans+=(n-1)/i;
            }  
            cout<<ans;
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


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

int a[100];
int n=0;
int b[100];
int N;

bool check(void){
  for(int i=N-1;i>=0;i--){
    if(b[i]==i+1){
      a[n]=i+1;
      n+=1;
      for(int j=i;j<N-1;j++) b[j]=b[j+1];
      N-=1;
      if(N>0){
        if(check()==false) return false;
      }
      return true;
    }
  }
  return false;
}

int main(void){
  cin>>N;
  for(int i=0;i<N;i++) cin>>b[i];
  if(check())
    for(int i=n-1;i>=0;i--) cout<<a[i]<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys

(K, S) = (int(x) for x in input().split())
comb = 0

for x in range(0, K + 1):
  for y in range(0, K + 1):
    z = S - x - y
    if z <= K and z >= 0:
#      print("%d %d %d" % (x, y, z))
      comb+=1

print(comb)

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

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(n); VI(ls, n);
  sort(ls.begin(), ls.end());
  int ans = 0;
  for(auto&& it0 = ls.begin(); it0!= ls.end() - 2; it0++){
    for(auto&& it1 = it0 + 2; it1!= ls.end(); it1++){
      ans += it1 - lower_bound(it0 + 1, it1, *it1 - *it0 + 1);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,rep=-1;
    cin>>n;
    rep(i,n+1){
        rep(j,n+1){
            if (4*i+7*j==n) {
                rep=1;
                break;
            }
        }
    }
    cout<<((rep!=-1) ? "Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
#define ll long long
#define endl "\n"
using namespace std;
int main()
{
    int a, b;
    string s;
    cin>>s;
    int ans=0;
    string w[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    rep(i,7){
        if(s==w[i])ans=7-i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String dance = sc.next();
		String[] s = dance.split("");
		String result = "Yes";
		for (int i = 0; i < s.length; i++) {
			if (i % 2 == 0) {
				if (s[i].equals("L")) {
					result = "No";
				}
			} else {
				if (s[i].equals("R")) {
					result = "No";
				}
			}
		}
		System.out.println(result);
	}
}

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

int main(){
  int q;
  set<int> s;
  cin >> q;
  while(q--){
    int x, y;
    cin >> x >> y;
    if(x)cout << s.count(y) <<endl;
    else{
      s.insert(y);
      cout << s.size() <<endl;
    }
  }
}


Measured memory_bytes: 12368
N, M = map(int, input().split())
max_L = 0
min_R = 10**5
for _ in range(M):
  L, R = map(int, input().split())
  max_L = max(max_L, L)
  min_R = min(min_R, R)
print(len(list(range(max_L, min_R+1))))

Measured memory_bytes: 6900
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::string S;
    std::cin >> S;

    int length = S.length();
    std::vector<int> children(length, 0);

    int comparison = 0;
    std::vector<int> components;
    for (int i = 0; i < length; i += 1) {
        if (S[i] == S[comparison]) {
            continue;
        }
        components.push_back(i - comparison);
        comparison = i;
    }
    components.push_back(length - comparison);

    int size = components.size();
    int count = 0;
    for (int i = 0; i < size; i += 1) {
        if (i % 2 == 0) {
            if (components[i] % 2 == 0) {
                children[count + components[i]] += components[i] / 2;
                children[count + components[i] - 1] += components[i] / 2;
            } else {
                children[count + components[i]] += components[i] / 2;
                children[count + components[i] - 1] += components[i] / 2 + 1;
            }
        } else {
            if (components[i] % 2 == 0) {
                children[count] += components[i] / 2;
                children[count - 1] += components[i] / 2;
            } else {
                children[count] += components[i] / 2 + 1;
                children[count - 1] += components[i] / 2;
            }
        }
        count += components[i];
    }

    for (int i = 0; i < length; i += 1) {
        if (i != 0) {
            std::cout << " ";
        }
        std::cout << children[i];
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 1528
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> fun [| x; _ |] ->
    [| 1 .. x |]
    |> Array.map (fun _ -> readIntArray ())
|> Array.indexed
|> fun x ->
    [| for (i1, v1) in x do
        for (i2, v2) in x do
            if i1 < i2 then
                v1
                |> Array.zip v2
                |> Array.sumBy (fun (a, b) -> (a - b) * (a - b))
                |> (fun x ->
                    let y = x |> float |> sqrt |> int
                    y * y = x) |]
|> Array.filter id
|> Array.length
|> printfn "%d"


Measured memory_bytes: 30716
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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

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

    int n; cin >> n;
    ll result = 0;
    for (int i = 1; i <= n; i++)
        result += (n%i == 0 ? n/i-1 : n/i);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  int AC = 0, WA = 0;
  vector<int> eachWA(N+1);
  vector<bool> solved(N+1, 0);  // 1-indexed
  rep(i, M) {
    int P;
    string S;
    cin >> P >> S;
    if (solved[P]) continue;
    if (S == "AC") {
      AC++;
      WA += eachWA[P];
      solved[P] = true;
    } else {
      eachWA[P]++;
    }
  }
  cout << AC << ' ' << WA << '\n';
  return 0;
}

Measured memory_bytes: 3792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int sum = 0;
    
    int maxi = 0;
    
    rep(i,s.size()){
        if(s[i]=='I')sum++;
        if(s[i]=='D')sum--;
        
        maxi = max(maxi,sum);
    }
    
    cout<<maxi<<endl;
}


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

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

  map<int, int> A;
  int n;
  int64_t sum = 0;
  
  for (n = 0; n < N; n++){
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }

  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (n = 0; n < Q; n++){
    cin >> B.at(n);
    cin >> C.at(n);
  }

  for (n = 0; n < Q; n++){
    int b = B.at(n);
    int c = C.at(n);
    int diff = c - b;

    if (A.count(b)){
      if (A.count(c)){
	A[c] += A[b];
	sum += diff*A[b];
	A.erase(b);
      }else{
	A[c] = A[b];
	sum += diff*A[b];
	A.erase(b);
      }
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 6844
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#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 FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

string S;

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

    cin >> S;

    set<char> s;
    map<char, int> P;
    map<char, int> cand;
    REP(i, S.size()) {
        char c = S[i];
        if (P.find(c) != P.end()) {
            cand[c] = max(cand[c], i - P[c] - 1);
        } else {
            cand[c] = i;
        }
        P[c] = i;
    }

    int ans = INF;
    for (auto kv : cand) {
        char c = kv.first;
        ans = min(ans, max(cand[c], (int)S.size() - 1 - P[c]));
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int Nmax = 2e5 + 5;

vector<int> v[Nmax];
bool used[Nmax];
int x, y, i, n, m, cnt[Nmax][2], node;
queue<int> bad;
char a[Nmax];

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    cin >> (a+1);

    for(i=1; i<=m; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    for(i=1; i<=n; ++i)
        for(auto it : v[i])
            ++cnt[i][a[it] - 'A'];

    for(i=1; i<=n; ++i)
        if(!cnt[i][0] || !cnt[i][1])
            bad.push(i), used[i] = 1;

    while(!bad.empty())
    {
        node = bad.front();
        bad.pop();

        for(auto it : v[node])
        {
            --cnt[it][a[node] - 'A'];
            if(!cnt[it][a[node] - 'A'] && !used[it])
            {
                used[it] = 1;
                bad.push(it);
            }
        }
    }

    for(i=1; i<=n; ++i)
        if(!used[i])
        {
            cout << "Yes\n";
            return 0;
        }
    cout << "No\n";
    return 0;
}


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

void update_weights(int &w0, int &w1, int n0, int n1, int n2, int n3)
{	
	int o0, o1;
	o0 = min(w0 + abs(n2 - n0), w1 + abs(n2 - n1));
	o0 = min(o0, w0 + abs(n1 - n0) + abs(n2 - n1));

	o1 = min(w1 + abs(n3 - n1), w1 + abs(n2 - n1) + abs(n3 - n1));
	o1 = min(o1, w0 + abs(n1 - n0) + abs(n3 - n1));
	o1 = min(o1, w0 + abs(n2 - n0) + abs(n3 - n2));
	w0 = o0;
	w1 = o1;
}


int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i=0;i<N;i++)
		cin >> a[i];
		
	int w0, w1;
	w0 = abs(a[0] - a[1]);
	w1 = min(abs(a[2] - a[0]), w0 + abs(a[2] - a[1]));
	int output;
	if (N == 2)
	{
	    cout << abs(a[1] - a[0]);
	}
	else if (!(N % 2)) // N is even
	{
		for (int i = 1; i <= N - 5; i += 2)
		{
			update_weights(w0, w1, a[i], a[i+1], a[i+2], a[i+3]);
		}
		output = min(w0 + abs(a[N - 1] - a[N - 3]), w1 + abs(a[N - 1] - a[N - 2]));
		cout << output;
	}
	else
	{
		for (int i = 1; i <= N - 4; i += 2)
		{
			update_weights(w0, w1, a[i], a[i+1], a[i+2], a[i+3]);
		}
		cout << w1;
	}

	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			int sumA=0;
			for(int i=0;i<4;i++){
				sumA += sc.nextInt();
			}
			int sumB=0;
			for(int i=0;i<4;i++){
				sumB += sc.nextInt();
			}
			if(sumA>sumB){
				System.out.println(sumA);
			}else{
				System.out.println(sumB);
			}
						
		}
	}
}

Measured memory_bytes: 17168
#include <cstdio>

int main()
{
	int n, k, c = 0; scanf ("%d %d", &n, &k);
	for (int i = 0, w; i < n; i++){
		scanf ("%d", &w);
		if (k <= w) c++;
	}
	printf ("%d\n", c);
	return 0;
}

Measured memory_bytes: 128
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int a[100100],b[100100],gr[100100];
vector<pint> v;
bool cal(){
	int n;cin>>n;
	rep(i,n){
		cin>>a[i];v.pb(mp(a[i],-i-1));
	}
	rep(i,n){
		cin>>b[i];v.pb(mp(b[i],i+1));
	}
	sort(All(v));
	int f=0,s=0;
	rep(i,n*2){
		if(v[i].se>0) s++;else s--;
		if(s>0) return false;
		if(s<-1) f=1;
	}
	if(f>0) return true;
	rep(i,n) gr[-v[i*2].se]=v[i*2+1].se;
	int x=1,it=gr[1];
	while(it!=1){
		x++;it=gr[it];
	}
	return x<n;
}
int main()
{
	if(cal()) cout<<"Yes"<<endl;else cout<<"No"<<endl;
}


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

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;

    if (a <= 0 && b >= 0)
        cout << "Zero" << endl;
    else if (a > 0)
        cout << "Positive" << endl;
    else
        cout << ((b - a + 1) & 1 ? "Negative" : "Positive") << endl;
}


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

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

ll mod = 1e9 + 7;

bool mizuyari(vector<int> &data) {
    int flag = true;
    int i = 0;
    int size = data.size();
    int l,r;
    while (flag) {
        if (i == size) {
            return false;
        } else if(data.at(i) == 0) {
            i ++;
        } else {
            l = i;
            flag = false;
        }
    }
    flag = true;
    while(flag) {
        if (i == size) {
            r = i;
            flag = false;
        } else if (data.at(i) == 0) {
            r = i;
            flag = false;
        } else {
            i ++ ;
        }
    }
    rp(j, l, r) {
        data.at(j) --;
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> garden(n);
    rp(i, 0, n) {
        scanf("%d", &garden.at(i));
    }
    int ans = 0;
    bool TF = true;
    while(TF) {
        TF = mizuyari(garden);
        ans++;
    }
    printf("%d", ans - 1);
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////
#define mp make_pair

int N,M;
char s[202020];
int a[202020],b[202020];
vector<int> ab[202020];
int cont[202020][2];
vector<int> nonodes;

int main(){
    scanf("%d%d",&N,&M);
    scanf("%s",s);
    for(i=1;i<=M;i++){
        scanf("%d%d",&a[i],&b[i]);
        ab[a[i]].push_back(b[i]);
        ab[b[i]].push_back(a[i]);
        cont[a[i]][s[b[i]-1]-'A']++;
        cont[b[i]][s[a[i]-1]-'A']++;
    }
    for(i=1;i<=N;i++){
        if(cont[i][0]*cont[i][1])
            continue;
        //printf("%d ",i);
        nonodes.push_back(i);
    }

    for(j=0;j<nonodes.size();j++){
        int AB=s[nonodes[j]-1]-'A';
        for(i=0;i<ab[nonodes[j]].size();i++){
            if(--cont[ab[nonodes[j]][i]][AB]==0
            &&cont[ab[nonodes[j]][i]][!AB]!=0){
                //printf("%d ",ab[nonodes[j]][i]);
                nonodes.push_back(ab[nonodes[j]][i]);
            }
            //printf("%d:%d ",ab[nonodes[j]][i],cont[ab[nonodes[j]][i]][AB]);
        }    
    }
    if(nonodes.size()==N){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 14588
#include<iostream>

using namespace std;

#define MAX 10000000

int H;
int A[MAX + 1];

void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;

	if (l <= H&&A[l] > A[i]) {
		largest = l;
	}
	else {
		largest = i;
	}
	if (r <= H&&A[r] > A[largest]) {
		largest = r;
	}
	if (largest != i) {
		int x;
		x = A[i];
		A[i] = A[largest];
		A[largest] = x;

		maxHeapify(largest);
	}
}

int main() {
	cin >> H;
	for (int i = 1;i <= H;i++) {
		cin >> A[i];
	}
	for (int i = H / 2;i >= 1;i--) {
		maxHeapify(i);
	}
	for (int i = 1;i <= H;i++) {
		cout << " " << A[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 4944
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
ll n,h,w;
cin>>n>>h>>w;
ll a[n];
ll b[n];
for(ll i=0;i<n;i++){
cin>>a[i]>>b[i];
}
ll count=0;
for(ll i=0;i<n;i++){
if(a[i]>=h&&b[i]>=w)
count++;
}
cout<<count;
  return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

  vector<vector<int> > X(200000, vector<int>(20,0));
  vector<vector<int> > S(200002, vector<int>(20,1145141919));

bool solve(int r,int l){
  REP(j,20){
    if (S[r][j] - S[l][j] >= 2)
    {
      return false;
    }
  }
  return true;
}

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

  REP(i,N){
    int A;
    cin >> A;
    REP(j,20){
      X[i][j] = A % 2;
      A /= 2;
    }
  }

  REP(j,20){
    S[0][j] = 0;
  }

  REP(i,N){
    REP(j,20){
      S[i + 1][j] = S[i][j] + X[i][j];
    }
  }



  LL sum = 0;

  REP(i, N)
  {
    int ok =i;
    int ng = 200002;
    while (abs(ok - ng) > 1)
    {
      int mid = abs(ok + ng) / 2;
      if (solve(mid, i))
      {
        ok = mid;
      }else{
        ng = mid;
      }
    }
    sum += ok - i;
  }

  cout << sum << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(K), b(K);
  for (int i = 0; i < K; ++i)
    cin >> a[i] >> b[i];

  for (int i = 0; i < K; ++i)
    cout << min(min(a[i] - 1, N - a[i]), min(b[i] - 1, N - b[i])) % 3 + 1
         << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define re register
#define ll long long
#define int ll
#define get getchar()
#define in inline
in int read()
{
	int t=0; char ch=get;
	while(ch<'0' || ch>'9') ch=get;
	while(ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
	return t;
}
const int _=2e5+5;
int n,q,A,B,x[_];
ll lazy[_<<4],min1[_<<4],min2[_<<4];
in void pushdown(int k)
{
	if(lazy[k]==0) return ;
	int x=lazy[k];
	lazy[k]=0;
	lazy[k<<1]+=x;
	lazy[k<<1|1]+=x;
	min1[k<<1]+=x;
	min1[k<<1|1]+=x;
	min2[k<<1]+=x;
	min2[k<<1|1]+=x;
}
in void update(int k,int l,int r,int x,int y)
{
	if(l==r)
	{
		min1[k]=min(min1[k],(ll)(y-l));
		min2[k]=min(min2[k],(ll)(y+l));
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,y);
	else update(k<<1|1,mid+1,r,x,y);
	min1[k]=min(min1[k<<1],min1[k<<1|1]);
	min2[k]=min(min2[k<<1],min2[k<<1|1]);
}
#define ls(_o) (_o << 1)
#define rs(_o) ((_o << 1) | 1)
ll query1(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min1[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query1(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query1(rl, rr, l, mid, ls(tree)));
        return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
    }
ll query2(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min2[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query2(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query2(rl, rr, l, mid, ls(tree)));
        return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
    }
/*
  in int query1(int k,int l,int r,int x,int y)
{
	cout<<1<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min1[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query1(k<<1|1,l,mid,x,y);
	if(x>mid) return query1(k<<1,mid+1,r,x,y);
	return min(query1(k<<1,l,mid,x,mid),query1(k<<1|1,mid+1,r,mid+1,r));
	}
in int query2(int k,int l,int r,int x,int y)
{
	cout<<2<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min2[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query2(k<<1|1,l,mid,x,y);
	if(x>mid) return query2(k<<1,mid+1,r,x,y);
	return min(query2(k<<1,l,mid,x,mid),query2(k<<1|1,mid+1,r,mid+1,r));
	}*/
in int getans(int k,int l,int r)
{
	if(l==r) return min1[k]+l;
	pushdown(k);
	int mid=l+r>>1;
	return min(getans(k<<1,l,mid), getans(k<<1|1,mid+1,r));
}
signed main()
{
	n=read(),q=read(),A=read(),B=read();
	x[0]=A;
	memset(min1,0x3f,sizeof(min1));
	memset(min2,0x3f,sizeof(min2));
	update(1,1,n,B,0);
	for(re int i=1;i<=q;i++)
	{
		x[i]=read();
		int qwe=min(query1(1, x[i], 1, n, 1) + x[i], query2(x[i], n, 1, n, 1) - x[i]);
		//int qwe=min(query1(1,1,n,1,x[i])+x[i],query2(1,1,n,x[i],n)-x[i]);
		lazy[1]+=abs(x[i]-x[i-1]);
		min1[1]+=abs(x[i]-x[i-1]);
		min2[1]+=abs(x[i]-x[i-1]);
		update(1,1,n,x[i-1],qwe);
	}
	cout<<getans(1,1,n);
}


Measured memory_bytes: 58368
#include <iostream>
#include <set>

int main() {

	std::set<int> choices = { 1, 2, 3 };

	int A(0);
	int B(0);
	std::cin >> A >> B;

	choices.erase(A);
	choices.erase(B);

	std::cout << *(choices.begin());

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools
import numpy as np

H, W, K = list(map(int, input().split()))
c_table = []

for _ in range(H):
    c_list = input()
    c_list = [0 if c == "." else 1 for c in list(c_list)]
    c_table.append(c_list)

h_patterns = list(itertools.product([True, False], repeat=H))
w_patterns = list(itertools.product([True, False], repeat=W))
count = 0
for h_p in h_patterns:
    for w_p in w_patterns:
        w_table = np.array(c_table)

        for i, h_flag in enumerate(h_p):
            if h_flag:
                w_table[i] = 0
            for j, w_flag in enumerate(w_p):
                if w_flag:
                    w_table.T[j] = 0
        if w_table.sum() == K:
            count += 1

ans = count

print(ans)


Measured memory_bytes: 27232
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
total = 0

for c in list(count.values()):
    total += c*(c-1)/2

for a in A:
    n = count[a]
    before = n*(n-1)/2
    after = (n-1)*(n-2)/2
    ans = total + after - before
    print(int(ans))


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int n, m, a[100001];
string s[101];

int main(){
	cin >> n;
	bool b = 0;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		for(int j = 0; j < i; j++){
			if(s[i] == s[j]){
				b = 1;
			}
		}
		if(i > 0 && s[i][0] != s[i-1][s[i-1].size()-1]) b = 1;
	}
	
	if(b) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

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


#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18+10
#define small -big
#define pb push_back
#define endl "\n"


template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a) {
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}


ll ans[200005];

ll pow(ll a, ll n, ll m) {
    ll res = 1LL;
    
    while(n) {
        if(n % 2) {
            res = (res % m) * (a % m) % m;
        }
        a = (a % m) * (a % m) % m;
        n /= 2;
    }
    
    return res;
}


void solve() {
 
 
   ll N;
   cin >> N;
   
   char A[N + 1];
   
   ll tot = 0;
   
   for(ll i = N - 1; i >= 0; i--) {
       cin >> A[i];
       if(A[i] == '1') {
           tot++;
       }
   }
   
/*   for(ll i = 0; i < N; i++) {
       cout << A[i] << " ";
   }
   cout << endl;
*/
   ans[0] = 0;
   
   for(ll i = 1; i <= 200001; i++) {
          ll g = __builtin_popcountll(i);
          ans[i] = 1LL + ans[i % g];
   }
   
 /*  for(ll i = 0; i <= 10; i++) {
       cout << ans[i] << " ";
   }
   cout <<endl;
   
   */
   
   ll up = 0;
   ll down = 0;

   
   for(ll i = N - 1; i >= 0; i--) {
       if(A[i] == '1') {
        up = ((up % (tot + 1)) + pow(2LL, i, tot + 1)) % (tot + 1);
        if(tot >= 2) {
            down = ((down % (tot - 1)) + pow(2LL, i, tot - 1)) % (tot - 1);
         }
       }
   }
   
  // cout << up << endl;
   //cout << down << endl;
   
    for(ll i = N - 1; i >= 0; i--) {
        if(A[i] == '0') {
            ll up1 = up + pow(2LL, i, tot + 1);
            up1 %= (tot + 1);
            
            cout << ans[up1] + 1 << endl;
        } else{
            if(tot == 1) {
                cout << 0 << endl;
            } else {
                ll down1 = down - pow(2LL, i, tot - 1);
                if(down1 < 0) {
                    down1 += (tot - 1);
                }
                down1 %= (tot - 1);
                 
                cout << ans[down1] + 1 << endl;
            }
        }
   }
   
   
   
  
    
   
    
    
}


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

    int t=1;
    //cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


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

#define int long long int
#define fi first
#define so second
#define ps push_back
#define ld long double
#define mod 1000000007

int check(vector<int> v,int n,int k)
{
    vector<int> p=v,s=v;
    int sum=0,i;
    for(i=1;i<v.size();i++) {p[i]+=p[i-1];}
    sum=0;
    for(i=v.size()-1;i>=0;i--) {s[i]=sum+n-v[i];sum+=n-v[i];}
    for(i=0;i<v.size()-1;i++) if(p[i]==s[i+1] && p[i]<=k) return 1;
    return 0;
}

signed main()
{
    int n,i,k;
    cin>>n>>k;
    int a[n],sum=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];sum+=a[i];
    }
    vector<int> div;
    for(i=1;i<=sqrt(sum);i++)
    {
        if(sum%i==0) {div.ps(i);div.ps(sum/i);}
    }
    sort(div.begin(),div.end());
    //cout<<endl;
    vector<int> v;
    for(i=div.size()-1;i>=0;i--)
    {
        for(int j=0;j<n;j++) {if(a[j]%div[i]!=0) v.ps(a[j]%div[i]);}
        if(v.size()==0) break;
        sort(v.begin(),v.end());
        //cout<<"checking for "<<div[i]<<endl;
        if(check(v,div[i],k)) break;
        v.clear();
    }
    cout<<div[i];

}


Measured memory_bytes: 256
#include<cstdio>

int main()
{
  while(1) {
    int sum_a,sum_b,a,b,i,n;
    scanf("%d",&n);
    if (n == 0) return 0;
    sum_a = 0;
    sum_b = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d",&a,&b);
      if (a > b) {
        sum_a += a + b;
      } else if (b > a) {
        sum_b += a + b;
      } else {
        sum_a += a;
        sum_b += b;
      }
    }
    printf("%d %d\n",sum_a,sum_b);
  }
  return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	int a[3];
	int ans=inf;
	rep(i,0,3)cin>>a[i];
	rep(i,0,3)rep(j,0,3){
		if(i==j)continue;
		ans=min(a[i]+a[j],ans);
	}
	print(ans);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    string ans = "APPROVED";
    
    for(int i = 0;i < N;i++){
         cin >> A[i];
        if(A[i]%2 == 0){
            if(A[i]%3 != 0 && A[i]%5 != 0){
                ans = "DENIED";
                break;
            }
        }
    }
    cout << ans << endl;
        
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define free(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%lld", &n)
#define sff(a,b) scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define in insert
#define bs binary_search
#define le length()
const ll max_i=1e16+7;
#define np(s) next_permutation(s.begin(),s.end())
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
//it gives the lexicographically smallest string//


void solve()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int t=1;
  //cin>>t;
  while(t--){
 int n,k,ans=0;
 cin>>n>>k;
 int arr[n];
 for(int i=0;i<n;i++) cin>>arr[i];
  sort(arr,arr+n);
 for(int i=0;i<k;i++) ans+=arr[i];
  cout<<ans;
  }
}

int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input1.txt", "r",stdin);
  freopen("output1.txt","w",stdout);
  #endif
  solve();
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> S;
    if (S.front() != S.back()) {
        if (S.size() & 1) {
            cout << "First" << endl;
        } else {
            cout << "Second" << endl;
        }
    } else {
        if (S.size() & 1) {
            cout << "Second" << endl;
        } else {
            cout << "First" << endl;
        }
    }
}

Measured memory_bytes: 3744