akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

struct fast_input{
  #if local
    static constexpr int input_max = 1e2;
  #else
    static constexpr int input_max = 1e7;
  #endif
  char buf[input_max];
  char* itr;
  fast_input(){fread(buf,1,input_max,stdin);itr=buf;}
  constexpr inline bool isdigit(char* ptr)const noexcept{
    return '0' <= *ptr and *ptr <= '9';
  }
  constexpr inline uint32_t operator()(){
    while(!isdigit(itr))itr++;
    uint32_t num{};
    while(isdigit(itr)){
      num *= 10;
      num += *itr-'0';
      itr++;
    }
    return num;
  }
}in;

struct fast_output{
  #if local
    static constexpr int output_max = 1e2;
  #else
    static constexpr int output_max = 1e7;
  #endif
  char buf[output_max];
  char* itr;
  fast_output(){itr=buf;}
  ~fast_output(){fwrite(buf,1,itr-buf,stdout);}
  void newl(){*itr++='\n';}
  void putc(char c){*itr++=c;}
  void putstr(const char* cs){while(*cs!='\0')*itr++=*cs++;}
  void putstr(std::string const& s){for(char const& c:s)*itr++=c;}
  void putstrln(const char* cs){while(*cs!='\0')*itr++=*cs++;*itr++='\n';}
  void putstrln(std::string const& s){for(char const& c:s)*itr++=c;*itr++='\n';}
  void operator()(uint32_t num){
    if(num==0){*itr++='0';return;}
    char tmp[33];
    int i{};
    while(num){
      tmp[i++] = num%10+'0';
      num /=10;
    }
    while(i--)*itr++=tmp[i];
  }
  void newl(uint32_t num){
    this->operator()(num);
    *itr++='\n';
  }
}out;

#include<atcoder/dsu>
using atcoder::dsu;
 
int main(){
 
  int n{in()},q{in()};
  dsu uni(n);
  while(q--){
    int t{in()};
    if(t)out.newl(uni.same(in(),in()));
    else uni.merge(in(),in());
  }
 
}

Measured memory_bytes: 6384
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
H,W,K = readInts()
cake = [input() for _ in range(H)]
ans = []
no = 0
cnt = 0
for h in range(H):
    if cake[h] == "."*W:
        no += 1
        continue
    else:
        cnt += 1
        same = []
        arrived = False
        for w in range(W):
            if cake[h][w] == "#":
                if not arrived:
                    arrived = True
                else:
                    cnt += 1
            same.append(cnt)
        for _ in range(no+1):
            ans.append(same)
        no = 0
for _ in range(no):
    ans.append(ans[-1])
for a in ans:
    print(*a,sep=" ")


Measured memory_bytes: 7572
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 18:42:33 2019
@author: doppe
"""

N = int(input())

list = [9,0,900,0,90000,0,9000000]
count = 0
i = 0
param = 1
while True:
    if N  < param * 10:
        if i % 2 == 0:
            count += N - param + 1
        break
    else:
        count += list[i]
    i += 1
    param *= 10
print(count)
    

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int eaten;
  
  if (a+b >= c){
    eaten = b+c;
  }
  else {
    if (c<b){
      eaten = 2*c+1;
    }
    else {
      eaten = 2*b+a+1;
    }
  }
  
 cout << eaten << endl;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  int64_t result = -kInf;
  result = max(result, a * c);
  result = max(result, b * d);
  result = max(result, a * d);
  result = max(result, b * c);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3664
s=str(input())
atoz=[]
for i in range(len(s)):
	if(s[i]=="A"):
		a=i
		break
#print(a)


for i in range(a,len(s)):
	atoz.append(s[i])

s_l=list(atoz)
#print(s_l)

r_s=[]
s_l_kep=s_l
for i in (reversed(s_l)):
	#print(i)
	if(i!="Z"):
		s_l.pop()
#		print(s_l)
	else:
		break
#	r_s.append(i)
#print(s_l)
str_s_l=''.join(s_l)
#print(str_s_l)
print(len(str_s_l))

Measured memory_bytes: 6632
/**
 * Created by karayuu on 2019/02/24
 */
fun main(args: Array<String>) {
    val day = readLine()!!
    val (y, m, d) = day.split("/").map { it.toInt() }

    if (y <= 2019 && m <= 4 && d <= 30) {
        println("Heisei")
    } else {
        println("TBD")
    }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li parent[UF_NUM];
inline void init_uf() {
    rep(i, UF_NUM)parent[i] = i;
}

inline li find(li x) {
    if (parent[x] == x)return x;
    else return (parent[x] = find(parent[x]));
}

inline void union_(li x, li y) {
    li parent_x = find(x);
    li parent_y = find(y);
    parent[parent_x] = parent_y;
}

li n, m;

int main() {
    cin >> n >> m;
    init_uf();
    rep(i, m) {
        li x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        union_(x, y);
    }

    set<li> groups;
    rin{
        groups.insert(find(i));
    }
    cout << sz(groups) << endl;

    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int k,x;
	cin>>k>>x;
	int strt = x-k+1;
	int end = x+k-1;
	for(int i=strt; i<=end;i++)
	{
		cout<<i<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c, max, min, total;
	scanf("%d %d %d", &a, &b, &c);
	total = a + b + c;
	if (a > b && a > c)
	{
		max = a;
	}
	else if(b > a && b > c)
	{
		max = b;
	}
	else
	{
		max = c;
	}
	if (a < b && a < c)
	{
		min = a;
	}
	else if(b < a && b < c)
	{
		min = b;
	}
	else
	{
		min = c;
	}
	printf("%d %d %d\n", min, total -max - min, max);
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>

typedef long long int ll;

using namespace std;

int main()
{
  char C,D;
  ll A;

  cin >> C;
  A = (ll)C;
  D = (char)A + 1;



  cout << D << endl;

}

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

int main(){
	int n;
	scanf("%d", &n);
	int min = 2000000, t, A[10001]{};
	r(i, n){
		scanf("%d", &t);
		if(t < min) min = t;
		A[t]++;
	}
	A[min]--;
	cout << min;
	for(int i = min; i < 10001; i++){
		r(j, A[i]){
			cout << ' ' << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3280
import java.util.Scanner;

public class Main{
	static Scanner s = new Scanner(System.in);			//文字の入力

	static int A = s.nextInt();
	static int B = s.nextInt();
	static int C = s.nextInt();
	static int D = s.nextInt();
	static double E = s.nextInt();
	static double F = s.nextInt();
	static int maxsatou = 0;
	static int maxsatousui = 0;
	static double maxnoud = 0;


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

	static void solve() {
		
		for(int i= 0;100*A*i<=F;i++){
			for(int j = 0;100*B*j<=F;j++){
				if(j == 0&&i ==0)j =1;
				
				water((100*A*j)+(100*B*i));
			
			}
		}
		System.out.println(maxsatousui);
		System.out.println((int)maxsatou);
		

		
	}
static void water(double water){
	for(int i= 0;C*i <=F-water;i++){
		for(int j = 0;D*j <=F-water;j++){
			
			
			dps(water, (C*j)+(D*i));
		}
	}
}
	
	
	

	static void dps(double water,double satou){
		if((water+satou <=F) && (100*satou/(water+satou) <= 100*E/(100+E)) && (100*satou/(water+satou) >=maxnoud)){
			maxsatou = (int)satou;
			maxsatousui =(int) (satou + water);
			maxnoud = (100*satou/(water+satou));
			
		}else {
			return;
		}

	}

}




Measured memory_bytes: 21844
n = int(input())
l = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
  b, f, r, v = map(int, input().split())
  l[b - 1][f - 1][r - 1] += v
for b in range(4):
  for f in range(3):
    for r in range(10):
      print(" %d" % l[b][f][r], end = "")
    print("")
  if b != 3:
    print("#" * 20)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
const int N=1410;
int i,j,k,n,m,x,y,t;
struct data{int x,y;}p[N*3];
int f[N][N],vis[N],w[N][N];
void color(int x,int co){
	vis[x]=co;
	if (co==1)p[t].x++;else p[t].y++;
	for (int i=1;i<=n;i++)
		if (w[x][i]){
			if (vis[i]&&vis[i]==co){
				puts("-1");
				exit(0);
			}
			else if (!vis[i]){
				color(i,3-co);
			}
		}
}
int main(){
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		for (j=i+1;j<=n;j++)
			w[i][j]=w[j][i]=1;
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		w[x][y]=w[y][x]=0;
	}
	for (i=1;i<=n;i++)
		if (!vis[i]){
			++t;
			color(i,1);
		}
	f[0][0]=1;
	for (i=1;i<=t;i++)
		for (j=n;j>=0;j--)
			for (k=n;k>=0;k--){
				f[j+p[i].x][k+p[i].y]|=f[j][k];
				f[j+p[i].y][k+p[i].x]|=f[j][k];
			}
	int ans=1013687232;
	for (i=0;i<=n;i++)if (f[i][n-i])ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 13568
#include <stdio.h>
int main(){
  long int a,b,c;
  scanf("%ld %ld %ld",&a,&b,&c);
  
  if(4*a*b<c*c-2*c*(a+b)+(a+b)*(a+b) && c-(a+b)>0){
    printf("Yes");
  }else{
    printf("No");
  }
}

Measured memory_bytes: 128
#ifdef LOCAL_EXEC
#include "include.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define trace(...)
#endif

using LL = long long;

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

	int n; cin >> n;
	cout << ((n - 1) / 2) << endl;

	return 0;
}


Measured memory_bytes: 256
main :: IO()
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ getsolve a b
    
getsolve :: Int -> Int -> String
getsolve 1 1 = "Draw"
getsolve 1 _ = "Alice"
getsolve _ 1 = "Bob"
getsolve a b
    | a > b			= "Alice"
    | a < b			= "Bob"
    | otherwise		= "Draw"

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

int main(){
    int N;
    cin >> N;
    vector<pair<long long, long long>> T(N);
    for(int i = 0; i < N; i++)cin >> T[i].second >> T[i].first;
    sort(T.begin(), T.end());
    
    long long now = 0;
    bool jdg = true;
    for(int i = 0; i < N; i++){
        now += T[i].second;
        if(T[i].first < now){
            jdg = false;
            break;
        }
    }
    cout << ((jdg) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3328
def integerCards(n, m, alist, bclist):

    count = 0
    alist.sort()
    bclist.sort(key=lambda x: x[1], reverse=True)

    for b, c in bclist:
        for _ in range(b):
            if alist[count] < c:
                alist[count] = c
                count += 1
            else:
                break
            if count == n:
                break
        if count == n:
            break

    return sum(alist)

def main():
    n, m = map(int, input().split())
    alist = list(map(int, input().split()))
    bclist = [list(map(int, input().split()))for i in range(m)]
    print(integerCards(n, m, alist, bclist))

if __name__ == '__main__':
    main()

Measured memory_bytes: 33044
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll a[maxn],ans,mx;

int main()
{
	int n=read(); rep(i,1,n) a[i]=read();
	rep(i,1,n)
	{
		mx=max(mx,a[i]);
		ans+=mx-a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5128
<?php
list($h, $w) = ints();
for ($i = 0; $i < $h; ++$i) {
    list($s) = strs();
    echo $s . PHP_EOL . $s . PHP_EOL;
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4604
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
n,k = inpl()
a = sorted(inpl())
res = 0
comb = Combination(10**5+10)
for i in range(n):
    if n-i-1 < k-1: continue
    p = comb(n-i-1,k-1)
    res -= a[i] * p
    res += a[-1-i] * p
    res %= mod
print(res)

Measured memory_bytes: 98968
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<vector<P>> g;
vector<bool> visited;
vector<ll> ans;
vector<ll> x; // the value of each vettex.

int dfs(int v) {
  int res = x[v];
  for (auto e : g[v]) {
    int nv = e.first;
    if (visited[nv]) { continue; }
    visited[nv] = true;
    int r = dfs(nv);
    if (r) { // if r == 1, we must use this edge
      ans.push_back(e.second);
      res ^= r;
    }
  }
  return res;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, m;
  cin >> n >> m;
  g.resize(n+1);
  visited.resize(n+1);
  x.resize(n+1);

  vector<P> a(n); // the pair of [pos, 0 or 1]
  rep(i, n) {
    cin >> a[i].first >> a[i].second;
  }
  sort(all(a));
  x[0] = a[0].second; // same with 0^a[0].second
  rep(i, n-1) {
    x[i+1] = a[i].second ^ a[i+1].second;
  }
  x[n] = a[n-1].second; // same with a[n-1].second^0
  rep(i, m) {
    ll l, r;
    cin >> l >> r;
    ll li = lower_bound(all(a), mp(l, 0ll)) - a.begin();
    ll ri = upper_bound(all(a), mp(r, 1ll)) - a.begin();
    g[li].emplace_back(ri, i);
    g[ri].emplace_back(li, i);
  }

  // Check each connected components in graph
  rep(i, n+1) {
    if (visited[i]) { continue; }
    visited[i] = true;
    if (dfs(i)) { // if 1, we can not make all nodes 0
      cout << -1 << endl;
      return 0;
    }
  }
  sort(all(ans));
  cout << ans.size() << endl;
  rep(i, ans.size()) {
    cout << ans[i] + 1;
    if (i < ans.size()-1) {
      cout << " ";
    }
  }
  cout << endl;

}


Measured memory_bytes: 21884
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    unordered_map<ll, int> mp;
    rep(i,n)mp[a[i]] = i;
    sort(all(a));
    ll ans = 0;
    rep(i,n){
        if((mp[a[i]] & 1) != (i & 1))ans++;
    }
    cout << ans / 2 << endl;
}

Measured memory_bytes: 5156
import math

n = int(input())
count = 0
for i in range(n):
    p = int(input())
    if p == 2 or p == 3:
        count+=1
    else:
        for j in range(2,int(math.sqrt(p))+1):
            if p%j == 0 and p != j:
                break
            if j == int(math.sqrt(p)):
                count += 1
print(count)



Measured memory_bytes: 5668
#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>

int main()
{
  uint64_t N,K;
  std::cin>>N>>K;
  
  std::vector<uint64_t> A(N);
  for(auto &e:A)
    std::cin>>e;
  
  uint64_t pos=1;
  std::vector<uint64_t> firstFoundCount(N, 0);
  uint64_t loopLength=0;
  uint64_t loopStartCount=0;
  for(uint64_t i=1;;i++)
  {
    pos=A[pos-1];
    if(i==K)
    {
      std::cout<<pos<<std::endl;
      return 0;
    }
    if(firstFoundCount[pos-1]!=0)
    {
      loopStartCount=firstFoundCount[pos-1];
      loopLength=i-loopStartCount;
      break;
    }
    firstFoundCount[pos-1]=i;
  }
  
  for(uint64_t i=(K-loopStartCount)%loopLength;i!=0;i--)
  {
    pos=A[pos-1];
  }
  
  std::cout<<pos<<std::endl;
  
  return 0;
}

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

ll mod = 1e9 + 7;

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

    vector<ll> histo(26, 0);
    for (int i = 0; i < n; i++)
    {
        histo[s[i] - 97]++;
    }

    ll result = 1;
    for (int i = 0; i < 26; i++)
    {
        result *= ((histo[i] + 1) % mod);
        result %= mod;
    }
    
    cout << (result - 1) % mod<< endl;
    
    return 0;
}


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

int main(){
	int N, X;
	cin >> N >> X;
	vector<int> m_i(N);

	for(int i = 0; i < N; i++){
		int m;
		cin >> m;
		m_i[i] = m;
	}

	int minimum = 0;
	for(int i = 0; i < N; i++){
		minimum += m_i[i];
	}

	int min = *min_element(m_i.begin(), m_i.end());

	int rest_X = X - minimum;

	int count;
	count = rest_X / min;

	cout << count + N << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

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

int main() {
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	
	cout << max({a*c,a*d,b*c,b*d});
	return 0;
}

Measured memory_bytes: 3628
//
// Created by 吉川純平 on 2019-12-01.
//

#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
//using ull = unsigned long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll partition(vector<ll> &vec,ll p,ll r){
  ll x = vec[r];
  ll i = p - 1;
  for(ll j = p;j <= r;j++){
    if(vec[j] <= x){
      i++;
      swap(vec[i],vec[j]);
    }
  }
  //swap(vec[i],vec[r]);
  return i;
}
int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll tmp = vec[n-1];
  ll piv = partition(vec,0,n-1);
  rep(i,n){
    if(i == piv){
      cout << "[" << vec[i] << "]";
    }else{
      cout << vec[i];
    }
    if(i != n-1){
      cout << " ";
    }
  }
  cout << endl;
}



Measured memory_bytes: 3544
#include<iostream>
#include<stdio.h>
#include<map>
#include<math.h>
using namespace std;
int a[1000002];
int mins=0;
map<long long ,long long >ss;
int main()
{
    int x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;

	return 0;
}


Measured memory_bytes: 256
a, b, c = (int(x) for x in input().split())

ans = ''

if a == b and a != c :
 ans = 'Yes'
elif a == c and a != b :
 ans = 'Yes'
elif b == c and a != b :
 ans = 'Yes'
else:
 ans = 'No'

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FKS 8002
using namespace std;
int x,y,sum[2];
bool okx[2][16005],oky[2][16005];
char s[8005];
int main(){
	scanf("%s%d%d",s+1,&x,&y);
	int len=strlen(s+1),S=0,fl=0,tg=0;
	int cs1=0,cs2=0;
	okx[cs1][FKS]=oky[cs2][FKS]=1;
	s[++len]='T';
	for (int p=1;p<=len;p++)
		if (s[p]=='T'){
			if (fl==0){
				memset(okx[cs1^1],0,sizeof(okx[cs1^1]));
				for (int i=0;i+S<16005;i++)
					okx[cs1^1][i+S]|=okx[cs1][i];
				if (tg)
					for (int i=S;i<16005;i++)
						okx[cs1^1][i-S]|=okx[cs1][i];
				cs1^=1;
			}
			else{
				memset(oky[cs2^1],0,sizeof(oky[cs2^1]));
				for (int i=0;i+S<16005;i++)
					oky[cs2^1][i+S]|=oky[cs2][i];
				if (tg)
					for (int i=S;i<16005;i++)
						oky[cs2^1][i-S]|=oky[cs2][i];
				cs2^=1;
			}
			fl^=1,tg=1; S=0;
			//printf("%d %d\n",cs1,cs2); 
		}
		else if (tg==1) S++;
		else x=x-1;
	if (!okx[cs1][x+FKS])
		puts("No");
	else if (!oky[cs2][y+FKS])
		puts("No");
	else puts("Yes"); 
} 

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;


public class Main {

    int N;
    int[] A,B;

    public void solve() {
        N = nextInt();

        A = new int[N];
        B = new int[N];
        int maxIndex = 0;
        int maxValue = 0;
        for(int i = 0;i < N;i++){
            A[i] = nextInt();
            B[i] = nextInt();

            if(maxIndex < A[i]){
                maxIndex = A[i];
                maxValue = B[i];
            }
        }

        out.println(maxIndex + maxValue);
    }

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

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 43392
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * pow(x, n - 1, mod) % mod);
}
signed main() {
	long long k; cin >> k;
	if (k == 1)cout << 1 << endl;
	else if (k % 2 == 0 || k % 5 == 0)cout << -1 << endl;
	else {
		ll ans = 1;
		ll nam = 7;
		while (nam % k != 0) {
			nam %= k;
			nam += pow(10, ans, k) * 7;
			nam %= k;
			ans++;
		}
			cout << ans << endl;
		
	}
}


Measured memory_bytes: 3604
#include <stdio.h>
#define REP(i, n) for(i = 0; i < n; ++i)
#define FOR(i, a, b) for(i = a; i < b; ++i)

int profit(int Open, int N, int F[N], int P[N][11]){
    int i, x;
    int X, Y;
    int cnt = 0;
    int ret = 0;

    REP(i, N){
        cnt = 0;
        X = F[i] & Open;
        //printf("X:%d\n", X);
        REP(x, 10){
            Y = X;
            Y &= 1;
            if(Y){
                cnt++;
            }
            X >>= 1;
        }
        ret += P[i][cnt];
    }
    return ret;
}

int main(){
    int N, x, y;
    scanf("%d", &N);
    int b;
    int F[N];
    int P[N][11];
    long max = - 1000000009;
    long ret;

    REP(x, N){
        F[x] = 0;
        REP(y, 10){
            scanf("%d", &b);
            F[x] <<= 1;
            F[x] += b;
        }
       // printf("F[%d] = %d\n", x, F[x]);
    }

    REP(x, N){
        REP(y, 11){
            scanf("%d", &P[x][y]);
        }
    }

    FOR(b, 1, 1024){
        ret = profit(b, N, F, P);
        if(max < ret){
            max = ret;
            //printf("ret:%ld bit:%d\n", ret, b);
        }
    }
    printf("%ld\n", max);
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int

	fmt.Scan(&n)
	for i := 3; i <= n; i++ {
		if three(i) {
			fmt.Printf(" %d", i)
		}
	}
	fmt.Println()
}

func three(n int) bool {
	if n%3 == 0 {
		return true
	}

	for ; n > 0; n /= 10 {
		if n%10 == 3 {
			return true
		}
	}
	return false
}



Measured memory_bytes: 1124
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string s;cin >> s;
    int p=0,m=0;
    rep(i, 4)if(s[i]=='+')p++;else m++;
    cout << p-m << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;cin >> n;vector<int> a(n);rep(i,n)cin>>a[i];sort(whole(a));int ans = a[n-1]-a[0];cout << ans << endl;return 0;
}


Measured memory_bytes: 3468
use proconio::input;
//use itertools::Itertools;
use std::cmp;

fn main() {
    input!{a :i128, b:i128, c:i128, d:i128};
    let res = cmp::max(a * c, a * d);
    let res = cmp::max(res, b * c);
    let res = cmp::max(res, b * d);
    println!("{}", res)
}

Measured memory_bytes: 2160
#include <iostream>
using namespace std;
int main(){
    int n,m,l,r,tl=1,tr;
    cin>>tr>>m;
    while(m--){
        cin>>l>>r;
        tl=max(tl,l);
        tr=min(tr,r);
    }
    cout<<max(0,tr-tl+1);
}

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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main()
{
    init;
    int a;
    cin >> a;

    cout << a + (a * a) + (a * a * a);
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdbool.h>

#define N 8
#define F -2
#define NF 1

int row[N],co[N],pos[2*N-1],neg[2*N-1];
bool T[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=F;
    co[i]=F;
  }
  for(i=0;i<N*2-1;i++){
    pos[i]=F;
    neg[i]=F;
  }
}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(T[i][j]){
	if(row[i]!=j)return;
      }
    }
  }

   for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}

void saiki(int i){

  int j;
  
  if(i==N){
    print();
    return;
  }

  for(j=0;j<N;j++){
    if(NF==co[j]||NF==pos[i+j]||NF==neg[i-j+N-1])continue;
    row[i]=j;
    co[j]=NF;
    pos[i+j]=NF;
    neg[i-j+N-1]=NF;

    saiki(i+1);
    
    row[i]=F;
    co[j]=F;
    pos[i+j]=F;
    neg[i-j+N-1]=F;
  }
}

  int main(){
    int i,j,a,b,c;
    
    initialize();

    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	T[i][j]=false;
      }
    }

    scanf("%d",&a);

    for(i=0;i<N;i++){
      scanf("%d%d",&b,&c);
      T[b][c]=true;
    }

    i=0;
    saiki(i);
    
    return 0;
  }

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PER(j,n,a) for (int j=n-1;j>=a;j--)
#define REP(i,a,n) for (int i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define show(x) cout<<(x)<<endl
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef string str;
/*FIN*/
const int MAXN = 1e5;
int n,m,cc,a,b;
V<int> adj[MAXN];
V<bool> vis(MAXN,0);

void dfs(int u) {
	vis[u] = 1;
	for(int v : adj[u]) {
		if(!vis[v])
			dfs(v);
	}
}

int main() {
	FAST;
	cin>>n>>m;
	REP(i,0,m) {
		cin>>a>>b;
		a--;b--;
		adj[a].PB(b);
		adj[b].PB(a);
	}

	cc = 0;
	REP(i,0,n) {
		if(!vis[i]) {
			dfs(i);
			cc++;
		}
	}
	show(cc-1);
	return 0;
}



Measured memory_bytes: 9580
a, b = map(int, input().split())
def isr(si):
    for j in range(0, len(si)//2):
        if si[j] != si[-1-j]:
            return False
    return True

c = 0
for i in range(a, b+1):
    si = str(i)
    if isr(si):
        c += 1
print(c)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	int N, x, y, dt, dxy;	cin >> N;
	vector<int> t(N + 1);
	vector<pair<int, int> > p(N + 1);
	t[0] = 0, p[0] = make_pair(0, 0);
	rep(i, N) {
		cin >> t[i + 1];
		cin >> x >> y;
		p[i + 1] = make_pair(x, y);
	}
	rep(i, N) {
		dt = t[i + 1] - t[i];
		dxy = abs(p[i + 1].first - p[i].first) + abs(p[i + 1].second - p[i].second);
		if (dt < dxy) {
			no;
			return 0;
		}
		if (abs(dt - dxy) % 2 != 0) {
			no;
			return 0;
		}
	}
	yes;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

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

    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    bool f=true;
    if(a[0]!=0) f=false;
    for(int i=1;i<n;i++) if(a[i]>a[i-1]+1) f=false;
    if(!f){
        cout<<-1<<endl;
        return 0;
    }
    ll res=0;
    vector<int> last(n,-1);
    last[0]=0;
    for(int i=1;i<n;i++){
        if(a[i]==0) last[i]=i;
        else if(a[i]>=a[i-1]){
            last[i]=max(i-a[i],last[i-1]);
        }
        else{
            last[i]=i-a[i];
        }
    }
    for(int i=n-1;i>=1;i--){
        if(a[i]>a[i-1]) res++;
        else {
            ll dif=i-last[i];
            res+=dif;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s;
  cin >> s;
  int len  = s.length();
  int cnt  = count(all(s), '0');
  int mini = min(cnt, len - cnt);
  cout << 2 * mini << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i=1; i<n+1; i++) cin >> a[i];
    
    vector<int> ans(n+1);
    vector<int> b;
    
    for (int i=n; i>0; i--){
        int cnt = 0;
        for (int j=i; j < n+1; j+=i){
            if(ans[j]) cnt++;
        }
        
        // cout << cnt << endl;
        if(cnt % 2 == a[i]){}
        else {ans[i] = 1; b.push_back(i);}
        
    }
    cout << b.size() << endl;
    reverse(b.begin(), b.end());
    for (int x: b) cout << x << endl;
    
}


Measured memory_bytes: 5288
#pragma comment(linker, "/STACK:1073741824")

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<fstream>
#include<iterator>
#include<functional>
#include<bitset>
#include<memory>
#include<sstream>
#include<new>
#include<cassert>
#include<iomanip>

using namespace std::placeholders;

typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<bool, bool> pbb;

const int inf = (int)2 * 1e9;
const ll linf = (ll) 1e18 * 8;
const ld eps = 1e-5;
const int mod = (int) 1e9 + 7;

#define it(v) begin(v), end(v)
#define pb push_back
#define eb emplace_back
#define mp std::make_pair
#define fst first
#define scn second
#define sgn(x) (x > 0 ? 1 : (x == 0 ? 0 : -1))

ll res = 0;

vi subarr(vi arr, int s, int f)
{
	vi ret;
	for (int i = s; i < f; i++)
	{
		ret.pb(arr[i]);
	}
	return ret;
}

vi merge(vi left, vi right)
{
	vi ret;
	int pl = 0, pr = 0;
	while (pl != left.size() || pr != right.size())
	{
		if (pl == left.size() || (pr != right.size() && right[pr] < left[pl]))
		{
			res += left.size() - pl;
			ret.pb(right[pr++]);
		}
		else
		{
			ret.pb(left[pl++]);
		}
	}
	return ret;
}

vi solve(vi arr)
{
	if (arr.size() == 1)
		return arr;
	int m = arr.size() / 2;
	return merge(solve(subarr(arr, 0, m)), solve(subarr(arr, m, arr.size())));
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::string s;
	std::cin >> s;
	int n = s.size();
	std::map<char, vi> map;
	for (int i = 0; i < n; i++)
	{
		map[s[i]].pb(i);
	}
	bool flag = false;
	vi dest(n);
	std::vector<pii> pairs;
	for (auto i : map)
	{
		if (i.scn.size() % 2 == 1)
		{
			if (flag)
			{
				std::cout << -1;
				return 0;
			}
			flag = true;
			dest[i.scn[i.scn.size() / 2]] = n / 2;
		}
		for (int j = 0; j < i.scn.size() / 2; j++)
		{
			pairs.eb(i.scn[j], i.scn[i.scn.size() - j - 1]);
		}
	}
	std::sort(it(pairs));
	for (int i = 0; i < pairs.size(); i++)
	{
		dest[pairs[i].fst] = i;
		dest[pairs[i].scn] = n - i - 1;
	}
	solve(dest);
	std::cout << res;
}

Measured memory_bytes: 10604
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    flag = False
    for i in range(1, 10):
        if n % i ==0 and n // i <=9:
            print("Yes")
            flag = True
            break

    if flag == False:
        print("No")
resolve()

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

const int N = 5005;
const int mod = 1e9 + 7;

int n, dp[N][N];
string s;

void add(int &x, int y){
	x += y;
	if (x >= mod){
		x -= mod;
	}
}

int rec(int pos, int sisa){
	if (!sisa){
		return !pos;
	}
	if (pos == N){
		return 0;
	}
	int &ret = dp[pos][sisa];
	if (ret != -1){
		return ret;
	}
	ret = rec(max(0, pos-1), sisa-1);
	add(ret, 2 * rec(pos+1, sisa-1) % mod);
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	memset(dp, -1, sizeof(dp));
	cout << rec((int)s.size(), n) << "\n";
}

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

using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define re return
#define fi first
#define mp make_pair
#define se second
#define sz(a) (int)a.size()
#define prev previ
#define tm tmmm
#define div divv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int ma = 1024 * 1024;
const ll mod = int(1e9) + 7;

int n, m;
map<int, int> qq;

int main() {
	iostream::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	forn (i, n) {
		int a;
		cin >> a;
		qq[a]++;
	}
	cin >> m;
	forn (j, m) {
		int a;
		cin >> a;
		qq[a]--;
		if (qq[a] < 0) {
			cout << "NO\n";
			re 0;
		}
	}
	cout << "YES\n";
}

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


signed main(){
    string A,B;
    cin>>A>>B;
    int ans=1;
    if(A.size()>B.size())ans=0;
    if(A.size()<B.size())ans=2;
    if(A.size()==B.size()){
        for(int i=0;i<A.size();i++){
            if(A[i]>B[i]){
                ans=0;
                break;
            }
            if(A[i]<B[i]){
                ans=2;
                break;
            }

        }
    }
    if(ans==0)cout<<"GREATER"<<endl;
    if(ans==1)cout<<"EQUAL"<<endl;
    if(ans==2)cout<<"LESS"<<endl;
}

Measured memory_bytes: 256
import bisect

n = int(input())
bar = [ int(v) for v in input().split() ]
bar.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect.bisect_right(bar,bar[i]+bar[j]-1) - j - 1
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i).second >> A.at(i).first;
  for (int i = 0; i < N; i++) cin >> B.at(i).first >> B.at(i).second;

  sort(A.rbegin(), A.rend());
  sort(B.begin(), B.end());

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (B.at(i).first > A.at(j).second && B.at(i).second > A.at(j).first) {
        A.at(j).first = 2 * N;
        ans++;
        break;
      }
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def cal(x):
    rr = 0
    for i in range(Q):
        a,b,c,d = query[i]
        if x[b] - x[a] == c:
            rr += d
    return rr

n,m,Q = inpl()
q = deque()
q.append([1])
query = []
for _ in range(Q):
    query.append(inpl())
res = 0
while q:
    now = q.popleft()
    if len(now) == n+1:
        res = max(res, cal(now))
        continue
    for i in range(now[-1],m+1):
        tmp = now + [i]
        q.append(tmp)
print(res)

Measured memory_bytes: 25808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

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

	ll n;
	string a,b,c;
	cin >> n >> a >> b >> c;
	ll ans = 0;
	FOR(i,0,n){
		vector<char> x(3);
		x[0] = a[i];
		x[1] = b[i];
		x[2] = c[i];
		SORT(x);
		if(x[0]==x[1]&&x[1]==x[2]){
			continue;
		}else if(x[0]==x[1]){
			ans++;
		}else if(x[1]==x[2]){
			ans++;
		}else{
			ans+=2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		String t = stdin.next();
		boolean a = false;
		boolean b = false;
		boolean c = false;
		if (t.charAt(0) == 'a') {
			a = true;
		}
		if (t.charAt(0) == 'b') {
			b = true;
		}
		if (t.charAt(0) == 'c') {
			c = true;
		}
		if (t.charAt(1) == 'a') {
			a = true;
		}
		if (t.charAt(1) == 'b') {
			b = true;
		}
		if (t.charAt(1) == 'c') {
			c = true;
		}
		if (t.charAt(2) == 'a') {
			a = true;
		}
		if (t.charAt(2) == 'b') {
			b = true;
		}
		if (t.charAt(2) == 'c') {
			c = true;
		}
		if(a&&b&&c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23252
s = gets.split("")

if (((s[0]==s[1]) and (s[2]==s[3]) and (s[0]!=s[2])) or ((s[0]==s[2]) and (s[1]==s[3]) and (s[0]!=s[1])) or ((s[0]==s[3]) and (s[1]==s[2]) and (s[0]!=s[1])))
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788