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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;

ll  qpow(ll x,ll n)
{
     ll sum=1;
     while(n){
        if(n&1)  sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
     }
     return sum;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    cout<<!n<<endl;
     return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
 
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int partition(int *A,int p,int q){
	int x = *(A + q);
  int i=p-1,j;
  for(j=p;j<q;j++){
    if(*(A + j)<=x){
      i++;
      swap(A+i,A + j);
    }
  }
  swap(A+i+1, A+q);
  return i+1;
}
 
int main(){
  int n,i,a;
  int A[100000];
	
  scanf("%d",&n);
	
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  a=partition(A,0,n-1);
	
  for(i=0;i<n;i++){
    if(i)printf(" ");
  	
    if(i==a)printf("[");
 
    printf("%d",A[i]);
  	
    if(i==a)printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2120
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll A, B, C; scanf("%lld%lld%lld", &A, &B, &C);
  if (C-A+B>0&&4*A*B<(C-A-B)*(C-A-B)) Yes();
  else No();


  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
using namespace std;
int main() {
  int a = 0, b = 0;
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
	if(s[i]=='A') a++;
    if(s[i]=='B') b++;
  }
  if (a == 0 || b == 0) cout << "No";
  else cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
public class Main{
    public static void main(String[]args){  
    Scanner sc=new Scanner(System.in);
    long X=sc.nextLong();
    long Y=sc.nextLong();
    int sum=0;
    for(;X<=Y;){
        sum++;
        X=X*2;
    }
    System.out.println(sum);

    }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

int main() {
	ll x;
	cin >> x;
	ll money = 100;
	ll ans = 0;
	while (money < x) {
		money *= 1.01;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
n = int(input())
blue = {}
for _ in range(n):
  s = input()
  if(s in blue):
    blue[s] += 1
  else:
    blue[s] = 1
m = int(input())
red = {}
for _ in range(m):
  t = input()
  if(t in red):
    red[t] += 1
  else:
    red[t] = 1
res = -100
for key, value in blue.items():
  tmp = 0
  if(key in red):
    tmp = blue[key] - red[key]
  else:
    tmp = blue[key]
  if(tmp > res):
    res = tmp
if(res >= 0):
  print(res)
else:
  print(0)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int N,K;
  int l[50];
  int i,j;
  int temp;
  int sum=0;
  
  scanf("%d %d",&N,&K);

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

  for(i=0;i<K;i++){
    for(j=0;j<N;j++){
      if(l[temp]<l[j]){
	temp=j;
      }
    }
    sum+=l[temp];
    l[temp]=0;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    int n,m,a;
    cin>>n>>m;
    while(m--)
    {
        cin>>a;
        n-=a;
    }
    if(n>=0)cout<<n<<endl;
    else cout<<-1<<endl;
    return 0;
}














Measured memory_bytes: 3636
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

string a,b;

int x,y;
string aa,bb;

int main(){
    cin>>a>>b;
    rep(i,b[0]-'0')aa+=a;
    rep(i,a[0]-'0')bb+=b;

    if(aa<bb)cout<<aa<<endl;
    else cout<<bb<<endl;    
    
    return 0;
}


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

using namespace std;

struct edge
{
  int to, cost;
};

int main()
{
  int N, M, L;
  vector< edge > g[41];
  cin >> N >> M >> L;
  for(int i = 0; i < M; i++) {
    int d, a, k, t;
    cin >> d >> a >> k >> t;
    --a;
    g[d * N + a].push_back((edge){d * N + a + k, t});
  }

  int dp[41][41] = {{}};
  int ret = 0;
  for(int i = 0; i <= 5 * N; i++) {
    for(int j = 0; j < L; j++) {
      if(i > 0) dp[j][i] = max(dp[j][i], dp[j][i - 1]);
      for(auto& e : g[i]) {
        dp[j + 1][e.to] = max(dp[j + 1][e.to], dp[j][i] + e.cost);
        ret = max(ret, dp[j + 1][e.to]);
      }
    }
  }
  cout << ret << endl;
}

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


int main() {

    int N; cin >> N;
    vector<int> H(N);
    forn(i, N) cin >> H[i];
    int pre = -999;
    forn(i, N) {
        if (pre <= H[i]-1) {
            pre = H[i]-1;
        } else if (pre <= H[i]) {
            pre = H[i];
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 768
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

class union_find{
	vector<int> a;
public:
	union_find(int n):a(n,-1){}
	int find(int x){
		if(a[x]<0) return x;
		return a[x]=find(a[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x!=y){ a[x]+=a[y]; a[y]=x; }
	}
};

struct edge{
	int u,v,cost;
	bool operator<(const edge &e)const{ return cost<e.cost; }
};

int solve(int n,int m,edge *E){
	union_find U(n);
	sort(E,E+m);

	int cnt=0,res;
	rep(i,m) if(U.find(E[i].u)!=U.find(E[i].v)) {
		U.unite(E[i].u,E[i].v);
		cnt++;
		if(cnt==n/2){ res=E[i].cost; break; }
	}
	return res;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		edge E[10000];
		rep(i,m){
			int u,v,cost; scanf("%d%d%d",&u,&v,&cost); u--; v--;
			E[i]=(edge){u,v,cost};
		}
		printf("%d\n",solve(n,m,E));
	}
	return 0;
}

Measured memory_bytes: 1172
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath> 
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <ll> v1,v2;
int n,ans=0;
ll a[100004],b[100004],pr=0;
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++) cin>>b[i];
	for (int i=0;i<n;i++){
		ll tt=a[i]-b[i];
		pr+=tt;
		if (tt<0) v1.push_back(tt);
		if (tt>0) v2.push_back(tt);
	}
	if (pr<0){
		cout<<"-1";
	}
	ll nnt=0;
	ans=int(v1.size());
	for (int i=0;i<v1.size();i++)
		nnt+=-v1[i];
	sort(v2.begin(),v2.end());
	if (nnt==0){
		puts("0");
		return 0;
	} 
	for (int i=int(v2.size())-1;i>=0;i--){
		nnt-=v2[i];
		if (nnt<=0){
			cout<<ans+int(v2.size())-i;
			return 0;
		} 
	}
}

Measured memory_bytes: 2812
import collections

def main():
    N = int(input())
    D = list(map(int, input().split()))
    M = int(input())
    T = list(map(int, input().split()))

    cD = dict(collections.Counter(D))
    cT = dict(collections.Counter(T))

    for k, v in cT.items():
        if k not in cD:
            print("NO")
            exit()
        else:
            if v > cD[k]:
                print("NO")
                exit()

    print("YES")


if __name__ == "__main__":
    main()


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22)cout<<"bust"<<endl;
  else cout<<"win"<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>                                                
#include <vector>  
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#define endl "\n"

using ll = long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    string three = "No";
    int count = 0;
    while (N--) {
        pair<int, int>roll;
        cin >> roll.first;
        cin >> roll.second;
        if (roll.first == roll.second) {
            count++;
        }
        else if (roll.first != roll.second) {
            count = 0;
        }
        if (count == 3) {
            three = "Yes";
            break;
        }

    }
    cout << three << endl;
    
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int w = scan.nextInt();
        int h = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();
        if(x >= r && x <= w - r && y >= r && y <= h - r) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 26376
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	int num[2] = { 0 };
	for (int i = 0; i < s.length(); i++) {
		num[s[i] - '0']++;
	}
	cout << min(num[0], num[1]) * 2 << endl;

	return 0;
}

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

int main() {
  int S;
  cin >> S;
  int A = S/100;
  int B = S%100;
  if (A <= 12 && B <= 12 && A >= 1 && B >= 1) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (A > 12 && B <= 12 && B >= 1) {
    cout << "YYMM" << endl;
  }
  else if (A == 0 && B <= 12 && B >= 1) {
    cout << "YYMM" << endl;
  }
  else if (A <= 12 && B > 12 && A >= 1 ) {
    cout << "MMYY" << endl;
  }
  else if (A <= 12 && B == 0 && A >= 1 ) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "NA" << endl;
  }
}
    

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

int a[105][105] = {0};
int main() {
	
	int r, c, sumr, sumc;
	cin >> r >> c;
	for (int y = 1; y <= r; y++){
		sumc = 0;
		for (int x = 1; x <= c; x++){
			cin >> a[x][y];
			sumc += a[x][y];
		}
		a[c + 1][y] = sumc;
	}
	
	for (int x = 1; x <= c + 1; x++) {
		sumr = 0;
		for (int y = 1; y <= r; y++) {
			sumr += a[x][y];
		}
		a[x][r + 1] = sumr;
	}
	
	for (int y = 1; y <= r + 1; y++){
		for (int x = 1; x <= c + 1; x++){
			cout << a[x][y];
			if (x <= c) {
				cout << " ";
			}
		}
		cout << "\n";
	}
	
	return 0;
}


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

function main()
	n = readline() |> parseInt
	v = Array{Int}(2,n)
	for i in 1:n
		v[:,i] = readline() |> split |> parseMap
	end
	num = [i for i in 1:n]
	sy = sum(v[1,:])
	sz = sum(v[2,:])
	x = [i for i in 1:n]
	g = Array{Int}(2,2*n)
	g[1,1:n] = x
	g[1,n+1:2*n] = x
	g[2,1:n] = v[1,:]
	g[2,n+1:2*n] = v[2,:]
	g = sortcols(g,by=y->y[2])
	sw = 0
	pre = sum(g[2,1:n+1])
	if length(Set(g[1,1:n])) < n
		sw = pre - g[2,n+1]
	elseif g[1,n] != g[1,n+1]
		sw = pre-g[2,n]
	else
		sw = min(pre+g[2,n+2]-g[2,n]-g[2,n+1],pre-g[2,n-1])
	end
	print(min(sy,sz,sw))
end

main()

Measured memory_bytes: 172296
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
class InputReader {
    BufferedReader buf;
    StringTokenizer tok;
 
    public InputReader() {
        buf = new BufferedReader(new InputStreamReader(System.in));
//        try {
//            Path currentRelativePath = Paths.get("");
//            String s = currentRelativePath.toAbsolutePath().toString();
//            String curDir = System.getProperty("user.dir");
//            System.out.println("current dir: " + s);
//            buf = new BufferedReader(new FileReader("/Users/wangdong/Dropbox/LC_Java/src/test/resources/testA.txt"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }
 
    public boolean hasNext() {
        while (tok == null || !tok.hasMoreElements()) {
            try {
                tok = new StringTokenizer(buf.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
 
    public String next() {
        if (hasNext()) return tok.nextToken();
        return null;
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public  Double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
 
    public BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }
}
 
 
public class Main {
  public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt(), m = in.nextInt();
	//     	out.println(n + " , " + m);
    	int tot = 0; 
    	int[] times = new int[m];
    	for (int i = 0; i < m; i++){
          
          times[i] = in.nextInt();
   		  tot += times[i];
          //out.print(times[i] + " , ");
        }
		out.println(tot > n ? -1  :  n-tot);
        out.close();
    }
  
}


Measured memory_bytes: 34076
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main(){
    string s; cin >> s;
    for(int i=0; i<s.length(); i += 2){
        if(s[i]!= 'h' || s[i+1] != 'i'){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;

}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  if(s[0] == 'A' &&s[1] == 'A' &&s[2] == 'A') printf("No\n");
  else if(s[0] == 'B' &&s[1] == 'B' &&s[2] == 'B') printf("No\n");
  else printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 300003

int n, m, jaw, l[mx], r[mx], maks[mx * 4], lazy[mx * 4];
vector<int> ve[mx];

void build(int idx, int l, int r){
	if(l == r){
		maks[idx] = -(m - l + 1);
		return;
	}
	int mid = (l + r) >> 1;
	build(2 * idx, l, mid);
	build(2 * idx + 1, mid + 1, r);
	maks[idx] = max(maks[idx * 2], maks[idx * 2 + 1]);
}

void upd(int idx, int l, int r, int fl, int fr, int val){
	if(fl > r || fr < l)
		return;
	if(fl <= l && r <= fr){
		maks[idx] += val;
		lazy[idx] += val;
		return;
	}
	int mid = (l + r) >> 1;
	if(lazy[idx] != 0){
		maks[idx * 2] += lazy[idx];
		maks[idx * 2 + 1] += lazy[idx];
		lazy[idx * 2] += lazy[idx];
		lazy[idx * 2 + 1] += lazy[idx];
		lazy[idx] = 0;
	}
	upd(2 * idx, l, mid, fl, fr, val);
	upd(2 * idx + 1, mid + 1, r, fl, fr, val);
	maks[idx] = max(maks[idx * 2], maks[idx * 2 + 1]);
}

int cari(int idx, int l, int r, int fl, int fr){
	if(fl > r || fr < l)
		return -1e9;
	if(fl <= l && r <= fr)
		return maks[idx];
	int mid = (l + r) >> 1;
	if(lazy[idx] != 0){
		maks[idx * 2] += lazy[idx];
		maks[idx * 2 + 1] += lazy[idx];
		lazy[idx * 2] += lazy[idx];
		lazy[idx * 2 + 1] += lazy[idx];
		lazy[idx] = 0;
	}
	return max(cari(2 * idx, l, mid, fl, fr), cari(2 * idx + 1, mid + 1, r, fl, fr));
}

int main(){
	cin >> n >> m;
	int hit = 0;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		if(l[i] == 0 && r[i] == m + 1)
			continue;
		hit += 1;
		ve[l[i]].pb(i);
	}
	jaw = max(jaw, hit - m);
	build(1, 1, m);
	for(int i = 1; i <= n; i++){
		if(l[i] == 0 && r[i] == m + 1)
			continue;
		upd(1, 1, m, 1, r[i], 1);
	}
	for(int i = m; i >= 0; i--){
		for(int j : ve[i + 1]){
			//hapus j
			upd(1, 1, m, 1, r[j], -1);
		}
		jaw = max(jaw, cari(1, 1, m, i + 2, m) - i);
	}
	// debug(jaw);
	cout << jaw + n - hit << endl;
}

Measured memory_bytes: 20224
W, H, N = [int(n) for n in raw_input().split(" ")]
a = [[int(x) for x in raw_input().split(" ")] for n in range(N)]
 
x_min = y_min = 0
x_max, y_max = W, H
 
for s in a:
  if s[2] == 1:
    x_min = max(x_min, s[0])
  elif s[2] == 2:
    x_max = min(x_max, s[0])
  elif s[2] == 3:
    y_min = max(y_min, s[1])
  elif s[2] == 4:
    y_max = min(y_max, s[1])
 
 
if (x_max > x_min) and (y_max > y_min):
  print (x_max - x_min) * (y_max - y_min)
else:
  print 0

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll a, b, x;
  cin >> a >> b >> x;
  ll ans = b/x+1;
  ans -= (a-1 >= 0) ? (a-1)/x+1 : 0;
  cout << ans << endl;
  return 0;
}

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

int main()
{
	ll a,b;
	cin>>a>>b;
	if(a*(b-1)%b)cout<<a*(b-1)<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Aatcoder solver = new Aatcoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class Aatcoder {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {

            int n = in.scanInt();
            int k = in.scanInt();
            if (k >= n) {
                out.println(1);
                return;
            }
            int ind = -1;
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) {
                ar[i] = in.scanInt();
                if (ar[i] == 1) ind = i;
            }
            int ans = 0;
            int ii = ind;
            for (; ii < n - 1; ii = ii + (k - 1)) {
                ans++;
            }
            ind -= (ii - (n - 1));
            for (int i = ind; i >= 1; i -= (k - 1)) {
                ans++;
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

int main(void){
    char s[17],t[17]="CODEFESTIVAL2016";
    int ans=0;
    scanf("%s",s);
    for (int i=0; i<16; i++){
        if (s[i]!=t[i]){
            ans++;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
    int x = 0;
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans;

    for(char i : S){
        if (i == 'I'){
            x++;
            ans = max(ans, x);
        }else{
            x--;
        }
    }

    cout << ans << endl;

}

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

int main()
{
  int N, L;
  cin >> N >> L;
  
  int orgPieTaste = 0;
  for (int i = 0; i < N; i++)
  {
    orgPieTaste += (L + i);
  }
  
  int maxPieTaste = 0;
  int minAppleDiff = 99999999;
  for (int i = 0; i < N; i++)
  {
    int diff = abs(L + i);
    if (diff < minAppleDiff)
    {
      maxPieTaste = orgPieTaste - (L + i);
      minAppleDiff = diff;
    }
  }
  cout << maxPieTaste << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int main() {
    double x, y, current_angle;
    int step, angle;
    x = 0, y = 0, current_angle = 90;

    while (true) {
        scanf("%d,%d", &step, &angle);

        if (!step && !angle) {
            break;
        }

        x += step * cos(current_angle * M_PI / 180);
        y += step * sin(current_angle * M_PI / 180);
        current_angle -= angle;
    }

    printf("%d\n%d\n", (int)x, (int)y);

    return 0;
}

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

using namespace std;

int n;
int g[510][510];
int lvl;

int main(){
	scanf("%d",&n);
	lvl=1;
	for(int k=1;k<=n;k<<=1){
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(g[i][j]==0 && (i&k)!=(j&k)){
					g[i][j]=lvl;
				}
			}
		}
		lvl++;
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			printf("%d",g[i][j]);
			if(j!=n)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

int main(){

    vector<int> A(3);
    readline(3, A);

    int min = 100000000;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(i != j && i != k && j!= k){
                    int v = abs(A[j] - A[i]) + abs(A[k] - A[j]);
                    if(v < min){
                        min = v;
                    }
                }
            }
        }
    }

    cout << min;

    return 0;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w,n;
    cin>>h>>w>>n;
    swap(h,w);
    vector<pair<int,int>> pts;
    rep(i,0,n) {
        int a,b;
        cin>>a>>b;
        pts.emplace_back(a,b);
    }
    sort(all(pts));
    int ans=w;
    int x=1, y = 0;
    bool candown = true;
    rep(i,0,n) {
        int xx,  yy;
        tie(xx,yy) = pts[i];
        if(xx>x) {
            y+=xx-x;
            x = xx;
            if(!candown) --y;
            candown = true;
        }
        if(yy<=y) {
            ans = xx-1;
            break;
        }
        else if(yy==y+1) candown = false;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 2420
//
//  main.cpp
//  programs
//
//  Created by Arunesh Sarker on 18/11/19.
//  Copyright © 2019 Arunesh Sarker. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_set>
using namespace std;

typedef long long ll;
#define mod 1000000007
    // 60 60 30 40 5 5
     
  // Function to return LCM of two numbers
 ll gcd(ll a, ll b)
 {
     if (a == 0)
         return b;
     return gcd(b % a, a);
 }
   
 // Function to find gcd of array of
 // numbers
 int findGCD(int arr[], int n)
 {
     int result = arr[0];
     for (int i = 1; i < n; i++)
     {
         result = gcd(arr[i], result);
   
         if(result == 1)
         {
            return 1;
         }
     }
     return result;
 }
// 2 3 4 4 18 24
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/gcd(a,b)<<"\n";
    
    
    
}


Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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 namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int H,W; cin >> H >> W;
    vector<string> maze(H);

    REP(i,H) cin >> maze[i];

    REP(y,H) {
        string S = "";
        REP(x,W) {
            if(maze[y][x] == '#') S += '#';

            else {

            int cnt = 0;

            for(int dy = -1; dy <= 1; dy++) 
                for(int dx = -1; dx <= 1; dx++) {
                    int nx = x + dx;
                    int ny = y + dy;

                    if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
                    if(maze[ny][nx] == '#') cnt++;
                }
            
            S += to_string(cnt);
            }
        }
        maze[y] = S;
    }

    REP(i,H) cout << maze[i] << endl;
}

Measured memory_bytes: 256
def check(d1, d2, direction):
    if d1 in direction and not d2 in direction:
        return False
    if d2 in direction and not d1 in direction:
        return False
    return True

S = input()
direction = {s for s in S}
for (x, y) in [("N", "S"), ("W", "E")]:
    if not check(x, y, direction):
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3060
<?php
  
  fscanf(STDIN,"%d %d %d",$n,$a,$b);

$sum_one = 0;
$sum_eve = 0;

for($i=1;$i<=$n;$i++){
  $i_str = (string)$i;
  for($j=0;$j<strlen($i_str);$j++){
    $sum_one += $i_str[$j];
  }
   // echo $sum_one."\n";
  if($sum_one>=$a && $b>=$sum_one){
    $sum_eve += $i;
  }
  $sum_one = 0;
}



echo $sum_eve."\n";

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{   
    int X, t;
    cin >> X >> t;
    if((X-t) >= 0)
    cout << X - t << endl;
    else if((X-t) < 0)
    cout << 0 << endl;    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[][] ab = new String[n][3];
        for (int i = 0; i < n; i++) {
            ab[i][0] = sc.next();
            ab[i][1] = sc.next();
            ab[i][2] = String.valueOf(i);
        }
        
        int count = 0;
        while (count < n) {
            String name = "zzzzzzzzzzzz";
            int score = 0;
            int idx = 0;
            for (int i = 0; i < n; i++) {
                if (ab[i][0].compareTo(name) < 0) {
                    name = ab[i][0];
                    score = Integer.valueOf(ab[i][1]);
                    idx = i + 1;
                } else if (ab[i][0].compareTo(name) == 0) {
                    if (Integer.valueOf(ab[i][1]) > score) {
                        score = Integer.valueOf(ab[i][1]);
                        idx = i + 1;
                    }
                }
            }
            
            System.out.println(idx);
            count++;
            ab[idx - 1][0] = "zzzzzzzzzzzz";
        }
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
 
using namespace std;
int n;
 
long long valor[105];
long long peso [105];
long long dp [105][1060000];
int p;
 
long long pd(long long id, long long aguenta)
{
    if (dp[id][aguenta]!=-1){return dp[id][aguenta];}
    if (id==n or !aguenta) {return dp[id][aguenta]=0;}
 
    long long nao_pega=pd(id+1,aguenta);
 
    if(peso[id]<=aguenta){
       long long pega=valor[id]+pd(id+1, aguenta - peso[id]);
        return dp[id][aguenta]=max(pega,nao_pega);
    }
 
 
return dp[id][aguenta]=nao_pega;
 
}
 
 
 
 
 
int main ()
{
    cin>>n;
    cin>>p;
for (int i=0;i<n;i++){
    cin>>peso[i];
    cin>>valor[i];
 
 
}
memset(dp,-1,sizeof(dp));
cout<<pd(0,p);
 
 
    return 0;
}

Measured memory_bytes: 869760
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(10**5+1)
for i in xrange(n):
    cnt[a[i]]+=1
cnt1=0
cnt2=0
for i in xrange(10**5+1):
    if cnt[i]==0:continue
    if cnt[i]%2==0:
        cnt2+=1
    else:
        cnt1+=1
if cnt2%2==0:
    print cnt1+cnt2
else:
    print cnt1+cnt2-1


Measured memory_bytes: 11304
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

edges = floyd_warshall(edges)

for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)


Measured memory_bytes: 29028
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main() {
    int N;
    cin >> N;
    vint L(N);
    int sum = 0;
    int m_edge = 0;
    rep(i, N) {
        cin >> L[i];
        m_edge = max(m_edge, L[i]);
        sum += L[i];
    }
    if (m_edge < (sum - m_edge))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	int n;

	while (std::cin >> n) {
		int result = 0;
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				for (int k = 0; k < 10; k++)
					for (int l = 0; l < 10; l++)
						if (i+j+k+l == n) result++;
		std::cout << result << std::endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    string s, t; cin >> s >> t;
    int ans = INT_MAX;
    for (int i = 0; i + t.length() - 1 < s.length(); i++) {
        int cur = 0;
        for (int j = 0; j < t.length(); j++) {
            if (s[i + j] != t[j]) cur += 1;
        }
        ans = min(ans, cur);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, a, b, c, d; cin >> n >> a >> b >> c >> d;
  string s; cin >> s; s += "#####";
  bool is_arrive = true;
  rep(i, a, max(c, d)-2) {
    if (s.at(i) == '#' && s.at(i+1) == '#') {
      is_arrive = false;
      break;
    }
  }
  if (is_arrive) {
    if (c < d) {
      cout << "Yes" << endl;
    } else {
      bool is_swap = false;
      rep(i, b-2, d-1) {
        if (s.at(i) == '.' && s.at(i+1) == '.' && s.at(i+2) == '.') {
          cout << "Yes" << endl;
          is_swap = true; break;
        }
      }
      if (!is_swap) cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

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

    double d = (double)(n*2.0*3.14159265358);
    cout<<d;
    
   
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n; cin >> n;
    str s; cin >> s;
    int ans = 0;
    for (int i=0; i<n-2; i++){
        if((s[i] == 'A') && (s[i+1] == 'B') && (s[i+2] == 'C')){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> pic(h);
  rep(i,h){
    string H;
    cin>>H;
    pic[i]=H;
  }
  rep(i,w+2)cout<<"#";
  cout<<endl;
  rep(i,h){
    cout<<"#";
    cout<<pic[i];
    cout<<"#"<<endl;
  }
  rep(i,w+2)cout<<"#";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int cnt = 0;
  char S[3];
  scanf("%s",S);
  int i;
  for(i = 0; i < 3; i++){
    if(S[i] == 'o'){
      cnt++;
    }
  }
  printf("%d",700 + cnt * 100);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    ans = 0
    for i in range(1000):
        i = str(i).zfill(3)
        prev = -1
        for s in i:
            pos = S.find(s, prev + 1)
            if pos > prev:
                prev = pos
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39280
// Problem : B - Sum AND Subarrays
// Contest : AtCoder - Dwango Programming Contest V 
// URL : https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b
// Memory Limit : 1024 MB
// Time Limit : 2525 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1001;

int n, k;
int a[N];
ll sum[N];
multiset<ll> ms;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	for (int l = 1; l <= n; l++) {
		for (int r = l; r <= n; r++) {
			ms.insert(sum[r] - sum[l - 1]);
		}
	}
	ll ans = 0;
	for (int i = 60; i >= 0; i--) {
		int cnt = 0;
		vector<ll> doom;
		for (auto& d : ms) {
			if ((d >> i) & 1) {
				cnt++;
			} else {
				doom.push_back(d);
			}
		}
		if (cnt >= k) {
			for (auto& x : doom) {
				ms.erase(ms.find(x));
			}
			ans |= 1ll << i;
		}
	}
	cout << ans;
}

Measured memory_bytes: 32956
#include<bits/stdc++.h> 
using namespace std;
char a[4],b[4];
int main(){
	cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]) printf("YES\n");
	else printf("NO\n");
    return 0;
}

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

ll h,w,a,b,fakt[1000000],rez,mod=1000000007;

ll step(ll a,ll b)
{
    if(b==0)
        return 1;
    else
    {
        ll p=step(a,b/2)%mod;
        if(b%2==0)
            return (p*p)%mod;
        else
            return (((p*p)%mod)*a)%mod;
    }
}

ll inverse(ll n)
{
    return step(n,mod-2)%mod;
}

ll binomni(ll n,ll k)
{
    return (( ( fakt[n]*inverse(fakt[k]) )%mod * inverse(fakt[n-k]) )%mod );
}

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

    cin>>h>>w>>a>>b;
    //a=h-a+1;
    fakt[0]=1;
    for(ll i=1;i<1000000;i++)
    {
        fakt[i]=fakt[i-1]*i;
        fakt[i]%=mod;
    }

    for(ll i=1;i<=h-a;i++)
    {
        rez+=binomni(b+i-2,b-1)*binomni(h+w-b-1-i,h-i);
        rez%=mod;
    }

    cout<<rez<<endl;

    return 0;
}
/*
100000 100000 44444 55555

738162020
*/


Measured memory_bytes: 11432
def count array
  d = Array.new(array.size, 0)
  0.upto(array.size - 1) do |i|
    0.upto(array.size - 1) do |j|
      d[i] += 1 if array[i] == array[j]
    end
  end
  d
end

while (n = $stdin.gets.to_i) > 0 do
  c = 0
  num = $stdin.gets.chomp.split(" ").map(&:to_i)
  loop do
    #分布を計測する
    array = count num;
    #前回の結果と比較して同じなら終了
    if num == array
      break
    end
    #カウントアップ
    c += 1
    #ベース配列を更新
    num = array
  end
  puts c
  puts num.join(' ')
end

Measured memory_bytes: 6100
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, q;
	cin >> N >> q;

	string s;
	cin >> s;

	Int len = s.size();


	vector<Int> a(len + 1, 0);
	for (Int i = 0; i < len; i++) {
		if ((s[i] == 'A') && (s[i + 1] == 'C')) {
			a[i + 1] = a[i] + 1;
			continue;
		}
		a[i + 1] = a[i];
	}

	
	Int l, r;
	for (Int i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		printf("%lld\n", a[r] - a[l]);
	}

}

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

int main(){


    int n; cin >> n;
    vector<int> a(100010);
    for(int i = 0; i < n; i++){
        int in; cin >> in;
        a[in]++;
    }

    int cnt = 0;

    for(int i = 0; i < 100010; i++){
        if(a[i] > 1){
            if(a[i] % 2 == 0){
                cnt += a[i] - 2;
                a[i] = 2;
            }else{
                cnt += a[i] - 1;
                a[i] = 1;
            }
        }
    }
    
    int cnt_e = 0;
    for(int i = 0; i < 100010; i++){
        if(a[i] == 2) cnt_e++;
    }

    if(cnt_e % 2 == 0){
        cnt += cnt_e;
    }else{
        cnt += cnt_e + 1;
    }

    cout << n - cnt << endl;

    return 0;

}

Measured memory_bytes: 640
function Main(input) {
    input = input.split("\n");
    tmp1 = input[0].split(" ");
    tmp2 = input[1].split(" ");
    
    var n = parseInt(tmp1[0], 10);
    var k = parseInt(tmp1[1], 10);
    
	for (var i = 0; i < n; i++) {
	tmp2[i]=parseInt(tmp2[i], 10);
	}
	
    var p = tmp2;
    
    p.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
	});
    
    var result = 0
	for (var i = 0; i < k; i++) {
	result = result + p[i];
	}
    
	console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29728
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;


void solve() {
    string x,y;
    cin >> x >> y;
    int nx = x.size();
    int ny = y.size();
    // dp[i][j] : xの 1 ~ i 文字目 とyの 1 ～ j 文字目　までの最小共通部分列の長さ
    int dp[nx+1][ny+1];
    rep(i,nx+1){
        rep(j,ny+1){
            dp[i][j] = 0;
        }
    }

    rep(i,nx){
        rep(j,ny){
            if(x[i]==y[j]){
                dp[i+1][j+1] = dp[i][j]+1;
            }else{
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }
    
    print(dp[nx][ny]);

}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    int q; cin >> q;
	while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B,C;
  cin >> A >> B >> C;
  if(A == 5 && B == 5 && C == 7) {
    cout << "YES" << endl;
  } else if(A == 5 && B == 7 && C == 5) {
    cout << "YES" << endl;
  } else if(A == 7 && B == 5 && C == 5) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3620
n=int(input())
s=[]
for i in range(n):
    s.append(int(input()))
if(sum(s)%10!=0):
    print(sum(s))
else:
    s.sort()
    for i in range(n):
        if(s[i]%10!=0):
            print(sum(s)-s[i])
            break
    else:
        print(0)


Measured memory_bytes: 3060
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

sum_A = sum(A)
d_candidate = make_divisors(sum_A)

for d in d_candidate:
    R = [a % d for a in A]
    R.sort()
    sum_R = sum(R)

    X, mod = divmod(sum_R, d)
    if mod != 0:
        continue

    if sum(R[:N-X]) <= K and (X * d - sum(R[-X:])) <= K:
        print(d)
        break


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 2e5 + 2;

// string to_=================================================

vector<bool> vis(NN, 0);
vi d;

void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> n >> k;
      vi a(n);
      fr(i, 0, n) {
            cin >> a[i];
            a[i]--;
      }
      m = 0;
      while(!vis[m]) {
            d.pb(m);
            vis[m] = 1;
            m = a[m];
      }
      // m is visited
      int l = sz(d);
      for(i = 0; i < l; i++) {
            if(d[i] == m) break;
      }

      // d[i..l-1] is cycle
      int cyclen = l - i;
      if(k < l) {
            cout << d[k]+1 << endl;
      }      else {
            k = k - i;
            k %= cyclen;
            cout << d[k + i]+1 << endl;
      } 
      // cout << d[k]+1 << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 6924
//https://atcoder.jp/contests/dp/tasks/dp_k
#include <bits/stdc++.h>
#define ALL(e) e.begin(), e.end()
#define RALL(e) e.rbegin(), e.rend()
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define dbg(x) (cerr << #x << ":" << x)
#define mid (l + r) / 2
#define fi first
#define sc second
#define N 1000000009

using namespace std;

typedef long long int lli;

int main(){
	ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector <int> ar(n);
	
	int dp[k+1][2];
	
	memset(dp, 0, sizeof dp);

	for(int i=0; i<n; i++) cin >> ar[i];

	dp[0][0] = 1;
	dp[0][1] = 0;


	for(auto s: ar){
		for(auto p: {0, 1}){
			dp[s][p] = p;
		}
	}

	for(int i=1; i<=k; i++){
		for(auto a: {0, 1}){
			bool at_least = false;
			for(auto s: ar){
				if(i >= s){
					dp[i][a] = dp[i-s][1-a];
					at_least = true;
					if(dp[i][a] == a)
						break;
				}
			}
			
			if(!at_least){
				dp[i][a] = 1-a;
			}
		}
	}

	cout << (dp[k][1] ? "First" : "Second");

	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_2020_0217_003();
	}


	public static void solve_2020_0217_003(){

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String kw = "AC";

		int[] l = new int[Q];
		int[] r = new int[Q];

		for(int i=0;i<Q;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		//cumulative sum

		int[] cs = new int[N+1];
		cs[0] = 0;
		cs[1] = 0;

		for(int i=1;i<N;i++){

			int cs_tmp = 0;

			if(S.substring(i-1, i+1).equals(kw)){
				cs_tmp = 1;
			}

			cs[i+1] = cs[i] + cs_tmp;
		}

		//cs[r-1] - cs[l-1]
		for(int i=0;i<Q;i++){

			int ans = cs[r[i]] - cs[l[i]];
			System.out.println(ans);
		}


	}
}

Measured memory_bytes: 86108