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

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 999999999


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ABC[3];
	REP(i, 3){ cin >> ABC[i]; }
	vector<ll> l(n);
	REP(i, n){ cin >> l[i]; }
	ll ans = INF;
	bool ok;
	ll cost_A, cost_B, cost_C;
	int use;
	ll cnt[3]; // 0: A, 1: B, 2: C
	ll score[3]; // 0: A, 1: B, 2: C
	ll sum;
	REP(i, pow(4, n)){
		ll id = i;
		// 0: used for A, 1: used for B, 2: used for C, 3: not used
		REP(j, 3){ cnt[j] = 0; }
		REP(j, 3){ score[j] = 0; }
		sum = 0;
		REP(j, n){
			use = id%4; id /= 4;
			if (use == 3){ continue; }
			else {score[use] += l[j]; cnt[use]++;}
		}
		if (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0){ continue; }
		REP(j, 3){ sum += 10 * (cnt[j]-1); }
		REP(j, 3){ sum += abs(score[j]-ABC[j]); }
		ans = min(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (a, b, c): (isize, isize, isize);
    input!(a, b, c);
    if c < a + b {
        println!("No");
        return;
    }
    if 4 * a * b < (c - a - b) * (c - a - b) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str1,str2;
  cin >> str1 >> str2;
  int k1 = str1.length();
  int k2 = str2.length();
  if(k1==k2)
  {
    for(int i=0;i<k1;i++)
    {
      cout << str1[i] << str2[i];
    }
    cout << endl;
  }
  else
  {
    if(k1>k2)
    {
      for(int i=0;i<k2;i++)
      {
        cout << str1[i] << str2[i];
      }
      cout << str1[k1-1];
        cout << endl;
    }
    else
    {
      for(int i=0;i<k1;i++)
      {
        cout << str1[i] << str2[i];
      }
      cout << str2[k2-1];
        cout << endl;
    }
  }
  return 0;
}


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

using ll = long long;
#define nINF -2000000000000000

int main(){
	
	int n,k;
	cin >> n >> k;
	vector<int> p(n);
	vector<int> c(n);
	int a;
	for(int i=0;i<n;i++){
		cin >> a;
		a--;
		p[i]=a;
	}
	for(int i=0;i<n;i++){
		cin >> a;
		c[i]=a;
	}

	ll ans=nINF;
	for(int start=0;start<n;start++){
		//1repを確認
		vector<int> dist(n,-1);
		int replen=0;
		ll repsum=0;
		int now=start;
		ll nowans=nINF;
		ll nowsum=0;
		ll repmax=nINF;
		while(1){
			now=p[now];
			//cout << now << "→";
			if(dist[now]!=-1) break;
			dist[now]++;
			repsum+=c[now];
			replen++;
			repmax=max(repmax,repsum);
		}
		int reptime=0;
		if(repsum>0) reptime=k/replen;
		int last = replen;
		if(repsum>0)last=k%replen;
		/*cout << "start:" << start << endl;
		cout << "replen:" << replen << endl;
		cout << "repsum:" << repsum << endl;
		cout << "reptime:" << reptime << endl;
		cout << "last:" << last << endl;*/

		//repsum>0ならできるだけ回す
		if(repsum>0) nowsum=repsum*reptime;
		now=start;
		int flag=0;
		if(last==replen){
			flag=1;
			now=p[now];
			nowsum=c[now];
		}
		nowans=nowsum;
		for(int i=flag;i<last;i++){
			now=p[now];
			nowsum+=c[now];
			nowans=max(nowans,nowsum);
		}

		//cout << nowans << "→";
		if(repsum>0 && reptime>0){
			nowans=max(nowans,repsum*(reptime-1)+repmax);
		}
		//nowans=max(nowans,repsum*max(0,reptime-1)+repmax);
		//cout << "nowans:" << nowans <<  endl;
		ans=max(ans,nowans);
		//cout << "ans:" << ans << endl << endl;
	}

	cout << ans << endl;
}



Measured memory_bytes: 3684
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N, A, B; 
  ll X, result = 0;
  cin >> N >> A >> B >> X;
  for (int i = 1; i < N; i++) {
    ll nextX;
    cin >> nextX;
    if ((nextX - X) * A > B) result += B;
    else result += (nextX - X) * A;
    X = nextX;
  }
  cout << result << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] a = new int[n][m];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    int[] b = new int[m];
    for(int i = 0; i < m; i++) {
      b[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i++) {
      int c = 0;
      for(int j = 0; j < m; j++) {
        c += a[i][j] * b[j];
      }
      System.out.println(c);
    }
  }
}



Measured memory_bytes: 40808
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  for(var i = 0, len = input.length; i < len; i++){
    if(input[i] == '0 0')
      break;

    var c = input[i].split(' ');
    var n = c[0], s = c[1];

    var pattern = 0;
    
    for(var a=9;a>=n-1;a--){
      pattern += conv(a, s - a, n - 1);
    }
    console.log(pattern);
  }
}

function conv(start, dist, limit){
  var result = 0;
  
  if(limit == 0 && dist == 0)
    return 1;

  if(start < 0 || dist < 0 || limit < 0)
    return result;

  for(var i = start - 1; i >= limit - 1; i--){
    result += conv(i, dist - i, limit - 1);
  }

  return result;
}

Measured memory_bytes: 8496
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = list(map(int, input().split()))

  buy = []
  sell = []

  iflag = False
  if A[0] < A[1]:
    iflag = True
    buy.append(0)
  else:
    iflag = False

  for i in range(2, N):
    if iflag and A[i-1] < A[i]:
      iflag = True

    elif iflag and A[i-1] > A[i]:
      iflag = False
      sell.append(i-1)

    elif not(iflag) and A[i-1] < A[i]:
      iflag = True
      buy.append(i-1)

    elif not(iflag) and A[i-1] > A[i]:
      iflag = False

    else:
      continue

  if iflag:
    sell.append(N-1)

  # print(buy)
  # print(sell)

  m = 1000
  nstack = 0
  for i in range(N):
    if i in buy:
      nbuy = (m//A[i])
      m -= A[i]*nbuy
      nstack += nbuy
    if i in sell:
      m += A[i]*nstack
      nstack = 0
    # print(i, m, nstack)
  print(m)


if(__name__ == '__main__'):
  main()


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

typedef long long ll;
using namespace std;

//class Node{
//public:
//    ll value;
//    Node* parent;
//    Node* leftChild;
//    Node* rightChild;
//    int left;
//    int right;
//    Node(int value,){
//
//    }
//};


bool isPrime(int n){
    if(n < 2){
        return 0;
    }
    if(n%2 == 0){
        return n==2;
    }
    for(int i=3;i*i<=n;i++){
        if(n%i == 0) return 0;
    }
    return 1;
}


int main() {
   int n,k;
   cin>>n>>k;
  //  priority_queue<int> q;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    ll f = 0;
    for(int i=0;i<k;i++) f += v[i];
    cout<<f<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
int n, m, a, b, c, x;
int t[8][8];
int k[8];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		t[a - 1][b - 1]++;
		t[b - 1][a - 1]++;
	}
	for (int i = 0; i < n; i++)k[i] = i;
	a = -1;
	while (1) {
		if (a == -1)goto A;
		a = n - 2;
		while (k[a] > k[a + 1])a--;
		if (!a)break;
		b = a + 1;
		while (b < n && k[b] > k[a])b++;
		c = k[b - 1];
		k[b - 1] = k[a];
		k[a] = c;
		for (int i = a + 1; i < n; i++) {
			if (i < a + n - i) {
				c = k[i];
				k[i] = k[a + n - i];
				k[a + n - i] = c;
			}
		}
		A:
		a = 1;
		for (int i = 0; i < n - 1; i++) {
			if (!t[k[i]][k[i + 1]])a = 0;
		}
		if (a)x++;
	}
	printf("%d\n", x);
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 2010, INF = 1e9;
VI e[N];
int a[N], cnt[N], mi[N], ma[N], d[N];

void dfs(int now, int past){
    cnt[now] = a[now];
    mi[now] = ma[now] = 0;
    for (int next : e[now]){
        if (next == past) continue;
        d[next] = d[now] + 1;
        dfs(next, now);
        cnt[now] += cnt[next];
        mi[next] += cnt[next];
        ma[next] += cnt[next];
        if (ma[now] < mi[next]){
            mi[now] = mi[next] - ma[now];
        }else if (ma[next] < mi[now]){
            mi[now] = mi[now] - ma[next];
        }else{
            mi[now] = (mi[now] + mi[next]) % 2;
        }
        ma[now] = ma[now] + ma[next];

        mi[next] -= cnt[next];
        ma[next] -= cnt[next];
    }
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    REP(i,n) a[i] = s[i] - '0';
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    int ans = INF;
    REP(i,n){
        d[i] = 0;
        dfs(i, -1);
        // REP(j,n) cout << mi[j] << " ";
        // cout << endl;
        if (mi[i] > 0) continue;
        int s = 0;
        REP(j,n) if (a[j]) s += d[j];
        chmin(ans, s / 2);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

int main(){
int N; cin >> N;
  
  vector<ll> A(N); 
  
  bool big_flag = true; //全部0であるかを判定
  
  for(int i = 0; i < N; i++){
    cin >> A[i]; 
    if( A[i] != 0){ big_flag = false;}}
  
  if( N % 3 == 1 || N % 3 == 2){
    if(big_flag){ cout << "Yes" << endl;}
    else{ cout << "No" << endl;}
     
    return 0;  } //Nが、３で割って１ないし２余る数の時は全部0
    
  
  else{
     ll cnt = 0; //何種類出てくるかカウント
     map<ll,ll> mp; mp.clear();
    
    for(ll i = 0; i < N; i++){
      ll x = A[i];
      if( mp[x] == 0){ mp[x]++; cnt++;}
      else{ mp[x]++;}}
    
    if( cnt != 3){ 
      if( cnt >= 4){ cout << "No" <<endl; return 0;}
      else{
        if( cnt == 1){
         if( big_flag){ cout << "Yes" << endl; return 0;}
         else{ cout << "No" << endl; return 0;}}
        else{ 
          if( mp[0] == (N / 3)){ cout << "Yes" << endl; return 0;}
          
          else{ cout << "No" << endl; return 0;}
          
          
          
          
          
          }  
      }
        
              
              
    }
    
      
    
    else{
      vector<ll> s; s.clear();
      for(auto ne : mp){
        if(!( ne.second == 0 || ne.second == (N / 3))){cout << "No" << endl; return 0;}
         
        if( ne.second == N / 3 ){  s.push_back(ne.first);}}
      
      if( (s[0] ^ s[2]) == s[1] && (s[1] ^ s[0]) == s[2] && (s[1] ^ s[2]) == s[0]){ cout<< "Yes" << endl; return 0;}
      else{ cout << "No" << endl; return 0;} } 
  }
 return 0;}


      
        

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  int a, b;
  cin >> a >> b;
  if((a * b) & 1) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)


void solve(){
  int hl, wl, h, w;
  cin >> hl >> wl >> h >> w;
  cout << (hl-h) * (wl-w) << endl;
}

int main(){
  solve();
  return 0;
}
  


Measured memory_bytes: 256
import java.util.Scanner;

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		int N=sc.nextInt();

		int a[];
		a=new int[N];

		for(int i=0;i<N;i++)
			a[i]=sc.nextInt();

		insertionSort(a,N);

	}

	private static void insertionSort(int A[], int N) {

		int v,j;
		
		for(int i=0;i<N-1;i++)
			System.out.print(A[i]+" ");
		System.out.println(A[N-1]);

		for (int i=1;i<N;i++) {
			v = A[i];
			j = i - 1;
			while( j >= 0 &&A[j] > v) {
				A[j+1] = A[j];
				j--;
			}
			A[j+1] = v;

			for(int k=0;k<N-1;k++)
				System.out.print(A[k]+" ");
			System.out.println(A[N-1]);
		}

	}


}


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

int beki(int a,int b){
	int ans=1;
	for(int i=0;i<b;i++){
		ans=ans*a;
	}
	return ans;
}
int main(){
	int a[100];
	int n;
	int ave;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ave+=a[i];
	}
	ave=ave/n;
	int ans=10000000;
	for(int i=-1;i<=1;i++){
		int temp=0;
		for(int j=0;j<n;j++){
			temp+=(a[j]-ave-i)*(a[j]-ave-i);
		}
		if(temp<ans){ans=temp;}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef struct{
    string cry;
    int po;
}To;
 
int main(){
    int i,j,n,c=0;
    while(cin>>n&&n){
        if(c)cout<<endl;
        c++;
        To t[n];
        for(i=0;i<n;i++){
            int w,l,d;
            cin>>t[i].cry>>w>>l>>d;
            t[i].po=w*3+d;
        }
        for(i=0;i<n-1;i++){
            for(j=0;j<n-1;j++){
                if(t[j].po<t[j+1].po){
                    To tmp=t[j];
                    t[j]=t[j+1];
                    t[j+1]=tmp;
                }
            }
        }
        for(i=0;i<n;i++){
            cout<<t[i].cry<<","<<t[i].po<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3056
import java.util.Scanner;

public class Main {
	final static int MAX_N = 100010;
	static int[] par = new int[MAX_N];
	static int[] rank = new int[MAX_N];

	static int[] nums;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		nums = new int[n];
		for(int i = 0; i < n; i++) {
			nums[i] = sc.nextInt()-1;
		}
		init(n);
		for(int i = 0; i < m; i++) {
			unite(sc.nextInt()-1, sc.nextInt()-1);
		}
		long ans = 0L;
		for(int i = 0; i < n; i++) {
			if(root(i)==root(nums[i])) {
				ans++;
			}
		}
		System.out.println(ans);
	}

	static void init(int n) {
		for(int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	static int root(int x) {
		if(par[x]==x) {
			return x;
		} else {
			return par[x] = root(par[x]);
		}
	}
	static boolean same(int x, int y) {
		return root(x)==root(y);
	}
	static void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if(x == y) return;

		if(rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
}

Measured memory_bytes: 91484
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
} 

//FUNCTION  
void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec(N+1);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i+1];
  }
  vector<int> ANS(N+1,0);
  for (int i = N ; i >= 1; i--)
  {
    int COUNT = 0;
    int C = 2;
    while(C*i <= N)
    {
      COUNT += ANS[C*i];
      C++;
    }
    ANS[i] = vec[i]^(COUNT%2);
  }

  int M = 0;
  vector<int> index;
  for (int i = 1; i <= N; i++)
  {
    M += ANS[i];
    if(ANS[i]>0)
    index.push_back(i);
  }
  cout<<M<<endl;
  if(M == 0)return;
  for (int i = 0; i < index.size(); i++)
  {
    if(i != 0)cout<<" ";
    cout<<index[i];
  }
  cout<<endl;
  
  
  
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n >> t;
  vector<int> c(n), tt(n);
  for(int i=0; i<n; i++){
    cin >> c[i] >> tt[i];
  }
  vector<int> real_c;
  for(int i=0; i<n; i++){
    if(tt[i]<=t){
      real_c.push_back(c[i]);
    }
  }
  if(real_c.size() ==0){
    cout << "TLE" << endl;
  }
  else{
    sort(real_c.begin(), real_c.end());
    cout << real_c[0] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  
  ll p = 1;
  for(int i = 1; i <= n; i++){
    p *= i;
    p %= 1000000007;
  }
  
  cout << p;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = 'Yay!'
NO =  ':('

def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    if (b - a > k or c - b > k or d - c > k or e - d > k or 
       c - a > k or d - b > k or e - c > k or d > k or
       d - a > k or e - b > k or e - a > k):
        ret = NO
    else:
        ret = YES
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#import <Foundation/Foundation.h>

int main(void){

     NSAutoreleasePool* pool = [NSAutoreleasePool new];
  	 {
    
        NSStringEncoding enc = NSUTF8StringEncoding;
        NSFileHandle *stdin = [NSFileHandle fileHandleWithStandardInput];
        NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput];
        
        NSData *indata = [stdin readDataToEndOfFile];
        NSMutableString *str = [NSMutableString alloc];
        [str initWithBytes:indata.bytes length:indata.length encoding:enc];
        
        NSScanner *scan = [NSScanner alloc];
        [scan initWithString:str];
        
        NSString *n_str = [NSString alloc];
        [scan scanUpToString:@"\n" intoString:&n_str];
        NSInteger n = [n_str integerValue];
      	
        
        [stdout writeData:[(n<1200?@"ABC":@"ARC") dataUsingEncoding:enc]];
    }
    [pool release];
    return 0;
}

Measured memory_bytes: 2404
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int n=s.size();
    ll ans=0;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
# 2020/01/19
# AtCoder Beginner Contest 152 - B

# Input
a, b = input().split()

sa = ""
sb = ""

# Calc
for i in range(int(a)):
    sa = sa + b
for j in range(int(b)):
    sb = sb + a

if sa < sb:
    ans = sa
else:
    ans = sb

# Output
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  rep(i,n){ 
    int x; cin >> x; 
    mp[x] += 1;
  }
  int ans=0;
  for(auto v:mp){
    if(v.F > v.S){ ans += v.S; }
    if(v.F < v.S){ ans += (v.S-v.F); }
  }
  cout << ans << endl;
  return 0;  
}

Measured memory_bytes: 4736
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            if (str[0] == str[1] && str[0] != str[2]) { Console.WriteLine("Yes"); }
            else if (str[0] == str[2] && str[0] != str[1]) Console.WriteLine("Yes");
            else if (str[1] == str[2] && str[0] != str[1]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function heap(a::Array{Int,1})
	h = [a[1]]
	for i in 2:length(a)
		hpush(h,a[i])
	end
	h
end

function hpush(h::Array{Int,1},x)
	push!(h,x)
	l = length(h)
	if l>1
		k = l>>1
		while h[k]>x&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Int,1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if h[2*k]>=z
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k]>=z&&h[2*k+1]>=z
					break
				else
					t = h[2*k]<h[2*k+1]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function heapb(a::Array{Int,1})
	h = [a[1]]
	for i in 2:length(a)
		hpush(h,a[i])
	end
	h
end

function hpushb(h::Array{Int,1},x)
	push!(h,x)
	l = length(h)
	if l>1
		k = l>>1
		while h[k]<x&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpopb(h::Array{Int,1})
	x = h[1]
	z = pop!(h)
	if length(h)>0
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if h[2*k]<=z
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k]<=z&&h[2*k+1]<=z
					break
				else
					t = h[2*k]<h[2*k+1]?2*k+1:2*k
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end


function main()
	q = readline() |> parseInt
	l = Int[]
	ls = 0
	lt = 0
	r = Int[]
	rs = 0
	rt = 0
	y = 0
	for i in 1:q
		a = readline() |> split |> parseMap
		if a[1] == 1
			y += a[3]
			if ls == 0
				push!(l,a[2])
				ls += 1
				lt += a[2]
			elseif rs == 0
				rs += 1
				if l[1]<a[2]
					push!(r,a[2])
					rt += a[2]
				else
					push!(r,pop!(l))
					push!(l,a[2])
					rt = lt
					lt = a[2]
				end
			else
				lm = hpopb(l)
				rm = hpop(r)
				if ls==rs
					ls += 1
					if rm<a[2]
						hpush(r,a[2])
						hpushb(l,lm)
						hpushb(l,rm)
						lt += rm
						rt += a[2]-rm
					else
						hpush(r,rm)
						hpushb(l,lm)
						hpushb(l,a[2])
						lt += a[2]
					end
				else
					rs += 1
					if a[2]<lm
						hpushb(l,a[2])
						hpush(r,lm)
						hpush(r,rm)
						lt += a[2]-lm
						rt += lm
					else
						hpushb(l,lm)
						hpush(r,rm)
						hpush(r,a[2])
						rt += a[2]
					end
				end
			end
		else
			println(l[1], " ",l[1]*ls-l[1]*rs-lt+rt+y)
		end
	end
end

main()


Measured memory_bytes: 216484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    int a, b;
    cin >> a >> b;
    if (a+b>=10)
        cout << "error" << endl;
    else
        cout << a + b << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := iScan(), iScan()
	m := iScan()
	x, y := make([]int, m), make([]int, m)
	xs, ys := make([][]int, h), make([][]int, w)
	for i := 0; i < h; i++ {
		xs[i] = make([]int, 2)
		xs[i][1] = i
	}
	for i := 0; i < w; i++ {
		ys[i] = make([]int, 2)
		ys[i][1] = i
	}
	d := make(map[[2]int]struct{})
	for i := 0; i < m; i++ {
		x[i], y[i] = iScan()-1, iScan()-1
		xs[x[i]][0]++
		ys[y[i]][0]++
		d[[2]int{x[i], y[i]}] = struct{}{}
	}
	ans := 0
	for i := 0; i < m; i++ {
		ans = larger(ans, xs[x[i]][0]+ys[y[i]][0]-1)
	}
	sort.Slice(xs, func(i, j int) bool { return xs[i][0] > xs[j][0] })
	sort.Slice(ys, func(i, j int) bool { return ys[i][0] > ys[j][0] })
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if _, ok := d[[2]int{xs[i][1], ys[j][1]}]; !ok {
				if xs[i][0]+ys[j][0] > ans {
					ans = xs[i][0] + ys[j][0]
					break
				}
			}
			if xs[i][0]+ys[j][0] <= ans {
				break
			}
		}
	}
	fmt.Println(ans)
}


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

void solve(long long N, std::string S)
{
    int count = 0;
    for (string::size_type pos = 0; (pos = S.find("ABC", pos)) != string::npos; pos += 3)
    {
        count++;
    }
    cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
use input::Input;

fn main() {
    let mut input = Input::default();

    let n = input.parse();

    let mut cnt = vec![0usize; n + 1];
    for i in 1..=n {
        let mut j = i;
        while j <= n {
            cnt[j] += 1;
            j += i;
        }
    }

    let mut ans = 0;
    for (i, x) in cnt.iter().enumerate() {
        ans += i * x;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 80160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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(){
  double R; cin >> R;
  cout << setprecision(22) << 2*R*3.14159265359 << endl;
  return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
vector<int>mp;
vector<int>mps;
int arr[1000001];
int main(){
	int n;
	cin>>n;
	for (int x=0;x<n;x++){
		int a;
		cin>>a;
		mp.push_back(a);
		mps.push_back(a);
		arr[a]++;
	}
	sort(mps.begin(),mps.end());
	for (int x=0;x<n;x++){
		int c=mps[mps.size()-1];
		if (mp[x]==c){
			if (arr[c]==1){
				cout<<mps[mps.size()-2]<<endl;
			}
			else cout<<c<<endl;
		}
		else cout<<c<<endl;
	}
}

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5 + 7;

unordered_map <string, int> ma;
int main()
{
    int n;
    cin>>n;
    string s;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        sort(s.begin(), s.end());
        if(ma[s]) ma[s]++;
        else ma[s] = 1;
    }
    unordered_map <string, int> :: iterator it;
    for(it = ma.begin(); it != ma.end(); it++)
    {
        ll x = it->second;
        ans += x*(x-1)/2;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 10660
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
function gcd(m, n) {
    if (m < n) [m, n] = [n, m]
    let r
    while (n > 0n) {
        r = m % n
        m = n
        n = r
    }
    return m
}

function lcm(m, n) { return m * n / gcd(m, n) }

const Main = () => {
    const n = next()
    let ans = BigInt(next())
    while (hasNext()) {
        ans = lcm(ans, BigInt(next()))
    }
    console.log(ans.toString())
}
Main()


Measured memory_bytes: 29448
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const ll MOD = 1000000007;

int main(void)
{
    cin.sync_with_stdio(false);
    ll N;
    cin >> N;

    vector<ll> prev_loc(2 * 100001, -1);
    vector<ll> dp(N + 10);
    dp[0] = 1;
    FOR(n, 1, N + 1) {
        ll c;
        cin >> c;
        if (n == 1) {
            dp[n] = 1;
        }
        else {
            dp[n] = dp[n - 1];
            if (prev_loc[c] == -1
                || prev_loc[c] == n - 1) {
                // do nothing
            }
            else {
                dp[n] += dp[prev_loc[c]];
                dp[n] %= MOD;
            }
        }
        prev_loc[c] = n;
    }
    cout << dp[N] << endl;

    // REP(n, N + 1) cout << dp[n] << ","; cout << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <iostream>

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;

    for (int i = 1; i < N; i++) {
        ans += (N - 1) / i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
# https://atcoder.jp/contests/abc051/tasks/abc051_b
from collections import defaultdict
k, s = map(int, input().split())

d = defaultdict(int)
for x in range(k + 1):
    for y in range(k + 1):
        d[x + y] += 1

ans = 0
for z in range(k + 1):
    ans += d.get(s - z, 0)
print(ans)

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

int main() {
  //HW入力
 int H, W;
  cin>>H>>W;
  //行列入力
  vector<vector<char>>letter(H,vector<char>(W)); 
  for(int i=0;i<H;i++)
  {for(int j=0;j<W;j++)
  {cin>>letter.at(i).at(j);}}
  //stringに変換
  vector<vector<string>>letters(H,vector<string>(W));
  for(int i=0;i<H;i++)
  {for(int j=0;j<W;j++)
  {letters.at(i).at(j)=letter.at(i).at(j);}}
  //CompressedGyou定義
  vector<string>CompressedGyou(H);
  //列圧縮の準備
  vector<int>RetsuCounter(W);
  for(int i=0;i<H;i++)
  {for(int j=0;j<W;j++)
  {if (letters.at(i).at(j)=="#")
  {RetsuCounter.at(j)++;}
  }}
  //列圧縮
   for(int i=0;i<H;i++)
   {CompressedGyou.at(i)="";
    for(int j=0;j<W;j++)
    {if(RetsuCounter.at(j)>0){CompressedGyou.at(i)+=letters.at(i).at(j);}}}
     
 string sample="";
 for(int i;i<CompressedGyou.at(0).size();i++)
 {sample+=".";}
     
     for(int i;i<H;i++)
     {if(CompressedGyou.at(i)==sample){}
      else{cout<<CompressedGyou.at(i)<<endl;}
     }
                               
  
  
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define  forn(i, n)  for(int i=0; i < (int)n; i++)
using namespace std ;
// #define INPUT_OUTPUT { \
//  freopen("input.txt","r",stdin) ; \
//  freopen("output.txt","w",stdout) ; \
// }
void solve() {
  string s ;
  cin >> s ;
  for(char c : s) {
    if(c == '7'){ 
      cout << "Yes" ;
      return;
    }
  }
  cout << "No" ;
}
int main() {
  // INPUT_OUTPUT ;
  int t=1;
  //cin >> t ;
  while(t--) solve() ;
  return 0 ;
}

Measured memory_bytes: 3572
n = input()
l = map(int, raw_input().split())
ans = []
for i in range(n):
	for j in range(len(l)-1, -1, -1):
		if l[j] == j + 1:
			ans.append(j+1)
			l.pop(j)
			break
if len(ans) != n:
	print -1
else:
	print '\n'.join([str(x) for x in list(reversed(ans))])

Measured memory_bytes: 2568
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>

constexpr int mod = 1000000007;
int main() {
	std::vector<std::vector<int>> power_memo(401, std::vector<int>(401));
	for (auto i = 1; i <= 400; ++i) {
		power_memo[i][0] = 1;
		for (auto j = 1; j <= 400; ++j) {
			power_memo[i][j] = (long long int)i * power_memo[i][j - 1] % mod;
		}
	}
	int n, c; std::cin >> n >> c;
	std::vector<int> lower(n), higher(n);
	for (auto& a : lower) std::cin >> a;
	for (auto& b : higher) std::cin >> b;
	std::vector<long long int> result(c + 1, 0); result[0] = 1;
	for (auto i = 0; i < n; ++i) {
		std::vector<int> memo(c + 1);
		for (auto j = 0; j <= c; ++j) {
			long long int sum{ 0 };
			for (auto a = lower[i]; a <= higher[i]; ++a) {
				sum += power_memo[a][j];
			}
			memo[j] = sum % mod;
		}
		for (int j = c; j >= 0; --j) {
			long long int sum{ 0 };
			for (auto k = 0; k <= j; ++k) {
				sum += result[j - k] * memo[k] % mod;
			}
			result[j] = sum % mod;
		}
	}
	std::cout << result[c] << '\n';
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

void solve() {
    lint n;
    int x, m;
    std::cin >> n >> x >> m;

    auto to = vec(40, vec(m, -1));
    auto sum = vec(40, vec(m, 0LL));
    for (lint i = 0; i < m; ++i) {
        to[0][i] = (i * i) % m;
        sum[0][i] = i;
    }

    for (int k = 0; k + 1 < 40; ++k) {
        for (int i = 0; i < m; ++i) {
            to[k + 1][i] = to[k][to[k][i]];
            sum[k + 1][i] = sum[k][i] + sum[k][to[k][i]];
        }
    }

    lint ans = 0;
    for (int k = 0; k < 40; ++k) {
        if ((~n >> k) & 1) continue;
        ans += sum[k][x];
        x = to[k][x];
    }

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

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

    solve();

    return 0;
}


Measured memory_bytes: 50960
#include <vector>
#include <cassert>

template<typename T, typename F>
struct segment_tree {
    int n;
    F f;
    T zero;
    std::vector<T> data;
    segment_tree(int n, F f, const T &zero) : n(n), f(f), zero(zero), data(n << 1, zero) {}
    template<typename I> segment_tree(I begin, I end, const T &zero, F f) : n(end - begin), data(n << 1) {
        std::copy(begin, end, data.begin() + n);
        for (int i = n - 1; i > 0; i--) { data[i] = f(data[i << 1 | 0], data[i << 1 | 1]); }
    }
    void set(int i, const T &x) {
        assert(0 <= i && i < n);
        data[i += n] = x;
        while (i >>= 1) { data[i] = f(data[i << 1 | 0], data[i << 1 | 1]); }
    }
    T operator[](int i) const { return data[i + n]; }
    T get_sum(int l, int r, T zero) const {
        assert(0 <= l && l < n);
        assert(0 < r && r <= n);
        T a = zero, b = zero;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) { a = f(a, data[l++]); }
            if (r & 1) { b = f(data[--r], b); }
        }
        return f(a, b);
    }
};

#include<bits/stdc++.h>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    auto f = [](int a, int b) { return min(a, b); };
    segment_tree<int, decltype(f)> rmq(n, f, INT_MAX);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) { rmq.set(x, y); }
        else if (com == 1) { cout << rmq.get_sum(x, y + 1, INT_MAX) << endl; }
    }
}


Measured memory_bytes: 3572
from collections import deque
s = input()
s = deque([i for i in s])
q = int(input())
r = False
for _ in range(q):
    qu = input()
    if qu == "1":
        r = not r
    else:
        _, f, c = [i for i in qu.split()]
        if (f != "1") == r:
            s.appendleft(c)
        else:
            s.append(c)

s = "".join(s)
if r:
    s = reversed(s)
print("".join(s))


Measured memory_bytes: 10212
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    string a, b, ans;
    cin >> a >> b;
    ans = b + a;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

#define POS(i,j) ((i)*(m+1)+(j))

void run(void){
  char *s=(char *)calloc(3001,sizeof(char));
  char *t=(char *)calloc(3001,sizeof(char));
  scanf("%s",s);
  scanf("%s",t);
  int n=strlen(s);
  int m=strlen(t);
  short *dp=(short *)calloc((n+1)*(m+1),sizeof(short));
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(s[i]==t[j]){
	dp[POS(i+1,j+1)]=dp[POS(i,j)]+1;
      } else {
	dp[POS(i+1,j+1)]=MAX(dp[POS(i+1,j)],dp[POS(i,j+1)]);
      }
    }
  }
  char *ans=(char *)calloc(3001,sizeof(char));
  int top=0;
  i=n;
  j=m;
  while(i>0 && j>0){
    if(s[i-1]==t[j-1]){
      ans[top++]=s[i-1];
      i--;
      j--;
    } else if(dp[POS(i,j)]==dp[POS(i-1,j)]){
      i--;
    } else {
      j--;
    }
  }
  while(top>0){
    putchar(ans[--top]);
  }
  putchar('\n');
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 17792
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;


int main(){
	string Y="YAKI";
	string s;
	cin>>s;
	
	if(s.size()<4){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<Y.size();i++){
		if(s[i]!=Y[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <cstdio>
#include <cmath>
#include <climits>
#include <iostream>
using namespace std;

//---- Grading
int main(void){
    int m,f,r;
    char grade='F';
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        else if(m==-1 || f==-1){
            grade='F';
        }
        else if(80<=m+f){
            grade='A';
        }
        else if(65<=m+f and m+f<80){
            grade='B';
        }
        else if(50<=m+f and m+f<65){
            grade='C';
        }
        else if(30<=m+f and m+f<50){
            grade='D';
            if(50<=r){grade='C';}
        }
        else if(m+f<30){
            grade='F';
        }
        cout << grade << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3088