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

int main(){
  long long N,K;
  cin >> N >> K;
  vector<long long> P(N);
  for(int i=0;i<N;i++){
    long long p;
    cin >> p;
    P[i] = p+1;
  }
  
  long long ans=0,now=0;
  for(int i=0;i<K;i++) now += P[i];
  ans = now;
  for(int i=K;i<N;i++){
    now -= P[i-K];
    now += P[i];
    ans = max(ans,now);
  }
  
  if(ans%2==0) cout << ans/2 << endl;
  else cout << ans/2 << ".5" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int,int>a, pair<int,int>b) {
	if (a.first == b.first) {
		return a.second > b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	swap(X, Y);
	swap(X, Z);
	cout << X << ' ' << Y << ' ' << Z << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
INF = float('inf')
n,m = map(int, sys.stdin.readline().rstrip("\n").split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int, sys.stdin.readline().rstrip("\n").split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
for _ in range(n):
    edge[_] = list(set(edge[_]))
done = [False]*n
d = deque()
gmax = -INF
for i in range(n):
    if not done[i]:
        done[i] = True
        d.append(i)
        g = 1
        while d:
            cp = d.pop()
            for np in edge[cp]:
                if not done[np]:
                    done[np] = True
                    d.append(np)
                    g += 1
        gmax = max(gmax,g)
print(gmax)

Measured memory_bytes: 122188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  int h,w,m;
  cin>>h>>w>>m;

  vector<set<int>> bs(h,set<int>());
  vector<int> counti(h,0);
  vector<int> countj(w,0);
  rep(i,m){
    int ui,uj;
    cin>>ui>>uj;
    ui--;uj--;
    counti[ui]++;
    countj[uj]++;
    bs[ui].insert(uj);
  }

  int maxi=0; vector<int> besti;
  rep(i,h) chmax(maxi,counti[i]);
  rep(i,h) if(maxi==counti[i]) besti.push_back(i);
  int maxj=0; vector<int> bestj;
  rep(j,w) chmax(maxj,countj[j]);
  rep(j,w) if(maxj==countj[j]) bestj.push_back(j);

  for(int i:besti) for(int j:bestj) {
    if(bs[i].count(j)==0) return maxi+maxj;
  }

  return maxi+maxj-1;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 37852
import sys
sys.setrecursionlimit(20000)

def add_node_2_tree_dic(tree_dic, x, y):
    if x not in tree_dic:
        tree_dic[x] = [y]
    else:
        tree_dic[x].append(y)

#   深さ優先探索で行けそう

N = int(input())
tree_dic = {}
for _ in range(N-1):
    a, b = map(int, input().split())
    add_node_2_tree_dic(tree_dic, a, b)
    add_node_2_tree_dic(tree_dic, b, a)

c_lst = list(map(int, input().split()))
c_lst.sort()
ans_lst = [0]*N

def search_next_node_and_add_side_wate(tree_dic, ans, current_node, c_lst, ans_lst):
    next_node_lst = tree_dic[current_node][:]

    for next_node in next_node_lst:
        c = c_lst.pop()
        ans += c
        ans_lst[next_node - 1] = c

        tree_dic[current_node].remove(next_node)    #   今回通った枝を取り払う
        tree_dic[next_node].remove(current_node)

        if len(tree_dic[current_node]) == 0:
            del tree_dic[current_node]#   探索し終えたノードの削除
        if len(tree_dic[next_node]) == 0:
            del tree_dic[next_node]#   探索し終えたノードの削除
        else:   #   次のノードにつながっている辺があるとき
            ans = search_next_node_and_add_side_wate(tree_dic, ans, next_node, c_lst, ans_lst)

    return ans


ans = 0
current_node = 1
ans_lst[0] = c_lst.pop()
ans = search_next_node_and_add_side_wate(tree_dic, ans, current_node, c_lst, ans_lst)


ans_str = ""
for i in range(N):
    ans_str += str(ans_lst[i])
    if i != N - 1:
        ans_str += " "


print(ans)
print(ans_str)


Measured memory_bytes: 14636
use io::*;
use proconio::{fastout, input};
use std::*;

#[fastout]
fn main() {
    input! {
        x : i64
    }
    let mut res = (2000 - x - 1) / 200 + 1;
    if (res > 8) {
        res = 8;
    }
    println!("{}", res);
}


Measured memory_bytes: 2200
n = int(input())
a = list(map(int, input().split()))

flag = 0
for aa in a:
    if aa % 2 == 0 and aa % 3 != 0 and aa % 5 != 0:
        flag = 1
        break

if flag == 0:
    print('APPROVED ')
else:
    print('DENIED')

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n;
    const int N=100000;
    cin >> n;
    vector<int> a(n),b(N);
    int m=0;
    rep(i,0,n) {
        cin >> a[i];
        b[a[i]]++;
    }
    rep(i,1,N-1) {
        m=max(b[i-1]+b[i]+b[i+1],m);
    }
    cout << m << endl;
}

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

using namespace std;
typedef long long ll;

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

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

    cout << (n - 1) * (m - 1) << "\n";

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

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

    bool flg = false;

    for (int i = 1; i <= 9; i++)
    {
        if (n % i == 0)
        {
            if ((n / i) >= 1 && (n / i) <= 9)
            {
                flg = true;
                break;
            }
        }
    }

    if (!flg)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

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

    // vector<ll> a;
    // for (int i = 0; i < n; i++)
    // {
    //     int j;
    //     cin >> j;
    //     a.push_back(j);
    // }

    //sort(a,a+n); ソート
}


Measured memory_bytes: 256
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int x=scan.nextInt();
            if(x>=30){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


Measured memory_bytes: 32428
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036ll;
const int nax = 55;
int n,k,ans = 0;
int v[nax];
int check(vector<int> s,int left)
 {
  //cerr<<left<<" ";
  int sum = 0;
  sort(s.begin(), s.end());
  for(auto x: s){
    //cerr<<x<<" ";
    if(x<0 && left>0)
       left--;
    else
       sum += x;
  }
 //cerr<<sum<<END;
 return sum;
 }
void solve()
 {
  cin>>n>>k;
  loop(i,1,n+1)
   cin>>v[i];
  vector<int> s;
  for(int i=0; i<=min(n,k); i++)
     {
      if(i!=0)
       s.pb(v[i]);
      int left = k-i;
      vector<int> now = s;
      int temp = left;
      for(int j=n+1; j>=i+1; j--)
         {
          if(j!=n+1){
            now.pb(v[j]);
            temp--;
          }
          if(temp>=0)
            ans = max(ans,check(now,temp));
          else
             break;
         }
     }
  cout<<ans;
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 

     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int p = floor(log2(N));
  int result = pow(2, p);
  cout << result << endl;
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a[5], k;
	for (int i = 0; i < 5; i++)
		cin >> a[i];
	cin >> k;
	if (a[4] - a[0] > k){
		cout << ":(";
	}
	else
		cout << "Yay!";
}

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

using ll = long long;
using pii = pair<int, int>;
constexpr int M = 1e9 + 7;
constexpr int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int res = 1;
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
        if(a[i] % 2 == 0) {
            res *= 2;
        }
    }
    res = pow(3, N) - res;
    cout << res << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main() {
    ll X,Y,Z;
    cin>>X>>Y>>Z>>K;
    vec a(X),b(Y),c(Z);
    rep(i,X) cin>>a[i];
    rep(i,Y) cin>>b[i];
    rep(i,Z) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());
    vec ans(0);
    rep(i,X){
        if(i+1>K) break;
        rep(j,Y){
            if((i+1)*(j+1)>K) break;
            rep(k,Z){
                if((i+1)*(j+1)*(k+1)>K) break;
               ans.push_back(a[i]+b[j]+c[k]);
            }
        }
    }
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    rep(i,K){
        cout<<ans.at(i)<<endl;
    }
}

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

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

const int INF = 1000000007;

int n, m;
bool flag[50];
int G[50][50];
int cnt;

int main(void){
 cin>>n>>m;

	int a[50] ={0}, b[50]={0};
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
		G[a[i]][b[i]] = 1;
		G[b[i]][a[i]] = 1;
	}

	int ans=0;
	vector<int> v(n-1);
	iota(v.begin(), v.end(), 1);
	do {
		bool can = G[0][v[0]];
		for(int i=0;i<n-2;i++) {
			can &= G[v[i]][v[i + 1]]; // can = (can) && G[v[i]][v[i + 1]];
		}
		if(can) ans++;

	} while( next_permutation(v.begin(), v.end()));

	cout<< ans <<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = 1;
        while(true){
            int input = sc.nextInt();
            if(input == 0){
                break;
            }
            System.out.println("Case "+i+": "+input);
            i++;
        }

	}
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n)cin>>a[i];
    ll ans=0;
    rep(i,0,n){
        if(i+1==a[i]){
            swap(a[i],a[i+1]);
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 640
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;
/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

vector<ii> a ;
int H , n ;
void solve(){
	cin >> H >> n ;
	a.resize(n) ;
	vector<int> dp(H+1,INF) ;dp[0] = 0 ;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i].ff >> a[i].ss ;
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < H ; j++){
			dp[min(j+a[i].ff, H)] = min(dp[min(j+a[i].ff, H)], dp[j] + a[i].ss) ; 
		}
	}
	trace(dp) ;
	cout << dp[H] << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


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

long long int read(long long int a)
{
	cin >> a;
	return a;
}

int main()
{
	long long int N, L, k, i, j;
	long long int aji;
	cin >> N >> L;
	aji = (2*L + N-1) * N / 2;

	if (L > 0) {
		cout << aji - L;
	}
	else if ((L <= 0)&&(abs(L-1)>abs(N))){
		cout << aji - (L + N-1);
	}
	else if ((L <= 0) && (abs(L-1) <= abs(N)))
	{
		cout << aji;
	}

}



Measured memory_bytes: 256
import math
K,A,B = list(map(int, input().strip().split(' ')))
biscuit = 1
if B-A <= 2: # ひたすら叩く
  print(1+K)
  exit()
remain_act = K
while remain_act > 0:
  if biscuit < A: # 交換できない
    if remain_act >= A-biscuit+2: # 交換できるようになるまで叩く
      biscuit += A-1
      remain_act -= A-1
    else: # 最後まで叩く
      biscuit += remain_act
      remain_act = 0
  elif remain_act > 1: #A枚→1円→ビスケットB枚
    t = math.floor(remain_act/2)
    biscuit += (B-A)*t
    remain_act -= 2*t
  elif remain_act == 1:
    biscuit += 1
    break
print(biscuit)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define DB(x){if(DEBUG)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define REP(i,b)for(LL i=(0);i<(b);++i)
#define FOR(i,a,b)for(LL i=(a);i<=(b);++i)
#define FORD(i,a,b)for(LL i=(a);i>=(b);--i)
#define ALL(x) (x).begin(),(x).end()
#define VV vector
template<typename X,typename Y>void MAX(X&a,Y b){a=(a>=b?a:b);}
template<typename X,typename Y>void MIN(X&a,Y b){a=(a<=b?a:b);}
typedef long long LL;typedef long double LD;
int DEBUG=0,MULTI=0,GCJ=0;

struct solver_t;solver_t *solver;
struct solver_t {


  void solve() {
    LL X, Y;
    cin >> X >> Y;
    if (X % Y == 0) {
      cout << -1 << "\n";
    }
    else cout << X << "\n";
  }
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  FOR(i,1,argc-1)for(int j=0;argv[i][j];j++)if(argv[i][j]=='.')freopen(argv[i],"r",stdin);
  FOR(i,1,argc-1)if(argv[i]==string("q"))DEBUG=1<<30;
  FOR(i,1,argc-1)if(argv[i]==string("gen")){(solver=new solver_t())->gen();exit(0);}
  FOR(i,1,argc-1)if(argv[i]==string("brute")){(solver=new solver_t())->brute();exit(0);}
  ios::sync_with_stdio(false),cin.tie(0);
  cout.setf(ios::fixed),cout.precision(10);int t;if(MULTI||GCJ)cin>>t;else t=1;
  FOR(i,1,t){if(DEBUG)cerr<<__LINE__<<" "<<i<<endl;if(GCJ)cout<<"Case #"<<i<<": ";
    solver = new solver_t();
    solver->solve();
  }return 0;
}



Measured memory_bytes: 256
# encoding:utf-8
while True:
    H, W = map(int, input().split(" "))
    if H == W == 0:
        break
    
    for i in range(H):
        if i == 0 or i == (H-1):
            print((W * "#"))
        else:
            print("#" + (W-2) * "." + "#")
    print()

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

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

    vint sum(N+1);
    REP(i,N) sum[i+1]=sum[i]+(s[i]=='E');

    int ans=N;
    REP(i,N){
        int w=i-sum[i];
        int e=sum[N]-sum[i+1];
        ans=min(ans,w+e);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<string.h>
int main(void){
  char A[12]={'\0'},B[12]={'\0'},C[12]={'\0'};
  scanf("%s %s %s",A,B,C);
  if((A[strlen(A)-1] == B[0]) && (B[strlen(B)-1] == C[0])){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void){
 
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
 
  sort((a).begin(), (a).end());
  int count = 0;
  for (int i=0; i<N-1; i++){
    x -= a[i];
    if(x >= 0) count++; 
    else break;
  }
  if(x - a[N-1] ==0) count++;
  
  cout << count << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,ans=0;
    cin>>N>>M;
    vector<int> P(N);
    vector<set<int>> AB(N);
    for(int i=0;i<N;i++) P[i]=i;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        AB[a-1].insert(b-1), AB[b-1].insert(a-1);
    }
    do{
        for(int i=0;i<N-1;i++)
            if(AB[P[i]].count(P[i+1])==false) goto skip;
        ans++;
        skip:;
    }while(next_permutation(P.begin()+1,P.end()));
    cout<<ans<<endl;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a*b << ende;
  return 0;
}


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

int main(){
    long long int a, b, c, k, res = 0, tempa, tempb, tempc;

    cin >> a >> b >> c >> k;

    if(k <= a){
        tempa = k;
        k = 0;
    }
    else{
        tempa = a;
        k -= a;
    }

    res = tempa * 1;

    if(k != 0){
        if(k <= b){
            tempb = k;
            k = 0;
        }
        else{
            tempb = b;
            k -= b;
        }
        res += tempb * 0;
    }

    if(k != 0){
        if(k <= c){
            tempc = k;
            k = 0;
        }
        else{
            tempc = c;
            k -= c;
        }
        res += tempc * (-1);
    }

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,a[maxn];
inline bool cmp(int a,int b){return a>b;}

int main()
{
	cin>>n>>m;
	ll tot=0;
	for(int i=1;i<=n;i++) a[i]=read(),tot+=a[i];
	sort(a+1,a+n+1,cmp);
	double p=(double)tot/(double)4; p/=(double)m;
	for(int i=1;i<=m;i++)
	{
		if((double)a[i]<p)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
n=int(input())
b=list(map(int,input().split()))

ans=[0]*n
ans[0],ans[1]=b[0],b[0]

for i in range(1,n-1):
    if ans[i]>=b[i]:
        ans[i]=b[i]
    ans[i+1]=b[i]
print(sum(ans))
    

Measured memory_bytes: 3060
n = gets.to_i

f = true
h= {}
prev = ''
n.times do |i|
  s = gets.chomp
  f = false if h.has_key?(s)
  f = false if prev != '' && prev != s[0]
  h[s] = true
  prev = s[-1]
end

if f
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int P=1e9+7;
int n;
int A[110],F[110][110][110];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<n<<1;++i) read(A[i]);
  sort(A+1,A+n*2);
  F[n][1][0]=1;
  for(int i=n;i>1;--i) {
    int a=A[i]!=A[i-1],b=A[n*2-i]!=A[n*2-i+1];
    for(int j=0;j<n<<1;++j) {
      for(int k=0;k<n<<1;++k) if(F[i][j][k]) {
        for(int l=1;l<=j+a;++l) (F[i-1][j+a-l+1][k+b+(l>1)]+=F[i][j][k])%=P;
        for(int l=1;l<=k+b;++l) (F[i-1][j+a+1][k+b-l]+=F[i][j][k])%=P;
      }
    }
  }
  int res=0;
  for(int i=0;i<n<<1;++i) {
    for(int j=0;j<n<<1;++j) {
      (res+=F[1][i][j])%=P;
    }
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
ll ans=(n*(n+1)*(n+1))/2-(n*(n+1)*(2*n+1))/6;

rep(i,1,n-1)
{
	ll x,y;
	cin>>x>>y;
	if(x>y)swap(x,y);
	ans-=x*(n-y+1);
}
ol(ans);
return 0;
}



Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;
const int MC = 3010;
#define rep(i,n)for(int i=0;i<n;++i)
#define p pair<int,int>
int main() {
	int A, B, C, D, E, F;
	bool w[31];
	int S[MC];
	int answ, ansS;
	cin >> A >> B >> C >> D >> E >> F;
	fill(S, S + MC, -1);
	S[0] = 0;
	for (int i = 0; i < MC; ++i) {
		if (S[i] < 0) {
			S[i] = S[i - 1];
			continue;
		}
		if (i + C < MC)S[i + C] = i + C;
		if (i + D < MC)S[i + D] = i + D;
	}
	w[0] = 1;
	answ = A;
	for (int i = 0; i < 31; ++i) {
		if (!w[i])continue;
		if (i + A < 31)w[i + A] = 1;
		if (i + B < 31)w[i + B] = 1;
		if (i == 0)continue;
		if (100 * i > F)break;
		int tmp = min(S[E*i], F - 100 * i);
		if (ansS*(100 * i + tmp) < tmp*(100 * answ + ansS)) {
			answ = i;
			ansS = tmp;
		}
	}
	cout << 100 * answ + ansS << ' ' << ansS << endl;
	return 0;
}

Measured memory_bytes: 256
def resolve():
    N,K,Q = map(int,input().split())
    A = [int(input()) for _ in range(Q)]
    import collections
    c = collections.Counter(A)
    for i in range(1,N+1):
        if c[i] + K - Q > 0:
            print("Yes")
        else:
            print("No")    
resolve()

Measured memory_bytes: 60632
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w, n;
int a[10010];

void solve() {
    int b[100][100];
    int y = 0, x = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < a[i]; j++) {
            b[y][x] = i+1;
            if (y%2==0) {
                x++;
                if (x >= w) {
                    x--;
                    y++;
                }
            } else {
                x--;
                if (x < 0) {
                    x++;
                    y++;
                }
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        cout << b[i][0];
        for (int j = 1; j < w; j++) {
            cout << " " << b[i][j];
        }
        cout << endl;
    }
}

void input() {
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    solve();
}



Measured memory_bytes: 384
A, B, C, D = map(int, input().split())

def gcd(a, b):
  if b > a:
    a, b = b, a
  a,b = b, a % b
  if b == 0:
    return a
  else:
    return gcd(a, b)
G = C * D // gcd(C, D)

print (B -B // C - B // D + B // G -(A-1)+ (A-1) // C + (A-1) // D - (A-1) // G)

Measured memory_bytes: 3060
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

ll a, b, c, k;

int main() {	
    
	cin >> a >> b >> c >> k;
	
	if (k % 2 == 0) {
		if (a - b <= INF) cout << a - b;
		else cout << "Unfair";
	}
	else {
		if (b - a <= INF) cout << b - a;	
		else cout << "Unfair";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100, MAX_W = 100000;
int N, W;
int w[MAX_N+1], v[MAX_N+1];
ll dp[MAX_N+1][MAX_W+1];

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

  cin >> N >> W;
  repa(i, 1, N) cin >> w[i] >> v[i];

  for (int i = 1; i <= N; ++i) {
      for (int j = 0; j <= W; ++j) {
          if (w[i] <= j) dp[i][j] = dp[i-1][j-w[i]] + v[i];
          dp[i][j] = max(dp[i][j], dp[i-1][j]);
      }
  }


  cout << dp[N][W] << endl;
  return 0;
}


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

int x[105],y[105],h[105];

signed main() {

   int n;cin>>n;
    for(int i = 0; i < n; i++)
    {
         cin>>x[i]>>y[i]>>h[i];
    }

    int cnt = 0;
    while(h[cnt] == 0) cnt++;

    for(int i = 0; i < 101; i++)
    {
         for(int j = 0; j < 101; j++)
         {
            int nowh = h[cnt] + abs(x[cnt]-i) + abs(y[cnt]-j);
            bool ok = true;
            for(int k = 0; k < n; k++)
            {
                int calch = nowh -abs(x[k]-i) - abs(y[k]-j);
                calch = max(calch,(int)0);
                if(calch != h[k]) ok =false;
            }
            if(ok)
            {
                cout << i << " " << j << " " << nowh << endl;
                return 0;
            }
         }
    }
}


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

int main() {
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	string z = "Yay!";
	if(e - a > k)
	{
		z = ":(";
	}
	cout << z << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  char ret;
  if(s[0]=='A')ret='T';
  else if(s[0]=='T')ret='A';
  else if(s[0]=='C')ret='G';
  else ret = 'C';
  cout<<ret<<endl;
  return 0;
}

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

int main()
{
	long long N, A, B;
	cin >> A >> B >> N;
	if (N >= B) {
		cout << (A * (B - 1)) / B << endl;
	}
	else {
		cout << (A * N) / B << endl;
	}
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int tmp=n;
  if(n==0){
    cout<<n<<endl;
    return 0;
  }
  string s;
  int k=1;
  while(n!=0){
    if(n%(k*2)==0){
      s+='0';
    }else{
      s+='1';
      n-=k;
    }
    k*=-2;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> dp(10010, 0);
    dp[0] = 1;
    rep(i, N) {
        for(int j = 10009; j >= 0; j--) {
            if(j + A[i] < 10010 & dp[j] == 1) dp[j + A[i]] = 1;
        }
    }
    for(int j = 10009; j >= 0; j--) {
        if(j % 10 != 0 && dp[j] == 1) {
            output(j);
            return 0;
        }
    }
    output(0);
    
    return 0;
}


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

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

int N;
string S;
const int mod = 1000000000 + 7;
int freq[26];
int main(){

    cin >> N;
    cin >> S;
    ll ans = 1;
    for(int i = 0; i < N; i++)
        freq[S[i] - 'a']++;
    for(int i = 0; i < 26; i++){
        (ans *= (1 + freq[i])) %= mod;
    }
    (ans += (mod - 1)) %= mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
function main(input) {
  var args = input.trim().split(" ");
  var a = parseInt(args[0], 10);
  var b = parseInt(args[1], 10);
  var c = parseInt(args[2], 10);
  if ( a == b && a != c) {
    return "Yes";
  } else if ( a!= b && a == c) {
    return "Yes";
  } else if ( b!= a && b == c) {
    return "Yes";
  } else {
    return "No";
  }
}
console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7372
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define Swap(a,b) (a+=b,b=a-b,a-=b)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline char GET(void)
{
  static char buf[1<<10],*s1=buf,*s2=buf;
  return s1==s2&&(s2=(s1=buf)+fread(buf,1,1<<10,stdin),s1==s2)?EOF:*s1++;
}
static inline void PUT(char c)
{
  static char buf[1<<10],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=GET();while(c<48||c>57){f^=c==45,c=GET();}
  while(c>47&&c<58){x=x*10+c-48,c=GET();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Max(int x,int y){return x>y?x:y;}
int work[9999][3],sz=0;
static inline void Add(int x,int y,int v){work[sz][0]=x;work[sz][1]=y;work[sz++][2]=v;}
int main(void)
{
  int N=IN(),A[3*N],dp[N][N],B[N],mx,extra=0;
  rep(i,3*N)A[i]=IN()-1;
  memset(B,-0x3f,sizeof(B));memset(dp,-0x3f,sizeof(dp));
  dp[A[0]][A[1]]=dp[A[1]][A[0]]=B[A[0]]=B[A[1]]=mx=0;
  rep(i,N-1)
  {
    int k=3*(i+1);
    if(A[k-1]>A[k])Swap(A[k-1],A[k]);
    if(A[k]>A[k+1])Swap(A[k],A[k+1]);
    if(A[k-1]>A[k])Swap(A[k-1],A[k]);
    int x[3]={A[k-1],A[k],A[k+1]};
    if(x[2]==x[0]){extra++;continue;}
    if(x[0]==x[1])rep(j,N)Add(j,x[2],dp[j][x[0]]+1);
    if(x[1]==x[2])rep(j,N)Add(j,x[0],dp[j][x[1]]+1);
    rep(j,3)Add(x[j==0],x[j==2?1:2],dp[x[j]][x[j]]+1);
    rep(j,3)rep(k,j)Add(x[j],x[k],mx);
    rep(j,N)rep(k,3)Add(j,x[k],B[j]);
    rep(j,sz)
    {
      if(dp[work[j][0]][work[j][1]]<work[j][2])
      {
        dp[work[j][0]][work[j][1]]=dp[work[j][1]][work[j][0]]=work[j][2],
        B[work[j][0]]=Max(B[work[j][0]],work[j][2]),
        B[work[j][1]]=Max(B[work[j][1]],work[j][2]),mx=Max(mx,work[j][2]);
      }
    }
    sz=0;
  }
  return OUT(Max(mx,dp[A[3*N-1]][A[3*N-1]]+1)+extra),0;
}

Measured memory_bytes: 17236
#include<cstdio>
using namespace std;
int main(void){
    int card[2][202] = {{0}};

    int n;scanf("%d",&n);
    for(int i = 0;i < 2*n;i++){
        card[0][i] = i+1;
    }

    int idx = 0;
    int m; scanf("%d",&m);
    for(int i = 0;i < m;i++){
        int k; scanf("%d",&k);
        if(k == 0){
            for(int j = 0;j < 2*n;j++){
                if(j < n) card[1-idx][2*j] = card[idx][j];
                else card[1-idx][2*(j-n)+1] = card[idx][j];
            }
        }
        else{
            for(int j = 0;j < 2*n;j++){
                if(j < k) card[1-idx][2*n-k+j] = card[idx][j];
                else card[1-idx][j-k] =card[idx][j];
            }
        }
        idx = 1-idx;
    }
    for(int i = 0;i < 2*n;i++){
        printf("%d\n",card[idx][i]);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	cin >> a;
	rep(i, n) { a[i] -= (i + 1); }
	sort(all(a));
	ll b = a[n / 2];
	//clog << a << endl;
//	clog << b << endl;
	rep(i, n) { ans += abs(b - a[i]); }
	cout<<ans<<endl;
}

Measured memory_bytes: 4800
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int N;
	int D[100000];
	int R=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>D[i];
	}
	int a1=1,a2=1,a3=1;
	for(int i=1;i<N;i++){
		if(D[i]==D[i-1]){
			R=max(R,a3);
			a3=a2+1;
			a2=a1+1;
			a1=1;
		}
		if(D[i]!=D[i-1]){
			a1+=1;
			a2+=1;
			a3+=1;
		}

	}
	R=max(R,a1);
	R=max(R,a2);
	R=max(R,a3);


	cout<<R<<endl;
	return 0;
}

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

using namespace std;

const int N = 4010;

int cnt[3][N];

int main() {
  int n;
  string str;
  cin >> n >> str;
  for (int i = n - 1; i >= 0; i--) {
    for (int k = 0; i < n - 1 && k < 3; k++) cnt[k][i] = cnt[k][i + 1];
    if (str[i] == 'R') cnt[0][i]++;
    if (str[i] == 'G') cnt[1][i]++;
    if (str[i] == 'B') cnt[2][i]++;
  }
  //for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) cerr << cnt[i][j] << ' ' ; cerr << endl;}
  long long answer = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (str[i] == str[j]) continue;
      int diff = j - i;
      //cerr << i << ' ' << j << endl;
      if (str[i] == 'R') {
        answer += str[j] == 'G' ? cnt[2][j] : cnt[1][j];  
      }
      if (str[i] == 'G') answer += str[j] == 'R' ? cnt[2][j] : cnt[0][j];
      if (str[i] == 'B') answer += str[j] == 'R' ? cnt[1][j] : cnt[0][j];
      if (j + diff < n && str[j + diff] != str[i] && str[j + diff] != str[j]) answer--;
    }
  }
  cout << answer << '\n';
  return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int V, E;
vector<int> v, g[100101];
vector<bool> visited(100101);
vector<vector<int> > c; //포레스트

void DFS(int n)
{
	c.back().push_back(v[n]);
	visited[n] = true;
	for (int i = 0; i < g[n].size(); i++)
	{
		int next = g[n][i];
		if (visited[next] == false)
			DFS(next);
	}
}

int main()
{
	scanf("%d %d", &V, &E);
	v.resize(V);
	for (int i = 0; i < V; i++)
		scanf("%d", &v[i]);

	for (int i = 0; i < E; i++)
	{
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		g[t1].push_back(t2);
		g[t2].push_back(t1);
	}

	for (int i = 0; i < V; i++)
	{
		if (visited[i] == false)
		{
			c.push_back(vector<int>());
			DFS(i);
			sort(c.back().begin(), c.back().end());
		}
	}

	if (2 * (c.size() - 1) > V)
		return !printf("Impossible");

	if (c.size() == 1)
		return !printf("0");
	
	vector<int> a;
	ll sum = 0;
	for (int i = 0; i < c.size(); i++)
	{
		sum += c[i][0];
		for (int j = 1; j < c[i].size(); j++)
			a.push_back(c[i][j]);
	}
	sort(a.begin(), a.end());
	int sel = c.size() - 2;
	for (int i = 0; i < sel; i++)
		sum += a[i];
	
	printf("%lld", sum);
	return 0;
}

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

int a[2000],b[2000];
int c[2000][2000];
int a1[2000000],b1[2000000];
ll sum[2000000];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n)scanf("%d",&a[i]),a1[a[i]]++;
	rep(i,m)scanf("%d",&b[i]),b1[b[i]]++;
	for(int i=1;i<=n*m;i++){
		if(a1[i]>1||b1[i]>1){
			puts("0");return 0;
		}
	}
	memset(c,0x3f,sizeof(c));
	int ax=-1,ay=-1;
	rep(i,n)rep(j,m){
		c[i][j]=min(a[i],b[j]);
		if(c[i][j]==n*m){
			if(ax!=-1){
				puts("0");return 0;
			}
			ax=i;ay=j;
		}
	}
	if(ax==-1&&ay==-1){
		puts("0");return 0;
	}
	ll ans=1;
	ll c1=1,c2=1;
	for(int i=n*m-1;i>=1;i--){
		ll cnt=n*m-i;
		//~ ll A=n*m-c1*m,B=n*m-c2*n;
		if(a1[i]&&b1[i]){
			(ans*=1)%=MOD;
		}
		if(a1[i]&&!b1[i]){
			(ans*=c2)%=MOD;
		}
		if(!a1[i]&&b1[i]){
			(ans*=c1)%=MOD;
		}
		if(!a1[i]&&!b1[i]){
			(ans*=(c1*c2-cnt))%=MOD;
		}
		if(a1[i])c1++;
		if(b1[i])c2++;
	}
	cout<<ans%MOD<<endl;
}

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

const int maxn = 1e5 + 10;
int n, res, a[maxn];
map<int, int> cnt;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (auto x : cnt) {
        if (x.second >= x.first) {
            res += x.second - x.first;
        } else {
            res += x.second;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5120