akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <algorithm>
using namespace std;

int main(void){
    int N; cin >> N;
    string answer = "";
    while(N){
        if (N % 2) {
            answer = "1" + answer;
        } else {
            answer = "0" + answer;
        }
        int r = N % 2;
        if (r < 0) r+=2;
        N -= r;
        N /= -2;
    };
    if(answer.empty()) {
        answer = "0";
    }
    cout << answer << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int  a,b,c;
 cin >> a >> b >> c;
 bool d=false;
 if(a+b==c)d=true;
 if(a+c==b)d=true;
 if(b+c==a)d=true;
 if(d)cout <<"Yes" << endl;
 else cout << "No" << endl;
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,s,d;
    cin>>a>>s;
    double f2;
    f2=1.0*a/s;
    cout<<a/s<<" "<<a%s<<" ";
    printf("%.10lf",f2);
    cout<<""<<endl;
    return 0;
}


Measured memory_bytes: 3212
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int r=nextInt();
		int g=nextInt();
		int b=nextInt();

		String ans = "NO";
		if((r*100+g*10+b)%4==0){
			ans="YES";
		}

		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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



int main(){
    int N;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++){
      cin>>A[i];
    }
    int a=A[0];
    int count=1;
    for(int i=1;i<N;i++){
        if(A[i]>=a){
            count++;
            a=A[i];
        }
    }
    cout<<count<<endl;
}


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

int check(string std);

int main()
{
	int num;
  cin >>num;
  int count[4] = {0,0,0,0};
  string std;
  for(int i=0;i<num;i++)
  {
   cin >> std;
    count[check(std)]++;
  }
  cout <<"AC x "<<count[0]<<endl
    <<"WA x "<<count[1]<<endl
    <<"TLE x "<<count[2]<<endl
    <<"RE x "<<count[3]<<endl;
}

int check(string std)
{
	if(std == "AC")
      return 0;
  if(std=="WA")
    return 1;
  if(std=="TLE")
  	return 2;
  if(std=="RE")
    return 3;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	int A,B,C,D,E,K;
	cin >> A >> B >> C >> D >> E >> K;

	if(E -A > K){
		printf(":(");
	}
	else {
		printf("Yay!");

	}


	return 0;
}



Measured memory_bytes: 256
import heapq

N, K = map(int, input().split())
V = list(map(int, input().split()))
max_cnt = min(N, K)
ans = 0

for a in range(0, max_cnt + 1):
    for b in range(0, max_cnt + 1):
        if a + b > max_cnt:
            break
        if a == b == 0:
            continue
        hoseki = V[:a] + V[::-1][:b]
        heapq.heapify(hoseki)
        tmp = K - (a + b)
        while tmp and len(hoseki):
            my_min = heapq.heappop(hoseki)
            if my_min >= 0:
                heapq.heappush(hoseki, my_min)
                break
            tmp -= 1
        ans = max(ans, sum(hoseki))

print(ans)

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

int main(){
  string s;
  cin >> s;
  deque<char> que;
  for(auto t : s) que.push_back(t);
  int q;
  cin >> q;
  int cnt = 0;
  rep(i,q){
    int a;
    cin >> a;
    if(a == 1) cnt++;
    else{
      int f;
      cin >> f;
      char c;
      cin >> c;
      if(f == 1){
        if(cnt%2 == 0) que.push_front(c);
        else que.push_back(c);
      }
      else{
        if(cnt%2 == 0) que.push_back(c);
        else que.push_front(c);
      }
    }
  }
  if(cnt%2 == 1) reverse(que.begin(),que.end());
  for(auto t : que) cout << t;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;
const int Max=100005;
int n,m,s;
int sum[Max];

inline int ksm(int a,int b)
{
	int ans=1;
	while(b)
	{
	  if(b&1) ans=(ans*a)%mod;
	  b>>=1;
	  a=(a*a)%mod;
	}
	return ans;
}

signed main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&m),sum[m]++;
	for(int i=0;i<n;i++) if(sum[i]>=3) {cout<<"0";return 0;}
	if((n&1&&sum[0]!=1)||(!(n%2)&&sum[0])) {cout<<"0";return 0;}
	cout<<ksm(2,n/2);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
  long long int m,n,i,j,k,c=0,x,y,z,p=0;
  map<long long int,long long int>mp;
  string s;
  cin>>n>>m;
  while(m--)
  {
      cin>>x>>s;
      //out<<x<<s;
      if(s=="AC")
      {
          y=1;
          //cout<<y<<endl;
      }
      else
        y=2;
        if(mp[x]==0)
        {
            //mp[x]=y;
            if(y==1)
            {
                c++;
                mp[x]=-1;
            }
            else if(y==2)
            {
                mp[x]++;
            }
        }
        else if(mp[x]>=1)
        {
            if(y==2)
            {
                mp[x]++;
            }
            else if(y==1)
            {
                c++;
                p=p+mp[x];
                mp[x]=-1;
            }
        }
  }
  cout<<c<<" "<<p<<endl;
}




Measured memory_bytes: 6528
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll m){
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % m;
        r = r * r % m;
        n /= 2;
    }
    return res;
}

ll primroot(ll m, int inv = 0){
    if(!inv){
        if (m == 2) return 1;
        if (m == 167772161) return 3;
        if (m == 469762049) return 3;
        if (m == 754974721) return 11;
        if (m == 998244353) return 3;
    }
    else{
        if (m == 2) return 1;
        if (m == 167772161) return 55924054;
        if (m == 469762049) return 156587350;
        if (m == 754974721) return 617706590;
        if (m == 998244353) return 332748118;
    }
    return -1;
}

vector<ll> NTT(const vector<ll> &f, int k, const ll &m, int inv){
    vector<ll> Ff = f;
    vector<ll> newFf(1 << k);
    for(int j = 1; j <= k; j++){
        ll z = modpow(primroot(m, inv), m / (1 << j), m);
        ll zz = 1;
        for(int i = 0; i < (1 << j); i++){
            for(int l = 0; l < (1 << (k - j)); l++){
                newFf[(i << (k - j)) + l] =
                    (Ff[((i << (k - j + 1)) + l) & ((1 << k) - 1)] +
                     Ff[((i << (k - j + 1)) + l + (1 << (k - j))) & ((1 << k) - 1)] * zz) % m;
            }
            zz = zz * z % m;
        }
        swap(Ff, newFf);
    }
    return Ff;
}

vector<ll> Convolution(vector<ll> a, vector<ll> b, const ll m){
    int k = 0;
    while((1 << k) < (int)a.size() + (int)b.size() - 1) k++;
    a.resize(1 << k);
    b.resize(1 << k);
    vector<ll> Fa = NTT(a, k, m, false), Fb = NTT(b, k, m, false);
    vector<ll> Fc(1 << k);
    for(int i = 0; i < (1 << k); i++) Fc[i] = Fa[i] * Fb[i] % m;
    vector<ll> c = NTT(Fc, k, m, true);
    ll r = modpow((1 << k), m - 2, m);
    for(int i = 0; i < (1 << k); i++) c[i] = c[i] * r % m;
    return c;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    vector<ll> c = Convolution(a, b, 998244353);
    for(int i = 0; i < n + m - 1; i++) cout << c[i] << " ";
    cout << endl;
}


Measured memory_bytes: 68896
#include<iostream>
#include<string>

using namespace std;

int main(){

	int N,Q;
	int year;
	string name,ans;

	cin>>N>>Q;

	ans="kogakubu10gokan";

	while(N --> 0){
		cin>>year>>name;
		if(Q>=year) ans=name;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

// repetition
#define FOR(i,m,n) for(ll i = ((ll) m); i < ((ll) n); ++i)
#define REP(i,n) FOR(i,0,n)

int main() {
    int n, W; cin >> n >> W;
    int *v = new int[n], *w = new int[n];
    int *dp = new int[W+1];
    REP(k, n) cin >> v[k] >> w[k];
    REP(w, W+1) dp[w] = 0;
    REP(k, n) {
        FOR(i, w[k], W+1) {
            if(k == 0) {
                dp[i] = dp[i- w[k]] + v[k];
            } else {
                dp[i] = max(dp[i - w[k]] + v[k], dp[i]);
            }
        }
    }
    int ans = 0;
    REP(i, W+1) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}
/*
Knapsack Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp

dp[k][w] = k番目までの物品で重さがwになるような価値の最大値
dp[k][w] = max_{0..}(dp[k-1][w-nw_k] + nv_k)
         = max(dp[k-1][w], max_{0..}(dp[k-1][w-w_k]) + v_k)
         = max(dp[k-1][w], dp[k][w-w_k] + v_k)
*/



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

int64_t mod = 1e9+7;

int64_t DP[5000];

int64_t f(int s) {
	if (s == 0) return 1;
	if (DP[s] != -1) return DP[s];
	int64_t ans = 0;
	for (int i = 3; i <= s; ++i) {
		ans += f(s-i);
		ans %= mod;
	}
	return DP[s] = ans;
}

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

	int N;
	cin >> N;

	memset(DP, -1, sizeof DP);

	cout << f(N) << endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    
    int now=0;
    REP(i,0,n){
        if(now>a[i]){cout<<"No"<<endl; return 0;}
        now=max(now,a[i]-1);
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		if (i >= K) {
			if (A[i] > A[i - K]) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
}

Measured memory_bytes: 4052
import numpy as np

N, K = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

ary = np.array([(1 + n) / 2 for n in numbers])

cumsum = ary.cumsum()

max_exv = cumsum[K-1]
for i in range(N - K):
    if cumsum[i+K] - cumsum[i] > max_exv:
        max_exv = cumsum[i+K] - cumsum[i]
    
print(max_exv)

Measured memory_bytes: 33940
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,m,a,b,ans=1e9;
  scanf("%d %d",&n,&m);
  while(n--){
    scanf("%d %d",&a,&b);
    if(b>m)continue;
    ans=MIN(ans,a);
  }
  if(ans<1e8)printf("%d\n",ans);
  else       printf("TLE\n");
  return 0;
}
    


Measured memory_bytes: 128
#include <stdio.h>
 
int main(void){
  long long int s,m;
  long long int i=1;
  long long int a[1000000];
  scanf("%d",&s);
  
  a[1]=s;
  
  while(1){
    if(a[i]==1 || a[i]==4 || a[i]==2){
      break;
    }
    i++;
    if( (a[i-1] & 1) == 1 ){
      a[i]=(3*a[i-1])+1;
    }else{
      a[i]=a[i-1]/2;
    }
  }
  
  printf("%d",i+3);
  return 0;
}

Measured memory_bytes: 128
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_var(x) cout << (#x) << ": " << x << "\n";
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");
 
typedef long long ll;
typedef long double ld;

const ll MOD = 1000000007;

void solve(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n + 1);
    for(ll i = 0; i <= n; i++){
        a[i] = i;
    }
    ll idx1 = 0, idx2 = n, curr1 = 0, curr2 = 0, res = 0;
    for(int i = 1; i < k; i++){
        curr1 += (a[idx1]);
        curr2 += (a[idx2]);
        idx1++;
        idx2--;
    }
    for(int i = 0; i < (n - k + 2); i++){
        curr1 += (a[idx1]);
        curr2 += (a[idx2]);
        idx1++;
        idx2--;
        curr1 %= MOD;
        curr2 %= MOD;
        res += (curr2 - curr1 + 1 + MOD) % MOD;
        res %= MOD;
        // debug_var(curr1);
        // debug_var(curr2);
        // debug_var(res);
    }
    cout << res << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

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

int main() {
	int d;
	while(cin >> d){
		int s = 0;
		for(int i = 1; i < 600 / d; ++i){
			s += pow(d * i, 2) * d;
		}
		cout << s << endl;
	}
	return 0;
}

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

namespace Sort_I
{
    class Selection_Sort
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var n = SelectionSort(A);
            for (int i = 0; i < A.Length - 1; i++)
            {
                Console.Write(A[i] + " ");
            }
            Console.WriteLine(A.Last());
            Console.WriteLine(n);
        }

        static int SelectionSort(int[] A)
        {
            var n = 0;
            for (int i = 0; i < A.Length; i++)
            {
                var minj = i;
                for (int j = i; j < A.Length; j++)
                    if (A[j] < A[minj])
                        minj = j;
                if (minj != i)
                {
                    var temp = A[i];
                    A[i] = A[minj];
                    A[minj] = temp;
                    n++;
                }
            }
            return n;
        }
    }
}

Measured memory_bytes: 9540
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int N, X;
  cin >> N >> X;
  vi L(N);
  rep(i,N) cin >> L[i];
  int D = 0; int ret = 0;
  if(D<=X) ret++;
  rep(i,N){
    D += L[i];
    if(D<=X) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	string s;
	cin >> s;
	ll dp[100010][2];
	dp[0][0]=2;
	dp[0][1]=1;
	for(int i=1;i<(int)s.size();i++){
		if(s[i]=='0'){
			dp[i][0]=dp[i-1][0];
			dp[i][1]=dp[i-1][1]*3ll%MOD;
		}else{
			dp[i][0]=dp[i-1][0]*2ll%MOD;
			dp[i][1]=(dp[i-1][1]*3ll+dp[i-1][0])%MOD;

		}
	}

	cout <<(dp[(int)s.size()-1][0]+dp[(int)s.size()-1][1])%MOD << endl;

}



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

signed main(void)
{
	int n;
	cin >> n;
	int a[n], b[n];
	ll ans;
	rep(i, n) cin >> a[i];
	if (a[0] != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	rep(i, n - 1)
	{
		if (a[i + 1] - a[i] > 1) 
		{
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = n - 1; i >= 0; i--)
		b[i] = i - a[i];
	ans = 0;
	int tmp = -1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (tmp != b[i])
			ans += i - b[i];
		tmp = b[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5128
# -*- coding: utf-8 -*-
N = int(input())
bm = int(N/7)

flag = 0
for b in range(bm + 1):
  if((N-7*b)%4 == 0):
    flag = 1
    break

if(flag == 1):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static final int W = 8;
	static final int H = 8;
	static char[][] board = new char[W + 2][H + 2];

	static int[] vx = {0,1,1,1,0,-1,-1,-1};
	static int[] vy = {1,1,0,-1,-1,-1,0,1};

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		for(int i = 0; i < board.length; i++){
			Arrays.fill(board[i], '.');
		}

		for(int i = 1; i <= H; i++){
			String str = sc.next();

			for(int j = 1; j <= W; j++){
				board[i][j] = str.charAt(j - 1);
			}
		}

		Player[] players = new Player[2];

		players[0] = new Player('o', 'x');
		players[1] = new Player('x', 'o');

		int pid = 0;

		while(true){
			Player current = players[pid%players.length];

			int tmpMax = 0;
			int maxX = 0;
			int maxY = 0;

			//最適な場所を探す
			for(int i = 1; i <= H; i++){
				for(int j = 1; j <= W; j++){
					if(board[i][j] != '.'){
						continue;
					}
					int tmpCount = countReversible(current, j, i);
//					System.out.println(tmpCount);

					if((pid%players.length == 0 &&  tmpMax < tmpCount) ||
							pid%players.length == 1 && tmpMax <= tmpCount){
						tmpMax = tmpCount;
						maxX = j;
						maxY = i;
					}
				}
			}

			if(tmpMax != 0){
//				System.out.println("put at "+maxX+", "+maxY+" expect "+tmpMax);
				reverse(current, maxX, maxY);
				current.put = true;
			}
			else {
//				System.out.println("cant fount");
				current.put = false;
			}
			pid++;

			if(!players[0].put && !players[1].put){
				break;
			}
//			printBoard();
//			System.out.println();
//			sc.next();
		}

		printBoard();
	}

	static void printBoard (){
		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				System.out.print(board[i][j]);
			}
			System.out.println();
		}
	}

	static int countReversible(Player player, int x, int y){
		int count = 0;

//		board[y][x] = player.piece;
		for(int i = 0; i < 8; i++){
			if(board[y + vy[i]][x + vx[i]] == player.enemy){
				int j = 1;
				while(board[y + vy[i]*j][x + vx[i]*j] != '.'){
					if(board[y + vy[i]*j][x + vx[i]*j] == player.piece){
						count += j - 1;
						break;
					}

					j++;
				}
			}
		}

		return count;
	}

	static void reverse(Player player, int x, int y){
		board[y][x] = player.piece;
		for(int i = 0; i < 8; i++){
			boolean reversible = false;
			if(board[y + vy[i]][x + vx[i]] == player.enemy){
				int j = 1;
				while(board[y + vy[i]*j][x + vx[i]*j] != '.'){
					if(board[y + vy[i]*j][x + vx[i]*j] == player.piece){
						reversible = true;
						break;
					}

					j++;
				}
			}

			if(reversible){
//				System.out.println("dir "+i);
				int j = 1;
				while(board[y + vy[i]*j][x + vx[i]*j] == player.enemy){
					board[y + vy[i]*j][x + vx[i]*j] = player.piece;
					j++;
				}
			}
		}
	}

}

class Player {
	char piece;
	char enemy;
	boolean put = true;

	Player(char piece, char enemy){
		this.piece = piece;
		this.enemy = enemy;
	}
}


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

#角、辺、内部の3つ分けて考える
#角は4flip -> 表
#辺は6flip -> 表
#内部は9flip -> 裏

if n >= 2 and m >= 2:
    ans = n*m - 2*m -2*n + 4
elif n == 1 and m == 1:
    ans = 1
elif n == 1:
    ans = max(0, m-2)
elif m == 1:
    ans = max(0, n-2)

print(ans)

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

using ll = long long;

vector<ll> primeFactors(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        bool flg = false;
        while (n % i == 0) {
            flg = true;
            n /= i;
        }
        if (flg) res.push_back(i);
    }
    if (n != 1) res.push_back(n);
    return res;
}

int main() {
    ll a, b;  cin >> a >> b;
    vector<ll> ap = primeFactors(a);
    vector<ll> bp = primeFactors(b);
    int j = 0;
    ll ans = 1;
    for (int i = 0; i < (int)ap.size(); ++i) {
        while (j < (int)bp.size() && bp[j] < ap[i]) ++j;
        if (j == (int)bp.size()) break;
        if (ap[i] == bp[j]) {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define FORD(x,a,b) for(int x=a;x>=b;x--)
#define maxn 100005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x,y) memset(x,y,sizeof(x))
#define task "vacation"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)

using namespace std;
int n,a[maxn],b[maxn],c[maxn],dpa[maxn],dpb[maxn],dpc[maxn];
int main()
{
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n;
    for(int i=1; i<=n; ++i)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=1; i<=n; ++i)
    {
        dpa[i] = max(dpb[i-1], dpc[i-1]) + a[i];
        dpb[i] = max(dpa[i-1], dpc[i-1]) + b[i];
        dpc[i] = max(dpb[i-1], dpa[i-1]) + c[i];
    }
    cout << max(dpa[n],max(dpb[n],dpc[n]));
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <queue>

using namespace std;

int N,M;

struct Edge {
    int src, dst, weight;
    Edge *next, *prev;
    Edge(int s, int d, int w, Edge *n, Edge *p)
        : src(s), dst(d), weight(w), next(n), prev(p) {}
    Edge() : Edge(0, 0, 0, nullptr, nullptr) {}

    void *operator new (size_t) {
        static char buf[500010*sizeof(Edge)];
        static int i = 0;
        Edge *res = (Edge*)(buf + i);
        i += sizeof(Edge);
        return res;
    }
};

vector<Edge*> first;

void add_edge(int u, int v, int d){
    Edge *next = first[u];
    first[u] = new Edge(u, v, d, next, nullptr);
    if(next != nullptr) next->prev = first[u];
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int V,E,r;
    while(cin >> V >> E >> r){
        first.assign(V, nullptr);
        for(int i = 0; i < E; ++i){
            int s,t,d;
            cin >> s >> t >> d;
            add_edge(s,t,d);
        }

        using State = pair<int,int>;
        priority_queue<State> q;
        vector<long long> dist(V, 1e18);
        q.emplace(0,r);
        dist[r] = 0;

        while(q.size()){
            long long d,v;
            tie(d,v) = q.top();
            q.pop();
            d = -d;
            if(dist[v] < d) continue;
            for(Edge *e = first[v]; e != nullptr; e = e->next){
                if(dist[e->dst] > e->weight + dist[v]){
                    dist[e->dst] = e->weight + dist[v];
                    q.emplace(-dist[e->dst], e->dst);
                }
            }
        }

        for(int i = 0; i < V; ++i){
            if(dist[i] == 1e18) cout << "INF";
            else cout << dist[i];
            cout << '\n';
        }
    }
    
    // {
    //     vector<string> u, v;
    //     static char s[3000], t[3000];
    //     map<string,int> id;
    //     N = 0;
    //     M = 0;
    //     while(cin >> s >> t){
    //         u.push_back(s);
    //         v.push_back(t);
    //         if(id.count(s) == 0) id[s] = N++;
    //         if(id.count(t) == 0) id[t] = N++;
    //         ++M;
    //     }

    //     first.assign(N, nullptr);
    //     for(int i = 0; i < M; ++i){
    //         add_edge(id[u[i]], id[v[i]]);
    //     }
    // }
}

Measured memory_bytes: 20536
#include <iostream>

int countDivisors(int a, int b, int c) {
	int numDiviosrs = 0;

	for (int i = a; i <= b; i++) {
		if (c % i == 0)
			numDiviosrs++;
	}
	return numDiviosrs;
}

int main()
{
	int a, b, c;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;

	int numDivisors = countDivisors(a, b, c);
	std::cout << numDivisors << "\n";

    return 0;
}




Measured memory_bytes: 3132
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int height,width,N;
char** table;
int** distanceTable;

struct Info{
	int cheese_id,row,col;
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= height-1 && col >=0 && col <= width-1)return true;
	else{
		return false;
	}
}

void func(int row,int col,int goal_row,int goal_col,int dist){
	distanceTable[row][col] = dist;
	if(row == goal_row && col == goal_col)return;

	if(rangeCheck(row-1,col) == true && (distanceTable[row-1][col] == 0 || distanceTable[row-1][col] > dist+1))func(row-1,col,goal_row,goal_col,dist+1);
	if(rangeCheck(row+1,col) == true && (distanceTable[row+1][col] == 0 || distanceTable[row+1][col] > dist+1))func(row+1,col,goal_row,goal_col,dist+1);
	if(rangeCheck(row,col-1) == true && (distanceTable[row][col-1] == 0 || distanceTable[row][col-1] > dist+1))func(row,col-1,goal_row,goal_col,dist+1);
	if(rangeCheck(row,col+1) == true && (distanceTable[row][col+1] == 0 || distanceTable[row][col+1] > dist+1))func(row,col+1,goal_row,goal_col,dist+1);
}

int main(){

	scanf("%d %d %d",&height,&width,&N);
	table = new char*[1000];
	distanceTable = new int*[1000];
	Info info[N+1];
	int info_index = 0,total_dist = 0;


	for(int i=0; i < height; i++){
		table[i] = new char[1001];
		distanceTable[i] = new int[1000];

		scanf("%s",table[i]);

		for(int k = 0; k <width; k++){
			if(table[i][k] == 'X')distanceTable[i][k] = -1;
			else{
				distanceTable[i][k] = 0;
			}

			if(table[i][k] == 'S'){
				info[info_index].cheese_id = 0;
				info[info_index].row = i;
				info[info_index].col = k;
				info_index++;
			}else if(table[i][k] >= '1' && table[i][k] <= '9'){
				info[info_index].cheese_id = table[i][k] - '0';
				info[info_index].row = i;
				info[info_index].col = k;
				info_index++;
			}
		}
	}


	//???????????????????????±?????????????????????
	for(int i=1; i <= N; i++){
		for(int k=N; k >= i; k--){
			if(info[k].cheese_id < info[k-1].cheese_id)swap(info[k],info[k-1]);
		}
	}

	//i????????????????????????i+1???????????????????????§??????????????¢?????¨??¢?´¢??§?±???????
	for(int i = 0; i <= N-1; i++){
		func(info[i].row,info[i].col,info[i+1].row,info[i+1].col,0);
		total_dist += distanceTable[info[i+1].row][info[i+1].col];

		for(int k = 0; k < height; k++){
			for(int p = 0; p < width; p++){
				if(distanceTable[k][p] > 0)distanceTable[k][p] = 0;
			}
		}
	}

	printf("%d\n",total_dist);

    return 0;
}

Measured memory_bytes: 15060
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

int N, X[1009], Y[1009], H[1009]; vector<tuple<int,int,int> >vec;

int main() {
  cin >> N; tuple<int,int,int>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			int V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); V = max(V, 0); bool flag = true;
			for (int k = 1; k <= N; k++) {
				int VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	if (vec.size() == 1) {
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll m=998244353;
int main()
{
    /*ll n,k;
    cin>>n>>k;
    set<ll>s;
    for(int i=1;i<=k;i++)
    {
        ll a,b;
        cin>>a>>b;
        s.insert(a);
        s.insert(b);
    }
    vector<ll>dp(n+1,0);
    dp[1]=1;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=i-1;j>=1;j--)
        {
            if(s.find(i-j)!=s.end())
            {
                dp[i]=(((dp[i]+m)%m)+((dp[j]+m)%m))%m;
                //dp[i]%=m;
            }
        }
        //dp[i]=dp[i]%m;
     }
     cout<<dp[n]<<endl;*/
     ll n;
     cin>>n;
     ll ans=0;
     for(ll a=1;a<=n;a++)
     {
        for(ll b=1;b<=n;b++)
        {
            if(a*b<n)
                ans++;
            else
                break;
         }
     }
     cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>//hdu1565
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<string>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
const int maxn=100005;
LL a[maxn],b[maxn];
int A,B,M;
struct node{
    int to;
    LL w;
};
vector<node> v[maxn];
int main()
{
    scanf("%d%d%d",&A,&B,&M);
    for(int i=1;i<=A;i++){
        cin>>a[i];
    }
    for(int i=1;i<=B;i++){
        cin>>b[i];
    }
    for(int i=1;i<=M;i++){
        int x,y;
        LL c;
        cin>>x>>y>>c;
        node pre;
        pre.to=y;
        pre.w=c;
        v[x].push_back(pre);
    }
    LL mia=a[1],mib=b[1];
    int la=1,lb=1;
    for(int i=1;i<=A;i++){
         mia=min(mia,a[i]);
    }
    for(int i=1;i<=B;i++){
        mib=min(mib,b[i]);
    }
    LL x2=1e9;
    for(int i=1;i<=A;i++){
        for(int j=0;j<v[i].size();j++){
               // printf("%d %d\n",i,v[i][j].to);
            int x=i,y=v[i][j].to;
            LL W=v[i][j].w;
            //printf("%lld\n",W);
            x2=min(x2,a[x]+b[y]-W);
        }
    }
    printf("%lld\n",min(x2,mia+mib));
    return 0;
}


Measured memory_bytes: 6784
import math
N,M=map(int, input().split())
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))
try :
    base = comb(N,2)
except:
    base=0
def comb2(M, r):
    return math.factorial(M) // (math.factorial(M - r) * math.factorial(r))
try:
    base2 = comb2(M,2)
except:
    base2=0

print(base+base2) 

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int N,M;
	int Counts[51]={};
	int a,b;
	scanf("%d %d",&N,&M);
	for(int i=0;i<M;i++){
		scanf("%d %d",&a,&b);
		Counts[a]++;
		Counts[b]++;
	}
	
	for(int i=0;i<N;i++){
		printf("%d\n",Counts[i+1]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int X; cin>>X;
    int ans=1;
    for(int b=2;b<X;b++){
        int power=b*b;
        for(int p=2;;p++){
            if(power>X) break;
            ans=max(ans,power);
            power*=b;
        }
    }
    cout<<ans<<endl;
 
}


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

bool prime[100001];
int ans[100001];

void build()
{
	int i,j;
	prime[0]=prime[1]=1;
	for(i=2;i*i<=100000;i++)
		for(j=100000/i*i;j>i;j-=i) prime[j]=1;
}

int main()
{
	int q,l,r,i;
	build();
	for(i=1;i<=100000;ans[i]+=ans[i-1],i++)
		if(!prime[i] && !prime[(i+1)/2]) ans[i]=1;
	cin >> q;
	while(q--)
		cin >> l >> r,cout << ans[r]-ans[l-1] << "\n";
} 

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

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> numberOfRoads(N);
    for(int i=0; i<N; i++){
        numberOfRoads.at(i) = 0;
    }

    vector<int> roads(2*M);
    for(int i=0; i<2*M; i++){
        cin >> roads.at(i);
    }

    for(int i=0; i+1<M*2; i+=2){
        numberOfRoads.at(roads.at(i)-1) += 1;
        numberOfRoads.at(roads.at(i+1)-1) += 1;
    }
    for(int i=0; i<N; i++){
        cout << numberOfRoads.at(i) << endl;
    }
}

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

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int min = 0;
  sort(a, a + 3, greater<int>());
  min += a[0] - a[1];
  min += a[1] - a[2];
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a,b;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>o;
        u[o]=i+1;
    }
    for(i=1;i<=n;i++)
    {
        cout<<u[i]<<" ";
    }
    cout<<endl;
}



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

int main()
{
    ll H,W;
    cin >> H >> W;
    ll ans=H*W;
    if(H==1 ||W== 1){
        cout << 1 << endl;
    }
    else if(ans%2==0){
        cout << ans/2 << endl;
    }else{
        cout << (ans/2)+1 << endl;
    }
}


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

int main() {
  
  int N; cin >> N; int sum = 0;
  
  vector<int> vecA(N); vector<int> vecB(N - 1);
  
  for (int i = 0; i < N - 1; i++) cin >> vecB[i];
  
  vecA.front() = vecB.front(); vecA.back() = vecB.back();
  
  for (int i = 1; i < N - 1; i++) {
    
    vecA[i] = min(vecB[i - 1], vecB[i]);
    
  }
  
  for (int x : vecA) sum += x;
  
  cout << sum << endl;
  
}

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

#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 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 

#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, w, weight[110];
  ll value[110], dp[110][100010];
  cin >> n >> w;
  REP(i, n) cin >> weight[i] >> value[i];
  REP(i, w+1) dp[0][i] = 0;
  REP(i, n){
      REP(j, w+1){
          if(j >= weight[i]) dp[i+1][j] = max(dp[i][j], dp[i][j-weight[i]] + value[i]);
          else dp[i+1][j] = dp[i][j];
      }
  }
  cout << dp[n][w] << endl;
}

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

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

    std::vector<int> A(N);
    for (int &a : A) {
        std::cin >> a;
    }

    int count = 0;
    while (std::all_of(A.begin(), A.end(), [](int a) { return a % 2 == 0; })) {
        count ++;
        for (int& a : A) {
            a /= 2;
        }
    }
    std::cout << count << std::endl;
}


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

using namespace std;

typedef long long ll;

void cldflm()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}

int main()
{

	cldflm();

	int a, b, c;
	int cnt = 0;

	cin >> a >> b >> c;

	for (int i = a; i <= b; i++)
	{
		if (i % c == 0)
			cnt++;
	}

	cout << cnt;

	return 0;
}



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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 3;
	if (a == b && b == c && a == c) count=1;
	else if (a != b && b != c && a != c) count=3;
	else count=2;
	cout << count << endl;
}


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

int prime(int i)
{
    if (i == 1) return 0;
    if (i == 2) return 1;
    for (int a = 2; a * a <= i; a++)
    {
        if (!(i % a)) return 0;
    }
    return 1;
}

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

    for (int i = x; ; i++)
    {
        if (prime(i))
        {
            cout << i << endl;
            return 0;
        }
    }
}

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

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

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//solve

// int D
void solve(void)
{
  string ins;
  cin>>ins;
  vector<int> vec (4,0);
  for (int i = 0; i < 4; i++)
  {
    vec[i] = (int)( ins[i] - '0');
  }
  // DEBUG(vec);
  for (int b = 0; b < 8; b++)
  {
    int SUM = vec[0];
    string str = "";
    for (int i = 0; i < 3; i++)
    {
      if((b>>i)&1)
      {
        SUM -= vec[i+1];
        str+= '-';
      }
      else
      {
        SUM += vec[i+1];
        str += '+';
      }
    }
    // DEBUG(b,SUM);
    if(SUM == 7)
    {
      for (int i = 0; i < 4; i++)
      {
        if(i>0)cout<<str[i-1];
        cout<<vec[i];
      }
      cout<<"=7"<<endl;
      return;
      
    }
    
  }
  
  return;
}

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

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

int a[200020];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];

    long long sum = accumulate(a, a + N, 0ll);
    long long sun = 0;
    long long mi = 200000000000000000;
    rep(i, N-1) {
        sun += a[i];
        mi = min(mi, abs(sun - (sum - sun)));
    }
    cout << mi << endl;
}

Measured memory_bytes: 1024
import scala.io.StdIn
import scala.collection.mutable.ListBuffer
import scala.annotation.tailrec

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toInt)

  @tailrec
  def rec(b:ListBuffer[Int], isEven:Boolean, num:Iterator[Int]):Unit = {
      if(num.hasNext) {
        if(isEven) rec(b += num.next, false, num)
        else rec(num.next +=: b, true, num)
      } else return
  }

  val b = ListBuffer.empty[Int]
  val ite = a.iterator

  if((n&1) == 0) rec(b, true, ite)
  else rec(b, false, ite)

  out.println(b.mkString(" "))
  out.flush
}

Measured memory_bytes: 81828
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new aoj0130().doIt();
    }
    class aoj0130{
    	class Pos{
    		int x,y;
    		public Pos(int x,int y) {
    			this.x = x;
    			this.y = y;
    		}
    	}
    	ArrayList<Pos> array = new ArrayList<Pos>();
    	int mx[] = {0,1,0,-1};
    	int my[] = {1,0,-1,0};
    	void bomb(int num){
    		int map[][] = new int [8][8];
    		for(int i = 0;i < 8;i++){
    			String str = sc.next();
    			char ctr[] = str.toCharArray();
    			for(int j = 0;j < 8;j++){
    				if(ctr[j] == '0')map[i][j] = 0;
    				else map[i][j] = 1;
    			}
    		}
    		array.add(new Pos(sc.nextInt()-1,sc.nextInt()-1));
    		while(array.size() > 0){
    			Pos p = array.remove(0);
    			for(int i = 0;i < 4;i++){
    				for(int j = 0;j < 4;j++){
    					if(p.x + mx[j]*i >= 0 && p.x + mx[j]*i < 8 
    							&& p.y + my[j]*i >= 0 && p.y + my[j]*i < 8){
    						if(map[p.y + my[j]*i][p.x + mx[j]*i] == 1){
    							array.add(new Pos(p.x + mx[j]*i,p.y + my[j]*i));
    							map[p.y + my[j]*i][p.x + mx[j]*i] = 0;
    						}
    					}
    				}
    			}
    		}
    		System.out.println("Data "+num+":");
    		for(int i = 0;i < 8;i++){
    			for(int j = 0;j < 8;j++){
    				System.out.print(map[i][j]);
    			}
    			System.out.println();
    		}
    	}
    	void doIt(){
    		int n = sc.nextInt();
    		for(int i = 0;i < n;i++){
    			bomb(i+1);
    		}
    	}
    }
}

Measured memory_bytes: 26332
import sys

lines = sys.stdin.readlines()
w = lines[0]
n = lines[1]
exchanges = lines[2:len(lines)]

ret = list(range(1,int(w)+1))

for line in exchanges:
    line = line.split(",")
    inp = []
    for i in line:
        inp.append(int(i))
    ret[inp[0]-1],ret[inp[1]-1] = ret[inp[1]-1],ret[inp[0]-1]

for i in ret:
    print (i)

Measured memory_bytes: 7548
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    string s; cin >> s;
    int n = s.size();
    //if(n % 2 != 0) n++;
    int count = 0;
    rep(i,n / 2){
        if(s[i] != s[n-i-1])
            count++;
    }
    cout << count;
    }



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N,a=2,b;
	scanf("%d",&N);
	while(a<N){
		a=a*2;
	}
	if(a>N){
	b=a/2;
	}
	else if(a<=N){
	b=a;
	}
	printf("%d\n",b);
	return 0;
}


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

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a + b == 15)
    cout << '+' << endl;
  else if (a * b == 15)
    cout << '*' << endl;
  else
    cout << 'x' << endl;
}


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

const int MAX_H = (int)50 + 5;
const int MAX_W = (int)50 + 5;

struct point {int x, y;};

int h, w;
char s[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main(void){
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; ++i) {
    scanf("%s", &s[i]);
  }

  fill((bool*)visited, (bool*)visited + h, false);

  for (int x = 0; x < h; ++x) for (int y = 0; y < w; ++y) {
    int chain = 0;
    if (s[x][y] == '#' && !visited[x][y]) {
      stack<point> st;
      point tmp = {x, y};
      st.push(tmp);

      while (!st.empty()) {
        point cur = st.top();
        st.pop();

        chain += 1;
        visited[cur.x][cur.y] = true;

        for (int i = 0; i < 4; ++i) {
          int nx = cur.x + dx[i];
          int ny = cur.y + dy[i];
          if (0 <= nx && nx <= h - 1 && 0 <= ny && ny <= w - 1 && !visited[nx][ny] && s[nx][ny] == '#') {
            point ncur = {nx, ny};
            st.push(ncur);
          }
        }
      }
    }
    if (chain == 1) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}

Measured memory_bytes: 256