akhauriyash/Code-Regression huggingface dataset:
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int N = 1e5 + 7;

int stones[N], cost[N], n, k;

int find_cost(int stone)
{
    if(stone > n)   return 1e9;
    if(stone == n)  return 0;

    int &ans = cost[stone];

    if(ans != -1) return ans;

    ans = 1e10;

    for(int i = 1; i <= k; ++ i)  // and stone + i <= n; ++ i)
    {   
        ans = min(ans, abs(stones[stone] - stones[stone + i]) + find_cost(stone + i));
    }
    
    
    return ans;
}

int32_t main()
{
    IOS;// FIO;

    cin >> n >> k;

    memset(cost, -1, sizeof(cost));

    for(int i = 1; i <= n; ++ i)
        cin  >> stones[i];

    cout << find_cost(1);

    return 0;
}

Measured memory_bytes: 4992
# include <iostream>
# include <cstdio>
# include <queue>
# include <vector>
# include <string>
# include <set>
# include <string>
# include <cmath>
# include <algorithm>
# define LL long long
using namespace std;
LL ans=0;
int main()
{
    int n,i,g;
    LL  f[5]={0};
    char a[15];
 
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",a);
        if(a[0]=='M')
            f[1]+=1;
        if(a[0]=='A')
            f[2]+=1;
        if(a[0]=='R')
            f[3]+=1;
        if(a[0]=='C')
            f[4]+=1;
        if(a[0]=='H')
            f[0]+=1;
    }
    /*for(i=1;i<=5;i++)
    {
        if(f[i]>0)
            g+=1;
        else
            f[i]=1;
    }*/
    //ans=f[1]*f[2]*f[3]+f[1]*f[2]*f[4]+f[1]*f[2]*f[5]+f[2]*f[3]*f[4]+f[2]*f[3]*f[5]+f[1]*f[3]*f[4]+f[1]*f[3]*f[5]+f[1]*f[4]*f[5]+f[2]*f[4]*f[5]+f[3]*f[4]*f[5];
    for ( i = 0; i < 3; i++) {
        for (int j = i + 1; j < 4; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += f[i] * f[j] * f[k];
            }
        }
    }
cout<<ans;
    return 0;
 
}

Measured memory_bytes: 256
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
    return 0;
}

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

int counta[100001],countb[100001];
int maxia,maxib,maxic,maxid;
int kea,keb,kec,ked;

int main() {
	int n;
	cin>>n;
	int a[n+1],b[n+1];
	for(int i=1; i<=n/2; i++) {
		cin>>a[i]>>b[i];
	}
	
	for(int i=1; i<=n/2; i++) {
		counta[a[i]]++;
	}
	for(int i=1; i<=n/2; i++) {
		countb[b[i]]++;
	}
	priority_queue<int> haha,hbhb;
	for(int i=1; i<=100000; i++) {
		if(counta[i]>maxia) {
			maxid=maxia;
			maxia=counta[i];
			kea=i;
		} else if(counta[i]>maxid){
			maxid=counta[i];
		}
		if(countb[i]>maxib) {
			maxic=maxib;
			maxib=countb[i];
			keb=i;
		}else if(countb[i]>maxic) {
			maxic=countb[i];
		}
	//	if(i<=20)cout<<counta[i]<<endl;
		haha.push(counta[i]);
		hbhb.push(countb[i]);
	}
//	cout<<counta[2]<<counta[1]<<endl;
//	cout<<haha.top()<<endl;
//	maxia=haha.top();
//	haha.pop();
//	maxid=haha.top();
//	haha.pop();
//	maxib=hbhb.top();
//	hbhb.pop();
//	maxid=hbhb.top();
//	hbhb.pop();
	int hasil=0;
//	maxia=1;
//	maxib=0;
//	cout<<maxia<<' '<<maxib<<' '<<maxic<<' '<<maxid<<endl;
	if(kea==keb) {
		if(maxia+maxic>maxib+maxid) {
			hasil+=n-maxia-maxic;
		}else {
			hasil+=n-maxib-maxid;
		}
	}else {
		hasil+=(n/2)-maxia;
		hasil+=(n/2)-maxib;
	}
	cout<<hasil<<endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

struct warshall_floyd {
	static void solve(vector<vector<ll>>& d) {
		int n = d.size();
		rep(k, n) {
			rep(i, n) {
				rep(j, n) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
};

int main(void)
{
	int h, w;
	cin >> h >> w;
	vector<vector<ll>> grid(10, vector<ll>(10));
	rep(i, 10) {
		rep(j, 10) {
			ll c;
			cin >> c;
			grid[i][j] = c;
		}
	}
	warshall_floyd::solve(grid);
	ll sum = 0;
	rep(i, h) {
		rep(j, w) {
			ll a;
			cin >> a;
			if (a >= 0) {
				sum += grid[a][1];
			}
		}
	}
	cout << sum << endl;
	return 0;
}


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

#define MAX_N 100

// int X = 3;
// int Y = 20;

long int X, Y;
int main() {
    cin >> X >> Y;
    long int ans = 1;
    long int target = X;
    // long int prev = X;
    // for (long int i = X; i <= Y; i += X) {
    //     // cout << i << endl;
    //     if (i % prev == 0) {
    //         prev = i;
    //         ans++;
    //     }
    // }
    
    while (true) {
        target *= 2;
        if (target <= Y) {
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;
}

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

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

const int N = 1e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);

int main(int argc, char **args){
  //  freopen("in.txt", "r", stdin);
    int sum, n; cin >> sum >> n;
    int t = 0;
    for(int i = 0; i < n; i++)
        {
            int c; cin >>c;
            t += c;
        }
    if(t > sum ) puts("-1");
    else cout << sum - t <<"\n";
return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    vector<int> prime;
    bool isPrime[10001];
    for(int i=0;i<=10000;i++) isPrime[i]=(i>=2);
    for(int j=2;j<=100;j++){
        if(isPrime[j]){
            for(int k=j*2;k<=10000;k+=j) isPrime[k]=false;
        }
    }
    for(int i=0;i<=10000;i++){
        if(isPrime[i]) prime.push_back(i);
    }

    int n, ans=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x<=1) continue;
        for(int p : prime){
            if(x==p) break;
            if(x%p==0){
                ans--;
                break;
            }
        }
        ans++;
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;

long long pointGenerator(int row, int column, int width){
    return (1LL*row*width)+column;
}

vector<int> getMax(vector<int> &men) {
    int maxSize=0;
    vector<int> ret;
    for(int & i : men) maxSize=max(maxSize, i);
    for(int i=0; i<men.size(); i++){
        if(maxSize==men[i]) ret.push_back(i);
    }
    return ret;
}

int main() {

    int h, w, m;
    scanf("%d%d%d", &h, &w, &m);

    vector<int> x(m), y(m);
    unordered_set<long long> coords;
    vector<int> menInRow(h, 0);
    vector<int> menInColumn(w, 0);

    for(int i=0; i<m; i++){
        scanf("%d%d", &x[i], &y[i]);
        x[i]--, y[i]--;
        coords.insert(pointGenerator(x[i], y[i], w));
        menInRow[x[i]]++;
        menInColumn[y[i]]++;
    }

    vector<int> maxRow = getMax(menInRow), maxCol = getMax(menInColumn);

    long long total=menInRow[maxRow[0]]+menInColumn[maxCol[0]];
    for(auto & currentRow : maxRow){
        for(auto & currentCol : maxCol){
            if(coords.find(pointGenerator(currentRow, currentCol, w))==coords.end()){
                printf("%lld\n", total);
                return 0;
            }
        }
    }
    printf("%lld\n", total-1);
    return 0;
}

/*Logic:
 * This problem was giving me TLE because some of the data structures such as
 * map, set used were slow as their insertion and deletion took logarithmic time.
 *
 * Main idea is that, for any row and column chosen, there are 2 possibilities.
 * 1. The bomb placed at a coordinate where there is no one. In that case,
 * summation of people in both row and column is the answer.
 *
 * 2. The bomb placed at a coordinate where there is a person. In, that case,
 * subtract 1 from summation of people in both row and column because we would be
 * counting the the guy on the bomb coordinates twice.
 *
 * So, all we need to do is to find rows where number of people is maxed.
 * Same goes for columns. In this case, row and column are independent to each other.
 *
 * Now, we know that case 1 is the best case. So we  need to find evidence from all
 * possible combinations of rows and columns where the number of people is maximum for each.
 * Once we have the evidence we can say case 1 is the answer. If no evidence is found, then
 * case 2 is the answer.
 */


Measured memory_bytes: 25612
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N,K;
int A[200005],F[200005];
vector<int> ans;
signed main(){
    scanf("%lld %lld",&N,&K);
    rep(i,N)scanf("%lld",&A[i]);
    rep(i,N)scanf("%lld",&F[i]);
    sort(A,A+N,greater<int>());//消化コストが高い順
    sort(F,F+N);//コストが低い順
    //答えを二分探索
    int a=-1;
    int b=A[0]*F[N-1];
    while(a+1<b){//aより大きくb以下
        int c=(a+b)/2;
        int left=K;
        rep(i,N){
            int useK=0;
            if(A[i]*F[i]>c)useK=A[i]-c/F[i];
            left-=useK;
        }
        if(left>=0){//このcまでは短縮できる
            b=c;
        }else{//このcまでは短縮できない
            a=c;
        }
    }
    printf("%lld\n",b);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define revv(V) reverse(allv(V))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int MAXN = 3005;

int MP[MAXN*2][MAXN*2];

int dp[MAXN*2][MAXN][2];

int N, M;

int f(int r, int b, int m, bool flag) {
    if(r < 0 || b < 0) return 0;
    flag |= (!r);
    if(!flag && (((M<<1)-m)>>1) < r) return 0;
	if(m == (M<<1)) return flag;
	int key = (r<<1) + flag;
	if(0 <= MP[m][key]) return MP[m][key];

	int ret = 0;
	if(m&1) {
		ret = f(r+1, b, m+1, flag) + f(r, b+1, m+1, flag);
	} else {
		ret = f(r-1, b, m+1, flag) + f(r, b-1, m+1, flag);
	}
	if(MOD <= ret) ret -= MOD;
	MP[m][key] = ret;
	return ret;
}

int Ans;

int main() {
	for(int i = 0; i < MAXN*2; i++)
		fill(MP[i], MP[i]+MAXN*2, -1);
	cin >> N >> M;

	/*
	for(int i = 0; i <= N; i++) dp[M<<1][i][1] = 1;
	for(int i = 2*M; i; i--) {
        for(int r = 0, b = N+(i&1); r <= N+1 && b; r++, b--) {
			for(int f = 0; f < 2; f++) {
				int ret = dp[i][r][f];
				if(!ret) continue;

				if(i&1) {
					for(int ff = 0; ff < 2; ff++) {
						dp[i-1][r+1][ff] = (dp[i-1][r+1][ff] + ret) % MOD;
						dp[i-1][r][ff] = (dp[i-1][r][ff] + ret) % MOD;
					}
				} else {
					for(int ff = 0; ff < 2; f++) {
						dp[i-1][r-1][ff] = (dp[i-1][r-1][ff] + ret) % MOD;
						dp[i-1][r][ff] = (dp[i-1][r][ff] + ret) % MOD;
					}
				}
        }
		}
		*/
	for(int i = 0; i <= N; i++) {
        Ans = (Ans + f(i, N-i, 0, false)) % MOD;
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 143616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = sc.nextInt();
            }
        }

        int[] a = new int[3];
        int[] b = new int[3];

        for (int i = 0; i <= 100; i++) {
            for (int j = 0; j <= 100; j++) {
                for (int k = 0; k <= 100; k++) {
                    a[0] = i;
                    a[1] = j;
                    a[2] = k;

                    b[0] = c[0][0] - i;
                    b[1] = c[0][1] - i;
                    b[2] = c[0][2] - i;

                    if (check(a, b, c)) {
                        System.out.println("Yes");
                        return;
                    }
                }
            }
        }
        System.out.println("No");
    }

    static boolean check(int a[], int b[], int c[][]) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a[i] + b [j] != c[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 24404
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

const double EPS = 1e-6;
const int BOARD_SIZE = 5000;

typedef complex<double> point;
ostream& operator<<(ostream& os,const point p){
    os << "(";
    os << p.imag() << "," << p.real();
    os << ")";
    return os;
}


inline bool is_ok(const point& p){
    double rr = round(p.real()),ri = round(p.imag());
    bool on_line = abs(p.real()-rr) < EPS and abs(p.imag() - ri) < EPS;
    bool on_board = 0 <= (int)rr and (int)rr <= BOARD_SIZE and 0 <= (int)ri and (int)ri <= BOARD_SIZE;
    return on_line and on_board;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<vector<char> > board(BOARD_SIZE+1,vector<char>(BOARD_SIZE+1,false));

        vector<point> ps(n);
        for(int i=0;i<n;i++){
            int x,y;
            cin >> x >> y;
            board[y][x] = true;
            ps[i].real(y);
            ps[i].imag(x);
        }

        int ret = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                point a = ps[i];
                point b = ps[j];
                for(int k=-1;k<=1;k+=2){
                    point c = a + (b-a) * point(0,1*k);
                    point d = b + (a-b) * point(0,-1*k);

                    int cy = (int)round(c.real());
                    int cx = (int)round(c.imag());
                    int dy = (int)round(d.real());
                    int dx = (int)round(d.imag());
                    if(is_ok(c) and is_ok(d) and board[cy][cx] and board[dy][dx]){
                        ret = max(ret,(int)(round(abs(a-b)*abs(a-b))));
                    }
                }
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 25912
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    lli n;
    cin>>n;
    lli arr[n];
    for(lli i=0;i<n;++i){
        cin>>arr[i];
    }    
    lli prev=arr[0];
    lli sum=0;
    for(lli i=1;i<n;++i){
        if(arr[i]<prev){
            sum+=prev-arr[i];
        }
        else
            prev=arr[i];
    }
    cout<<sum<<endl;    
}

Measured memory_bytes: 5172
import sys
sys.setrecursionlimit(10**6)
from collections import deque
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)
nan=deque([0])
check=[1 if i==0 else -1 for i in range(n)]
def bfs():
    global n,m,path,nan
    l=len(nan)
    if not l:
        return
    for _ in range(l):
        x=nan.popleft()
        for j in path[x]:
            if check[j]==-1:
                check[j]=x
                nan.append(j)
    bfs()
bfs()
if any([i==-1 for i in check]):
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(check[i]+1)

Measured memory_bytes: 111000
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n, h, w;
  cin >> n >> h >> w;
  int res = (n - h + 1) * (n - w + 1);
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 50000
using namespace std;
typedef long long ll;
bool used[N];

ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}

bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=n;i++){
    if(n%i)continue;
    if(i<N)res&=!used[i],used[i]=1;
    if(i!=n/i&&n/i<N)res&=!used[n/i],used[n/i]=1;
  }
  return res;
}

int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
  
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
	ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
	if(!mark(lcm))continue;
	sum-=SumD(lcm,lcm,n/lcm);
	cnt-=(n/lcm);
      }
    }

    printf("%.8f\n",(p[0]!=1)*(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3308
#atcorder beginner contest 141
#D powerful discount tickets
import math
import heapq

goods, tickets = map(int, input().split())

price = []
price = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(price)


for i in range(tickets):
    max = heapq.heappop(price) * (-1)
    heapq.heappush(price, math.ceil(-max/2))
   

total = 0
for i in range(goods):
    total += price[i]

print(total * (-1))

Measured memory_bytes: 14380
#include<iostream>
using namespace std;
int main(){
    int r,c;
    while(cin>>r>>c)
    {
                    if(r == 0 && c == 0) break;
                    if(r % 2 == 0 || c % 2 == 0) cout<<"yes"<<endl;
                    else cout<<"no"<<endl;
                    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<queue>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
using namespace std;

int main(){
  int n,m; cin >>n>>m;
  int a,b;
  vector<pair<int,int>> v;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end());
  int cnt=0;
  int check=-1;
  for(int i=0;i<m;i++){
    if(v[i].second>check){
      cnt++;
      check=v[i].first-1;
    }
  }
  cout <<cnt<<endl;
}

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

int main(int argc, char* argv[]){
  std::ios::sync_with_stdio(false);
  std::string s;
  int w;
  std::cin >> s;
  std::cin >> w;
  for (std::size_t i = 0; i < s.size(); i+= w){
    std::cout << s[i];
  }
  std::cout << std::endl;
  return 0;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxN	100001
#define nl		"\n"
using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin >> k >> n;
	vector<int> v(n);
	for(int&x: v) cin >> x;
	sort(v.begin(), v.end());
	vector<int> g;
	int max = 0;
	ll ans = 0LL;
	for(int i = 1, x;i < n; ++i){
		if((x = v[i] - v[i -1])  > max)
			max = x;
		ans += x;
	}
	int x = k - v[n - 1] + v[0];
	if(x > max) max = x;
	ans += x;
	cout << ans - max << nl;
	return 0;
}


Measured memory_bytes: 1024
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>
#include <set>

//#define int long long
//typedef long long ll;
using ll = long long;
//using R = double;

//#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 1000000007

const int INF = int(1e9);

using namespace std;

typedef vector<int> V;
typedef vector<V> VV;

int n;
int a[100000];
int dp[100010];

signed main()
{
    cin >> n;
    REP(i,n) cin >> a[i];

    fill(dp, dp + n, INT_MAX);
    for (int i=0; i<n; i++) {
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }

    cout << lower_bound(dp, dp + n, INT_MAX) - dp << endl;

    return 0;
}

Measured memory_bytes: 3864
#include<stdio.h>
int d[10][10],s=0,n,h[10];
void f(int a,int m){
  int i;
  h[a]=1;
  for(i=0;i<n;i++){
    if(d[a][i]==0||h[i])continue;
    if(m+1==n)s++;
    else f(i,m+1);
  }
  h[a]=0;
}	     
int main(){
  int i,m,a,b;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    d[a-1][b-1]=d[b-1][a-1]=1;
  }
  f(0,1);
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 128
from collections import defaultdict

N = int(input())
points = [tuple(map(int, input().split()))for _ in range(N)]

if N == 1:
    print(1)
    exit(0)

points.sort(key=lambda p: p[1])
points.sort(key=lambda p: p[0])
d = defaultdict(int)
max_count = 0
max_f = None
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        key = (xj - xi, yj - yi)
        d[key] += 1
        if d[key] > max_count:
            max_count = d[key]
            max_f = key


class UnionFind(object):

    def __init__(self, N):
        self.tree = [i for i in range(N)]
        self.rank = [0] * (N + 1)

    def find(self, x):
        if self.tree[x] == x:
            return x
        else:
            self.tree[x] = self.find(self.tree[x])  # 経路圧縮
            return self.tree[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        # ランクを考慮しない場合はどちらが親になっても良い
        if self.rank[x] < self.rank[y]:
            self.tree[x] = y
        else:
            self.tree[y] = x

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def has_same_parent(self, x, y):
        return self.find(x) == self.find(y)


p, q = max_f
uf = UnionFind(N)
for i in range(N):
    for j in range(i + 1, N):
        xi, yi = points[i]
        xj, yj = points[j]
        if xj - xi == p and yj - yi == q:
            uf.unite(i, j)

print(len(set(uf.tree)))


Measured memory_bytes: 40560
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	string s;
	cin >> s;
	s += 'X';
	int ans = 0;
	int start;
	int status = 0;
	
	REP(i, s.length()) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			i++;
			int count = 1;
			while (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') { 
				i++;
				count++; 
			}
			ans = max(ans, count);
		}
	}



	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    while(1){
        ll x,y;cin>>x>>y;
        if(!x&&!y)return;
        if(x>y)swap(x,y);
        cout<<x<<" "<<y<<endl;
    }
}

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



Measured memory_bytes: 3056
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int N,K;
    cin >> N >> K;
    int ans = 0;
    while(N>0){
        N /= K;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
}

Measured memory_bytes: 26284
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int M = sc.nextInt();

		int[] a = nextIntArray1origin(sc, A);
		int[] b = nextIntArray1origin(sc, B);
		a[0] = Integer.MAX_VALUE;
		b[0] = Integer.MAX_VALUE;
		
		int[] x = new int[M];
		int[] y = new int[M];
		int[] c = new int[M];
		for (int i = 0; i < M; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		sc.close();

		int ans1 = min(a) + min(b);

		int ans2 = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			ans2 = Math.min(ans2, a[x[i]] + b[y[i]] - c[i]);
		}

		out.println(Math.min(ans1, ans2));

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int min(int[] arr) {
		if (arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for (int i = 1; i < arr.length; i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 139084
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b)>(c+d)) cout<<"Left"<<endl;
    else if((a+b)==(c+d)) cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}


Measured memory_bytes: 256
mod=10**9+7

N=int(input())
S=input()

d={}
for s in S:
    if s in d:
        d[s]+=1
    else:
        d[s]=1
ans=1
for D in d:
    ans*=d[D]+1
    ans%=mod
print((ans-1)%mod)

Measured memory_bytes: 9096
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}


int main(){
    char a;
    cin >> a;
    if(a >= 'A' && a <= 'Z') cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  const auto m = n;
  std::string s;
  std::cin >> s;
  for (int64_t i = 1; i < m; i++) {
    if (s[i] == s[i - 1]) {
      n--;
    }
  }
  std::cout << n << std::endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){

  int i,j,n,minj,swap,a[37],b[37],f=0;
  char swapc,c[37],d[37];

  //load N
  scanf("%d",&n);

  //load number
  for(i=1;i<=n;i++){
    scanf(" %c%d",&c[i],&a[i]);
    b[i]=a[i];
    d[i]=c[i];
  }



  //BubbleSort
  for(i=1;i<=n;i++){
    for(j=n;j>=i+1;j--){
      //swap
      if(a[j]<a[j-1]){
        swap=a[j];
        a[j]=a[j-1];
        a[j-1]=swap;
	swapc=c[j];
	c[j]=c[j-1];
	c[j-1]=swapc;

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

    //stability
    printf("Stable\n");

  //SelectionSort
  for(i=1;i<=n;i++){
    minj=i;
    for(j=i;j<=n;j++){
      if(b[j]<b[minj]){
        minj=j;
      }
    }
      //swap
      swap=b[i];
      b[i]=b[minj];
      b[minj]=swap;
      swapc=d[i];
      d[i]=d[minj];
      d[minj]=swapc;
  }


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

  //stability
  f=0;
  for(i=1;i<=n;i++){
    if(d[i]!=c[i]){
      printf("Not stable\n");
      f=1;
      break;
    }
  }  
  if(f==0)printf("Stable\n");
  
  
  

  return 0;

}



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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string n;
    cin >> n;
    string s = "0123456789";
    Int ma = -INF;
    string res = "";
    Int x = 1;
    for (Int i = 0; i < (Int)n.size(); i++) {
        x *= 10;
    }
    do {
        string t = "";
        for (Int i = 0; i < (Int)n.size(); i++) {
            t.push_back(s[i]);
        }
        Int a = stoll(n);
        Int b = stoll(t);
        if (min(abs(a - b), x - abs(a - b)) > ma) {
            ma = min(abs(a - b), x - abs(a - b));
            res = t;
        }
    } while (next_permutation(all(s)));
    print(res);
    return 0;
}



Measured memory_bytes: 3224
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;
struct st{
  int x,y,m,c;
  st(int x,int y,int m,int c) : x(x),y(y),m(m),c(c) {}
};
int W,H;
char fie[21][21];
int gomi[21][21];
int memo[21][21][(1<<10)];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int bit_max;
int solve(int x,int y){
  queue<st> q;
  while(!q.empty()) q.pop();
  q.push(st(x,y,0,0));
  memo[x][y][0]=0;
  while(!q.empty()){
    st p = q.front(); q.pop();
    x = p.x; y = p.y;
    for(int i=0;i<4;i++){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(nx < 0 || ny < 0 || nx>=W || ny>=H) continue;
      if(fie[nx][ny]=='x') continue;
      if(fie[nx][ny]=='*'){
	if( !((1<<gomi[nx][ny]) & p.m) ){
	  int next_m = ((1<<gomi[nx][ny]) | p.m);
	  if(memo[nx][ny][next_m]!=-1) continue;
	  if(bit_max == next_m) return p.c+1;
	  memo[nx][ny][next_m]=p.c+1;
	  q.push(st(nx,ny,next_m,p.c+1));
	}else{
	  if(memo[nx][ny][p.m]!=-1) continue;
	  memo[nx][ny][p.m]=p.c+1;
	  q.push(st(nx,ny,p.m,p.c+1));
	}
      }else{
	if(memo[nx][ny][p.m]!=-1) continue;
	memo[nx][ny][p.m]=p.c+1;
	q.push(st(nx,ny,p.m,p.c+1));
      }
    }
  }
  return -1;
}
int main(){
  while(1){
    int sx,sy;
    memset(memo,-1,sizeof(memo));
    memset(gomi,-1,sizeof(gomi));
    cin >> W >> H;
    if(!W && !H) break;
    int co=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> fie[j][i];
	if(fie[j][i]=='o'){
	  sx=j; sy=i;
	} else if(fie[j][i]=='*'){
	  gomi[j][i]=co;
	  ++co;
	}
      }
    }
    bit_max = (1<<co)-1;
    //    cout << bitset<16>(bit_max) << "\n";
    if(bit_max==0) cout << 0 << "\n";
    else cout << solve(sx,sy) << "\n";
  }
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 3e5+2;
vector<int> rows[MX];
int cols[MX];
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int R, C, m;
	cin >> R >> C >> m;
	for(int i=0; i<m; i++) {
		int r, c;
		cin >> r >> c;
		rows[r].push_back(c);
		cols[c]++;
	}
	vector<int> mxcol;
	int mxv = *max_element(cols, cols+C+1);
	for(int i=1; i<=C; i++)
		if(mxv == cols[i])
			mxcol.push_back(i);
	int mxrow = 0;
	for(int i=1; i<=R; i++) {
		mxrow = max(mxrow, (int)rows[i].size());
	}
	for(int i=1; i<=R; i++) {
		if(mxrow != (int)rows[i].size())
			continue;
		sort(rows[i].begin(), rows[i].end());
		for(int t: mxcol) {
			if(!binary_search(rows[i].begin(), rows[i].end(), t)) {
				return !(cout << mxrow + mxv);
			}
		}
	}
	cout << mxrow + mxv - 1;
}

Measured memory_bytes: 26096
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

int cnt[30];
int main(){
	int n;
	scanf("%d",&n);
	int xs = 0;
	for(int i=0; i<n; i++){
		int x;
		scanf("%d",&x);
		xs ^= x;
		x ^= (x - 1);
		for(int j=0; j<=30; j++){
			if(x + 1 == (1 << j)){
				cnt[j]++;
				break;
			}
		}
	}
	int ans = 0;
	for(int i=30; i; i--){
		if((xs >> i) % 2 != (xs >> (i - 1)) % 2){
			if(!cnt[i]){
				puts("-1");
				return 0;
			}
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
S = list(input())
T = list(input())

diff = len(S) - len(T)

mins = []
for i in range(diff+1):
    s = S[i:i+len(T)]
    c = 0
    #print(s)
    for ss, tt in zip(s, T):
        if(ss != tt):
            c += 1
    mins.append(c)     

print(min(mins))

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

int main(){
    ll a; long double B; cin >> a >> B;
    long double b = (B*10000.0);
    __uint128_t bb = b; if(bb % 10 != 0) bb+=1;
    __uint128_t ans = a;
    ans *= bb;
    __uint128_t w = ans/10000;
    cout << (ll)w << endl;
    
}

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

int main() {
    int N, M, C, tmp, ans = 0;
    int a, B[20];
    for (int i = 0; i < 20; i++) {
        B[i] = 0;
    }
    cin >> N >> M >> C;
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        tmp = 0;
        for (int j = 0; j < M; j++) {
            cin >> a;
            tmp += a * B[j];
        }
        if (tmp > -C) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<ctime>
#include<unordered_map>
const  int N = 2e6*1.0;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double lw;
#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
int ans=INF;
map<pa, int> mp;
int p, q;
int main()
{
	int n;
	pa a[55];
	cin >> n ;
	fo(i, 0, n)
	{
		sc(a[i].first);
		sc(a[i].second);
		mp[pa(a[i].first, a[i].second)] = 1;
	}
	fo(i,0,n-1)
		fo(j, i + 1, n)
	{
		int cnt = 0;
		p = a[j].first - a[i].first, q = a[j].second - a[i].second;
		if (p != 0 || q != 0)
		{
			fo(i, 0, n)
			{
				if (mp[pa(a[i].first - p, a[i].second - q)]!=1)
					cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	if (n == 1)
		cout << 1 << endl;
	else
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll n, a[200005], ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (ll i = 1; i <= n; ++i)
        cin >> a[i];
    for (ll i = 1; i < n; ++i)
        if (a[i] > a[i + 1]) {
            ans += (a[i] - a[i + 1]);
            a[i + 1] = a[i];
        }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5184
#include <cstdio>
using namespace std;

int main()
{
	int dp[301]={0}, c[18];
	dp[0]=1;
	for(int i=1; i<=17; i++)
		c[i]=i*i;
		
	for(int i=1; i<18; i++)
	for(int j=300; j>=0; j--)
	for(int k=1; k<=300; k++)
	{
		if(j+c[i]*k>300) break;
		if(dp[j]!=0) dp[j+c[i]*k]+=dp[j];
	}
	
	int N;
	while(scanf("%d", &N), N)
	{
		printf("%d\n", dp[N]);
	}
}

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

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

int main(void){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int len = 0;
      while (j+len < w) {
	if (s[i][j+len] == '#') break;
	++len;
      }
      rep(k, len) {
	cnt[i][j+k] += len;
	done[j+k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(h);
    rep(i, h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int len = 0;
      while (i+len < h) {
	if (s[i+len][j] == '#') break;
	++len;
      }
      rep(k, len) {
	cnt[i+k][j] += len;
	done[i+k] = 1;
      }
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;
  return 0;
}


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

int main() {
  //数の代入
  int N, K;
  cin >> N >> K;
  vector<int> length(N);
  for (int i = 0; i < N; i++) {
    cin >> length.at(i);
  }
  
 
  //lengthをソート→リバースして，最初からK本をつなげる
  sort(length.begin(),length.end());
  reverse(length.begin(),length.end());
  
  int max = 0;
  for (int i = 0; i < K; i++) {
    max += length.at(i);
  }
  
  cout << max << endl;
}



Measured memory_bytes: 256
<?php

$sc = new Scanner();
$out = new out();
$input[0] = $sc->nextInt();
$input[1] = $sc->nextInt();
if ($input[0] == $input[1] || $input[0] % $input[1] == 0) {
    $out->println(-1);
    exit;
}
for($i = $input[0] * 2; $i < pow(10,18); $i += $input[0]) { 
    if ($i % $input[1] != 0) {
        $out->println($i);
        exit;
    }
}
$out->println(-1);

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

Measured memory_bytes: 3956
#include <stdio.h>
#include <vector>

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> dp(3, 0);
  std::vector<int> new_dp(3, 0);
  for (int i = 0; i < n; i++) {
    int win[3];
    scanf("%d%d%d", &win[0], &win[1], &win[2]);
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++)
        if (j != k)
          new_dp[k] = std::max(new_dp[k], win[k] + dp[j]);
    dp = new_dp;
  }
  int answer = 0;
  for (int j = 0; j < 3; j++)
    answer = std::max(answer, dp[j]);
  printf("%d\n", answer);
  return 0;
}


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

int main()
{   string s;
    string t;
    cin>>s;
    cin>>t;
    ll m=s.size();
    ll n=t.size();
    ll k=m;
    ll l=n;
    vector <char> crr={};
    string s1="";
    ll arr[m+1][n+1]={};
    for (int i=0;i<n+1;i++){
        arr[0][i]=0;
    }
    for (int i=0;i<m+1;i++){
        arr[i][0]=0;
    }
    for (int i=1;i<m+1;i++){
        for (int j=1;j<n+1;j++){
            if (s[i-1]==t[j-1]){
                arr[i][j]=1+arr[i-1][j-1];
            }
            else{
                arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
            }
        }
    }
    while (k>0 && l>0){
        if (s[k-1]==t[l-1]){
            crr.push_back(s[k-1]);
            k--;
            l--;
        }
        else{
            if (arr[k-1][l]>arr[k][l-1]){
                k--;
            }
            else{
                l--;
            }
        }
    }
    for (int i=crr.size()-1;i>=0;i--){
        s1=s1+crr[i];
    }
    cout<<s1<<endl;
    
    
    return 0;
}



Measured memory_bytes: 73920
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BFiveDishes {
public:
    void solve(std::istream &in, std::ostream &out) {
        vi times(5);
        in >> times;
        int res = 0, mini = 10;
        trav(t, times) {
            res += (t + 9) / 10 * 10;
            if (t % 10) {
                ckmin(mini, t % 10);
            }
        }
        res -= 10 - mini;
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BFiveDishes solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mn=1e5+4;
ll a[mn],b[mn];
int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; scanf("%lld",&n);
	for (ll i=0;i<n;i++) scanf("%lld%lld",a+i,b+i);
	ll sum=0;
	for (ll i=n-1;i>=0;i--) {
		ll needadd=(2*b[i]-((a[i]+sum)%b[i]))%b[i];
		sum+=needadd;
	}
	printf("%lld\n",sum);
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  int nowx=0,nowy=0,nowt=0;
  for (int i=1;i<=n;i++)
  {
  	int t,x,y;
  	cin>>t>>x>>y;
  	int ile=abs(nowx-x)+abs(nowy-y);
  	if (ile<=t-nowt && (t-nowt-ile)%2==0);
  	else
  	{
  		cout<<"No";
  		return 0;
  	}
  	nowx=x,nowy=y,nowt=t;
  }
  
  cout<<"Yes";
  return 0;
}


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

using namespace std;

#define INF (unsigned)!((int)0)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back

typedef long long ll;
typedef vector<int> vi;

int main(){
    int n;
    cin>>n;
    vi v(n);
    rep(i,n) {
        cin>>v[i];
        v[i]-=i+1;
    }
    sort(all(v));
    ll ans = 0;
    rep(i,n) ans+=abs(v[i]-v[n/2]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024