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

int numcup(const void *n1,const void *n2){
  if(*(long *)n1 < *(long *)n2){
    return -1;
  }
  else if(*(long *)n1 > *(long *)n2){
    return 1;
  }
  else{ 
    return 0;
  }
}

int main(void){
  int n;
  scanf("%d",&n);
 
  long a[n];
  
  for(int i = 0;i < n;i ++){
    scanf("%ld",&a[i]);
  }
  
  qsort(a,n,sizeof(long),numcup);
    
   long temp = a[0];
   int count = 0 , ans = 0;
   a[n] = '\0';
 for(int i = 0; i <= n;i ++){
   if(temp == a[i]){
     count ++;
   }
   else if(temp != a[i]){
     if(count%2 != 0){
       ans ++;
     }
     count = 1;
     temp = a[i];
   }
 }
    printf("%d",ans);
    
    return 0;
  }


Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

vector<vector<int>> G;
int N;
map<P, int> mp;

void dfs(int v, int pv, int pc) {
  int color = 0;
  for (auto nv : G[v]) {
    if (pv == nv) continue;
    color++;
    if (pc == color) color++;
    mp[P(v, nv)] = color;
    mp[P(nv, v)] = color;
    dfs(nv, v, color);
  }
}

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

  cin >> N;
  G.assign(N, vector<int>());
  int a, b;
  vector<P> ab;
  rep(i, N - 1) {
    cin >> a >> b;
    a--, b--;
    ab.emplace_back(a, b);
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  dfs(0, -1, -1);

  int k = 0;
  vector<int> ans;
  for (int i = 0; i < N - 1; i++) {
    ans.emplace_back(mp[ab[i]]);
    k = max(k, ans.back());
  }

  cout << k << endl;
  for (auto x : ans) {
    cout << x << endl;
  }

  return 0;
}

Measured memory_bytes: 21752
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dis=[]
for i in range(M):
    d=list(map(int,input().split()))
    dis.append(d)
mn=min(a)+min(b)
for x,y,c in dis:
    r1=a[x-1]+b[y-1]-c
    if(r1<mn):
        mn=r1
print(mn)

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

int main(){
    int n;
    cin>>n;
    int arr[n][3];
    vector<vector<int>>dp(n,vector<int>(3,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>arr[i][j];
        }
    }
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];

    for(int i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][1]+arr[i][0],dp[i-1][2]+arr[i][0]);
        dp[i][1] = max(dp[i-1][0]+arr[i][1],dp[i-1][2]+arr[i][1]);
        dp[i][2] = max(dp[i-1][0]+arr[i][2],dp[i-1][1]+arr[i][2]);
    }
    int res = 0;
    for(int i=0;i<3;i++)res=max(res,dp[n-1][i]);
    cout<<res;
    return 0;
}

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

using namespace std;

int main()
{
    int n,k,x,y, result =0 ;

    cin >> n>>k>>x>>y ;

    if(n <= k){
        result = x*n ;
    }else{
        result = x*k +(n-k)*y;
    }

    cout << result;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i, j, H, W;
	
	while(1){
	    scanf("%d %d",&H,&W);
	    if(H == 0 && W == 0){
		   break;
	    }
		
		for(i = 0; i < H; i++){
			for(j = 0;j < W; j++){
				if(i != 0 && i != H - 1 && j != 0 && j != W - 1){
					printf(".");
				}else{
			    	printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 600005;

char str[maxn];int n[maxn],L,sum;
int main()
{
	#ifdef Amberframe
		freopen("agc011e.in","r",stdin);
		freopen("agc011e.out","w",stdout);
	#endif
	scanf("%s",str+1);L=strlen(str+1);
	for (int i=1;i<=L;i++) n[i]=str[L-i+1]-'0';
	for (int t=0,i=1;i<=L+10;i++)
		n[i]=n[i]*9+t,t=n[i]/10,n[i]%=10,sum+=n[i];
	for (int k=0;;k++) {
		if (sum<=9*k) {printf("%d\n",k);return 0;}
		else {
			n[1]+=9;sum+=9;int p=1;
			while (n[p]>=10) n[p]-=10,sum-=9,n[++p]++;
		}
	}
	return 0;
}

Measured memory_bytes: 2688
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(x => x.to!int-1).array;

    auto B = new int[](N);
    foreach (a; A) B[a] += 1;

    B.each!writeln;
}

Measured memory_bytes: 9704
#include "bits/stdc++.h"
#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define P(s) cout<<(s)<< endl
#define P2(a, b) cout<<(a) << " " << (b) << endl
using namespace std;
typedef long long ll;

struct teams{
	int ac=0;
	int time=0;
	int team_name=0;
};

bool cmp(const teams &A, const teams &B){
	return A.ac > B.ac ||
		(A.ac == B.ac && A.time < B.time) ||
		(A.ac == B.ac && A.time == B.time && A.team_name > B.team_name);
}

int main() {
	int M,T,P,R;
	while(cin >> M >> T >> P >> R && M){
		int m,t,p,j;
		vector<vector<int>> ac(T,vector<int>(P,0));
		vector<vector<int>> time(T,vector<int>(P,0));
		vector<vector<int>> pena(T,vector<int>(P,0));

		REP(i,0,R){
			cin >> m >> t >> p >> j;
			t--;p--;
			if(j==0){
				ac[t][p]++;
				time[t][p]+=m+pena[t][p]*20;
			}else{
				pena[t][p]++;
			}
		}
		vector<teams> ranp;
		REP(i,0,T){
			teams team;
			REP(j,0,P){
				team.ac+=ac[i][j];
				team.time+=time[i][j];
			}
			team.team_name=i+1;
			ranp.push_back(team);
		}

		sort(ranp.begin(),ranp.end(),cmp);
		/**
		for(auto r : ranp){
			P2(r.team_name,r.ac);
		}
		 **/

		cout << ranp[0].team_name;
		REP(i,1,ranp.size()){
			if(ranp[i-1].ac==ranp[i].ac && ranp[i-1].time==ranp[i].time){
				cout << '=' << ranp[i].team_name;
			}else{
				cout << ',' << ranp[i].team_name;
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, a[100100], num[100100], ans, even;

int main () {
        scanf("%d", &N);
        fo(i, 0, N) scanf("%d", &a[i]), num[a[i]]++;

        fo(i, 1, 100100) {
                if (num[i] > 0) {
                        ans++;
                        if (num[i]%2 == 0) {
                                even++;
                        }
                }
        }

        if (even&1) ans--;

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

        return 0;
}


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

using namespace std;
using ll = long long;

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

    ll ans = 0ll;
    ll sum = 0ll;
    for(int i=0;i<N+1;i++){
        if(A[i] == 0){
            ans += sum/2;
            sum = 0ll;
        }else{
            sum += A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
//最大公約数
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
//最小公倍数
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    ll x,y;
    cin>>x>>y;
    for(int i=0;100>=i;++i){
        for(int j=0;100>=j;++j){
            if(i+j==x&&2*i+4*j==y){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<list>
using namespace std;
#define LL long long
#define INF 20001
struct e{
	int cost, to;
};
int main(){
	int n, m, c, s, g;
	while (1){
		cin >> n >> m >> c >> s >> g;
		if (n + m + c + s + g == 0)return 0;

		vector<vector<vector<int>>> edge(c + 1, vector<vector<int>>(n + 1, vector<int>(n + 1, INF)));
		for (auto &i : edge)
		{
			for (int j = 1; j <= n; j++)
				i[j][j] = 0;
		}
		for (int i = 0; i < m; i++)
		{
			int x, y, d, cc;
			cin >> x >> y >> d >> cc;
			edge[cc][x][y] = edge[cc][y][x] = min(edge[cc][x][y], d);
		}
		for (int cc = 1; cc <= c; cc++)
		{
			for (int k = 1; k <= n; k++)for (int j = 1; j <= n; j++)for (int i = 1; i <= n; i++)edge[cc][i][j] = min(edge[cc][i][j], edge[cc][i][k] + edge[cc][k][j]);
		}
		vector<vector<int>> cost(c + 1, vector<int>(20002, 0));
		vector<int> p(c + 1);
		for (int i = 1; i <= c; i++)
		{
			cin >> p[i];
		}
		vector<vector<int>> q(c + 1);
		vector<vector<int>> r(c + 1);
		for (int cc = 1; cc <= c; cc++){
			q[cc].resize(p[cc]);
			q[cc][0] = 0;
			for (int i = 1; i < p[cc]; i++)
				cin >> q[cc][i];
			r[cc].resize(p[cc] + 1);
			for (int i = 1; i <= p[cc]; i++){
				cin >> r[cc][i];
			}
			q[cc].push_back(20000);

			
		}
		for (int cc = 1; cc <= c; cc++){
			for (int i = 1; i <= p[cc]; i++)
			for (int j = q[cc][i - 1] + 1; j <= q[cc][i]; j++)
				cost[cc][j] = cost[cc][j - 1] + r[cc][i];
			cost[cc][INF] = INF*INF;

		}
		vector<vector<int>> d(n + 1, vector<int>(n + 1));
		for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++){
			if (i == j){
				d[i][j] = 0;
				continue;
			}
			d[i][j] = INF*INF;
			for (int cc = 1; cc <= c; cc++)
				d[i][j] = min(d[i][j], cost[cc][edge[cc][i][j]]);

		}
		for (int k = 1; k <= n; k++)for (int j = 1; j <= n; j++)for (int i = 1; i <= n; i++)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		if (d[s][g] >= INF*INF)cout << -1 << endl;
		else cout << d[s][g] << endl;
		
	}

}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s;
  cin >> s;
  int a=0;
  int b=0;
  rep(i,0,200000){
    if(s[i]=='A') {
      a = i;
      break;
    }
  }
  repr(i,s.size(),-1){
    if(s[i]=='Z') {
      b = i;
      break;
    }
  }
  cout << b-a+1 << endl;
}

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

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

  long long x;
  cin >> x;

  if(x % 11 <= 6 && x % 11 != 0) {
    cout << (x+(11-1))/11*2 - 1 << endl;
  }
  else {
    cout << (x+(11-1))/11*2  << endl;
  }

    return 0;
}


Measured memory_bytes: 3636
s, k = input().split()
from random import randint
# k = 200
# s = "".join([str(randint(0,1)) for i in range(k)])
# print(s,k)

mod = 998244353
k = min(302, int(k))
n = len(s)
z = s.count("0")
S = [0] * (z+1)
ind = 0
for i in range(n):
    if s[i] == "0":
        ind += 1
    else:
        S[ind] += 1
# print(S)

D = [[0] * (k+1) for i in range(k+1)]
D[0][0] = 1
for ii in range(z+1):
    
    D0 = [[0] * (k+1) for i in range(k+1)]
    for j in range(k):
        if j+1 < k+1:
            for l in range(k+1):
                D0[j+1][l] = (D0[j+1][l] + D[j][l]) % mod
        if S[len(S)-1-ii] + j + 1 < k+1:
            # print("ind",S[len(S)-1-ii] + j + 1)
            for l in range(k+1):
                D0[S[len(S)-1-ii] + j + 1][l] = (D0[S[len(S)-1-ii] + j + 1][l] - D[j][l]) % mod

    for j in range(1, k+1):
        for l in range(k+1):
            D0[j][l] = (D0[j][l] + D0[j-1][l]) % mod

    D1 = [D[i][:] for i in range(k+1)]
    # D1[0][0] = 0
    for i in range(1, k+1):
        r = i-1
        c = 1
        while 0 <= r < k+1 and 0 <= c < k+1:
            # print("r c",r,c)
            D1[r][c] = (D1[r][c] + D1[r+1][c-1]) % mod
            r -= 1
            c += 1
    for i in range(1, k):
        r = k-1
        c = i+1
        while 0 <= r < k+1 and 0 <= c < k+1:
            D1[r][c] = (D1[r][c] + D1[r+1][c-1]) % mod
            r -= 1
            c += 1

    # for i in range(k):
    #     D1[i][0] = 0
    # for i in range(k):
    #     D1[k][i] = 0

    # print(D,D0,D1)
    for i in range(k+1):
        for j in range(k+1):
            D[i][j] = (D0[i][j] + D1[i][j]) % mod

# print(sum(D[i][i] for i in range(k+1)))
print(sum(D[0]) % mod)
# print(D)




Measured memory_bytes: 125168
def read_input():
    n, m = map(int, input().split())

    edges = []
    for i in range(m):
        edges.append(list(map(int, input().split())))

    return n, m, edges

def submit():
    n, m, edges = read_input()

    edges_dic = {}
    for i in  range(n):
        edges_dic[i + 1] = []

    for e in edges:
        (s, t) = e
        edges_dic[s].append(t)
        edges_dic[t].append(s)

    for i in range(n):
        print(len(edges_dic[i + 1]))

if __name__ == '__main__':
    submit()

Measured memory_bytes: 38256
n, k = map(int, input().split())
mod = 10**9 + 7
# For each X, in 1<= X <= K, let us find the number of sequences {A1, A2, .., An} with GCD = X. 

# The necessary and sufficient condition of the greatest common divisor being a multiple of X
# is that all the A1, ..., AN are multiples of X. The number of such sequences is (floor(K/X))^N.
# The necessary and sufficient condition of it being **exactly** X is that it is a multiple of X, but
# not 2X, 3X.... If they are calculated in the decreasing order of X, it can be found by subtracting
# the number of those of 2X, 3X

# Let dp[i] store the number of sequences whose GCD is i.
dp = [0]*(k+1)
for i in range(k, 0, -1):
    # no. of sequences whose gcd is a multiple of i.
    dp[i] = pow(k//i, n, mod)

    # no. of sequences whose gcd is exactly i. 
    for j in range(2*i, k+1, i):
        dp[i] -= dp[j]

ans = 0
for i in range(1, k+1):
    ans += (i*dp[i])%mod
print(ans%mod)

Measured memory_bytes: 69056
# AOJ 0069: Drawing Lots II
# Python3 2018.6.28 bal4u

while True:
	n = int(input())
	if n == 0: break
	m, p, d = [int(input()) for i in range(3)]
	m -= 1
	p -= 1
	a = [[] for i in range(d+1)]
	for i in range(d): a[i] = list(map(int, input()))
	s = [[0 for j in range(n)] for i in range(d+1)]
	s[d] = [i for i in range(n)]
	for i in range(d-1, -1, -1):
		for j in range(n): s[i][j] = s[i+1][j]
		for j in range(n-1):
			if a[i][j]: s[i][j], s[i][j+1] = s[i][j+1], s[i][j]
	k = s[0][m]
	if k == p:
		print(0)
		continue
	f = False
	for i in range(d):
		for j in range(n-1):
			if ((s[i][j] == k and s[i][j+1] == p) or (s[i][j] == p and s[i][j+1] == k)) \
				and (j == 0 or a[i][j-1] == 0) and a[i][j] == 0 and (j == n-2 or a[i][j+1] == 0):
				print(i+1, j+1)
				f = True
				break
		if f: break
	if not f: print(1)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();

template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<int>(0,N,"");

template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);
// outarr<ll>(0,V.size(),V);

// #define NMAX 1000000000
ll H,W;

auto solve(){
	ll ans = 0;
	if(H<W) swap(H,W);
	ans = H*(W/2);
	if(W%2){//odd
		if(W==1){
			ans += 1;
		}
		else{
			ans += (H+2-1)/2;
		}
	}
	return ans;
}

int main(){
	cin>>H>>W;
	cout<< solve() <<endl;
	// printf("%f\n",solve());
}


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

using namespace std;

char str[100010];

int main()  {
    int r=0,p=0;
    cin >> str;
    int n = strlen(str);
    for ( int c=0 ; c<n ; c++ )
    {
        if ( str[c] == 'g') r++;
        else    p++;
    }
    int canp = n/2;
    cout << canp-p;
}


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

using namespace std;

int main () {
    int a[5], last, sum = 0, flag = 0;
    for (int i=0; i<5; i++) {
        cin >> a[i];
    }
    last = a[0];
    for (int i=0; i<5; i++) {
        if (last%10 == 0) {
            last = a[i];
        }
        if (a[i]%10 < last%10 && a[i]%10 != 0) {
            last = a[i];
        }
    }
    for (int i=0; i<5; i++) {
        if (a[i] == last && flag == 0) {
            flag = 1;
            sum += a[i];
        } else if (a[i]%10 == 0) {
            sum += a[i];
        } else{
            sum += (a[i]/10 +1)*10;
        }
    }
    cout << sum << endl;

    return 0;
}

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

int	main()
{
	int	N, K;
	cin >> N >> K;
	vector<int>	cnt_vec(N, 0);
	unordered_set<int>	appeared;
	int	A;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		--A;
		appeared.insert(A);
		++cnt_vec.at(A);
	}
	int	num_change_num = appeared.size() - K;
	sort(cnt_vec.begin(), cnt_vec.end());
	int	cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (num_change_num <= 0)
			break;
		if (cnt_vec.at(i) == 0)
			continue;
		cnt += cnt_vec.at(i);
		--num_change_num;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
struct dat{
  int T,t,f,lap;
  dat(){T=t=f=lap=0;}
  vector<dat> V;
  bool operator < (const dat &a)const{return T<a.T;}
  bool operator > (const dat &a)const{return T>a.T;}
};

double Pos(const dat &a){return 1.0*a.t/a.T;}
bool onFront(const dat &a,const dat &b){return a.f==b.f&&Pos(a) < Pos(b);}
bool checkJam(const dat &a,const dat &b){return onFront(a,b)&&a.T-a.t<b.T-b.t;}


bool merge(vector<dat>&A,int idx){
  int in = -1,mx=-1;
  for(int i=0;i<(int)A.size();i++){
    dat &a = A[idx],&b = A[i];
    if(checkJam(a,b)&&b.T-b.t>mx)in=i,mx = b.T-b.t;
  }
  if(in!=-1){  
    dat &a=A[idx],&b=A[in];
    a.t=0,a.lap-=a.f,a.f=!a.f;
    b.V.push_back(a);
    A.erase(A.begin()+idx);
    return 1;
  }
  
  return 0;
}

void Push(vector<dat>&A,dat &a){
  for(int i=0;i<(int)a.V.size();i++)Push(A,a.V[i]);
  a.V.clear();
  if(a.lap) A.push_back(a);
}

void pr(dat &a){cout<<a.T<<" "<<a.t<<" "<<a.f<<" "<<a.lap<<" "<<a.V.size()<<endl;}

int sim(vector<dat> A){
  int res=0;
  while(!A.empty()){
    sort(A.begin(),A.end(),greater<dat>());
    
    // for(int i=0;i<A.size();i++)pr(A[i]);
    int mn = 1e9;
    for(int i=A.size()-1;i>=0;i--)
      if(!merge(A,i))mn=min(mn,A[i].T-A[i].t);
    
    //    cout<<"res="<<res<<endl,cout<<"mn="<<mn<<endl;for(int i=0;i<A.size();i++)pr(A[i]);cout<<"-------------"<<endl;
    vector<dat>nA;
    for(int i=0;i<(int)A.size();i++)
      if(A[i].t+mn<A[i].T) A[i].t+=mn,nA.push_back(A[i]);
      else A[i].t=0, A[i].lap-=A[i].f, A[i].f=!A[i].f,Push(nA,A[i]);

    A=nA;
    res+=mn;
  }
  return res;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<dat> A(n);
    for(int i=0;i<n;i++)cin>>A[i].T>>A[i].lap;
    cout<<sim(A)<<endl;
  }
  return 0;
}

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

int main () {
int N,M,sum = 0;
cin >> N >> M;
if (N == 1) {
sum += 0;
}
else {
sum += N*(N - 1) / 2;
}
  if (M == 1) {
sum += 0;
}
else {
sum += M*(M - 1) / 2;
}
  cout << sum << endl;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

points = [k - q]*n
for i in range(q):
    points[a[i]-1] += 1
for i in range(n):
    if points[i] <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 10472
#include<bits/stdc++.h>
#define int long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;
int table[200005]={0};
int n;
void update(int i,int delta)
{
	while(i<=n)
	{
       table[i]+=delta;
       i+=(i&-i);
	}	
}
int pref_sum(int i)
{
	int sum=0;
	while(i>0)
	{
		sum+=table[i];
		i-=i&-i;
	}
	return sum;	
}
int sum(int l,int r)
{
	if(l>r) return 0;
	return pref_sum(r)-pref_sum(l-1);
}
int32_t main()
{
     cin>>n;
     int min1=INF;
     int cnt=0;
     rep(i,0,n)
     {
         int x;
         cin>>x;
           if(x<min1)
           {
           	 cnt++;
           }
           min1=min(min1,x); 
     }
     cout<<cnt<<endl;
     return 0;     
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    if n <= 1000000000:
        print(0,0,1,0,0,n)
    else:
        b = int(n**0.5)
        if b**2 == n:
            print(0,0,b,0,0,n//b)
            return
        b += 1
        x = b
        n = b*x-n
        for a in range(int(n**0.5)+1)[::-1]:
            if n%a == 0:
                print(0,0,x,n//a,a,b)
                return

    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
int main(){
   
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    string str;
    cin >> str;
    map<char,set<int> >st;
    for(int i=0;i<n;i++){
        st[str[i]].insert(i);
    }
    int q;
    cin >> q;
    while(q--){
        int type;
        cin >> type;
        if(type==1){
            int pos;
            char c;
            cin >> pos >> c;
            pos--;
            char var = str[pos];
            st[var].erase(pos);
            st[c].insert(pos);
            str[pos] = c;
        }
        else{
            int l,r;
            cin >> l >> r;
            l--,r--;
            int ans = 0;
            for(char ch='a';ch<='z';ch++){
                if(st[ch].size()==0)
                  continue;
                auto it = st[ch].lower_bound(l);
                if(it==st[ch].end())
                  continue;
                if(*it<=r){
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 24220
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let (ab, bc, _ca) = get!(u64, u64, u64);
    println!("{}", ab*bc/2);
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long
// 0-indexedに注意
template<typename T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost) {}
};

template<typename T>
class Prim{
    private:
        vector<vector<Edge<T>>> graph;
        vector<bool> used;
    public:
        Prim(int n);
        void AddEdge(int from, int to, T cost);
        T Run();
};

template<typename T>
Prim<T>::Prim(int n): graph(n), used(n, false) {}

template<typename T>
void Prim<T>::AddEdge(int from, int to, T cost){
    graph[from].push_back(Edge<T>(to, cost));
}

template<typename T>
T Prim<T>::Run(){
    using Pi = pair<T, int>;
    T total = 0;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    que.emplace(0, 0);
    while(!que.empty()){
        Pi p = que.top();
        que.pop();
        if(used[p.second]) continue;
        used[p.second] = true;
        total += p.first;
        for(auto &e : graph[p.second]){
            que.emplace(e.cost, e.to);
        }
    }
    return total;
}
/*************** using variables ***************/

/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    Prim<int> prim(n);
    REP(i, n){
        REP(j, n){
            int x;
            cin >> x;
            if(x != -1) prim.AddEdge(i, j, x);
        }
    }

    cout << prim.Run() << endl;
}



Measured memory_bytes: 3252
def atoi(a):
    return ord(a) + (1 << 31)


S = input()
T = input()
ns = len(S)
nt = len(T)

if ns < nt:
    exit()

mod = (1 << 61) - 1
b = 10 ** 9 + 7
bn = pow(b, nt, mod)

hs = 0
ht = 0

for s, t in zip(S, T):
    hs = (hs * b + atoi(s)) % mod
    ht = (ht * b + atoi(t)) % mod

for i in range(ns - nt + 1):
    if hs == ht:
        print(i)
    if ns - nt <= i:
        break
    hs = (hs * b + atoi(S[i + nt]) - bn * atoi(S[i])) % mod


Measured memory_bytes: 7516
#include <iostream>
#include <string>
using namespace std;
class DICE{
private:
  int foo;
  int temp;
public:
  int dice[6];
  void rollN(){roll(1,5,4);}
  void rollS(){roll(4,5,1);}
  void rollW(){roll(2,5,3);}
  void rollE(){roll(3,5,2);}
  void roll(int a,int b,int c){
    temp=dice[0]; dice[0]=dice[a];
    dice[a]=dice[b]; dice[b]=dice[c];
    dice[c]=temp;
  }
  void fi(char ch){
    if(ch=='N'){rollN();}
    if(ch=='S'){rollS();}
    if(ch=='W'){rollW();}
    if(ch=='E'){rollE();}
  }
};
int main(){
  int i;
  DICE c;
for(i=0;i<6;i++){
  cin>>c.dice[i];
}
string com;
cin>>com;
for(i=0;i<com.length();i++){
  c.fi(com[i]);
}
cout<<c.dice[0]<<endl;
  return 0;
}
/*N 1->2 2->6 6->5 5->1
  S 1->5 5->6 6->2 2->1
  W 1->3 3->6 6->4 4->1
  E 1->4 4->6 6->3 3->1
*/

Measured memory_bytes: 3160
//42-47
#include<iostream>

using namespace std;

int main(){
  bool cmp[10001]={true,true};
  for(int i=2;i<=10000;i++){
    if(!cmp[i]){
      for(int j=2;i*j<=10000;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int n;cin>>n,n;){
    int nt=n;
    int ans=1;
    for(int i=0;i<=10001;i++){
      if(!cmp[i]){
	int f=1;
	int s=1;
	while(nt%i==0){
	  nt/=i;
	  f*=i;
	  s+=f;
	}
	ans*=s;
      }
    }
    if(nt!=1){
      ans*=(1+nt);
    }
    ans-=n;
    if(n>ans){
      cout<<"deficient number"<<endl;
    }else if(n<ans){
      cout<<"abundant number"<<endl;
    }else{
      cout<<"perfect number"<<endl;
    }
  }
  return 0;
}

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

struct UnionFind{
    vi d;
    UnionFind(int n=0):d(n,-1) {}
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};

int deg[100005];
vi to[100005];

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        --a; --b;
        deg[a]++; deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int c, d;
        cin >> c >> d;
        --c; --d;
        to[c].push_back(d);
        to[d].push_back(c);
    }
    rep(i,n){
        int ans = uf.size(i)-1-deg[i];
        for (int t : to[i]){
            if (uf.same(i,t)) --ans;
        }
        printf("%d%c", ans, i==n-1 ? '\n':' ');
    }
}

Measured memory_bytes: 9244
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	int d, w;
	while (cin >> d >> w, d) {
		int out = 0;
		int pond[10][10];
		rep(i, d) {
			rep(j, w) {
				cin >> pond[i][j];
			}
		}
		rep(i, d) {
			rep(j, w) {
				Rep(k, i + 2, d) {
					Rep(l, j + 2, w) {
						int mi = 100;
						int sum = 0;
						int ma = 0;
						Rep1(x, i, k) {
							Rep1(y, j, l) {
								if (x == i || x == k || y == j || y == l)mi = min(mi, pond[x][y]);
								else {
									sum += pond[x][y];
									ma = max(ma, pond[x][y]);
								}
							}
						}
						if (ma >= mi)continue;
						out = max(out, mi*(k - i - 1)*(l - j - 1) - sum);
					}
				}
			}
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector< pair<int,int> > a;
	for(int i=0;i<n;i++)
	{
		int p,q;
		cin>>p>>q;
		a.push_back(make_pair(q,p));
	}
	sort(a.begin(),a.end());
	int e=0;
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=a[i].second;
		if(sum<=a[i].first)
		{
			
		}
		else
		{
			e++;
			break;
		}
	}
	if(e)
	{
		cout<<"No"<<endl;
	}
	else
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	int N;
	int min = 0;
	int max = 0;
	int temp;
	vector<int> a;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> temp;
		a.push_back(temp);
		if (i == 0)
		{
			min = a[i];
			max = a[i];
		}
		min = (min <= a[i]) ? min : a[i];
		max = (max >= a[i]) ? max : a[i];
	}

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

	int maxCount = 0;
	int beforeIndex = 0;
	bool first;
	for (int X = min; X <= max; X++)
	{
		int count = 0;
		first = true;
		
		for (int i = beforeIndex; i < N; i++)
		{
			if (abs(X - a[i]) <= 1)
			{
				if (first)
				{
					beforeIndex = i;
					first = false;;
				}
				count++;
			}
			else if(a[i] - X >= 2)
			{
				break;
			}
		}

		maxCount = (maxCount >= count) ? maxCount : count;
	}
	
	std::cout << maxCount;
}

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


// Lazy Segment Tree (for RAQ)

template <typename T>
struct RAQ{
    int n = 1;
    vector<T> raq,lazy;     // 0 indexed

    RAQ(vector<T> v){
        int sz = v.size();
        while(n<sz) n*=2;
        raq.resize(2*n+10); lazy.resize(2*n+10);

        for(int i=0;i<sz;i++) raq[i+n-1] = v[i];
        for(int i=n-2;i>=0;i--) raq[i] = raq[i*2+1] + raq[i*2+2];
    }

    void add(int a, int b, T x, int i, int l, int r){
        if(a<=l && r<=b){
            lazy[i] += x;
        }else if(l<b && a<r){
            raq[i] += (min(b,r) - max(a,l)) * x;
            add(a,b,x,i*2+1,l,(l+r)/2);
            add(a,b,x,i*2+2,(l+r)/2,r);
        }
    }

    T getSum(int a, int b, int i, int l, int r){
        if(b<=l || r<=a) return 0;
        else if(a<=l && r<=b) return (r-l)*lazy[i] + raq[i];
        else{
            T res = (min(b,r) - max(a,l)) * lazy[i];
            res += getSum(a,b,i*2+1,l,(l+r)/2);
            res += getSum(a,b,i*2+2,(l+r)/2,r);
            return res;
        }
    }
};


int main(){
    int n,q; cin >> n >> q;
    vector<int> v(n);

    RAQ<int> raq(v);
    rep(i,q){
        int x; cin >> x;
        if(x){
            int j; cin >> j;
            j--;
            cout << raq.getSum(j,j+1,0,0,n) << endl;
        }else{
            int a,b,x; cin >> a >> b >> x;
            a--;b--;
            raq.add(a,b+1,x,0,0,n);
        }
    }
}


Measured memory_bytes: 5756
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        char c[]=sc.getCharSet();
        long r=0,g=0,b=0,ans=0;
        for (int i = 0; i < c.length; i++) {
			if(c[i]=='R')r++;
			else if(c[i]=='G')g++;
			else b++;
		}
        ans=r*g*b;
        for (int i = 1; i < c.length; i++) {
			for (int j = i; j+i < c.length; j++) {
				if(c[j-i]!=c[j] && c[j]!=c[i+j] && c[j-i]!=c[i+j])ans--;
			}
		}
    
        out.println(ans);
     	out.flush();
    }

    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


//class P implements Comparable<P>{
//    int i,x,r,f;
//    P(int i,int x,int r,int f) {
//    	this.i=i;
//    	this.x=x;
//    	this.r=r;
//    	this.f=f;
//    }
//
//    public int compareTo(P p){
//    	if(-this.r+p.r==0) {
//    		return -this.x+p.x;
//    	}
//        return -this.r+p.r;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 33004
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		//*
		m.input();
		m.solve();
		m.output();
		/*/
		m.debug();
		//*/
	}
	
	public void debug() {
	}
	
	/*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String S = null;
	/*/
	InputUtil in = new InputUtil();
	//*/
	PrintWriter out = new PrintWriter(System.out);
	int X = 0;
	int Y = 0;
	long ans = 0L;
	
	public void input() throws IOException {
		X = in.nextInt();
		Y = in.nextInt();
	}
	
	public void solve() throws IOException {
		if (X%Y == 0) {
			ans = -1;
		} else {
			ans = X;
		}
	}
	
	public void output() {
		out.println(ans);
		out.flush();
	}
}

//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }
 
	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}
 
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/


Measured memory_bytes: 25172
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}


clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int N = 100100;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	startTime = clock();
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)<<nl;
	return 0;
}



Measured memory_bytes: 3608
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toLong()
        val B = sc.next().toLong()
        if ((A + B) % 2 == 0L) {
            pw.println((A + B) / 2)
        } else {
            pw.println("IMPOSSIBLE")
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int A=0,B=0,C=0,cnt=0;
  for(int i = 0; i < N-2; i++){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') cnt++;
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii a(n);
    deque<int> b;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (i%2 == n%2) b.pb(a);
        else b.push_front(a);
    }
    rep(i, 0, n) {
        cout << b[i] << (i != b.size()-1 ? " " : "\n");
    }
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout<<min(string(b,'0'+a),string(a,'0'+b))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  // 1は1箇所しか出てこない
  int a1 = -1;
  rep(i, n) {
    if(a[i] == 1) {
      a1 = i;
    }
  }

  // 1回の操作でk-1個が置き換わる
  int min_n = min(a1, n-a1-1);
  int max_n = max(a1, n-a1-1);

  int min_cnt = min_n / (k-1);
  int remainder = min_n % (k-1);
  int max_cnt = ceil((max_n + remainder) / (double)(k-1));

  cout << min_cnt + max_cnt << endl;

  return 0;
}

Measured memory_bytes: 640