akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define NM_MAX (100000)

long long A[NM_MAX];

int pushHeap(long long *list, long long val, int len)
{
    long long tmp, cmp;
    int i, n;
    list[len] = val;

    n = len;

    while(n != 0) {
        i = (n - 1) / 2;
        cmp = list[i];
        if (val >= cmp) {
            tmp = cmp;
            list[i] = val;
            list[n] = cmp;
        }
        n = i;
    }

    return (len + 1);
}

int popHeap(long long *list, long long *val, int len)
{
    long long tmp;
    int i = 0, j;

    *val = list[0];
    list[0] = list[len - 1];

    for (i = 0; ((2 * i) + 1) < (len - 1); ) {
        j = (2 * i) + 1;
        if ((j != len - 1) && (list[j] <= list[j + 1])) {
            j++;
        }
        if (list[i] <= list[j]) {
            tmp = list[i];
            list[i] = list[j];
            list[j] = tmp;
        }
        i = j;
    }

    return (len - 1);
}


int comp(const void *a, const void *b)
{
    long long v1 = *((long long *)a);
    long long v2 = *((long long *)b);

    if (v1 < v2) {
      return 1;
    } else if (v1 > v2) {
      return -1;
    } else {
      return 0;
    }
}

int main(void)
{
    int N, M;
    int i;
    long long val = 0;
    long long tmp;

    scanf("%d %d", &N, &M);
    for (i = 0; i < N; i++) {
        scanf("%d", &tmp);
        pushHeap(A, tmp, i);
    }

    for ( i = 0; i < M; i++) {
       popHeap(A, &tmp, N);
       tmp /= 2;
       pushHeap(A, tmp, (N - 1));
    }

    for (i = 0; i < N; i++) {
        val += A[i];
    }

    printf("%ld",val);

    return 0;
}

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

int main()
{
    string str;
    int i;

    cin >> str;

    for (i = 0; i < 4; i++) {
        cout << str[i];
    }
    cout << ' ';
    for (; i < 12; i++) {
        cout << str[i];
    }
    cout << endl;

    return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int sum[10000005];
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  sum[1] = 1;
  int tailIndex = 1;
  while(sum[tailIndex] < n) {
    sum[tailIndex+1] = sum[tailIndex] + tailIndex+1;
    tailIndex++;
  }
  vector<int> v;
  int current = sum[tailIndex];
  REPRS(i,1,tailIndex) {
    if(n <= current - i) {
      current-=i;
    } else {
      v.PB(i);
    }
  }
  REPROBJ(itr,v) {
    cout << *itr << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x,y,z,w;
  x = c-(d-b);
  y = d+(c-a);
  z = x-(c-a);
  w = y-(d-b);
  cout << x <<" "<< y <<" "<< z << " "<<w << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int money=100000,n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  	money+=money/20;
  	if(money%1000>0)money=money+1000-money%1000;
  }
  printf("%d\n",money);
  return 0;
}

Measured memory_bytes: 592
fun main(args: Array<String>) {

    val n = readLine()?.toInt()!!
    var d = 0
    var x = 0

    readLine()
            ?.split(" ")
            ?.map { it.toInt() }
            .let {
                d = it!![0] - 1
                x = it[1]
            }

    print(
            mutableListOf<Int>()
                    .apply {
                        (0 until n).forEach {
                            add((d / readLine()?.toInt()!!) + 1)
                        }
                    }.sum() + x
    )
}

Measured memory_bytes: 37800
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N, M; cin >> N >> M;
  vector<int> C(N, -1);
  int res = true;
  for (int _ = 0; _ < M; ++_) {
    int s, c; cin >> s >> c;
    if (!res) {
      continue;
    }
    --s;
    if (C[s] == -1) {
      ;
    } else {
      if (C[s] != c) {
        res = false;
        continue;
      }
    }
    C[s] = c;
  }
  if (!res) {
    cout << -1 << CRLF;
    return;
  }
  if (N > 1 && C[0] == 0) {
    cout << -1 << CRLF;
    return;
  }
  if (N > 1 && C[0] == -1) {
    C[0] = 1;
  }
  for (auto& c : C) {
    if (c == -1) {
      c = 0;
    }
  }
  int ans{};
  int bai = 1;
  // int inf = std::pow(10, N) - 1;
  // for (int tmp = 1; tmp <= inf; ++tmp) {
  //   switch(N) {
  //     case 1:
  //       if (C[0] ==)
  //       if (tmp % 10 == C[0]) {
  //         ans = tmp;
  //       }
  //       break;


  //     case 2:
  //       break;
  //     case 3:
  //       break;

  //     default:
  //       abort();
  //   }
  // }
  for (auto it = C.rbegin(); it != C.rend(); ++it) {
    ans += *it * bai;
    bai *= 10;
  }
  if (N > 1 && ans == 0) {
    ans = -1;
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static int[] a;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		a=sc.Ia;
		int lb=0,ub=n,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(Fu(mid)){ub=mid;}
			else{lb=mid;}
		}
		Console.WriteLine("{0}",ub);
	}
	static bool Fu(int n){
		var li=new List<int[]>();
		li.Add(new int[]{0,0});
		for(int i = 1;i<a.Length;i++) {
			if(a[i]<=a[i-1]){
				int p=a[i];
				while(li[li.Count-1][0]>a[i]){li.RemoveAt(li.Count-1);}
				while(li[li.Count-1][0]==p&&li[li.Count-1][1]==n-1){
					li.RemoveAt(li.Count-1);
					p--;
				}
				if(p==0||n==1){return false;}
				if(li[li.Count-1][0]==p){li[li.Count-1][1]++;}
				else{li.Add(new int[]{p,1});}
			}
		}
		return true;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 33500
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
const ll N=5e5+6;
ll bit[N];
void update(ll idx,ll val){
   for(ll i=idx;i<N;i+=i&(-i)){
      bit[i]+=val;
   }return;
}
ll query(ll idx){
   ll res=0;
   if(idx==0)return 0;
   for(ll i=idx;i>0;i-=i&(-i)){
      res+=bit[i];
   }return res;
}
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,q,x,l,r;cin>>n>>q;
         ll a[n+1];
         for(ll i=1;i<=n;i++){
            cin>>a[i];
            update(i,a[i]);
         }
         while(q--){
            cin>>x;
            if(x){
               cin>>l>>r;l++;r++;
               cout<<query(r-1)-query(l-1);
               cout<<"\n";
            }
            else{
               cin>>l>>x;l++;
               update(l,x);
            }
         }
    }
}


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e5+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

int dp[mx],n,a[mx],k;

int solve (int i)
{
    if ( i >= n )
        return 0;
    if ( dp[i]!= -1 )
        return dp[i];

    int ret1 = INT_MAX;
    for(int j=1; j<=k; j++)
    {
        if (i+j<=n )
            ret1 =min(ret1,abs(a[i]-a[i+j])+ solve (i+j));

    }
    dp[i]= ret1;

    return dp[i];
}

int main()
{
    su;

    mem ( dp, -1 );

    cin>>n>>k;

    for ( int i = 1; i <= n; i++ )
    {
        cin >>a[i];
    }

    cout << solve( 1 )<< nl;


    return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  vector<int>S(N);
  S.at(N-1)=0;
  for(int i=N-1;i>0;i--){
    if(H.at(i)-H.at(i-1) > 0){
      S.at(i-1)=0;
    }
    else{
      S.at(i-1) = S.at(i) + 1;
    }
  }
  int MAX = 0;
  for(int i=0;i<N;i++){
    if(S.at(i)>MAX){
      MAX = S.at(i);
    }
  }
  cout << MAX << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  cin >> s;
  ll ans=0;
  rep(i,s.size())if(s[i]=='2')ans++;
  pr(ans);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
//static const ll MOD = 1;
static const ll MAX_L = (ll)1 << 62;

static const ll FACT_SIZE = 1000000;

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

	rep(i, 0, s.size()) {
		if (i + 1 <= s.size() - 1 && s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (i + 2 <= s.size() - 1 && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;

	return 0;
}

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

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;
}
//using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);
//string = to_string(数値)
//int = stoi(文字列)
//(int)(char-'0')
//string = itoa(int)
//円周率: M_PI


int main() {

//////////////

    ll n;
    ll k; cin>>n>>k;
    vector<int> A(n+1);
    rep(i,n) cin>>A[i+1];
    vector<int> visit(n+1);///訪問回数
    visit[1]=0;
    vector<int> teni(n+1);///初訪問が何回目の転移か


    ll cnt=0; ///転移回数
    ll city=1; ///現在地
    for(ll i=0;i<k;++i){
        ++cnt;
        city=A[city]; //次の街

        ++visit[city];
        if(visit[city]>1){
            break;
        }
        teni[city]=cnt;
    }
    if(cnt==k) {
        cout<<city<<endl;
        return 0;
    }
    ll loop = cnt-teni[city]; ///一回のループにかかる回数
    if(loop<1){
        for(ll i=0;i<k;++i){
            city=A[city];
        }
        cout << city << endl;
        return 0;
    }
    ll kaisuu=(k-teni[city])%loop;
    if (kaisuu<0) kaisuu+=loop;

    for(ll i=0;i<kaisuu;++i){
        city=A[city];
    }
    cout << city << endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(var,start,stop,step) for(auto var=start;var<stop;var+=step)
#define vi vector<int>
#define fio  cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr);
 void primeFactors(ll n)  
{ 
     unsigned ll count=0;ll p=0;
    while (n % 2 == 0)  
    {  
         p++;
          n = n/2;  
    }  
    ll i=1;
    ll tot=1;
     while(tot<=p)
     {
          count++;i++;
         tot+=i; 
     }
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
         ll c=0;
        while (n % i == 0)  
        { 
            c++;
             n = n/i;  
        }  
        ll t=1;ll j=1;
     while(t<=c)
     {
          count++;j++;
         t+=j; 
     }
    }  
    if (n > 2)  
          count++;
     cout<<count<<endl;
}

int main()
{
     fio;
     ll n;cin>>n;
     primeFactors(n);
     return 0;
}



Measured memory_bytes: 3700
#include<stdio.h>
#define MAX 2000001
int CountingSort(int);
int A[MAX],B[MAX],C[10001],k;

main(){

  int n;
  int i;

  k=0;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
    if(A[i]>k)
      k=A[i];
  }

  CountingSort(n);

  for(i=1;i<=n;i++){
    printf("%d", B[i]);
    if(i!=n)
      printf(" ");
  }
  printf("\n");

  return 0;

}

int CountingSort(int n){

  int i,j;
  
  for(i=0; i<=k; i++)
    C[i]=0;
  for(j=0; j<n; j++)
    C[A[j]]=C[A[j]]+1;
  for(i=1; i<=k; i++)
    C[i]=C[i]+C[i-1];
  for(j=n-1; j>=0; j--){
    B[C[A[j]]]=A[j];
    C[A[j]]=C[A[j]]-1;
  }
}

Measured memory_bytes: 16268
N = int(input())
dicts = {}
for i in range(N):
    s = "".join(sorted(input()))
    dicts[s] = dicts[s] + 1 if s in dicts.keys() else 1

num = 0
for k, v in dicts.items():
  num += v * (v-1) // 2
print(num)

Measured memory_bytes: 17852
N, M = map(int, input().split())
H = list(map(int, input().split()))
A_B = [list(map(int, input().split())) for i in range(M)]

good = [1 for i in range(1, N+1)]

for i in range(M):
    A = A_B[i][0]
    B = A_B[i][1]
    if H[A-1] > H[B-1]:
        good[B-1] = 0 
    elif H[A-1] == H[B-1]:
        good[A-1] = 0
        good[B-1] = 0
    else:
        good[A-1] = 0

print(sum(good))

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


int main(){
  int n,m,i,ans;
  ans=0;
  cin >> n >> m;
  vector<int> s(m),c(m);
  vector<pair<int,int>> sm(m);
  map<int,int> mp;
  for(i=0;i<m;++i){
    cin >> s[i] >> c[i];
    if(s[i]==1 && c[i]==0 && n>=2){
      ans=-1;
      cout << ans << endl;
      return 0;
    }
    sm[i]=make_pair(s[i],c[i]);
    mp[s[i]]=c[i];
  }
  sort(sm.begin(),sm.end());
  bool ha=true;
  for(i=0;i<m;++i){
    if(sm[i].first==sm[i+1].first){
      if(sm[i].second!=sm[i+1].second){
        ha=false;
      }
    }
  }
  if(ha==true){
    ans=0;
    for(auto p : mp){
      if(n>p.first){
        ans+=pow(10,(n-p.first))*p.second;
      }else{
        ans+=p.second;
      }
    }
    if(n==3 && ans<100){
      ans+=100;
    }else if(n==2 && ans<10){
      ans+=10;
    }
  }else{
    ans=-1;
  }
  if(m==0){
    if(n==1){
      ans=0;
    }else if(n==2){
      ans=10;
    }else{
      ans=100;
    }
  }
  cout << ans << endl;
  return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << string(b + 2, '#') << '\n';
    for (int i = 0; i < a; ++i)
    {
        string s;
        cin >> s;
        cout << "#" << s << "#\n";
    }
    cout << string(b + 2, '#');
}


Measured memory_bytes: 256
# include <algorithm>
using namespace std;

int main() {
    int a_size; scanf("%d", &a_size);
    int a[a_size]; for (int i = 0; i < a_size; ++i) scanf("%d", a + i);
    int num_query; scanf("%d", &num_query);
    int command, begin, end;
    
    for (int i = 0; i < num_query; ++i) {
        scanf("%d%d%d", &command, &begin, &end);
        switch (command) {
            case 0:
                printf("%d\n", *min_element(a + begin, a + end));
                break;
            case 1:
                printf("%d\n", *max_element(a + begin, a + end));
                break;
        }
    }
    
    return 0;
}


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

int main() {
  int N, M, c = 0;
  vector<string> target(200);
  vector<int> sum(200);

  cin >> N;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;

    for (int j = 0; j < N; j++) {
      if (target.at(j) == s) {
        sum.at(j) += 1;
        break;
      }
      
      if (j == i) {
        target.at(c) = s;
        sum.at(c) += 1;
        c++;
        break;
      }
    }
  }

  cin >> M;
  string t;
  for (int i = 0; i < M; i++) {
    cin >> t;

    for (int j = 0; j < N + M; j++) {
      if (target.at(j) == t) {
        sum.at(j) -= 1;
        break;
      }
      
      if (j == i + N) {
        target.at(c) = t;
        sum.at(c) -= 1;
        c++;
        break;
      }
    }
  }

  cout << *std::max_element(sum.begin(), sum.end()) << endl;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	boolean f(char[] cs,int l,int r) {
		boolean ret=true;
		while(l<r) {
			ret&=cs[l]==cs[r-1];
			++l;--r;
		}
		return ret;
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		char[] cs=sc.next().toCharArray();
		int n=cs.length;
		System.out.println(n%2==1&&f(cs,0,n)&&f(cs,0,(n-1)/2)&&f(cs,(n+3)/2-1,n)?"Yes":"No");
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 10000

int main(){
  int n;
  cin >> n;
  int tmp, w1[n+1], w2[n+1], idx[MAX+1], x = MAX, color[MAX+1];
  for ( int i = 0; i < n; i++){
    cin >> tmp ;
    w1[i] = w2[i] = tmp;
    x = min(x, tmp);
    color[i] = 0;
  }

  sort(w2, w2+n);
  for ( int i = 0; i < n; i++ ){
    idx[w2[i]] = i;
  }

  int aSum = 0;
  for ( int i = 0; i < n; i++){
    if ( w1[i] == w2[i] || color[i]) continue;
    int cur = i;
    int Min = w2[i], lSum = 0, lN = 0, nextCorrect = 0;;
    while( 1 ){
      color[cur] = 1;
      Min = min(Min, w2[cur]);
      lSum += w2[cur];
      lN ++;
      cur = idx[w1[cur]];
      if (color[cur]) break;
    }
    aSum += min( Min * (lN - 2) + lSum, x * (lN + 1) + Min + lSum );
  }

  cout << aSum << endl;

  return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(){
  int n, t, i;
  int min=1050;
  scanf("%d %d", &n, &t);
  for(i=0;i<n;i++){
    int a, b;
    scanf("%d %d", &a, &b);
    if(b<=t && a<min)min = a;
  }
  if(min>1000)printf("TLE\n");
  else printf("%d\n", min);
  return 0;
}


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

using namespace std;

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

    string s; cin >> s;
    if(s == "SUN") {
        cout << 7;
    } else if (s == "MON") {
        cout << 6;
    } else if (s == "TUE") {
        cout << 5;
    } else if (s == "WED") {
        cout << 4;
    } else if (s == "THU") {
        cout << 3;
    } else if (s == "FRI") {
        cout << 2;
    } else {
        cout << 1;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,c;
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0){
			break;
		}
		if(a>b){
			c=a;
			a=b;
			b=c;
		}
		printf("%d %d\n",a,b);
	}
	return 0;
	
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long calc(bitset<64> L, bitset<64> R, int d, int lf, int rf){
    //cerr << L << endl;
    //cerr << R << endl;
    //cerr << d << " " << lf << " " << rf << endl;

    long long dp[100][2][2];
    REP(i, 100) REP(j, 2) REP(k, 2)
        dp[i][j][k] = 0;
    dp[d][lf][rf] = 1;
    for(int dd=d; dd>0; dd--){
        for(int x=0; x<2; x++){
            for(int y=0; y<2; y++){
                if(x==1 && y==0) continue;
                for(int l=0; l<2; l++){
                    for(int r=0; r<2; r++){
                        if(l==0 && L[dd-1]==1 && x==0) continue;
                        if(r==0 && R[dd-1]==0 && y==1) continue;
                        int l2 = l;
                        int r2 = r;
                        if(L[dd-1]==0 && x==1) l2 = 1;
                        if(R[dd-1]==1 && y==0) r2 = 1;
                        dp[dd-1][l2][r2] += dp[dd][l][r];
                        dp[dd-1][l2][r2] %= MOD;
                    }
                }
            }
        }
    }
    long long ret = 0;
    REP(i, 2) REP(j, 2){
        ret += dp[0][i][j];
        ret %= MOD;
    }
    return ret;
}

int msb(bitset<64> x){
    for(int i=63; i>=0; i--)
        if(x[i]) return i;
    return -1;
}


int main(){
    long long L, R;
    cin >> L >> R;
    bitset<64> Lb = L, Rb = R;
    long long ans = 0;
    int Lmsb = msb(Lb);
    int Rmsb = msb(Rb);
    if(Lmsb == Rmsb){
        ans = calc(Lb, Rb, Rmsb, 0, 0);
    }else{
        ans = (ans + calc(Lb, Rb, Rmsb, 1, 0)) % MOD;
        ans = (ans + calc(Lb, Rb, Lmsb, 0, 1)) % MOD;
        for(int i=Lmsb+1; i<Rmsb; i++)
            ans = (ans + calc(Lb, Rb, i, 1, 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
int main(){
IOS;
int n,k,sum=0,i;
cin>>n>>k;
int a[n];
for(i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
}
set<int> s;
for(i=1;i*i<=sum;i++){
    if(sum%i==0){
        s.insert(i);
        s.insert(sum/i);
    }
}
priority_queue<int> ans;
for(auto it: s){
    vector<int> v;
    for(i=0;i<n;i++)
        v.pb(a[i]%it);
    sort(all(v));
    int suffix[n];
    suffix[n-1]=it-v[n-1];
    for(i=v.size()-2;i>=0;i--){
        suffix[i]=suffix[i+1]+it-v[i];
    }
    int cum=0;
    for(i=0;i<n;i++){
        if(suffix[i]==cum&&cum<=k)
            break;
        cum+=v[i];
    }
    if(i!=n)
        ans.push(it);
}
if(!ans.size())
    cout<<1<<endl;
else cout<<ans.top()<<endl;
}


Measured memory_bytes: 384
def divisible(n):
    if n % 3 == 0:
        print(' {0}'.format(n), end='')


def include(n):
    if '3' in str(n):
        print(' {0}'.format(n), end='')


n = int(input())
for n in range(3, n+1):
    divisible(n)
    if n % 3:
        include(n)
print()



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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    double N, D;
    std::cin >> N >> D;

    std::cout << ceil(N / (2 * D + 1)) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;

    vector<int> niz(n);
    int sum = 0, cnt = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> niz[i];
        sum += niz[i];
        if (sum <= x)
            cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#define pi acos(-1)
using namespace std;
double aabs(double x)
{
	if(x<0)return -x;
	return x;
}
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<gcd(a,b)<<endl;
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll X;
    cin >> X;
    if(X>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
long long modinv(long long a,long long mod)//extgcdの方がいいらしい
{
  return modpow(a,mod-2,mod);
}
vector<int>inv;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,x;
  int mod=1e9+7;
  cin>>n>>x;
  vector<int>s(n);
  rep(i,n)cin>>s[i];
  sort(all(s),greater<int>());
  inv.resize(n+1);
  repi(i,1,n+1)inv[i]=modinv(i,mod);
  vector<vector<int>>dp(2,vector<int>(x+1,0));
  dp[0][x]=1;
  rep(i,n)
  {
    int no=i&1,ne=1-no;
    fill(all(dp[ne]),0);
    rep(j,x+1)
    {
      if(dp[no][j]==0)continue;
      int t=(ll)dp[no][j]*inv[n-i]%mod;
      int jsi=j%s[i];
      dp[ne][jsi]+=t;
      dp[ne][j]+=(ll)t*(n-i-1)%mod;
      if(dp[ne][jsi]>mod)dp[ne][jsi]-=mod;
      if(dp[ne][j]>mod)dp[ne][jsi]-=mod;
    }
  }
  ll res=0;
  int kai=1;
  rep(i,n)kai=(ll)kai*(i+1)%mod;
  rep(i,x+1)
  {
    res+=(ll)kai*dp[n&1][i]%mod*i%mod;
  }
  cout<<res%mod<<endl;


  return 0;

}


Measured memory_bytes: 1408
"use strict";
function Main(input) {
  const first = parseInt(input.slice(0, 2));
  const second = parseInt(input.slice(2));
  const firstMM = 0 < first && first < 13;
  const secondMM = 0 < second && second < 13;
  if (firstMM && secondMM) {
    console.log('AMBIGUOUS');
    return;
  } else if (firstMM) {
    console.log('MMYY');
    return;
  } else if (secondMM) {
    console.log('YYMM');
    return;
  }
  console.log('NA');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import sys
sys.setrecursionlimit(10 ** 6)

def root(v):
    if v == par[v]:
        return v
    par[v] = root(par[v])
    return par[v]

def unite(u, v):
    u = root(u)
    v = root(v)
    if u == v:
        return
    if rank[u] < rank[v]:
        u, v = v, u
    par[v] = u
    if rank[u] == rank[v]:
        rank[u] += 1

def same(u, v):
    return root(u) == root(v)

N, M = map(int, input().split())
par = list(range(2 * N))
rank = [0] * (2 * N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b + N)
    unite(a + N, b)

if same(0, N):
    print(N * (N - 1) // 2 - M)
else:
    c = 0
    for i in range(N):
        c += same(0, i)
    print(c * (N - c) - M)


Measured memory_bytes: 14452
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > P;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;

int main()
{
    ll N,K,res;
    cin >> N >> K;
    if(K%2 == 1) res = (N/K)*(N/K)*(N/K); 
    else res = (N/K)*(N/K)*(N/K) + (N/(K/2)-N/K)*(N/(K/2)-N/K)*(N/(K/2)-N/K);
    cout << res << endl;
}

Measured memory_bytes: 256
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+2;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;

int main()
{
    IOS();
   
    int n,m,i,j=0,ans=0;  
    cin>>n>>m;
    if(m==1)
    {
      cout<<0;
      return 0;
    }
    j=n;
    ans++;
    while(j<m)
    {
        j=j+n-1;
        ans++;
    }
    cout<<ans;

    return 0;
  
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    vector<ll> dp1(N+1),dp2(N+1);
    dp2[0] = 1;
    rep(i,N) {
        int k = S[i] - '0';
        dp1[i+1] = min(dp1[i],dp2[i]+1)+k;
        dp2[i+1] = min(dp1[i]+10-k,dp2[i]+9-k);
    }

    cout << min(dp1[N],dp2[N]+1) << ln;
}

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

using namespace std;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> Player(N);
  for (int i = 0; i < Q; i++) {
    int x;
    cin >> x;
    Player[x - 1] += 1;
  }

  for (int x : Player) {
    int tmp = K - Q + x;
    cout << ((tmp > 0) ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 1024
n, m = map(int, input().split())

co = 0
pe = 0

ac= [0] * (n+1)
wa= [0] * (n+1)

for _ in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if ac[p]==0 and s == 'AC':
        co += 1
        ac[p] =1
        if wa[p]>0:
            pe += wa[p]
    elif ac[p] == 0 and s == 'WA':
        wa[p] += 1

print('{} {}'.format(co, pe))

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int sx, sy, tx, ty;
int main() {
    std::cin >> sx >> sy >> tx >> ty;
	int x = tx - sx;
	int y = ty - sy;
	REP(i, y) std::cout << 'U';
	REP(i, x) std::cout << 'R';
	REP(i, y) std::cout << 'D';
	REP(i, x) std::cout << 'L';
	std::cout << "LU";
	REP(i, y) std::cout << 'U';
	REP(i, x) std::cout << 'R';
	std::cout << "RDRD";
	REP(i, y) std::cout << 'D';
	REP(i, x) std::cout << 'L';
	std::cout << "LU" << std::endl;
}



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

int main(){
  int n,m; cin >> n >> m; //スイッチ数 = N ; 電球数 = M;
  vector<int> a(n); //それぞれのスイッチを表す a (0 ~ (n-1))

  REP(i,m){ // それぞれ電球の電球が、どのスイッチに繋がっているかを入力する
    int k; cin >> k; //電球[i]が繋がっているスイッチの数
    REP(j,k){ //スイッチの個数分 ループ
      int s; cin >> s; // 電球[i]に繋がっている スイッチ[s]
      s--; // 1 index で始めたくないから デクリメントして 0 indexにする
      a[s] |= 1 << i; // s番目のスイッチを押した時に、i 番目の電球がつくことを記録する
      // (例) i = 0 s = 0 → スイッチ[0] = 001　// i = 1 s = 0 → スイッチ[0] = 011 (電球[0]も光ることが最初に記録されているため "010" ではなく "011" になる)
    }
  }

  int p = 0;
  REP(i,m){
    int x; cin >> x;
    p |= x << i;
  }

  int ans = 0;
  REP(s,(1<<n)){ // スイッチの押しパターンを全て試す
    int t = 0; // どの電球が付いているかを記録する変数
    REP(i,n){ // どのスイッチが押されているかを判定する
      if((s>>i) & 1){ // i番目のスイッチが押されているかを確認
      // (例) i = 1, s = 2;
      // s = 2 は 2進数で 100 と表せる (10進数)2 = (2進数)100;
      // s >> i = 2 >> 1 = 100 >> 1
      // 100 >> 1 は 2進数 100 を右に1個シフトするので  10 となる
      // 10 & 1 の 1 を 2進数に変換すると 01
      // 10 & 01  = 00 となり Integerの 0 は c++ で false となるため、 i = 1, s = 2 の場合は false
        t ^= a[i];
      }
    }
    if(t == p) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string A, B;
	std::cin >> A >> B;
	if (A.size() < B.size())
		std::cout << "LESS\n";
	else if (A.size() > B.size())
		std::cout << "GREATER\n";
	else if (A < B)
		std::cout << "LESS\n";
	else if (A > B)
		std::cout << "GREATER\n";
	else
		std::cout << "EQUAL\n";
}


Measured memory_bytes: 512
N, *a = map(int, open(0).read().split())
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] != part_rem:
        a[i] = 1 - a[i]
        
print(sum(a))
print(*[i+1 for i, v in enumerate(a) if v == 1])

Measured memory_bytes: 11644
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
ll a[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    x=n/500;
    x*=1000;
    n%=500;
    x+=(n/5)*5;
    cout<<x;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N, X, Y;
    cin >> N >> X >> Y;
    X--, Y--;

    vector<vector<int>> G(N);
    rep(i,N){
      for(int d=-1; d<=1; d++){
        int nx = i + d;
        if(d==0 || nx<0 || nx>=N) continue;
        G[i].pb(nx);
      }
    }
    G[X].pb(Y);
    G[Y].pb(X);

    vector<int> ans(N,0);

    rep(i,N){
      vector<int> dis(N+1,-1);
      queue<int> que;

      int s = i;
      dis[s] = 0;
      que.push(s);

      while(!que.empty()){
        int p = que.front();
        que.pop();
        rep(j,G[p].size()){
          int nx = G[p][j];
          if(dis[nx]==-1){
            que.push(nx);
            dis[nx] = dis[p]+1;
          }
        }
      }

      for(int k=s; k<N; k++){
        int index = dis[k];
        ans[index]++;
      }
    }

    for(int i = 1; i < N; i++){
      cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <cmath>

int main(void){
    int n;
    std::cin >> n;
    int sum = 0; 
    int y = n;

    while(y > 0){
        sum += y%10;
        y = y/10;
    }
    std::cout << (n%sum == 0 ? "Yes" : "No");
    return 0;
}



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

int main(){
    int n;
    int cont = 1;
    int cambios = 0;
    cin >> n;
    int arr[n];
    for (int i=0;i<n;i++){
        cin >> arr[i];
        if(arr[i]==cont){
            cont++;
        }else{
            cambios++;
            cont++;
        }
    }
    if(cambios==2 || cambios==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

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

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

#define EQ(a,b) (abs((a)-(b))<eps)

ld dot (P a, P b) { return real(conj(a) * b); }
ld cross (P a, P b) { return imag(conj(a) * b); }

struct L{ P a, b; };

P is_ll(L s, L t){
  P sv = s.b - s.a, tv = t.b - t.a;
  return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_sp(L s, P p) {
  return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<L> vl;
    int sum = 1;
    REP(i,n) {
      int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      P p1(x1,y1), p2(x2,y2);
      L l{p1, p2};
      VP crs;
      crs.push_back(p1);
      crs.push_back(p2);
      REP(j,i) {
        P cr = is_ll(l,vl[j]);
        if(isis_sp(l,cr)) {
          bool ok = true;
          REP(k,crs.size()) {
            if (abs(crs[k]-cr) < eps) ok = false;
          }
          if (ok) crs.push_back(cr);
        }
      }
      sum += crs.size() - 1;
      vl.push_back(l);
    }
    cout << sum << endl;
  }
  return 0;
}

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

long long int N, M, C, a, b, d, i, c, r = 1099511627775LL;
pair<long long int, long long int> j;
unsigned long long int y[100000];
bool u[100000];
pair<long long int, long long int> p;
vector<pair<long long int, long long int> > R[100000];
priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int> >, greater<pair<long long int, long long int> > > z;

int main(){
    scanf("%lld%lld%lld", &N, &M, &C);
    for(; i < M; ++i){
        scanf("%lld%lld%lld", &a, &b, &d);
        R[a - 1].push_back(make_pair(d, b - 1));
        R[b - 1].push_back(make_pair(d, a - 1));
        c += d;
    }
    memset(y, -1, sizeof(y));
    z.push(make_pair(0, 0));
    while(!z.empty()){
        p = z.top();
        z.pop();
        if(y[p.second] < p.first)continue;
        y[p.second] = p.first;
        u[p.second] = true;
        for(j : R[p.second]){
            if(y[j.second] > p.first + j.first){
                y[j.second] = p.first + j.first;
                z.push(make_pair(p.first + j.first, j.second));
            }
            if(u[j.second]){
                c -= j.first;
            }
        }
        r = min(r, C * p.first + c);
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 17416