akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________
const int N = 3*five;
int row[N],col[N];
vector<int> colm[N];
int rows[N];
int main()
{
       int h,w;
       cin>>h>>w;
       int m;
       cin>>m;
       memset(row,0,sizeof row);
       memset(col,0,sizeof col);
       fri(i,0,m)
       {
              int hh,ww;
              cin>>hh>>ww;
              row[hh]++;
              col[ww]++;
              colm[ww].pb(hh);
       }
       map<int,int> mp;
       fri(i,0,N){
              if(col[i]==0)continue;
              mp[col[i]]++;
       }
       map<int,int> :: iterator it = mp.end();
       --it;
       int mx = it->fr;
       int tot = it->sc;
       memset(rows,0,sizeof rows);
       fri(i,0,N)
       {
              if(col[i]==mx)
              {
                     for(int j : colm[i])
                     {
                            rows[j]++;
                     }
              }
       }
       int ans = 0;
       fri(i,0,N)
       {
              if(row[i])
              {
                     int curr = mx;
                     if(rows[i] == tot)
                     {
                            --curr;
                     }
                     ans = max(ans,curr+row[i]);
              }
       }
       cout<<ans<<endl;
}


Measured memory_bytes: 23548
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N, U, V, M;
    scanf("%d %d %d %d\n", &N, &U, &V, &M);

    int[][] R = new int[][N];
    foreach (i; 0 .. N) R[i] = readln.chomp.split(" ").map!(to!int).array;
    int[][] C = new int[][N];
    foreach (i; 0 .. N) C[i] = readln.chomp.split(" ").map!(to!int).array;

    alias Tuple!(int, "y", int, "x") P;
    P[int] Cmap, Rmap;
    foreach (i; 0 .. N) {
        foreach (j; 0 .. N) {
            Cmap[ C[i][j] ] = P(i, j);
            Rmap[ R[i][j] ] = P(i, j);
        }
    }

    if (N == 1) {
        bool r, c;
        foreach (i; 0 .. M) {
            int v; scanf("%d\n", &v);
            if (v in Rmap && U == 1) r = true;
            if (v in Cmap && V == 1) c = true;
            if (r && c) {
                writeln("DRAW"); return;
            } else if (r) {
                writeln("USAGI"); return;
            } else if (c) {
                writeln("NEKO"); return;
            }
        }
        writeln("DRAW"); return;
    }

    int Rcount, Ccount;
    auto Rrow = new int[N],
         Rcol = new int[N],
         Rdia = new int[2],
         Crow = new int[N],
         Ccol = new int[N],
         Cdia = new int[2];
    Rrow[] = N;
    Rcol[] = N;
    Rdia[] = N;
    Crow[] = N;
    Ccol[] = N;
    Cdia[] = N;
    foreach (_; 0 .. M) {
        int v;
        scanf("%d\n", &v);
        int y, x;
        if (v in Cmap) {
            y = Cmap[v].y; x = Cmap[v].x;
            C[y][x] = 0;
            Ccol[x]--;
            Crow[y]--;
            if (x == y) {
                Cdia[0]--;
                if (Cdia[0] == 0) Ccount++;
            }
            if (x + y == N - 1) {
                Cdia[1]--;
                if (Cdia[1] == 0) Ccount++;
            }
            if (Ccol[x] == 0) Ccount++;
            if (Crow[y] == 0) Ccount++;
        }
        if (v in Rmap) {
            y = Rmap[v].y; x = Rmap[v].x;
            R[y][x] = 0;
            Rcol[x]--;
            Rrow[y]--;
            if (x == y) {
                Rdia[0]--;
                if (Rdia[0] == 0) Rcount++;
            }
            if (x + y == N - 1) {
                Rdia[1]--;
                if (Rdia[1] == 0) Rcount++;
            }
            if (Rcol[x] == 0) Rcount++;
            if (Rrow[y] == 0) Rcount++;
        }
        //writeln([Rcount, Ccount]);
        if (Ccount >= V && Rcount >= U) {
            writeln("DRAW"); return;
        } else if (Ccount >= V) {
            writeln("NEKO"); return;
        } else if (Rcount >= U) {
            writeln("USAGI"); return;
        }
    }
    writeln("DRAW");
}

Measured memory_bytes: 25928
n,m = map(int,input().split())
mi = 0
ma = 200000
for i in range(m):
    l,r = map(int,input().split())
    mi = max(mi,l)
    ma = min(ma,r)
if ma-mi>=0:
    print(ma-mi+1)
else:
    print(0)

Measured memory_bytes: 3188
import fractions

def count_div(x, v, w):
  return w // x - (v - 1) // x

a, b, c, d = map(int, input().split())
e = fractions.gcd(c, d)
print(b - a + 1 - count_div(c, a, b) - count_div(d, a, b) + count_div((c * d) // e, a, b))


Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int solve(int a[], int all_payment, int i)
{
  int ans = all_payment;

  ans += max(a[i-1], a[i+1]) - min(a[i-1], a[i+1]);
  ans -= max(a[i-1], a[i]) - min(a[i-1], a[i]);
  ans -= max(a[i], a[i+1]) - min(a[i], a[i+1]);

  return ans;
}

int main()
{
  int n, tmp, all_payment = 0;
  cin>>n;

  int a[n+2];
  a[0] = 0; a[n+1] = 0;
  FOR(i,1,n+1) {
    cin>>a[i];
  }

  REP(i,n+1) all_payment += max(a[i], a[i+1]) - min(a[i], a[i+1]);

  FOR(i,1,n+1) {
    cout<<solve(a, all_payment, i)<<endl;
  }

  return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
 
 
public class Main{
	
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	final int N = sc.nextInt();
    	for(int tt = 0; tt < N; tt++){
    		char[] input = sc.next().toCharArray();
    		
    		boolean flag = false;
    		for(int i = 0; i < input.length / 2; i++){
    			if(input[i*2] == input[i*2+1]){
    				flag = true;
    				break;
    			}
    		}
    		
    		if(flag){
    			System.out.println("No");
    			continue;
    		}
    		
    		//left-start
    		boolean flag1 = false;
    		for(int i = 0; i < input.length / 2; i++){
    			if(input[i*2] == 'R'){
    				flag1 = true;
    				break;
    			}else if(input[i*2+1] == 'L'){
    				flag1 = true;
    				break;
    			}
    		}
    		
    		boolean flag2 = false;
    		for(int i = 0; i < input.length / 2; i++){
    			if(input[i*2] == 'L'){
    				flag2 = true;
    				break;
    			}else if(input[i*2+1] == 'R'){
    				flag2 = true;
    				break;
    			}
    		}
    		
    		if(flag1 && flag2){
    			System.out.println("No");
    		}else{
    			System.out.println("Yes");
    		}
    		
    	}	
        
    }
     
}

Measured memory_bytes: 26980
from bisect import bisect_left

class SegTree():
    def segfunc(self, x, y):
        return x+y

    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segfunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segfunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segfunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segfunc(res, self.seg[begin])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[begin]), self.seg[end])
        return res

def main():
    lim = int(input())
    s = list(map(int, input().split()))
    n = len(s)
    s.sort()
    f = True
    tmp = [1]*n
    tmp[n-1] = 0
    seg = SegTree(0, tmp)
    st = set()
    st.add(n-1)
    for _ in range(1, lim+1):
        adst = set()
        for v in st:
            u = bisect_left(s, s[v])
            if seg.query(0, u) == 0:
                f = False
                break
            L, R = 0, u
            while L+1 < R:
                P = (L+R)//2
                if seg.query(P, u) > 0:
                    L = P
                else:
                    R = P
            seg.update(L, 0)
            adst.add(L)
        for v in adst:
            st.add(v)
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

using ll = long long;

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

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

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

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

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

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

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

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

    ll a; std::cin >> a;
    long double b; std::cin >> b;
    ll y = round(b*100);
    std::cout << a*y/100 << "\n";
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128_t LL;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 1e5 + 10;
int a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += a[i] >> 1;
        a[i] &= 1;
        if (a[i] && a[i + 1]) {
            ans++;
            a[i]--;
            a[i + 1]--;
        }
    }
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4048
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


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

	string a, b;
	cin >> a >> b;
	int ans = 0;
	for (int len = min(a.size(), b.size()); len > 0; len--) {
		set<array<int, 26>> s;
		array<int, 26> ar;
		ar.fill(0);
		rep(i, len) {
			ar[a[i] - 'a']++;
		}
		s.insert(ar);
		for (int i = len; i < a.size(); i++) {
			ar[a[i - len] - 'a']--;
			ar[a[i] - 'a']++;
			s.insert(ar);
		}

		ar.fill(0);
		rep(i, len) {
			ar[b[i] - 'a']++;
		}
		if (s.count(ar))ans = len;
		else {
			for (int i = len; i < b.size(); i++) {
				ar[b[i - len] - 'a']--;
				ar[b[i] - 'a']++;
				if (s.count(ar)) {
					ans = len;
					break;
				}
			}
		}
		if (ans)break;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3540
<?php
list($n, $a, $b) = ints();
$ans = 0;
for ($i = 1; $i <= $n; ++$i) {
    $num = array_sum(str_split((string) $i));
    if ($num >= $a && $num <= $b) $ans += $i;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int a[1000];
int b[1000];
int c[1000][12];
int dp[1000][1 << 12];
int main(){
  int N;
  int M;
  cin >> N >> M;

  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    for(int j = 0; j < b[i]; j++){
      cin >> c[i][j];
    }
  }

  for(int i = 0; i < M; i++){
    for(int j = 0; j < (1 << N); j++){
      dp[i][j] = INT_MAX;
    }
  }

  int cur_bitset = 0;
  for(int i = 0; i < b[0]; i++){
    cur_bitset = (cur_bitset) | (1 << (c[0][i] - 1));
  }
  dp[0][0] = 0;
  dp[0][cur_bitset] = a[0];

  for(int i = 0; i < M - 1; i++){
    for(int j = 0; j < (1 << N); j++){
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if(dp[i][j] != INT_MAX){
        int next_bitset = j;
        for(int k = 0; k < b[i + 1]; k++){
          next_bitset = next_bitset | (1 << (c[i + 1][k] - 1));
        }
        dp[i + 1][next_bitset] = min(dp[i + 1][next_bitset], a[i + 1] + dp[i][j]);
      }
    }
  }

  int full_bitset = (1 << N) - 1;
  if(dp[M - 1][full_bitset] == INT_MAX){
    cout << - 1 << endl;
  } else {
    cout << dp[M - 1][full_bitset] << endl;
  }

  /*
  for(int i = 0; i < M; i++){
    for(int j = 0; j < (1 << N); j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  return 0;
}


Measured memory_bytes: 16256
#include<iostream>
#include<cstdio>
#define MAX 105
#define INFTY (1<<21)
using namespace std;

void matrixmax(int n, int a[MAX][MAX]) {
    int S[n][n][n], T[n][n];
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            for ( int k = 1; k < n - j + 1; k++ ) {
                if ( k == 1 ) {
                    S[i][j][k] = a[i][j];
                    continue;
                }
                S[i][j][k] = S[i][j][k - 1] + a[i][j + k - 1];
            }
        }
    }
    for ( int j = 0; j < n; j++ ) {
        for ( int k = 1; k < n - j + 1; k++ ) {
            int s[n], maxs = -INFTY;
            for ( int l = 0; l < n; l++ ) {
                if ( l == 0 ) {
                    s[l] = S[0][j][k];
                    continue;
                }
                s[l] = max(S[l][j][k], S[l][j][k] + s[l - 1]);
            }
            for ( int l = 0; l < n; l++ ) maxs = max(maxs, s[l]);
            T[j][k] = maxs;
        }
    }
    int maxt = -INFTY;
    for ( int j = 0; j < n; j++ ) {
        for ( int k = 1; k < n - j + 1; k++ ) {
            maxt = max(maxt, T[j][k]);
        }
    }
    cout << maxt << endl;
}

int main() {
    int n;
    cin >> n;
    int a[MAX][MAX];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);
    }
    matrixmax(n, a);
    return 0;
}


Measured memory_bytes: 7124
#include<iostream>
#include<vector>
#include<algorithm> // sort,reverse,min,lower_bound

using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

void update(vector<double>& E,int a,const vector<vector<int>>& adj){
  double temp=0;
  for(int i: adj.at(a)){
    temp+=E.at(i);
  }
  temp/=adj.at(a).size();
  temp+=1;
  E.at(a)=temp;
}

double calc(vector<double>& E,int a,int b,const vector<vector<int>>& adj){
  int n=E.size();
  vector<double> E2(n);
  vector<int> f(n,0);
  f.at(a)=1;
  for(int i=n-2;i>=a+1;i--){
    E2.at(i)=E.at(i);
  }
  double temp=0;
  for(int j: adj.at(a)){
    if(j==b)continue;
    temp+=E2.at(j);
  }
  temp/=adj.at(a).size()-1;
  temp+=1;
  E2.at(a)=temp;
  
  for(int i=a-1;i>=0;i--){
    int flag=0;
    for(int x:adj.at(i)){
      if(f.at(x)==0)
	continue;
      flag=1;break;
    }
    if(flag==0){
      E2.at(i)=E.at(i);
      continue;
    }
    f.at(i)=1;
    double temp=0;
    for(int j: adj.at(i)){
      temp+=E2.at(j);
    }
    temp/=adj.at(i).size();
    temp+=1;
    E2.at(i)=temp;
    
  }
  return E2.at(0);
}

int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int a,b; cin >>a >>b;a--;b--;
    adj.at(a).push_back(b);
  }
  vector<double> E(n,0);
  E.at(n-1)=0;
  for(int i=n-2;i>=0;i--){
    update(E,i,adj);
  }
  double ans=E.at(0);
  if(df)printf("done(%lf)\n",ans);
  rep(i,n){
    if(df)printf("%d:(size%d)",i,adj.at(i).size());
    if(adj.at(i).size()<=1)continue;
    int am=adj.at(i).at(0);
    
    for(int x: adj.at(i)){
      if(df)printf("%lf ",E.at(x));
      if(E.at(am)<E.at(x)) am=x;
      // double temp=calc(E,i,x,adj);
      // if(temp<ans)ans=temp;
    }
    if(df) printf("->%d \n",am);
    double temp=calc(E,i,am,adj);
    if(temp<ans)ans=temp;
  }
  printf("%.10lf",ans);
}

/// confirm df==0 ///


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll      long long 
#define double      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
#define PI 3.14159265
const int N=300005;
// ll a[N],BIT[N];
// void upd(ll x,ll y)
// {
//     for(;x<N;x+=x&-x)
//         BIT[x]+=y;
// }
// ll get(ll x)
// {
//     ll res=0;
//     for(;x;x-=x&-x)
//         res+=BIT[x];
//     return res;
// }
// void f(ll i,ll l,ll r){
//     ll lo,hi,mid,st,en;
//     lo=0;
//     hi=n-1;
//     st=n;
//     while(lo<=hi){
//         mid=(lo+hi)/2;
//         if(v[mid].F>=l) st=mid,hi=mid-1;
//         else lo=mid+1;
//     }
//     en=-1;
//     while(lo<=hi){
//         mid=(lo+hi)/2;
//         if(v[mid].F<=r) en=mid,lo=mid+1;
//         else hi=mid-1;
//     }
//     for(;st<=en;st++)
//         seg[i].pb(v[st].S);
//     mid=(l+r)/2;
//     f(2*i,l,mid);
//     f(2*i+1,mid+1,r);
// }
// ll g(ll i,ll l,ll r,ll x,ll y){
    
// }
// void run(int t){
//     cin>>n>>q;
//     for(i=0;i<n;i++)cin>>a[i];
//     for(i=0;i<n;i++)
//         v.pb(MP(a[i],i));
    
//     sort(all(v));
//     f(1,1,100000);
//     while(q--){
//         cin>>x>>y;
//         cout<<g(1,1,100000,x,y)<<"\n";
//     }


   


// }
 ll a[N];
void run()
{
    ll n,i,cnt=1;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++){
        if(a[i]==cnt) cnt++;
    }

    ll ans=n-cnt+1;
    if(ans<=n-1) cout<<ans;
    else cout<<-1;

}
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

N,K = inpl()
ll = inpl()
ll.sort(reverse=True)
print(sum(ll[:K]))

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N; cin >> N;
    string s, t;
    cin >> s >> t;

    int ans = N*2;

    rep(i, N) {
        if (s.substr(i, N - i) == t.substr(0, N - i)) {
            ans = N + i;
            break;
        }
    }

    cout << ans << endl;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll ans = 0;
    ll n, d;
    cin >> n >> d;

    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;

        if (x * x + y * y <= d * d) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#define MAX 101
using namespace std;
int main(void){
    int n,A[MAX][MAX]={0};
    cin >> n;
    for(int i=0;i<n;i++){
        int id,adj;
        cin >> id >> adj;
        for(int j=0;j<adj;j++){
            int k;
            cin >> k;
            A[id-1][k-1] = 1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j>0){
                cout << ' ';
            }
            cout << A[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}



int32_t main() {


	int n;
	cin >> n;

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

		if(s=="AC"){
			a[0]++;
		}
		else if(s=="RE"){
			a[3]++;
		}
		else if(s=="TLE"){
			a[2]++;
		}
		else{
			a[1]++;
		}
	}

	cout << "AC x " << a[0] << "\n";
	cout << "WA x " << a[1] << "\n";
	cout << "TLE x " << a[2] << "\n";
	cout << "RE x " << a[3] << "\n";

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 int main(){
 ll n,k, c ;cin>>n>>k>>c ;
 string s; cin>> s; 
 vector<ll> A(k) ;
 ll j=0 ; 
 ll no = 0;
 rep(i,n){
   if(s[i]=='o'&&no==0){
     A[j]=i ;
     no = c ;
     j++ ;
   }
   else{
    if(no>0) no -- ;
   }
   if(j==k) break ;
 }
 reverse(s.begin(),s.end()) ;
 vector<ll> B(k) ;
 j=0 ;
 no=0 ;
 rep(i,n){
   if(s[i]=='o'&&no==0){
     B[j]=i ;
     no = c ;
     j++ ;
   }
   else{
     if(no>0)no -- ;
   }
   if(j==k) break ;
 }

 rep(i,k){
   if(A[i]+B[k-1-i]+1==n) cout<<A[i]+1<<endl ;
 }
   return 0 ;
 }



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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

string s;
ll n;

int main(){
	cin>>s;
  n=s.size();
  ll res=n;
  rep(i,n-1){
    if(s[i]!=s[i+1])minch(res,max(i+1,n-i-1));
  }
  cout<<res<<endl;
	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dp[10000+10][2][101];

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

  string S;
  cin >> S;
  LL D;
  cin >> D;

  int N = SZ(S);
  dp[N][0][0] = dp[N][1][0] = 1;
  for(int i=N-1;i>=0;--i){
    int c = S[i] - '0';
    for(int dc=0;dc<10;++dc){
      for(int d=0;d<D;++d){
        (dp[i][1][(d+dc)%D] += dp[i+1][1][d]) %= MOD;
        if(dc == c) (dp[i][0][(d+dc)%D] += dp[i+1][0][d]) %= MOD;
        else if(dc < c) (dp[i][0][(d+dc)%D] += dp[i+1][1][d]) %= MOD;
      }
    }
  }

  cout << (MOD-1+dp[0][0][0])%MOD << endl;

  return 0;
}


Measured memory_bytes: 16000
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    auto table = new long[][](h, w);
    foreach (ref e; table)
        e = aryread();
    auto p = new Pair[](0);

    long cnt;
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            if (i + 1 >= h && j + 1 >= w)
                break;

            if ((j / w) % 2)
            {
                // right to left
                if ((w - j - 2) > 0)
                {
                    table[i][(w - 1 - j)]--, table[i][(w - j - 2)]++;
                    p ~= [Pair(i + 1, w - j), Pair(i + 1, w - j - 1)];
                }
                else
                {
                    table[i][(w - 1 - j)]--, table[i + 1][(w - j - 1)]++;
                    p ~= [Pair(i + 1, w - j), Pair(i + 2, w - j)];
                }
                cnt++;
            }
            else
            {
                // left to right
                if (table[i][j] % 2)
                {
                    if (j + 1 < w)
                    {
                        table[i][j]--, table[i][j + 1]++;
                        p ~= [Pair(i + 1, j + 1), Pair(i + 1, j + 2)];
                    }
                    else
                    {
                        table[i][j]--, table[i + 1][j]++;
                        p ~= [Pair(i + 1, j + 1), Pair(i + 2, j + 1)];
                    }
                    cnt++;
                }
            }
        }
    }
    cnt.writeln();
    foreach (i; iota(cnt))
    {
        writefln("%s %s %s %s", p[2 * i].x, p[2 * i].y, p[2 * i + 1].x, p[2 * i + 1].y);
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main(){

    #ifndef ONLINE_JUDGE
    freopen( "input.txt", "r", stdin);
    #endif

    string s,t;
    cin >> s >> t;
    int flag=0;
    
    for(int i=0;i<s.size();i++){
        if(s[i]==t[i]) continue;
        else {
            flag=1;
            break;
        }
    }

        if(flag==0){
            cout << "Yes\n";
        } 
        else cout << "No\n";
    

    return 0;
}

Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n, m int
	con.Scan(&n, &m)
	if n > m {
		n, m = m, n
	}
	if m > n+1 {
		con.Println(0)
		return nil
	}
	mod := int(1e9 + 7)
	p := 1
	for i := 1; i <= n; i++ {
		p *= i
		p %= mod
	}
	for i := 1; i <= m; i++ {
		p *= i
		p %= mod
	}
	if n == m {
		p = p + p
		p %= mod
	}
	con.Println(p)
	return nil
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        if ( mp[a] == 0 ) {
            mp[a] = 1;
        }
        else {
            mp[a] = 0;
        }
    }
    ll ans = 0;
    for ( auto num : mp ) {
        if ( num.second != 0 ) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

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

  if((b - a) % 2 == 1){
    cout << min(a + (b - a) / 2, n-b+1 + (n - (a + n-b+1)) / 2) << endl;
  }else{
    cout << (b - a) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n,x,t = invr()
    print(math.ceil(n / x) * t)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
      
  
  
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Measured memory_bytes: 63016
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
bool judge(vector<int>&b);
int main(){
    int n;
    while(scanf("%d",&n),n){
		
        vector<int>b;//satge
		int sum = 0;
		int x = 0;
        for(int i = 0; i < n; i++){
            scanf("%d",&x);
            sum += x;
            b.push_back(x);
        }
		bool f = judge(b);
		if(f){
			puts("0");
			continue;
		}
		bool w = false;
		for(int i = 2; ; i++){
			if(i*(i+1)/2 == sum)break;
			if(i*(i+1)/2 > sum){
				w = true;
				break;
			}
		}
		
		if(w){
			puts("-1");
			continue;
		}
        for(int i = 0; i <= 10000 && !judge(b) ; i++){
            int len = b.size();
            for(int j = 0; j < len; j++)b[j]--;
            b.erase(remove(b.begin(),b.end(),0),b.end());
            b.push_back(len);
			x = i;
        }
		x++;
        printf("%d\n",x > 10000 ? -1 : x);
    }
}
bool judge(vector<int>&b){
	bool f=true;
	int len = b.size();
	for(int i = 0; i < len; i++){
		if(b[i] != i+1){
			f = false;
			break;
		}
	}
	return f;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
int main (){
string a,b;
cin>>a>>b;
if (a[0]=='D'&&b[0]=='D'||a[0]=='H'&&b[0]=='H')cout<<"H";
else if (a[0]=='D'&&b[0]=='H'||a[0]=='H'&&b[0]=='D')cout<<"D";
return 0;
}





Measured memory_bytes: 256
import sys
from sys import stdin,stdout
import math
import time
from functools import lru_cache
from collections import Counter
import heapq
#@lru_cache(maxsize=None) #for optimizing the execution time of callable objects/functions(placed above callable functions)
try:
    for _ in range(1):
        N=int(input())
        if N%9==0:
            print("Yes")
        else:
            print("No")
except EOFError as e:
    print(e)


Measured memory_bytes: 69960
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int count=0;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C')
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,w;
int main()
{
  cin>>n;
  for(int i=sqrt(n);i>=0;i--)if(n%i==0){a=n/i;break;}
  while(a!=0)w++,a/=10;
  cout<<w<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,detA,detB;
  int k=0;
  int i=0;
  cin>>a>>b;
  
  for(i=0;i<=1000000000;i++){
  	detA=abs(a-i);
    detB=abs(b-i);
    if(detA==detB) k=i;
  }

 
  if(k==0)  cout<<"IMPOSSIBLE"<<endl;
  else cout<<k<<endl;
}

Measured memory_bytes: 384
import heapq

enemy_list = [int(i) for i in input().split()]
hp_list = [int(i) for i in input().split()]

if enemy_list[0] == enemy_list[1]:
    print(0)
elif enemy_list[1] == 0:
    print(sum(hp_list))
else:
    print(sum(heapq.nsmallest((len(hp_list) - enemy_list[1]), hp_list)))

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

int main()
{
    ll n;
    cin >> n;
    ll m;
    vector<ll> data(n);
    vector<ll> ans(n);
    rep(i, n) cin >> data[i];
    for (ll i = n; i > 0; i--)
    { //n〜1までの倍数を調べていく
        //ただし、全探索を愚直にしてしまってもギリギリいけそう
        if (2 * i > n)
        {
            ans[i - 1] = data[i - 1];
            if (ans[i - 1] == 1)
            {
                m++;
            }
            continue;
        }
        ll count = 0;
        for (ll j = 2; j * i <= n; j++)
        {
            count += ans[j * i - 1];
        }
        if (count % 2 == data[i - 1])
        {
            ans[i - 1] = 0;
        }
        else
        {
            ans[i - 1] = 1;
            m++;
        }
    }

    cout << m << endl;
    for (ll i = 0; i < ans.size(); i++)
    {
        if (ans[i] == 1)
        {
            cout << i + 1<<" ";
        }
    }
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> p;
  UF(int n) : p(n, -1) {}
  int r(int x) {
    if (p[x] < 0) return x;
    return p[x] = r(p[x]);
  }
  void m(int x, int y) {
    x = r(x); y = r(y);
    if (x == y) return;
    if (-p[x] > -p[y]) swap(x, y);
    p[y] += p[x];
    p[x] = y;
  }
};

int main() {
  int n, k, l; cin >> n >> k >> l;
  UF a(n), b(n);
  while (k--) {
    int f, t; cin >> f >> t; f--; t--;
    a.m(f, t);
  }
  while (l--) {
    int f, t; cin >> f >> t; f--; t--;
    b.m(f, t);
  }
  map<pair<int, int>, int> m;
  for (int i = 0; i < n; i++) {
    m[{a.r(i), b.r(i)}]++;
  }
  for (int i = 0; i < n; i++) {
    cout << m[{a.r(i), b.r(i)}] << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  map<int,int> MD;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    MD[x] += 1;
  }
  
  int M;
  cin >> M;
  map<int,int> RD;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    RD[x] += 1;
  }
  
  for (auto m : RD) {
    if (RD[m.first] > MD[m.first]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 18944
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg.slice(1, N + 1).map(n=>parseInt(n));
    const sorted = [...A].sort((a,b)=>b-a);
    
    const max = sorted[0];
    const second = sorted[1];
    
    let answer = [];
    
    for(let i in A) {
        if(max === A[i]) {
            answer.push(second);
        } else {
            answer.push(max);
        }
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 60976
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    if a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MOD=998244353,MAX_N=2e5;
ll N,M,K,fact[MAX_N+1],ifact[MAX_N+1];
ll cmb(ll n,ll m){
	return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;
}
ll mpw(ll n,ll m){
	ll ret=1;
	while(m){
		if(m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		m>>=1;
		n%=MOD;
	}
	return ret;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
int main(){
	cin>>N>>M>>K;
	fact[0]=1;
	REP(i,N){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	ifact[N]=minv(fact[N]);
	for(ll i=N-1;i>=0;i--){
		ifact[i]=ifact[i+1]*(i+1)%MOD;
	}
	ll ans=0;
	REP(i,min(N,K+1)){
		ans+=cmb(N-1,i)*mpw(M-1,N-1-i)%MOD*M;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6708
n = int(input())
c = input()

head = 0
tail = n-1
cnt = 0

while head < tail:
  if c[tail] == "R":
    while c[head] == "R" and head != tail:
      head += 1
    if head != tail:
      head += 1
      cnt += 1
  tail -= 1
  
print(cnt)

Measured memory_bytes: 9280
w = [str(input()) for i in range(5)]
num = ['0','9','8','7','6','5','4','3','2','1']
w1 = []
m = 0
t = 0
for h in w:
    for j in num:
        if h[-1] == j:
            w1.append(int(h)+num.index(j))
            if m <= num.index(j):
                m = num.index(j)
                k = w.index(h)
for l in range(5):
    if l != k:
        t += w1[l]
print(t+int(w[k]))

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

// 運賃 Ai <= 50, M = 100 -> 必要最高枚数 = 10000
// dp[頂点][残り枚数] = かかった時間 

using Cost = ll; // time
struct Edge{
    Cost cost;
    int to;
    int fee;
    bool operator>(const Edge &right)const{
        return cost > right.cost;
    }
};


#define MAX_N 50
#define MAX_C 10000
ll dp[MAX_N][MAX_C+1];

int main(void){
    rep(i, MAX_N)rep(j, MAX_C+1) dp[i][j] = 1e16;
    int n, m, s;
    cin >> n >> m >> s;
    vector<vector<Edge>> g(n);
    rep(i,m) {
        ll u,v,fee,cost;
        cin >> u >> v >> fee >> cost;
        u--, v--;
        g[u].push_back((Edge){cost, (int)v, (int)fee});
        g[v].push_back((Edge){cost, (int)u, (int)fee});
    }
    rep(i,n) {
        ll c, d;
        cin >> c >> d;
        g[i].push_back((Edge){d, i, -(int)c});
    }

    dp[0][min(s,MAX_C)] = 0;
    using P = pair<Cost, pair<int, int>>;
    priority_queue<P,vector<P>,greater<P>> qu;

    qu.push({0,{0,min(s,MAX_C)}});
    while(qu.size()){
        P top = qu.top(); qu.pop();
        Cost cost = top.first;
        int cur = top.second.first;
        int rem = top.second.second;
        // debug(cost);
        // debug(cur);
        // debug(rem);

        if(dp[cur][rem] < cost) continue;
        for(Edge e : g[cur]){
            if(rem - e.fee >= 0 && dp[e.to][min(MAX_C, rem - e.fee)] > cost + e.cost) {
                dp[e.to][min(MAX_C, rem - e.fee)] = cost + e.cost;
                qu.push({cost + e.cost, {e.to, min(MAX_C, rem - e.fee)}});
            }
        }
    }
    vector<Cost> res(n, 1e18);
    rep1(i,n-1)rep(j,MAX_C+1){
        res[i] = min(res[i], dp[i][j]);
    }
    rep1(i,n-1){
        cout << res[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 15324