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

int main()
{
	int n,m,count2=0,count1=0,flag=0;
	cin>>n>>m;
	char a[100][100] ;
	int i,j;
	for(i=0;i<n;i++)
	for( j=0;j<m;j++)
	{
	cin>>a[i][j];
	if(a[i][j]=='#')
	count1++;
    }
    i=0;j=0;
	while(i!=n-1 || j!=m-1)
	{
		if(a[i][j]=='#')
		count2++;
		
		if(i!=n-1 && j!=m-1)
		{
			if(a[i][j+1] == '#' && a[i+1][j]=='#')
			{
				flag=1;
				break;
			}
			else if(a[i][j+1]=='#')
			j+=1;
			else if(a[i+1][j] =='#')
			i+=1 ;
			else
			{
				flag=1;
				break;
			}
		}
		else if(i!=n-1)
		{
			if(a[i+1][j]=='#')
			i+=1;
			else
			{
				flag=1;
				break;
			}
			
		}
		else if(j!=m-1)
		{
			if(a[i][j+1]=='#')
			j+=1 ;
			else
			{
				flag=1;
				break;
			}
		}
	}
	count2++;
	//cout<<count1<<" "<<count2<<endl;;
	if(flag==1 || count2!=count1)
	cout<<"Impossible\n";
	else
	cout<<"Possible\n" ;
 	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    vector<int> L(N);
    REP(i, N){
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    int ans = 0;
    REP(i, N-2){
        FOR(j, i+1, N-2){
            FOR(k, j+1, N-1){
                //cout << L[i] << " " << L[j] << " " << L[k] << endl;
                if(L[i]+L[j] > L[k] and L[j]+L[k] > L[i] and L[i]+L[k] > L[j] and L[i] != L[j] and L[i] != L[k] and L[j] != L[k]){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();

		sc.close();

		if(c-(a+b) < 0) {
			out.println("No");
			return;
		}
		
		if (4*a*b < (c-(a+b))*(c-(a+b))) {
			out.println("Yes");
		} else {
			out.println("No");

		}

	}

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


Measured memory_bytes: 25300
#include <stdio.h>

int main(){
   int n,l,i,j,m,ms,s;
    
   scanf("%d %d",&n,&l);
   s=0;
   for (i=1;i<=n;i++) s+=l+i-1;
   m=s*s;
   for (i=1;i<=n;i++) {
      j=l+i-1;
      if (j*j<m) {
         m=j*j;
         ms=s-j;
      }
   }
   printf("%d\n",ms);
   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 10010
#define F(a,b) for(register int (a)(0);(a)^(b);(a)++)
using namespace std;
int n,a[szxb];
signed main()
{
	scanf("%d",&n);long long x(0),y(0);int t;
	F(i,n){scanf("%d",&a[i]);}
	F(i,n){scanf("%d",&t),((t>a[i])?(x+=((t-a[i])>>1)):(y+=(a[i]-t)));}
	puts(((x>=y)?("Yes"):("No")));
	return 0;
}

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

int main() {
  int a = 0;
  
  string s;
  
  cin >> s;
  
  if(s[0]=='1') a++;
  if(s[1]=='1') a++;
  if(s[2]=='1') a++;
  
  cout << a << endl;
}

Measured memory_bytes: 256
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
template <typename T>
void read(T &x) {
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch)) {
        if (ch == '-') f *= -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#pragma endregion
const int maxn = 1e5 + 5;
int a[maxn], b[maxn], c[maxn], dp[maxn][3];
int main() {
    IO;
    int n;
    cin >> n;
    rep(i, 1, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, 1, n) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

Measured memory_bytes: 5968
A,B = map(int,input().split())
a_min = int((A//0.08)+1)
b_min = int((B//0.1)+1)
a_max = int(((A+1)//0.08)+1)
b_max = int(((B+1)//0.1)+1)
lisa = []
lisb = []
ans = []
for i in range(a_min,a_max):
    lisa.append(i)
for j in range(b_min,b_max):
    lisb.append(j)
for k in lisa:
    for g in lisb:
        if k == g:
            ans.append(k)
if ans != []:
    print(ans[0])
else:
    print("-1")

Measured memory_bytes: 3064
k,n=(int(i) for i in input().split())
l=[int(i) for i in input().split()]
mini=l[n-1]-l[0]
for i in range(1,n-1):
    j=min(k-l[i]+l[i-1],k-l[i+1]+l[i])
    mini=min(mini,j)
print(mini)

Measured memory_bytes: 26436
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define HMAX 52
#define WMAX 52

using namespace std;

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

ll N;
static const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
vector<ll> v;

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end(),greater<>() );
	int ans = 0;
	for (int i = 0; i < v.size(); ++i)
	{
		ans += (i%2 == 0 ? v[i] : -v[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int N;
    cin >> N;
    int a = N/1000;
    int b = (N-a*1000)/100;
    int c = (N-a*1000-b*100)/10;
    int d = N%10;
    if((a==b && b==c) || (b==c && c==d)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
}


Measured memory_bytes: 256
use proconio::input;
 
#[allow(unused_mut)]
fn main() {
    input! {
        n: isize,
        y: isize
    };
    'milion: for a in 0..n + 1 {
        'thousand: for b in 0..n + 1 {
            let c = n - a - b;
            if c < 0 {
                continue 'thousand;
            }
            let sum = 10_000 * a + 5_000 * b + 1_000 * c;
            if sum == y {
                println!("{} {} {}", a, b, c);
                return;
            }
        }
    }
    println!("-1 -1 -1");
}

Measured memory_bytes: 2088
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
    string s;
    int alpha[27]={0};
  cin>>s;
  forn(i,s.size())
  {
    alpha[s[i]-'A']++;
  }
  int cnt[10]={0};
  int no=0;
  forn(i,27)
  {
  if(alpha[i]>0)
  {no++;
cnt[alpha[i]]++;
  }

}
  if(cnt[2]==2&&no==2)
  cout<<"Yes\n";
  else
  cout<<"No\n";


    return 0;
  }


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int i,i0,n,m,a,b,c,d;
    while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    {
        n=min(b,d);
        m=max(a,c);
        if(n-m<0)printf("0\n");
        else printf("%d\n",n-m);
    }
    return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<usize>();
    v.sort();
    v.reverse();

    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i % 2 == 0 {
            alice += v[i];
        } else {
            bob += v[i];
        }
    }
    println!("{}", alice - bob);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>

#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd

using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
	for (T x : s)
		cout << x << " ";
	cout << endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define pi  3.14159265
const ll mod = 1e6;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,t,n,val;
    cin>>t>>k;
    cout<<t*k;
return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		public static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var table = new int[10001];
			for(int x = 1; x<=100; x++) {
				for(int y = 1; y<=100; y++) {
					for(int z = 1; z<=100; z++) {
						var val = x*x+y*y+z*z+x*y+y*z+z*x;
						if(val<=10000) table[val]++;
					}
				}
			}
			var N = cin.ReadInt;
			Console.WriteLine(table.Skip(1).Take(N).Join("\n"));
		}

	}

	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ")
			=> string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
	
}


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;

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

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N; cin >> N;
    bool is_zero = false;
    ll A[N]; 
    REP(i, N) {
        cin >> A[i];
        if (A[i] == 0) is_zero = true;
    }

    ll ans;
    if(is_zero) {
        ans = 0; 
    } else {
        ans = 1;
        REP(i, N) {
            if ((ans * A[i] > (ll)1e18) || (log10(ans) + log10(A[i]) > 18)) {
                ans = -1;
                break;
            }
            ans *= A[i];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int A,B;
ll ans = 0, fac[2000], ifac[2000], po2[2000];
ll sum1[2000][2000], sum2[2000][2000];

ll comb(ll a, ll b) {
    if (b > a) return 0;
    ll tmp = fac[a]*ifac[b] % MOD;
    tmp = tmp*ifac[a-b] % MOD;
    return tmp;
}

ll solve(int numA, int numB) {
    if (numB == 0) return 1;
    
    ll z = 0, tmp = max(numA-numB+1,0);
    
    // rewrite this sum?
    // numA-x+1 <= numB 
    z = sum2[numB-1][numA-tmp]; // sum2[x][y] = sum1[x][y-1]+sum1[x][y-2]+...
    //cout << numB-1 << " " << " " << numA-tmp << " " << z << "\n";
    
    // numB < numA-x+1
    z = (z+tmp*po2[numB-1]) % MOD;
    return z;
}

void test(int x) { // how many A's were used 
    F0R(i,min(B,A-x+1)) ans = (ans+comb(B-1,i)*solve(A-x-i,i)) % MOD;
    // how many more A's were used
}

ll inv (ll x) {
    ll ans = 1, p = MOD-2;
    while (p) {
        if (p&1) ans = (ans*x) % MOD;
        p /= 2;
        x = x*x % MOD;
    }
    return ans;
}

void gen() {
    fac[0] = ifac[0] = 1;
    FOR(i,1,2000) {
        fac[i] = i*fac[i-1] % MOD;
        ifac[i] = inv(fac[i]);
    }
    po2[0] = 1;
    FOR(i,1,2000) po2[i] = 2*po2[i-1] % MOD;
    
    // sum1[i][j] = comb(i,j)+comb(i,j-1)+...
    F0R(i,2000) F0R(j,2000) {
        sum1[i][j] = comb(i,j);
        if (j) sum1[i][j] = (sum1[i][j]+sum1[i][j-1]) % MOD;
    }
    F0R(i,2000) F0R(j,2000) {
        sum2[i][j] = sum1[i][j];
        if (j) sum2[i][j] = (sum2[i][j]+sum2[i][j-1]) % MOD;
    }
}

int main() {
    gen();
	cin >> A >> B;
	F0R(i,A+1) {
	    test(i);
	    //cout << ans << "\n";
	}
	cout << ans;
}

// read!
// ll vs. int!

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

int main(void) {

    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << endl;
    }
    else {
        string sub = s.substr(0, k);
        cout << sub << "..." << endl;
    }


    return 0;

}

Measured memory_bytes: 3624
#include <cstdio>

bool solve(int *A, int m, int i, int n){
	//std::printf("solve\n");
	if(m==0){
		return true;
	}
	else if(m<0){
		return false;
	}
	else{
		if(i==n){
			return false;
		}
		else{
			return (solve(A, m, i+1, n) || solve(A, m-A[i], i+1, n));
		}
	}
}


int main(){

	int n,q,i,m;
	int *A;

	std::scanf("%d", &n);
	A = new int[n];
	for(i=0;i<n;i++){
		std::scanf("%d", &A[i]);
	}
	
	std::scanf("%d", &q);
	for(i=0;i<q;i++){
		std::scanf("%d", &m);
		if(solve(A, m, 0, n)){
			std::printf("yes\n");
		}
		else{
			std::printf("no\n");
		}
	}

	delete[] A;
	return 0;
}

Measured memory_bytes: 2676
fun main(args: Array<String>) {
  var (a, b, c, k) = readLine()!!.split(" ").map{ it.toInt() }
  var count = 0
  for (n in 1..k) {
    if(0 < a) {
      count++
      a -= 1
    } else if (a == 0 && b == 0) {
      count--
      c -= 1
    } else {
      b -= 1
    }
  }
  println(count.toString())
}

Measured memory_bytes: 36688
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        set の最悪計算量は O(N) なので size 指定のほうが若干速い
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :return:
        """
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]


N, M = list(map(int, input().split()))
X, Y, Z = zip(*[list(map(int, input().split())) for _ in range(M)])

uf = UnionFind(size=(N + 1) * 2)
for x, y, z in zip(X, Y, Z):
    uf.unite(x, y)

roots = set()
ans = 0
for i in range(1, N + 1):
    root = uf.find(i)
    if root not in roots:
        roots.add(root)
        ans += 1

print(ans)


Measured memory_bytes: 103380
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
//vector <bool> prime(boolsize,1);
//void seive()
//{
//    ll n=boolsize;
//    prime[0]=prime[1]=0;
//    for(ll i=2;i<=sqrt(boolsize);i++)
//    {
//        if(prime[i]==1)
//        {
//            for(ll j=i*i;j<=n;j+=i)
//            {
//                prime[j]=0;
//            }
//        }
//    }
//}

/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n>>k;
    vi v(n);
    fo(i,n)
        cin>>v[i];
    v.pb(v[n-1]+k+10);
    ll prev=0,ans=0,y,x;
    fo(i,n)
    {
        if(v[i]+k<v[i+1])
        {
            y=v[i]+k;
            x=v[prev];
            ans+=y-x;
            prev=i+1;
        }
    }
    cout<<ans;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

        //fun();
        vfun();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not




Measured memory_bytes: 6368
n = gets.strip.to_i

march = {
    M: 0,
    A: 0,
    R: 0,
    C: 0,
    H: 0
}

n.times do |i|
    s = gets[0].intern
    march[s] += 1 if march.has_key?(s)
end

patterns = 0
march.values.combination(3) {|c|
    patterns += c[0] * c[1] * c[2]
}

puts patterns

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;

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

	cin >> N >> M;
    int acc = 0;
    int wac = 0;
    vector<bool> q(N, false);
    map<int, int> wa;
    rep(i, M) {
        int f; string s;
        cin >> f >> s;
        if (s == "AC") {
            if (!q[f]) {
                q[f] = true;
                acc += 1;
                wac += wa[f];
            }
        } else {
            wa[f]++;
        }
    }

    cout << acc << space << wac << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  ll N;
  cin>>N;
  ll C[N-1],S[N-1],F[N-1];
  for(ll i=0;i<N-1;i++){
    cin>>C[i]>>S[i]>>F[i];
  }

  ll ans=0;  
  for(ll i=0;i<N-1;i++){
    ans=0;
    for(ll j=i;j<N-1;j++){
      if(ans<=S[j]){ans=S[j];}
      else {
        	if(ans%F[j]!=0){
        	ll start=(ll)(ans/F[j]+1);
           //ll start=(ll)((double)(ans/F[j]));
           	ans=start*F[j];
            //cout<<"else ans  "<<ans;
        	}
       }
      ans=ans+C[j];
      //cout<<"c[j]"<<C[j];
      //cout<<"j:"<<j<<"  ans:"<<ans<<endl;
    }
    
    cout<<ans<<endl;
    
  }
  cout<<0<<endl;
  
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#include <iomanip>
#include <map>
#define MAX_N 100
#define INF 10000000

using namespace std;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int n,m,a,b;
int N[100];
string s,t;

void solve() {
    int ans=INF;
    for(int i=0;i<s.length()-2;i++){
        int x=(int)(s[i]-'0')*100+(int)(s[i+1]-'0')*10+(int)(s[i+2]-'0');
        
        if(abs(n-x)<ans){
            ans=abs(n-x);
        }
    }
    cout<<ans<<endl;
}

int main() {
	n=753;
	cin>>s;
	solve();
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int n) {
    // n! を素因数分解
    int[int] factors;
    for (int i = 2; i <= n; i++) {
        int x = i;
        for (int j = 2; j * j <= x; j++) {
            while (x % j == 0) {
                factors[j]++;
                x /= j;
            }
        }
        if (x > 1) factors[x]++;
    }
    // if (factors.empty) return 0;
    // v2.070.1 だと empty でコンパイルエラーになるので、代わりに n = 1 でチェック
    if (n == 1) return 0;

    int[] t; // p_i^k の k の部分
    foreach (k, v; factors) t ~= v;

    // do[i][約数の個数]
    auto dp = new int[][](t.length, 76);
    for (int i = 0; i <= t[0]; i++)
        dp[0][i + 1] = 1;

    for (int i = 1; i < t.length; i++) {
        for (int j = 1; j <= 75; j++) { // i-1 までの約数の個数
            for (int k = 0; k <= t[i]; k++) {
                int x = j * (k + 1);
                if (x <= 75) {
                    dp[i][x] += dp[i - 1][j];
                }
            }
        }
    }

    return dp[t.length - 1][75];
}

void main() {
    int n = readint;
    writeln(calc(n));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    while(m--){
        int k; cin >> k;
        sum += k;
    }
    if(sum > n) cout << -1 << endl;
    else if(sum == n) cout << 0 << endl;
    else cout << n-sum << endl;
    
}




Measured memory_bytes: 3636
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e6+9;
pair<int, pair<int, int> >p[MAX];
int idx[MAX];
int cost,n,m;
void init(int n){
	for(int i=0;i<n;i++){
		idx[i]=i;
	}
}
int findroot(int i){
	while(i!=idx[i]){
		i=idx[i];
	}
	
	return i;
}
void makeunion(int u, int v){
	u=findroot(u);
	v=findroot(v);
	idx[u]=v;
}
void spanning(){
	for(int i=0;i<m;i++){
		int w=p[i].first;
		int u=p[i].second.first;
		int v=p[i].second.second;
		int x=findroot(u);
	    int y=findroot(v);
		if(x!=y){
			makeunion(u,v);
			cost+=w;
		}

	}
}
int main(){
	int i,j;
	cin>>n>>m;
	init(n);
	for(i=0;i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		p[i]=make_pair(z,make_pair(x,y));
	}
	sort(p, p+m);
	spanning();
	cout<<cost<<"\n";


}


Measured memory_bytes: 14856
def main():
    n = int(input())
    s = input()

    ans = 0

    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j), a + 1)
            if b == -1:
                continue
            for k in range(10):
                c = s.find(str(k), b + 1)
                if c == -1:
                    continue
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a * b % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
int dp[102][4][4][4] = {{{0}}};
int ans = 0;
signed main(){
  fast;
   
   int n;
   cin >> n;
    for(int a = 0 ; a<4 ; a++)
      for(int b = 0 ; b<4 ; b++)
        for(int c = 0 ; c<4 ; c++)
          dp[3][a][b][c] = 1;
   dp[3][0][2][1] = 0  , dp[3][0][1][2] = 0 , dp[3][2][0][1] = 0;
   for(int i = 4 ; i <=n ; i++)
    for(int a = 0 ; a<4 ; a++)
      for(int b = 0 ; b<4 ; b++)
        for(int c = 0 ; c<4 ; c++)
          for(int d = 0 ; d< 4 ; d++){
              if((b==0&&c==2&&d==1)||(b==0&&c==1&&d==2)||(b==2&&c==0&&d==1))
                dp[i][b][c][d] = 0;
              else if((a==0&&c==2&&d==1) || (a==0&&b==2&&d==1))
                dp[i][b][c][d] = 0;
              else{
                dp[i][b][c][d] += dp[i-1][a][b][c];
                dp[i][b][c][d] %= mod;
              }
          }
   
   for(int a = 0 ; a<4 ; a++)
      for(int b = 0 ; b<4 ; b++)
        for(int c = 0 ; c<4 ; c++){
            ans += dp[n][a][b][c];
            ans %= mod;
        }

        cout << ans << endl;
}
// agc;  021
// acg;  012
// gac;  201
// a?gc:
// ag?c
// ?agc

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int n; cin >> n;
    ll W; cin >> W;
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    // dp[i][j] := i 番目まで見て 重さの和が j 以下になるように荷物を選んだ時の、価値の最大値
    vector<vector<ll>> dp(n+5, vector<ll>(W+5, 0));
    rep(i, n){
        rep(j, W+1){
            chmax(dp[i+1][j], dp[i][j]);
            if(j-w[i]>=0) chmax(dp[i+1][j], dp[i][j-w[i]]+v[i]);
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


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

using namespace std;


int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    long long int n, m;
    cin>>n>>m;
    long long int total = 0;
    for (int i=0; i<m; i++){
        long long int curr;
        cin>>curr;
        total += curr;  
    }
    if (total > n) cout<<-1;
    else cout<<n-total;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
    int a;
    int b;
    int c=0;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    while(1){
        if(op=='+'){
            c = a+b;
        }
        else if(op == '-'){
            c = a-b;
        }
        else if(op == '*'){
            c = a*b;
        }
        else if(op == '/'){
            c = a/b;
        }
        else if(op == '?'){
            break;
        }
        printf("%d\n",c);
         scanf("%d %c %d",&a,&op,&b);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int c = 0;
		String[] st = sc.nextLine().split(" ");
		int h = Integer.parseInt(st[0]);
		int w = Integer.parseInt(st[1]);
		int[] t = new int[h];
		int[][] n = new int [h][w];
		for(int i = 0;i < h;i++){
			st = sc.nextLine().split(" ");
			for(int k = 0;k < w;k++){
				n[i][k] = Integer.parseInt(st[k]);
			}
		}
		for(int i = 0;i < h;i++){
			for(int k = 0;k < w;k++){
				sb.append(n[i][k]+" ");
				t[i] = c += n[i][k];
			}
			sb.append(c+"\n");
			t[i] = c;
			c = 0;
		}
		for(int i = 0;i < w;i++){
			for(int k = 0;k < h;k++){
				c += n[k][i];
			}
			sb.append(c+" ");
			c = 0;
		}
		for(int i = 0;i < h;i++){
			c += t[i];
		}
		sb.append(c);
		System.out.println(sb);
	}
}

Measured memory_bytes: 31092
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long dp[1000][1000];
int main() {
    int n, k; cin >> n >> k;

    long long ans = k;
    rep(i, n - 1) {
        ans *= k - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=1e5+4;
int mm[N];


int main(){	
	fastio;
	int n,q;cin>>n>>q;
	string s;
	cin>>s;
	int cnt=0;
	FER(i,1,n){
		if(s[i]=='C'&&s[i-1]=='A'){
			cnt++;
		}
		mm[i]=cnt;
	}
	
	while(q--){
		int l,r;cin>>l>>r;
		l--,r--;
		cout<<mm[r]-mm[l]<<endl;
	}

	return 0;
}


Measured memory_bytes: 1488
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        int[] fact;
        int[] invFact;
        int mod = 1000000007;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt() - 1;
            fact = new int[n + 1];
            invFact = new int[n + 1];
            fact[0] = invFact[0] = 1;
            for (int i = 1; i <= n; i++) {
                fact[i] = (int) ((long) fact[i - 1] * i % mod);
            }
            invFact[n] = (int) MathUtils.inv(fact[n], mod);
            for (int i = n - 1; i >= 0; i--) {
                invFact[i] = (int) ((long) invFact[i + 1] * (i + 1) % mod);
            }

            long ans = 0;

            for (int count = 0; count <= n; count++) {
                long add = 1;
                add = choose(count - 1, n - count);
                add = (add * fact[count] % mod * fact[n - count] % mod);
                ans += fact[n] - add;
            }
            out.println((ans % mod + mod) % mod);
        }

        private long choose(int n, int k) {
            if (k < 0 || k > n) {
                return 0;
            }
            return (long) fact[n] * invFact[k] % mod * invFact[n - k] % mod;
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }

    static class MathUtils {
        public static long modPow(long a, long b, long mod) {
            while (a < 0) {
                a += mod;
            }
            long res = 1;
            while (b > 0) {
                if ((b & 1) != 0) {
                    res = res * a % mod;
                }
                a = a * a % mod;
                b >>>= 1;
            }
            return res;
        }

        public static long inv(long a, long mod) {
            return modPow(a, mod - 2, mod);
        }

    }
}



Measured memory_bytes: 29268
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

map<string, long long> m;

int main() {
	int i, j;
	int n;
	cin>>n;
	for(i=1;i<=n;i++){
	    string s;
	    cin>>s;
	    sort(s.begin(), s.end());
	    m[s]++;
	}
	long long ans = 0;
	for(auto p: m) {
	    ans+=(p.second*(p.second-1))/2;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 11136
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int main(void) {
    int num;
    cin >> num;
    vector<int> arr;
    for(int i = 0; i < num; i++) {
        int val;
        cin >> val;
        arr.push_back(val);
    }

    vector<int> ans;
    while(!arr.empty()) {
        int flag = 0;
        for(int i = arr.size()-1; i >= 0; i--) {
            if(arr[i] == i+1) {
                arr.erase(arr.begin() + i);
                debug("%d\n", i+1);
                ans.push_back(i+1);
                flag = 1;
                break;
            }
        }
        if(!flag) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for(auto e: ans) cout << e << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define PB push_back
#define MP make pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;

int W,H,N;
int X1[1001],Y1[1001],X2[1001],Y2[1001];
int fld[2005][2005];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int ans;
vector<int> xs;

int compress(int* x1,int* x2,int w){
    xs.clear();
    for(int i=0;i<N;++i){
        for(int d=-1;d<=1;++d){
            int tx1=x1[i]+d;
            int tx2=x2[i]+d;
            if(0<=tx1&&tx1<w)xs.PB(tx1);
            if(0<=tx2&&tx2<w)xs.PB(tx2);
        }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    for(int i=0;i<N;++i){
        x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
        x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
    }
    return xs.size();
}

signed main(){
    while(1){
        cin>>W>>H;
        if(W==0&&H==0)break;
        cin>>N;
        for(int i=0;i<N;++i){
            cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
        }
        W=compress(X1,X2,W);
        H=compress(Y1,Y2,H);
        for(int i=0;i<N;++i){
            for(int y=Y1[i];y<Y2[i];++y){
                for(int x=X1[i];x<X2[i];++x){
                    fld[y][x]=1;
                }
            }
        }
        for(int y=0;y<H;++y){
            for(int x=0;x<W;++x){
                if(fld[y][x]==1)continue;
                queue<pii> que;
                que.push(pii(x,y));
                fld[y][x]=1;
                while(!que.empty()){
                    pii p=que.front();
                    que.pop();
                    int x=p.FI;
                    int y=p.SE;
                    for(int i=0;i<4;++i){
                        int nx = x+dx[i];
                        int ny = y+dy[i];
                        if(nx<0||nx>=W||ny<0||ny>=H)continue;
                        if(fld[ny][nx]==1)continue;
                        fld[ny][nx]=1;
                        que.push(pii(nx,ny));
                    }
                }
                ans++;
            }
        }
        cout<<ans<<endl;
        memset(fld,0,sizeof(fld));
        ans=0;
    }
}

Measured memory_bytes: 18892
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split()
                .Select(int.Parse).ToArray();

            int result = 0;

            for(int i = 0; i < n; i++)
            {
                if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
                    result++;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28064
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N, M;
    cin >> N >> M;
    priority_queue<pair<i32, i32>, Vec<pair<i32, i32>> > q;
    for (i32 i = 0; i < N; i++) {
        i32 A, B;
        cin >> A >> B;
        q.push(make_pair(B, A));
    }
    Vec<i32> D(M + 1, 0);
    while (!q.empty()) {
        pair<i32, i32> c = q.top();
        q.pop();
        while (c.second > M && !q.empty()) {
            c = q.top();
            q.pop();
        }
        if (c.second > M) break;
        for (i32 j = c.second; j <= M; j++) {
            if (D[j] == 0) {
                D[j] = c.first;
                break;
            }
        }
        if (q.empty()) break;
    }
    i32 sum = 0;
    for (i32 i = 0; i <= M; i++) sum += D[i];
    cout << sum << endl;
}


Measured memory_bytes: 4460